emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 165f738: Update Org to 9.3


From: Bastien Guerry
Subject: master 165f738: Update Org to 9.3
Date: Tue, 3 Dec 2019 17:27:58 -0500 (EST)

branch: master
commit 165f7383822086d465519ebe6e4283723923f097
Author: Bastien <address@hidden>
Commit: Bastien <address@hidden>

    Update Org to 9.3
---
 doc/misc/org.texi                          | 28995 +++++++++++++++------------
 etc/ORG-NEWS                               |   922 +-
 etc/refcards/orgcard.tex                   |    39 +-
 etc/schema/schemas.xml                     |    59 +-
 lisp/org/ob-C.el                           |    14 +-
 lisp/org/ob-J.el                           |     2 +-
 lisp/org/ob-calc.el                        |     2 +-
 lisp/org/ob-clojure.el                     |   127 +-
 lisp/org/ob-comint.el                      |     2 +-
 lisp/org/ob-core.el                        |   435 +-
 lisp/org/ob-dot.el                         |     2 +
 lisp/org/ob-emacs-lisp.el                  |    36 +-
 lisp/org/ob-eshell.el                      |   102 +
 lisp/org/ob-exp.el                         |    14 +-
 lisp/org/ob-forth.el                       |     2 +-
 lisp/org/ob-fortran.el                     |     5 +-
 lisp/org/ob-gnuplot.el                     |     2 +-
 lisp/org/ob-haskell.el                     |    12 +-
 lisp/org/ob-js.el                          |   118 +-
 lisp/org/ob-keys.el                        |   106 -
 lisp/org/ob-latex.el                       |     2 +-
 lisp/org/ob-lilypond.el                    |     6 +-
 lisp/org/ob-lisp.el                        |     4 +-
 lisp/org/ob-lob.el                         |     7 +-
 lisp/org/ob-lua.el                         |     9 +-
 lisp/org/ob-ocaml.el                       |     6 +-
 lisp/org/ob-octave.el                      |    18 +-
 lisp/org/ob-plantuml.el                    |    17 +-
 lisp/org/ob-python.el                      |    23 +-
 lisp/org/ob-ref.el                         |     6 +-
 lisp/org/ob-ruby.el                        |     2 +-
 lisp/org/ob-scheme.el                      |    12 +-
 lisp/org/ob-sed.el                         |     4 +-
 lisp/org/ob-shell.el                       |   117 +-
 lisp/org/ob-sql.el                         |    52 +-
 lisp/org/ob-sqlite.el                      |     1 -
 lisp/org/ob-table.el                       |     3 +-
 lisp/org/ob-tangle.el                      |    77 +-
 lisp/org/ob-vala.el                        |     3 +-
 lisp/org/ob.el                             |     2 +-
 lisp/org/{org-bbdb.el => ol-bbdb.el}       |    38 +-
 lisp/org/{org-bibtex.el => ol-bibtex.el}   |    31 +-
 lisp/org/{org-docview.el => ol-docview.el} |    21 +-
 lisp/org/{org-eshell.el => ol-eshell.el}   |    16 +-
 lisp/org/{org-eww.el => ol-eww.el}         |    33 +-
 lisp/org/{org-gnus.el => ol-gnus.el}       |    40 +-
 lisp/org/{org-info.el => ol-info.el}       |    14 +-
 lisp/org/{org-irc.el => ol-irc.el}         |    27 +-
 lisp/org/{org-mhe.el => ol-mhe.el}         |    16 +-
 lisp/org/{org-rmail.el => ol-rmail.el}     |    16 +-
 lisp/org/{org-w3m.el => ol-w3m.el}         |    47 +-
 lisp/org/ol.el                             |  1907 ++
 lisp/org/org-agenda.el                     |  1869 +-
 lisp/org/org-archive.el                    |   133 +-
 lisp/org/org-attach-git.el                 |   119 +
 lisp/org/org-attach.el                     |   748 +-
 lisp/org/org-capture.el                    |   780 +-
 lisp/org/org-clock.el                      |   663 +-
 lisp/org/org-colview.el                    |   325 +-
 lisp/org/org-compat.el                     |   731 +-
 lisp/org/org-crypt.el                      |     2 +-
 lisp/org/org-duration.el                   |     1 -
 lisp/org/org-element.el                    |   430 +-
 lisp/org/org-entities.el                   |    10 +-
 lisp/org/org-faces.el                      |    28 +-
 lisp/org/org-feed.el                       |     7 +-
 lisp/org/org-footnote.el                   |   611 +-
 lisp/org/org-goto.el                       |   312 +
 lisp/org/org-habit.el                      |    76 +-
 lisp/org/org-id.el                         |   188 +-
 lisp/org/org-indent.el                     |    73 +-
 lisp/org/org-inlinetask.el                 |    80 +-
 lisp/org/org-keys.el                       |   924 +
 lisp/org/org-lint.el                       |    76 +-
 lisp/org/org-list.el                       |   313 +-
 lisp/org/org-macro.el                      |   280 +-
 lisp/org/org-macs.el                       |  1238 +-
 lisp/org/org-mobile.el                     |   101 +-
 lisp/org/org-mouse.el                      |    22 +-
 lisp/org/org-num.el                        |   469 +
 lisp/org/org-pcomplete.el                  |   253 +-
 lisp/org/org-plot.el                       |     2 +-
 lisp/org/org-protocol.el                   |    95 +-
 lisp/org/org-src.el                        |   249 +-
 lisp/org/org-table.el                      |  3953 ++--
 lisp/org/org-tempo.el                      |   188 +
 lisp/org/org-timer.el                      |    35 +-
 lisp/org/org-version.el                    |     4 +-
 lisp/org/org.el                            | 10596 ++++------
 lisp/org/ox-ascii.el                       |    61 +-
 lisp/org/ox-beamer.el                      |    90 +-
 lisp/org/ox-html.el                        |   457 +-
 lisp/org/ox-icalendar.el                   |   123 +-
 lisp/org/ox-latex.el                       |   545 +-
 lisp/org/ox-man.el                         |     2 +-
 lisp/org/ox-md.el                          |    46 +-
 lisp/org/ox-odt.el                         |    68 +-
 lisp/org/ox-org.el                         |    13 +-
 lisp/org/ox-publish.el                     |    91 +-
 lisp/org/ox-texinfo.el                     |   282 +-
 lisp/org/ox.el                             |   476 +-
 101 files changed, 34729 insertions(+), 27082 deletions(-)

diff --git a/doc/misc/org.texi b/doc/misc/org.texi
index adb795e..f7818a2 100644
--- a/doc/misc/org.texi
+++ b/doc/misc/org.texi
@@ -1,266 +1,21 @@
-\input texinfo  @c -*- coding: utf-8 -*-
+\input texinfo    @c -*- texinfo -*-
 @c %**start of header
-@setfilename ../../info/org.info
+@setfilename org.info
 @settitle The Org Manual
-@include docstyle.texi
-
-@set VERSION 9.1.9
-@set DATE 2018-03-22
-
-@c Version and Contact Info
-@set MAINTAINERSITE @uref{https://orgmode.org,maintainers web page}
-@set AUTHOR Carsten Dominik
+@documentencoding UTF-8
+@documentlanguage en
+@set txicodequoteundirected
+@set txicodequotebacktick
+@set MAINTAINERSITE @uref{https://orgmode.org,maintainers webpage}
 @set MAINTAINER Carsten Dominik
 @set MAINTAINEREMAIL @email{carsten at orgmode dot org}
 @set MAINTAINERCONTACT @uref{mailto:carsten at orgmode dot org,contact the 
maintainer}
 @c %**end of header
-@finalout
-
-
-@c 
-----------------------------------------------------------------------------
-
-@c Macro definitions for commands and keys
-@c =======================================
-
-@c The behavior of the key/command macros will depend on the flag cmdnames
-@c When set, commands names are shown.  When clear, they are not shown.
-
-@set cmdnames
-
-@c Below we define the following macros for Org key tables:
-
-@c orgkey{key}                        A key item
-@c orgcmd{key,cmd}                    Key with command name
-@c xorgcmd{key,cmd}                   Key with command name as @itemx
-@c orgcmdnki{key,cmd}                 Like orgcmd, but do not index the key
-@c orgcmdtkc{text,key,cmd}            Like orgcmd,special text instead of key
-@c orgcmdkkc{key1,key2,cmd}           Two keys with one command name, use "or"
-@c orgcmdkxkc{key1,key2,cmd}          Two keys with one command name, but
-@c                                    different functions, so format as @itemx
-@c orgcmdkskc{key1,key2,cmd}          Same as orgcmdkkc, but use "or short"
-@c xorgcmdkskc{key1,key2,cmd}         Same as previous, but use @itemx
-@c orgcmdkkcc{key1,key2,cmd1,cmd2}    Two keys and two commands
-
-@c a key but no command
-@c    Inserts:    @item key
-@macro orgkey{key}
-@kindex \key\
-@item @kbd{\key\}
-@end macro
-
-@macro xorgkey{key}
-@kindex \key\
-@itemx @kbd{\key\}
-@end macro
-
-@c one key with a command
-@c   Inserts:    @item KEY               COMMAND
-@macro orgcmd{key,command}
-@ifset cmdnames
-@kindex \key\
-@findex \command\
-@iftex
-@item @kbd{\key\} @hskip 0pt plus 1filll @code{\command\}
-@end iftex
-@ifnottex
-@item @kbd{\key\} @tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key\
-@item @kbd{\key\}
-@end ifclear
-@end macro
-
-@c One key with one command, formatted using @itemx
-@c   Inserts:    @itemx KEY               COMMAND
-@macro xorgcmd{key,command}
-@ifset cmdnames
-@kindex \key\
-@findex \command\
-@iftex
-@itemx @kbd{\key\} @hskip 0pt plus 1filll @code{\command\}
-@end iftex
-@ifnottex
-@itemx @kbd{\key\} @tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key\
-@itemx @kbd{\key\}
-@end ifclear
-@end macro
-
-@c one key with a command, bit do not index the key
-@c   Inserts:    @item KEY               COMMAND
-@macro orgcmdnki{key,command}
-@ifset cmdnames
-@findex \command\
-@iftex
-@item @kbd{\key\} @hskip 0pt plus 1filll @code{\command\}
-@end iftex
-@ifnottex
-@item @kbd{\key\} @tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@item @kbd{\key\}
-@end ifclear
-@end macro
-
-@c one key with a command, and special text to replace key in item
-@c   Inserts:    @item TEXT                    COMMAND
-@macro orgcmdtkc{text,key,command}
-@ifset cmdnames
-@kindex \key\
-@findex \command\
-@iftex
-@item @kbd{\text\} @hskip 0pt plus 1filll @code{\command\}
-@end iftex
-@ifnottex
-@item @kbd{\text\} @tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key\
-@item @kbd{\text\}
-@end ifclear
-@end macro
-
-@c two keys with one command
-@c   Inserts:    @item KEY1 or KEY2            COMMAND
-@macro orgcmdkkc{key1,key2,command}
-@ifset cmdnames
-@kindex \key1\
-@kindex \key2\
-@findex \command\
-@iftex
-@item @kbd{\key1\} @ @r{or} @ @kbd{\key2\} @hskip 0pt plus 1filll 
@code{\command\}
-@end iftex
-@ifnottex
-@item @kbd{\key1\} @ @r{or} @ @kbd{\key2\} 
@tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key1\
-@kindex \key2\
-@item @kbd{\key1\} @ @r{or} @ @kbd{\key2\}
-@end ifclear
-@end macro
-
-@c Two keys with one command name, but different functions, so format as
-@c @itemx
-@c   Inserts:    @item KEY1
-@c               @itemx KEY2                COMMAND
-@macro orgcmdkxkc{key1,key2,command}
-@ifset cmdnames
-@kindex \key1\
-@kindex \key2\
-@findex \command\
-@iftex
-@item @kbd{\key1\}
-@itemx @kbd{\key2\} @hskip 0pt plus 1filll @code{\command\}
-@end iftex
-@ifnottex
-@item @kbd{\key1\}
-@itemx @kbd{\key2\} @tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key1\
-@kindex \key2\
-@item @kbd{\key1\}
-@itemx @kbd{\key2\}
-@end ifclear
-@end macro
-
-@c Same as previous, but use "or short"
-@c   Inserts:    @item KEY1 or short KEY2            COMMAND
-@macro orgcmdkskc{key1,key2,command}
-@ifset cmdnames
-@kindex \key1\
-@kindex \key2\
-@findex \command\
-@iftex
-@item @kbd{\key1\} @ @r{or short} @ @kbd{\key2\} @hskip 0pt plus 1filll 
@code{\command\}
-@end iftex
-@ifnottex
-@item @kbd{\key1\} @ @r{or short} @ @kbd{\key2\} 
@tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key1\
-@kindex \key2\
-@item @kbd{\key1\} @ @r{or short} @ @kbd{\key2\}
-@end ifclear
-@end macro
-
-@c Same as previous, but use @itemx
-@c   Inserts:    @itemx KEY1 or short KEY2            COMMAND
-@macro xorgcmdkskc{key1,key2,command}
-@ifset cmdnames
-@kindex \key1\
-@kindex \key2\
-@findex \command\
-@iftex
-@itemx @kbd{\key1\} @ @r{or short} @ @kbd{\key2\} @hskip 0pt plus 1filll 
@code{\command\}
-@end iftex
-@ifnottex
-@itemx @kbd{\key1\} @ @r{or short} @ @kbd{\key2\} 
@tie{}@tie{}@tie{}@tie{}(@code{\command\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key1\
-@kindex \key2\
-@itemx @kbd{\key1\} @ @r{or short} @ @kbd{\key2\}
-@end ifclear
-@end macro
-
-@c two keys with two commands
-@c   Inserts:    @item KEY1                        COMMAND1
-@c               @itemx KEY2                       COMMAND2
-@macro orgcmdkkcc{key1,key2,command1,command2}
-@ifset cmdnames
-@kindex \key1\
-@kindex \key2\
-@findex \command1\
-@findex \command2\
-@iftex
-@item @kbd{\key1\} @hskip 0pt plus 1filll @code{\command1\}
-@itemx @kbd{\key2\} @hskip 0pt plus 1filll @code{\command2\}
-@end iftex
-@ifnottex
-@item @kbd{\key1\} @tie{}@tie{}@tie{}@tie{}(@code{\command1\})
-@itemx @kbd{\key2\} @tie{}@tie{}@tie{}@tie{}(@code{\command2\})
-@end ifnottex
-@end ifset
-@ifclear cmdnames
-@kindex \key1\
-@kindex \key2\
-@item @kbd{\key1\}
-@itemx @kbd{\key2\}
-@end ifclear
-@end macro
-@c 
-----------------------------------------------------------------------------
-
-@iftex
-@c @hyphenation{time-stamp time-stamps time-stamp-ing time-stamp-ed}
-@end iftex
-
-@c Subheadings inside a table.
-@macro tsubheading{text}
-@ifinfo
-@subsubheading \text\
-@end ifinfo
-@ifnotinfo
-@item @b{\text\}
-@end ifnotinfo
-@end macro
 
 @copying
-This manual is for Org version @value{VERSION}.
+This manual is for Org version 9.3.
 
-Copyright @copyright{} 2004--2019 Free Software Foundation, Inc.
+Copyright @copyright{} 2004--2019  Free Software Foundation, Inc.
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -272,957 +27,943 @@ is included in the section entitled ``GNU Free 
Documentation License.''
 
 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
 modify this GNU manual.''
+
 @end quotation
 @end copying
 
-@dircategory Emacs editing modes
+@dircategory Emacs
 @direntry
-* Org Mode: (org).      Outline-based notes management and organizer
+* Org Mode: (org).      Outline-based notes management and organizer.
 @end direntry
 
+@finalout
 @titlepage
 @title The Org Manual
-
-@subtitle Release @value{VERSION}
-@author by Carsten Dominik
-with contributions by Bastien Guerry, Nicolas Goaziou, Eric Schulte,
-Jambunathan K, Dan Davison, Thomas Dye, David O'Toole, and Philip Rooke.
-
-@c The following two commands start the copyright page.
+@subtitle Release 9.3
+@author The Org Mode Developers
 @page
 @vskip 0pt plus 1filll
 @insertcopying
 @end titlepage
 
-@c Output the short table of contents at the beginning.
-@shortcontents
-
-@c Output the table of contents at the beginning.
 @contents
 
 @ifnottex
-
-@node Top, Introduction, (dir), (dir)
-@top Org Mode Manual
+@node Top
+@top The Org Manual
 
 @insertcopying
 @end ifnottex
 
 @menu
-* Introduction::                Getting started
-* Document structure::          A tree works like your brain
-* Tables::                      Pure magic for quick formatting
-* Hyperlinks::                  Notes in context
-* TODO items::                  Every tree branch can be a TODO item
-* Tags::                        Tagging headlines and matching sets of tags
-* Properties and columns::      Storing information about an entry
-* Dates and times::             Making items useful for planning
-* Capture - Refile - Archive::  The ins and outs for projects
-* Agenda views::                Collecting information into views
-* Markup::                      Prepare text for rich export
-* Exporting::                   Sharing and publishing notes
-* Publishing::                  Create a web site of linked Org files
-* Working with source code::    Export, evaluate, and tangle code blocks
-* Miscellaneous::               All the rest which did not fit elsewhere
-* Hacking::                     How to hack your way around
-* History and acknowledgments::  How Org came into being
-* GNU Free Documentation License::  The license for this documentation.
-* Main Index::                  An index of Org's concepts and features
-* Key Index::                   Key bindings and where they are described
-* Command and Function Index::  Command names and some internal functions
-* Variable Index::              Variables mentioned in the manual
+* Introduction::                 Getting started.
+* Document Structure::           A tree works like your brain.
+* Tables::                       Pure magic for quick formatting.
+* Hyperlinks::                   Notes in context.
+* TODO Items::                   Every tree branch can be a TODO item.
+* Tags::                         Tagging headlines and matching sets of tags.
+* Properties and Columns::       Storing information about an entry.
+* Dates and Times::              Making items useful for planning.
+* Refiling and Archiving::       Moving and copying information with ease.
+* Capture and Attachments::      Dealing with external data.
+* Agenda Views::                 Collecting information into views.
+* Markup for Rich Contents::     Compose beautiful documents.
+* Exporting::                    Sharing and publishing notes.
+* Publishing::                   Create a web site of linked Org files.
+* Working with Source Code::     Export, evaluate, and tangle code blocks.
+* Miscellaneous::                All the rest which did not fit elsewhere.
+* Hacking::                      How to hack your way around.
+* History and Acknowledgments::  How Org came into being.
+* GNU Free Documentation License:: The license for this documentation.
+* Main Index::                   An index of Org's concepts and features.
+* Key Index::                    Key bindings and where they are described.
+* Command and Function Index::   Command names and some internal functions.
+* Variable Index::               Variables mentioned in the manual.
 
 @detailmenu
- --- The Detailed Node Listing ---
+--- The Detailed Node Listing ---
 
 Introduction
 
-* Summary::                     Brief summary of what Org does
-* Installation::                Installing Org
-* Activation::                  How to activate Org for certain buffers
-* Feedback::                    Bug reports, ideas, patches etc.
-* Conventions::                 Typesetting conventions in the manual
-
-Document structure
-
-* Outlines::                    Org is based on Outline mode
-* Headlines::                   How to typeset Org tree headlines
-* Visibility cycling::          Show and hide, much simplified
-* Motion::                      Jumping to other headlines
-* Structure editing::           Changing sequence and level of headlines
-* Sparse trees::                Matches embedded in context
-* Plain lists::                 Additional structure within an entry
-* Drawers::                     Tucking stuff away
-* Blocks::                      Folding blocks
-* Footnotes::                   How footnotes are defined in Org's syntax
-* Orgstruct mode::              Structure editing outside Org
-* Org syntax::                  Formal description of Org's syntax
-
-Visibility cycling
-
-* Global and local cycling::    Cycling through various visibility states
-* Initial visibility::          Setting the initial visibility state
-* Catching invisible edits::    Preventing mistakes when editing invisible 
parts
-
-Tables
-
-* Built-in table editor::       Simple tables
-* Column width and alignment::  Overrule the automatic settings
-* Column groups::               Grouping to trigger vertical lines
-* Orgtbl mode::                 The table editor as minor mode
-* The spreadsheet::             The table editor has spreadsheet capabilities
-* Org-Plot::                    Plotting from org tables
-
-The spreadsheet
-
-* References::                  How to refer to another field or range
-* Formula syntax for Calc::     Using Calc to compute stuff
-* Formula syntax for Lisp::     Writing formulas in Emacs Lisp
-* Durations and time values::   How to compute durations and time values
-* Field and range formulas::    Formula for specific (ranges of) fields
-* Column formulas::             Formulas valid for an entire column
-* Lookup functions::            Lookup functions for searching tables
-* Editing and debugging formulas::  Fixing formulas
-* Updating the table::          Recomputing all dependent fields
-* Advanced features::           Field and column names, parameters and 
automatic recalc
+* Summary::                      Brief summary of what Org does.
+* Installation::                 Installing Org.
+* Activation::                   How to activate Org for certain buffers.
+* Feedback::                     Bug reports, ideas, patches, etc.
+* Conventions::                  Typesetting conventions used in this manual.
 
-Hyperlinks
-
-* Link format::                 How links in Org are formatted
-* Internal links::              Links to other places in the current file
-* External links::              URL-like links to the world
-* Handling links::              Creating, inserting and following
-* Using links outside Org::     Linking from my C source code?
-* Link abbreviations::          Shortcuts for writing complex links
-* Search options::              Linking to a specific location
-* Custom searches::             When the default search is not enough
+Document Structure
 
-Internal links
+* Headlines::                    How to typeset Org tree headlines.
+* Visibility Cycling::           Show and hide, much simplified.
+* Motion::                       Jumping to other headlines.
+* Structure Editing::            Changing sequence and level of headlines.
+* Sparse Trees::                 Matches embedded in context.
+* Plain Lists::                  Additional structure within an entry.
+* Drawers::                      Tucking stuff away.
+* Blocks::                       Folding blocks.
 
-* Radio targets::               Make targets trigger links in plain text
+Visibility Cycling
 
-TODO items
+* Global and local cycling::     Cycling through various visibility states.
+* Initial visibility::           Setting the initial visibility state.
+* Catching invisible edits::     Preventing mistakes when editing invisible 
parts.
 
-* TODO basics::                 Marking and displaying TODO entries
-* TODO extensions::             Workflow and assignments
-* Progress logging::            Dates and notes for progress
-* Priorities::                  Some things are more important than others
-* Breaking down tasks::         Splitting a task into manageable pieces
-* Checkboxes::                  Tick-off lists
-
-Extended use of TODO keywords
+Tables
 
-* Workflow states::             From TODO to DONE in steps
-* TODO types::                  I do this, Fred does the rest
-* Multiple sets in one file::   Mixing it all, and still finding your way
-* Fast access to TODO states::  Single letter selection of a state
-* Per-file keywords::           Different files, different requirements
-* Faces for TODO keywords::     Highlighting states
-* TODO dependencies::           When one task needs to wait for others
+* Built-in Table Editor::        Simple tables.
+* Column Width and Alignment::   Overrule the automatic settings.
+* Column Groups::                Grouping to trigger vertical lines.
+* Orgtbl Mode::                  The table editor as minor mode.
+* The Spreadsheet::              The table editor has spreadsheet capabilities.
+* Org Plot::                     Plotting from Org tables.
+
+The Spreadsheet
+
+* References::                   How to refer to another field or range.
+* Formula syntax for Calc::      Using Calc to compute stuff.
+* Formula syntax for Lisp::      Writing formulas in Emacs Lisp.
+* Durations and time values::    How to compute durations and time values.
+* Field and range formulas::     Formula for specific (ranges of) fields.
+* Column formulas::              Formulas valid for an entire column.
+* Lookup functions::             Lookup functions for searching tables.
+* Editing and debugging formulas:: Fixing formulas.
+* Updating the table::           Recomputing all dependent fields.
+* Advanced features::            Field and column names, automatic 
recalculation...
 
-Progress logging
+Hyperlinks
 
-* Closing items::               When was this entry marked DONE?
+* Link Format::                  How links in Org are formatted.
+* Internal Links::               Links to other places in the current file.
+* Radio Targets::                Make targets trigger links in plain text.
+* External Links::               URL-like links to the world.
+* Handling Links::               Creating, inserting and following.
+* Using Links Outside Org::      Linking from my C source code?
+* Link Abbreviations::           Shortcuts for writing complex links.
+* Search Options::               Linking to a specific location.
+* Custom Searches::              When the default search is not enough.
+
+TODO Items
+
+* TODO Basics::                  Marking and displaying TODO entries.
+* TODO Extensions::              Workflow and assignments.
+* Progress Logging::             Dates and notes for progress.
+* Priorities::                   Some things are more important than others.
+* Breaking Down Tasks::          Splitting a task into manageable pieces.
+* Checkboxes::                   Tick-off lists.
+
+TODO Extensions
+
+* Workflow states::              From TODO to DONE in steps.
+* TODO types::                   I do this, Fred does the rest.
+* Multiple sets in one file::    Mixing it all, still finding your way.
+* Fast access to TODO states::   Single letter selection of state.
+* Per-file keywords::            Different files, different requirements.
+* Faces for TODO keywords::      Highlighting states.
+* TODO dependencies::            When one task needs to wait for others.
+
+Progress Logging
+
+* Closing items::                When was this entry marked as done?
 * Tracking TODO state changes::  When did the status change?
-* Tracking your habits::        How consistent have you been?
+* Tracking your habits::         How consistent have you been?
 
 Tags
 
-* Tag inheritance::             Tags use the tree structure of the outline
-* Setting tags::                How to assign tags to a headline
-* Tag hierarchy::               Create a hierarchy of tags
-* Tag searches::                Searching for combinations of tags
+* Tag Inheritance::              Tags use the tree structure of an outline.
+* Setting Tags::                 How to assign tags to a headline.
+* Tag Hierarchy::                Create a hierarchy of tags.
+* Tag Searches::                 Searching for combinations of tags.
 
-Properties and columns
+Properties and Columns
 
-* Property syntax::             How properties are spelled out
-* Special properties::          Access to other Org mode features
-* Property searches::           Matching property values
-* Property inheritance::        Passing values down the tree
-* Column view::                 Tabular viewing and editing
-* Property API::                Properties for Lisp programmers
+* Property Syntax::              How properties are spelled out.
+* Special Properties::           Access to other Org mode features.
+* Property Searches::            Matching property values.
+* Property Inheritance::         Passing values down a tree.
+* Column View::                  Tabular viewing and editing.
 
-Column view
+Column View
 
-* Defining columns::            The COLUMNS format property
-* Using column view::           How to create and use column view
-* Capturing column view::       A dynamic block for column view
+* Defining columns::             The COLUMNS format property.
+* Using column view::            How to create and use column view.
+* Capturing column view::        A dynamic block for column view.
 
 Defining columns
 
 * Scope of column definitions::  Where defined, where valid?
-* Column attributes::           Appearance and content of a column
+* Column attributes::            Appearance and content of a column.
 
-Dates and times
+Dates and Times
 
-* Timestamps::                  Assigning a time to a tree entry
-* Creating timestamps::         Commands which insert timestamps
-* Deadlines and scheduling::    Planning your work
-* Clocking work time::          Tracking how long you spend on a task
-* Effort estimates::            Planning work effort in advance
-* Timers::                      Notes with a running timer
+* Timestamps::                   Assigning a time to a tree entry.
+* Creating Timestamps::          Commands to insert timestamps.
+* Deadlines and Scheduling::     Planning your work.
+* Clocking Work Time::           Tracking how long you spend on a task.
+* Effort Estimates::             Planning work effort in advance.
+* Timers::                       Notes with a running timer.
 
-Creating timestamps
+Creating Timestamps
 
-* The date/time prompt::        How Org mode helps you entering date and time
-* Custom time format::          Making dates look different
+* The date/time prompt::         How Org mode helps you enter dates and times.
+* Custom time format::           Making dates look different.
 
-Deadlines and scheduling
+Deadlines and Scheduling
 
-* Inserting deadline/schedule::  Planning items
-* Repeated tasks::              Items that show up again and again
+* Inserting deadline/schedule::  Planning items.
+* Repeated tasks::               Items that show up again and again.
 
-Clocking work time
+Clocking Work Time
 
-* Clocking commands::           Starting and stopping a clock
-* The clock table::             Detailed reports
-* Resolving idle time::         Resolving time when you've been idle
+* Clocking commands::            Starting and stopping a clock.
+* The clock table::              Detailed reports.
+* Resolving idle time::          Resolving time when you've been idle.
 
-Capture - Refile - Archive
+Refiling and Archiving
 
-* Capture::                     Capturing new stuff
-* Attachments::                 Add files to tasks
-* RSS feeds::                   Getting input from RSS feeds
-* Protocols::                   External (e.g., Browser) access to Emacs and 
Org
-* Refile and copy::             Moving/copying a tree from one place to another
-* Archiving::                   What to do with finished projects
+* Refile and Copy::              Moving/copying a tree from one place to 
another.
+* Archiving::                    What to do with finished products.
 
-Capture
+Archiving
 
-* Setting up capture::          Where notes will be stored
-* Using capture::               Commands to invoke and terminate capture
-* Capture templates::           Define the outline of different note types
+* Moving subtrees::              Moving a tree to an archive file.
+* Internal archiving::           Switch off a tree but keep it in the file.
 
-Capture templates
+Capture and Attachments
 
-* Template elements::           What is needed for a complete template entry
-* Template expansion::          Filling in information about time and context
-* Templates in contexts::       Only show a template in a specific context
+* Capture::                      Capturing new stuff.
+* Attachments::                  Attach files to outlines.
+* RSS Feeds::                    Getting input from RSS feeds.
 
-Protocols for external access
+Capture
 
-* @code{store-link} protocol::  Store a link, push URL to kill-ring.
-* @code{capture} protocol::     Fill a buffer with external information.
-* @code{open-source} protocol::  Edit published contents.
+* Setting up capture::           Where notes will be stored.
+* Using capture::                Commands to invoke and terminate capture.
+* Capture templates::            Define the outline of different note types.
 
-Archiving
+Capture templates
+
+* Template elements::            What is needed for a complete template entry.
+* Template expansion::           Filling in information about time and context.
+* Templates in contexts::        Only show a template in a specific context.
 
-* Moving subtrees::             Moving a tree to an archive file
-* Internal archiving::          Switch off a tree but keep it in the file
+Attachments
 
-Agenda views
+* Attachment defaults and dispatcher:: How to access attachment commands
+* Attachment options::           Configuring the attachment system
+* Attachment links::             Hyperlink access to attachments
+* Automatic version-control with Git:: Everything safely stored away
+* Attach from Dired::            Using dired to select an attachment
 
-* Agenda files::                Files being searched for agenda information
-* Agenda dispatcher::           Keyboard access to agenda views
-* Built-in agenda views::       What is available out of the box?
-* Presentation and sorting::    How agenda items are prepared for display
-* Agenda commands::             Remote editing of Org trees
-* Custom agenda views::         Defining special searches and views
-* Exporting agenda views::      Writing a view to a file
-* Agenda column view::          Using column view for collected entries
+Agenda Views
 
-The built-in agenda views
+* Agenda Files::                 Files being searched for agenda information.
+* Agenda Dispatcher::            Keyboard access to agenda views.
+* Built-in Agenda Views::        What is available out of the box?
+* Presentation and Sorting::     How agenda items are prepared for display.
+* Agenda Commands::              Remote editing of Org trees.
+* Custom Agenda Views::          Defining special searches and views.
+* Exporting Agenda Views::       Writing a view to a file.
+* Agenda Column View::           Using column view for collected entries.
 
-* Weekly/daily agenda::         The calendar page with current tasks
-* Global TODO list::            All unfinished action items
-* Matching tags and properties::  Structured information with fine-tuned search
-* Search view::                 Find entries by searching for text
-* Stuck projects::              Find projects you need to review
+Built-in Agenda Views
 
-Presentation and sorting
+* Weekly/daily agenda::          The calendar page with current tasks.
+* Global TODO list::             All unfinished action items.
+* Matching tags and properties:: Structured information with fine-tuned search.
+* Search view::                  Find entries by searching for text.
+* Stuck projects::               Find projects you need to review.
 
-* Categories::                  Not all tasks are equal
-* Time-of-day specifications::  How the agenda knows the time
-* Sorting agenda items::        The order of things
-* Filtering/limiting agenda items::  Dynamically narrow the agenda
+Presentation and Sorting
 
-Custom agenda views
+* Categories::                   Not all tasks are equal.
+* Time-of-day specifications::   How the agenda knows the time.
+* Sorting of agenda items::      The order of things.
+* Filtering/limiting agenda items:: Dynamically narrow the agenda.
 
-* Storing searches::            Type once, use often
-* Block agenda::                All the stuff you need in a single buffer
-* Setting options::             Changing the rules
+Custom Agenda Views
 
-Markup for rich export
+* Storing searches::             Type once, use often.
+* Block agenda::                 All the stuff you need in a single buffer.
+* Setting options::              Changing the rules.
 
-* Paragraphs::                  The basic unit of text
-* Emphasis and monospace::      Bold, italic, etc.
-* Horizontal rules::            Make a line
-* Images and tables::           Images, tables and caption mechanism
-* Literal examples::            Source code examples with special formatting
-* Special symbols::             Greek letters and other symbols
-* Subscripts and superscripts::  Simple syntax for raising/lowering text
-* Embedded @LaTeX{}::           LaTeX can be freely used inside Org documents
+Markup for Rich Contents
+
+* Paragraphs::                   The basic unit of text.
+* Emphasis and Monospace::       Bold, italic, etc.
+* Subscripts and Superscripts::  Simple syntax for raising/lowering text.
+* Special Symbols::              Greek letters and other symbols.
+* Embedded @LaTeX{}::            LaTeX can be freely used inside Org documents.
+* Literal Examples::             Source code examples with special formatting.
+* Images::                       Display an image.
+* Captions::                     Describe tables, images...
+* Horizontal Rules::             Make a line.
+* Creating Footnotes::           Edit and read footnotes.
 
 Embedded @LaTeX{}
 
-* @LaTeX{} fragments::          Complex formulas made easy
-* Previewing @LaTeX{} fragments::  What will this snippet look like?
-* CDLaTeX mode::                Speed up entering of formulas
+* @LaTeX{} fragments::           Complex formulas made easy.
+* Previewing @LaTeX{} fragments:: What will this snippet look like?
+* CD@LaTeX{} mode::              Speed up entering of formulas.
 
 Exporting
 
-* The export dispatcher::       The main interface
-* Export settings::             Common export settings
-* Table of contents::           The if and where of the table of contents
-* Include files::               Include additional files into a document
-* Macro replacement::           Use macros to create templates
-* Comment lines::               What will not be exported
-* ASCII/Latin-1/UTF-8 export::  Exporting to flat files with encoding
-* Beamer export::               Exporting as a Beamer presentation
-* HTML export::                 Exporting to HTML
-* @LaTeX{} export::             Exporting to @LaTeX{}, and processing to PDF
-* Markdown export::             Exporting to Markdown
-* OpenDocument Text export::    Exporting to OpenDocument Text
-* Org export::                  Exporting to Org
-* Texinfo export::              Exporting to Texinfo
-* iCalendar export::            Exporting to iCalendar
-* Other built-in back-ends::    Exporting to a man page
-* Advanced configuration::      Fine-tuning the export output
-* Export in foreign buffers::   Author tables and lists in Org syntax
-
-Beamer export
-
-* Beamer export commands::      For creating Beamer documents.
-* Beamer specific export settings::  For customizing Beamer export.
-* Sectioning Frames and Blocks in Beamer::  For composing Beamer slides.
-* Beamer specific syntax::      For using in Org documents.
-* Editing support::             For using helper functions.
-* A Beamer example::            A complete presentation.
-
-HTML export
-
-* HTML Export commands::        Invoking HTML export
-* HTML Specific export settings::  Settings for HTML export
-* HTML doctypes::               Exporting various (X)HTML flavors
-* HTML preamble and postamble::  Inserting preamble and postamble
-* Quoting HTML tags::           Using direct HTML in Org files
-* Links in HTML export::        Interpreting and formatting links
-* Tables in HTML export::       Formatting and modifying tables
-* Images in HTML export::       Inserting figures with HTML output
-* Math formatting in HTML export::  Handling math equations
-* Text areas in HTML export::   Showing an alternate approach, an example
-* CSS support::                 Styling HTML output
-* JavaScript support::          Folding scripting in the web browser
-
-@LaTeX{} export
-
-* @LaTeX{} export commands::    For producing @LaTeX{} and PDF documents.
-* @LaTeX{} specific export settings::  Unique to this @LaTeX{} back-end.
-* @LaTeX{} header and sectioning::  For file structure.
-* Quoting @LaTeX{} code::       Directly in the Org document.
-* Tables in @LaTeX{} export::   Attributes specific to tables.
-* Images in @LaTeX{} export::   Attributes specific to images.
-* Plain lists in @LaTeX{} export::  Attributes specific to lists.
-* Source blocks in @LaTeX{} export::  Attributes specific to source code 
blocks.
-* Example blocks in @LaTeX{} export::  Attributes specific to example blocks.
-* Special blocks in @LaTeX{} export::  Attributes specific to special blocks.
-* Horizontal rules in @LaTeX{} export::  Attributes specific to horizontal 
rules.
-
-OpenDocument Text export
-
-* Pre-requisites for ODT export::  Required packages.
-* ODT export commands::         Invoking export.
-* ODT specific export settings::  Configuration options.
-* Extending ODT export::        Producing @file{.doc}, @file{.pdf} files.
-* Applying custom styles::      Styling the output.
-* Links in ODT export::         Handling and formatting links.
-* Tables in ODT export::        Org table conversions.
-* Images in ODT export::        Inserting images.
-* Math formatting in ODT export::  Formatting @LaTeX{} fragments.
-* Labels and captions in ODT export::  Rendering objects.
-* Literal examples in ODT export::  For source code and example blocks.
-* Advanced topics in ODT export::  For power users.
+* The Export Dispatcher::        The main interface.
+* Export Settings::              Common export settings.
+* Table of Contents::            The if and where of the table of contents.
+* Include Files::                Include additional files into a document.
+* Macro Replacement::            Use macros to create templates.
+* Comment Lines::                What will not be exported.
+* ASCII/Latin-1/UTF-8 export::   Exporting to flat files with encoding.
+* Beamer Export::                Producing presentations and slides.
+* HTML Export::                  Exporting to HTML.
+* @LaTeX{} Export::              Exporting to @LaTeX{} and processing to PDF.
+* Markdown Export::              Exporting to Markdown.
+* OpenDocument Text Export::     Exporting to OpenDocument Text.
+* Org Export::                   Exporting to Org.
+* Texinfo Export::               Exporting to Texinfo.
+* iCalendar Export::             Exporting to iCalendar.
+* Other Built-in Back-ends::     Exporting to a man page.
+* Advanced Export Configuration:: Fine-tuning the export output.
+* Export in Foreign Buffers::    Author tables and lists in Org syntax.
+
+Beamer Export
+
+* Beamer export commands::       For creating Beamer documents.
+* Beamer specific export settings:: For customizing Beamer export.
+* Frames and Blocks in Beamer::  For composing Beamer slides.
+* Beamer specific syntax::       For using in Org documents.
+* Editing support::              Editing support.
+* A Beamer example::             A complete presentation.
+
+HTML Export
+
+* HTML export commands::         Invoking HTML export.
+* HTML specific export settings:: Settings for HTML export.
+* HTML doctypes::                Exporting various (X)HTML flavors.
+* HTML preamble and postamble::  Inserting preamble and postamble.
+* Quoting HTML tags::            Using direct HTML in Org files.
+* Headlines in HTML export::     Formatting headlines.
+* Links in HTML export::         Inserting and formatting links.
+* Tables in HTML export::        How to modify the formatting of tables.
+* Images in HTML export::        How to insert figures into HTML output.
+* Math formatting in HTML export:: Beautiful math also on the web.
+* Text areas in HTML export::    An alternate way to show an example.
+* CSS support::                  Changing the appearance of the output.
+* JavaScript support::           Info and folding in a web browser.
+
+@LaTeX{} Export
+
+* @LaTeX{}/PDF export commands:: For producing @LaTeX{} and PDF documents.
+* @LaTeX{} specific export settings:: Unique to this @LaTeX{} back-end.
+* @LaTeX{} header and sectioning:: Setting up the export file structure.
+* Quoting @LaTeX{} code::        Incorporating literal @LaTeX{} code.
+* Tables in @LaTeX{} export::    Options for exporting tables to @LaTeX{}.
+* Images in @LaTeX{} export::    How to insert figures into @LaTeX{} output.
+* Plain lists in @LaTeX{} export:: Attributes specific to lists.
+* Source blocks in @LaTeX{} export:: Attributes specific to source code blocks.
+* Example blocks in @LaTeX{} export:: Attributes specific to example blocks.
+* Special blocks in @LaTeX{} export:: Attributes specific to special blocks.
+* Horizontal rules in @LaTeX{} export:: Attributes specific to horizontal 
rules.
+
+OpenDocument Text Export
+
+* Pre-requisites for ODT export:: Required packages.
+* ODT export commands::          Invoking export.
+* ODT specific export settings:: Configuration options.
+* Extending ODT export::         Producing DOC, PDF files.
+* Applying custom styles::       Styling the output.
+* Links in ODT export::          Handling and formatting links.
+* Tables in ODT export::         Org tables conversions.
+* Images in ODT export::         Inserting images.
+* Math formatting in ODT export:: Formatting @LaTeX{} fragments.
+* Labels and captions in ODT export:: Rendering objects.
+* Literal examples in ODT export:: For source code and example blocks.
+* Advanced topics in ODT export:: For power users.
 
 Math formatting in ODT export
 
-* Working with @LaTeX{} math snippets::  Embedding in @LaTeX{} format.
-* Working with MathML or OpenDocument formula files::  Embedding in native 
format.
-
-Advanced topics in ODT export
-
-* Configuring a document converter::  Registering a document converter.
-* Working with OpenDocument style files::  Exploring internals.
-* Creating one-off styles::     Customizing styles, highlighting.
-* Customizing tables in ODT export::  Defining table templates.
-* Validating OpenDocument XML::  Debugging corrupted OpenDocument files.
-
-Texinfo export
-
-* Texinfo export commands::     Invoking commands.
-* Texinfo specific export settings::  Setting the environment.
-* Texinfo file header::         Generating the header.
-* Texinfo title and copyright page::  Creating preamble pages.
-* Info directory file::     Installing a manual in Info file hierarchy.
-* Headings and sectioning structure::  Building document structure.
-* Indices::                     Creating indices.
-* Quoting Texinfo code::        Incorporating literal Texinfo code.
-* Plain lists in Texinfo export::  List attributes.
-* Tables in Texinfo export::    Table attributes.
-* Images in Texinfo export::    Image attributes.
-* Special blocks in Texinfo export::  Special block attributes.
-* A Texinfo example::           Processing Org to Texinfo.
+* @LaTeX{} math snippets::       Embedding in @LaTeX{} format.
+* MathML and OpenDocument formula files:: Embedding in native format.
+
+Texinfo Export
+
+* Texinfo export commands::      Invoking commands.
+* Texinfo specific export settings:: Setting the environment.
+* Texinfo file header::          Generating the header.
+* Texinfo title and copyright page:: Creating preamble pages.
+* Info directory file::          Installing a manual in Info file hierarchy.
+* Headings and sectioning structure:: Building document structure.
+* Indices::                      Creating indices.
+* Quoting Texinfo code::         Incorporating literal Texinfo code.
+* Plain lists in Texinfo export:: List attributes.
+* Tables in Texinfo export::     Table attributes.
+* Images in Texinfo export::     Image attributes.
+* Quotations in Texinfo export:: Quote block attributes.
+* Special blocks in Texinfo export:: Special block attributes.
+* A Texinfo example::            Processing Org to Texinfo.
 
 Publishing
 
-* Configuration::               Defining projects
-* Uploading files::             How to get files up on the server
-* Sample configuration::        Example projects
-* Triggering publication::      Publication commands
+* Configuration::                Defining projects.
+* Uploading Files::              How to get files up on the server.
+* Sample Configuration::         Example projects.
+* Triggering Publication::       Publication commands.
 
 Configuration
 
-* Project alist::               The central configuration variable
-* Sources and destinations::    From here to there
-* Selecting files::             What files are part of the project?
-* Publishing action::           Setting the function doing the publishing
-* Publishing options::          Tweaking HTML/@LaTeX{} export
-* Publishing links::            Which links keep working after publishing?
-* Sitemap::                     Generating a list of all pages
-* Generating an index::         An index that reaches across pages
-
-Sample configuration
-
-* Simple example::              One-component publishing
-* Complex example::             A multi-component publishing example
-
-Working with source code
-
-* Structure of code blocks::    Code block syntax described
-* Editing source code::         Language major-mode editing
-* Exporting code blocks::       Export contents and/or results
-* Extracting source code::      Create pure source code files
-* Evaluating code blocks::      Place results of evaluation in the Org mode 
buffer
-* Library of Babel::            Use and contribute to a library of useful code 
blocks
-* Languages::                   List of supported code block languages
-* Header arguments::            Configure code block functionality
-* Results of evaluation::       How evaluation results are handled
-* Noweb reference syntax::      Literate programming in Org mode
-* Key bindings and useful functions::  Work quickly with code blocks
-* Batch execution::             Call functions from the command line
-
-Header arguments
-
-* Using header arguments::      Different ways to set header arguments
-* Specific header arguments::   List of header arguments
-
-Using header arguments
-
-* System-wide header arguments::  Set globally, language-specific
-* Language-specific header arguments::  Set in the Org file's headers
-* Header arguments in Org mode properties::  Set in the Org file
-* Language-specific mode properties::
-* Code block specific header arguments::  The most commonly used method
-* Arguments in function calls::  The most specific level, takes highest 
priority
-
-Specific header arguments
-
-* var::                         Pass arguments to @samp{src} code blocks
-* results::                     Specify results type; how to collect
-* file::                        Specify a path for output file
-* file-desc::                   Specify a description for file results
-* file-ext::                    Specify an extension for file output
-* output-dir::                  Specify a directory for output file
-* dir::                         Specify the default directory for code block 
execution
-* exports::                     Specify exporting code, results, both, none
-* tangle::                      Toggle tangling; or specify file name
-* mkdirp::                      Toggle for parent directory creation for 
target files during tangling
-* comments::                    Toggle insertion of comments in tangled code 
files
-* padline::                     Control insertion of padding lines in tangled 
code files
-* no-expand::                   Turn off variable assignment and noweb 
expansion during tangling
-* session::                     Preserve the state of code evaluation
-* noweb::                       Toggle expansion of noweb references
-* noweb-ref::                   Specify block's noweb reference resolution 
target
-* noweb-sep::                   String to separate noweb references
-* cache::                       Avoid re-evaluating unchanged code blocks
-* sep::                         Delimiter for writing tabular results outside 
Org
-* hlines::                      Handle horizontal lines in tables
-* colnames::                    Handle column names in tables
-* rownames::                    Handle row names in tables
-* shebang::                     Make tangled files executable
-* tangle-mode::                 Set permission of tangled files
-* eval::                        Limit evaluation of specific code blocks
-* wrap::                        Mark source block evaluation results
-* post::                        Post processing of results of code block 
evaluation
-* prologue::                    Text to prepend to body of code block
-* epilogue::                    Text to append to body of code block
+* Project alist::                The central configuration variable.
+* Sources and destinations::     From here to there.
+* Selecting files::              What files are part of the project?
+* Publishing action::            Setting the function doing the publishing.
+* Publishing options::           Tweaking HTML/@LaTeX{} export.
+* Publishing links::             Which links keep working after publishing?
+* Site map::                     Generating a list of all pages.
+* Generating an index::          An index that reaches across pages.
+
+Sample Configuration
+
+* Simple example::               One-component publishing.
+* Complex example::              A multi-component publishing example.
+
+Working with Source Code
+
+* Structure of Code Blocks::     Code block syntax described.
+* Using Header Arguments::       Different ways to set header arguments.
+* Environment of a Code Block::  Arguments, sessions, working directory...
+* Evaluating Code Blocks::       Place results of evaluation in the Org buffer.
+* Results of Evaluation::        Choosing a results type, post-processing...
+* Exporting Code Blocks::        Export contents and/or results.
+* Extracting Source Code::       Create pure source code files.
+* Languages::                    List of supported code block languages.
+* Editing Source Code::          Language major-mode editing.
+* Noweb Reference Syntax::       Literate programming in Org mode.
+* Library of Babel::             Use and contribute to a library of useful 
code blocks.
+* Key bindings and Useful Functions:: Work quickly with code blocks.
+* Batch Execution::              Call functions from the command line.
 
 Miscellaneous
 
-* Completion::                  M-@key{TAB} guesses completions
-* Easy templates::              Quick insertion of structural elements
-* Speed keys::                  Electric commands at the beginning of a 
headline
-* Code evaluation security::    Org mode files evaluate inline code
-* Customization::               Adapting Org to changing tastes
-* In-buffer settings::          Overview of the #+KEYWORDS
-* The very busy C-c C-c key::   When in doubt, press C-c C-c
-* Clean view::                  Getting rid of leading stars in the outline
-* TTY keys::                    Using Org on a tty
-* Interaction::                 With other Emacs packages
-* org-crypt::                   Encrypting Org files
-* Org Mobile::                  Viewing and capture on a mobile device
+* Completion::                   @kbd{M-@key{TAB}} guesses completions.
+* Structure Templates::          Quick insertion of structural elements.
+* Speed Keys::                   Electric commands at the beginning of a 
headline.
+* Clean View::                   Getting rid of leading stars in the outline.
+* Dynamic Headline Numbering::   Display and update outline numbering.
+* The Very Busy @kbd{C-c C-c} Key:: When in doubt, press @kbd{C-c C-c}.
+* In-buffer Settings::           Overview of keywords.
+* Org Syntax::                   Formal description of Org's syntax.
+* Documentation Access::         Read documentation about current syntax.
+* Escape Character::
+* Code Evaluation Security::     Org files evaluate in-line code.
+* Interaction::                  With other Emacs packages.
+* TTY Keys::                     Using Org on a tty.
+* Protocols::                    External access to Emacs and Org.
+* Org Crypt::                    Encrypting Org files.
+* Org Mobile::                   Viewing and capture on a mobile device.
+
+Clean View
+
+* Org Indent Mode::
+* Hard indentation::
+
+Interaction
 
-Interaction with other packages
+* Cooperation::                  Packages Org cooperates with.
+* Conflicts::                    Packages that lead to conflicts.
 
-* Cooperation::                 Packages Org cooperates with
-* Conflicts::                   Packages that lead to conflicts
+Protocols
+
+* The @code{store-link} protocol:: Store a link, push URL to kill-ring.
+* The @code{capture} protocol::  Fill a buffer with external information.
+* The @code{open-source} protocol:: Edit published contents.
 
 Org Mobile
 
-* Setting up the staging area::  For the mobile device
-* Pushing to the mobile application::  Uploading Org files and agendas
-* Pulling from the mobile application::  Integrating captured and flagged items
+* Setting up the staging area::  For the mobile device.
+* Pushing to the mobile application:: Uploading Org files and agendas.
+* Pulling from the mobile application:: Integrating captured and flagged items.
 
 Hacking
 
-* Hooks::                       How to reach into Org's internals
-* Add-on packages::             Available extensions
-* Adding hyperlink types::      New custom link types
-* Adding export back-ends::     How to write new export back-ends
-* Context-sensitive commands::  How to add functionality to such commands
-* Tables in arbitrary syntax::  Orgtbl for @LaTeX{} and other programs
-* Dynamic blocks::              Automatically filled blocks
-* Special agenda views::        Customized views
-* Speeding up your agendas::    Tips on how to speed up your agendas
-* Extracting agenda information::  Post-processing of agenda information
-* Using the property API::      Writing programs that use entry properties
-* Using the mapping API::       Mapping over all or selected entries
-
-Tables and lists in arbitrary syntax
-
-* Radio tables::                Sending and receiving radio tables
-* A @LaTeX{} example::          Step by step, almost a tutorial
-* Translator functions::        Copy and modify
-* Radio lists::                 Sending and receiving lists
+* Hooks: Hooks (2).              How to reach into Org's internals.
+* Add-on Packages::              Available extensions.
+* Adding Hyperlink Types::       New custom link types.
+* Adding Export Back-ends::      How to write new export back-ends.
+* Tables in Arbitrary Syntax::   Orgtbl for LaTeX and other programs.
+* Dynamic Blocks::               Automatically filled blocks.
+* Special Agenda Views::         Customized views.
+* Speeding Up Your Agendas::     Tips on how to speed up your agendas.
+* Extracting Agenda Information:: Post-processing agenda information.
+* Using the Property API::       Writing programs that use entry properties.
+* Using the Mapping API::        Mapping over all or selected entries.
+
+Tables in Arbitrary Syntax
+
+* Radio tables::                 Sending and receiving radio tables.
+* A @LaTeX{} example::           Step by step, almost a tutorial.
+* Translator functions::         Copy and modify.
 
 @end detailmenu
 @end menu
 
 @node Introduction
 @chapter Introduction
+
 @cindex introduction
 
 @menu
-* Summary::                     Brief summary of what Org does
-* Installation::                Installing Org
-* Activation::                  How to activate Org for certain buffers
-* Feedback::                    Bug reports, ideas, patches etc.
-* Conventions::                 Typesetting conventions in the manual
+* Summary::                      Brief summary of what Org does.
+* Installation::                 Installing Org.
+* Activation::                   How to activate Org for certain buffers.
+* Feedback::                     Bug reports, ideas, patches, etc.
+* Conventions::                  Typesetting conventions used in this manual.
 @end menu
 
 @node Summary
 @section Summary
+
 @cindex summary
 
-Org is a mode for keeping notes, maintaining TODO lists, and project planning
-with a fast and effective plain-text system.  It also is an authoring system
-with unique support for literate programming and reproducible research.
-
-Org is implemented on top of Outline mode, which makes it possible to keep
-the content of large files well structured.  Visibility cycling and structure
-editing help to work with the tree.  Tables are easily created with a
-built-in table editor.  Plain text URL-like links connect to websites,
-emails, Usenet messages, BBDB entries, and any files related to the projects.
-
-Org develops organizational tasks around notes files that contain lists or
-information about projects as plain text.  Project planning and task
-management makes use of metadata which is part of an outline node.  Based on
-this data, specific entries can be extracted in queries and create dynamic
-@i{agenda views} that also integrate the Emacs calendar and diary.  Org can
-be used to implement many different project planning schemes, such as David
-Allen's GTD system.
-
-Org files can serve as a single source authoring system with export to many
-different formats such as HTML, @LaTeX{}, Open Document, and Markdown.  New
-export backends can be derived from existing ones, or defined from scratch.
-
-Org files can include source code blocks, which makes Org uniquely suited for
-authoring technical documents with code examples.  Org source code blocks are
-fully functional; they can be evaluated in place and their results can be
-captured in the file.  This makes it possible to create a single file
-reproducible research compendium.
-
-Org keeps simple things simple.  When first fired up, it should feel like a
-straightforward, easy to use outliner.  Complexity is not imposed, but a
-large amount of functionality is available when needed.  Org is a toolbox.
-Many users actually run only a (very personal) fraction of Org's capabilities, 
and
-know that there is more whenever they need it.
-
-All of this is achieved with strictly plain text files, the most portable and
-future-proof file format.  Org runs in Emacs.  Emacs is one of the most
-widely ported programs, so that Org mode is available on every major
-platform.
+Org is a mode for keeping notes, maintaining TODO lists, and project
+planning with a fast and effective plain-text markup language.  It
+also is an authoring system with unique support for literate
+programming and reproducible research.
+
+Org is implemented on top of Outline mode, which makes it possible to
+keep the content of large files well structured.  Visibility cycling
+and structure editing help to work with the tree.  Tables are easily
+created with a built-in table editor.  Plain text URL-like links
+connect to websites, emails, Usenet messages, BBDB entries, and any
+files related to the projects.
+
+Org develops organizational tasks around notes files that contain
+lists or information about projects as plain text.  Project planning
+and task management make use of metadata which is part of an outline
+node.  Based on this data, specific entries can be extracted in
+queries and create dynamic @emph{agenda views} that also integrate the
+Emacs calendar and diary.  Org can be used to implement many different
+project planning schemes, such as David Allen's GTD system.
+
+Org files can serve as a single source authoring system with export to
+many different formats such as HTML, @LaTeX{}, Open Document, and
+Markdown.  New export backends can be derived from existing ones, or
+defined from scratch.
+
+Org files can include source code blocks, which makes Org uniquely
+suited for authoring technical documents with code examples. Org
+source code blocks are fully functional; they can be evaluated in
+place and their results can be captured in the file.  This makes it
+possible to create a single file reproducible research compendium.
+
+Org keeps simple things simple.  When first fired up, it should feel
+like a straightforward, easy to use outliner.  Complexity is not
+imposed, but a large amount of functionality is available when needed.
+Org is a toolbox.  Many users actually run only a---very
+personal---fraction of Org's capabilities, and know that there is more
+whenever they need it.
+
+All of this is achieved with strictly plain text files, the most
+portable and future-proof file format.  Org runs in Emacs.  Emacs is
+one of the most widely ported programs, so that Org mode is available
+on every major platform.
 
 @cindex FAQ
-There is a website for Org which provides links to the newest
-version of Org, as well as additional information, frequently asked
-questions (FAQ), links to tutorials, etc.  This page is located at
+There is a website for Org which provides links to the newest version
+of Org, as well as additional information, frequently asked questions
+(FAQ), links to tutorials, etc.  This page is located at
 @uref{https://orgmode.org}.
-@cindex print edition
 
-An earlier version (7.3) of this manual is available as a
-@uref{http://www.network-theory.co.uk/org/manual/, paperback book from
-Network Theory Ltd.}
-
-@page
+@cindex print edition
+An earlier version (7.3) of this manual is available as a 
@uref{http://www.network-theory.co.uk/org/manual/, paperback
+book from Network Theory Ltd.}.
 
 @node Installation
 @section Installation
+
 @cindex installation
 
-Org is part of recent distributions of GNU Emacs, so you normally don't need
-to install it.  If, for one reason or another, you want to install Org on top
-of this pre-packaged version, there are three ways to do it:
+Org is included in all recent distributions of GNU Emacs, so you
+probably do not need to install it.  Most users will simply activate
+Org and begin exploring its many features.
 
-@itemize @bullet
-@item By using Emacs package system.
-@item By downloading Org as an archive.
-@item By using Org's git repository.
+If, for one reason or another, you want to install Org on top of this
+pre-packaged version, there are three ways to do it:
+
+@itemize
+@item
+by using the Emacs package system;
+@item
+by downloading Org as an archive; or
+@item
+by using Org's git repository.
 @end itemize
 
-We @b{strongly recommend} to stick to a single installation method.
+We @strong{strongly recommend} sticking to a single installation method.
 
-@subsubheading Using Emacs packaging system
+@anchor{Using Emacs packaging system}
+@subheading Using Emacs packaging system
 
-Recent Emacs distributions include a packaging system which lets you install
-Elisp libraries.  You can install Org with @kbd{M-x package-install @key{RET}
-org}.
+Recent Emacs distributions include a packaging system which lets you
+install Elisp libraries.  You can install Org with @kbd{M-x package-install 
@key{RET} org}.
 
-@noindent @b{Important}: you need to do this in a session where no @code{.org} 
file has
-been visited, i.e., where no Org built-in function have been loaded.
+@quotation Important
+You need to do this in a session where no @samp{.org} file has been
+visited, i.e., where no Org built-in function have been loaded.
 Otherwise autoload Org functions will mess up the installation.
 
-If you want to use Org's package repository,
-check out the @uref{https://orgmode.org/elpa.html, Org ELPA page}.
+@end quotation
+
+If you want to use Org's package repository, check out the 
@uref{https://orgmode.org/elpa.html, Org ELPA
+page}.
 
-@subsubheading Downloading Org as an archive
+@anchor{Downloading Org as an archive}
+@subheading Downloading Org as an archive
 
-You can download Org latest release from @uref{https://orgmode.org/, Org's
-website}.  In this case, make sure you set the load-path correctly in your
-Emacs init file:
+You can download Org latest release from @uref{https://orgmode.org/, Org's 
website}.  In this case,
+make sure you set the load-path correctly in your Emacs init file:
 
 @lisp
 (add-to-list 'load-path "~/path/to/orgdir/lisp")
 @end lisp
 
-The downloaded archive contains contributed libraries that are not included
-in Emacs.  If you want to use them, add the @file{contrib} directory to your
-load-path:
+The downloaded archive contains contributed libraries that are not
+included in Emacs.  If you want to use them, add the @samp{contrib/}
+directory to your load-path:
 
 @lisp
 (add-to-list 'load-path "~/path/to/orgdir/contrib/lisp" t)
 @end lisp
 
-Optionally, you can compile the files and/or install them in your system.
-Run @code{make help} to list compilation and installation options.
+Optionally, you can compile the files and/or install them in your
+system.  Run @samp{make help} to list compilation and installation options.
 
-@subsubheading Using Org's git repository
+@anchor{Using Org's git repository}
+@subheading Using Org's git repository
 
 You can clone Org's repository and install Org like this:
 
 @example
 $ cd ~/src/
-$ git clone https://code.orgmode.org/bzg/org-mode.git
+$ git clone git@@code.orgmode.org:bzg/org-mode.git
 $ cd org-mode/
 $ make autoloads
 @end example
 
-Note that in this case, @code{make autoloads} is mandatory: it defines Org's
-version in @file{org-version.el} and Org's autoloads in
-@file{org-loaddefs.el}.
+Note that in this case, @samp{make autoloads} is mandatory: it defines
+Org's version in @samp{org-version.el} and Org's autoloads in
+@samp{org-loaddefs.el}.
 
-Remember to add the correct load-path as described in the method above.
+Remember to add the correct load-path as described in the method
+above.
 
-You can also compile with @code{make}, generate the documentation with
-@code{make doc}, create a local configuration with @code{make config} and
-install Org with @code{make install}.  Please run @code{make help} to get
-the list of compilation/installation options.
+You can also compile with @samp{make}, generate the documentation with
+@samp{make doc}, create a local configuration with @samp{make config} and
+install Org with @samp{make install}.  Please run @samp{make help} to get the
+list of compilation/installation options.
 
-For more detailed explanations on Org's build system, please check the Org
-Build System page on @uref{https://orgmode.org/worg/dev/org-build-system.html,
-Worg}.
+For more detailed explanations on Org's build system, please check the
+Org Build System page on 
@uref{https://orgmode.org/worg/dev/org-build-system.html, Worg}.
 
 @node Activation
 @section Activation
+
 @cindex activation
 @cindex autoload
 @cindex ELPA
 @cindex global key bindings
 @cindex key bindings, global
-@findex org-agenda
-@findex org-capture
-@findex org-store-link
-@findex org-switchb
 
-Org mode buffers need font-lock to be turned on: this is the default in
-Emacs@footnote{If you don't use font-lock globally, turn it on in Org buffer
-with @code{(add-hook 'org-mode-hook 'turn-on-font-lock)}}.
+Org mode buffers need Font Lock to be turned on: this is the default
+in Emacs@footnote{If you do not use Font Lock globally turn it on in Org buffer
+with @samp{(add-hook 'org-mode-hook 'turn-on-font-lock)}.}.
 
 There are compatibility issues between Org mode and some other Elisp
-packages, please take the time to check the list (@pxref{Conflicts}).
+packages (see @ref{Conflicts}).  Please take the
+time to check the list.
+
+@findex org-agenda
+@findex org-capture
+@findex org-store-link
+For a better experience, the three Org commands @code{org-store-link},
+@code{org-capture} and @code{org-agenda} ought to be accessible anywhere in
+Emacs, not just in Org buffers.  To that effect, you need to bind them
+to globally available keys, like the ones reserved for users (see
+@ref{Key Binding Conventions,,,elisp,}).  Here are suggested bindings,
+please modify the keys to your own liking.
 
-The four Org commands @command{org-store-link}, @command{org-capture},
-@command{org-agenda}, and @command{org-switchb} should be accessible through
-global keys (i.e., anywhere in Emacs, not just in Org buffers).  Here are
-suggested bindings for these keys, please modify the keys to your own
-liking.
 @lisp
-(global-set-key "\C-cl" 'org-store-link)
-(global-set-key "\C-ca" 'org-agenda)
-(global-set-key "\C-cc" 'org-capture)
-(global-set-key "\C-cb" 'org-switchb)
+(global-set-key (kbd "C-c l") 'org-store-link)
+(global-set-key (kbd "C-c a") 'org-agenda)
+(global-set-key (kbd "C-c c") 'org-capture)
 @end lisp
 
 @cindex Org mode, turning on
-Files with the @file{.org} extension use Org mode by default.  To turn on Org
-mode in a file that does not have the extension @file{.org}, make the first
-line of a file look like this:
+Files with the @samp{.org} extension use Org mode by default.  To turn on
+Org mode in a file that does not have the extension @samp{.org}, make the
+first line of a file look like this:
 
 @example
 MY PROJECTS    -*- mode: org; -*-
 @end example
 
+
 @vindex org-insert-mode-line-in-empty-file
-@noindent which will select Org mode for this buffer no matter what
-the file's name is.  See also the variable
-@code{org-insert-mode-line-in-empty-file}.
+@noindent
+which selects Org mode for this buffer no matter what the file's name
+is.  See also the variable @code{org-insert-mode-line-in-empty-file}.
 
-Many commands in Org work on the region if the region is @i{active}.  To make
-use of this, you need to have @code{transient-mark-mode} turned on, which is
-the default.  If you do not like @code{transient-mark-mode}, you can create
-an active region by using the mouse to select a region, or pressing
-@kbd{C-@key{SPC}} twice before moving the cursor.
+Many commands in Org work on the region if the region is @emph{active}.  To
+make use of this, you need to have Transient Mark mode turned on,
+which is the default.  If you do not like it, you can create an active
+region by using the mouse to select a region, or pressing
+@kbd{C-@key{SPC}} twice before moving point.
 
 @node Feedback
 @section Feedback
+
 @cindex feedback
 @cindex bug reports
+@cindex reporting a bug
 @cindex maintainer
 @cindex author
 
-If you find problems with Org, or if you have questions, remarks, or ideas
-about it, please mail to the Org mailing list @email{emacs-orgmode@@gnu.org}.
-You can subscribe to the list
-@uref{https://lists.gnu.org/mailman/listinfo/emacs-orgmode, on this web page}.
-If you are not a member of the mailing list, your mail will be passed to the
-list after a moderator has approved it@footnote{Please consider subscribing
-to the mailing list, in order to minimize the work the mailing list
-moderators have to do.}.
+If you find problems with Org, or if you have questions, remarks, or
+ideas about it, please send an email to the Org mailing list
+@email{emacs-orgmode@@gnu.org}.  You can subscribe to the list 
@uref{https://lists.gnu.org/mailman/listinfo/emacs-orgmode, from this
+web page}.  If you are not a member of the mailing list, your mail will
+be passed to the list after a moderator has approved it@footnote{Please 
consider subscribing to the mailing list in order to
+minimize the work the mailing list moderators have to do.}.
 
+@findex org-version
+@findex org-submit-bug-report
 For bug reports, please first try to reproduce the bug with the latest
-version of Org available---if you are running an outdated version, it is
-quite possible that the bug has been fixed already.  If the bug persists,
-prepare a report and provide as much information as possible, including the
-version information of Emacs (@kbd{M-x emacs-version @key{RET}}) and Org
-(@kbd{M-x org-version @key{RET}}), as well as the Org related setup in the
-Emacs init file.  The easiest way to do this is to use the command
+version of Org available---if you are running an outdated version, it
+is quite possible that the bug has been fixed already.  If the bug
+persists, prepare a report and provide as much information as
+possible, including the version information of Emacs (@kbd{M-x emacs-version}) 
and Org (@kbd{M-x org-version}), as well as
+the Org related setup in the Emacs init file.  The easiest way to do
+this is to use the command
+
 @example
-@kbd{M-x org-submit-bug-report @key{RET}}
+M-x org-submit-bug-report <RET>
 @end example
-@noindent which will put all this information into an Emacs mail buffer so
-that you only need to add your description.  If you are not sending the Email
-from within Emacs, please copy and paste the content into your Email program.
 
-Sometimes you might face a problem due to an error in your Emacs or Org mode
-setup.  Before reporting a bug, it is very helpful to start Emacs with minimal
-customizations and reproduce the problem.  Doing so often helps you determine
-if the problem is with your customization or with Org mode itself.  You can
-start a typical minimal session with a command like the example below.
+
+@noindent
+which puts all this information into an Emacs mail buffer so that you
+only need to add your description.  If you are not sending the Email
+from within Emacs, please copy and paste the content into your Email
+program.
+
+Sometimes you might face a problem due to an error in your Emacs or
+Org mode setup.  Before reporting a bug, it is very helpful to start
+Emacs with minimal customizations and reproduce the problem.  Doing so
+often helps you determine if the problem is with your customization or
+with Org mode itself.  You can start a typical minimal session with
+a command like the example below.
 
 @example
 $ emacs -Q -l /path/to/minimal-org.el
 @end example
 
-However if you are using Org mode as distributed with Emacs, a minimal setup
-is not necessary.  In that case it is sufficient to start Emacs as
-@code{emacs -Q}.  The @code{minimal-org.el} setup file can have contents as
+
+However if you are using Org mode as distributed with Emacs, a minimal
+setup is not necessary.  In that case it is sufficient to start Emacs
+as @samp{emacs -Q}.  The @samp{minimal-org.el} setup file can have contents as
 shown below.
 
 @lisp
-;;; Minimal setup to load latest 'org-mode'
+;;; Minimal setup to load latest `org-mode'.
 
-;; activate debugging
+;; Activate debugging.
 (setq debug-on-error t
       debug-on-signal nil
       debug-on-quit nil)
 
-;; add latest org-mode to load path
-(add-to-list 'load-path "/path/to/org-mode/lisp")
-(add-to-list 'load-path "/path/to/org-mode/contrib/lisp" t)
+;; Add latest Org mode to load path.
+(add-to-list 'load-path (expand-file-name "/path/to/org-mode/lisp"))
+(add-to-list 'load-path (expand-file-name "/path/to/org-mode/contrib/lisp" t))
 @end lisp
 
-If an error occurs, a backtrace can be very useful (see below on how to
-create one).  Often a small example file helps, along with clear information
-about:
+If an error occurs, a ``backtrace'' can be very useful---see below on
+how to create one.  Often a small example file helps, along with clear
+information about:
 
 @enumerate
-@item What exactly did you do?
-@item What did you expect to happen?
-@item What happened instead?
+@item
+What exactly did you do?
+@item
+What did you expect to happen?
+@item
+What happened instead?
 @end enumerate
-@noindent Thank you for helping to improve this program.
 
-@subsubheading How to create a useful backtrace
+Thank you for helping to improve this program.
+
+@anchor{How to create a useful backtrace}
+@subheading How to create a useful backtrace
 
 @cindex backtrace of an error
-If working with Org produces an error with a message you don't
+If working with Org produces an error with a message you do not
 understand, you may have hit a bug.  The best way to report this is by
-providing, in addition to what was mentioned above, a @emph{backtrace}.
-This is information from the built-in debugger about where and how the
+providing, in addition to what was mentioned above, a backtrace.  This
+is information from the built-in debugger about where and how the
 error occurred.  Here is how to produce a useful backtrace:
 
 @enumerate
 @item
-Reload uncompiled versions of all Org mode Lisp files.  The backtrace
-contains much more information if it is produced with uncompiled code.
-To do this, use
+Reload uncompiled versions of all Org mode Lisp files.  The
+backtrace contains much more information if it is produced with
+uncompiled code.  To do this, use
+
 @example
-@kbd{C-u M-x org-reload @key{RET}}
+C-u M-x org-reload <RET>
 @end example
+
+
 @noindent
-or select @code{Org -> Refresh/Reload -> Reload Org uncompiled} from the
-menu.
+or, from the menu: Org @arrow{} Refresh/Reload @arrow{} Reload Org uncompiled.
+
 @item
-Go to the @code{Options} menu and select @code{Enter Debugger on Error}.
+Then, activate the debugger:
+
+@example
+M-x toggle-debug-or-error <RET>
+@end example
+
+
+@noindent
+or, from the menu: Options @arrow{} Enter Debugger on Error.
+
 @item
-Do whatever you have to do to hit the error.  Don't forget to
+Do whatever you have to do to hit the error.  Do not forget to
 document the steps you take.
+
 @item
-When you hit the error, a @file{*Backtrace*} buffer will appear on the
-screen.  Save this buffer to a file (for example using @kbd{C-x C-w}) and
-attach it to your bug report.
+When you hit the error, a @samp{*Backtrace*} buffer appears on the
+screen.  Save this buffer to a file---for example using @kbd{C-x C-w}---and 
attach it to your bug report.
 @end enumerate
 
 @node Conventions
-@section Typesetting conventions used in this manual
+@section Typesetting Conventions Used in this Manual
+
 
-@subsubheading TODO keywords, tags, properties, etc.
 
-Org mainly uses three types of keywords: TODO keywords, tags and property
-names.  In this manual we use the following conventions:
+@anchor{TODO keywords tags properties etc}
+@subheading TODO keywords, tags, properties, etc.
 
-@table @code
-@item TODO
-@itemx WAITING
+Org uses various syntactical elements: TODO keywords, tags, property
+names, keywords, blocks, etc.  In this manual we use the following
+conventions:
+
+@table @asis
+@item @samp{TODO}
+@itemx @samp{WAITING}
 TODO keywords are written with all capitals, even if they are
 user-defined.
-@item boss
-@itemx ARCHIVE
-User-defined tags are written in lowercase; built-in tags with special
-meaning are written with all capitals.
-@item Release
-@itemx PRIORITY
+
+@item @samp{boss}
+@itemx @samp{ARCHIVE}
+Tags are case-sensitive.  User-defined tags are written in
+lowercase; built-in tags with special meaning are written as they
+should appear in the document, usually with all capitals.
+
+@item @samp{Release}
+@itemx @samp{PRIORITY}
 User-defined properties are capitalized; built-in properties with
 special meaning are written with all capitals.
+
+@item @samp{TITLE}
+@itemx @samp{BEGIN} @dots{} @samp{END}
+Keywords and blocks are written in uppercase to enhance their
+readability, but you can use lowercase in your Org files.
 @end table
 
-Moreover, Org uses @i{option keywords} (like @code{#+TITLE} to set the title)
-and @i{environment keywords} (like @code{#+BEGIN_EXPORT html} to start
-a @code{HTML} environment).  They are written in uppercase in the manual to
-enhance its readability, but you can use lowercase in your Org file.
+@anchor{Key bindings and commands}
+@subheading Key bindings and commands
 
-@subsubheading Key bindings and commands
-@kindex C-c a
-@findex org-agenda
-@kindex C-c c
-@findex org-capture
+The manual lists both the keys and the corresponding commands for
+accessing a functionality.  Org mode often uses the same key for
+different functions, depending on context.  The command that is bound
+to such keys has a generic name, like @code{org-metaright}.  In the manual
+we will, wherever possible, give the function that is internally
+called by the generic command.  For example, in the chapter on
+document structure, @kbd{M-@key{RIGHT}} will be listed to call
+@code{org-do-demote}, while in the chapter on tables, it will be listed to
+call @code{org-table-move-column-right}.
+
+@node Document Structure
+@chapter Document Structure
 
-The manual suggests a few global key bindings, in particular @kbd{C-c a} for
-@code{org-agenda} and @kbd{C-c c} for @code{org-capture}.  These are only
-suggestions, but the rest of the manual assumes that these key bindings are in
-place in order to list commands by key access.
-
-Also, the manual lists both the keys and the corresponding commands for
-accessing a functionality.  Org mode often uses the same key for different
-functions, depending on context.  The command that is bound to such keys has
-a generic name, like @code{org-metaright}.  In the manual we will, wherever
-possible, give the function that is internally called by the generic command.
-For example, in the chapter on document structure, @kbd{M-@key{RIGHT}} will
-be listed to call @code{org-do-demote}, while in the chapter on tables, it
-will be listed to call @code{org-table-move-column-right}.  If you prefer,
-you can compile the manual without the command names by unsetting the flag
-@code{cmdnames} in @file{org.texi}.
-
-@node Document structure
-@chapter Document structure
 @cindex document structure
 @cindex structure of document
-
-Org is based on Outline mode and provides flexible commands to
-edit the structure of the document.
+Org is an outliner.  Outlines allow a document to be organized in
+a hierarchical structure, which, least for me, is the best
+representation of notes and thoughts.  An overview of this structure
+is achieved by folding, i.e., hiding large parts of the document to
+show only the general document structure and the parts currently being
+worked on.  Org greatly simplifies the use of outlines by compressing
+the entire show and hide functionalities into a single command,
+@code{org-cycle}, which is bound to the @kbd{@key{TAB}} key.
 
 @menu
-* Outlines::                    Org is based on Outline mode
-* Headlines::                   How to typeset Org tree headlines
-* Visibility cycling::          Show and hide, much simplified
-* Motion::                      Jumping to other headlines
-* Structure editing::           Changing sequence and level of headlines
-* Sparse trees::                Matches embedded in context
-* Plain lists::                 Additional structure within an entry
-* Drawers::                     Tucking stuff away
-* Blocks::                      Folding blocks
-* Footnotes::                   How footnotes are defined in Org's syntax
-* Orgstruct mode::              Structure editing outside Org
-* Org syntax::                  Formal description of Org's syntax
+* Headlines::                    How to typeset Org tree headlines.
+* Visibility Cycling::           Show and hide, much simplified.
+* Motion::                       Jumping to other headlines.
+* Structure Editing::            Changing sequence and level of headlines.
+* Sparse Trees::                 Matches embedded in context.
+* Plain Lists::                  Additional structure within an entry.
+* Drawers::                      Tucking stuff away.
+* Blocks::                       Folding blocks.
 @end menu
 
-@node Outlines
-@section Outlines
-@cindex outlines
-@cindex Outline mode
-
-Org is implemented on top of Outline mode.  Outlines allow a
-document to be organized in a hierarchical structure, which (at least
-for me) is the best representation of notes and thoughts.  An overview
-of this structure is achieved by folding (hiding) large parts of the
-document to show only the general document structure and the parts
-currently being worked on.  Org greatly simplifies the use of
-outlines by compressing the entire show/hide functionality into a single
-command, @command{org-cycle}, which is bound to the @key{TAB} key.
-
 @node Headlines
 @section Headlines
+
 @cindex headlines
 @cindex outline tree
 @vindex org-special-ctrl-a/e
 @vindex org-special-ctrl-k
 @vindex org-ctrl-k-protect-subtree
 
-Headlines define the structure of an outline tree.  The headlines in Org
-start with one or more stars, on the left margin@footnote{See the variables
-@code{org-special-ctrl-a/e}, @code{org-special-ctrl-k}, and
-@code{org-ctrl-k-protect-subtree} to configure special behavior of @kbd{C-a},
-@kbd{C-e}, and @kbd{C-k} in headlines.} @footnote{Clocking only works with
-headings indented less than 30 stars.}.  For example:
+Headlines define the structure of an outline tree.  The headlines in
+Org start with one or more stars, on the left margin@footnote{See the 
variables @code{org-special-ctrl-a/e}, @code{org-special-ctrl-k},
+and @code{org-ctrl-k-protect-subtree} to configure special behavior of
+@kbd{C-a}, @kbd{C-e}, and @kbd{C-k} in headlines.  Note
+also that clocking only works with headings indented less than 30
+stars.}.  For
+example:
 
 @example
 * Top level headline
 ** Second level
-*** 3rd level
+*** Third level
     some text
-*** 3rd level
+*** Third level
     more text
-
 * Another top level headline
 @end example
 
 @vindex org-footnote-section
-@noindent Note that a headline named after @code{org-footnote-section},
-which defaults to @samp{Footnotes}, is considered as special.  A subtree with
-this headline will be silently ignored by exporting functions.
+The name defined in @code{org-footnote-section} is reserved.  Do not use it
+as a title for your own headings.
 
-Some people find the many stars too noisy and would prefer an
-outline that has whitespace followed by a single star as headline
-starters.  @ref{Clean view}, describes a setup to realize this.
+Some people find the many stars too noisy and would prefer an outline
+that has whitespace followed by a single star as headline starters.
+This can be achieved using a Org Indent minor mode.  See @ref{Clean View} for 
more information.
+
+Headlines are not numbered.  However, you may want to dynamically
+number some, or all, of them.  See @ref{Dynamic Headline Numbering}.
 
 @vindex org-cycle-separator-lines
 An empty line after the end of a subtree is considered part of it and
-will be hidden when the subtree is folded.  However, if you leave at
-least two empty lines, one empty line will remain visible after folding
-the subtree, in order to structure the collapsed view.  See the
-variable @code{org-cycle-separator-lines} to modify this behavior.
+is hidden when the subtree is folded.  However, if you leave at least
+two empty lines, one empty line remains visible after folding the
+subtree, in order to structure the collapsed view.  See the variable
+@code{org-cycle-separator-lines} to modify this behavior.
+
+@node Visibility Cycling
+@section Visibility Cycling
 
-@node Visibility cycling
-@section Visibility cycling
 @cindex cycling, visibility
 @cindex visibility cycling
 @cindex trees, visibility
@@ -1230,25 +971,28 @@ variable @code{org-cycle-separator-lines} to modify this 
behavior.
 @cindex hide text
 
 @menu
-* Global and local cycling::    Cycling through various visibility states
-* Initial visibility::          Setting the initial visibility state
-* Catching invisible edits::    Preventing mistakes when editing invisible 
parts
+* Global and local cycling::     Cycling through various visibility states.
+* Initial visibility::           Setting the initial visibility state.
+* Catching invisible edits::     Preventing mistakes when editing invisible 
parts.
 @end menu
 
 @node Global and local cycling
 @subsection Global and local cycling
 
-Outlines make it possible to hide parts of the text in the buffer.
-Org uses just two commands, bound to @key{TAB} and
-@kbd{S-@key{TAB}} to change the visibility in the buffer.
-
 @cindex subtree visibility states
 @cindex subtree cycling
 @cindex folded, subtree visibility state
 @cindex children, subtree visibility state
 @cindex subtree, subtree visibility state
+
+Outlines make it possible to hide parts of the text in the buffer.
+Org uses just two commands, bound to @kbd{@key{TAB}} and
+@kbd{S-@key{TAB}} to change the visibility in the buffer.
+
 @table @asis
-@orgcmd{@key{TAB},org-cycle}
+@item @kbd{@key{TAB}} (@code{org-cycle})
+@kindex TAB
+@findex org-cycle
 @emph{Subtree cycling}: Rotate current subtree among the states
 
 @example
@@ -1257,16 +1001,18 @@ Org uses just two commands, bound to @key{TAB} and
 @end example
 
 @vindex org-cycle-emulate-tab
-The cursor must be on a headline for this to work@footnote{see, however,
-the option @code{org-cycle-emulate-tab}.}.
+Point must be on a headline for this to work@footnote{See, however, the option 
@code{org-cycle-emulate-tab}.}.
 
+@item @kbd{S-@key{TAB}} (@code{org-global-cycle})
+@itemx @kbd{C-u @key{TAB}}
 @cindex global visibility states
 @cindex global cycling
 @cindex overview, global visibility state
 @cindex contents, global visibility state
 @cindex show all, global visibility state
-@orgcmd{S-@key{TAB},org-global-cycle}
-@itemx C-u @key{TAB}
+@kindex C-u TAB
+@kindex S-TAB
+@findex org-global-cycle
 @emph{Global cycling}: Rotate the entire buffer among the states
 
 @example
@@ -1274,67 +1020,84 @@ the option @code{org-cycle-emulate-tab}.}.
 '--------------------------------------'
 @end example
 
-When @kbd{S-@key{TAB}} is called with a numeric prefix argument N, the
-CONTENTS view up to headlines of level N will be shown.  Note that inside
-tables, @kbd{S-@key{TAB}} jumps to the previous field.
+When @kbd{S-@key{TAB}} is called with a numeric prefix argument N,
+the CONTENTS view up to headlines of level N are shown.  Note that
+inside tables (see @ref{Tables}), @kbd{S-@key{TAB}} jumps to the previous
+field instead.
 
 @vindex org-cycle-global-at-bob
-You can run global cycling using @key{TAB} only if point is at the very
-beginning of the buffer, but not on a headline, and
+You can run global cycling using @kbd{@key{TAB}} only if point is at
+the very beginning of the buffer, but not on a headline, and
 @code{org-cycle-global-at-bob} is set to a non-@code{nil} value.
 
-@cindex set startup visibility, command
-@orgcmd{C-u C-u @key{TAB},org-set-startup-visibility}
-Switch back to the startup visibility of the buffer (@pxref{Initial 
visibility}).
+@item @kbd{C-u C-u @key{TAB}} (@code{org-set-startup-visibility})
+@cindex startup visibility
+@kindex C-u C-u TAB
+@findex org-set-startup-visibility
+Switch back to the startup visibility of the buffer (see @ref{Initial 
visibility}).
+
+@item @kbd{C-u C-u C-u @key{TAB}} (@code{outline-show-all})
 @cindex show all, command
-@orgcmd{C-u C-u C-u @key{TAB},outline-show-all}
+@kindex C-u C-u C-u TAB
+@findex outline-show-all
 Show all, including drawers.
+
+@item @kbd{C-c C-r} (@code{org-reveal})
 @cindex revealing context
-@orgcmd{C-c C-r,org-reveal}
-Reveal context around point, showing the current entry, the following heading
-and the hierarchy above.  Useful for working near a location that has been
-exposed by a sparse tree command (@pxref{Sparse trees}) or an agenda command
-(@pxref{Agenda commands}).  With a prefix argument show, on each
-level, all sibling headings.  With a double prefix argument, also show the
-entire subtree of the parent.
+@kindex C-c C-r
+@findex org-reveal
+Reveal context around point, showing the current entry, the
+following heading and the hierarchy above.  Useful for working near
+a location that has been exposed by a sparse tree command (see
+@ref{Sparse Trees}) or an agenda command (see @ref{Agenda Commands}).  With a 
prefix argument show, on each level, all sibling
+headings.  With a double prefix argument, also show the entire
+subtree of the parent.
+
+@item @kbd{C-c C-k} (@code{outline-show-branches})
 @cindex show branches, command
-@orgcmd{C-c C-k,outline-show-branches}
-Expose all the headings of the subtree, CONTENTS view for just one subtree.
+@kindex C-c C-k
+@findex outline-show-branches
+Expose all the headings of the subtree, CONTENTS view for just one
+subtree.
+
+@item @kbd{C-c @key{TAB}} (@code{outline-show-children})
 @cindex show children, command
-@orgcmd{C-c @key{TAB},outline-show-children}
-Expose all direct children of the subtree.  With a numeric prefix argument N,
-expose all children down to level N@.
-@orgcmd{C-c C-x b,org-tree-to-indirect-buffer}
-Show the current subtree in an indirect buffer@footnote{The indirect buffer
-(@pxref{Indirect Buffers,,,emacs,GNU Emacs Manual}) will contain the entire
-buffer, but will be narrowed to the current tree.  Editing the indirect
-buffer will also change the original buffer, but without affecting visibility
-in that buffer.}.  With a numeric prefix argument N, go up to level N and
-then take that tree.  If N is negative then go up that many levels.  With
-a @kbd{C-u} prefix, do not remove the previously used indirect buffer.
-@orgcmd{C-c C-x v,org-copy-visible}
-Copy the @i{visible} text in the region into the kill ring.
+@kindex C-c TAB
+@findex outline-show-children
+Expose all direct children of the subtree.  With a numeric prefix
+argument N, expose all children down to level N@.
+
+@item @kbd{C-c C-x b} (@code{org-tree-to-indirect-buffer})
+@kindex C-c C-x b
+@findex org-tree-to-indirect-buffer
+Show the current subtree in an indirect buffer@footnote{The indirect buffer 
contains the entire buffer, but is narrowed
+to the current tree.  Editing the indirect buffer also changes the
+original buffer, but without affecting visibility in that buffer.  For
+more information about indirect buffers, see @ref{Indirect Buffers,GNU Emacs 
Manual,,emacs,}.}.  With
+a numeric prefix argument, N, go up to level N and then take that
+tree.  If N is negative then go up that many levels.  With
+a @kbd{C-u} prefix, do not remove the previously used indirect
+buffer.
+
+@item @kbd{C-c C-x v} (@code{org-copy-visible})
+@kindex C-c C-x v
+@findex org-copy-visible
+Copy the @emph{visible} text in the region into the kill ring.
 @end table
 
 @node Initial visibility
 @subsection Initial visibility
 
-@cindex visibility, initialize
 @vindex org-startup-folded
-@vindex org-agenda-inhibit-startup
-@cindex @code{overview}, STARTUP keyword
-@cindex @code{content}, STARTUP keyword
-@cindex @code{showall}, STARTUP keyword
-@cindex @code{showeverything}, STARTUP keyword
-
-When Emacs first visits an Org file, the global state is set to OVERVIEW,
-i.e., only the top level headlines are visible@footnote{When
-@code{org-agenda-inhibit-startup} is non-@code{nil}, Org will not honor the 
default
-visibility state when first opening a file for the agenda (@pxref{Speeding up
-your agendas}).}.  This can be configured through the variable
-@code{org-startup-folded}, or on a per-file basis by adding one of the
-following lines anywhere in the buffer:
+When Emacs first visits an Org file, the global state is set to
+OVERVIEW, i.e., only the top level headlines are visible@footnote{When 
@code{org-agenda-inhibit-startup} is non-@code{nil}, Org does not
+honor the default visibility state when first opening a file for the
+agenda (see @ref{Speeding Up Your Agendas}).}.  This
+can be configured through the variable @code{org-startup-folded}, or on
+a per-file basis by adding one of the following lines anywhere in the
+buffer:
 
+@cindex @samp{STARTUP}, keyword
 @example
 #+STARTUP: overview
 #+STARTUP: content
@@ -1342,73 +1105,109 @@ following lines anywhere in the buffer:
 #+STARTUP: showeverything
 @end example
 
-@cindex property, @code{VISIBILITY}
-@noindent
-Furthermore, any entries with a @code{VISIBILITY} property (@pxref{Properties
-and columns}) will get their visibility adapted accordingly.  Allowed values
-for this property are @code{folded}, @code{children}, @code{content}, and
-@code{all}.
+@cindex @samp{VISIBILITY}, property
+Furthermore, any entries with a @samp{VISIBILITY} property (see 
@ref{Properties and Columns}) get their visibility adapted accordingly.  
Allowed values
+for this property are @samp{folded}, @samp{children}, @samp{content}, and 
@samp{all}.
 
 @table @asis
-@orgcmd{C-u C-u @key{TAB},org-set-startup-visibility}
-Switch back to the startup visibility of the buffer, i.e., whatever is
-requested by startup options and @code{VISIBILITY} properties in individual
-entries.
+@item @kbd{C-u C-u @key{TAB}} (@code{org-set-startup-visibility})
+@kindex C-u C-u TAB
+@findex org-set-startup-visibility
+Switch back to the startup visibility of the buffer, i.e., whatever
+is requested by startup options and @samp{VISIBILITY} properties in
+individual entries.
 @end table
 
 @node Catching invisible edits
 @subsection Catching invisible edits
 
-@vindex org-catch-invisible-edits
 @cindex edits, catching invisible
-Sometimes you may inadvertently edit an invisible part of the buffer and be
-confused on what has been edited and how to undo the mistake.  Setting
-@code{org-catch-invisible-edits} to non-@code{nil} will help prevent this.  
See the
-docstring of this option on how Org should catch invisible edits and process
-them.
+
+@vindex org-catch-invisible-edits
+Sometimes you may inadvertently edit an invisible part of the buffer
+and be confused on what has been edited and how to undo the mistake.
+Setting @code{org-catch-invisible-edits} to non-@code{nil} helps preventing
+this.  See the docstring of this option on how Org should catch
+invisible edits and process them.
 
 @node Motion
 @section Motion
+
 @cindex motion, between headlines
 @cindex jumping, to headlines
 @cindex headline navigation
+
 The following commands jump to other headlines in the buffer.
 
 @table @asis
-@orgcmd{C-c C-n,org-next-visible-heading}
+@item @kbd{C-c C-n} (@code{org-next-visible-heading})
+@kindex C-c C-n
+@findex org-next-visible-heading
 Next heading.
-@orgcmd{C-c C-p,org-previous-visible-heading}
+
+@item @kbd{C-c C-p} (@code{org-previous-visible-heading})
+@kindex C-c C-p
+@findex org-previous-visible-heading
 Previous heading.
-@orgcmd{C-c C-f,org-forward-same-level}
+
+@item @kbd{C-c C-f} (@code{org-forward-heading-same-level})
+@kindex C-c C-f
+@findex org-forward-heading-same-level
 Next heading same level.
-@orgcmd{C-c C-b,org-backward-same-level}
+
+@item @kbd{C-c C-b} (@code{org-backward-heading-same-level})
+@kindex C-c C-b
+@findex org-backward-heading-same-level
 Previous heading same level.
-@orgcmd{C-c C-u,outline-up-heading}
+
+@item @kbd{C-c C-u} (@code{outline-up-heading})
+@kindex C-c C-u
+@findex outline-up-heading
 Backward to higher level heading.
-@orgcmd{C-c C-j,org-goto}
-Jump to a different place without changing the current outline
-visibility.  Shows the document structure in a temporary buffer, where
-you can use the following keys to find your destination:
+
+@item @kbd{C-c C-j} (@code{org-goto})
+@kindex C-c C-j
+@findex org-goto
 @vindex org-goto-auto-isearch
-@example
-@key{TAB}         @r{Cycle visibility.}
-@key{DOWN} / @key{UP}   @r{Next/previous visible headline.}
-@key{RET}         @r{Select this location.}
-@kbd{/}           @r{Do a Sparse-tree search}
-@r{The following keys work if you turn off @code{org-goto-auto-isearch}}
-n / p        @r{Next/previous visible headline.}
-f / b        @r{Next/previous headline same level.}
-u            @r{One level up.}
-0-9          @r{Digit argument.}
-q            @r{Quit}
-@end example
+Jump to a different place without changing the current outline
+visibility.  Shows the document structure in a temporary buffer,
+where you can use the following keys to find your destination:
+
+@multitable @columnfractions 0.3 0.7
+@item @kbd{@key{TAB}}
+@tab Cycle visibility.
+@item @kbd{@key{DOWN}} / @kbd{@key{UP}}
+@tab Next/previous visible headline.
+@item @kbd{@key{RET}}
+@tab Select this location.
+@item @kbd{/}
+@tab Do a Sparse-tree search
+@end multitable
+
+@noindent
+The following keys work if you turn off @code{org-goto-auto-isearch}
+
+@multitable @columnfractions 0.3 0.7
+@item @kbd{n} / @kbd{p}
+@tab Next/previous visible headline.
+@item @kbd{f} / @kbd{b}
+@tab Next/previous headline same level.
+@item @kbd{u}
+@tab One level up.
+@item @kbd{0} @dots{} @kbd{9}
+@tab Digit argument.
+@item @kbd{q}
+@tab Quit.
+@end multitable
+
 @vindex org-goto-interface
 @noindent
-See also the option @code{org-goto-interface}.
+See also the variable @code{org-goto-interface}.
 @end table
 
-@node Structure editing
-@section Structure editing
+@node Structure Editing
+@section Structure Editing
+
 @cindex structure editing
 @cindex headline, promotion and demotion
 @cindex promotion, of subtrees
@@ -1421,130 +1220,196 @@ See also the option @code{org-goto-interface}.
 @cindex subtrees, cut and paste
 
 @table @asis
-@orgcmd{M-@key{RET},org-meta-return}
+@item @kbd{M-@key{RET}} (@code{org-meta-return})
+@kindex M-RET
+@findex org-meta-return
 @vindex org-M-RET-may-split-line
 Insert a new heading, item or row.
 
 If the command is used at the @emph{beginning} of a line, and if there is
-a heading or a plain list item (@pxref{Plain lists}) at point, the new
+a heading or a plain list item (see @ref{Plain Lists}) at point, the new
 heading/item is created @emph{before} the current line.  When used at the
 beginning of a regular line of text, turn that line into a heading.
 
-When this command is used in the middle of a line, the line is split and the
-rest of the line becomes the new item or headline.  If you do not want the
-line to be split, customize @code{org-M-RET-may-split-line}.
+When this command is used in the middle of a line, the line is split
+and the rest of the line becomes the new item or headline.  If you
+do not want the line to be split, customize
+@code{org-M-RET-may-split-line}.
 
-Calling the command with a @kbd{C-u} prefix unconditionally inserts a new
-heading at the end of the current subtree, thus preserving its contents.
-With a double @kbd{C-u C-u} prefix, the new heading is created at the end of
-the parent subtree instead.
-@orgcmd{C-@key{RET},org-insert-heading-respect-content}
+Calling the command with a @kbd{C-u} prefix unconditionally
+inserts a new heading at the end of the current subtree, thus
+preserving its contents.  With a double @kbd{C-u C-u} prefix,
+the new heading is created at the end of the parent subtree instead.
+
+@item @kbd{C-@key{RET}} (@code{org-insert-heading-respect-content})
+@kindex C-RET
+@findex org-insert-heading-respect-content
 Insert a new heading at the end of the current subtree.
-@orgcmd{M-S-@key{RET},org-insert-todo-heading}
+
+@item @kbd{M-S-@key{RET}} (@code{org-insert-todo-heading})
+@kindex M-S-RET
+@findex org-insert-todo-heading
 @vindex org-treat-insert-todo-heading-as-state-change
-Insert new TODO entry with same level as current heading.  See also the
-variable @code{org-treat-insert-todo-heading-as-state-change}.
-@orgcmd{C-S-@key{RET},org-insert-todo-heading-respect-content}
+Insert new TODO entry with same level as current heading.  See also
+the variable @code{org-treat-insert-todo-heading-as-state-change}.
+
+@item @kbd{C-S-@key{RET}} (@code{org-insert-todo-heading-respect-content})
+@kindex C-S-RET
+@findex org-insert-todo-heading-respect-content
 Insert new TODO entry with same level as current heading.  Like
-@kbd{C-@key{RET}}, the new headline will be inserted after the current
+@kbd{C-@key{RET}}, the new headline is inserted after the current
 subtree.
-@orgcmd{@key{TAB},org-cycle}
-In a new entry with no text yet, the first @key{TAB} demotes the entry to
-become a child of the previous one.  The next @key{TAB} makes it a parent,
-and so on, all the way to top level.  Yet another @key{TAB}, and you are back
-to the initial level.
-@orgcmd{M-@key{LEFT},org-do-promote}
+
+@item @kbd{@key{TAB}} (@code{org-cycle})
+@kindex TAB
+@findex org-cycle
+In a new entry with no text yet, the first @kbd{@key{TAB}} demotes
+the entry to become a child of the previous one.  The next
+@kbd{@key{TAB}} makes it a parent, and so on, all the way to top
+level.  Yet another @kbd{@key{TAB}}, and you are back to the initial
+level.
+
+@item @kbd{M-@key{LEFT}} (@code{org-do-promote})
+@kindex M-LEFT
+@findex org-do-promote
 Promote current heading by one level.
-@orgcmd{M-@key{RIGHT},org-do-demote}
+
+@item @kbd{M-@key{RIGHT}} (@code{org-do-demote})
+@kindex M-RIGHT
+@findex org-do-demote
 Demote current heading by one level.
-@orgcmd{M-S-@key{LEFT},org-promote-subtree}
+
+@item @kbd{M-S-@key{LEFT}} (@code{org-promote-subtree})
+@kindex M-S-LEFT
+@findex org-promote-subtree
 Promote the current subtree by one level.
-@orgcmd{M-S-@key{RIGHT},org-demote-subtree}
+
+@item @kbd{M-S-@key{RIGHT}} (@code{org-demote-subtree})
+@kindex M-S-RIGHT
+@findex org-demote-subtree
 Demote the current subtree by one level.
-@orgcmd{M-@key{UP},org-move-subtree-up}
-Move subtree up (swap with previous subtree of same
-level).
-@orgcmd{M-@key{DOWN},org-move-subtree-down}
-Move subtree down (swap with next subtree of same level).
-@orgcmd{M-h,org-mark-element}
-Mark the element at point.  Hitting repeatedly will mark subsequent elements
-of the one just marked.  E.g., hitting @kbd{M-h} on a paragraph will mark it,
-hitting @kbd{M-h} immediately again will mark the next one.
-@orgcmd{C-c @@,org-mark-subtree}
-Mark the subtree at point.  Hitting repeatedly will mark subsequent subtrees
-of the same level than the marked subtree.
-@orgcmd{C-c C-x C-w,org-cut-subtree}
+
+@item @kbd{M-@key{UP}} (@code{org-move-subtree-up})
+@kindex M-UP
+@findex org-move-subtree-up
+Move subtree up, i.e., swap with previous subtree of same level.
+
+@item @kbd{M-@key{DOWN}} (@code{org-move-subtree-down})
+@kindex M-DOWN
+@findex org-move-subtree-down
+Move subtree down, i.e., swap with next subtree of same level.
+
+@item @kbd{C-c @@} (@code{org-mark-subtree})
+@kindex C-c @@
+@findex org-mark-subtree
+Mark the subtree at point.  Hitting repeatedly marks subsequent
+subtrees of the same level as the marked subtree.
+
+@item @kbd{C-c C-x C-w} (@code{org-cut-subtree})
+@kindex C-c C-x C-w
+@findex org-cut-subtree
 Kill subtree, i.e., remove it from buffer but save in kill ring.
 With a numeric prefix argument N, kill N sequential subtrees.
-@orgcmd{C-c C-x M-w,org-copy-subtree}
-Copy subtree to kill ring.  With a numeric prefix argument N, copy the N
-sequential subtrees.
-@orgcmd{C-c C-x C-y,org-paste-subtree}
-Yank subtree from kill ring.  This does modify the level of the subtree to
-make sure the tree fits in nicely at the yank position.  The yank level can
-also be specified with a numeric prefix argument, or by yanking after a
-headline marker like @samp{****}.
-@orgcmd{C-y,org-yank}
+
+@item @kbd{C-c C-x M-w} (@code{org-copy-subtree})
+@kindex C-c C-x M-w
+@findex org-copy-subtree
+Copy subtree to kill ring.  With a numeric prefix argument N, copy
+the N sequential subtrees.
+
+@item @kbd{C-c C-x C-y} (@code{org-paste-subtree})
+@kindex C-c C-x C-y
+@findex org-paste-subtree
+Yank subtree from kill ring.  This does modify the level of the
+subtree to make sure the tree fits in nicely at the yank position.
+The yank level can also be specified with a numeric prefix argument,
+or by yanking after a headline marker like @samp{****}.
+
+@item @kbd{C-y} (@code{org-yank})
+@kindex C-y
+@findex org-yank
 @vindex org-yank-adjusted-subtrees
 @vindex org-yank-folded-subtrees
-Depending on the options @code{org-yank-adjusted-subtrees} and
-@code{org-yank-folded-subtrees}, Org's internal @code{yank} command will
-paste subtrees folded and in a clever way, using the same command as @kbd{C-c
-C-x C-y}.  With the default settings, no level adjustment will take place,
-but the yanked tree will be folded unless doing so would swallow text
-previously visible.  Any prefix argument to this command will force a normal
-@code{yank} to be executed, with the prefix passed along.  A good way to
-force a normal yank is @kbd{C-u C-y}.  If you use @code{yank-pop} after a
-yank, it will yank previous kill items plainly, without adjustment and
-folding.
-@orgcmd{C-c C-x c,org-clone-subtree-with-time-shift}
-Clone a subtree by making a number of sibling copies of it.  You will be
-prompted for the number of copies to make, and you can also specify if any
-timestamps in the entry should be shifted.  This can be useful, for example,
-to create a number of tasks related to a series of lectures to prepare.  For
-more details, see the docstring of the command
-@code{org-clone-subtree-with-time-shift}.
-@orgcmd{C-c C-w,org-refile}
-Refile entry or region to a different location.  @xref{Refile and copy}.
-@orgcmd{C-c ^,org-sort}
-Sort same-level entries.  When there is an active region, all entries in the
-region will be sorted.  Otherwise the children of the current headline are
-sorted.  The command prompts for the sorting method, which can be
-alphabetically, numerically, by time (first timestamp with active preferred,
-creation time, scheduled time, deadline time), by priority, by TODO keyword
-(in the sequence the keywords have been defined in the setup) or by the value
-of a property.  Reverse sorting is possible as well.  You can also supply
-your own function to extract the sorting key.  With a @kbd{C-u} prefix,
-sorting will be case-sensitive.
-@orgcmd{C-x n s,org-narrow-to-subtree}
+Depending on the variables @code{org-yank-adjusted-subtrees} and
+@code{org-yank-folded-subtrees}, Org's internal @code{yank} command pastes
+subtrees folded and in a clever way, using the same command as
+@kbd{C-c C-x C-y}.  With the default settings, no level
+adjustment takes place, but the yanked tree is folded unless doing
+so would swallow text previously visible.  Any prefix argument to
+this command forces a normal @code{yank} to be executed, with the prefix
+passed along.  A good way to force a normal yank is @kbd{C-u C-y}.  If you use 
@code{yank-pop} after a yank, it yanks previous kill
+items plainly, without adjustment and folding.
+
+@item @kbd{C-c C-x c} (@code{org-clone-subtree-with-time-shift})
+@kindex C-c C-x c
+@findex org-clone-subtree-with-time-shift
+Clone a subtree by making a number of sibling copies of it.  You are
+prompted for the number of copies to make, and you can also specify
+if any timestamps in the entry should be shifted.  This can be
+useful, for example, to create a number of tasks related to a series
+of lectures to prepare.  For more details, see the docstring of the
+command @code{org-clone-subtree-with-time-shift}.
+
+@item @kbd{C-c C-w} (@code{org-refile})
+@kindex C-c C-w
+@findex org-refile
+Refile entry or region to a different location.  See @ref{Refile and Copy}.
+
+@item @kbd{C-c ^} (@code{org-sort})
+@kindex C-c ^
+@findex org-sort
+Sort same-level entries.  When there is an active region, all
+entries in the region are sorted.  Otherwise the children of the
+current headline are sorted.  The command prompts for the sorting
+method, which can be alphabetically, numerically, by time---first
+timestamp with active preferred, creation time, scheduled time,
+deadline time---by priority, by TODO keyword---in the sequence the
+keywords have been defined in the setup---or by the value of
+a property.  Reverse sorting is possible as well.  You can also
+supply your own function to extract the sorting key.  With
+a @kbd{C-u} prefix, sorting is case-sensitive.
+
+@item @kbd{C-x n s} (@code{org-narrow-to-subtree})
+@kindex C-x n s
+@findex org-narrow-to-subtree
 Narrow buffer to current subtree.
-@orgcmd{C-x n b,org-narrow-to-block}
+
+@item @kbd{C-x n b} (@code{org-narrow-to-block})
+@kindex C-x n b
+@findex org-narrow-to-block
 Narrow buffer to current block.
-@orgcmd{C-x n w,widen}
+
+@item @kbd{C-x n w} (@code{widen})
+@kindex C-x n w
+@findex widen
 Widen buffer to remove narrowing.
-@orgcmd{C-c *,org-toggle-heading}
-Turn a normal line or plain list item into a headline (so that it becomes a
-subheading at its location).  Also turn a headline into a normal line by
-removing the stars.  If there is an active region, turn all lines in the
-region into headlines.  If the first line in the region was an item, turn
-only the item lines into headlines.  Finally, if the first line is a
-headline, remove the stars from all headlines in the region.
+
+@item @kbd{C-c *} (@code{org-toggle-heading})
+@kindex C-c *
+@findex org-toggle-heading
+Turn a normal line or plain list item into a headline---so that it
+becomes a subheading at its location.  Also turn a headline into
+a normal line by removing the stars.  If there is an active region,
+turn all lines in the region into headlines.  If the first line in
+the region was an item, turn only the item lines into headlines.
+Finally, if the first line is a headline, remove the stars from all
+headlines in the region.
 @end table
 
 @cindex region, active
 @cindex active region
 @cindex transient mark mode
-When there is an active region (Transient Mark mode), promotion and
-demotion work on all headlines in the region.  To select a region of
-headlines, it is best to place both point and mark at the beginning of a
-line, mark at the beginning of the first headline, and point at the line
-just after the last headline to change.  Note that when the cursor is
-inside a table (@pxref{Tables}), the Meta-Cursor keys have different
-functionality.
+When there is an active region---i.e., when Transient Mark mode is
+active---promotion and demotion work on all headlines in the region.
+To select a region of headlines, it is best to place both point and
+mark at the beginning of a line, mark at the beginning of the first
+headline, and point at the line just after the last headline to
+change.  Note that when point is inside a table (see @ref{Tables}), the
+Meta-Cursor keys have different functionality.
 
+@node Sparse Trees
+@section Sparse Trees
 
-@node Sparse trees
-@section Sparse trees
 @cindex sparse trees
 @cindex trees, sparse
 @cindex folding, sparse trees
@@ -1553,42 +1418,55 @@ functionality.
 @vindex org-show-context-detail
 An important feature of Org mode is the ability to construct @emph{sparse
 trees} for selected information in an outline tree, so that the entire
-document is folded as much as possible, but the selected information is made
-visible along with the headline structure above it@footnote{See also the
-variable @code{org-show-context-detail} to decide how much context is shown
-around each match.}.  Just try it out and you will see immediately how it
-works.
+document is folded as much as possible, but the selected information
+is made visible along with the headline structure above it@footnote{See also 
the variable @code{org-show-context-detail} to decide how
+much context is shown around each match.}.
+Just try it out and you will see immediately how it works.
 
-Org mode contains several commands for creating such trees, all these
+Org mode contains several commands creating such trees, all these
 commands can be accessed through a dispatcher:
 
 @table @asis
-@orgcmd{C-c /,org-sparse-tree}
-This prompts for an extra key to select a sparse-tree creating command.
-@orgcmdkkc{C-c / r,C-c / /,org-occur}
+@item @kbd{C-c /} (@code{org-sparse-tree})
+@kindex C-c /
+@findex org-sparse-tree
+This prompts for an extra key to select a sparse-tree creating
+command.
+
+@item @kbd{C-c / r} or @kbd{C-c / /} (@code{org-occur})
+@kindex C-c / r
+@kindex C-c / /
+@findex org-occur
 @vindex org-remove-highlights-with-change
 Prompts for a regexp and shows a sparse tree with all matches.  If
-the match is in a headline, the headline is made visible.  If the match is in
-the body of an entry, headline and body are made visible.  In order to
-provide minimal context, also the full hierarchy of headlines above the match
-is shown, as well as the headline following the match.  Each match is also
-highlighted; the highlights disappear when the buffer is changed by an
-editing command@footnote{This depends on the option
-@code{org-remove-highlights-with-change}}, or by pressing @kbd{C-c C-c}.
-When called with a @kbd{C-u} prefix argument, previous highlights are kept,
-so several calls to this command can be stacked.
-@orgcmdkkc{M-g n,M-g M-n,next-error}
+the match is in a headline, the headline is made visible.  If the
+match is in the body of an entry, headline and body are made
+visible.  In order to provide minimal context, also the full
+hierarchy of headlines above the match is shown, as well as the
+headline following the match.  Each match is also highlighted; the
+highlights disappear when the buffer is changed by an editing
+command, or by pressing @kbd{C-c C-c}@footnote{This depends on the option 
@code{org-remove-highlights-with-change}.}.  When called with
+a @kbd{C-u} prefix argument, previous highlights are kept, so
+several calls to this command can be stacked.
+
+@item @kbd{M-g n} or @kbd{M-g M-n} (@code{next-error})
+@kindex M-g n
+@kindex M-g M-n
+@findex next-error
 Jump to the next sparse tree match in this buffer.
-@orgcmdkkc{M-g p,M-g M-p,previous-error}
+
+@item @kbd{M-g p} or @kbd{M-g M-p} (@code{previous-error})
+@kindex M-g p
+@kindex M-g M-p
+@findex previous-error
 Jump to the previous sparse tree match in this buffer.
 @end table
 
-@noindent
 @vindex org-agenda-custom-commands
 For frequently used sparse trees of specific search strings, you can
-use the option @code{org-agenda-custom-commands} to define fast
-keyboard access to specific sparse trees.  These commands will then be
-accessible through the agenda dispatcher (@pxref{Agenda dispatcher}).
+use the variable @code{org-agenda-custom-commands} to define fast keyboard
+access to specific sparse trees.  These commands will then be
+accessible through the agenda dispatcher (see @ref{Agenda Dispatcher}).
 For example:
 
 @lisp
@@ -1596,772 +1474,780 @@ For example:
       '(("f" occur-tree "FIXME")))
 @end lisp
 
-@noindent will define the key @kbd{C-c a f} as a shortcut for creating
-a sparse tree matching the string @samp{FIXME}.
+@noindent
+defines the key @kbd{f} as a shortcut for creating a sparse tree
+matching the string @samp{FIXME}.
 
 The other sparse tree commands select headings based on TODO keywords,
-tags, or properties and will be discussed later in this manual.
+tags, or properties and are discussed later in this manual.
 
-@kindex C-c C-e C-v
+@kindex C-c C-e v
 @cindex printing sparse trees
 @cindex visible text, printing
 To print a sparse tree, you can use the Emacs command
-@code{ps-print-buffer-with-faces} which does not print invisible parts of the
-document.  Or you can use @kbd{C-c C-e C-v} to export only the visible part
-of the document and print the resulting file.
+@code{ps-print-buffer-with-faces} which does not print invisible parts of
+the document.  Or you can use the command @kbd{C-c C-e v} to
+export only the visible part of the document and print the resulting
+file.
+
+@node Plain Lists
+@section Plain Lists
 
-@node Plain lists
-@section Plain lists
 @cindex plain lists
 @cindex lists, plain
 @cindex lists, ordered
 @cindex ordered lists
 
 Within an entry of the outline tree, hand-formatted lists can provide
-additional structure.  They also provide a way to create lists of checkboxes
-(@pxref{Checkboxes}).  Org supports editing such lists, and every exporter
-(@pxref{Exporting}) can parse and format them.
+additional structure.  They also provide a way to create lists of
+checkboxes (see @ref{Checkboxes}).  Org supports editing such lists, and
+every exporter (see @ref{Exporting}) can parse and format them.
 
 Org knows ordered lists, unordered lists, and description lists.
-@itemize @bullet
+
+@itemize
 @item
-@emph{Unordered} list items start with @samp{-}, @samp{+}, or
-@samp{*}@footnote{When using @samp{*} as a bullet, lines must be indented or
-they will be seen as top-level headlines.  Also, when you are hiding leading
-stars to get a clean outline view, plain list items starting with a star may
-be hard to distinguish from true headlines.  In short: even though @samp{*}
-is supported, it may be better to not use it for plain list items.}  as
-bullets.
+@emph{Unordered} list items start with @samp{-}, @samp{+}, or 
@samp{*}@footnote{When using @samp{*} as a bullet, lines must be indented so 
that they
+are not interpreted as headlines.  Also, when you are hiding leading
+stars to get a clean outline view, plain list items starting with
+a star may be hard to distinguish from true headlines.  In short: even
+though @samp{*} is supported, it may be better to not use it for plain list
+items.} as bullets.
+
 @item
 @vindex org-plain-list-ordered-item-terminator
-@vindex org-list-allow-alphabetical
-@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)}@footnote{You can also get @samp{a.}, @samp{A.}, @samp{a)} and
-@samp{A)} by configuring @code{org-list-allow-alphabetical}.  To minimize
-confusion with normal text, those are limited to one character only.  Beyond
-that limit, bullets will automatically fallback to numbers.}.  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.  If you have activated alphabetical
-lists, you can also use counters like @code{[@@b]}.}.  Those constructs can
-be used in any item of the list in order to enforce a particular numbering.
+@vindex org-alphabetical-lists
+@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)}@footnote{You can also get @samp{a.}, @samp{A.}, @samp{a)} and 
@samp{A)} by configuring
+@code{org-list-allow-alphabetical}.  To minimize confusion with normal
+text, those are limited to one character only.  Beyond that limit,
+bullets automatically become numbers.}
+If you want a list to start with a different value---e.g.,
+20---start the text of the item with @samp{[@@20]}@footnote{If there's a 
checkbox in the item, the cookie must be put
+@emph{before} the checkbox.  If you have activated alphabetical lists, you
+can also use counters like @samp{[@@b]}.}.  Those
+constructs can be used in any item of the list in order to enforce
+a particular numbering.
+
 @item
 @emph{Description} list items are unordered list items, and contain the
-separator @samp{ :: } to distinguish the description @emph{term} from the
+separator @samp{::} to distinguish the description @emph{term} from the
 description.
 @end itemize
 
-Items belonging to the same list must have the same indentation on the first
-line.  In particular, if an ordered list reaches number @samp{10.}, then the
-2--digit numbers must be written left-aligned with the other numbers in the
-list.  An item ends before the next line that is less or equally indented
-than its bullet/number.
-
-A list ends whenever every item has ended, which means before any line less
-or equally indented than items at top level.  It also ends before two blank
-lines.  In that case, all items are closed.  Here is an example:
-
-@example
-@group
-** Lord of the Rings
-   My favorite scenes are (in this order)
-   1. The attack of the Rohirrim
-   2. Eowyn's fight with the witch king
-      + this was already my favorite scene in the book
-      + I really like Miranda Otto.
-   3. Peter Jackson being shot by Legolas
-      - on DVD only
-      He makes a really funny face when it happens.
-   But in the end, no individual scenes matter but the film as a whole.
-   Important actors in this film are:
-   - @b{Elijah Wood} :: He plays Frodo
-   - @b{Sean Astin} :: He plays Sam, Frodo's friend.  I still remember
-     him very well from his role as Mikey Walsh in @i{The Goonies}.
-@end group
-@end example
-
-Org supports these lists by tuning filling and wrapping commands to deal with
-them correctly, 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
-belong to a particular item.
+Items belonging to the same list must have the same indentation on the
+first line.  In particular, if an ordered list reaches number @samp{10.},
+then the 2-digit numbers must be written left-aligned with the other
+numbers in the list.  An item ends before the next line that is less
+or equally indented than its bullet/number.
+
+A list ends whenever every item has ended, which means before any line
+less or equally indented than items at top level.  It also ends before
+two blank lines.  In that case, all items are closed.  Here is an
+example:
+
+@example
+* Lord of the Rings
+My favorite scenes are (in this order)
+1. The attack of the Rohirrim
+2. Eowyn's fight with the witch king
+   + this was already my favorite scene in the book
+   + I really like Miranda Otto.
+3. Peter Jackson being shot by Legolas
+   - on DVD only
+   He makes a really funny face when it happens.
+But in the end, no individual scenes matter but the film as a whole.
+Important actors in this film are:
+- Elijah Wood :: He plays Frodo
+- Sean Astin :: He plays Sam, Frodo's friend. I still remember him
+     very well from his role as Mikey Walsh in /The Goonies/.
+@end example
+
+Org supports these lists by tuning filling and wrapping commands to
+deal with them correctly, and by exporting them properly (see
+@ref{Exporting}).  Since indentation is what governs the structure of these
+lists, many structural constructs like @samp{#+BEGIN_} blocks can be
+indented to signal that they belong to a particular item.
 
 @vindex org-list-demote-modify-bullet
 @vindex org-list-indent-offset
-If you find that using a different bullet for a sub-list (than that used for
-the current list-level) improves readability, customize the variable
-@code{org-list-demote-modify-bullet}.  To get a greater difference of
-indentation between items and their sub-items, customize
+If you find that using a different bullet for a sub-list---than that
+used for the current list-level---improves readability, customize the
+variable @code{org-list-demote-modify-bullet}.  To get a greater difference
+of indentation between items and theirs sub-items, customize
 @code{org-list-indent-offset}.
 
 @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 intact.  If some of
-these actions get in your way, configure @code{org-list-automatic-rules}
+The following commands act on items when point 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 intact.  If some
+of these actions get in your way, configure @code{org-list-automatic-rules}
 to disable them individually.
 
 @table @asis
-@orgcmd{@key{TAB},org-cycle}
+@item @kbd{@key{TAB}} (@code{org-cycle})
 @cindex cycling, in plain lists
+@kindex TAB
+@findex org-cycle
 @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}.  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.  In a new item with no text yet, the
-first @key{TAB} demotes 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.
-@orgcmd{M-@key{RET},org-insert-heading}
+Items can be folded just like headline levels.  Normally this works
+only if point is on a plain list item.  For more details, see the
+variable @code{org-cycle-include-plain-lists}.  If this variable is set
+to @code{integrate}, plain list items are 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.  In a new item
+with no text yet, the first @kbd{@key{TAB}} demotes the item to
+become a child of the previous one.  Subsequent @kbd{@key{TAB}}s move
+the item to meaningful levels in the list and eventually get it back
+to its initial position.
+
+@item @kbd{M-@key{RET}} (@code{org-insert-heading})
+@kindex M-RET
+@findex org-insert-heading
 @vindex org-M-RET-may-split-line
-@vindex org-list-automatic-rules
-Insert new item at current level.  With a prefix argument, force a new
-heading (@pxref{Structure editing}).  If this command is used in the middle
-of an item, that item is @emph{split} in two, and the second part becomes the
-new item@footnote{If you do not want the item to be split, customize the
+Insert new item at current level.  With a prefix argument, force
+a new heading (see @ref{Structure Editing}).  If this command is used in
+the middle of an item, that item is @emph{split} in two, and the second
+part becomes the new item@footnote{If you do not want the item 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
 one.
-@end table
 
-@table @kbd
+@item @kbd{M-S-@key{RET}}
 @kindex M-S-RET
-@item M-S-@key{RET}
-Insert a new item with a checkbox (@pxref{Checkboxes}).
+Insert a new item with a checkbox (see @ref{Checkboxes}).
+
+@item @kbd{S-@key{UP}}
+@itemx @kbd{S-@key{DOWN}}
+@kindex S-UP
 @kindex S-DOWN
-@item S-up
-@itemx S-down
 @cindex shift-selection-mode
 @vindex org-support-shift-select
 @vindex org-list-use-circular-motion
-Jump to the previous/next item in the current list@footnote{If you want to
-cycle around items that way, you may customize
-@code{org-list-use-circular-motion}.}, but only if
-@code{org-support-shift-select} is off.  If not, you can still use paragraph
-jumping commands like @kbd{C-@key{UP}} and @kbd{C-@key{DOWN}} to quite
-similar effect.
+Jump to the previous/next item in the current list, but only if
+@code{org-support-shift-select} is off@footnote{If you want to cycle around 
items that way, you may customize
+@code{org-list-use-circular-motion}.}.  If not, you can still use
+paragraph jumping commands like @kbd{C-@key{UP}} and
+@kbd{C-@key{DOWN}} to quite similar effect.
+
+@item @kbd{M-@key{UP}}
+@itemx @kbd{M-@key{DOWN}}
 @kindex M-UP
 @kindex M-DOWN
-@item M-up
-@itemx M-down
-Move the item including subitems up/down@footnote{See
-@code{org-list-use-circular-motion} for a cyclic behavior.} (swap with
-previous/next item of same indentation).  If the list is ordered, renumbering
-is automatic.
+Move the item including subitems up/down@footnote{See 
@code{org-list-use-circular-motion} for a cyclic behavior.}, i.e., swap with
+previous/next item of same indentation.  If the list is ordered,
+renumbering is automatic.
+
+@item @kbd{M-@key{LEFT}}
+@itemx @kbd{M-@key{RIGHT}}
 @kindex M-LEFT
 @kindex M-RIGHT
-@item M-left
-@itemx M-right
-Decrease/increase the indentation of an item, leaving children alone.
+Decrease/increase the indentation of an item, leaving children
+alone.
+
+@item @kbd{M-S-@key{LEFT}}
+@itemx @kbd{M-S-@key{RIGHT}}
 @kindex M-S-LEFT
 @kindex M-S-RIGHT
-@item M-S-@key{LEFT}
-@itemx M-S-@key{RIGHT}
 Decrease/increase the indentation of the item, including subitems.
-Initially, the item tree is selected based on current indentation.  When
-these commands are executed several times in direct succession, the initially
-selected region is used, even if the new indentation would imply a different
-hierarchy.  To use the new hierarchy, break the command chain with a cursor
-motion or so.
-
-As a special case, using this command on the very first item of a list will
-move the whole list.  This behavior can be disabled by configuring
-@code{org-list-automatic-rules}.  The global indentation of a list has no
-influence on the text @emph{after} the list.
+Initially, the item tree is selected based on current indentation.
+When these commands are executed several times in direct succession,
+the initially selected region is used, even if the new indentation
+would imply a different hierarchy.  To use the new hierarchy, break
+the command chain by moving point.
+
+As a special case, using this command on the very first item of
+a list moves the whole list.  This behavior can be disabled by
+configuring @code{org-list-automatic-rules}.  The global indentation of
+a list has no influence on the text @emph{after} the list.
+
+@item @kbd{C-c C-c}
 @kindex C-c C-c
-@item C-c C-c
-If there is a checkbox (@pxref{Checkboxes}) in the item line, toggle the
-state of the checkbox.  In any case, verify bullets and indentation
-consistency in the whole list.
+If there is a checkbox (see @ref{Checkboxes}) in the item line, toggle
+the state of the checkbox.  In any case, verify bullets and
+indentation consistency in the whole list.
+
+@item @kbd{C-c -}
 @kindex C-c -
 @vindex org-plain-list-ordered-item-terminator
-@item C-c -
-Cycle the entire list level through the different itemize/enumerate bullets
-(@samp{-}, @samp{+}, @samp{*}, @samp{1.}, @samp{1)}) or a subset of them,
-depending on @code{org-plain-list-ordered-item-terminator}, the type of list,
-and its indentation.  With a numeric prefix argument N, select the Nth bullet
-from this list.  If there is an active region when calling this, all selected
-lines are converted to list items.  With a prefix argument, selected text is
-changed into a single item.  If the first line already was a list item, any
-item marker will be removed from the list.  Finally, even without an active
-region, a normal line will be converted into a list item.
+Cycle the entire list level through the different itemize/enumerate
+bullets (@samp{-}, @samp{+}, @samp{*}, @samp{1.}, @samp{1)}) or a subset of 
them, depending
+on @code{org-plain-list-ordered-item-terminator}, the type of list, and
+its indentation.  With a numeric prefix argument N, select the Nth
+bullet from this list.  If there is an active region when calling
+this, selected text is changed into an item.  With a prefix
+argument, all lines are converted to list items.  If the first line
+already was a list item, any item marker is removed from the list.
+Finally, even without an active region, a normal line is converted
+into a list item.
+
+@item @kbd{C-c *}
 @kindex C-c *
-@item C-c *
-Turn a plain list item into a headline (so that it becomes a subheading at
-its location).  @xref{Structure editing}, for a detailed explanation.
+Turn a plain list item into a headline---so that it becomes
+a subheading at its location.  See @ref{Structure Editing}, for
+a detailed explanation.
+
+@item @kbd{C-c C-*}
 @kindex C-c C-*
-@item C-c C-*
-Turn the whole plain list into a subtree of the current heading.  Checkboxes
-(@pxref{Checkboxes}) will become TODO (resp. DONE) keywords when unchecked
-(resp. checked).
+Turn the whole plain list into a subtree of the current heading.
+Checkboxes (see @ref{Checkboxes}) become @samp{TODO}, respectively @samp{DONE},
+keywords when unchecked, respectively checked.
+
+@item @kbd{S-@key{LEFT}}
+@itemx @kbd{S-@key{RIGHT}}
+@vindex org-support-shift-select
 @kindex S-LEFT
 @kindex S-RIGHT
-@item S-@key{LEFT}/@key{RIGHT}
-@vindex org-support-shift-select
-This command also cycles bullet styles when the cursor in on the bullet or
-anywhere in an item line, details depending on
+This command also cycles bullet styles when point is in on the
+bullet or anywhere in an item line, details depending on
 @code{org-support-shift-select}.
+
+@item @kbd{C-c ^}
 @kindex C-c ^
 @cindex sorting, of plain list
-@item C-c ^
-Sort the plain list.  You will be prompted for the sorting method:
-numerically, alphabetically, by time, by checked status for check lists,
-or by a custom function.
+Sort the plain list.  Prompt for the sorting method: numerically,
+alphabetically, by time, or by custom function.
 @end table
 
 @node Drawers
 @section Drawers
+
 @cindex drawers
 @cindex visibility cycling, drawers
 
-@cindex @code{org-insert-drawer}
-@kindex C-c C-x d
-Sometimes you want to keep information associated with an entry, but you
-normally don't want to see it.  For this, Org mode has @emph{drawers}.  They
-can contain anything but a headline and another drawer.  Drawers look like
-this:
+Sometimes you want to keep information associated with an entry, but
+you normally do not want to see it.  For this, Org mode has @emph{drawers}.
+They can contain anything but a headline and another drawer.  Drawers
+look like this:
 
 @example
 ** This is a headline
-   Still outside the drawer
-   :DRAWERNAME:
-   This is inside the drawer.
-   :END:
-   After the drawer.
-@end example
-
-You can interactively insert drawers at point by calling
-@code{org-insert-drawer}, which is bound to @kbd{C-c C-x d}.  With an active
-region, this command will put the region inside the drawer.  With a prefix
-argument, this command calls @code{org-insert-property-drawer} and add
-a property drawer right below the current headline.  Completion over drawer
-keywords is also possible using @kbd{M-@key{TAB}}@footnote{Many desktops
-intercept @kbd{M-@key{TAB}} to switch windows.  Use @kbd{C-M-i} or
-@kbd{@key{ESC} @key{TAB}} instead for completion (@pxref{Completion}).}.
-
-Visibility cycling (@pxref{Visibility cycling}) on the headline will hide and
-show the entry, but keep the drawer collapsed to a single line.  In order to
-look inside the drawer, you need to move the cursor to the drawer line and
-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 to state
-changes, use
-
-@table @kbd
+Still outside the drawer
+:DRAWERNAME:
+This is inside the drawer.
+:END:
+After the drawer.
+@end example
+
+@kindex C-c C-x d
+@findex org-insert-drawer
+You can interactively insert a drawer at point by calling
+@code{org-insert-drawer}, which is bound to @kbd{C-c C-x d}.  With an
+active region, this command puts the region inside the drawer.  With
+a prefix argument, this command calls @code{org-insert-property-drawer},
+which creates a @samp{PROPERTIES} drawer right below the current headline.
+Org mode uses this special drawer for storing properties (see
+@ref{Properties and Columns}).  You cannot use it for anything else.
+
+Completion over drawer keywords is also possible using
+@kbd{M-@key{TAB}}@footnote{Many desktops intercept @kbd{M-@key{TAB}} to switch 
windows.
+Use @kbd{C-M-i} or @kbd{@key{ESC} @key{TAB}} instead.}.
+
+Visibility cycling (see @ref{Visibility Cycling}) on the headline hides and
+shows the entry, but keep the drawer collapsed to a single line.  In
+order to look inside the drawer, you need to move point to the drawer
+line and press @kbd{@key{TAB}} there.
+
+You can also arrange for state change notes (see @ref{Tracking TODO state 
changes}) and clock times (see @ref{Clocking Work Time}) to be stored in
+a @samp{LOGBOOK} drawer.  If you want to store a quick note there, in
+a similar way to state changes, use
+
+@table @asis
+@item @kbd{C-c C-z}
 @kindex C-c C-z
-@item C-c C-z
-Add a time-stamped note to the LOGBOOK drawer.
+Add a time-stamped note to the @samp{LOGBOOK} drawer.
 @end table
 
-@vindex org-export-with-drawers
-@vindex org-export-with-properties
-You can select the name of the drawers which should be exported with
-@code{org-export-with-drawers}.  In that case, drawer contents will appear in
-export output.  Property drawers are not affected by this variable: configure
-@code{org-export-with-properties} instead.
-
 @node Blocks
 @section Blocks
 
 @vindex org-hide-block-startup
 @cindex blocks, folding
-Org mode uses begin...end blocks for various purposes from including source
-code examples (@pxref{Literal examples}) to capturing time logging
-information (@pxref{Clocking work time}).  These blocks can be folded and
-unfolded by pressing @key{TAB} in the begin line.  You can also get all blocks
-folded at startup by configuring the option @code{org-hide-block-startup}
-or on a per-file basis by using
 
-@cindex @code{hideblocks}, STARTUP keyword
-@cindex @code{nohideblocks}, STARTUP keyword
+Org mode uses @samp{#+BEGIN} @dots{} @samp{#+END} blocks for various purposes 
from
+including source code examples (see @ref{Literal Examples}) to capturing
+time logging information (see @ref{Clocking Work Time}).  These blocks can
+be folded and unfolded by pressing @kbd{@key{TAB}} in the @samp{#+BEGIN}
+line.  You can also get all blocks folded at startup by configuring
+the variable @code{org-hide-block-startup} or on a per-file basis by using
+
+@cindex STARTUP, keyword
 @example
 #+STARTUP: hideblocks
 #+STARTUP: nohideblocks
 @end example
 
-@node Footnotes
-@section Footnotes
-@cindex footnotes
+@node Tables
+@chapter Tables
 
-Org mode supports the creation of footnotes.
+@cindex tables
+@cindex editing tables
 
-A footnote is started by a footnote marker in square brackets in column 0, no
-indentation allowed.  It ends at the next footnote definition, headline, or
-after two consecutive empty lines.  The footnote reference is simply the
-marker in square brackets, inside text.  Markers always start with
-@code{fn:}.  For example:
+Org comes with a fast and intuitive table editor.  Spreadsheet-like
+calculations are supported using the Emacs Calc package (see @ref{Top,GNU Emacs
+Calculator Manual,,calc,}).
 
-@example
-The Org homepage[fn:1] now looks a lot better than it used to.
-...
-[fn:1] The link is: https://orgmode.org
-@end example
+@menu
+* Built-in Table Editor::        Simple tables.
+* Column Width and Alignment::   Overrule the automatic settings.
+* Column Groups::                Grouping to trigger vertical lines.
+* Orgtbl Mode::                  The table editor as minor mode.
+* The Spreadsheet::              The table editor has spreadsheet capabilities.
+* Org Plot::                     Plotting from Org tables.
+@end menu
 
-Org mode extends the number-based syntax to @emph{named} footnotes and
-optional inline definition.  Here are the valid references:
+@node Built-in Table Editor
+@section Built-in Table Editor
 
-@table @code
-@item [fn:name]
-A named footnote reference, where @code{name} is a unique label word, or, for
-simplicity of automatic creation, a number.
-@item [fn::This is the inline definition of this footnote]
-A @LaTeX{}-like anonymous footnote where the definition is given directly at 
the
-reference point.
-@item [fn:name:a definition]
-An inline definition of a footnote, which also specifies a name for the note.
-Since Org allows multiple references to the same note, you can then use
-@code{[fn:name]} to create additional references.
-@end table
+@cindex table editor, built-in
 
-@vindex org-footnote-auto-label
-Footnote labels can be created automatically, or you can create names yourself.
-This is handled by the variable @code{org-footnote-auto-label} and its
-corresponding @code{#+STARTUP} keywords.  See the docstring of that variable
-for details.
+@cindex header lines, in tables
+@cindex horizontal rule, in tables
+@cindex row separator, in tables
+@cindex table syntax
+Org makes it easy to format tables in plain ASCII@.  Any line with @samp{|}
+as the first non-whitespace character is considered part of a table.
+@samp{|} is also the column separator@footnote{To insert a vertical bar into a 
table field, use @samp{\vert} or,
+inside a word @samp{abc\vert@{@}def}.}.  Moreover, a line starting
+with @samp{|-} is a horizontal rule.  It separates rows explicitly.  Rows
+before the first horizontal rule are header lines. A table might look
+like this:
 
-@noindent The following command handles footnotes:
+@example
+| Name  | Phone | Age |
+|-------+-------+-----|
+| Peter |  1234 |  17 |
+| Anna  |  4321 |  25 |
+@end example
 
-@table @kbd
-@kindex C-c C-x f
-@item C-c C-x f
-The footnote action command.
+A table is re-aligned automatically each time you press
+@kbd{@key{TAB}}, @kbd{@key{RET}} or @kbd{C-c C-c} inside the table.
+@kbd{@key{TAB}} also moves to the next field---@kbd{@key{RET}} to the
+next row---and creates new table rows at the end of the table or
+before horizontal lines.  The indentation of the table is set by the
+first line.  Horizontal rules are automatically expanded on every
+re-align to span the whole table width.  So, to create the above
+table, you would only type
 
-When the cursor is on a footnote reference, jump to the definition.  When it
-is at a definition, jump to the (first) reference.
+@example
+|Name|Phone|Age|
+|-
+@end example
 
-@vindex org-footnote-define-inline
-@vindex org-footnote-section
-@vindex org-footnote-auto-adjust
-Otherwise, create a new footnote.  Depending on the option
-@code{org-footnote-define-inline}@footnote{The corresponding in-buffer
-setting is: @code{#+STARTUP: fninline} or @code{#+STARTUP: nofninline}}, the
-definition will be placed right into the text as part of the reference, or
-separately into the location determined by the option
-@code{org-footnote-section}.
-
-When this command is called with a prefix argument, a menu of additional
-options is offered:
-@example
-s   @r{Sort the footnote definitions by reference sequence.  During editing,}
-    @r{Org makes no effort to sort footnote definitions into a particular}
-    @r{sequence.  If you want them sorted, use this command, which will}
-    @r{also move entries according to @code{org-footnote-section}.  Automatic}
-    @r{sorting after each insertion/deletion can be configured using the}
-    @r{option @code{org-footnote-auto-adjust}.}
-r   @r{Renumber the simple @code{fn:N} footnotes.  Automatic renumbering}
-    @r{after each insertion/deletion can be configured using the option}
-    @r{@code{org-footnote-auto-adjust}.}
-S   @r{Short for first @code{r}, then @code{s} action.}
-n   @r{Normalize the footnotes by collecting all definitions (including}
-    @r{inline definitions) into a special section, and then numbering them}
-    @r{in sequence.  The references will then also be numbers.}
-d   @r{Delete the footnote at point, and all definitions of and references}
-    @r{to it.}
-@end example
-Depending on the variable @code{org-footnote-auto-adjust}@footnote{the
-corresponding in-buffer options are @code{fnadjust} and @code{nofnadjust}.},
-renumbering and sorting footnotes can be automatic after each insertion or
-deletion.
+@noindent
+and then press @kbd{@key{TAB}} to align the table and start filling in
+fields.  Even faster would be to type @samp{|Name|Phone|Age} followed by
+@kbd{C-c @key{RET}}.
 
-@kindex C-c C-c
-@item C-c C-c
-If the cursor is on a footnote reference, jump to the definition.  If it is a
-the definition, jump back to the reference.  When called at a footnote
-location with a prefix argument, offer the same menu as @kbd{C-c C-x f}.
-@kindex C-c C-o
-@kindex mouse-1
-@kindex mouse-2
-@item C-c C-o  @r{or} mouse-1/2
-Footnote labels are also links to the corresponding definition/reference, and
-you can use the usual commands to follow these links.
+When typing text into a field, Org treats @kbd{DEL},
+@kbd{Backspace}, and all character keys in a special way, so that
+inserting and deleting avoids shifting other fields.  Also, when
+typing @emph{immediately} after point was moved into a new field with
+@kbd{@key{TAB}}, @kbd{S-@key{TAB}} or @kbd{@key{RET}}, the field is
+automatically made blank.  If this behavior is too unpredictable for
+you, configure the option @code{org-table-auto-blank-field}.
 
-@vindex org-edit-footnote-reference
-@kindex C-c '
-@item C-c '
-@item C-c '
-Edit the footnote definition corresponding to the reference at point in
-a separate window.  The window can be closed by pressing @kbd{C-c '}.
+@anchor{Creation and conversion}
+@subheading Creation and conversion
+
+@table @asis
+@item @kbd{C-c |} (@code{org-table-create-or-convert-from-region})
+@kindex C-c |
+@findex org-table-create-or-convert-from-region
+Convert the active region to table.  If every line contains at least
+one @kbd{@key{TAB}} character, the function assumes that the material
+is tab separated.  If every line contains a comma, comma-separated
+values (CSV) are assumed.  If not, lines are split at whitespace
+into fields.  You can use a prefix argument to force a specific
+separator: @kbd{C-u} forces CSV, @kbd{C-u C-u} forces
+@kbd{@key{TAB}}, @kbd{C-u C-u C-u} prompts for a regular
+expression to match the separator, and a numeric argument
+N indicates that at least N consecutive spaces, or alternatively
+a @kbd{@key{TAB}} will be the separator.
 
+If there is no active region, this command creates an empty Org
+table.  But it is easier just to start typing, like @kbd{| N a m e | P h o n e 
| A g e @key{RET} | - @key{TAB}}.
 @end table
 
-@node Orgstruct mode
-@section The Orgstruct minor mode
-@cindex Orgstruct mode
-@cindex minor mode for structure editing
+@anchor{Re-aligning and field motion}
+@subheading Re-aligning and field motion
 
-If you like the intuitive way the Org mode structure editing and list
-formatting works, you might want to use these commands in other modes like
-Text mode or Mail mode as well.  The minor mode @code{orgstruct-mode} makes
-this possible.   Toggle the mode with @kbd{M-x orgstruct-mode @key{RET}}, or
-turn it on by default, for example in Message mode, with one of:
+@table @asis
+@item @kbd{C-c C-c} (@code{org-table-align})
+@kindex C-c C-c
+@findex org-table-align
+Re-align the table without moving point.
 
-@lisp
-(add-hook 'message-mode-hook 'turn-on-orgstruct)
-(add-hook 'message-mode-hook 'turn-on-orgstruct++)
-@end lisp
+@item @kbd{@key{TAB}} (@code{org-table-next-field})
+@kindex TAB
+@findex org-table-next-field
+Re-align the table, move to the next field.  Creates a new row if
+necessary.
 
-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 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.
-
-@vindex orgstruct-heading-prefix-regexp
-You can also use Org structure editing to fold and unfold headlines in
-@emph{any} file, provided you defined @code{orgstruct-heading-prefix-regexp}:
-the regular expression must match the local prefix to use before Org's
-headlines.  For example, if you set this variable to @code{";; "} in Emacs
-Lisp files, you will be able to fold and unfold headlines in Emacs Lisp
-commented lines.  Some commands like @code{org-demote} are disabled when the
-prefix is set, but folding/unfolding will work correctly.
-
-@node Org syntax
-@section Org syntax
-@cindex Org syntax
+@item @kbd{C-c @key{SPC}} (@code{org-table-blank-field})
+@kindex C-c SPC
+@findex org-table-blank-field
+Blank the field at point.
 
-A reference document providing a formal description of Org's syntax is
-available as @uref{https://orgmode.org/worg/dev/org-syntax.html, a draft on
-Worg}, written and maintained by Nicolas Goaziou.  It defines Org's core
-internal concepts such as @code{headlines}, @code{sections}, @code{affiliated
-keywords}, @code{(greater) elements} and @code{objects}.  Each part of an Org
-file falls into one of the categories above.
+@item @kbd{S-@key{TAB}} (@code{org-table-previous-field})
+@kindex S-TAB
+@findex org-table-previous-field
+Re-align, move to previous field.
 
-To explore the abstract structure of an Org buffer, run this in a buffer:
+@item @kbd{@key{RET}} (@code{org-table-next-row})
+@kindex RET
+@findex org-table-next-row
+Re-align the table and move down to next row.  Creates a new row if
+necessary.  At the beginning or end of a line, @kbd{@key{RET}} still
+inserts a new line, so it can be used to split a table.
+
+@item @kbd{M-a} (@code{org-table-beginning-of-field})
+@kindex M-a
+@findex org-table-beginning-of-field
+Move to beginning of the current table field, or on to the previous
+field.
+
+@item @kbd{M-e} (@code{org-table-end-of-field})
+@kindex M-e
+@findex org-table-end-of-field
+Move to end of the current table field, or on to the next field.
+@end table
 
-@lisp
-M-: (org-element-parse-buffer) @key{RET}
-@end lisp
+@anchor{Column and row editing}
+@subheading Column and row editing
 
-It will output a list containing the buffer's content represented as an
-abstract structure.  The export engine relies on the information stored in
-this list.  Most interactive commands (e.g., for structure editing) also
-rely on the syntactic meaning of the surrounding context.
+@table @asis
+@item @kbd{M-@key{LEFT}} (@code{org-table-move-column-left})
+@kindex M-LEFT
+@findex org-table-move-column-left
+Move the current column left.
 
-@cindex syntax checker
-@cindex linter
-You can check syntax in your documents using @code{org-lint} command.
+@item @kbd{M-@key{RIGHT}} (@code{org-table-move-column-right})
+@kindex M-RIGHT
+@findex org-table-move-column-right
+Move the current column right.
 
-@node Tables
-@chapter Tables
-@cindex tables
-@cindex editing tables
+@item @kbd{M-S-@key{LEFT}} (@code{org-table-delete-column})
+@kindex M-S-LEFT
+@findex org-table-delete-column
+Kill the current column.
 
-Org comes with a fast and intuitive table editor.  Spreadsheet-like
-calculations are supported using the Emacs @file{calc} package
-(@pxref{Top, Calc, , calc, GNU Emacs Calculator Manual}).
+@item @kbd{M-S-@key{RIGHT}} (@code{org-table-insert-column})
+@kindex M-S-RIGHT
+@findex org-table-insert-column
+Insert a new column to the left of point position.
 
-@menu
-* Built-in table editor::       Simple tables
-* Column width and alignment::  Overrule the automatic settings
-* Column groups::               Grouping to trigger vertical lines
-* Orgtbl mode::                 The table editor as minor mode
-* The spreadsheet::             The table editor has spreadsheet capabilities
-* Org-Plot::                    Plotting from org tables
-@end menu
+@item @kbd{M-@key{UP}} (@code{org-table-move-row-up})
+@kindex M-UP
+@findex org-table-move-row-up
+Move the current row up.
 
-@node Built-in table editor
-@section The built-in table editor
-@cindex table editor, built-in
+@item @kbd{M-@key{DOWN}} (@code{org-table-move-row-down})
+@kindex M-DOWN
+@findex org-table-move-row-down
+Move the current row down.
 
-Org makes it easy to format tables in plain ASCII@.  Any line with @samp{|} as
-the first non-whitespace character is considered part of a table.  @samp{|}
-is also the column separator@footnote{To insert a vertical bar into a table
-field, use @code{\vert} or, inside a word @code{abc\vert@{@}def}.}.  A table
-might look like this:
+@item @kbd{M-S-@key{UP}} (@code{org-table-kill-row})
+@kindex M-S-UP
+@findex org-table-kill-row
+Kill the current row or horizontal line.
 
-@example
-| Name  | Phone | Age |
-|-------+-------+-----|
-| Peter |  1234 |  17 |
-| Anna  |  4321 |  25 |
-@end example
+@item @kbd{S-@key{UP}} (@code{org-table-move-cell-up})
+@kindex S-UP
+@findex org-table-move-cell-up
+Move cell up by swapping with adjacent cell.
 
-A table is re-aligned automatically each time you press @key{TAB} or
-@key{RET} or @kbd{C-c C-c} inside the table.  @key{TAB} also moves to
-the next field (@key{RET} to the next row) and creates new table rows
-at the end of the table or before horizontal lines.  The indentation
-of the table is set by the first line.  Any line starting with
-@samp{|-} is considered as a horizontal separator line and will be
-expanded on the next re-align to span the whole table width.  So, to
-create the above table, you would only type
+@item @kbd{S-@key{DOWN}} (@code{org-table-move-cell-down})
+@kindex S-DOWN
+@findex org-table-move-cell-down
+Move cell down by swapping with adjacent cell.
 
-@example
-|Name|Phone|Age|
-|-
-@end example
+@item @kbd{S-@key{LEFT}} (@code{org-table-move-cell-left})
+@kindex S-LEFT
+@findex org-table-move-cell-left
+Move cell left by swapping with adjacent cell.
 
-@noindent and then press @key{TAB} to align the table and start filling in
-fields.  Even faster would be to type @code{|Name|Phone|Age} followed by
-@kbd{C-c @key{RET}}.
+@item @kbd{S-@key{RIGHT}} (@code{org-table-move-cell-right})
+@kindex S-RIGHT
+@findex org-table-move-cell-right
+Move cell right by swapping with adjacent cell.
 
-@vindex org-table-auto-blank-field
-When typing text into a field, Org treats @key{DEL}, @key{Backspace}, and all
-character keys in a special way, so that inserting and deleting avoids
-shifting other fields.  Also, when typing @emph{immediately after the cursor
-was moved into a new field with @kbd{@key{TAB}}, @kbd{S-@key{TAB}} or
-@kbd{@key{RET}}}, the field is automatically made blank.  If this behavior is
-too unpredictable for you, configure the option
-@code{org-table-auto-blank-field}.
-
-@table @kbd
-@tsubheading{Creation and conversion}
-@orgcmd{C-c |,org-table-create-or-convert-from-region}
-Convert the active region to a table.  If every line contains at least one
-TAB character, the function assumes that the material is tab separated.
-If every line contains a comma, comma-separated values (CSV) are assumed.
-If not, lines are split at whitespace into fields.  You can use a prefix
-argument to force a specific separator: @kbd{C-u} forces CSV, @kbd{C-u
-C-u} forces TAB, @kbd{C-u C-u C-u} will prompt for a regular expression to
-match the separator, and a numeric argument N indicates that at least N
-consecutive spaces, or alternatively a TAB will be the separator.
-@*
-If there is no active region, this command creates an empty Org
-table.  But it is easier just to start typing, like
-@kbd{|Name|Phone|Age @key{RET} |- @key{TAB}}.
-
-@tsubheading{Re-aligning and field motion}
-@orgcmd{C-c C-c,org-table-align}
-Re-align the table and don't move to another field.
-@c
-@orgcmd{C-c @key{SPC},org-table-blank-field}
-Blank the field at point.
-@c
-@orgcmd{@key{TAB},org-table-next-field}
-Re-align the table, move to the next field.  Creates a new row if
-necessary.
-@c
-@orgcmd{S-@key{TAB},org-table-previous-field}
-Re-align, move to previous field.
-@c
-@orgcmd{@key{RET},org-table-next-row}
-Re-align the table and move down to next row.  Creates a new row if
-necessary.  At the beginning or end of a line, @key{RET} still does
-NEWLINE, so it can be used to split a table.
-@c
-@orgcmd{M-a,org-table-beginning-of-field}
-Move to beginning of the current table field, or on to the previous field.
-@orgcmd{M-e,org-table-end-of-field}
-Move to end of the current table field, or on to the next field.
+@item @kbd{M-S-@key{DOWN}} (@code{org-table-insert-row})
+@kindex M-S-DOWN
+@findex org-table-insert-row
+Insert a new row above the current row.  With a prefix argument, the
+line is created below the current one.
 
-@tsubheading{Column and row editing}
-@orgcmdkkcc{M-@key{LEFT},M-@key{RIGHT},org-table-move-column-left,org-table-move-column-right}
-Move the current column left/right.
-@c
-@orgcmd{M-S-@key{LEFT},org-table-delete-column}
-Kill the current column.
-@c
-@orgcmd{M-S-@key{RIGHT},org-table-insert-column}
-Insert a new column to the left of the cursor position.
-@c
-@orgcmdkkcc{M-@key{UP},M-@key{DOWN},org-table-move-row-up,org-table-move-row-down}
-Move the current row up/down.
-@c
-@orgcmd{M-S-@key{UP},org-table-kill-row}
-Kill the current row or horizontal line.
-@c
-@orgcmd{M-S-@key{DOWN},org-table-insert-row}
-Insert a new row above the current row.  With a prefix argument, the line is
-created below the current one.
-@c
-@orgcmd{C-c -,org-table-insert-hline}
-Insert a horizontal line below current row.  With a prefix argument, the line
-is created above the current line.
-@c
-@orgcmd{C-c @key{RET},org-table-hline-and-move}
-Insert a horizontal line below current row, and move the cursor into the row
-below that line.
-@c
-@orgcmd{C-c ^,org-table-sort-lines}
-Sort the table lines in the region.  The position of point indicates the
-column to be used for sorting, and the range of lines is the range
-between the nearest horizontal separator lines, or the entire table.  If
-point is before the first column, you will be prompted for the sorting
-column.  If there is an active region, the mark specifies the first line
-and the sorting column, while point should be in the last line to be
-included into the sorting.  The command prompts for the sorting type
-(alphabetically, numerically, or by time).  You can sort in normal or
-reverse order.  You can also supply your own key extraction and comparison
-functions.  When called with a prefix argument, alphabetic sorting will be
-case-sensitive.
-
-@tsubheading{Regions}
-@orgcmd{C-c C-x M-w,org-table-copy-region}
-Copy a rectangular region from a table to a special clipboard.  Point and
-mark determine edge fields of the rectangle.  If there is no active region,
-copy just the current field.  The process ignores horizontal separator lines.
-@c
-@orgcmd{C-c C-x C-w,org-table-cut-region}
+@item @kbd{C-c -} (@code{org-table-insert-hline})
+@kindex C-c -
+@findex org-table-insert-hline
+Insert a horizontal line below current row.  With a prefix argument,
+the line is created above the current line.
+
+@item @kbd{C-c @key{RET}} (@code{org-table-hline-and-move})
+@kindex C-c RET
+@findex org-table-hline-and-move
+Insert a horizontal line below current row, and move point into the
+row below that line.
+
+@item @kbd{C-c ^} (@code{org-table-sort-lines})
+@kindex C-c ^
+@findex org-table-sort-lines
+Sort the table lines in the region.  The position of point indicates
+the column to be used for sorting, and the range of lines is the
+range between the nearest horizontal separator lines, or the entire
+table.  If point is before the first column, you are prompted for
+the sorting column.  If there is an active region, the mark
+specifies the first line and the sorting column, while point should
+be in the last line to be included into the sorting.  The command
+prompts for the sorting type, alphabetically, numerically, or by
+time.  You can sort in normal or reverse order.  You can also supply
+your own key extraction and comparison functions.  When called with
+a prefix argument, alphabetic sorting is case-sensitive.
+@end table
+
+@anchor{Regions}
+@subheading Regions
+
+@table @asis
+@item @kbd{C-c C-x M-w} (@code{org-table-copy-region})
+@kindex C-c C-x M-w
+@findex org-table-copy-region
+Copy a rectangular region from a table to a special clipboard.
+Point and mark determine edge fields of the rectangle.  If there is
+no active region, copy just the current field.  The process ignores
+horizontal separator lines.
+
+@item @kbd{C-c C-x C-w} (@code{org-table-cut-region})
+@kindex C-c C-x C-w
+@findex org-table-cut-region
 Copy a rectangular region from a table to a special clipboard, and
 blank all fields in the rectangle.  So this is the ``cut'' operation.
-@c
-@orgcmd{C-c C-x C-y,org-table-paste-rectangle}
-Paste a rectangular region into a table.
-The upper left corner ends up in the current field.  All involved fields
-will be overwritten.  If the rectangle does not fit into the present table,
-the table is enlarged as needed.  The process ignores horizontal separator
-lines.
-@c
-@orgcmd{M-@key{RET},org-table-wrap-region}
-Split the current field at the cursor position and move the rest to the line
-below.  If there is an active region, and both point and mark are in the same
-column, the text in the column is wrapped to minimum width for the given
-number of lines.  A numeric prefix argument may be used to change the number
-of desired lines.  If there is no region, but you specify a prefix argument,
-the current field is made blank, and the content is appended to the field
-above.
 
-@tsubheading{Calculations}
+@item @kbd{C-c C-x C-y} (@code{org-table-paste-rectangle})
+@kindex C-c C-x C-y
+@findex org-table-paste-rectangle
+Paste a rectangular region into a table.  The upper left corner ends
+up in the current field.  All involved fields are overwritten.  If
+the rectangle does not fit into the present table, the table is
+enlarged as needed.  The process ignores horizontal separator lines.
+
+@item @kbd{M-@key{RET}} (@code{org-table-wrap-region})
+@kindex M-RET
+@findex org-table-wrap-region
+Split the current field at point position and move the rest to the
+line below.  If there is an active region, and both point and mark
+are in the same column, the text in the column is wrapped to minimum
+width for the given number of lines.  A numeric prefix argument may
+be used to change the number of desired lines.  If there is no
+region, but you specify a prefix argument, the current field is made
+blank, and the content is appended to the field above.
+@end table
+
+@anchor{Calculations}
+@subheading Calculations
+
 @cindex formula, in tables
 @cindex calculations, in tables
-@cindex region, active
-@cindex active region
-@cindex transient mark mode
-@orgcmd{C-c +,org-table-sum}
-Sum the numbers in the current column, or in the rectangle defined by
-the active region.  The result is shown in the echo area and can
+
+@table @asis
+@item @kbd{C-c +} (@code{org-table-sum})
+@kindex C-c +
+@findex org-table-sum
+Sum the numbers in the current column, or in the rectangle defined
+by the active region.  The result is shown in the echo area and can
 be inserted with @kbd{C-y}.
-@c
-@orgcmd{S-@key{RET},org-table-copy-down}
+
+@item @kbd{S-@key{RET}} (@code{org-table-copy-down})
+@kindex S-RET
+@findex org-table-copy-down
 @vindex org-table-copy-increment
-When current field is empty, copy from first non-empty field above.  When not
-empty, copy current field down to next row and move cursor along with it.
-Depending on the option @code{org-table-copy-increment}, integer field
-values will be incremented during copy.  Integers that are too large will not
-be incremented.  Also, a @code{0} prefix argument temporarily disables the
-increment.  This key is also used by shift-selection and related modes
-(@pxref{Conflicts}).
-
-@tsubheading{Miscellaneous}
-@orgcmd{C-c `,org-table-edit-field}
-Edit the current field in a separate window.  This is useful for fields that
-are not fully visible (@pxref{Column width and alignment}).  When called with
-a @kbd{C-u} prefix, just make the full field visible, so that it can be
-edited in place.  When called with two @kbd{C-u} prefixes, make the editor
-window follow the cursor through the table and always show the current
-field.  The follow mode exits automatically when the cursor leaves the table,
-or when you repeat this command with @kbd{C-u C-u C-c `}.
-@c
-@item M-x org-table-import @key{RET}
+When current field is empty, copy from first non-empty field above.
+When not empty, copy current field down to next row and move point
+along with it.
+
+Depending on the variable @code{org-table-copy-increment}, integer and
+time stamp field values, and fields prefixed or suffixed with
+a whole number, can be incremented during copy.  Also, a @code{0} prefix
+argument temporarily disables the increment.
+
+This key is also used by shift-selection and related modes (see
+@ref{Conflicts}).
+@end table
+
+@anchor{Miscellaneous (1)}
+@subheading Miscellaneous
+
+@table @asis
+@item @kbd{C-c `} (@code{org-table-edit-field})
+@kindex C-c `
+@findex org-table-edit-field
+Edit the current field in a separate window.  This is useful for
+fields that are not fully visible (see @ref{Column Width and Alignment}).
+When called with a @kbd{C-u} prefix, just make the full field
+visible, so that it can be edited in place.  When called with two
+@kbd{C-u} prefixes, make the editor window follow point through
+the table and always show the current field.  The follow mode exits
+automatically when point leaves the table, or when you repeat this
+command with @kbd{C-u C-u C-c `}.
+
+@item @kbd{M-x org-table-import}
+@findex org-table-import
 Import a file as a table.  The table should be TAB or whitespace
 separated.  Use, for example, to import a spreadsheet table or data
 from a database, because these programs generally can write
-TAB-separated text files.  This command works by inserting the file into
-the buffer and then converting the region to a table.  Any prefix
-argument is passed on to the converter, which uses it to determine the
-separator.
-@orgcmd{C-c |,org-table-create-or-convert-from-region}
+TAB-separated text files.  This command works by inserting the file
+into the buffer and then converting the region to a table.  Any
+prefix argument is passed on to the converter, which uses it to
+determine the separator.
+
+@item @kbd{C-c |} (@code{org-table-create-or-convert-from-region})
+@kindex C-c |
+@findex org-table-create-or-convert-from-region
 Tables can also be imported by pasting tabular text into the Org
-buffer, selecting the pasted text with @kbd{C-x C-x} and then using the
-@kbd{C-c |} command (see above under @i{Creation and conversion}).
-@c
-@item M-x org-table-export @key{RET}
+buffer, selecting the pasted text with @kbd{C-x C-x} and then
+using the @kbd{C-c |} command (see @ref{Creation and conversion}).
+
+@item @kbd{M-x org-table-export}
 @findex org-table-export
 @vindex org-table-export-default-format
 Export the table, by default as a TAB-separated file.  Use for data
-exchange with, for example, spreadsheet or database programs.  The format
-used to export the file can be configured in the option
+exchange with, for example, spreadsheet or database programs.  The
+format used to export the file can be configured in the variable
 @code{org-table-export-default-format}.  You may also use properties
-@code{TABLE_EXPORT_FILE} and @code{TABLE_EXPORT_FORMAT} to specify the file
-name and the format for table export in a subtree.  Org supports quite
-general formats for exported tables.  The exporter format is the same as the
-format used by Orgtbl radio tables, see @ref{Translator functions}, for a
-detailed description.
+@samp{TABLE_EXPORT_FILE} and @samp{TABLE_EXPORT_FORMAT} to specify the file
+name and the format for table export in a subtree.  Org supports
+quite general formats for exported tables.  The exporter format is
+the same as the format used by Orgtbl radio tables, see @ref{Translator 
functions}, for a detailed description.
 @end table
 
-@node Column width and alignment
-@section Column width and alignment
+@node Column Width and Alignment
+@section Column Width and Alignment
+
 @cindex narrow columns in tables
 @cindex alignment in tables
 
-The width of columns is automatically determined by the table editor.  And
-also the alignment of a column is determined automatically from the fraction
-of number-like versus non-number fields in the column.
-
-Sometimes a single field or a few fields need to carry more text, leading to
-inconveniently wide columns.  Or maybe you want to make a table with several
-columns having a fixed width, regardless of content.  To set the width of
-a column, one field anywhere in the column may contain just the string
-@samp{<N>} where @samp{N} is an integer specifying the width of the column in
-characters.  The next re-align will then set the width of this column to this
-value.
+The width of columns is automatically determined by the table editor.
+The alignment of a column is determined automatically from the
+fraction of number-like versus non-number fields in the column.
 
-@example
-@group
-|---+------------------------------|               |---+--------|
-|   |                              |               |   | <6>    |
-| 1 | one                          |               | 1 | one    |
-| 2 | two                          |     ----\     | 2 | two    |
-| 3 | This is a long chunk of text |     ----/     | 3 | This=> |
-| 4 | four                         |               | 4 | four   |
-|---+------------------------------|               |---+--------|
-@end group
-@end example
+@vindex org-table-automatic-realign
+Editing a field may modify alignment of the table.  Moving
+a contiguous row or column---i.e., using @kbd{@key{TAB}} or
+@kbd{@key{RET}}---automatically re-aligns it.  If you want to disable
+this behavior, set @code{org-table-automatic-realign} to @code{nil}.  In any
+case, you can always align manually a table:
 
-@noindent
-Fields that are wider become clipped and end in the string @samp{=>}.
-Note that the full text is still in the buffer but is hidden.
-To see the full text, hold the mouse over the field---a tool-tip window
-will show the full content.  To edit such a field, use the command
-@kbd{C-c `} (that is @kbd{C-c} followed by the grave accent).  This will
-open a new window with the full field.  Edit it and finish with @kbd{C-c
-C-c}.
+@table @asis
+@item @kbd{C-c C-c} (@code{org-table-align})
+@kindex C-c C-c
+@findex org-table-align
+Align the current table.
+@end table
 
 @vindex org-startup-align-all-tables
-When visiting a file containing a table with narrowed columns, the
-necessary character hiding has not yet happened, and the table needs to
-be aligned before it looks nice.  Setting the option
-@code{org-startup-align-all-tables} will realign all tables in a file
-upon visiting, but also slow down startup.  You can also set this option
-on a per-file basis with:
+Setting the option @code{org-startup-align-all-tables} re-aligns all tables
+in a file upon visiting it.  You can also set this option on
+a per-file basis with:
 
 @example
 #+STARTUP: align
 #+STARTUP: noalign
 @end example
 
-If you would like to overrule the automatic alignment of number-rich columns
-to the right and of string-rich columns 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{<r10>}.
+Sometimes a single field or a few fields need to carry more text,
+leading to inconveniently wide columns.  Maybe you want to hide away
+several columns or display them with a fixed width, regardless of
+content, as shown in the following example.
+
+@example
+|---+---------------------+--------|           |---+-------…|…|
+|   | <6>                 |        |           |   | <6>   …|…|
+| 1 | one                 | some   |   ----\   | 1 | one   …|…|
+| 2 | two                 | boring |   ----/   | 2 | two   …|…|
+| 3 | This is a long text | column |           | 3 | This i…|…|
+|---+---------------------+--------|           |---+-------…|…|
+@end example
+
+To set the width of a column, one field anywhere in the column may
+contain just the string @samp{<N>} where @var{N} specifies the width
+as a number of characters.  You control displayed width of columns
+with the following tools:
+
+@table @asis
+@item @kbd{C-c @key{TAB}} (@code{org-table-toggle-column-width})
+@kindex C-c TAB
+@findex org-table-toggle-column-width
+Shrink or expand current column.
+
+If a width cookie specifies a width W for the column, shrinking it
+displays the first W visible characters only.  Otherwise, the column
+is shrunk to a single character.
+
+When called before the first column or after the last one, ask for
+a list of column ranges to operate on.
+
+@item @kbd{C-u C-c @key{TAB}} (@code{org-table-shrink})
+@kindex C-u C-c TAB
+@findex org-table-shrink
+Shrink all columns with a column width.  Expand the others.
+
+@item @kbd{C-u C-u C-c @key{TAB}} (@code{org-table-expand})
+@kindex C-u C-u C-c TAB
+@findex org-table-expand
+Expand all columns.
+@end table
+
+To see the full text of a shrunk field, hold the mouse over it:
+a tool-tip window then shows the full contents of the field.
+Alternatively, @kbd{C-h .} (@code{display-local-help}) reveals them,
+too.  For convenience, any change near the shrunk part of a column
+expands it.
+
+@vindex org-startup-shrink-all-tables
+Setting the option @code{org-startup-shrink-all-tables} shrinks all columns
+containing a width cookie in a file the moment it is visited.  You can
+also set this option on a per-file basis with:
+
+@example
+#+STARTUP: shrink
+@end example
+
+
+If you would like to overrule the automatic alignment of number-rich
+columns to the right and of string-rich columns to the left, you can
+use @samp{<r>}, @samp{<c>} or @samp{<l>} in a similar fashion.  You may also 
combine
+alignment and field width like this: @samp{<r10>}.
+
+Lines which only contain these formatting cookies are removed
+automatically upon exporting the document.
 
-Lines which only contain these formatting cookies will be removed
-automatically when exporting the document.
+@node Column Groups
+@section Column Groups
 
-@node Column groups
-@section Column groups
 @cindex grouping columns in tables
 
-When Org exports tables, it does so by default without vertical lines because
-that is visually more satisfying in general.  Occasionally however, vertical
-lines can be useful to structure a table into groups of columns, much like
-horizontal lines can do for groups of rows.  In order to specify column
-groups, you can use a special row where the first field contains only
-@samp{/}.  The further fields can either contain @samp{<} to indicate that
-this column should start a group, @samp{>} to indicate the end of a group, or
-@samp{<>} (no space between @samp{<} and @samp{>}) to make a column a group
-of its own.  Boundaries between column groups will upon export be marked with
-vertical lines.  Here is an example:
-
-@example
-| N | N^2 | N^3 | N^4 | ~sqrt(n)~ | ~sqrt[4](N)~ |
-|---+-----+-----+-----+-----------+--------------|
-| / |   < |     |   > |         < |            > |
-| 1 |   1 |   1 |   1 |         1 |            1 |
-| 2 |   4 |   8 |  16 |    1.4142 |       1.1892 |
-| 3 |   9 |  27 |  81 |    1.7321 |       1.3161 |
-|---+-----+-----+-----+-----------+--------------|
+When Org exports tables, it does so by default without vertical lines
+because that is visually more satisfying in general.  Occasionally
+however, vertical lines can be useful to structure a table into groups
+of columns, much like horizontal lines can do for groups of rows.  In
+order to specify column groups, you can use a special row where the
+first field contains only @samp{/}.  The further fields can either contain
+@samp{<} to indicate that this column should start a group, @samp{>} to 
indicate
+the end of a column, or @samp{<>} (no space between @samp{<} and @samp{>}) to 
make
+a column a group of its own.  Upon export, boundaries between column
+groups are marked with vertical lines.  Here is an example:
+
+@example
+| N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
+|---+-----+-----+-----+---------+------------|
+| / |  <  |     |  >  |       < |          > |
+| 1 |  1  |  1  |  1  |       1 |          1 |
+| 2 |  4  |  8  | 16  |  1.4142 |     1.1892 |
+| 3 |  9  | 27  | 81  |  1.7321 |     1.3161 |
+|---+-----+-----+-----+---------+------------|
 #+TBLFM: $2=$1^2::$3=$1^3::$4=$1^4::$5=sqrt($1)::$6=sqrt(sqrt(($1)))
 @end example
 
@@ -2369,640 +2255,740 @@ It is also sufficient to just insert the column group 
starters after
 every vertical line you would like to have:
 
 @example
-|  N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
-|----+-----+-----+-----+---------+------------|
-| /  | <   |     |     | <       |            |
+| N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
+|---+-----+-----+-----+---------+------------|
+| / | <   |     |     | <       |            |
 @end example
 
-@node Orgtbl mode
-@section The Orgtbl minor mode
+@node Orgtbl Mode
+@section The Orgtbl Minor Mode
+
 @cindex Orgtbl mode
 @cindex minor mode for tables
 
-If you like the intuitive way the Org table editor works, you might also want
-to use it in other modes like Text mode or Mail mode.  The minor mode Orgtbl
-mode makes this possible.  You can always toggle the mode with @kbd{M-x
-orgtbl-mode @key{RET}}.  To turn it on by default, for example in Message
-mode, use
+@findex orgtbl-mode
+If you like the intuitive way the Org table editor works, you might
+also want to use it in other modes like Text mode or Mail mode.  The
+minor mode Orgtbl mode makes this possible.  You can always toggle the
+mode with @kbd{M-x orgtbl-mode}.  To turn it on by default, for
+example in Message mode, use
 
 @lisp
 (add-hook 'message-mode-hook 'turn-on-orgtbl)
 @end lisp
 
-Furthermore, with some special setup, it is possible to maintain tables
-in arbitrary syntax with Orgtbl mode.  For example, it is possible to
-construct @LaTeX{} tables with the underlying ease and power of
-Orgtbl mode, including spreadsheet capabilities.  For details, see
-@ref{Tables in arbitrary syntax}.
+Furthermore, with some special setup, it is possible to maintain
+tables in arbitrary syntax with Orgtbl mode.  For example, it is
+possible to construct @LaTeX{} tables with the underlying ease and power
+of Orgtbl mode, including spreadsheet capabilities.  For details, see
+@ref{Tables in Arbitrary Syntax}.
+
+@node The Spreadsheet
+@section The Spreadsheet
 
-@node The spreadsheet
-@section The spreadsheet
 @cindex calculations, in tables
 @cindex spreadsheet capabilities
-@cindex @file{calc} package
-
-The table editor makes use of the Emacs @file{calc} package to implement
-spreadsheet-like capabilities.  It can also evaluate Emacs Lisp forms to
-derive fields from other fields.  While fully featured, Org's implementation
-is not identical to other spreadsheets.  For example, Org knows the concept
-of a @emph{column formula} that will be applied to all non-header fields in a
-column without having to copy the formula to each relevant field.  There is
-also a formula debugger, and a formula editor with features for highlighting
-fields in the table corresponding to the references at the point in the
-formula, moving these references by arrow keys
+@cindex Calc package
+
+The table editor makes use of the Emacs Calc package to implement
+spreadsheet-like capabilities.  It can also evaluate Emacs Lisp forms
+to derive fields from other fields.  While fully featured, Org's
+implementation is not identical to other spreadsheets.  For example,
+Org knows the concept of a @emph{column formula} that will be applied to
+all non-header fields in a column without having to copy the formula
+to each relevant field.  There is also a formula debugger, and a
+formula editor with features for highlighting fields in the table
+corresponding to the references at point in the formula, moving these
+references by arrow keys.
 
 @menu
-* References::                  How to refer to another field or range
-* Formula syntax for Calc::     Using Calc to compute stuff
-* Formula syntax for Lisp::     Writing formulas in Emacs Lisp
-* Durations and time values::   How to compute durations and time values
-* Field and range formulas::    Formula for specific (ranges of) fields
-* Column formulas::             Formulas valid for an entire column
-* Lookup functions::            Lookup functions for searching tables
-* Editing and debugging formulas::  Fixing formulas
-* Updating the table::          Recomputing all dependent fields
-* Advanced features::           Field and column names, parameters and 
automatic recalc
+* References::                   How to refer to another field or range.
+* Formula syntax for Calc::      Using Calc to compute stuff.
+* Formula syntax for Lisp::      Writing formulas in Emacs Lisp.
+* Durations and time values::    How to compute durations and time values.
+* Field and range formulas::     Formula for specific (ranges of) fields.
+* Column formulas::              Formulas valid for an entire column.
+* Lookup functions::             Lookup functions for searching tables.
+* Editing and debugging formulas:: Fixing formulas.
+* Updating the table::           Recomputing all dependent fields.
+* Advanced features::            Field and column names, automatic 
recalculation...
 @end menu
 
 @node References
 @subsection References
+
 @cindex references
 
 To compute fields in the table from other fields, formulas must
-reference other fields or ranges.  In Org, fields can be referenced
-by name, by absolute coordinates, and by relative coordinates.  To find
-out what the coordinates of a field are, press @kbd{C-c ?} in that
-field, or press @kbd{C-c @}} to toggle the display of a grid.
+reference other fields or ranges.  In Org, fields can be referenced by
+name, by absolute coordinates, and by relative coordinates.  To find
+out what the coordinates of a field are, press @kbd{C-c ?} in
+that field, or press @kbd{C-c @}} to toggle the display of a grid.
 
+@anchor{Field references}
 @subsubheading Field references
+
 @cindex field references
 @cindex references, to fields
-
-Formulas can reference the value of another field in two ways.  Like in
-any other spreadsheet, you may reference fields with a letter/number
-combination like @code{B3}, meaning the 2nd field in the 3rd row.
-@vindex org-table-use-standard-references
-However, Org prefers@footnote{Org will understand references typed by the
-user as @samp{B4}, but it will not use this syntax when offering a formula
-for editing.  You can customize this behavior using the option
-@code{org-table-use-standard-references}.} to use another, more general
-representation that looks like this:
-@example
-@@@var{row}$@var{column}
-@end example
-
-Column specifications can be absolute like @code{$1},
-@code{$2},...@code{$@var{N}}, or relative to the current column (i.e., the
-column of the field which is being computed) like @code{$+1} or @code{$-2}.
-@code{$<} and @code{$>} are immutable references to the first and last
-column, respectively, and you can use @code{$>>>} to indicate the third
-column from the right.
-
-The row specification only counts data lines and ignores horizontal separator
-lines (hlines).  Like with columns, you can use absolute row numbers
-@code{@@1}, @code{@@2},...@code{@@@var{N}}, and row numbers relative to the
-current row like @code{@@+3} or @code{@@-1}.  @code{@@<} and @code{@@>} are
-immutable references the first and last@footnote{For backward compatibility
-you can also use special names like @code{$LR5} and @code{$LR12} to refer in
-a stable way to the 5th and 12th field in the last row of the table.
-However, this syntax is deprecated, it should not be used for new documents.
-Use @code{@@>$} instead.} row in the table, respectively.  You may also
-specify the row relative to one of the hlines: @code{@@I} refers to the first
-hline, @code{@@II} to the second, etc.  @code{@@-I} refers to the first such
-line above the current line, @code{@@+I} to the first such line below the
-current line.  You can also write @code{@@III+2} which is the second data line
-after the third hline in the table.
-
-@code{@@0} and @code{$0} refer to the current row and column, respectively,
-i.e., to the row/column for the field being computed.  Also, if you omit
-either the column or the row part of the reference, the current row/column is
-implied.
-
-Org's references with @emph{unsigned} numbers are fixed references
-in the sense that if you use the same reference in the formula for two
-different fields, the same field will be referenced each time.
-Org's references with @emph{signed} numbers are floating
-references because the same reference operator can reference different
-fields depending on the field being calculated by the formula.
+Formulas can reference the value of another field in two ways.  Like
+in any other spreadsheet, you may reference fields with
+a letter/number combination like @samp{B3}, meaning the second field in the
+third row.  However, Org prefers to use another, more general
+representation that looks like this:@footnote{Org understands references typed 
by the user as @samp{B4}, but it
+does not use this syntax when offering a formula for editing.  You can
+customize this behavior using the variable
+@code{org-table-use-standard-references}.}
+
+@example
+@@ROW$COLUMN
+@end example
+
+
+Column specifications can be absolute like @samp{$1}, @samp{$2}, @dots{}, 
@samp{$N}, or
+relative to the current column, i.e., the column of the field which is
+being computed, like @samp{$+1} or @samp{$-2}.  @samp{$<} and @samp{$>} are 
immutable
+references to the first and last column, respectively, and you can use
+@samp{$>>>} to indicate the third column from the right.
+
+The row specification only counts data lines and ignores horizontal
+separator lines, or ``hlines''.  Like with columns, you can use absolute
+row numbers @samp{@@1}, @samp{@@2}, @dots{}, @samp{@@N}, and row numbers 
relative to the
+current row like @samp{@@+3} or @samp{@@-1}.  @samp{@@<} and @samp{@@>} are 
immutable
+references the first and last row in the table, respectively.  You may
+also specify the row relative to one of the hlines: @samp{@@I} refers to the
+first hline, @samp{@@II} to the second, etc.  @samp{@@-I} refers to the first 
such
+line above the current line, @samp{@@+I} to the first such line below the
+current line.  You can also write @samp{@@III+2} which is the second data
+line after the third hline in the table.
+
+@samp{@@0} and @samp{$0} refer to the current row and column, respectively, 
i.e.,
+to the row/column for the field being computed.  Also, if you omit
+either the column or the row part of the reference, the current
+row/column is implied.
+
+Org's references with @emph{unsigned} numbers are fixed references in the
+sense that if you use the same reference in the formula for two
+different fields, the same field is referenced each time.  Org's
+references with @emph{signed} numbers are floating references because the
+same reference operator can reference different fields depending on
+the field being calculated by the formula.
 
 Here are a few examples:
 
-@example
-@@2$3      @r{2nd row, 3rd column (same as @code{C2})}
-$5        @r{column 5 in the current row (same as @code{E&})}
-@@2        @r{current column, row 2}
-@@-1$-3    @r{the field one row up, three columns to the left}
-@@-I$2     @r{field just under hline above current row, column 2}
-@@>$5      @r{field in the last row, in column 5}
-@end example
+@multitable @columnfractions 0.2 0.8
+@item @samp{@@2$3}
+@tab 2nd row, 3rd column (same as @samp{C2})
+@item @samp{$5}
+@tab column 5 in the current row (same as @samp{E&})
+@item @samp{@@2}
+@tab current column, row 2
+@item @samp{@@-1$-3}
+@tab field one row up, three columns to the left
+@item @samp{@@-I$2}
+@tab field just under hline above current row, column 2
+@item @samp{@@>$5}
+@tab field in the last row, in column 5
+@end multitable
 
+@anchor{Range references}
 @subsubheading Range references
+
 @cindex range references
 @cindex references, to ranges
+You may reference a rectangular range of fields by specifying two
+field references connected by two dots @samp{..}.  If both fields are in
+the current row, you may simply use @samp{$2..$7}, but if at least one
+field is in a different row, you need to use the general @samp{@@ROW$COLUMN}
+format at least for the first field, i.e., the reference must start
+with @samp{@@} in order to be interpreted correctly.  Examples:
+
+@multitable @columnfractions 0.2 0.8
+@item @samp{$1..$3}
+@tab first three fields in the current row
+@item @samp{$P..$Q}
+@tab range, using column names (see @ref{Advanced features})
+@item @samp{$<<<..$>>}
+@tab start in third column, continue to the last but one
+@item @samp{@@2$1..@@4$3}
+@tab six fields between these two fields (same as @samp{A2..C4})
+@item @samp{@@-1$-2..@@-1}
+@tab 3 fields in the row above, starting from 2 columns on the left
+@item @samp{@@I..II}
+@tab between first and second hline, short for @samp{@@I..@@II}
+@end multitable
 
-You may reference a rectangular range of fields by specifying two field
-references connected by two dots @samp{..}.  If both fields are in the
-current row, you may simply use @samp{$2..$7}, but if at least one field
-is in a different row, you need to use the general @code{@@row$column}
-format at least for the first field (i.e the reference must start with
-@samp{@@} in order to be interpreted correctly).  Examples:
-
-@example
-$1..$3        @r{first three fields in the current row}
-$P..$Q        @r{range, using column names (see under Advanced)}
-$<<<..$>>     @r{start in third column, continue to the last but one}
-@@2$1..@@4$3    @r{6 fields between these two fields (same as @code{A2..C4})}
-@@-1$-2..@@-1   @r{3 fields in the row above, starting from 2 columns on the 
left}
-@@I..II        @r{between first and second hline, short for @code{@@I..@@II}}
-@end example
-
-@noindent Range references return a vector of values that can be fed
-into Calc vector functions.  Empty fields in ranges are normally suppressed,
-so that the vector contains only the non-empty fields.  For other options
-with the mode switches @samp{E}, @samp{N} and examples @pxref{Formula syntax
-for Calc}.
+@noindent
+Range references return a vector of values that can be fed into Calc
+vector functions.  Empty fields in ranges are normally suppressed, so
+that the vector contains only the non-empty fields.  For other options
+with the mode switches @samp{E}, @samp{N} and examples, see @ref{Formula 
syntax for Calc}.
 
+@anchor{Field coordinates in formulas}
 @subsubheading Field coordinates in formulas
+
 @cindex field coordinates
 @cindex coordinates, of field
 @cindex row, of field coordinates
 @cindex column, of field coordinates
+@vindex org-table-current-column
+@vindex org-table-current-dline
+One of the very first actions during evaluation of Calc formulas and
+Lisp formulas is to substitute @samp{@@#} and @samp{$#} in the formula with the
+row or column number of the field where the current result will go to.
+The traditional Lisp formula equivalents are @code{org-table-current-dline}
+and @code{org-table-current-column}.  Examples:
 
-One of the very first actions during evaluation of Calc formulas and Lisp
-formulas is to substitute @code{@@#} and @code{$#} in the formula with the
-row or column number of the field where the current result will go to.  The
-traditional Lisp formula equivalents are @code{org-table-current-dline} and
-@code{org-table-current-column}.  Examples:
-
-@table @code
-@item if(@@# % 2, $#, string(""))
+@table @asis
+@item @samp{if(@@# % 2, $#, string(""))}
 Insert column number on odd rows, set field to empty on even rows.
-@item $2 = '(identity remote(FOO, @@@@#$1))
-Copy text or values of each row of column 1 of the table named @code{FOO}
-into column 2 of the current table.
-@item @@3 = 2 * remote(FOO, @@1$$#)
-Insert the doubled value of each column of row 1 of the table named
-@code{FOO} into row 3 of the current table.
+
+@item @samp{$2 = '(identity remote(FOO, @@@@#$1))}
+Copy text or values of each row of column 1 of the table named
+@var{FOO} into column 2 of the current table.
+
+@item @samp{@@3 = 2 * remote(FOO, @@@@1$$#)}
+Insert the doubled value of each column of row 1 of the table
+named @var{FOO} into row 3 of the current table.
 @end table
 
-@noindent For the second/third example, the table named @code{FOO} must have
-at least as many rows/columns as the current table.  Note that this is
-inefficient@footnote{The computation time scales as O(N^2) because the table
-named @code{FOO} is parsed for each field to be read.} for large number of
-rows/columns.
+@noindent
+For the second and third examples, table @var{FOO} must have at
+least as many rows or columns as the current table.  Note that this is
+inefficient@footnote{The computation time scales as O(N^2) because table
+@var{FOO} is parsed for each field to be copied.} for large number of rows.
 
+@anchor{Named references}
 @subsubheading Named references
+
 @cindex named references
 @cindex references, named
 @cindex name, of column or field
 @cindex constants, in calculations
-@cindex @code{#+CONSTANTS}
-
+@cindex @samp{CONSTANTS}, keyword
 @vindex org-table-formula-constants
-@samp{$name} is interpreted as the name of a column, parameter or
-constant.  Constants are defined globally through the option
-@code{org-table-formula-constants}, and locally (for the file) through a
-line like
+
+@samp{$name} is interpreted as the name of a column, parameter or constant.
+Constants are defined globally through the variable
+@code{org-table-formula-constants}, and locally---for the file---through
+a line like this example:
 
 @example
 #+CONSTANTS: c=299792458. pi=3.14 eps=2.4e-6
 @end example
 
-@noindent
+
 @vindex constants-unit-system
 @pindex constants.el
-Also properties (@pxref{Properties and columns}) can be used as
-constants in table formulas: for a property @samp{:Xyz:} use the name
-@samp{$PROP_Xyz}, and the property will be searched in the current
-outline entry and in the hierarchy above it.  If you have the
-@file{constants.el} package, it will also be used to resolve constants,
-including natural constants like @samp{$h} for Planck's constant, and
-units like @samp{$km} for kilometers@footnote{@file{constants.el} can
-supply the values of constants in two different unit systems, @code{SI}
-and @code{cgs}.  Which one is used depends on the value of the variable
-@code{constants-unit-system}.  You can use the @code{#+STARTUP} options
-@code{constSI} and @code{constcgs} to set this value for the current
-buffer.}.  Column names and parameters can be specified in special table
-lines.  These are described below, see @ref{Advanced features}.  All
-names must start with a letter, and further consist of letters and
-numbers.
-
+Also, properties (see @ref{Properties and Columns}) can be used as
+constants in table formulas: for a property @samp{Xyz} use the name
+@samp{$PROP_Xyz}, and the property will be searched in the current outline
+entry and in the hierarchy above it.  If you have the @samp{constants.el}
+package, it will also be used to resolve constants, including natural
+constants like @samp{$h} for Planck's constant, and units like @samp{$km} for
+kilometers@footnote{The file @samp{constants.el} can supply the values of 
constants in
+two different unit systems, @samp{SI} and @samp{cgs}.  Which one is used 
depends
+on the value of the variable @code{constants-unit-system}.  You can use the
+@samp{STARTUP} options @samp{constSI} and @samp{constcgs} to set this value 
for the
+current buffer.}.  Column names and parameters can be specified in
+special table lines.  These are described below, see @ref{Advanced features}.  
All names must start with a letter, and further consist
+of letters and numbers.
+
+@anchor{Remote references}
 @subsubheading Remote references
+
 @cindex remote references
 @cindex references, remote
 @cindex references, to a different table
 @cindex name, of column or field
-@cindex constants, in calculations
-@cindex @code{#+NAME}, for table
-
-You may also reference constants, fields and ranges from a different table,
-either in the current file or even in a different file.  The syntax is
+@cindex @samp{NAME}, keyword
+You may also reference constants, fields and ranges from a different
+table, either in the current file or even in a different file.  The
+syntax is
 
 @example
-remote(NAME-OR-ID,REF)
+remote(NAME,REF)
 @end example
 
+
 @noindent
-where NAME can be the name of a table in the current file as set by a
-@code{#+NAME: Name} line before the table.  It can also be the ID of an
-entry, even in a different file, and the reference then refers to the first
-table in that entry.  REF is an absolute field or range reference as
-described above for example @code{@@3$3} or @code{$somename}, valid in the
-referenced table.
-
-Indirection of NAME-OR-ID: When NAME-OR-ID has the format @code{@@ROW$COLUMN}
-it will be substituted with the name or ID found in this field of the current
-table.  For example @code{remote($1, @@>$2)} => @code{remote(year_2013,
-@@>$1)}.  The format @code{B3} is not supported because it can not be
-distinguished from a plain table name or ID.
+where @var{NAME} can be the name of a table in the current file
+as set by a @samp{#+NAME:} line before the table.  It can also be the ID of
+an entry, even in a different file, and the reference then refers to
+the first table in that entry.  @var{REF} is an absolute field or
+range reference as described above for example @samp{@@3$3} or 
@samp{$somename},
+valid in the referenced table.
+
+@cindex table indirection
+When @var{NAME} has the format @samp{@@ROW$COLUMN}, it is substituted
+with the name or ID found in this field of the current table.  For
+example @samp{remote($1, @@@@>$2)} @result{} @samp{remote(year_2013, 
@@@@>$1)}.  The format
+@samp{B3} is not supported because it can not be distinguished from a plain
+table name or ID@.
 
 @node Formula syntax for Calc
 @subsection Formula syntax for Calc
+
 @cindex formula syntax, Calc
 @cindex syntax, of formulas
 
-A formula can be any algebraic expression understood by the Emacs @file{Calc}
-package.  Note that @file{calc} has the non-standard convention that @samp{/}
-has lower precedence than @samp{*}, so that @samp{a/b*c} is interpreted as
-@samp{a/(b*c)}.  Before evaluation by @code{calc-eval} (@pxref{Calling Calc
-from Your Programs, calc-eval, Calling Calc from Your Lisp Programs, calc,
-GNU Emacs Calc Manual}), variable substitution takes place according to the
-rules described above.
+A formula can be any algebraic expression understood by the Emacs Calc
+package.  Note that Calc has the non-standard convention that @samp{/} has
+lower precedence than @samp{*}, so that @samp{a/b*c} is interpreted as
+@samp{(a/(b*c))}.  Before evaluation by @code{calc-eval} (see @ref{Calling 
Calc from Your Programs,Calling Calc from
+Your Lisp Programs,,calc,}), variable substitution takes place according to
+the rules described above.
+
 @cindex vectors, in table calculations
 The range vectors can be directly fed into the Calc vector functions
-like @samp{vmean} and @samp{vsum}.
+like @code{vmean} and @code{vsum}.
 
-@cindex format specifier
-@cindex mode, for @file{calc}
+@cindex format specifier, in spreadsheet
+@cindex mode, for Calc
 @vindex org-calc-default-modes
 A formula can contain an optional mode string after a semicolon.  This
 string consists of flags to influence Calc and other modes during
 execution.  By default, Org uses the standard Calc modes (precision
-12, angular units degrees, fraction and symbolic modes off).  The display
-format, however, has been changed to @code{(float 8)} to keep tables
-compact.  The default settings can be configured using the option
-@code{org-calc-default-modes}.
-
-@noindent List of modes:
+12, angular units degrees, fraction and symbolic modes off).  The
+display format, however, has been changed to @samp{(float 8)} to keep
+tables compact.  The default settings can be configured using the
+variable @code{org-calc-default-modes}.
 
 @table @asis
-@item @code{p20}
+@item @samp{p20}
 Set the internal Calc calculation precision to 20 digits.
-@item @code{n3}, @code{s3}, @code{e2}, @code{f4}
-Normal, scientific, engineering or fixed format of the result of Calc passed
-back to Org.  Calc formatting is unlimited in precision as long as the Calc
-calculation precision is greater.
-@item @code{D}, @code{R}
+
+@item @samp{n3}, @samp{s3}, @samp{e2}, @samp{f4}
+Normal, scientific, engineering or fixed format of the result of
+Calc passed back to Org.  Calc formatting is unlimited in precision
+as long as the Calc calculation precision is greater.
+
+@item @samp{D}, @samp{R}
 Degree and radian angle modes of Calc.
-@item @code{F}, @code{S}
+
+@item @samp{F}, @samp{S}
 Fraction and symbolic modes of Calc.
-@item @code{T}, @code{t}, @code{U}
-Duration computations in Calc or Lisp, @pxref{Durations and time values}.
-@item @code{E}
-If and how to consider empty fields.  Without @samp{E} empty fields in range
-references are suppressed so that the Calc vector or Lisp list contains only
-the non-empty fields.  With @samp{E} the empty fields are kept.  For empty
-fields in ranges or empty field references the value @samp{nan} (not a
-number) is used in Calc formulas and the empty string is used for Lisp
-formulas.  Add @samp{N} to use 0 instead for both formula types.  For the
-value of a field the mode @samp{N} has higher precedence than @samp{E}.
-@item @code{N}
-Interpret all fields as numbers, use 0 for non-numbers.  See the next section
-to see how this is essential for computations with Lisp formulas.  In Calc
-formulas it is used only occasionally because there number strings are
-already interpreted as numbers without @samp{N}.
-@item @code{L}
+
+@item @samp{T}, @samp{t}, @samp{U}
+Duration computations in Calc or Lisp, @ref{Durations and time values}.
+
+@item @samp{E}
+If and how to consider empty fields.  Without @samp{E} empty fields in
+range references are suppressed so that the Calc vector or Lisp list
+contains only the non-empty fields.  With @samp{E} the empty fields are
+kept.  For empty fields in ranges or empty field references the
+value @samp{nan} (not a number) is used in Calc formulas and the empty
+string is used for Lisp formulas.  Add @samp{N} to use 0 instead for both
+formula types.  For the value of a field the mode @samp{N} has higher
+precedence than @samp{E}.
+
+@item @samp{N}
+Interpret all fields as numbers, use 0 for non-numbers.  See the
+next section to see how this is essential for computations with Lisp
+formulas.  In Calc formulas it is used only occasionally because
+there number strings are already interpreted as numbers without @samp{N}.
+
+@item @samp{L}
 Literal, for Lisp formulas only.  See the next section.
 @end table
 
-@noindent
-Unless you use large integer numbers or high-precision-calculation and
--display for floating point numbers you may alternatively provide a
-@samp{printf} format specifier to reformat the Calc result after it has been
-passed back to Org instead of letting Calc already do the
-formatting@footnote{The @samp{printf} reformatting is limited in precision
-because the value passed to it is converted into an @samp{integer} or
-@samp{double}.  The @samp{integer} is limited in size by truncating the
-signed value to 32 bits.  The @samp{double} is limited in precision to 64
-bits overall which leaves approximately 16 significant decimal digits.}.  A
-few examples:
-
-@example
-$1+$2                @r{Sum of first and second field}
-$1+$2;%.2f           @r{Same, format result to two decimals}
-exp($2)+exp($1)      @r{Math functions can be used}
-$0;%.1f              @r{Reformat current cell to 1 decimal}
-($3-32)*5/9          @r{Degrees F -> C conversion}
-$c/$1/$cm            @r{Hz -> cm conversion, using @file{constants.el}}
-tan($1);Dp3s1        @r{Compute in degrees, precision 3, display SCI 1}
-sin($1);Dp3%.1e      @r{Same, but use printf specifier for display}
-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, (@pxref{Logical
-Operations, , Logical Operations, calc, GNU Emacs Calc Manual}).  For example
-
-@table @code
-@item if($1 < 20, teen, string(""))
-"teen" if age $1 is less than 20, else the Org table result field is set to
-empty with the empty string.
-@item if("$1" == "nan" || "$2" == "nan", string(""), $1 + $2); E f-1
-Sum of the first two columns.  When at least one of the input fields is empty
-the Org table result field is set to empty.  @samp{E} is required to not
-convert empty fields to 0.  @samp{f-1} is an optional Calc format string
-similar to @samp{%.1f} but leaves empty results empty.
-@item if(typeof(vmean($1..$7)) == 12, string(""), vmean($1..$7); E
-Mean value of a range unless there is any empty field.  Every field in the
-range that is empty is replaced by @samp{nan} which lets @samp{vmean} result
-in @samp{nan}.  Then @samp{typeof == 12} detects the @samp{nan} from
-@samp{vmean} and the Org table result field is set to empty.  Use this when
-the sample set is expected to never have missing values.
-@item if("$1..$7" == "[]", string(""), vmean($1..$7))
-Mean value of a range with empty fields skipped.  Every field in the range
-that is empty is skipped.  When all fields in the range are empty the mean
-value is not defined and the Org table result field is set to empty.  Use
-this when the sample set can have a variable size.
-@item vmean($1..$7); EN
-To complete the example before: Mean value of a range with empty fields
-counting as samples with value 0.  Use this only when incomplete sample sets
-should be padded with 0 to the full size.
+Unless you use large integer numbers or high-precision calculation and
+display for floating point numbers you may alternatively provide
+a @code{printf} format specifier to reformat the Calc result after it has
+been passed back to Org instead of letting Calc already do the
+formatting@footnote{The printf reformatting is limited in precision because the
+value passed to it is converted into an ``integer'' or ``double''.  The
+``integer'' is limited in size by truncating the signed value to 32
+bits.  The ``double'' is limited in precision to 64 bits overall which
+leaves approximately 16 significant decimal digits.}.  A few examples:
+
+@multitable {aaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{$1+$2}
+@tab Sum of first and second field
+@item @samp{$1+$2;%.2f}
+@tab Same, format result to two decimals
+@item @samp{exp($2)+exp($1)}
+@tab Math functions can be used
+@item @samp{$0;%.1f}
+@tab Reformat current cell to 1 decimal
+@item @samp{($3-32)*5/9}
+@tab Degrees F @arrow{} C conversion
+@item @samp{$c/$1/$cm}
+@tab Hz @arrow{} cm conversion, using @samp{constants.el}
+@item @samp{tan($1);Dp3s1}
+@tab Compute in degrees, precision 3, display SCI 1
+@item @samp{sin($1);Dp3%.1e}
+@tab Same, but use @code{printf} specifier for display
+@item @samp{vmean($2..$7)}
+@tab Compute column range mean, using vector function
+@item @samp{vmean($2..$7);EN}
+@tab Same, but treat empty fields as 0
+@item @samp{taylor($3,x=7,2)}
+@tab Taylor series of $3, at x=7, second degree
+@end multitable
+
+Calc also contains a complete set of logical operations (see @ref{Logical 
Operations,Logical
+Operations,,calc,}).  For example
+
+@table @asis
+@item @samp{if($1 < 20, teen, string(""))}
+@samp{"teen"} if age @samp{$1} is less than 20, else the Org table result
+field is set to empty with the empty string.
+
+@item @samp{if("$1" =​= "nan" || "$2" =​= "nan", string(""), $1 + $2); E f-1}
+Sum of the first two columns.  When at least one of the input fields
+is empty the Org table result field is set to empty.  @samp{E} is
+required to not convert empty fields to 0.  @samp{f-1} is an optional
+Calc format string similar to @samp{%.1f} but leaves empty results empty.
+
+@item @samp{if(typeof(vmean($1..$7)) =​= 12, string(""), vmean($1..$7); E}
+Mean value of a range unless there is any empty field.  Every field
+in the range that is empty is replaced by @samp{nan} which lets @samp{vmean}
+result in @samp{nan}.  Then @samp{typeof =} 12= detects the @samp{nan} from 
@code{vmean}
+and the Org table result field is set to empty.  Use this when the
+sample set is expected to never have missing values.
+
+@item @samp{if("$1..$7" =​= "[]", string(""), vmean($1..$7))}
+Mean value of a range with empty fields skipped.  Every field in the
+range that is empty is skipped.  When all fields in the range are
+empty the mean value is not defined and the Org table result field
+is set to empty.  Use this when the sample set can have a variable
+size.
+
+@item @samp{vmean($1..$7); EN}
+To complete the example before: Mean value of a range with empty
+fields counting as samples with value 0.  Use this only when
+incomplete sample sets should be padded with 0 to the full size.
 @end table
 
-You can add your own Calc functions defined in Emacs Lisp with @code{defmath}
-and use them in formula syntax for Calc.
+You can add your own Calc functions defined in Emacs Lisp with
+@code{defmath} and use them in formula syntax for Calc.
 
 @node Formula syntax for Lisp
 @subsection Emacs Lisp forms as formulas
+
 @cindex Lisp forms, as table formulas
 
-It is also possible to write a formula in Emacs Lisp.  This can be useful
-for string manipulation and control structures, if Calc's functionality is
-not enough.
+It is also possible to write a formula in Emacs Lisp.  This can be
+useful for string manipulation and control structures, if Calc's
+functionality is not enough.
 
-If a formula starts with an apostrophe followed by an opening parenthesis,
-then it is evaluated as a Lisp form.  The evaluation should return either a
-string or a number.  Just as with @file{calc} formulas, you can specify modes
-and a printf format after a semicolon.
+If a formula starts with a single-quote followed by an opening
+parenthesis, then it is evaluated as a Lisp form.  The evaluation
+should return either a string or a number.  Just as with Calc
+formulas, you can specify modes and a @code{printf} format after
+a semicolon.
 
 With Emacs Lisp forms, you need to be conscious about the way field
-references are interpolated into the form.  By default, a reference will be
-interpolated as a Lisp string (in double-quotes) containing the field.  If
-you provide the @samp{N} mode switch, all referenced elements will be numbers
-(non-number fields will be zero) and interpolated as Lisp numbers, without
-quotes.  If you provide the @samp{L} flag, all fields will be interpolated
-literally, without quotes.  I.e., if you want a reference to be interpreted
-as a string by the Lisp form, enclose the reference operator itself in
-double-quotes, like @code{"$3"}.  Ranges are inserted as space-separated
-fields, so you can embed them in list or vector syntax.
+references are interpolated into the form.  By default, a reference is
+interpolated as a Lisp string (in double-quotes) containing the field.
+If you provide the @samp{N} mode switch, all referenced elements are
+numbers---non-number fields will be zero---and interpolated as Lisp
+numbers, without quotes.  If you provide the @samp{L} flag, all fields are
+interpolated literally, without quotes.  For example, if you want a
+reference to be interpreted as a string by the Lisp form, enclose the
+reference operator itself in double-quotes, like @samp{"$3"}.  Ranges are
+inserted as space-separated fields, so you can embed them in list or
+vector syntax.
 
 Here are a few examples---note how the @samp{N} mode is used when we do
 computations in Lisp:
 
-@table @code
-@item '(concat (substring $1 1 2) (substring $1 0 1) (substring $1 2))
+@table @asis
+@item @samp{'(concat (substring $1 1 2) (substring $1 0 1) (substring $1 2))}
 Swap the first two characters of the content of column 1.
-@item '(+ $1 $2);N
-Add columns 1 and 2, equivalent to Calc's @code{$1+$2}.
-@item '(apply '+ '($1..$4));N
-Compute the sum of columns 1 to 4, like Calc's @code{vsum($1..$4)}.
+
+@item @samp{'(+ $1 $2);N}
+Add columns 1 and 2, equivalent to Calc's @samp{$1+$2}.
+
+@item @samp{'(apply '+ '($1..$4));N}
+Compute the sum of columns 1 to 4, like Calc's @samp{vsum($1..$4)}.
 @end table
 
 @node Durations and time values
 @subsection Durations and time values
-@cindex Duration, computing
-@cindex Time, computing
+
+@cindex duration, computing
+@cindex time, computing
 @vindex org-table-duration-custom-format
 
-If you want to compute time values use the @code{T}, @code{t}, or @code{U}
-flag, either in Calc formulas or Elisp formulas:
+If you want to compute time values use the @samp{T}, @samp{t}, or @samp{U} 
flag,
+either in Calc formulas or Elisp formulas:
 
 @example
-@group
-  |  Task 1 |   Task 2 |    Total |
-  |---------+----------+----------|
-  |    2:12 |     1:47 | 03:59:00 |
-  |    2:12 |     1:47 |    03:59 |
-  | 3:02:20 | -2:07:00 |     0.92 |
-  #+TBLFM: @@2$3=$1+$2;T::@@3$3=$1+$2;U::@@4$3=$1+$2;t
-@end group
+|  Task 1 |   Task 2 |    Total |
+|---------+----------+----------|
+|    2:12 |     1:47 | 03:59:00 |
+|    2:12 |     1:47 |    03:59 |
+| 3:02:20 | -2:07:00 |     0.92 |
+#+TBLFM: @@2$3=$1+$2;T::@@3$3=$1+$2;U::@@4$3=$1+$2;t
 @end example
 
-Input duration values must be of the form @code{HH:MM[:SS]}, where seconds
-are optional.  With the @code{T} flag, computed durations will be displayed
-as @code{HH:MM:SS} (see the first formula above).  With the @code{U} flag,
-seconds will be omitted so that the result will be only @code{HH:MM} (see
-second formula above).  Zero-padding of the hours field will depend upon the
-value of the variable @code{org-table-duration-hour-zero-padding}.
+Input duration values must be of the form @samp{HH:MM[:SS]}, where seconds
+are optional.  With the @samp{T} flag, computed durations are displayed as
+@samp{HH:MM:SS} (see the first formula above).  With the @samp{U} flag, seconds
+are omitted so that the result is only @samp{HH:MM} (see second formula
+above).  Zero-padding of the hours field depends upon the value of the
+variable @code{org-table-duration-hour-zero-padding}.
 
-With the @code{t} flag, computed durations will be displayed according to the
+With the @samp{t} flag, computed durations are displayed according to the
 value of the option @code{org-table-duration-custom-format}, which defaults
-to @code{'hours} and will display the result as a fraction of hours (see the
+to @code{hours} and displays the result as a fraction of hours (see the
 third formula in the example above).
 
-Negative duration values can be manipulated as well, and integers will be
+Negative duration values can be manipulated as well, and integers are
 considered as seconds in addition and subtraction.
 
 @node Field and range formulas
 @subsection Field and range formulas
+
 @cindex field formula
 @cindex range formula
 @cindex formula, for individual table field
 @cindex formula, for range of fields
 
-To assign a formula to a particular field, type it directly into the field,
-preceded by @samp{:=}, for example @samp{:=vsum(@@II..III)}.  When you press
-@key{TAB} or @key{RET} or @kbd{C-c C-c} with the cursor still in the field,
-the formula will be stored as the formula for this field, evaluated, and the
-current field will be replaced with the result.
-
-@cindex @code{#+TBLFM}
-Formulas are stored in a special line starting with @code{#+TBLFM:} directly
-below the table.  If you type the equation in the 4th field of the 3rd data
-line in the table, the formula will look like @samp{@@3$4=$1+$2}.  When
-inserting/deleting/swapping columns and rows with the appropriate commands,
-@i{absolute references} (but not relative ones) in stored formulas are
-modified in order to still reference the same field.  To avoid this, in
-particular in range references, anchor ranges at the table borders (using
-@code{@@<}, @code{@@>}, @code{$<}, @code{$>}), or at hlines using the
-@code{@@I} notation.  Automatic adaptation of field references does of course
-not happen if you edit the table structure with normal editing
-commands---then you must fix the equations yourself.
-
-Instead of typing an equation into the field, you may also use the following
-command
-
-@table @kbd
-@orgcmd{C-u C-c =,org-table-eval-formula}
-Install a new formula for the current field.  The command prompts for a
-formula with default taken from the @code{#+TBLFM:} line, applies
-it to the current field, and stores it.
+To assign a formula to a particular field, type it directly into the
+field, preceded by @samp{:=}, for example @samp{vsum(@@II..III)}.  When you 
press
+@kbd{@key{TAB}} or @kbd{@key{RET}} or @kbd{C-c C-c} with point
+still in the field, the formula is stored as the formula for this
+field, evaluated, and the current field is replaced with the result.
+
+@cindex @samp{TBLFM}, keyword
+Formulas are stored in a special @samp{TBLFM} keyword located directly
+below the table.  If you type the equation in the fourth field of the
+third data line in the table, the formula looks like @samp{@@3$4=$1+$2}.
+When inserting/deleting/swapping column and rows with the appropriate
+commands, @emph{absolute references} (but not relative ones) in stored
+formulas are modified in order to still reference the same field.  To
+avoid this from happening, in particular in range references, anchor
+ranges at the table borders (using @samp{@@<}, @samp{@@>}, @samp{$<}, 
@samp{$>}), or at
+hlines using the @samp{@@I} notation.  Automatic adaptation of field
+references does not happen if you edit the table structure with normal
+editing commands---you must fix the formulas yourself.
+
+Instead of typing an equation into the field, you may also use the
+following command
+
+@table @asis
+@item @kbd{C-u C-c =} (@code{org-table-eval-formula})
+@kindex C-u C-c =
+@findex org-table-eval-formula
+Install a new formula for the current field.  The command prompts
+for a formula with default taken from the @samp{TBLFM} keyword,
+applies it to the current field, and stores it.
 @end table
 
-The left-hand side of a formula can also be a special expression in order to
-assign the formula to a number of different fields.  There is no keyboard
-shortcut to enter such range formulas.  To add them, use the formula editor
-(@pxref{Editing and debugging formulas}) or edit the @code{#+TBLFM:} line
-directly.
-
-@table @code
-@item $2=
-Column formula, valid for the entire column.  This is so common that Org
-treats these formulas in a special way, see @ref{Column formulas}.
-@item @@3=
-Row formula, applies to all fields in the specified row.  @code{@@>=} means
-the last row.
-@item @@1$2..@@4$3=
-Range formula, applies to all fields in the given rectangular range.  This
-can also be used to assign a formula to some but not all fields in a row.
-@item $name=
+The left-hand side of a formula can also be a special expression in
+order to assign the formula to a number of different fields.  There is
+no keyboard shortcut to enter such range formulas.  To add them, use
+the formula editor (see @ref{Editing and debugging formulas}) or edit
+the @samp{TBLFM} keyword directly.
+
+@table @asis
+@item @samp{$2=}
+Column formula, valid for the entire column.  This is so common that
+Org treats these formulas in a special way, see @ref{Column formulas}.
+
+@item @samp{@@3=}
+Row formula, applies to all fields in the specified row.  @samp{@@>=}
+means the last row.
+
+@item @samp{@@1$2..@@4$3=}
+Range formula, applies to all fields in the given rectangular range.
+This can also be used to assign a formula to some but not all fields
+in a row.
+
+@item @samp{$NAME=}
 Named field, see @ref{Advanced features}.
 @end table
 
 @node Column formulas
 @subsection Column formulas
+
 @cindex column formula
 @cindex formula, for table column
 
-When you assign a formula to a simple column reference like @code{$3=}, the
-same formula will be used in all fields of that column, with the following
-very convenient exceptions: (i) If the table contains horizontal separator
-hlines with rows above and below, everything before the first such hline is
-considered part of the table @emph{header} and will not be modified by column
-formulas.  Therefore a header is mandatory when you use column formulas and
-want to add hlines to group rows, like for example to separate a total row at
-the bottom from the summand rows above.  (ii) Fields that already get a value
-from a field/range formula will be left alone by column formulas.  These
-conditions make column formulas very easy to use.
-
-To assign a formula to a column, type it directly into any field in the
-column, preceded by an equal sign, like @samp{=$1+$2}.  When you press
-@key{TAB} or @key{RET} or @kbd{C-c C-c} with the cursor still in the field,
-the formula will be stored as the formula for the current column, evaluated
-and the current field replaced with the result.  If the field contains only
-@samp{=}, the previously stored formula for this column is used.  For each
-column, Org will only remember the most recently used formula.  In the
-@code{#+TBLFM:} line, column formulas will look like @samp{$4=$1+$2}.  The
-left-hand side of a column formula cannot be the name of column, it must be
-the numeric column reference or @code{$>}.
+When you assign a formula to a simple column reference like @samp{$3=}, the
+same formula is used in all fields of that column, with the following
+very convenient exceptions: (i) If the table contains horizontal
+separator hlines with rows above and below, everything before the
+first such hline is considered part of the table @emph{header} and is not
+modified by column formulas.  Therefore a header is mandatory when you
+use column formulas and want to add hlines to group rows, like for
+example to separate a total row at the bottom from the summand rows
+above.  (ii) Fields that already get a value from a field/range
+formula are left alone by column formulas.  These conditions make
+column formulas very easy to use.
+
+To assign a formula to a column, type it directly into any field in
+the column, preceded by an equal sign, like @samp{=$1+$2}.  When you press
+@kbd{@key{TAB}} or @kbd{@key{RET}} or @kbd{C-c C-c} with point
+still in the field, the formula is stored as the formula for the
+current column, evaluated and the current field replaced with the
+result.  If the field contains only @samp{=}, the previously stored formula
+for this column is used.  For each column, Org only remembers the most
+recently used formula.  In the @samp{TBLFM} keyword, column formulas look
+like @samp{$4=$1+$2}.  The left-hand side of a column formula can not be
+the name of column, it must be the numeric column reference or @samp{$>}.
 
 Instead of typing an equation into the field, you may also use the
 following command:
 
-@table @kbd
-@orgcmd{C-c =,org-table-eval-formula}
-Install a new formula for the current column and replace current field with
-the result of the formula.  The command prompts for a formula, with default
-taken from the @code{#+TBLFM} line, applies it to the current field and
-stores it.  With a numeric prefix argument(e.g., @kbd{C-5 C-c =}) the command
-will apply it to that many consecutive fields in the current column.
+@table @asis
+@item @kbd{C-c =} (@code{org-table-eval-formula})
+@kindex C-c =
+@findex org-table-eval-formula
+Install a new formula for the current column and replace current
+field with the result of the formula.  The command prompts for
+a formula, with default taken from the @samp{TBLFM} keyword, applies it
+to the current field and stores it.  With a numeric prefix argument,
+e.g., @kbd{C-5 C-c =}, the command applies it to that many
+consecutive fields in the current column.
 @end table
 
 @node Lookup functions
 @subsection Lookup functions
+
 @cindex lookup functions in tables
 @cindex table lookup functions
 
 Org has three predefined Emacs Lisp functions for lookups in tables.
-@table @code
-@item (org-lookup-first VAL S-LIST R-LIST &optional PREDICATE)
+
+@table @asis
+@item @samp{(org-lookup-first VAL S-LIST R-LIST &optional PREDICATE)}
 @findex org-lookup-first
-Searches for the first element @code{S} in list @code{S-LIST} for which
+Searches for the first element @var{S} in list
+@var{S-LIST} for which
 @lisp
 (PREDICATE VAL S)
 @end lisp
-is @code{t}; returns the value from the corresponding position in list
-@code{R-LIST}.  The default @code{PREDICATE} is @code{equal}.  Note that the
-parameters @code{VAL} and @code{S} are passed to @code{PREDICATE} in the same
-order as the corresponding parameters are in the call to
-@code{org-lookup-first}, where @code{VAL} precedes @code{S-LIST}.  If
-@code{R-LIST} is @code{nil}, the matching element @code{S} of @code{S-LIST}
-is returned.
-@item (org-lookup-last VAL S-LIST R-LIST &optional PREDICATE)
+is non-@code{nil}; returns the value from the corresponding position in
+list @var{R-LIST}.  The default @var{PREDICATE} is
+@code{equal}.  Note that the parameters @var{VAL} and @var{S}
+are passed to @var{PREDICATE} in the same order as the
+corresponding parameters are in the call to @code{org-lookup-first},
+where @var{VAL} precedes @var{S-LIST}.  If
+@var{R-LIST} is @code{nil}, the matching element @var{S} of
+@var{S-LIST} is returned.
+
+@item @samp{(org-lookup-last VAL S-LIST R-LIST &optional PREDICATE)}
 @findex org-lookup-last
-Similar to @code{org-lookup-first} above, but searches for the @i{last}
-element for which @code{PREDICATE} is @code{t}.
-@item (org-lookup-all VAL S-LIST R-LIST &optional PREDICATE)
+Similar to @code{org-lookup-first} above, but searches for the @emph{last}
+element for which @var{PREDICATE} is non-@code{nil}.
+
+@item @samp{(org-lookup-all VAL S-LIST R-LIST &optional PREDICATE)}
 @findex org-lookup-all
-Similar to @code{org-lookup-first}, but searches for @i{all} elements for
-which @code{PREDICATE} is @code{t}, and returns @i{all} corresponding
-values.  This function can not be used by itself in a formula, because it
-returns a list of values.  However, powerful lookups can be built when this
-function is combined with other Emacs Lisp functions.
+Similar to @code{org-lookup-first}, but searches for @emph{all} elements for
+which @var{PREDICATE} is non-@code{nil}, and returns @emph{all}
+corresponding values.  This function can not be used by itself in
+a formula, because it returns a list of values.  However, powerful
+lookups can be built when this function is combined with other Emacs
+Lisp functions.
 @end table
 
-If the ranges used in these functions contain empty fields, the @code{E} mode
-for the formula should usually be specified: otherwise empty fields will not be
-included in @code{S-LIST} and/or @code{R-LIST} which can, for example, result
-in an incorrect mapping from an element of @code{S-LIST} to the corresponding
-element of @code{R-LIST}.
+If the ranges used in these functions contain empty fields, the @samp{E}
+mode for the formula should usually be specified: otherwise empty
+fields are not included in @var{S-LIST} and/or @var{R-LIST}
+which can, for example, result in an incorrect mapping from an element
+of @var{S-LIST} to the corresponding element of
+@var{R-LIST}.
 
-These three functions can be used to implement associative arrays, count
-matching cells, rank results, group data etc.  For practical examples
-see @uref{https://orgmode.org/worg/org-tutorials/org-lookups.html, this
-tutorial on Worg}.
+These three functions can be used to implement associative arrays,
+count matching cells, rank results, group data, etc.  For practical
+examples see @uref{https://orgmode.org/worg/org-tutorials/org-lookups.html, 
this tutorial on Worg}.
 
 @node Editing and debugging formulas
 @subsection Editing and debugging formulas
+
 @cindex formula editing
 @cindex editing, of table formulas
 
 @vindex org-table-use-standard-references
-You can edit individual formulas in the minibuffer or directly in the field.
-Org can also prepare a special buffer with all active formulas of a table.
-When offering a formula for editing, Org converts references to the standard
-format (like @code{B3} or @code{D&}) if possible.  If you prefer to only work
-with the internal format (like @code{@@3$2} or @code{$4}), configure the
-option @code{org-table-use-standard-references}.
-
-@table @kbd
-@orgcmdkkc{C-c =,C-u C-c =,org-table-eval-formula}
+You can edit individual formulas in the minibuffer or directly in the
+field.  Org can also prepare a special buffer with all active formulas
+of a table.  When offering a formula for editing, Org converts
+references to the standard format (like @samp{B3} or @samp{D&}) if possible.  
If
+you prefer to only work with the internal format (like @samp{@@3$2} or
+@samp{$4}), configure the variable @code{org-table-use-standard-references}.
+
+@table @asis
+@item @kbd{C-c =} or @kbd{C-u C-c =} (@code{org-table-eval-formula})
+@kindex C-c =
+@kindex C-u C-c =
+@findex org-table-eval-formula
 Edit the formula associated with the current column/field in the
 minibuffer.  See @ref{Column formulas}, and @ref{Field and range formulas}.
-@orgcmd{C-u C-u C-c =,org-table-eval-formula}
-Re-insert the active formula (either a
-field formula, or a column formula) into the current field, so that you
-can edit it directly in the field.  The advantage over editing in the
-minibuffer is that you can use the command @kbd{C-c ?}.
-@orgcmd{C-c ?,org-table-field-info}
+
+@item @kbd{C-u C-u C-c =} (@code{org-table-eval-formula})
+@kindex C-u C-u C-c =
+@findex org-table-eval-formula
+Re-insert the active formula (either a field formula, or a column
+formula) into the current field, so that you can edit it directly in
+the field.  The advantage over editing in the minibuffer is that you
+can use the command @kbd{C-c ?}.
+
+@item @kbd{C-c ?} (@code{org-table-field-info})
+@kindex C-c ?
+@findex org-table-field-info
 While editing a formula in a table field, highlight the field(s)
-referenced by the reference at the cursor position in the formula.
+referenced by the reference at point position in the formula.
+
+@item @kbd{C-c @}} (@code{org-table-toggle-coordinate-overlays})
 @kindex C-c @}
 @findex org-table-toggle-coordinate-overlays
-@item C-c @}
-Toggle the display of row and column numbers for a table, using overlays
-(@command{org-table-toggle-coordinate-overlays}).  These are updated each
-time the table is aligned; you can force it with @kbd{C-c C-c}.
+Toggle the display of row and column numbers for a table, using
+overlays.  These are updated each time the table is aligned; you can
+force it with @kbd{C-c C-c}.
+
+@item @kbd{C-c @{} (@code{org-table-toggle-formula-debugger})
 @kindex C-c @{
 @findex org-table-toggle-formula-debugger
-@item C-c @{
-Toggle the formula debugger on and off
-(@command{org-table-toggle-formula-debugger}).  See below.
-@orgcmd{C-c ',org-table-edit-formulas}
-Edit all formulas for the current table in a special buffer, where the
-formulas will be displayed one per line.  If the current field has an
-active formula, the cursor in the formula editor will mark it.
-While inside the special buffer, Org will automatically highlight
-any field or range reference at the cursor position.  You may edit,
-remove and add formulas, and use the following commands:
-
-@table @kbd
-@orgcmdkkc{C-c C-c,C-x C-s,org-table-fedit-finish}
-Exit the formula editor and store the modified formulas.  With @kbd{C-u}
-prefix, also apply the new formulas to the entire table.
-@orgcmd{C-c C-q,org-table-fedit-abort}
+Toggle the formula debugger on and off.  See below.
+
+@item @kbd{C-c '} (@code{org-table-edit-formulas})
+@kindex C-c '
+@findex org-table-edit-formulas
+Edit all formulas for the current table in a special buffer, where
+the formulas are displayed one per line.  If the current field has
+an active formula, point in the formula editor marks it.  While
+inside the special buffer, Org automatically highlights any field or
+range reference at point position.  You may edit, remove and add
+formulas, and use the following commands:
+
+@table @asis
+@item @kbd{C-c C-c} or @kbd{C-x C-s} (@code{org-table-fedit-finish})
+@kindex C-x C-s
+@kindex C-c C-c
+@findex org-table-fedit-finish
+Exit the formula editor and store the modified formulas.  With
+@kbd{C-u} prefix, also apply the new formulas to the
+entire table.
+
+@item @kbd{C-c C-q} (@code{org-table-fedit-abort})
+@kindex C-c C-q
+@findex org-table-fedit-abort
 Exit the formula editor without installing changes.
-@orgcmd{C-c C-r,org-table-fedit-toggle-ref-type}
+
+@item @kbd{C-c C-r} (@code{org-table-fedit-toggle-ref-type})
+@kindex C-c C-r
+@findex org-table-fedit-toggle-ref-type
 Toggle all references in the formula editor between standard (like
-@code{B3}) and internal (like @code{@@3$2}).
-@orgcmd{@key{TAB},org-table-fedit-lisp-indent}
-Pretty-print or indent Lisp formula at point.  When in a line containing
-a Lisp formula, format the formula according to Emacs Lisp rules.
-Another @key{TAB} collapses the formula back again.  In the open
-formula, @key{TAB} re-indents just like in Emacs Lisp mode.
-@orgcmd{M-@key{TAB},lisp-complete-symbol}
-Complete Lisp symbols, just like in Emacs Lisp mode.@footnote{Many desktops
-intercept @kbd{M-@key{TAB}} to switch windows.  Use @kbd{C-M-i} or
-@kbd{@key{ESC} @key{TAB}} instead for completion (@pxref{Completion}).}
+@samp{B3}) and internal (like @samp{@@3$2}).
+
+@item @kbd{@key{TAB}} (@code{org-table-fedit-lisp-indent})
+@kindex TAB
+@findex org-table-fedit-lisp-indent
+Pretty-print or indent Lisp formula at point.  When in a line
+containing a Lisp formula, format the formula according to Emacs
+Lisp rules.  Another @kbd{@key{TAB}} collapses the formula back
+again.  In the open formula, @kbd{@key{TAB}} re-indents just like
+in Emacs Lisp mode.
+
+@item @kbd{M-@key{TAB}} (@code{lisp-complete-symbol})
+@kindex M-TAB
+@findex lisp-complete-symbol
+Complete Lisp symbols, just like in Emacs Lisp mode.
+
+@item @kbd{S-@key{UP}}, @kbd{S-@key{DOWN}}, @kbd{S-@key{LEFT}}, 
@kbd{S-@key{RIGHT}}
 @kindex S-UP
 @kindex S-DOWN
 @kindex S-LEFT
@@ -3011,44 +2997,60 @@ intercept @kbd{M-@key{TAB}} to switch windows.  Use 
@kbd{C-M-i} or
 @findex org-table-fedit-ref-down
 @findex org-table-fedit-ref-left
 @findex org-table-fedit-ref-right
-@item S-@key{UP}/@key{DOWN}/@key{LEFT}/@key{RIGHT}
 Shift the reference at point.  For example, if the reference is
-@code{B3} and you press @kbd{S-@key{RIGHT}}, it will become @code{C3}.
-This also works for relative references and for hline references.
-@orgcmdkkcc{M-S-@key{UP},M-S-@key{DOWN},org-table-fedit-line-up,org-table-fedit-line-down}
-Move the test line for column formulas in the Org buffer up and
-down.
-@orgcmdkkcc{M-@key{UP},M-@key{DOWN},org-table-fedit-scroll-down,org-table-fedit-scroll-up}
-Scroll the window displaying the table.
+@samp{B3} and you press @kbd{S-@key{RIGHT}}, it becomes @samp{C3}.  This also
+works for relative references and for hline references.
+
+@item @kbd{M-S-@key{UP}} (@code{org-table-fedit-line-up})
+@kindex M-S-UP
+@findex org-table-fedit-line-up
+Move the test line for column formulas up in the Org buffer.
+
+@item @kbd{M-S-@key{DOWN}} (@code{org-table-fedit-line-down})
+@kindex M-S-DOWN
+@findex org-table-fedit-line-down
+Move the test line for column formulas down in the Org buffer.
+
+@item @kbd{M-@key{UP}} (@code{org-table-fedit-scroll-up})
+@kindex M-UP
+@findex org-table-fedit-scroll-up
+Scroll up the window displaying the table.
+
+@item @kbd{M-@key{DOWN}} (@code{org-table-fedit-scroll-down})
+@kindex M-DOWN
+@findex org-table-fedit-scroll-down
+Scroll down the window displaying the table.
+
+@item @kbd{C-c @}}
 @kindex C-c @}
 @findex org-table-toggle-coordinate-overlays
-@item C-c @}
 Turn the coordinate grid in the table on and off.
 @end table
 @end table
 
 Making a table field blank does not remove the formula associated with
-the field, because that is stored in a different line (the @code{#+TBLFM}
-line)---during the next recalculation the field will be filled again.
-To remove a formula from a field, you have to give an empty reply when
-prompted for the formula, or to edit the @code{#+TBLFM} line.
+the field, because that is stored in a different line---the @samp{TBLFM}
+keyword line.  During the next recalculation, the field will be filled
+again.  To remove a formula from a field, you have to give an empty
+reply when prompted for the formula, or to edit the @samp{TBLFM} keyword.
 
 @kindex C-c C-c
-You may edit the @code{#+TBLFM} directly and re-apply the changed
+You may edit the @samp{TBLFM} keyword directly and re-apply the changed
 equations with @kbd{C-c C-c} in that line or with the normal
 recalculation commands in the table.
 
-@anchor{Using multiple #+TBLFM lines}
-@subsubheading Using multiple @code{#+TBLFM} lines
-@cindex @code{#+TBLFM} line, multiple
-@cindex @code{#+TBLFM}
-@cindex @code{#+TBLFM}, switching
-@kindex C-c C-c
+@anchor{Using multiple @samp{TBLFM} lines}
+@subsubheading Using multiple @samp{TBLFM} lines
+
+@cindex multiple formula lines
+@cindex @samp{TBLFM} keywords, multiple
+@cindex @samp{TBLFM}, switching
 
-You may apply the formula temporarily.  This is useful when you
-switch the formula.  Place multiple @code{#+TBLFM} lines right
-after the table, and then press @kbd{C-c C-c} on the formula to
-apply.  Here is an example:
+@kindex C-c C-c
+You may apply the formula temporarily.  This is useful when you want
+to switch the formula applied to the table.  Place multiple @samp{TBLFM}
+keywords right after the table, and then press @kbd{C-c C-c} on
+the formula to apply.  Here is an example:
 
 @example
 | x | y |
@@ -3072,8 +3074,9 @@ Pressing @kbd{C-c C-c} in the line of @samp{#+TBLFM: 
$2=$1*2} yields:
 @end example
 
 @noindent
-Note: If you recalculate this table (with @kbd{C-u C-c *}, for example), you
-will get the following result of applying only the first @code{#+TBLFM} line.
+If you recalculate this table, with @kbd{C-u C-c *}, for example,
+you get the following result from applying only the first @samp{TBLFM}
+keyword.
 
 @example
 | x | y |
@@ -3084,74 +3087,87 @@ will get the following result of applying only the 
first @code{#+TBLFM} line.
 #+TBLFM: $2=$1*2
 @end example
 
+@anchor{Debugging formulas}
 @subsubheading Debugging formulas
+
 @cindex formula debugging
 @cindex debugging, of table formulas
+
 When the evaluation of a formula leads to an error, the field content
-becomes the string @samp{#ERROR}.  If you would like see what is going
-on during variable substitution and calculation in order to find a bug,
-turn on formula debugging in the @code{Tbl} menu and repeat the
-calculation, for example by pressing @kbd{C-u C-u C-c = @key{RET}} in a
-field.  Detailed information will be displayed.
+becomes the string @samp{#ERROR}.  If you would like to see what is going
+on during variable substitution and calculation in order to find
+a bug, turn on formula debugging in the Tbl menu and repeat the
+calculation, for example by pressing @kbd{C-u C-u C-c = @key{RET}} in
+a field.  Detailed information are displayed.
 
 @node Updating the table
 @subsection Updating the table
+
 @cindex recomputing table fields
 @cindex updating, table
 
 Recalculation of a table is normally not automatic, but needs to be
-triggered by a command.  See @ref{Advanced features}, for a way to make
-recalculation at least semi-automatic.
+triggered by a command.  To make recalculation at least
+semi-automatic, see @ref{Advanced features}.
 
 In order to recalculate a line of a table or the entire table, use the
 following commands:
 
-@table @kbd
-@orgcmd{C-c *,org-table-recalculate}
-Recalculate the current row by first applying the stored column formulas
-from left to right, and all field/range formulas in the current row.
-@c
+@table @asis
+@item @kbd{C-c *} (@code{org-table-recalculate})
+@kindex C-c *
+@findex org-table-recalculate
+Recalculate the current row by first applying the stored column
+formulas from left to right, and all field/range formulas in the
+current row.
+
+@item @kbd{C-u C-c *} or @kbd{C-u C-c C-c}
 @kindex C-u C-c *
-@item C-u C-c *
 @kindex C-u C-c C-c
-@itemx C-u C-c C-c
-Recompute the entire table, line by line.  Any lines before the first
-hline are left alone, assuming that these are part of the table header.
-@c
-@orgcmdkkc{C-u C-u C-c *,C-u C-u C-c C-c,org-table-iterate}
+Recompute the entire table, line by line.  Any lines before the
+first hline are left alone, assuming that these are part of the
+table header.
+
+@item @kbd{C-u C-u C-c *} or @kbd{C-u C-u C-c C-c} (@code{org-table-iterate})
+@kindex C-u C-u C-c *
+@kindex C-u C-u C-c C-c
+@findex org-table-iterate
 Iterate the table by recomputing it until no further changes occur.
 This may be necessary if some computed fields use the value of other
-fields that are computed @i{later} in the calculation sequence.
-@item M-x org-table-recalculate-buffer-tables @key{RET}
+fields that are computed @emph{later} in the calculation sequence.
+
+@item @kbd{M-x org-table-recalculate-buffer-tables}
 @findex org-table-recalculate-buffer-tables
 Recompute all tables in the current buffer.
-@item M-x org-table-iterate-buffer-tables @key{RET}
+
+@item @kbd{M-x org-table-iterate-buffer-tables}
 @findex org-table-iterate-buffer-tables
-Iterate all tables in the current buffer, in order to converge table-to-table
-dependencies.
+Iterate all tables in the current buffer, in order to converge
+table-to-table dependencies.
 @end table
 
 @node Advanced features
 @subsection Advanced features
 
-If you want the recalculation of fields to happen automatically, or if you
-want to be able to assign @i{names}@footnote{Such names must start by an
-alphabetic character and use only alphanumeric/underscore characters.} to
-fields and columns, you need to reserve the first column of the table for
-special marking characters.
-
-@table @kbd
-@orgcmd{C-#,org-table-rotate-recalc-marks}
-Rotate the calculation mark in first column through the states @samp{ },
-@samp{#}, @samp{*}, @samp{!}, @samp{$}.  When there is an active region,
-change all marks in the region.
+If you want the recalculation of fields to happen automatically, or if
+you want to be able to assign @emph{names}@footnote{Such names must start with 
an alphabetic character and use
+only alphanumeric/underscore characters.} to fields and columns,
+you need to reserve the first column of the table for special marking
+characters.
+
+@table @asis
+@item @kbd{C-#} (@code{org-table-rotate-recalc-marks})
+@kindex C-#
+@findex org-table-rotate-recalc-marks
+Rotate the calculation mark in first column through the states @samp{#},
+@samp{*}, @samp{!}, @samp{$}.  When there is an active region, change all 
marks in
+the region.
 @end table
 
-Here is an example of a table that collects exam results of students and
-makes use of these features:
+Here is an example of a table that collects exam results of students
+and makes use of these features:
 
 @example
-@group
 |---+---------+--------+--------+--------+-------+------|
 |   | Student | Prob 1 | Prob 2 | Prob 3 | Total | Note |
 |---+---------+--------+--------+--------+-------+------|
@@ -3167,61 +3183,61 @@ makes use of these features:
 | $ | max=50  |        |        |        |       |      |
 |---+---------+--------+--------+--------+-------+------|
 #+TBLFM: $6=vsum($P1..$P3)::$7=10*$Tot/$max;%.1f::$at=vmean(@@-II..@@-I);%.1f
-@end group
 @end example
 
-@noindent @b{Important}: please note that for these special tables,
-recalculating the table with @kbd{C-u C-c *} will only affect rows that
-are marked @samp{#} or @samp{*}, and fields that have a formula assigned
-to the field itself.  The column formulas are not applied in rows with
-empty first field.
+@quotation Important
+Please note that for these special tables, recalculating the table
+with @kbd{C-u C-c *} only affects rows that are marked @samp{#} or
+@samp{*}, and fields that have a formula assigned to the field itself.  The
+column formulas are not applied in rows with empty first field.
+
+@end quotation
 
 @cindex marking characters, tables
 The marking characters have the following meaning:
 
-@table @samp
-@item !
-The fields in this line define names for the columns, so that you may
-refer to a column as @samp{$Tot} instead of @samp{$6}.
-@item ^
+@table @asis
+@item @samp{!}
+The fields in this line define names for the columns, so that you
+may refer to a column as @samp{$Tot} instead of @samp{$6}.
+
+@item @samp{^}
 This row defines names for the fields @emph{above} the row.  With such
-a definition, any formula in the table may use @samp{$m1} to refer to
-the value @samp{10}.  Also, if you assign a formula to a names field, it
-will be stored as @samp{$name=...}.
-@item _
-Similar to @samp{^}, but defines names for the fields in the row
-@emph{below}.
-@item $
+a definition, any formula in the table may use @samp{$m1} to refer to the
+value @samp{10}.  Also, if you assign a formula to a names field, it is
+stored as @samp{$name = ...}.
+
+@item @samp{_}
+Similar to @samp{^}, but defines names for the fields in the row @emph{below}.
+
+@item @samp{$}
 Fields in this row can define @emph{parameters} for formulas.  For
-example, if a field in a @samp{$} row contains @samp{max=50}, then
-formulas in this table can refer to the value 50 using @samp{$max}.
-Parameters work exactly like constants, only that they can be defined on
-a per-table basis.
-@item #
+example, if a field in a @samp{$} row contains @samp{max=50}, then formulas in
+this table can refer to the value 50 using @samp{$max}.  Parameters work
+exactly like constants, only that they can be defined on a per-table
+basis.
+
+@item @samp{#}
 Fields in this row are automatically recalculated when pressing
-@key{TAB} or @key{RET} or @kbd{S-@key{TAB}} in this row.  Also, this row
-is selected for a global recalculation with @kbd{C-u C-c *}.  Unmarked
-lines will be left alone by this command.
-@item *
-Selects this line for global recalculation with @kbd{C-u C-c *}, but
-not for automatic recalculation.  Use this when automatic
+@kbd{@key{TAB}} or @kbd{@key{RET}} or @kbd{S-@key{TAB}} in this row.
+Also, this row is selected for a global recalculation with
+@kbd{C-u C-c *}.  Unmarked lines are left alone by this
+command.
+
+@item @samp{*}
+Selects this line for global recalculation with @kbd{C-u C-c *}, but not for 
automatic recalculation.  Use this when automatic
 recalculation slows down editing too much.
-@item @w{ }
-Unmarked lines are exempt from recalculation with @kbd{C-u C-c *}.
-All lines that should be recalculated should be marked with @samp{#}
-or @samp{*}.
-@item /
-Do not export this line.  Useful for lines that contain the narrowing
-@samp{<N>} markers or column group markers.
+
+@item @samp{/}
+Do not export this line.  Useful for lines that contain the
+narrowing @samp{<N>} markers or column group markers.
 @end table
 
 Finally, just to whet your appetite for what can be done with the
-fantastic @file{calc.el} package, here is a table that computes the Taylor
-series of degree @code{n} at location @code{x} for a couple of
-functions.
+fantastic Calc package, here is a table that computes the Taylor
+series of degree n at location x for a couple of functions.
 
 @example
-@group
 |---+-------------+---+-----+--------------------------------------|
 |   | Func        | n | x   | Result                               |
 |---+-------------+---+-----+--------------------------------------|
@@ -3233,29 +3249,28 @@ functions.
 | * | tan(x)      | 3 | x   | 0.0175 x + 1.77e-6 x^3               |
 |---+-------------+---+-----+--------------------------------------|
 #+TBLFM: $5=taylor($2,$4,$3);n3
-@end group
 @end example
 
-@node Org-Plot
-@section Org-Plot
+@node Org Plot
+@section Org Plot
+
 @cindex graph, in tables
 @cindex plot tables using Gnuplot
-@cindex @code{#+PLOT}
 
-Org-Plot can produce graphs of information stored in org tables, either
-graphically or in ASCII-art.
+Org Plot can produce graphs of information stored in Org tables,
+either graphically or in ASCII art.
 
-@subheading Graphical plots using @file{Gnuplot}
+@anchor{Graphical plots using Gnuplot}
+@subheading Graphical plots using Gnuplot
 
-Org-Plot produces 2D and 3D graphs using @file{Gnuplot}
-@uref{http://www.gnuplot.info/} and @file{gnuplot-mode}
-@uref{http://xafs.org/BruceRavel/GnuplotMode}.  To see this in action, ensure
-that you have both Gnuplot and Gnuplot mode installed on your system, then
-call @kbd{C-c " g} or @kbd{M-x org-plot/gnuplot @key{RET}} on the following
-table.
+@cindex @samp{PLOT}, keyword
+Org Plot can produce 2D and 3D graphs of information stored in Org
+tables using @uref{http://www.gnuplot.info/, Gnuplot} and 
@uref{http://cars9.uchicago.edu/~ravel/software/gnuplot-mode.html, Gnuplot 
mode}.  To see this in action, ensure
+that you have both Gnuplot and Gnuplot mode installed on your system,
+then call @kbd{C-c " g} or @kbd{M-x org-plot/gnuplot} on the
+following table.
 
 @example
-@group
 #+PLOT: title:"Citas" ind:1 deps:(3) type:2d with:histograms set:"yrange [0:]"
 | Sede      | Max cites | H-index |
 |-----------+-----------+---------|
@@ -3264,79 +3279,78 @@ table.
 | Sao Paolo |     71.00 |   11.50 |
 | Stockholm |    134.19 |   14.33 |
 | Morelia   |    257.56 |   17.67 |
-@end group
 @end example
 
-Notice that Org Plot is smart enough to apply the table's headers as labels.
-Further control over the labels, type, content, and appearance of plots can
-be exercised through the @code{#+PLOT:} lines preceding a table.  See below
-for a complete list of Org-plot options.  The @code{#+PLOT:} lines are
-optional.  For more information and examples see the Org-plot tutorial at
-@uref{https://orgmode.org/worg/org-tutorials/org-plot.html}.
+Notice that Org Plot is smart enough to apply the table's headers as
+labels.  Further control over the labels, type, content, and
+appearance of plots can be exercised through the @samp{PLOT} keyword
+preceding a table.  See below for a complete list of Org Plot options.
+For more information and examples see the 
@uref{https://orgmode.org/worg/org-tutorials/org-plot.html, Org Plot tutorial}.
 
-@subsubheading Plot Options
+@anchor{Plot options}
+@subsubheading Plot options
 
-@table @code
-@item set
-Specify any @command{gnuplot} option to be set when graphing.
+@table @asis
+@item @samp{set}
+Specify any Gnuplot option to be set when graphing.
 
-@item title
+@item @samp{title}
 Specify the title of the plot.
 
-@item ind
-Specify which column of the table to use as the @code{x} axis.
+@item @samp{ind}
+Specify which column of the table to use as the @samp{x} axis.
 
-@item deps
-Specify the columns to graph as a Lisp style list, surrounded by parentheses
-and separated by spaces for example @code{dep:(3 4)} to graph the third and
-fourth columns (defaults to graphing all other columns aside from the 
@code{ind}
-column).
+@item @samp{deps}
+Specify the columns to graph as a Lisp style list, surrounded by
+parentheses and separated by spaces for example @samp{dep:(3 4)} to graph
+the third and fourth columns.  Defaults to graphing all other
+columns aside from the @samp{ind} column.
 
-@item type
-Specify whether the plot will be @code{2d}, @code{3d}, or @code{grid}.
+@item @samp{type}
+Specify whether the plot is @samp{2d}, @samp{3d}, or @samp{grid}.
 
-@item with
-Specify a @code{with} option to be inserted for every col being plotted
-(e.g., @code{lines}, @code{points}, @code{boxes}, @code{impulses}, etc...).
-Defaults to @code{lines}.
+@item @samp{with}
+Specify a @samp{with} option to be inserted for every column being
+plotted, e.g., @samp{lines}, @samp{points}, @samp{boxes}, @samp{impulses}.  
Defaults to
+@samp{lines}.
 
-@item file
-If you want to plot to a file, specify 
@code{"@var{path/to/desired/output-file}"}.
+@item @samp{file}
+If you want to plot to a file, specify
+@samp{"path/to/desired/output-file"}.
 
-@item labels
-List of labels to be used for the @code{deps} (defaults to the column headers
-if they exist).
+@item @samp{labels}
+List of labels to be used for the @samp{deps}.  Defaults to the column
+headers if they exist.
 
-@item line
+@item @samp{line}
 Specify an entire line to be inserted in the Gnuplot script.
 
-@item map
-When plotting @code{3d} or @code{grid} types, set this to @code{t} to graph a
-flat mapping rather than a @code{3d} slope.
-
-@item timefmt
-Specify format of Org mode timestamps as they will be parsed by Gnuplot.
-Defaults to @samp{%Y-%m-%d-%H:%M:%S}.
-
-@item script
-If you want total control, you can specify a script file (place the file name
-between double-quotes) which will be used to plot.  Before plotting, every
-instance of @code{$datafile} in the specified script will be replaced with
-the path to the generated data file.  Note: even if you set this option, you
-may still want to specify the plot type, as that can impact the content of
-the data file.
+@item @samp{map}
+When plotting @samp{3d} or @samp{grid} types, set this to @samp{t} to graph a 
flat
+mapping rather than a @samp{3d} slope.
+
+@item @samp{timefmt}
+Specify format of Org mode timestamps as they will be parsed by
+Gnuplot.  Defaults to @samp{%Y-%m-%d-%H:%M:%S}.
+
+@item @samp{script}
+If you want total control, you can specify a script file---place the
+file name between double-quotes---which will be used to plot.
+Before plotting, every instance of @samp{$datafile} in the specified
+script will be replaced with the path to the generated data file.
+Note: even if you set this option, you may still want to specify the
+plot type, as that can impact the content of the data file.
 @end table
 
+@anchor{ASCII bar plots}
 @subheading ASCII bar plots
 
-While the cursor is on a column, typing @kbd{C-c " a} or
-@kbd{M-x orgtbl-ascii-plot @key{RET}} create a new column containing an
-ASCII-art bars plot.  The plot is implemented through a regular column
-formula.  When the source column changes, the bar plot may be updated by
-refreshing the table, for example typing @kbd{C-u C-c *}.
+While point is on a column, typing @kbd{C-c `` a} or @kbd{M-x 
orgtbl-ascii-plot} create a new column containing an ASCII-art bars
+plot.  The plot is implemented through a regular column formula.  When
+the source column changes, the bar plot may be updated by refreshing
+the table, for example typing @kbd{C-u C-c *}.
 
 @example
-@group
 | Sede          | Max cites |              |
 |---------------+-----------+--------------|
 | Chile         |    257.72 | WWWWWWWWWWWW |
@@ -3346,104 +3360,148 @@ refreshing the table, for example typing @kbd{C-u C-c 
*}.
 | Morelia       |    257.56 | WWWWWWWWWWWH |
 | Rochefourchat |      0.00 |              |
 #+TBLFM: $3='(orgtbl-ascii-draw $2 0.0 257.72 12)
-@end group
 @end example
 
-The formula is an elisp call:
-@lisp
-(orgtbl-ascii-draw COLUMN MIN MAX WIDTH)
-@end lisp
+The formula is an Elisp call.
 
-@table @code
-@item COLUMN
-  is a reference to the source column.
+@defun orgtbl-ascii-draw value min max &optional width
+Draw an ASCII bar in a table.
 
-@item MIN MAX
-  are the minimal and maximal values displayed.  Sources values
-  outside this range are displayed as @samp{too small}
-  or @samp{too large}.
+@var{VALUE} is the value to plot.
 
-@item WIDTH
-  is the width in characters of the bar-plot.  It defaults to @samp{12}.
+@var{MIN} is the value displayed as an empty bar.  @var{MAX}
+is the value filling all the @var{WIDTH}.  Sources values outside
+this range are displayed as @samp{too small} or @samp{too large}.
 
-@end table
+@var{WIDTH} is the number of characters of the bar plot.  It
+defaults to @samp{12}.
+@end defun
 
 @node Hyperlinks
 @chapter Hyperlinks
+
 @cindex hyperlinks
 
-Like HTML, Org provides links inside a file, external links to
-other files, Usenet articles, emails, and much more.
+Like HTML, Org provides support for links inside a file, external
+links to other files, Usenet articles, emails, and much more.
 
 @menu
-* Link format::                 How links in Org are formatted
-* Internal links::              Links to other places in the current file
-* External links::              URL-like links to the world
-* Handling links::              Creating, inserting and following
-* Using links outside Org::     Linking from my C source code?
-* Link abbreviations::          Shortcuts for writing complex links
-* Search options::              Linking to a specific location
-* Custom searches::             When the default search is not enough
+* Link Format::                  How links in Org are formatted.
+* Internal Links::               Links to other places in the current file.
+* Radio Targets::                Make targets trigger links in plain text.
+* External Links::               URL-like links to the world.
+* Handling Links::               Creating, inserting and following.
+* Using Links Outside Org::      Linking from my C source code?
+* Link Abbreviations::           Shortcuts for writing complex links.
+* Search Options::               Linking to a specific location.
+* Custom Searches::              When the default search is not enough.
 @end menu
 
-@node Link format
-@section Link format
+@node Link Format
+@section Link Format
+
 @cindex link format
 @cindex format, of links
 
-Org will recognize plain URL-like links and activate them as
-clickable links.  The general link format, however, looks like this:
+@cindex angle bracket links
+@cindex plain links
+Org recognizes plain URIs, possibly wrapped within angle
+brackets@footnote{Plain URIs are recognized only for a well-defined set of
+schemes.  See @ref{External Links}.  Unlike URI syntax, they cannot contain
+parenthesis or white spaces, either.  URIs within angle brackets have
+no such limitation.}, and activate them as clickable links.
+
+@cindex bracket links
+The general link format, however, looks like this:
 
 @example
-[[link][description]]       @r{or alternatively}           [[link]]
+[[LINK][DESCRIPTION]]
 @end example
 
+
 @noindent
-Once a link in the buffer is complete (all brackets present), Org
-will change the display so that @samp{description} is displayed instead
-of @samp{[[link][description]]} and @samp{link} is displayed instead of
-@samp{[[link]]}.  Links will be highlighted in the face @code{org-link},
-which by default is an underlined face.  You can directly edit the
-visible part of a link.  Note that this can be either the @samp{link}
-part (if there is no description) or the @samp{description} part.  To
-edit also the invisible @samp{link} part, use @kbd{C-c C-l} with the
-cursor on the link.
-
-If you place the cursor at the beginning or just behind the end of the
-displayed text and press @key{BACKSPACE}, you will remove the
-(invisible) bracket at that location.  This makes the link incomplete
-and the internals are again displayed as plain text.  Inserting the
-missing bracket hides the link internals again.  To show the
-internal structure of all links, use the menu entry
-@code{Org->Hyperlinks->Literal links}.
-
-@node Internal links
-@section Internal links
-@cindex internal links
+or alternatively
+
+@example
+[[LINK]]
+@end example
+
+
+@cindex escape syntax, for links
+@cindex backslashes, in links
+Some @samp{\} and @samp{]} characters in the @var{LINK} part need to be
+``escaped'', i.e., preceded by another @samp{\} character.  More
+specifically, the following character categories, and only them, must
+be escaped, in order:
+
+@enumerate
+@item
+all consecutive @samp{\} characters at the end of the link,
+@item
+any @samp{]} character at the very end of the link,
+@item
+all consecutive @samp{\} characters preceding @samp{][} or @samp{]]} patterns,
+@item
+any @samp{]} character followed by either @samp{[} or @samp{]}.
+@end enumerate
+
+@findex org-link-escape
+Org takes for granted that such links are correctly escaped.
+Functions inserting links (see @ref{Handling Links}) take care of this.
+You only need to bother about those rules when inserting directly, or
+yanking, a URI within square brackets.  When in doubt, you may use the
+function @code{org-link-escape}, which turns a link string into its
+properly escaped form.
+
+Once a link in the buffer is complete, with all brackets present, Org
+changes the display so that @samp{DESCRIPTION} is displayed instead of
+@samp{[[LINK][DESCRIPTION]]} and @samp{LINK} is displayed instead of 
@samp{[[LINK]]}.
+Links are highlighted in the @code{org-link} face, which, by default, is an
+underlined face.
+
+You can directly edit the visible part of a link.  This can be either
+the @var{LINK} part, if there is no description, or the
+@var{DESCRIPTION} part otherwise.  To also edit the invisible
+@var{LINK} part, use @kbd{C-c C-l} with point on the link
+(see @ref{Handling Links}).
+
+If you place point at the beginning or just behind the end of the
+displayed text and press @kbd{@key{BS}}, you remove
+the---invisible---bracket at that location@footnote{More accurately, the 
precise behavior depends on how point
+arrived there---see @ref{Invisible Text,Invisible Text,,elisp,}.}.  This makes 
the link
+incomplete and the internals are again displayed as plain text.
+Inserting the missing bracket hides the link internals again.  To show
+the internal structure of all links, use the menu: Org @arrow{} Hyperlinks 
@arrow{}
+Literal links.
+
+@node Internal Links
+@section Internal Links
+
+@cindex internal links
 @cindex links, internal
 @cindex targets, for links
 
-@cindex property, @code{CUSTOM_ID}
-If the link does not look like a URL, it is considered to be internal in the
-current file.  The most important case is a link like
-@samp{[[#my-custom-id]]} which will link to the entry with the
-@code{CUSTOM_ID} property @samp{my-custom-id}.  You are responsible yourself
-to make sure these custom IDs are unique in a file.
+@cindex @samp{CUSTOM_ID}, property
+If the link does not look like a URL, it is considered to be internal
+in the current file.  The most important case is a link like
+@samp{[[#my-custom-id]]} which links to the entry with the @samp{CUSTOM_ID} 
property
+@samp{my-custom-id}.  You are responsible yourself to make sure these
+custom IDs are unique in a file.
 
-Links such as @samp{[[My Target]]} or @samp{[[My Target][Find my target]]}
-lead to a text search in the current file.
+Links such as @samp{[[My Target]]} or @samp{[[My Target][Find my target]]} 
lead to a text search in
+the current file.
 
-The link can be followed with @kbd{C-c C-o} when the cursor is on the link,
-or with a mouse click (@pxref{Handling links}).  Links to custom IDs will
-point to the corresponding headline.  The preferred match for a text link is
-a @i{dedicated target}: the same string in double angular brackets, like
-@samp{<<My Target>>}.
+The link can be followed with @kbd{C-c C-o} when point is on
+the link, or with a mouse click (see @ref{Handling Links}).  Links to
+custom IDs point to the corresponding headline.  The preferred match
+for a text link is a @emph{dedicated target}: the same string in double
+angular brackets, like @samp{<<My Target>>}.
 
-@cindex @code{#+NAME}
-If no dedicated target exists, the link will then try to match the exact name
-of an element within the buffer.  Naming is done with the @code{#+NAME}
-keyword, which has to be put in the line before the element it refers to, as
-in the following example
+@cindex @samp{NAME}, keyword
+If no dedicated target exists, the link tries to match the exact name
+of an element within the buffer.  Naming is done with the @samp{NAME}
+keyword, which has to be put in the line before the element it refers
+to, as in the following example
 
 @example
 #+NAME: My Target
@@ -3452,23 +3510,23 @@ in the following example
 | of | four cells |
 @end example
 
-If none of the above succeeds, Org will search for a headline that is exactly
-the link text but may also include a TODO keyword and tags@footnote{To insert
-a link targeting a headline, in-buffer completion can be used.  Just type
-a star followed by a few optional letters into the buffer and press
-@kbd{M-@key{TAB}}.  All headlines in the current buffer will be offered as
-completions.}.
+If none of the above succeeds, Org searches for a headline that is
+exactly the link text but may also include a TODO keyword and
+tags@footnote{To insert a link targeting a headline, in-buffer completion
+can be used.  Just type a star followed by a few optional letters into
+the buffer and press @kbd{M-@key{TAB}}.  All headlines in the current
+buffer are offered as completions.}.
 
-During export, internal links will be used to mark objects and assign them
-a number.  Marked objects will then be referenced by links pointing to them.
-In particular, links without a description will appear as the number assigned
-to the marked object@footnote{When targeting a @code{#+NAME} keyword,
-@code{#+CAPTION} keyword is mandatory in order to get proper numbering
-(@pxref{Images and tables}).}.  In the following excerpt from an Org buffer
+During export, internal links are used to mark objects and assign them
+a number.  Marked objects are then referenced by links pointing to
+them.  In particular, links without a description appear as the number
+assigned to the marked object@footnote{When targeting a @samp{NAME} keyword, 
the @samp{CAPTION} keyword is
+mandatory in order to get proper numbering (see @ref{Captions}).}.  In the 
following excerpt from
+an Org buffer
 
 @example
-- one item
-- <<target>>another item
+1. one item
+2. <<target>>another item
 Here we refer to item [[target]].
 @end example
 
@@ -3476,354 +3534,477 @@ Here we refer to item [[target]].
 The last sentence will appear as @samp{Here we refer to item 2} when
 exported.
 
-In non-Org files, the search will look for the words in the link text.  In
-the above example the search would be for @samp{my target}.
+In non-Org files, the search looks for the words in the link text.  In
+the above example the search would be for @samp{target}.
 
 Following a link pushes a mark onto Org's own mark ring.  You can
-return to the previous position with @kbd{C-c &}.  Using this command
-several times in direct succession goes back to positions recorded
-earlier.
+return to the previous position with @kbd{C-c &}.  Using this
+command several times in direct succession goes back to positions
+recorded earlier.
 
-@menu
-* Radio targets::               Make targets trigger links in plain text
-@end menu
+@node Radio Targets
+@section Radio Targets
 
-@node Radio targets
-@subsection Radio targets
 @cindex radio targets
 @cindex targets, radio
 @cindex links, radio targets
 
-Org can automatically turn any occurrences of certain target names
-in normal text into a link.  So without explicitly creating a link, the
+Org can automatically turn any occurrences of certain target names in
+normal text into a link.  So without explicitly creating a link, the
 text connects to the target radioing its position.  Radio targets are
 enclosed by triple angular brackets.  For example, a target @samp{<<<My
 Target>>>} causes each occurrence of @samp{my target} in normal text to
-become activated as a link.  The Org file is scanned automatically
-for radio targets only when the file is first loaded into Emacs.  To
-update the target list during editing, press @kbd{C-c C-c} with the
-cursor on or at a target.
+become activated as a link.  The Org file is scanned automatically for
+radio targets only when the file is first loaded into Emacs.  To
+update the target list during editing, press @kbd{C-c C-c} with
+point on or at a target.
+
+@node External Links
+@section External Links
 
-@node External links
-@section External links
 @cindex links, external
 @cindex external links
-@cindex Gnus links
+@cindex attachment links
 @cindex BBDB links
-@cindex IRC links
-@cindex URL links
+@cindex Elisp links
 @cindex file links
-@cindex RMAIL links
-@cindex MH-E links
-@cindex USENET links
-@cindex SHELL links
+@cindex Gnus links
+@cindex Help links
+@cindex IRC links
 @cindex Info links
-@cindex Elisp links
+@cindex MH-E links
+@cindex Rmail links
+@cindex shell links
+@cindex URL links
+@cindex Usenet links
 
 Org supports links to files, websites, Usenet and email messages, BBDB
 database entries and links to both IRC conversations and their logs.
-External links are URL-like locators.  They start with a short identifying
-string followed by a colon.  There can be no space after the colon.  The
-following list shows examples for each link type.
-
-@example
-https://api.uva.nl/                          @r{on the web}
-doi:10.1000/182                              @r{DOI for an electronic resource}
-file:/home/dominik/images/jupiter.jpg        @r{file, absolute path}
-/home/dominik/images/jupiter.jpg             @r{same as above}
-file:papers/last.pdf                         @r{file, relative path}
-./papers/last.pdf                            @r{same as above}
-file:/ssh:myself@@some.where:papers/last.pdf  @r{file, path on remote machine}
-/ssh:myself@@some.where:papers/last.pdf       @r{same as above}
-file:sometextfile::NNN                       @r{file, jump to line number}
-file:projects.org                            @r{another Org file}
-file:projects.org::some words                @r{text search in Org 
file}@footnote{
-The actual behavior of the search will depend on the value of
-the option @code{org-link-search-must-match-exact-headline}.  If its value
-is @code{nil}, then a fuzzy text search will be done.  If it is @code{t}, then 
only
-the exact headline will be matched, ignoring spaces and cookies.  If the
-value is @code{query-to-create}, then an exact headline will be searched; if
-it is not found, then the user will be queried to create it.}
-file:projects.org::*task title               @r{heading search in Org 
file}@footnote{
-Headline searches always match the exact headline, ignoring
-spaces and cookies.  If the headline is not found and the value of the option
-@code{org-link-search-must-match-exact-headline} is @code{query-to-create},
-then the user will be queried to create it.}
-docview:papers/last.pdf::NNN                 @r{open in doc-view mode at page}
-id:B7423F4D-2E8A-471B-8810-C40F074717E9      @r{Link to heading by ID}
-news:comp.emacs                              @r{Usenet link}
-mailto:adent@@galaxy.net                      @r{Mail link}
-mhe:folder                                   @r{MH-E folder link}
-mhe:folder#id                                @r{MH-E message link}
-rmail:folder                                 @r{RMAIL folder link}
-rmail:folder#id                              @r{RMAIL message link}
-gnus:group                                   @r{Gnus group link}
-gnus:group#id                                @r{Gnus article link}
-bbdb:R.*Stallman                             @r{BBDB link (with regexp)}
-irc:/irc.com/#emacs/bob                      @r{IRC link}
-info:org#External links                      @r{Info node or index link}
-shell:ls *.org                               @r{A shell command}
-elisp:org-agenda                             @r{Interactive Elisp command}
-elisp:(find-file-other-frame "Elisp.org")    @r{Elisp form to evaluate}
-@end example
+External links are URL-like locators.  They start with a short
+identifying string followed by a colon.  There can be no space after
+the colon.
 
-@cindex VM links
-@cindex WANDERLUST links
-On top of these built-in link types, some are available through the
-@code{contrib/} directory (@pxref{Installation}).  For example, these links
-to VM or Wanderlust messages are available when you load the corresponding
-libraries from the @code{contrib/} directory:
+Here is the full set of built-in link types:
 
-@example
-vm:folder                                    @r{VM folder link}
-vm:folder#id                                 @r{VM message link}
-vm://myself@@some.where.org/folder#id         @r{VM on remote machine}
-vm-imap:account:folder                       @r{VM IMAP folder link}
-vm-imap:account:folder#id                    @r{VM IMAP message link}
-wl:folder                                    @r{WANDERLUST folder link}
-wl:folder#id                                 @r{WANDERLUST message link}
-@end example
+@table @asis
+@item @samp{file}
+File links.  File name may be remote, absolute, or relative.
+
+Additionally, you can specify a line number, or a text search.
+In Org files, you may link to a headline name, a custom ID, or a
+code reference instead.
+
+As a special case, ``file'' prefix may be omitted if the file name
+is complete, e.g., it starts with @samp{./}, or @samp{/}.
+
+@item @samp{attachment}
+Same as file links but for files and folders attached to the current
+node (see @ref{Attachments}).  Attachment links are intended to behave
+exactly as file links but for files relative to the attachment
+directory.
+
+@item @samp{bbdb}
+Link to a BBDB record, with possible regexp completion.
+
+@item @samp{docview}
+Link to a document opened with DocView mode.  You may specify a page
+number.
+
+@item @samp{doi}
+Link to an electronic resource, through its handle.
+
+@item @samp{elisp}
+Execute an Elisp command upon activation.
+
+@item @samp{gnus}, @samp{rmail}, @samp{mhe}
+Link to messages or folders from a given Emacs' MUA@.
+
+@item @samp{help}
+Display documentation of a symbol in @samp{*Help*} buffer.
+
+@item @samp{http}, @samp{https}
+Web links.
+
+@item @samp{id}
+Link to a specific headline by its ID property, in an Org file.
+
+@item @samp{info}
+Link to an Info manual, or to a specific node.
+
+@item @samp{irc}
+Link to an IRC channel.
+
+@item @samp{mailto}
+Link to message composition.
+
+@item @samp{news}
+Usenet links.
+
+@item @samp{shell}
+Execute a shell command upon activation.
+@end table
+
+The following table illustrates the link types above, along with their
+options:
+
+@multitable {aaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@headitem Link Type
+@tab Example
+@item http
+@tab @samp{http://staff.science.uva.nl/c.dominik/}
+@item https
+@tab @samp{https://orgmode.org/}
+@item doi
+@tab @samp{doi:10.1000/182}
+@item file
+@tab @samp{file:/home/dominik/images/jupiter.jpg}
+@item
+@tab @samp{/home/dominik/images/jupiter.jpg} (same as above)
+@item
+@tab @samp{file:papers/last.pdf}
+@item
+@tab @samp{./papers/last.pdf} (same as above)
+@item
+@tab @samp{file:/ssh:me@@some.where:papers/last.pdf} (remote)
+@item
+@tab @samp{/ssh:me@@some.where:papers/last.pdf} (same as above)
+@item
+@tab @samp{file:sometextfile::NNN} (jump to line number)
+@item
+@tab @samp{file:projects.org}
+@item
+@tab @samp{file:projects.org::some words} (text search) @footnote{The actual 
behavior of the search depends on the value of the
+variable @code{org-link-search-must-match-exact-headline}.  If its value is
+@code{nil}, then a fuzzy text search is done.  If it is @code{t}, then only the
+exact headline is matched, ignoring spaces and statistic cookies.  If
+the value is @code{query-to-create}, then an exact headline is searched; if
+it is not found, then the user is queried to create it.}
+@item
+@tab @samp{file:projects.org::*task title} (headline search)
+@item
+@tab @samp{file:projects.org::#custom-id} (headline search)
+@item attachment
+@tab @samp{attachment:projects.org}
+@item
+@tab @samp{attachment:projects.org::some words} (text search)
+@item docview
+@tab @samp{docview:papers/last.pdf::NNN}
+@item id
+@tab @samp{id:B7423F4D-2E8A-471B-8810-C40F074717E9}
+@item news
+@tab @samp{news:comp.emacs}
+@item mailto
+@tab @samp{mailto:adent@@galaxy.net}
+@item mhe
+@tab @samp{mhe:folder} (folder link)
+@item
+@tab @samp{mhe:folder#id} (message link)
+@item rmail
+@tab @samp{rmail:folder} (folder link)
+@item
+@tab @samp{rmail:folder#id} (message link)
+@item gnus
+@tab @samp{gnus:group} (group link)
+@item
+@tab @samp{gnus:group#id} (article link)
+@item bbdb
+@tab @samp{bbdb:R.*Stallman} (record with regexp)
+@item irc
+@tab @samp{irc:/irc.com/#emacs/bob}
+@item help
+@tab @samp{help:org-store-link}
+@item info
+@tab @samp{info:org#External links}
+@item shell
+@tab @samp{shell:ls *.org}
+@item elisp
+@tab @samp{elisp:(find-file "Elisp.org")} (Elisp form to evaluate)
+@item
+@tab @samp{elisp:org-agenda} (interactive Elisp command)
+@end multitable
+
+@cindex VM links
+@cindex Wanderlust links
+On top of these built-in link types, additional ones are available
+through the @samp{contrib/} directory (see @ref{Installation}).  For example,
+these links to VM or Wanderlust messages are available when you load
+the corresponding libraries from the @samp{contrib/} directory:
+
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{vm:folder}
+@tab VM folder link
+@item @samp{vm:folder#id}
+@tab VM message link
+@item @samp{vm://myself@@some.where.org/folder#id}
+@tab VM on remote machine
+@item @samp{vm-imap:account:folder}
+@tab VM IMAP folder link
+@item @samp{vm-imap:account:folder#id}
+@tab VM IMAP message link
+@item @samp{wl:folder}
+@tab Wanderlust folder link
+@item @samp{wl:folder#id}
+@tab Wanderlust message link
+@end multitable
 
-For customizing Org to add new link types @ref{Adding hyperlink types}.
+For information on customizing Org to add new link types, see @ref{Adding 
Hyperlink Types}.
 
-A link should be enclosed in double brackets and may contain a descriptive
-text to be displayed instead of the URL (@pxref{Link format}), for example:
+A link should be enclosed in double brackets and may contain
+descriptive text to be displayed instead of the URL (see @ref{Link Format}), 
for example:
 
 @example
-[[https://www.gnu.org/software/emacs/][GNU Emacs]]
+[[http://www.gnu.org/software/emacs/][GNU Emacs]]
 @end example
 
-@noindent
+
 If the description is a file name or URL that points to an image, HTML
-export (@pxref{HTML export}) will inline the image as a clickable
-button.  If there is no description at all and the link points to an
-image,
-that image will be inlined into the exported HTML file.
+export (see @ref{HTML Export}) inlines the image as a clickable button.  If
+there is no description at all and the link points to an image, that
+image is inlined into the exported HTML file.
 
 @cindex square brackets, around links
+@cindex angular brackets, around links
 @cindex plain text external links
-Org also finds external links in the normal text and activates them
+Org also recognizes external links amid normal text and activates them
 as links.  If spaces must be part of the link (for example in
-@samp{bbdb:Richard Stallman}), or if you need to remove ambiguities
-about the end of the link, enclose them in square brackets.
+@samp{bbdb:R.*Stallman}), or if you need to remove ambiguities about the
+end of the link, enclose the link in square or angular brackets.
+
+@node Handling Links
+@section Handling Links
 
-@node Handling links
-@section Handling links
 @cindex links, handling
 
-Org provides methods to create a link in the correct syntax, to
-insert it into an Org file, and to follow the link.
+Org provides methods to create a link in the correct syntax, to insert
+it into an Org file, and to follow the link.
 
-@table @kbd
-@orgcmd{C-c l,org-store-link}
+@findex org-store-link
 @cindex storing links
-Store a link to the current location.  This is a @emph{global} command (you
-must create the key binding yourself) which can be used in any buffer to
-create a link.  The link will be stored for later insertion into an Org
-buffer (see below).  What kind of link will be created depends on the current
-buffer:
+The main function is @code{org-store-link}, called with @kbd{M-x 
org-store-link}.  Because of its importance, we suggest to bind it
+to a widely available key (see @ref{Activation}).  It stores a link to the
+current location.  The link is stored for later insertion into an Org
+buffer---see below.  The kind of link that is created depends on the
+current buffer:
 
-@b{Org mode buffers}@*
-For Org files, if there is a @samp{<<target>>} at the cursor, the link points
-to the target.  Otherwise it points to the current headline, which will also
-be the description@footnote{If the headline contains a timestamp, it will be
-removed from the link and result in a wrong link---you should avoid putting
-timestamp in the headline.}.
+@table @asis
+@item @emph{Org mode buffers}
+For Org files, if there is a @samp{<<target>>} at point, the link points
+to the target.  Otherwise it points to the current headline, which
+is also the description@footnote{If the headline contains a timestamp, it is 
removed from the
+link, which results in a wrong link---you should avoid putting
+a timestamp in the headline.}.
 
 @vindex org-id-link-to-org-use-id
-@cindex property, @code{CUSTOM_ID}
-@cindex property, @code{ID}
-If the headline has a @code{CUSTOM_ID} property, a link to this custom ID
-will be stored.  In addition or alternatively (depending on the value of
-@code{org-id-link-to-org-use-id}), a globally unique @code{ID} property will
-be created and/or used to construct a link@footnote{The library
-@file{org-id.el} must first be loaded, either through @code{org-customize} by
-enabling @code{org-id} in @code{org-modules}, or by adding @code{(require
-'org-id)} in your Emacs init file.}.  So using this command in Org buffers
-will potentially create two links: a human-readable from the custom ID, and
-one that is globally unique and works even if the entry is moved from file to
-file.  Later, when inserting the link, you need to decide which one to use.
-
-@b{Email/News clients: VM, Rmail, Wanderlust, MH-E, Gnus}@*
-Pretty much all Emacs mail clients are supported.  The link will point to the
-current article, or, in some GNUS buffers, to the group.  The description is
-constructed from the author and the subject.
-
-@b{Web browsers: Eww, W3 and W3M}@*
-Here the link will be the current URL, with the page title as description.
-
-@b{Contacts: BBDB}@*
-Links created in a BBDB buffer will point to the current entry.
-
-@b{Chat: IRC}@*
-@vindex org-irc-link-to-logs
-For IRC links, if you set the option @code{org-irc-link-to-logs} to @code{t},
-a @samp{file:/} style link to the relevant point in the logs for the current
-conversation is created.  Otherwise an @samp{irc:/} style link to the
-user/channel/server under the point will be stored.
-
-@b{Other files}@*
-For any other files, the link will point to the file, with a search string
-(@pxref{Search options}) pointing to the contents of the current line.  If
-there is an active region, the selected words will form the basis of the
-search string.  If the automatically created link is not working correctly or
-accurately enough, you can write custom functions to select the search string
-and to do the search for particular file types---see @ref{Custom searches}.
-The key binding @kbd{C-c l} is only a suggestion---see @ref{Installation}.
-
-@b{Agenda view}@*
-When the cursor is in an agenda view, the created link points to the
+@cindex @samp{CUSTOM_ID}, property
+@cindex @samp{ID}, property
+If the headline has a @samp{CUSTOM_ID} property, store a link to this
+custom ID@.  In addition or alternatively, depending on the value of
+@code{org-id-link-to-org-use-id}, create and/or use a globally unique
+@samp{ID} property for the link@footnote{The Org Id library must first be 
loaded, either through
+@code{org-customize}, by enabling @code{id} in @code{org-modules}, or by adding
+@samp{(require 'org-id)} in your Emacs init file.}.  So using this command in 
Org
+buffers potentially creates two links: a human-readable link from
+the custom ID, and one that is globally unique and works even if the
+entry is moved from file to file.  Later, when inserting the link,
+you need to decide which one to use.
+
+@item @emph{Email/News clients: VM, Rmail, Wanderlust, MH-E, Gnus}
+@vindex org-link-email-description-format
+Pretty much all Emacs mail clients are supported.  The link points
+to the current article, or, in some Gnus buffers, to the group.  The
+description is constructed according to the variable
+@code{org-link-email-description-format}.  By default, it refers to the
+addressee and the subject.
+
+@item @emph{Web browsers: W3, W3M and EWW}
+Here the link is the current URL, with the page title as the
+description.
+
+@item @emph{Contacts: BBDB}
+Links created in a BBDB buffer point to the current entry.
+
+@item @emph{Chat: IRC}
+@vindex org-irc-links-to-logs
+For IRC links, if the variable @code{org-irc-link-to-logs} is non-@code{nil},
+create a @samp{file} style link to the relevant point in the logs for the
+current conversation.  Otherwise store an @samp{irc} style link to the
+user/channel/server under the point.
+
+@item @emph{Other files}
+For any other file, the link points to the file, with a search
+string (see @ref{Search Options}) pointing to the contents
+of the current line.  If there is an active region, the selected
+words form the basis of the search string. You can write custom Lisp
+functions to select the search string and perform the search for
+particular file types (see @ref{Custom Searches}).
+
+You can also define dedicated links to other files.  See @ref{Adding Hyperlink 
Types}.
+
+@item @emph{Agenda view}
+When point is in an agenda view, the created link points to the
 entry referenced by the current line.
+@end table
+
+From an Org buffer, the following commands create, navigate or, more
+generally, act on links.
 
-@c
-@orgcmd{C-c C-l,org-insert-link}
+@table @asis
+@item @kbd{C-c C-l} (@code{org-insert-link})
+@kindex C-c C-l
+@findex org-insert-link
 @cindex link completion
 @cindex completion, of links
 @cindex inserting links
-@vindex org-keep-stored-link-after-insertion
-@vindex org-link-parameters
-Insert a link@footnote{Note that you don't have to use this command to
-insert a link.  Links in Org are plain text, and you can type or paste them
-straight into the buffer.  By using this command, the links are automatically
-enclosed in double brackets, and you will be asked for the optional
-descriptive text.}.  This prompts for a link to be inserted into the buffer.
-You can just type a link, using text for an internal link, or one of the link
-type prefixes mentioned in the examples above.  The link will be inserted
-into the buffer@footnote{After insertion of a stored link, the link will be
-removed from the list of stored links.  To keep it in the list later use, use
-a triple @kbd{C-u} prefix argument to @kbd{C-c C-l}, or configure the option
-@code{org-keep-stored-link-after-insertion}.}, along with a descriptive text.
-If some text was selected when this command is called, the selected text
-becomes the default description.
-
-@b{Inserting stored links}@*
-All links stored during the
-current session are part of the history for this prompt, so you can access
-them with @key{UP} and @key{DOWN} (or @kbd{M-p/n}).
-
-@b{Completion support}@* Completion with @key{TAB} will help you to insert
-valid link prefixes like @samp{https:}, including the prefixes
-defined through link abbreviations (@pxref{Link abbreviations}).  If you
-press @key{RET} after inserting only the @var{prefix}, Org will offer
-specific completion support for some link types@footnote{This works if
-a completion function is defined in the @samp{:complete} property of a link
-in @code{org-link-parameters}.}  For example, if you type @kbd{file
-@key{RET}}, file name completion (alternative access: @kbd{C-u C-c C-l}, see
-below) will be offered, and after @kbd{bbdb @key{RET}} you can complete
+@vindex org-link-keep-stored-after-insertion
+Insert a link@footnote{Note that you do not have to use this command to insert
+a link.  Links in Org are plain text, and you can type or paste them
+straight into the buffer.  By using this command, the links are
+automatically enclosed in double brackets, and you will be asked for
+the optional descriptive text.}.  This prompts for a link to be inserted into
+the buffer.  You can just type a link, using text for an internal
+link, or one of the link type prefixes mentioned in the examples
+above.  The link is inserted into the buffer, along with
+a descriptive text@footnote{After insertion of a stored link, the link will be 
removed
+from the list of stored links.  To keep it in the list for later use,
+use a triple @kbd{C-u} prefix argument to @kbd{C-c C-l}, or
+configure the option @code{org-link-keep-stored-after-insertion}.}.  If some 
text was selected at this time,
+it becomes the default description.
+
+@table @asis
+@item @emph{Inserting stored links}
+All links stored during the current session are part of the
+history for this prompt, so you can access them with @kbd{@key{UP}}
+and @kbd{@key{DOWN}} (or @kbd{M-p}, @kbd{M-n}).
+
+@item @emph{Completion support}
+Completion with @kbd{@key{TAB}} helps you to insert valid link
+prefixes like @samp{http} or @samp{ftp}, including the prefixes defined
+through link abbreviations (see @ref{Link Abbreviations}).  If you
+press @kbd{@key{RET}} after inserting only the prefix, Org offers
+specific completion support for some link types@footnote{This works if a 
function has been defined in the @code{:complete}
+property of a link in @code{org-link-parameters}.}.  For
+example, if you type @kbd{f i l e @key{RET}}---alternative access:
+@kbd{C-u C-c C-l}, see below---Org offers file name
+completion, and after @kbd{b b d b @key{RET}} you can complete
 contact names.
-@orgkey C-u C-c C-l
+@end table
+
+@item @kbd{C-u C-c C-l}
 @cindex file name completion
 @cindex completion, of file names
-When @kbd{C-c C-l} is called with a @kbd{C-u} prefix argument, a link to
-a file will be inserted and you may use file name completion to select
-the name of the file.  The path to the file is inserted relative to the
-directory of the current Org file, if the linked file is in the current
-directory or in a sub-directory of it, or if the path is written relative
-to the current directory using @samp{../}.  Otherwise an absolute path
-is used, if possible with @samp{~/} for your home directory.  You can
-force an absolute path with two @kbd{C-u} prefixes.
-@c
-@item C-c C-l @ @r{(with cursor on existing link)}
-When the cursor is on an existing link, @kbd{C-c C-l} allows you to edit the
-link and description parts of the link.
-@c
+@kindex C-u C-c C-l
+When @kbd{C-c C-l} is called with a @kbd{C-u} prefix
+argument, insert a link to a file.  You may use file name completion
+to select the name of the file.  The path to the file is inserted
+relative to the directory of the current Org file, if the linked
+file is in the current directory or in a sub-directory of it, or if
+the path is written relative to the current directory using @samp{../}.
+Otherwise an absolute path is used, if possible with @samp{~/} for your
+home directory.  You can force an absolute path with two
+@kbd{C-u} prefixes.
+
+@item @kbd{C-c C-l} (with point on existing link)
 @cindex following links
-@orgcmd{C-c C-o,org-open-at-point}
+When point is on an existing link, @kbd{C-c C-l} allows you to
+edit the link and description parts of the link.
+
+@item @kbd{C-c C-o} (@code{org-open-at-point})
+@kindex C-c C-o
+@findex org-open-at-point
 @vindex org-file-apps
+Open link at point.  This launches a web browser for URL (using
+@code{browse-url-at-point}), run VM/MH-E/Wanderlust/Rmail/Gnus/BBDB for
+the corresponding links, and execute the command in a shell link.
+When point is on an internal link, this command runs the
+corresponding search.  When point is on the tags part of a headline,
+it creates the corresponding tags view (see @ref{Matching tags and 
properties}).  If point is on a timestamp, it compiles the agenda for
+that date.  Furthermore, it visits text and remote files in @samp{file}
+links with Emacs and select a suitable application for local
+non-text files.  Classification of files is based on file extension
+only.  See option @code{org-file-apps}.  If you want to override the
+default application and visit the file with Emacs, use
+a @kbd{C-u} prefix.  If you want to avoid opening in Emacs, use
+a @kbd{C-u C-u} prefix.
+
 @vindex org-link-frame-setup
-Open link at point.  This will launch a web browser for URLs (using
-@command{browse-url-at-point}), run VM/MH-E/Wanderlust/Rmail/Gnus/BBDB for
-the corresponding links, and execute the command in a shell link.  When the
-cursor is on an internal link, this command runs the corresponding search.
-When the cursor is on a TAG list in a headline, it creates the corresponding
-TAGS view.  If the cursor is on a timestamp, it compiles the agenda for that
-date.  Furthermore, it will visit text and remote files in @samp{file:} links
-with Emacs and select a suitable application for local non-text files.
-Classification of files is based on file extension only.  See option
-@code{org-file-apps}.  If you want to override the default application and
-visit the file with Emacs, use a @kbd{C-u} prefix.  If you want to avoid
-opening in Emacs, use a @kbd{C-u C-u} prefix.@*
-If the cursor is on a headline, but not on a link, offer all links in the
-headline and entry text.  If you want to setup the frame configuration for
-following links, customize @code{org-link-frame-setup}.
-
-@orgkey @key{RET}
+If point is on a headline, but not on a link, offer all links in the
+headline and entry text.  If you want to setup the frame
+configuration for following links, customize @code{org-link-frame-setup}.
+
+@item @kbd{@key{RET}}
 @vindex org-return-follows-link
-When @code{org-return-follows-link} is set, @kbd{@key{RET}} will also follow
+@kindex RET
+When @code{org-return-follows-link} is set, @kbd{@key{RET}} also follows
 the link at point.
-@c
+
+@item @kbd{mouse-2} or @kbd{mouse-1}
 @kindex mouse-2
 @kindex mouse-1
-@item mouse-2
-@itemx mouse-1
-On links, @kbd{mouse-1} and @kbd{mouse-2} will open the link just as @kbd{C-c
-C-o} would.
-@c
+On links, @kbd{mouse-1} and @kbd{mouse-2} opens the link
+just as @kbd{C-c C-o} does.
+
+@item @kbd{mouse-3}
+@vindex org-link-use-indirect-buffer-for-internals
 @kindex mouse-3
-@item mouse-3
-@vindex org-display-internal-link-with-indirect-buffer
-Like @kbd{mouse-2}, but force file links to be opened with Emacs, and
-internal links to be displayed in another window@footnote{See the
-option @code{org-display-internal-link-with-indirect-buffer}}.
-@c
-@orgcmd{C-c C-x C-v,org-toggle-inline-images}
-@cindex inlining images
-@cindex images, inlining
-@vindex org-startup-with-inline-images
-@cindex @code{inlineimages}, STARTUP keyword
-@cindex @code{noinlineimages}, STARTUP keyword
-Toggle the inline display of linked images.  Normally this will only inline
-images that have no description part in the link, i.e., images that will also
-be inlined during export.  When called with a prefix argument, also display
-images that do have a link description.  You can ask for inline images to be
-displayed at startup by configuring the variable
-@code{org-startup-with-inline-images}@footnote{with corresponding
-@code{#+STARTUP} keywords @code{inlineimages} and @code{noinlineimages}}.
-@orgcmd{C-c %,org-mark-ring-push}
+Like @kbd{mouse-2}, but force file links to be opened with
+Emacs, and internal links to be displayed in another window@footnote{See the 
variable @code{org-link-use-indirect-buffer-for-internals}.}.
+
+@item @kbd{C-c %} (@code{org-mark-ring-push})
+@kindex C-c %
+@findex org-mark-ring-push
 @cindex mark ring
-Push the current position onto the mark ring, to be able to return
-easily.  Commands following an internal link do this automatically.
-@c
-@orgcmd{C-c &,org-mark-ring-goto}
+Push the current position onto the Org mark ring, to be able to
+return easily.  Commands following an internal link do this
+automatically.
+
+@item @kbd{C-c &} (@code{org-mark-ring-goto})
+@kindex C-c &
+@findex org-mark-ring-goto
 @cindex links, returning to
 Jump back to a recorded position.  A position is recorded by the
-commands following internal links, and by @kbd{C-c %}.  Using this
-command several times in direct succession moves through a ring of
-previously recorded positions.
-@c
-@orgcmdkkcc{C-c C-x C-n,C-c C-x C-p,org-next-link,org-previous-link}
+commands following internal links, and by @kbd{C-c %}.  Using
+this command several times in direct succession moves through a ring
+of previously recorded positions.
+
+@item @kbd{C-c C-x C-n} (@code{org-next-link})
+@itemx @kbd{C-c C-x C-p} (@code{org-previous-link})
+@kindex C-c C-x C-p
+@findex org-previous-link
+@kindex C-c C-x C-n
+@findex org-next-link
 @cindex links, finding next/previous
-Move forward/backward to the next link in the buffer.  At the limit of
-the buffer, the search fails once, and then wraps around.  The key
-bindings for this are really too long; you might want to bind this also
-to @kbd{C-n} and @kbd{C-p}
+Move forward/backward to the next link in the buffer.  At the limit
+of the buffer, the search fails once, and then wraps around.  The
+key bindings for this are really too long; you might want to bind
+this also to @kbd{M-n} and @kbd{M-p}.
+
 @lisp
 (add-hook 'org-load-hook
-  (lambda ()
-    (define-key org-mode-map "\C-n" 'org-next-link)
-    (define-key org-mode-map "\C-p" 'org-previous-link)))
+          (lambda ()
+            (define-key org-mode-map "\M-n" 'org-next-link)
+            (define-key org-mode-map "\M-p" 'org-previous-link)))
 @end lisp
 @end table
 
-@node Using links outside Org
-@section Using links outside Org
+@node Using Links Outside Org
+@section Using Links Outside Org
 
-You can insert and follow links that have Org syntax not only in
-Org, but in any Emacs buffer.  For this, you should create two
-global commands, like this (please select suitable global keys
-yourself):
+@findex org-insert-link-global
+@findex org-open-at-point-global
+You can insert and follow links that have Org syntax not only in Org,
+but in any Emacs buffer.  For this, Org provides two functions:
+@code{org-insert-link-global} and @code{org-open-at-point-global}.
 
-@lisp
-(global-set-key "\C-c L" 'org-insert-link-global)
-(global-set-key "\C-c o" 'org-open-at-point-global)
-@end lisp
+You might want to bind them to globally available keys.  See
+@ref{Activation} for some advice.
+
+@node Link Abbreviations
+@section Link Abbreviations
 
-@node Link abbreviations
-@section Link abbreviations
 @cindex link abbreviations
 @cindex abbreviation, links
 
-Long URLs can be cumbersome to type, and often many similar links are
+Long URL can be cumbersome to type, and often many similar links are
 needed in a document.  For this you can use link abbreviations.  An
 abbreviated link looks like this
 
@@ -3831,83 +4012,86 @@ abbreviated link looks like this
 [[linkword:tag][description]]
 @end example
 
+
 @noindent
 @vindex org-link-abbrev-alist
-where the tag is optional.
-The @i{linkword} must be a word, starting with a letter, followed by
-letters, numbers, @samp{-}, and @samp{_}.  Abbreviations are resolved
-according to the information in the variable @code{org-link-abbrev-alist}
-that relates the linkwords to replacement text.  Here is an example:
-
-@smalllisp
-@group
+where the tag is optional.  The @emph{linkword} must be a word, starting
+with a letter, followed by letters, numbers, @samp{-}, and @samp{_}.
+Abbreviations are resolved according to the information in the
+variable @code{org-link-abbrev-alist} that relates the linkwords to
+replacement text.  Here is an example:
+
+@lisp
 (setq org-link-abbrev-alist
-  '(("bugzilla"  . "http://10.1.2.9/bugzilla/show_bug.cgi?id=";)
-    ("url-to-ja" . "http://translate.google.fr/translate?sl=en&tl=ja&u=%h";)
-    ("google"    . "http://www.google.com/search?q=";)
-    ("gmap"      . "http://maps.google.com/maps?q=%s";)
-    ("omap"      . "http://nominatim.openstreetmap.org/search?q=%s&polygon=1";)
-    ("ads"       . 
"http://adsabs.harvard.edu/cgi-bin/nph-abs_connect?author=%s&db_key=AST";)))
-@end group
-@end smalllisp
-
-If the replacement text contains the string @samp{%s}, it will be
-replaced with the tag.  Using @samp{%h} instead of @samp{%s} will
-url-encode the tag (see the example above, where we need to encode
-the URL parameter.)  Using @samp{%(my-function)} will pass the tag
-to a custom function, and replace it by the resulting string.
-
-If the replacement text doesn't contain any specifier, the tag will simply be
-appended in order to create the link.
-
-Instead of a string, you may also specify a function that will be
-called with the tag as the only argument to create the link.
+      '(("bugzilla"  . "http://10.1.2.9/bugzilla/show_bug.cgi?id=";)
+        ("url-to-ja" . "http://translate.google.fr/translate?sl=en&tl=ja&u=%h";)
+        ("google"    . "http://www.google.com/search?q=";)
+        ("gmap"      . "http://maps.google.com/maps?q=%s";)
+        ("omap"      . 
"http://nominatim.openstreetmap.org/search?q=%s&polygon=1";)
+        ("ads"       . 
"https://ui.adsabs.harvard.edu/search/q=%20author%3A\"%s\"";)))
+@end lisp
+
+If the replacement text contains the string @samp{%s}, it is replaced with
+the tag.  Using @samp{%h} instead of @samp{%s} percent-encodes the tag (see the
+example above, where we need to encode the URL parameter).  Using
+@samp{%(my-function)} passes the tag to a custom Lisp function, and replace
+it by the resulting string.
+
+If the replacement text do not contain any specifier, it is simply
+appended to the string in order to create the link.
+
+Instead of a string, you may also specify a Lisp function to create
+the link.  Such a function will be called with the tag as the only
+argument.
 
 With the above setting, you could link to a specific bug with
-@code{[[bugzilla:129]]}, search the web for @samp{OrgMode} with
-@code{[[google:OrgMode]]}, show the map location of the Free Software
-Foundation @code{[[gmap:51 Franklin Street, Boston]]} or of Carsten office
-@code{[[omap:Science Park 904, Amsterdam, The Netherlands]]} and find out
-what the Org author is doing besides Emacs hacking with
-@code{[[ads:Dominik,C]]}.
+@samp{[[bugzilla:129]]}, search the web for @samp{OrgMode} with 
@samp{[[google:OrgMode]]},
+show the map location of the Free Software Foundation @samp{[[gmap:51
+Franklin Street, Boston]]} or of Carsten office @samp{[[omap:Science Park 904,
+Amsterdam, The Netherlands]]} and find out what the Org author is doing
+besides Emacs hacking with @samp{[[ads:Dominik,C]]}.
 
 If you need special abbreviations just for a single Org buffer, you
 can define them in the file with
 
-@cindex @code{#+LINK}
+@cindex @samp{LINK}, keyword
 @example
 #+LINK: bugzilla  http://10.1.2.9/bugzilla/show_bug.cgi?id=
 #+LINK: google    http://www.google.com/search?q=%s
 @end example
 
-@noindent
-In-buffer completion (@pxref{Completion}) can be used after @samp{[} to
-complete link abbreviations.  You may also define a function 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.  You can add a completion function to a link like this:
+In-buffer completion (see @ref{Completion}) can be used after @samp{[} to
+complete link abbreviations.  You may also define a Lisp function 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 should return the full link with a prefix.  You can set
+the link completion function like this:
 
 @lisp
-(org-link-set-parameters ``type'' :complete #'some-function)
+(org-link-set-parameter "type" :complete #'some-completion-function)
 @end lisp
 
+@node Search Options
+@section Search Options in File Links
 
-@node Search options
-@section Search options in file links
 @cindex search option in file links
 @cindex file links, searching
+@cindex attachment links, searching
 
 File links can contain additional information to make Emacs jump to a
 particular location in the file when following a link.  This can be a
-line number or a search option after a double@footnote{For backward
-compatibility, line numbers can also follow a single colon.} colon.  For
-example, when the command @kbd{C-c l} creates a link (@pxref{Handling
-links}) to a file, it encodes the words in the current line as a search
-string that can be used to find this line back later when following the
-link with @kbd{C-c C-o}.
+line number or a search option after a double colon@footnote{For backward 
compatibility, line numbers can also follow a
+single colon.}.  For
+example, when the command @code{org-store-link} creates a link (see
+@ref{Handling Links}) to a file, it encodes the words in the current line
+as a search string that can be used to find this line back later when
+following the link with @kbd{C-c C-o}.
+
+Note that all search options apply for Attachment links in the same
+way that they apply for File links.
 
 Here is the syntax of the different ways to attach a search to a file
-link, together with an explanation:
+link, together with explanations for each:
 
 @example
 [[file:~/code/main.c::255]]
@@ -3915,102 +4099,105 @@ link, together with an explanation:
 [[file:~/xx.org::*My Target]]
 [[file:~/xx.org::#my-custom-id]]
 [[file:~/xx.org::/regexp/]]
+[[attachment:main.c::255]]
 @end example
 
-@table @code
-@item 255
+@table @asis
+@item @samp{255}
 Jump to line 255.
-@item My Target
+
+@item @samp{My Target}
 Search for a link target @samp{<<My Target>>}, or do a text search for
-@samp{my target}, similar to the search in internal links, see
-@ref{Internal links}.  In HTML export (@pxref{HTML export}), such a file
-link will become an HTML reference to the corresponding named anchor in
-the linked file.
-@item *My Target
+@samp{my target}, similar to the search in internal links, see @ref{Internal 
Links}.  In HTML export (see @ref{HTML Export}), such a file link becomes
+a HTML reference to the corresponding named anchor in the linked
+file.
+
+@item @samp{*My Target}
 In an Org file, restrict search to headlines.
-@item #my-custom-id
-Link to a heading with a @code{CUSTOM_ID} property
-@item /regexp/
-Do a regular expression search for @code{regexp}.  This uses the Emacs
-command @code{occur} to list all matches in a separate window.  If the
-target file is in Org mode, @code{org-occur} is used to create a
-sparse tree with the matches.
-@c If the target file is a directory,
-@c @code{grep} will be used to search all files in the directory.
+
+@item @samp{#my-custom-id}
+Link to a heading with a @samp{CUSTOM_ID} property
+
+@item @samp{/REGEXP/}
+Do a regular expression search for @var{REGEXP}.  This uses the
+Emacs command @code{occur} to list all matches in a separate window.  If
+the target file is in Org mode, @code{org-occur} is used to create
+a sparse tree with the matches.
 @end table
 
 As a degenerate case, a file link with an empty file name can be used
-to search the current file.  For example, @code{[[file:::find me]]} does
-a search for @samp{find me} in the current file, just as
-@samp{[[find me]]} would.
+to search the current file.  For example, @samp{[[file:::find me]]} does
+a search for @samp{find me} in the current file, just as @samp{[[find me]]}
+would.
 
-@node Custom searches
+@node Custom Searches
 @section Custom Searches
+
 @cindex custom search strings
 @cindex search strings, custom
 
 The default mechanism for creating search strings and for doing the
 actual search related to a file link may not work correctly in all
 cases.  For example, Bib@TeX{} database files have many entries like
-@samp{year="1993"} which would not result in good search strings,
-because the only unique identification for a Bib@TeX{} entry is the
-citation key.
+@code{year="1993"} which would not result in good search strings, because
+the only unique identification for a Bib@TeX{} entry is the citation key.
 
 @vindex org-create-file-search-functions
 @vindex org-execute-file-search-functions
-If you come across such a problem, you can write custom functions to set
-the right search string for a particular file type, and to do the search
-for the string in the file.  Using @code{add-hook}, these functions need
-to be added to the hook variables
+If you come across such a problem, you can write custom functions to
+set the right search string for a particular file type, and to do the
+search for the string in the file.  Using @code{add-hook}, these functions
+need to be added to the hook variables
 @code{org-create-file-search-functions} and
 @code{org-execute-file-search-functions}.  See the docstring for these
-variables for more information.  Org actually uses this mechanism
-for Bib@TeX{} database files, and you can use the corresponding code as
-an implementation example.  See the file @file{org-bibtex.el}.
+variables for more information.  Org actually uses this mechanism for
+Bib@TeX{} database files, and you can use the corresponding code as an
+implementation example.  See the file @samp{ol-bibtex.el}.
+
+@node TODO Items
+@chapter TODO Items
 
-@node TODO items
-@chapter TODO items
 @cindex TODO items
 
-Org mode does not maintain TODO lists as separate documents@footnote{Of
-course, you can make a document that contains only long lists of TODO items,
-but this is not required.}.  Instead, TODO items are an integral part of the
-notes file, because TODO items usually come up while taking notes!  With Org
-mode, simply mark any entry in a tree as being a TODO item.  In this way,
-information is not duplicated, and the entire context from which the TODO
-item emerged is always present.
+Org mode does not maintain TODO lists as separate documents@footnote{Of 
course, you can make a document that contains only long
+lists of TODO items, but this is not required.}.
+Instead, TODO items are an integral part of the notes file, because
+TODO items usually come up while taking notes!  With Org mode, simply
+mark any entry in a tree as being a TODO item.  In this way,
+information is not duplicated, and the entire context from which the
+TODO item emerged is always present.
 
 Of course, this technique for managing TODO items scatters them
-throughout your notes file.  Org mode compensates for this by providing
-methods to give you an overview of all the things that you have to do.
+throughout your notes file.  Org mode compensates for this by
+providing methods to give you an overview of all the things that you
+have to do.
 
 @menu
-* TODO basics::                 Marking and displaying TODO entries
-* TODO extensions::             Workflow and assignments
-* Progress logging::            Dates and notes for progress
-* Priorities::                  Some things are more important than others
-* Breaking down tasks::         Splitting a task into manageable pieces
-* Checkboxes::                  Tick-off lists
+* TODO Basics::                  Marking and displaying TODO entries.
+* TODO Extensions::              Workflow and assignments.
+* Progress Logging::             Dates and notes for progress.
+* Priorities::                   Some things are more important than others.
+* Breaking Down Tasks::          Splitting a task into manageable pieces.
+* Checkboxes::                   Tick-off lists.
 @end menu
 
-@node TODO basics
-@section Basic TODO functionality
+@node TODO Basics
+@section Basic TODO Functionality
 
-Any headline becomes a TODO item when it starts with the word
-@samp{TODO}, for example:
+Any headline becomes a TODO item when it starts with the word @samp{TODO},
+for example:
 
 @example
 *** TODO Write letter to Sam Fortune
 @end example
 
-@noindent
+
 The most important commands to work with TODO entries are:
 
-@table @kbd
-@orgcmd{C-c C-t,org-todo}
+@table @asis
+@item @kbd{C-c C-t} (@code{org-todo})
+@kindex C-c C-t
 @cindex cycling, of TODO states
-@vindex org-use-fast-todo-selection
-
 Rotate the TODO state of the current item among
 
 @example
@@ -4018,152 +4205,160 @@ Rotate the TODO state of the current item among
 '--------------------------------'
 @end example
 
-If TODO keywords have fast access keys (see @ref{Fast access to TODO
-states}), you will be prompted for a TODO keyword through the fast selection
+If TODO keywords have fast access keys (see @ref{Fast access to TODO states}), 
prompt for a TODO keyword through the fast selection
 interface; this is the default behavior when
 @code{org-use-fast-todo-selection} is non-@code{nil}.
 
-The same rotation can also be done ``remotely'' from agenda buffers with the
-@kbd{t} command key (@pxref{Agenda commands}).
-
-@orgkey{C-u C-c C-t}
-When TODO keywords have no selection keys, select a specific keyword using
-completion; otherwise force cycling through TODO states with no prompt.  When
-@code{org-use-fast-todo-selection} is set to @code{prefix}, use the fast
-selection interface.
+The same state changing can also be done ``remotely'' from the agenda
+buffer with the @kbd{t} command key (see @ref{Agenda Commands}).
 
+@item @kbd{S-@key{RIGHT}} @kbd{S-@key{LEFT}}
 @kindex S-RIGHT
 @kindex S-LEFT
-@item S-@key{RIGHT} @ @r{/} @ S-@key{LEFT}
 @vindex org-treat-S-cursor-todo-selection-as-state-change
-Select the following/preceding TODO state, similar to cycling.  Useful
-mostly if more than two TODO states are possible (@pxref{TODO
-extensions}).  See also @ref{Conflicts}, for a discussion of the interaction
-with @code{shift-selection-mode}.  See also the variable
+Select the following/preceding TODO state, similar to cycling.
+Useful mostly if more than two TODO states are possible (see
+@ref{TODO Extensions}).  See also @ref{Conflicts}, for a discussion of the 
interaction with
+shift-selection.  See also the variable
 @code{org-treat-S-cursor-todo-selection-as-state-change}.
-@orgcmd{C-c / t,org-show-todo-tree}
+
+@item @kbd{C-c / t} (@code{org-show-todo-tree})
+@kindex C-c / t
 @cindex sparse tree, for TODO
 @vindex org-todo-keywords
-View TODO items in a @emph{sparse tree} (@pxref{Sparse trees}).  Folds the
-entire buffer, but shows all TODO items (with not-DONE state) and the
-headings hierarchy above them.  With a prefix argument (or by using @kbd{C-c
-/ T}), search for a specific TODO@.  You will be prompted for the keyword,
-and you can also give a list of keywords like @code{KWD1|KWD2|...} to list
-entries that match any one of these keywords.  With a numeric prefix argument
-N, show the tree for the Nth keyword in the option @code{org-todo-keywords}.
-With two prefix arguments, find all TODO states, both un-done and done.
-@orgcmd{C-c a t,org-todo-list}
-Show the global TODO list.  Collects the TODO items (with not-DONE states)
-from all agenda files (@pxref{Agenda views}) into a single buffer.  The new
-buffer will be in @code{agenda-mode}, which provides commands to examine and
-manipulate the TODO entries from the new buffer (@pxref{Agenda commands}).
-@xref{Global TODO list}, for more information.
-@orgcmd{S-M-@key{RET},org-insert-todo-heading}
+@findex org-show-todo-tree
+View TODO items in a @emph{sparse tree} (see @ref{Sparse Trees}).  Folds the
+entire buffer, but shows all TODO items---with not-DONE state---and
+the headings hierarchy above them.  With a prefix argument, or by
+using @kbd{C-c / T}, search for a specific TODO@.  You are
+prompted for the keyword, and you can also give a list of keywords
+like @samp{KWD1|KWD2|...} to list entries that match any one of these
+keywords.  With a numeric prefix argument N, show the tree for the
+Nth keyword in the variable @code{org-todo-keywords}.  With two prefix
+arguments, find all TODO states, both un-done and done.
+
+@item @kbd{M-x org-agenda t} (@code{org-todo-list})
+@kindex t @r{(Agenda dispatcher)}
+Show the global TODO list.  Collects the TODO items (with not-DONE
+states) from all agenda files (see @ref{Agenda Views}) into a single
+buffer.  The new buffer is in Org Agenda mode, which provides
+commands to examine and manipulate the TODO entries from the new
+buffer (see @ref{Agenda Commands}).  See @ref{Global TODO list}, for more 
information.
+
+@item @kbd{S-M-@key{RET}} (@code{org-insert-todo-heading})
+@kindex S-M-RET
+@findex org-insert-todo-heading
 Insert a new TODO entry below the current one.
 @end table
 
-@noindent
 @vindex org-todo-state-tags-triggers
-Changing a TODO state can also trigger tag changes.  See the docstring of the
-option @code{org-todo-state-tags-triggers} for details.
+Changing a TODO state can also trigger tag changes.  See the docstring
+of the option @code{org-todo-state-tags-triggers} for details.
+
+@node TODO Extensions
+@section Extended Use of TODO Keywords
 
-@node TODO extensions
-@section Extended use of TODO keywords
 @cindex extended TODO keywords
 
 @vindex org-todo-keywords
 By default, marked TODO entries have one of only two states: TODO and
 DONE@.  Org mode allows you to classify TODO items in more complex ways
-with @emph{TODO keywords} (stored in @code{org-todo-keywords}).  With
-special setup, the TODO keyword system can work differently in different
+with @emph{TODO keywords} (stored in @code{org-todo-keywords}).  With special
+setup, the TODO keyword system can work differently in different
 files.
 
-Note that @i{tags} are another way to classify headlines in general and
-TODO items in particular (@pxref{Tags}).
+Note that @emph{tags} are another way to classify headlines in general and
+TODO items in particular (see @ref{Tags}).
 
 @menu
-* Workflow states::             From TODO to DONE in steps
-* TODO types::                  I do this, Fred does the rest
-* Multiple sets in one file::   Mixing it all, and still finding your way
-* Fast access to TODO states::  Single letter selection of a state
-* Per-file keywords::           Different files, different requirements
-* Faces for TODO keywords::     Highlighting states
-* TODO dependencies::           When one task needs to wait for others
+* Workflow states::              From TODO to DONE in steps.
+* TODO types::                   I do this, Fred does the rest.
+* Multiple sets in one file::    Mixing it all, still finding your way.
+* Fast access to TODO states::   Single letter selection of state.
+* Per-file keywords::            Different files, different requirements.
+* Faces for TODO keywords::      Highlighting states.
+* TODO dependencies::            When one task needs to wait for others.
 @end menu
 
 @node Workflow states
 @subsection TODO keywords as workflow states
+
 @cindex TODO workflow
 @cindex workflow states as TODO keywords
 
-You can use TODO keywords to indicate different @emph{sequential} states
-in the process of working on an item, for example@footnote{Changing
-this variable only becomes effective after restarting Org mode in a
-buffer.}:
+You can use TODO keywords to indicate different, possibly @emph{sequential}
+states in the process of working on an item, for example@footnote{Changing the 
variable @code{org-todo-keywords} only becomes
+effective after restarting Org mode in a buffer.}:
 
 @lisp
 (setq org-todo-keywords
-  '((sequence "TODO" "FEEDBACK" "VERIFY" "|" "DONE" "DELEGATED")))
+      '((sequence "TODO" "FEEDBACK" "VERIFY" "|" "DONE" "DELEGATED")))
 @end lisp
 
 The vertical bar separates the TODO keywords (states that @emph{need
 action}) from the DONE states (which need @emph{no further action}).  If
-you don't provide the separator bar, the last state is used as the DONE
-state.
+you do not provide the separator bar, the last state is used as the
+DONE state.
+
 @cindex completion, of TODO keywords
-With this setup, the command @kbd{C-c C-t} will cycle an entry from TODO
-to FEEDBACK, then to VERIFY, and finally to DONE and DELEGATED@.  You may
-also use a numeric prefix argument to quickly select a specific state.  For
-example @kbd{C-3 C-c C-t} will change the state immediately to VERIFY@.
-Or you can use @kbd{S-@key{LEFT}} to go backward through the sequence.  If you
-define many keywords, you can use in-buffer completion
-(@pxref{Completion}) or even a special one-key selection scheme
-(@pxref{Fast access to TODO states}) to insert these words into the
-buffer.  Changing a TODO state can be logged with a timestamp, see
-@ref{Tracking TODO state changes}, for more information.
+With this setup, the command @kbd{C-c C-t} cycles an entry from
+@samp{TODO} to @samp{FEEDBACK}, then to @samp{VERIFY}, and finally to 
@samp{DONE} and
+@samp{DELEGATED}.  You may also use a numeric prefix argument to quickly
+select a specific state.  For example @kbd{C-3 C-c C-t} changes
+the state immediately to @samp{VERIFY}.  Or you can use @kbd{S-@key{RIGHT}}
+and @kbd{S-@key{LEFT}} to go forward and backward through the states.
+If you define many keywords, you can use in-buffer completion (see
+@ref{Completion}) or a special one-key selection scheme (see @ref{Fast access 
to TODO states}) to insert these words into the buffer.
+Changing a TODO state can be logged with a timestamp, see @ref{Tracking TODO 
state changes}, for more information.
 
 @node TODO types
 @subsection TODO keywords as types
+
 @cindex TODO types
 @cindex names as TODO keywords
 @cindex types as TODO keywords
 
 The second possibility is to use TODO keywords to indicate different
-@emph{types} of action items.  For example, you might want to indicate
-that items are for ``work'' or ``home''.  Or, when you work with several
-people on a single project, you might want to assign action items
-directly to persons, by using their names as TODO keywords.  This would
-be set up like this:
+@emph{types} of action items.  For example, you might want to indicate that
+items are for ``work'' or ``home''.  Or, when you work with several people
+on a single project, you might want to assign action items directly to
+persons, by using their names as TODO keywords.  This type of
+functionality is actually much better served by using tags (see
+@ref{Tags}), so the TODO implementation is kept just for backward
+compatibility.
+
+Using TODO types, it would be set up like this:
 
 @lisp
 (setq org-todo-keywords '((type "Fred" "Sara" "Lucy" "|" "DONE")))
 @end lisp
 
-In this case, different keywords do not indicate a sequence, but rather
-different types.  So the normal work flow would be to assign a task to
-a person, and later to mark it DONE@.  Org mode supports this style by
-adapting the workings of the command @kbd{C-c C-t}@footnote{This is also true
-for the @kbd{t} command in the agenda buffers.}.  When used several times in
-succession, it will still cycle through all names, in order to first select
-the right type for a task.  But when you return to the item after some time
-and execute @kbd{C-c C-t} again, it will switch from any name directly to
-DONE@.  Use prefix arguments or completion to quickly select a specific name.
-You can also review the items of a specific TODO type in a sparse tree by
-using a numeric prefix to @kbd{C-c / t}.  For example, to see all things Lucy
-has to do, you would use @kbd{C-3 C-c / t}.  To collect Lucy's items from all
-agenda files into a single buffer, you would use the numeric prefix argument
-as well when creating the global TODO list: @kbd{C-3 C-c a t}.
+In this case, different keywords do not indicate states, but
+rather different types.  So the normal work flow would be to assign
+a task to a person, and later to mark it DONE@.  Org mode supports this
+style by adapting the workings of the command @kbd{C-c C-t}@footnote{This is 
also true for the @kbd{t} command in the agenda
+buffer.}.  When used several times in succession, it still
+cycles through all names, in order to first select the right type for
+a task.  But when you return to the item after some time and execute
+@kbd{C-c C-t} again, it will switch from any name directly to
+@samp{DONE}.  Use prefix arguments or completion to quickly select
+a specific name.  You can also review the items of a specific TODO
+type in a sparse tree by using a numeric prefix to @kbd{C-c / t}.
+For example, to see all things Lucy has to do, you would use
+@kbd{C-3 C-c / t}.  To collect Lucy's items from all agenda files
+into a single buffer, you would use the numeric prefix argument as
+well when creating the global TODO list: @kbd{C-3 M-x org-agenda t}.
 
 @node Multiple sets in one file
 @subsection Multiple keyword sets in one file
+
 @cindex TODO keyword sets
 
 Sometimes you may want to use different sets of TODO keywords in
-parallel.  For example, you may want to have the basic
-@code{TODO}/@code{DONE}, but also a workflow for bug fixing, and a
-separate state indicating that an item has been canceled (so it is not
-DONE, but also does not require action).  Your setup would then look
-like this:
+parallel.  For example, you may want to have the basic TODO/DONE, but
+also a workflow for bug fixing, and a separate state indicating that
+an item has been canceled---so it is not DONE, but also does not
+require action.  Your setup would then look like this:
 
 @lisp
 (setq org-todo-keywords
@@ -4172,45 +4367,46 @@ like this:
         (sequence "|" "CANCELED")))
 @end lisp
 
-The keywords should all be different, this helps Org mode to keep track
+The keywords should all be different, this helps Org mode keep track
 of which subsequence should be used for a given entry.  In this setup,
-@kbd{C-c C-t} only operates within a subsequence, so it switches from
-@code{DONE} to (nothing) to @code{TODO}, and from @code{FIXED} to
-(nothing) to @code{REPORT}.  Therefore you need a mechanism to initially
-select the correct sequence.  Besides the obvious ways like typing a
-keyword or using completion, you may also apply the following commands:
+@kbd{C-c C-t} only operates within a sub-sequence, so it switches
+from @samp{DONE} to (nothing) to @samp{TODO}, and from @samp{FIXED} to 
(nothing) to
+@samp{REPORT}.  Therefore you need a mechanism to initially select the
+correct sequence.  In addition to typing a keyword or using completion
+(see @ref{Completion}), you may also apply the following commands:
 
-@table @kbd
+@table @asis
+@item @kbd{C-u C-u C-c C-t}
+@itemx @kbd{C-S-@key{RIGHT}}
+@itemx @kbd{C-S-@key{LEFT}}
 @kindex C-S-RIGHT
 @kindex C-S-LEFT
 @kindex C-u C-u C-c C-t
-@item C-u C-u C-c C-t
-@itemx C-S-@key{RIGHT}
-@itemx C-S-@key{LEFT}
-These keys jump from one TODO subset to the next.  In the above example,
-@kbd{C-u C-u C-c C-t} or @kbd{C-S-@key{RIGHT}} would jump from @code{TODO} or
-@code{DONE} to @code{REPORT}, and any of the words in the second row to
-@code{CANCELED}.  Note that the @kbd{C-S-} key binding conflict with
-@code{shift-selection-mode} (@pxref{Conflicts}).
+These keys jump from one TODO sub-sequence to the next.  In the
+above example, @kbd{C-u C-u C-c C-t} or @kbd{C-S-@key{RIGHT}}
+would jump from @samp{TODO} or @samp{DONE} to @samp{REPORT}, and any of the 
words
+in the second row to @samp{CANCELED}.  Note that the @kbd{C-S-} key
+binding conflict with shift-selection (see @ref{Conflicts}).
+
+@item @kbd{S-@key{RIGHT}}
+@itemx @kbd{S-@key{LEFT}}
 @kindex S-RIGHT
 @kindex S-LEFT
-@item S-@key{RIGHT}
-@itemx S-@key{LEFT}
-@kbd{S-@key{LEFT}} and @kbd{S-@key{RIGHT}} and walk through @emph{all}
-keywords from all sets, so for example @kbd{S-@key{RIGHT}} would switch
-from @code{DONE} to @code{REPORT} in the example above.  See also
-@ref{Conflicts}, for a discussion of the interaction with
-@code{shift-selection-mode}.
+@kbd{S-@key{LEFT}} and @kbd{S-@key{RIGHT}} walk through @emph{all} keywords
+from all sub-sequences, so for example @kbd{S-@key{RIGHT}} would
+switch from @samp{DONE} to @samp{REPORT} in the example above.  For
+a discussion of the interaction with shift-selection, see @ref{Conflicts}.
 @end table
 
 @node Fast access to TODO states
 @subsection Fast access to TODO states
 
-If you would like to quickly change an entry to an arbitrary TODO state
-instead of cycling through the states, you can set up keys for single-letter
-access to the states.  This is done by adding the selection character after
-each keyword, in parentheses@footnote{All characters are allowed except
-@code{@@^!}, which have a special meaning here.}.  For example:
+If you would like to quickly change an entry to an arbitrary TODO
+state instead of cycling through the states, you can set up keys for
+single-letter access to the states.  This is done by adding the
+selection character after each keyword, in parentheses@footnote{All characters 
are allowed except @samp{@@}, @samp{^} and @samp{!}, which have
+a special meaning here.}.  For
+example:
 
 @lisp
 (setq org-todo-keywords
@@ -4220,37 +4416,43 @@ each keyword, in parentheses@footnote{All characters 
are allowed except
 @end lisp
 
 @vindex org-fast-tag-selection-include-todo
-If you then press @kbd{C-c C-t} followed by the selection key, the entry will
-be switched to this state.  @kbd{@key{SPC}} can be used to remove any TODO
-keyword from an entry.@footnote{Check also the option
-@code{org-fast-tag-selection-include-todo}, it allows you to change the TODO
-state through the tags interface (@pxref{Setting tags}), in case you like to
-mingle the two concepts.  Note that this means you need to come up with
-unique keys across both sets of keywords.}
+If you then press @kbd{C-c C-t} followed by the selection key,
+the entry is switched to this state.  @kbd{@key{SPC}} can be used to
+remove any TODO keyword from an entry@footnote{Check also the variable 
@code{org-fast-tag-selection-include-todo},
+it allows you to change the TODO state through the tags interface (see
+@ref{Setting Tags}), in case you like to mingle the two concepts.  Note
+that this means you need to come up with unique keys across both sets
+of keywords.}.
 
 @node Per-file keywords
 @subsection Setting up keywords for individual files
+
 @cindex keyword options
 @cindex per-file keywords
-@cindex @code{#+TODO}
-@cindex @code{#+TYP_TODO}
-@cindex @code{#+SEQ_TODO}
+@cindex @samp{TODO}, keyword
+@cindex @samp{TYP_TODO}, keyword
+@cindex @samp{SEQ_TODO}, keyword
 
-It can be very useful to use different aspects of the TODO mechanism in
-different files.  For file-local settings, you need to add special lines to
-the file which set the keywords and interpretation for that file only.  For
-example, to set one of the two examples discussed above, you need one of the
-following lines anywhere in the file:
+It can be very useful to use different aspects of the TODO mechanism
+in different files.  For file-local settings, you need to add special
+lines to the file which set the keywords and interpretation for that
+file only.  For example, to set one of the two examples discussed
+above, you need one of the following lines, starting in column zero
+anywhere in the file:
 
 @example
 #+TODO: TODO FEEDBACK VERIFY | DONE CANCELED
 @end example
-@noindent (you may also write @code{#+SEQ_TODO} to be explicit about the
-interpretation, but it means the same as @code{#+TODO}), or
+
+
+You may also write @samp{#+SEQ_TODO} to be explicit about the
+interpretation, but it means the same as @samp{#+TODO}, or
+
 @example
 #+TYP_TODO: Fred Sara Lucy Mike | DONE
 @end example
 
+
 A setup for using several sets in parallel would be:
 
 @example
@@ -4261,65 +4463,67 @@ A setup for using several sets in parallel would be:
 
 @cindex completion, of option keywords
 @kindex M-TAB
-@noindent To make sure you are using the correct keyword, type
-@samp{#+} into the buffer and then use @kbd{M-@key{TAB}} completion.
+To make sure you are using the correct keyword, type @samp{#+} into the
+buffer and then use @kbd{M-@key{TAB}} to complete it (see @ref{Completion}).
 
 @cindex DONE, final TODO keyword
-Remember that the keywords after the vertical bar (or the last keyword
-if no bar is there) must always mean that the item is DONE (although you
-may use a different word).  After changing one of these lines, use
-@kbd{C-c C-c} with the cursor still in the line to make the changes
-known to Org mode@footnote{Org mode parses these lines only when
-Org mode is activated after visiting a file.  @kbd{C-c C-c} with the
-cursor in a line starting with @samp{#+} is simply restarting Org mode
-for the current buffer.}.
+Remember that the keywords after the vertical bar---or the last
+keyword if no bar is there---must always mean that the item is DONE,
+although you may use a different word.  After changing one of these
+lines, use @kbd{C-c C-c} with point still in the line to make the
+changes known to Org mode@footnote{Org mode parses these lines only when Org 
mode is activated
+after visiting a file.  @kbd{C-c C-c} with point in a line
+starting with @samp{#+} is simply restarting Org mode for the current
+buffer.}.
 
 @node Faces for TODO keywords
 @subsection Faces for TODO keywords
+
 @cindex faces, for TODO keywords
 
-@vindex org-todo @r{(face)}
-@vindex org-done @r{(face)}
+@vindex org-todo, face
+@vindex org-done, face
 @vindex org-todo-keyword-faces
-Org mode highlights TODO keywords with special faces: @code{org-todo}
-for keywords indicating that an item still has to be acted upon, and
-@code{org-done} for keywords indicating that an item is finished.  If
-you are using more than 2 different states, you might want to use
-special faces for some of them.  This can be done using the option
+Org mode highlights TODO keywords with special faces: @code{org-todo} for
+keywords indicating that an item still has to be acted upon, and
+@code{org-done} for keywords indicating that an item is finished.  If you
+are using more than two different states, you might want to use
+special faces for some of them.  This can be done using the variable
 @code{org-todo-keyword-faces}.  For example:
 
 @lisp
-@group
 (setq org-todo-keyword-faces
       '(("TODO" . org-warning) ("STARTED" . "yellow")
         ("CANCELED" . (:foreground "blue" :weight bold))))
-@end group
 @end lisp
 
-While using a list with face properties as shown for CANCELED @emph{should}
-work, this does not always seem to be the case.  If necessary, define a
-special face and use that.  A string is interpreted as a color.  The option
-@code{org-faces-easy-properties} determines if that color is interpreted as a
-foreground or a background color.
+@vindex org-faces-easy-properties
+While using a list with face properties as shown for @samp{CANCELED}
+@emph{should} work, this does not always seem to be the case.  If
+necessary, define a special face and use that.  A string is
+interpreted as a color.  The variable @code{org-faces-easy-properties}
+determines if that color is interpreted as a foreground or
+a background color.
 
 @node TODO dependencies
 @subsection TODO dependencies
+
 @cindex TODO dependencies
 @cindex dependencies, of TODO states
-@cindex TODO dependencies, NOBLOCKING
 
 @vindex org-enforce-todo-dependencies
-@cindex property, @code{ORDERED}
-The structure of Org files (hierarchy and lists) makes it easy to define TODO
-dependencies.  Usually, a parent TODO task should not be marked DONE until
-all subtasks (defined as children tasks) are marked as DONE@.  And sometimes
-there is a logical sequence to a number of (sub)tasks, so that one task
-cannot be acted upon before all siblings above it are done.  If you customize
-the option @code{org-enforce-todo-dependencies}, Org will block entries
-from changing state to DONE while they have children that are not DONE@.
-Furthermore, if an entry has a property @code{ORDERED}, each of its children
-will be blocked until all earlier siblings are marked DONE@.  Here is an
-example:
+@cindex @samp{ORDERED}, property
+The structure of Org files---hierarchy and lists---makes it easy to
+define TODO dependencies.  Usually, a parent TODO task should not be
+marked as done until all TODO subtasks, or children tasks, are marked
+as done.  Sometimes there is a logical sequence to (sub)tasks, so that
+one subtask cannot be acted upon before all siblings above it have
+been marked as done.  If you customize the variable
+@code{org-enforce-todo-dependencies}, Org blocks entries from changing
+state to DONE while they have TODO children that are not DONE@.
+Furthermore, if an entry has a property @samp{ORDERED}, each of its TODO
+children is blocked until all earlier siblings are marked as done.
+Here is an example:
 
 @example
 * TODO Blocked until (two) is done
@@ -4327,78 +4531,94 @@ example:
 ** TODO two
 
 * Parent
-  :PROPERTIES:
-  :ORDERED: t
-  :END:
+:PROPERTIES:
+:ORDERED:  t
+:END:
 ** TODO a
 ** TODO b, needs to wait for (a)
 ** TODO c, needs to wait for (a) and (b)
 @end example
 
-You can ensure an entry is never blocked by using the @code{NOBLOCKING}
-property:
+@cindex TODO dependencies, @samp{NOBLOCKING}
+@cindex @samp{NOBLOCKING}, property
+You can ensure an entry is never blocked by using the @samp{NOBLOCKING}
+property (see @ref{Properties and Columns}):
 
 @example
 * This entry is never blocked
-  :PROPERTIES:
-  :NOBLOCKING: t
-  :END:
+:PROPERTIES:
+:NOBLOCKING: t
+:END:
 @end example
 
-@table @kbd
-@orgcmd{C-c C-x o,org-toggle-ordered-property}
+@table @asis
+@item @kbd{C-c C-x o} (@code{org-toggle-ordered-property})
+@kindex C-c C-x o
+@findex org-toggle-ordered-property
 @vindex org-track-ordered-property-with-tag
-@cindex property, @code{ORDERED}
-Toggle the @code{ORDERED} property of the current entry.  A property is used
-for this behavior because this should be local to the current entry, not
-inherited like a tag.  However, if you would like to @i{track} the value of
-this property with a tag for better visibility, customize the option
+Toggle the @samp{ORDERED} property of the current entry.  A property is
+used for this behavior because this should be local to the current
+entry, not inherited from entries above like a tag (see @ref{Tags}).
+However, if you would like to @emph{track} the value of this property
+with a tag for better visibility, customize the variable
 @code{org-track-ordered-property-with-tag}.
-@orgkey{C-u C-u C-u C-c C-t}
-Change TODO state, circumventing any state blocking.
+
+@item @kbd{C-u C-u C-u C-c C-t}
+@kindex C-u C-u C-u C-u C-c C-t
+Change TODO state, regardless of any state blocking.
 @end table
 
 @vindex org-agenda-dim-blocked-tasks
-If you set the option @code{org-agenda-dim-blocked-tasks}, TODO entries
-that cannot be closed because of such dependencies will be shown in a dimmed
-font or even made invisible in agenda views (@pxref{Agenda views}).
+If you set the variable @code{org-agenda-dim-blocked-tasks}, TODO entries
+that cannot be marked as done because of unmarked children are shown
+in a dimmed font or even made invisible in agenda views (see @ref{Agenda 
Views}).
 
 @cindex checkboxes and TODO dependencies
 @vindex org-enforce-todo-dependencies
-You can also block changes of TODO states by looking at checkboxes
-(@pxref{Checkboxes}).  If you set the option
+You can also block changes of TODO states by using checkboxes (see
+@ref{Checkboxes}).  If you set the variable
 @code{org-enforce-todo-checkbox-dependencies}, an entry that has unchecked
-checkboxes will be blocked from switching to DONE.
+checkboxes is blocked from switching to DONE@.
 
-If you need more complex dependency structures, for example dependencies
-between entries in different trees or files, check out the contributed
-module @file{org-depend.el}.
+If you need more complex dependency structures, for example
+dependencies between entries in different trees or files, check out
+the contributed module @samp{org-depend.el}.
+
+@node Progress Logging
+@section Progress Logging
 
-@page
-@node Progress logging
-@section Progress logging
 @cindex progress logging
 @cindex logging, of progress
 
-Org mode can automatically record a timestamp and possibly a note when
-you mark a TODO item as DONE, or even each time you change the state of
-a TODO item.  This system is highly configurable; settings can be on a
-per-keyword basis and can be localized to a file or even a subtree.  For
-information on how to clock working time for a task, see @ref{Clocking
-work time}.
+To record a timestamp and a note when changing a TODO state, call the
+command @code{org-todo} with a prefix argument.
+
+@table @asis
+@item @kbd{C-u C-c C-t} (@code{org-todo})
+@kindex C-u C-c C-t
+Prompt for a note and record a the time of the TODO state change.
+The note is inserted as a list item below the headline, but can also
+be placed into a drawer, see @ref{Tracking TODO state changes}.
+@end table
+
+If you want to be more systematic, Org mode can automatically record a
+timestamp and optionally a note when you mark a TODO item as DONE, or
+even each time you change the state of a TODO item.  This system is
+highly configurable, settings can be on a per-keyword basis and can be
+localized to a file or even a subtree.  For information on how to
+clock working time for a task, see @ref{Clocking Work Time}.
 
 @menu
-* Closing items::               When was this entry marked DONE?
+* Closing items::                When was this entry marked as done?
 * Tracking TODO state changes::  When did the status change?
-* Tracking your habits::        How consistent have you been?
+* Tracking your habits::         How consistent have you been?
 @end menu
 
 @node Closing items
 @subsection Closing items
 
-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}}
+The most basic automatic logging is to keep track of @emph{when} a certain
+TODO item was marked as done.  This can be achieved with@footnote{The 
corresponding in-buffer setting is: @samp{#+STARTUP: logdone}.}
 
 @lisp
 (setq org-log-done 'time)
@@ -4406,14 +4626,13 @@ in-buffer setting is: @code{#+STARTUP: logdone}}
 
 @vindex org-closed-keep-when-no-todo
 @noindent
-Then each time you turn an entry from a TODO (not-done) state into any of the
-DONE states, a line @samp{CLOSED: [timestamp]} will be inserted just after
-the headline.  If you turn the entry back into a TODO item through further
-state cycling, that line will be removed again.  If you turn the entry back
-to a non-TODO state (by pressing @kbd{C-c C-t @key{SPC}} for example), that 
line
-will also be removed, unless you set @code{org-closed-keep-when-no-todo} to
-non-@code{nil}.  If you want to record a note along with the timestamp,
-use@footnote{The corresponding in-buffer setting is: @code{#+STARTUP:
+Then each time you turn an entry from a TODO (not-done) state into any
+of the DONE states, a line @samp{CLOSED: [timestamp]} is inserted just
+after the headline.  If you turn the entry back into a TODO item
+through further state cycling, that line is removed again.  If you
+turn the entry back to a non-TODO state (by pressing @kbd{C-c C-t @key{SPC}} 
for example), that line is also removed, unless you set
+@code{org-closed-keep-when-no-todo} to non-@code{nil}.  If you want to record
+a note along with the timestamp, use@footnote{The corresponding in-buffer 
setting is: @samp{#+STARTUP:
 lognotedone}.}
 
 @lisp
@@ -4421,76 +4640,76 @@ lognotedone}.}
 @end lisp
 
 @noindent
-You will then be prompted for a note, and that note will be stored below
-the entry with a @samp{Closing Note} heading.
+You are then prompted for a note, and that note is stored below the
+entry with a @samp{Closing Note} heading.
 
 @node Tracking TODO state changes
 @subsection Tracking TODO state changes
+
 @cindex drawer, for state change recording
 
 @vindex org-log-states-order-reversed
 @vindex org-log-into-drawer
-@cindex property, @code{LOG_INTO_DRAWER}
-When TODO keywords are used as workflow states (@pxref{Workflow states}), you
-might want to keep track of when a state change occurred and maybe take a
-note about this change.  You can either record just a timestamp, or a
-time-stamped note for a change.  These records will be inserted after the
-headline as an itemized list, newest first@footnote{See the option
-@code{org-log-states-order-reversed}}.  When taking a lot of notes, you might
-want to get the notes out of the way into a drawer (@pxref{Drawers}).
-Customize @code{org-log-into-drawer} to get this behavior---the recommended
-drawer for this is called @code{LOGBOOK}@footnote{Note that the
-@code{LOGBOOK} drawer is unfolded when pressing @kbd{@key{SPC}} in the agenda 
to
-show an entry---use @kbd{C-u @key{SPC}} to keep it folded here}.  You can also
-overrule the setting of this variable for a subtree by setting a
-@code{LOG_INTO_DRAWER} property.
-
-Since it is normally too much to record a note for every state, Org mode
-expects configuration on a per-keyword basis for this.  This is achieved by
-adding special markers @samp{!} (for a timestamp) or @samp{@@} (for a note
-with timestamp) in parentheses after each keyword.  For example, with the
-setting
+@cindex @samp{LOG_INTO_DRAWER}, property
+You might want to automatically keep track of when a state change
+occurred and maybe take a note about this change.  You can either
+record just a timestamp, or a time-stamped note.  These records are
+inserted after the headline as an itemized list, newest first@footnote{See the 
variable @code{org-log-states-order-reversed}.}.
+When taking a lot of notes, you might want to get the notes out of the
+way into a drawer (see @ref{Drawers}).  Customize the variable
+@code{org-log-into-drawer} to get this behavior---the recommended drawer
+for this is called @samp{LOGBOOK}@footnote{Note that the @samp{LOGBOOK} drawer 
is unfolded when pressing
+@kbd{@key{SPC}} in the agenda to show an entry---use @kbd{C-u @key{SPC}} to 
keep it folded here.}.  You can also overrule the
+setting of this variable for a subtree by setting a @samp{LOG_INTO_DRAWER}
+property.
+
+Since it is normally too much to record a note for every state, Org
+mode expects configuration on a per-keyword basis for this.  This is
+achieved by adding special markers @samp{!} (for a timestamp) or @samp{@@} (for
+a note with timestamp) in parentheses after each keyword.  For
+example, with the setting
 
 @lisp
 (setq org-todo-keywords
-  '((sequence "TODO(t)" "WAIT(w@@/!)" "|" "DONE(d!)" "CANCELED(c@@)")))
+      '((sequence "TODO(t)" "WAIT(w@@/!)" "|" "DONE(d!)" "CANCELED(c@@)")))
 @end lisp
 
+@noindent
 To record a timestamp without a note for TODO keywords configured with
 @samp{@@}, just type @kbd{C-c C-c} to enter a blank note when prompted.
 
-@noindent
 @vindex org-log-done
-You not only define global TODO keywords and fast access keys, but also
-request that a time is recorded when the entry is set to
-DONE@footnote{It is possible that Org mode will record two timestamps
-when you are using both @code{org-log-done} and state change logging.
-However, it will never prompt for two notes---if you have configured
-both, the state change recording note will take precedence and cancel
-the @samp{Closing Note}.}, and that a note is recorded when switching to
-WAIT or CANCELED@.  The setting for WAIT is even more special: the
+You not only define global TODO keywords and fast access keys, but
+also request that a time is recorded when the entry is set to @samp{DONE},
+and that a note is recorded when switching to @samp{WAIT} or
+@samp{CANCELED}@footnote{It is possible that Org mode records two timestamps 
when you
+are using both @code{org-log-done} and state change logging.  However, it
+never prompts for two notes: if you have configured both, the state
+change recording note takes precedence and cancel the closing note.}.  The 
setting for @samp{WAIT} is even more special: the
 @samp{!} after the slash means that in addition to the note taken when
-entering the state, a timestamp should be recorded when @i{leaving} the
-WAIT state, if and only if the @i{target} state does not configure
-logging for entering it.  So it has no effect when switching from WAIT
-to DONE, because DONE is configured to record a timestamp only.  But
-when switching from WAIT back to TODO, the @samp{/!} in the WAIT
-setting now triggers a timestamp even though TODO has no logging
-configured.
+entering the state, a timestamp should be recorded when @emph{leaving} the
+@samp{WAIT} state, if and only if the @emph{target} state does not configure
+logging for entering it.  So it has no effect when switching from
+@samp{WAIT} to @samp{DONE}, because @samp{DONE} is configured to record a 
timestamp
+only.  But when switching from @samp{WAIT} back to @samp{TODO}, the @samp{/!} 
in the
+@samp{WAIT} setting now triggers a timestamp even though @samp{TODO} has no
+logging configured.
 
 You can use the exact same syntax for setting logging preferences local
 to a buffer:
+
 @example
 #+TODO: TODO(t) WAIT(w@@/!) | DONE(d!) CANCELED(c@@)
 @end example
 
-@cindex property, @code{LOGGING}
-In order to define logging settings that are local to a subtree or a single
-item, define a @code{LOGGING} property in this entry.  Any non-empty
-@code{LOGGING} property resets all logging settings to @code{nil}.  You may
-then turn on logging for this specific tree using @code{#+STARTUP} keywords
-like @code{lognotedone} or @code{logrepeat}, as well as adding state specific
-settings like @code{TODO(!)}.  For example
+
+@cindex @samp{LOGGING}, property
+In order to define logging settings that are local to a subtree or
+a single item, define a @samp{LOGGING} property in this entry.  Any
+non-empty @samp{LOGGING} property resets all logging settings to @code{nil}.
+You may then turn on logging for this specific tree using @samp{STARTUP}
+keywords like @samp{lognotedone} or @samp{logrepeat}, as well as adding state
+specific settings like @samp{TODO(!)}.  For example:
 
 @example
 * TODO Log each state with only a time
@@ -4509,32 +4728,39 @@ settings like @code{TODO(!)}.  For example
 
 @node Tracking your habits
 @subsection Tracking your habits
+
 @cindex habits
+@cindex @samp{STYLE}, property
 
-Org has the ability to track the consistency of a special category of TODOs,
-called ``habits''.  A habit has the following properties:
+Org has the ability to track the consistency of a special category of
+TODO, called ``habits.''  To use habits, you have to enable the @code{habits}
+module by customizing the variable @code{org-modules}.
+
+A habit has the following properties:
 
 @enumerate
 @item
-You have enabled the @code{habits} module by customizing @code{org-modules}.
-@item
-The habit is a TODO item, with a TODO keyword representing an open state.
+The habit is a TODO item, with a TODO keyword representing an open
+state.
+
 @item
-The property @code{STYLE} is set to the value @code{habit}.
+The property @samp{STYLE} is set to the value @samp{habit} (see 
@ref{Properties and Columns}).
+
 @item
-The TODO has a scheduled date, usually with a @code{.+} style repeat
-interval.  A @code{++} style may be appropriate for habits with time
-constraints, e.g., must be done on weekends, or a @code{+} style for an
+The TODO has a scheduled date, usually with a @samp{.+} style repeat
+interval.  A @samp{++} style may be appropriate for habits with time
+constraints, e.g., must be done on weekends, or a @samp{+} style for an
 unusual habit that can have a backlog, e.g., weekly reports.
+
 @item
-The TODO may also have minimum and maximum ranges specified by using the
-syntax @samp{.+2d/3d}, which says that you want to do the task at least every
-three days, but at most every two days.
+The TODO may also have minimum and maximum ranges specified by
+using the syntax @samp{.+2d/3d}, which says that you want to do the task
+at least every three days, but at most every two days.
+
 @item
-You must also have state logging for the @code{DONE} state enabled
-(@pxref{Tracking TODO state changes}), in order for historical data to be
-represented in the consistency graph.  If it is not enabled it is not an
-error, but the consistency graphs will be largely meaningless.
+State logging for the DONE state is enabled (see @ref{Tracking TODO state 
changes}), in order for historical data to be represented in
+the consistency graph.  If it is not enabled it is not an error,
+but the consistency graphs are largely meaningless.
 @end enumerate
 
 To give you an idea of what the above rules look like in action, here's an
@@ -4559,20 +4785,22 @@ actual habit with some history:
    - State "DONE"       from "TODO"       [2009-09-12 Sat]
 @end example
 
-What this habit says is: I want to shave at most every 2 days (given by the
-@code{SCHEDULED} date and repeat interval) and at least every 4 days.  If
-today is the 15th, then the habit first appears in the agenda on Oct 17,
-after the minimum of 2 days has elapsed, and will appear overdue on Oct 19,
-after four days have elapsed.
+What this habit says is: I want to shave at most every 2 days---given
+by the @samp{SCHEDULED} date and repeat interval---and at least every
+4 days.  If today is the 15th, then the habit first appears in the
+agenda (see @ref{Agenda Views}) on Oct 17, after the minimum of 2 days has
+elapsed, and will appear overdue on Oct 19, after four days have
+elapsed.
 
-What's really useful about habits is that they are displayed along with a
-consistency graph, to show how consistent you've been at getting that task
-done in the past.  This graph shows every day that the task was done over the
-past three weeks, with colors for each day.  The colors used are:
+What's really useful about habits is that they are displayed along
+with a consistency graph, to show how consistent you've been at
+getting that task done in the past.  This graph shows every day that
+the task was done over the past three weeks, with colors for each day.
+The colors used are:
 
-@table @code
+@table @asis
 @item Blue
-If the task wasn't to be done yet on that day.
+If the task was not to be done yet on that day.
 @item Green
 If the task could have been done on that day.
 @item Yellow
@@ -4581,104 +4809,121 @@ If the task was going to be overdue the next day.
 If the task was overdue on that day.
 @end table
 
-In addition to coloring each day, the day is also marked with an asterisk if
-the task was actually done that day, and an exclamation mark to show where
-the current day falls in the graph.
-
-There are several configuration variables that can be used to change the way
-habits are displayed in the agenda.
-
-@table @code
-@item org-habit-graph-column
-The buffer column at which the consistency graph should be drawn.  This will
-overwrite any text in that column, so it is a good idea to keep your habits'
-titles brief and to the point.
-@item org-habit-preceding-days
-The amount of history, in days before today, to appear in consistency graphs.
-@item org-habit-following-days
-The number of days after today that will appear in consistency graphs.
-@item org-habit-show-habits-only-for-today
-If non-@code{nil}, only show habits in today's agenda view.  This is set to 
true by
-default.
+In addition to coloring each day, the day is also marked with an
+asterisk if the task was actually done that day, and an exclamation
+mark to show where the current day falls in the graph.
+
+There are several configuration variables that can be used to change
+the way habits are displayed in the agenda.
+
+@table @asis
+@item @code{org-habit-graph-column}
+@vindex org-habit-graph-column
+The buffer column at which the consistency graph should be drawn.
+This overwrites any text in that column, so it is a good idea to
+keep your habits' titles brief and to the point.
+
+@item @code{org-habit-preceding-days}
+@vindex org-habit-preceding-days
+The amount of history, in days before today, to appear in
+consistency graphs.
+
+@item @code{org-habit-following-days}
+@vindex org-habit-following-days
+The number of days after today that appear in consistency graphs.
+
+@item @code{org-habit-show-habits-only-for-today}
+@vindex org-habit-show-habits-only-for-today
+If non-@code{nil}, only show habits in today's agenda view.  The default
+value is @code{t}.  Pressing @kbd{C-u K} in the agenda toggles this
+variable.
 @end table
 
-Lastly, pressing @kbd{K} in the agenda buffer will cause habits to
-temporarily be disabled and they won't appear at all.  Press @kbd{K} again to
-bring them back.  They are also subject to tag filtering, if you have habits
-which should only be done in certain contexts, for example.
+Lastly, pressing @kbd{K} in the agenda buffer causes habits to
+temporarily be disabled and do not appear at all.  Press @kbd{K}
+again to bring them back.  They are also subject to tag filtering, if
+you have habits which should only be done in certain contexts, for
+example.
 
 @node Priorities
 @section Priorities
+
 @cindex priorities
+@cindex priority cookie
 
-If you use Org mode extensively, you may end up with enough TODO items that
-it starts to make sense to prioritize them.  Prioritizing can be done by
-placing a @emph{priority cookie} into the headline of a TODO item, like this
+If you use Org mode extensively, you may end up with enough TODO items
+that it starts to make sense to prioritize them.  Prioritizing can be
+done by placing a @emph{priority cookie} into the headline of a TODO item,
+like this
 
 @example
 *** TODO [#A] Write letter to Sam Fortune
 @end example
 
-@noindent
+
 @vindex org-priority-faces
-By default, Org mode supports three priorities: @samp{A}, @samp{B}, and
-@samp{C}.  @samp{A} is the highest priority.  An entry without a cookie is
-treated just like priority @samp{B}.  Priorities make a difference only for
-sorting in the agenda (@pxref{Weekly/daily agenda}); outside the agenda, they
-have no inherent meaning to Org mode.  The cookies can be highlighted with
-special faces by customizing @code{org-priority-faces}.
-
-Priorities can be attached to any outline node; they do not need to be TODO
-items.
+By default, Org mode supports three priorities: @samp{A}, @samp{B}, and 
@samp{C}.
+@samp{A} is the highest priority.  An entry without a cookie is treated as
+equivalent if it had priority @samp{B}.  Priorities make a difference only
+for sorting in the agenda (see @ref{Weekly/daily agenda}); outside the
+agenda, they have no inherent meaning to Org mode.  The cookies are
+displayed with the face defined by the variable @code{org-priority-faces},
+which can be customized.
 
-@table @kbd
-@item @kbd{C-c ,}
+Priorities can be attached to any outline node; they do not need to be
+TODO items.
+
+@table @asis
+@item @kbd{C-c ,} (@code{org-priority})
 @kindex C-c ,
 @findex org-priority
-Set the priority of the current headline (@command{org-priority}).  The
-command prompts for a priority character @samp{A}, @samp{B} or @samp{C}.
-When you press @key{SPC} instead, the priority cookie is removed from the
-headline.  The priorities can also be changed ``remotely'' from the agenda
-buffer with the @kbd{,} command (@pxref{Agenda commands}).
-@c
-@orgcmdkkcc{S-@key{UP},S-@key{DOWN},org-priority-up,org-priority-down}
+Set the priority of the current headline.  The command prompts for
+a priority character @samp{A}, @samp{B} or @samp{C}.  When you press 
@kbd{@key{SPC}}
+instead, the priority cookie, if one is set, is removed from the
+headline.  The priorities can also be changed ``remotely'' from the
+agenda buffer with the @kbd{,} command (see @ref{Agenda Commands}).
+
+@item @kbd{S-@key{UP}} (@code{org-priority-up})
+@itemx @kbd{S-@key{DOWN}} (@code{org-priority-down})
+@kindex S-UP
+@kindex S-DOWN
+@findex org-priority-up
+@findex org-priority-down
 @vindex org-priority-start-cycle-with-default
-Increase/decrease priority of current headline@footnote{See also the option
-@code{org-priority-start-cycle-with-default}.}.  Note that these keys are
-also used to modify timestamps (@pxref{Creating timestamps}).  See also
-@ref{Conflicts}, for a discussion of the interaction with
-@code{shift-selection-mode}.
+Increase/decrease the priority of the current headline@footnote{See also the 
option @code{org-priority-start-cycle-with-default}.}.  Note
+that these keys are also used to modify timestamps (see @ref{Creating 
Timestamps}).  See also @ref{Conflicts}, for
+a discussion of the interaction with shift-selection.
 @end table
 
 @vindex org-highest-priority
 @vindex org-lowest-priority
 @vindex org-default-priority
-You can change the range of allowed priorities by setting the options
-@code{org-highest-priority}, @code{org-lowest-priority}, and
-@code{org-default-priority}.  For an individual buffer, you may set
-these values (highest, lowest, default) like this (please make sure that
-the highest priority is earlier in the alphabet than the lowest
-priority):
+You can change the range of allowed priorities by setting the
+variables @code{org-highest-priority}, @code{org-lowest-priority}, and
+@code{org-default-priority}.  For an individual buffer, you may set these
+values (highest, lowest, default) like this (please make sure that the
+highest priority is earlier in the alphabet than the lowest priority):
 
-@cindex @code{#+PRIORITIES}
+@cindex @samp{PRIORITIES}, keyword
 @example
 #+PRIORITIES: A C B
 @end example
 
-@node Breaking down tasks
-@section Breaking tasks down into subtasks
+@node Breaking Down Tasks
+@section Breaking Down Tasks into Subtasks
+
 @cindex tasks, breaking down
 @cindex statistics, for TODO items
 
 @vindex org-agenda-todo-list-sublevels
-It is often advisable to break down large tasks into smaller, manageable
-subtasks.  You can do this by creating an outline tree below a TODO item,
-with detailed subtasks on the tree@footnote{To keep subtasks out of the
-global TODO list, see the @code{org-agenda-todo-list-sublevels}.}.  To keep
-the overview over the fraction of subtasks that are already completed, insert
-either @samp{[/]} or @samp{[%]} anywhere in the headline.  These cookies will
-be updated each time the TODO status of a child changes, or when pressing
-@kbd{C-c C-c} on the cookie.  For example:
+It is often advisable to break down large tasks into smaller,
+manageable subtasks.  You can do this by creating an outline tree
+below a TODO item, with detailed subtasks on the tree@footnote{To keep 
subtasks out of the global TODO list, see the option
+@code{org-agenda-todo-list-sublevels}.}.  To keep
+an overview of the fraction of subtasks that have already been marked
+as done, insert either @samp{[/]} or @samp{[%]} anywhere in the headline.  
These
+cookies are updated each time the TODO status of a child changes, or
+when pressing @kbd{C-c C-c} on the cookie.  For example:
 
 @example
 * Organize Party [33%]
@@ -4689,17 +4934,16 @@ be updated each time the TODO status of a child 
changes, or when pressing
 ** DONE Talk to neighbor
 @end example
 
-@cindex property, @code{COOKIE_DATA}
-If a heading has both checkboxes and TODO children below it, the meaning of
-the statistics cookie become ambiguous.  Set the property
-@code{COOKIE_DATA} to either @samp{checkbox} or @samp{todo} to resolve
-this issue.
+@cindex @samp{COOKIE_DATA}, property
+If a heading has both checkboxes and TODO children below it, the
+meaning of the statistics cookie become ambiguous.  Set the property
+@samp{COOKIE_DATA} to either @samp{checkbox} or @samp{todo} to resolve this 
issue.
 
 @vindex org-hierarchical-todo-statistics
-If you would like to have the statistics cookie count any TODO entries in the
-subtree (not just direct children), configure
+If you would like to have the statistics cookie count any TODO entries
+in the subtree (not just direct children), configure the variable
 @code{org-hierarchical-todo-statistics}.  To do this for a single subtree,
-include the word @samp{recursive} into the value of the @code{COOKIE_DATA}
+include the word @samp{recursive} into the value of the @samp{COOKIE_DATA}
 property.
 
 @example
@@ -4709,37 +4953,34 @@ property.
   :END:
 @end example
 
-If you would like a TODO entry to automatically change to DONE
-when all children are done, you can use the following setup:
+If you would like a TODO entry to automatically change to DONE when
+all children are done, you can use the following setup:
 
-@example
+@lisp
 (defun org-summary-todo (n-done n-not-done)
   "Switch entry to DONE when all subentries are done, to TODO otherwise."
   (let (org-log-done org-log-states)   ; turn off logging
     (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
 
 (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
-@end example
-
-
-Another possibility is the use of checkboxes to identify (a hierarchy of) a
-large number of subtasks (@pxref{Checkboxes}).
+@end lisp
 
+Another possibility is the use of checkboxes to identify (a hierarchy
+of) a large number of subtasks (see @ref{Checkboxes}).
 
 @node Checkboxes
 @section Checkboxes
+
 @cindex checkboxes
 
 @vindex org-list-automatic-rules
-Every item in a plain list@footnote{With the exception of description
-lists.  But you can allow it by modifying @code{org-list-automatic-rules}
-accordingly.} (@pxref{Plain lists}) can be made into a checkbox by starting
-it with the string @samp{[ ]}.  This feature is similar to TODO items
-(@pxref{TODO items}), but is more lightweight.  Checkboxes are not included
-in the global TODO list, so they are often great to split a task into a
-number of simple steps.  Or you can use them in a shopping list.  To toggle a
-checkbox, use @kbd{C-c C-c}, or use the mouse (thanks to Piotr Zielinski's
-@file{org-mouse.el}).
+Every item in a plain list@footnote{With the exception of description lists.  
But you can allow it
+by modifying @code{org-list-automatic-rules} accordingly.} (see @ref{Plain 
Lists}) can be made into
+a checkbox by starting it with the string @samp{[ ]}.  This feature is
+similar to TODO items (see @ref{TODO Items}), but is more lightweight.
+Checkboxes are not included into the global TODO list, so they are
+often great to split a task into a number of simple steps.  Or you can
+use them in a shopping list.
 
 Here is an example of a checkbox list.
 
@@ -4754,124 +4995,141 @@ Here is an example of a checkbox list.
   - [X] talk to the neighbors
 @end example
 
-Checkboxes work hierarchically, so if a checkbox item has children that
-are checkboxes, toggling one of the children checkboxes will make the
+Checkboxes work hierarchically, so if a checkbox item has children
+that are checkboxes, toggling one of the children checkboxes makes the
 parent checkbox reflect if none, some, or all of the children are
 checked.
 
 @cindex statistics, for checkboxes
 @cindex checkbox statistics
-@cindex property, @code{COOKIE_DATA}
-@vindex org-checkbox-hierarchical-statistics
+@cindex @samp{COOKIE_DATA}, property
+@vindex org-hierarchical-checkbox-statistics
 The @samp{[2/4]} and @samp{[1/3]} in the first and second line are cookies
-indicating how many checkboxes present in this entry have been checked off,
-and the total number of checkboxes present.  This can give you an idea on how
-many checkboxes remain, even without opening a folded entry.  The cookies can
-be placed into a headline or into (the first line of) a plain list item.
-Each cookie covers checkboxes of direct children structurally below the
-headline/item on which the cookie appears@footnote{Set the option
-@code{org-checkbox-hierarchical-statistics} if you want such cookies to
-count all checkboxes below the cookie, not just those belonging to direct
-children.}.  You have to insert the cookie yourself by typing either
-@samp{[/]} or @samp{[%]}.  With @samp{[/]} you get an @samp{n out of m}
-result, as in the examples above.  With @samp{[%]} you get information about
-the percentage of checkboxes checked (in the above example, this would be
-@samp{[50%]} and @samp{[33%]}, respectively).  In a headline, a cookie can
-count either checkboxes below the heading or TODO states of children, and it
-will display whatever was changed last.  Set the property @code{COOKIE_DATA}
-to either @samp{checkbox} or @samp{todo} to resolve this issue.
+indicating how many checkboxes present in this entry have been checked
+off, and the total number of checkboxes present.  This can give you an
+idea on how many checkboxes remain, even without opening a folded
+entry.  The cookies can be placed into a headline or into (the first
+line of) a plain list item.  Each cookie covers checkboxes of direct
+children structurally below the headline/item on which the cookie
+appears@footnote{Set the variable @code{org-hierarchical-checkbox-statistics} 
if you
+want such cookies to count all checkboxes below the cookie, not just
+those belonging to direct children.}.  You have to insert the cookie yourself 
by typing
+either @samp{[/]} or @samp{[%]}.  With @samp{[/]} you get an @samp{n out of m} 
result, as
+in the examples above.  With @samp{[%]} you get information about the
+percentage of checkboxes checked (in the above example, this would be
+@samp{[50%]} and @samp{[33%]}, respectively).  In a headline, a cookie can 
count
+either checkboxes below the heading or TODO states of children, and it
+displays whatever was changed last.  Set the property @samp{COOKIE_DATA} to
+either @samp{checkbox} or @samp{todo} to resolve this issue.
 
 @cindex blocking, of checkboxes
 @cindex checkbox blocking
-@cindex property, @code{ORDERED}
-If the current outline node has an @code{ORDERED} property, checkboxes must
-be checked off in sequence, and an error will be thrown if you try to check
+@cindex @samp{ORDERED}, property
+If the current outline node has an @samp{ORDERED} property, checkboxes must
+be checked off in sequence, and an error is thrown if you try to check
 off a box while there are unchecked boxes above it.
 
-@noindent The following commands work with checkboxes:
-
-@table @kbd
-@orgcmd{C-c C-c,org-toggle-checkbox}
-Toggle checkbox status or (with prefix arg) checkbox presence at point.  With
-a single prefix argument, add an empty checkbox or remove the current
-one@footnote{@kbd{C-u C-c C-c} before the @emph{first} bullet in a list with
-no checkbox will add checkboxes to the rest of the list.}.  With a double
-prefix argument, set it to @samp{[-]}, which is considered to be an
-intermediate state.
-@orgcmd{C-c C-x C-b,org-toggle-checkbox}
-Toggle checkbox status or (with prefix arg) checkbox presence at point.  With
-double prefix argument, set it to @samp{[-]}, which is considered to be an
-intermediate state.
-@itemize @minus
-@item
-If there is an active region, toggle the first checkbox in the region
-and set all remaining boxes to the same status as the first.  With a prefix
-arg, add or remove the checkbox for all items in the region.
-@item
-If the cursor is in a headline, toggle the state of the first checkbox in the
-region between this headline and the next---so @emph{not} the entire
-subtree---and propagate this new state to all other checkboxes in the same
-area.
+The following commands work with checkboxes:
+
+@table @asis
+@item @kbd{C-c C-c} (@code{org-toggle-checkbox})
+@kindex C-c C-c
+@findex org-toggle-checkbox
+Toggle checkbox status or---with prefix argument---checkbox presence
+at point.  With a single prefix argument, add an empty checkbox or
+remove the current one@footnote{@kbd{C-u C-c C-c} on the @emph{first} item of 
a list with no
+checkbox adds checkboxes to the rest of the list.}.  With a double prefix 
argument, set
+it to @samp{[-]}, which is considered to be an intermediate state.
+
+@item @kbd{C-c C-x C-b} (@code{org-toggle-checkbox})
+@kindex C-c C-x C-b
+Toggle checkbox status or---with prefix argument---checkbox presence
+at point.  With double prefix argument, set it to @samp{[-]}, which is
+considered to be an intermediate state.
+
+@itemize
+@item
+If there is an active region, toggle the first checkbox in the
+region and set all remaining boxes to the same status as the
+first.  With a prefix argument, add or remove the checkbox for all
+items in the region.
+
+@item
+If point is in a headline, toggle checkboxes in the region between
+this headline and the next---so @emph{not} the entire subtree.
+
 @item
 If there is no active region, just toggle the checkbox at point.
 @end itemize
-@orgcmd{M-S-@key{RET},org-insert-todo-heading}
-Insert a new item with a checkbox.  This works only if the cursor is already
-in a plain list item (@pxref{Plain lists}).
-@orgcmd{C-c C-x o,org-toggle-ordered-property}
+
+@item @kbd{M-S-@key{RET}} (@code{org-insert-todo-heading})
+@kindex M-S-RET
+@findex org-insert-todo-heading
+Insert a new item with a checkbox.  This works only if point is
+already in a plain list item (see @ref{Plain Lists}).
+
+@item @kbd{C-c C-x o} (@code{org-toggle-ordered-property})
+@kindex C-c C-x o
+@findex org-toggle-ordered-property
 @vindex org-track-ordered-property-with-tag
-@cindex property, @code{ORDERED}
-Toggle the @code{ORDERED} property of the entry, to toggle if checkboxes must
-be checked off in sequence.  A property is used for this behavior because
-this should be local to the current entry, not inherited like a tag.
-However, if you would like to @i{track} the value of this property with a tag
-for better visibility, customize @code{org-track-ordered-property-with-tag}.
-@orgcmd{C-c #,org-update-statistics-cookies}
-Update the statistics cookie in the current outline entry.  When called with
-a @kbd{C-u} prefix, update the entire file.  Checkbox statistic cookies are
-updated automatically if you toggle checkboxes with @kbd{C-c C-c} and make
-new ones with @kbd{M-S-@key{RET}}.  TODO statistics cookies update when
-changing TODO states.  If you delete boxes/entries or add/change them by
+Toggle the @samp{ORDERED} property of the entry, to toggle if checkboxes
+must be checked off in sequence.  A property is used for this
+behavior because this should be local to the current entry, not
+inherited like a tag.  However, if you would like to @emph{track} the
+value of this property with a tag for better visibility, customize
+@code{org-track-ordered-property-with-tag}.
+
+@item @kbd{C-c #} (@code{org-update-statistics-cookies})
+@kindex C-c #
+@findex org-update-statistics-cookies
+Update the statistics cookie in the current outline entry.  When
+called with a @kbd{C-u} prefix, update the entire file.
+Checkbox statistic cookies are updated automatically if you toggle
+checkboxes with @kbd{C-c C-c} and make new ones with
+@kbd{M-S-@key{RET}}.  TODO statistics cookies update when changing
+TODO states.  If you delete boxes/entries or add/change them by
 hand, use this command to get things back into sync.
 @end table
 
 @node Tags
 @chapter Tags
+
 @cindex tags
 @cindex headline tagging
 @cindex matching, tags
 @cindex sparse tree, tag based
 
-An excellent way to implement labels and contexts for cross-correlating
-information is to assign @i{tags} to headlines.  Org mode has extensive
-support for tags.
+An excellent way to implement labels and contexts for
+cross-correlating information is to assign @emph{tags} to headlines.  Org
+mode has extensive support for tags.
 
 @vindex org-tag-faces
-Every headline can contain a list of tags; they occur at the end of the
-headline.  Tags are normal words containing letters, numbers, @samp{_}, and
-@samp{@@}.  Tags must be preceded and followed by a single colon, e.g.,
-@samp{:work:}.  Several tags can be specified, as in @samp{:work:urgent:}.
-Tags will by default be in bold face with the same color as the headline.
-You may specify special faces for specific tags using the option
+Every headline can contain a list of tags; they occur at the end of
+the headline.  Tags are normal words containing letters, numbers, @samp{_},
+and @samp{@@}.  Tags must be preceded and followed by a single colon, e.g.,
+@samp{:work:}.  Several tags can be specified, as in @samp{:work:urgent:}.  
Tags
+by default are in bold face with the same color as the headline.  You
+may specify special faces for specific tags using the variable
 @code{org-tag-faces}, in much the same way as you can for TODO keywords
-(@pxref{Faces for TODO keywords}).
+(see @ref{Faces for TODO keywords}).
 
 @menu
-* Tag inheritance::             Tags use the tree structure of the outline
-* Setting tags::                How to assign tags to a headline
-* Tag hierarchy::               Create a hierarchy of tags
-* Tag searches::                Searching for combinations of tags
+* Tag Inheritance::              Tags use the tree structure of an outline.
+* Setting Tags::                 How to assign tags to a headline.
+* Tag Hierarchy::                Create a hierarchy of tags.
+* Tag Searches::                 Searching for combinations of tags.
 @end menu
 
-@node Tag inheritance
-@section Tag inheritance
+@node Tag Inheritance
+@section Tag Inheritance
+
 @cindex tag inheritance
 @cindex inheritance, of tags
 @cindex sublevels, inclusion into tags match
 
-@i{Tags} make use of the hierarchical structure of outline trees.  If a
-heading has a certain tag, all subheadings will inherit the tag as
-well.  For example, in the list
+@emph{Tags} make use of the hierarchical structure of outline trees.  If
+a heading has a certain tag, all subheadings inherit the tag as well.
+For example, in the list
 
 @example
 * Meeting with the French group      :work:
@@ -4880,45 +5138,46 @@ well.  For example, in the list
 @end example
 
 @noindent
-the final heading will have the tags @samp{:work:}, @samp{:boss:},
-@samp{:notes:}, and @samp{:action:} even though the final heading is not
-explicitly marked with all those tags.  You can also set tags that all
-entries in a file should inherit just as if these tags were defined in
-a hypothetical level zero that surrounds the entire file.  Use a line like
-this@footnote{As with all these in-buffer settings, pressing @kbd{C-c C-c}
-activates any changes in the line.}:
+the final heading has the tags @samp{work}, @samp{boss}, @samp{notes}, and 
@samp{action}
+even though the final heading is not explicitly marked with those
+tags.  You can also set tags that all entries in a file should inherit
+just as if these tags were defined in a hypothetical level zero that
+surrounds the entire file.  Use a line like this@footnote{As with all these 
in-buffer settings, pressing @kbd{C-c C-c} activates any changes in the line.}
 
-@cindex @code{#+FILETAGS}
+@cindex @samp{FILETAGS}, keyword
 @example
 #+FILETAGS: :Peter:Boss:Secret:
 @end example
 
-@noindent
+
 @vindex org-use-tag-inheritance
 @vindex org-tags-exclude-from-inheritance
-To limit tag inheritance to specific tags, use 
@code{org-tags-exclude-from-inheritance}.
-To turn it off entirely, use @code{org-use-tag-inheritance}.
+To limit tag inheritance to specific tags, or to turn it off entirely,
+use the variables @code{org-use-tag-inheritance} and
+@code{org-tags-exclude-from-inheritance}.
 
 @vindex org-tags-match-list-sublevels
-When a headline matches during a tags search while tag inheritance is turned
-on, all the sublevels in the same tree will (for a simple match form) match
-as well@footnote{This is only true if the search does not involve more
-complex tests including properties (@pxref{Property searches}).}.  The list
-of matches may then become very long.  If you only want to see the first tags
-match in a subtree, configure @code{org-tags-match-list-sublevels} (not
+When a headline matches during a tags search while tag inheritance is
+turned on, all the sublevels in the same tree---for a simple match
+form---match as well@footnote{This is only true if the search does not involve 
more complex
+tests including properties (see @ref{Property Searches}).}.  The list of 
matches may then become
+very long.  If you only want to see the first tags match in a subtree,
+configure the variable @code{org-tags-match-list-sublevels} (not
 recommended).
 
 @vindex org-agenda-use-tag-inheritance
-Tag inheritance is relevant when the agenda search tries to match a tag,
-either in the @code{tags} or @code{tags-todo} agenda types.  In other agenda
-types, @code{org-use-tag-inheritance} has no effect.  Still, you may want to
-have your tags correctly set in the agenda, so that tag filtering works fine,
-with inherited tags.  Set @code{org-agenda-use-tag-inheritance} to control
-this: the default value includes all agenda types, but setting this to 
@code{nil}
-can really speed up agenda generation.
-
-@node Setting tags
-@section Setting tags
+Tag inheritance is relevant when the agenda search tries to match
+a tag, either in the @code{tags} or @code{tags-todo} agenda types.  In other
+agenda types, @code{org-use-tag-inheritance} has no effect.  Still, you may
+want to have your tags correctly set in the agenda, so that tag
+filtering works fine, with inherited tags.  Set
+@code{org-agenda-use-tag-inheritance} to control this: the default value
+includes all agenda types, but setting this to @code{nil} can really speed
+up agenda generation.
+
+@node Setting Tags
+@section Setting Tags
+
 @cindex setting tags
 @cindex tags, setting
 
@@ -4927,91 +5186,101 @@ Tags can simply be typed into the buffer at the end of 
a headline.
 After a colon, @kbd{M-@key{TAB}} offers completion on tags.  There is
 also a special command for inserting tags:
 
-@table @kbd
-@orgcmd{C-c C-q,org-set-tags-command}
+@table @asis
+@item @kbd{C-c C-q} (@code{org-set-tags-command})
+@kindex C-c C-q
+@findex org-set-tags-command
 @cindex completion, of tags
 @vindex org-tags-column
-Enter new tags for the current headline.  Org mode will either offer
+Enter new tags for the current headline.  Org mode either offers
 completion or a special single-key interface for setting tags, see
-below.  After pressing @key{RET}, the tags will be inserted and aligned
-to @code{org-tags-column}.  When called with a @kbd{C-u} prefix, all
-tags in the current buffer will be aligned to that column, just to make
-things look nice.  TAGS are automatically realigned after promotion,
-demotion, and TODO state changes (@pxref{TODO basics}).
-
-@orgcmd{C-c C-c,org-set-tags-command}
-When the cursor is in a headline, this does the same as @kbd{C-c C-q}.
+below.  After pressing @kbd{@key{RET}}, the tags are inserted and
+aligned to @code{org-tags-column}.  When called with a @kbd{C-u}
+prefix, all tags in the current buffer are aligned to that column,
+just to make things look nice.  Tags are automatically realigned
+after promotion, demotion, and TODO state changes (see @ref{TODO Basics}).
+
+@item @kbd{C-c C-c} (@code{org-set-tags-command})
+@kindex C-c C-c
+When point is in a headline, this does the same as @kbd{C-c C-q}.
 @end table
 
+@vindex org-complete-tags-always-offer-all-agenda-tags
 @vindex org-tag-alist
-Org supports tag insertion based on a @emph{list of tags}.  By
-default this list is constructed dynamically, containing all tags
-currently used in the buffer.  You may also globally specify a hard list
-of tags with the variable @code{org-tag-alist}.  Finally you can set
-the default tags for a given file with lines like
+@cindex @samp{TAGS}, keyword
+Org supports tag insertion based on a @emph{list of tags}.  By default this
+list is constructed dynamically, containing all tags currently used in
+the buffer@footnote{To extend this default list to all tags used in all agenda
+files (see @ref{Agenda Views}), customize the variable
+@code{org-complete-tags-always-offer-all-agenda-tags}.}.  You may also 
globally specify a hard list of tags
+with the variable @code{org-tag-alist}.  Finally you can set the default
+tags for a given file using the @samp{TAGS} keyword, like
 
-@cindex @code{#+TAGS}
 @example
 #+TAGS: @@work @@home @@tennisclub
 #+TAGS: laptop car pc sailboat
 @end example
 
 If you have globally defined your preferred set of tags using the
-variable @code{org-tag-alist}, but would like to use a dynamic tag list
-in a specific file, add an empty TAGS option line to that file:
+variable @code{org-tag-alist}, but would like to use a dynamic tag list in
+a specific file, add an empty @samp{TAGS} keyword to that file:
 
 @example
 #+TAGS:
 @end example
 
+
 @vindex org-tag-persistent-alist
-If you have a preferred set of tags that you would like to use in every file,
-in addition to those defined on a per-file basis by TAGS option lines, then
-you may specify a list of tags with the variable
+If you have a preferred set of tags that you would like to use in
+every file, in addition to those defined on a per-file basis by @samp{TAGS}
+keyword, then you may specify a list of tags with the variable
 @code{org-tag-persistent-alist}.  You may turn this off on a per-file basis
-by adding a @code{#+STARTUP} option line to that file:
+by adding a @samp{STARTUP} keyword to that file:
 
 @example
 #+STARTUP: noptag
 @end example
 
-By default Org mode uses the standard minibuffer completion facilities for
-entering tags.  However, it also implements another, quicker, tag selection
-method called @emph{fast tag selection}.  This allows you to select and
-deselect tags with just a single key press.  For this to work well you should
-assign unique, case-sensitive, letters to most of your commonly used tags.
-You can do this globally by configuring the variable @code{org-tag-alist} in
-your Emacs init file.  For example, you may find the need to tag many items
-in different files with @samp{:@@home:}.  In this case you can set something
-like:
+
+By default Org mode uses the standard minibuffer completion facilities
+for entering tags.  However, it also implements another, quicker, tag
+selection method called @emph{fast tag selection}.  This allows you to
+select and deselect tags with just a single key press.  For this to
+work well you should assign unique letters to most of your commonly
+used tags.  You can do this globally by configuring the variable
+@code{org-tag-alist} in your Emacs init file.  For example, you may find
+the need to tag many items in different files with @samp{@@home}.  In this
+case you can set something like:
 
 @lisp
 (setq org-tag-alist '(("@@work" . ?w) ("@@home" . ?h) ("laptop" . ?l)))
 @end lisp
 
-@noindent If the tag is only relevant to the file you are working on, then you
-can instead set the TAGS option line as:
+If the tag is only relevant to the file you are working on, then you
+can instead set the @samp{TAGS} keyword as:
 
 @example
 #+TAGS: @@work(w)  @@home(h)  @@tennisclub(t)  laptop(l)  pc(p)
 @end example
 
-@noindent The tags interface will show the available tags in a splash
-window.  If you want to start a new line after a specific tag, insert
-@samp{\n} into the tag list
+
+The tags interface shows the available tags in a splash window.  If
+you want to start a new line after a specific tag, insert @samp{\n} into
+the tag list
 
 @example
-#+TAGS: @@work(w)  @@home(h)  @@tennisclub(t) \n laptop(l)  pc(p)
+#+TAGS: @@work(w) @@home(h) @@tennisclub(t) \n laptop(l) pc(p)
 @end example
 
-@noindent or write them in two lines:
+
+@noindent
+or write them in two lines:
 
 @example
 #+TAGS: @@work(w)  @@home(h)  @@tennisclub(t)
 #+TAGS: laptop(l)  pc(p)
 @end example
 
-@noindent
 You can also group together tags that are mutually exclusive by using
 braces, as in:
 
@@ -5019,18 +5288,19 @@ braces, as in:
 #+TAGS: @{ @@work(w)  @@home(h)  @@tennisclub(t) @}  laptop(l)  pc(p)
 @end example
 
-@noindent you indicate that at most one of @samp{@@work}, @samp{@@home},
-and @samp{@@tennisclub} should be selected.  Multiple such groups are allowed.
-
-@noindent Don't forget to press @kbd{C-c C-c} with the cursor in one of
-these lines to activate any changes.
 
 @noindent
-To set these mutually exclusive groups in the variable @code{org-tag-alist},
-you must use the dummy tags @code{:startgroup} and @code{:endgroup} instead
-of the braces.  Similarly, you can use @code{:newline} to indicate a line
-break.  The previous example would be set globally by the following
-configuration:
+you indicate that at most one of @samp{@@work}, @samp{@@home}, and 
@samp{@@tennisclub}
+should be selected.  Multiple such groups are allowed.
+
+Do not forget to press @kbd{C-c C-c} with point in one of these
+lines to activate any changes.
+
+To set these mutually exclusive groups in the variable
+@code{org-tags-alist}, you must use the dummy tags @code{:startgroup} and
+@code{:endgroup} instead of the braces.  Similarly, you can use @code{:newline}
+to indicate a line break.  The previous example would be set globally
+by the following configuration:
 
 @lisp
 (setq org-tag-alist '((:startgroup . nil)
@@ -5040,101 +5310,107 @@ configuration:
                       ("laptop" . ?l) ("pc" . ?p)))
 @end lisp
 
-If at least one tag has a selection key then pressing @kbd{C-c C-c} will
-automatically present you with a special interface, listing inherited tags,
-the tags of the current headline, and a list of all valid tags with
-corresponding keys@footnote{Keys will automatically be assigned to tags which
-have no configured keys.}.
+If at least one tag has a selection key then pressing @kbd{C-c C-c} 
automatically presents you with a special interface, listing
+inherited tags, the tags of the current headline, and a list of all
+valid tags with corresponding keys@footnote{Keys are automatically assigned to 
tags that have no
+configured keys.}.
 
-Pressing keys assigned to tags will add or remove them from the list of tags
-in the current line.  Selecting a tag in a group of mutually exclusive tags
-will turn off any other tags from that group.
+Pressing keys assigned to tags adds or removes them from the list of
+tags in the current line.  Selecting a tag in a group of mutually
+exclusive tags turns off any other tag from that group.
 
 In this interface, you can also use the following special keys:
 
-@table @kbd
+@table @asis
+@item @kbd{@key{TAB}}
 @kindex TAB
-@item @key{TAB}
-Enter a tag in the minibuffer, even if the tag is not in the predefined
-list.  You will be able to complete on all tags present in the buffer.
-You can also add several tags: just separate them with a comma.
+Enter a tag in the minibuffer, even if the tag is not in the
+predefined list.  You can complete on all tags present in the
+buffer.  You can also add several tags: just separate them with
+a comma.
 
+@item @kbd{@key{SPC}}
 @kindex SPC
-@item @key{SPC}
 Clear all tags for this line.
 
+@item @kbd{@key{RET}}
 @kindex RET
-@item @key{RET}
 Accept the modified set.
 
-@item C-g
+@item @kbd{C-g}
+@kindex C-g
 Abort without installing changes.
 
-@item q
-If @kbd{q} is not assigned to a tag, it aborts like @kbd{C-g}.
+@item @kbd{q}
+@kindex q
+If @kbd{q} is not assigned to a tag, it aborts like
+@kbd{C-g}.
 
-@item !
+@item @kbd{!}
+@kindex !
 Turn off groups of mutually exclusive tags.  Use this to (as an
 exception) assign several tags from such a group.
 
-@item C-c
-Toggle auto-exit after the next change (see below).
-If you are using expert mode, the first @kbd{C-c} will display the
-selection window.
+@item @kbd{C-c}
+@kindex C-c C-c
+Toggle auto-exit after the next change (see below).  If you are
+using expert mode, the first @kbd{C-c} displays the selection
+window.
 @end table
 
-@noindent
-This method lets you assign tags to a headline with very few keys.  With
-the above setup, you could clear the current tags and set @samp{@@home},
-@samp{laptop} and @samp{pc} tags with just the following keys: @kbd{C-c
-C-c @key{SPC} h l p @key{RET}}.  Switching from @samp{@@home} to
-@samp{@@work} would be done with @kbd{C-c C-c w @key{RET}} or
-alternatively with @kbd{C-c C-c C-c w}.  Adding the non-predefined tag
-@samp{Sarah} could be done with @kbd{C-c C-c @key{TAB} S a r a h
-@key{RET} @key{RET}}.
+This method lets you assign tags to a headline with very few keys.
+With the above setup, you could clear the current tags and set
+@samp{@@home}, @samp{laptop} and @samp{pc} tags with just the following keys:
+@kbd{C-c C-c @key{SPC} h l p @key{RET}}.  Switching from @samp{@@home} to 
@samp{@@work}
+would be done with @kbd{C-c C-c w @key{RET}} or alternatively with
+@kbd{C-c C-c C-c w}.  Adding the non-predefined tag @samp{sarah} could
+be done with @kbd{C-c C-c @key{TAB} s a r a h @key{RET}}.
 
 @vindex org-fast-tag-selection-single-key
 If you find that most of the time you need only a single key press to
-modify your list of tags, set @code{org-fast-tag-selection-single-key}.
-Then you no longer have to press @key{RET} to exit fast tag selection---it
-will immediately exit after the first change.  If you then occasionally
-need more keys, press @kbd{C-c} to turn off auto-exit for the current tag
-selection process (in effect: start selection with @kbd{C-c C-c C-c}
-instead of @kbd{C-c C-c}).  If you set the variable to the value
-@code{expert}, the special window is not even shown for single-key tag
-selection, it comes up only when you press an extra @kbd{C-c}.
-
-@node Tag hierarchy
-@section Tag hierarchy
+modify your list of tags, set the variable
+@code{org-fast-tag-selection-single-key}.  Then you no longer have to press
+@kbd{@key{RET}} to exit fast tag selection---it exits after the first
+change.  If you then occasionally need more keys, press @kbd{C-c}
+to turn off auto-exit for the current tag selection process (in
+effect: start selection with @kbd{C-c C-c C-c} instead of
+@kbd{C-c C-c}).  If you set the variable to the value @code{expert},
+the special window is not even shown for single-key tag selection, it
+comes up only when you press an extra @kbd{C-c}.
+
+@node Tag Hierarchy
+@section Tag Hierarchy
 
 @cindex group tags
 @cindex tags, groups
-@cindex tag hierarchy
+@cindex tags hierarchy
+
 Tags can be defined in hierarchies.  A tag can be defined as a @emph{group
-tag} for a set of other tags.  The group tag can be seen as the ``broader
-term'' for its set of tags.  Defining multiple @emph{group tags} and nesting
-them creates a tag hierarchy.
+tag} for a set of other tags.  The group tag can be seen as the
+``broader term'' for its set of tags.  Defining multiple group tags and
+nesting them creates a tag hierarchy.
 
-One use-case is to create a taxonomy of terms (tags) that can be used to
-classify nodes in a document or set of documents.
+One use-case is to create a taxonomy of terms (tags) that can be used
+to classify nodes in a document or set of documents.
 
-When you search for a group tag, it will return matches for all members in
-the group and its subgroups.  In an agenda view, filtering by a group tag
-will display or hide headlines tagged with at least one of the members of the
-group or any of its subgroups.  This makes tag searches and filters even more
-flexible.
+When you search for a group tag, it return matches for all members in
+the group and its subgroups.  In an agenda view, filtering by a group
+tag displays or hide headlines tagged with at least one of the members
+of the group or any of its subgroups.  This makes tag searches and
+filters even more flexible.
 
-You can set group tags by using brackets and inserting a colon between the
-group tag and its related tags---beware that all whitespaces are mandatory so
-that Org can parse this line correctly:
+You can set group tags by using brackets and inserting a colon between
+the group tag and its related tags---beware that all whitespaces are
+mandatory so that Org can parse this line correctly:
 
 @example
 #+TAGS: [ GTD : Control Persp ]
 @end example
 
-In this example, @samp{GTD} is the @emph{group tag} and it is related to two
-other tags: @samp{Control}, @samp{Persp}.  Defining @samp{Control} and
-@samp{Persp} as group tags creates a hierarchy of tags:
+
+In this example, @samp{GTD} is the group tag and it is related to two other
+tags: @samp{Control}, @samp{Persp}.  Defining @samp{Control} and @samp{Persp} 
as group
+tags creates a hierarchy of tags:
 
 @example
 #+TAGS: [ Control : Context Task ]
@@ -5143,146 +5419,173 @@ other tags: @samp{Control}, @samp{Persp}.  Defining 
@samp{Control} and
 
 That can conceptually be seen as a hierarchy of tags:
 
-@example
-- GTD
-  - Persp
-    - Vision
-    - Goal
-    - AOF
-    - Project
-  - Control
-    - Context
-    - Task
-@end example
-
-You can use the @code{:startgrouptag}, @code{:grouptags} and
-@code{:endgrouptag} keyword directly when setting @code{org-tag-alist}
-directly:
-
-@lisp
-(setq org-tag-alist '((:startgrouptag)
-                      ("GTD")
-                      (:grouptags)
-                      ("Control")
-                      ("Persp")
-                      (:endgrouptag)
-                      (:startgrouptag)
-                      ("Control")
-                      (:grouptags)
-                      ("Context")
-                      ("Task")
-                      (:endgrouptag)))
-@end lisp
+@itemize
+@item
+@samp{GTD}
+@itemize
+@item
+@samp{Persp}
+@itemize
+@item
+@samp{Vision}
+@item
+@samp{Goal}
+@item
+@samp{AOF}
+@item
+@samp{Project}
+@end itemize
+@item
+@samp{Control}
+@itemize
+@item
+@samp{Context}
+@item
+@samp{Task}
+@end itemize
+@end itemize
+@end itemize
+
+You can use the @code{:startgrouptag}, @code{:grouptags} and 
@code{:endgrouptag}
+keyword directly when setting @code{org-tag-alist} directly:
+
+@lisp
+(setq org-tag-alist '((:startgrouptag)
+                      ("GTD")
+                      (:grouptags)
+                      ("Control")
+                      ("Persp")
+                      (:endgrouptag)
+                      (:startgrouptag)
+                      ("Control")
+                      (:grouptags)
+                      ("Context")
+                      ("Task")
+                      (:endgrouptag)))
+@end lisp
 
-The tags in a group can be mutually exclusive if using the same group syntax
-as is used for grouping mutually exclusive tags together; using curly
-brackets.
+The tags in a group can be mutually exclusive if using the same group
+syntax as is used for grouping mutually exclusive tags together; using
+curly brackets.
 
 @example
 #+TAGS: @{ Context : @@Home @@Work @@Call @}
 @end example
 
-When setting @code{org-tag-alist} you can use @code{:startgroup} &
-@code{:endgroup} instead of @code{:startgrouptag} & @code{:endgrouptag} to
-make the tags mutually exclusive.
 
-Furthermore, the members of a @emph{group tag} can also be regular
+When setting @code{org-tag-alist} you can use @code{:startgroup} and 
@code{:endgroup}
+instead of @code{:startgrouptag} and @code{:endgrouptag} to make the tags
+mutually exclusive.
+
+Furthermore, the members of a group tag can also be regular
 expressions, creating the possibility of a more dynamic and rule-based
 tag structure.  The regular expressions in the group must be specified
-within @{ @}.  Here is an expanded example:
+within curly brackets.  Here is an expanded example:
 
 @example
-#+TAGS: [ Vision : @{V@@@.+@} ]
-#+TAGS: [ Goal : @{G@@@.+@} ]
-#+TAGS: [ AOF : @{AOF@@@.+@} ]
-#+TAGS: [ Project : @{P@@@.+@} ]
+#+TAGS: [ Vision : @{V@@.+@} ]
+#+TAGS: [ Goal : @{G@@.+@} ]
+#+TAGS: [ AOF : @{AOF@@.+@} ]
+#+TAGS: [ Project : @{P@@.+@} ]
 @end example
 
-Searching for the tag @samp{Project} will now list all tags also including
-regular expression matches for @samp{P@@@.+}, and similarly for tag searches on
-@samp{Vision}, @samp{Goal} and @samp{AOF}.  For example, this would work well
-for a project tagged with a common project-identifier, e.g. 
@samp{P@@2014_OrgTags}.
+Searching for the tag @samp{Project} now lists all tags also including
+regular expression matches for @samp{P@@.+}, and similarly for tag searches
+on @samp{Vision}, @samp{Goal} and @samp{AOF}.  For example, this would work 
well for
+a project tagged with a common project-identifier, e.g.,
+@samp{P@@2014_OrgTags}.
 
 @kindex C-c C-x q
+@findex org-toggle-tags-groups
 @vindex org-group-tags
-If you want to ignore group tags temporarily, toggle group tags support
-with @command{org-toggle-tags-groups}, bound to @kbd{C-c C-x q}.  If you
-want to disable tag groups completely, set @code{org-group-tags} to @code{nil}.
+If you want to ignore group tags temporarily, toggle group tags
+support with @code{org-toggle-tags-groups}, bound to @kbd{C-c C-x q}.
+If you want to disable tag groups completely, set @code{org-group-tags} to
+@code{nil}.
+
+@node Tag Searches
+@section Tag Searches
 
-@node Tag searches
-@section Tag searches
 @cindex tag searches
 @cindex searching for tags
 
-Once a system of tags has been set up, it can be used to collect related
-information into special lists.
-
-@table @kbd
-@orgcmdkkc{C-c / m,C-c \\,org-match-sparse-tree}
-Create a sparse tree with all headlines matching a tags/property/TODO search.
-With a @kbd{C-u} prefix argument, ignore headlines that are not a TODO line.
-@xref{Matching tags and properties}.
-@orgcmd{C-c a m,org-tags-view}
-Create a global list of tag matches from all agenda files.  @xref{Matching
-tags and properties}.
-@orgcmd{C-c a M,org-tags-view}
+Once a system of tags has been set up, it can be used to collect
+related information into special lists.
+
+@table @asis
+@item @kbd{C-c / m} or @kbd{C-c \} (@code{org-match-sparse-tree})
+@kindex C-c / m
+@kindex C-c \
+@findex org-match-sparse-tree
+Create a sparse tree with all headlines matching a tags search.
+With a @kbd{C-u} prefix argument, ignore headlines that are not
+a TODO line.
+
+@item @kbd{M-x org-agenda m} (@code{org-tags-view})
+@kindex m @r{(Agenda dispatcher)}
+@findex org-tags-view
+Create a global list of tag matches from all agenda files.  See
+@ref{Matching tags and properties}.
+
+@item @kbd{M-x org-agenda M} (@code{org-tags-view})
+@kindex M @r{(Agenda dispatcher)}
 @vindex org-tags-match-list-sublevels
 Create a global list of tag matches from all agenda files, but check
 only TODO items and force checking subitems (see the option
 @code{org-tags-match-list-sublevels}).
 @end table
 
-These commands all prompt for a match string which allows basic Boolean logic
-like @samp{+boss+urgent-project1}, to find entries with tags @samp{boss} and
-@samp{urgent}, but not @samp{project1}, or @samp{Kathy|Sally} to find entries
-tagged as @samp{Kathy} or @samp{Sally}.  The full syntax of the search string
-is rich and allows also matching against TODO keywords, entry levels and
-properties.  For a complete description with many examples, see @ref{Matching
-tags and properties}.
+These commands all prompt for a match string which allows basic
+Boolean logic like @samp{+boss+urgent-project1}, to find entries with tags
+@samp{boss} and @samp{urgent}, but not @samp{project1}, or @samp{Kathy|Sally} 
to find
+entries which are tagged, like @samp{Kathy} or @samp{Sally}.  The full syntax 
of
+the search string is rich and allows also matching against TODO
+keywords, entry levels and properties.  For a complete description
+with many examples, see @ref{Matching tags and properties}.
 
+@node Properties and Columns
+@chapter Properties and Columns
 
-@node Properties and columns
-@chapter Properties and columns
 @cindex properties
 
-A property is a key-value pair associated with an entry.  Properties can be
-set so they are associated with a single entry, with every entry in a tree,
-or with every entry in an Org mode file.
+A property is a key-value pair associated with an entry.  Properties
+can be set so they are associated with a single entry, with every
+entry in a tree, or with every entry in an Org file.
 
 There are two main applications for properties in Org mode.  First,
-properties are like tags, but with a value.  Imagine maintaining a file where
-you document bugs and plan releases for a piece of software.  Instead of
-using tags like @code{:release_1:}, @code{:release_2:}, you can use a
-property, say @code{:Release:}, that in different subtrees has different
-values, such as @code{1.0} or @code{2.0}.  Second, you can use properties to
-implement (very basic) database capabilities in an Org buffer.  Imagine
-keeping track of your music CDs, where properties could be things such as the
-album, artist, date of release, number of tracks, and so on.
-
-Properties can be conveniently edited and viewed in column view
-(@pxref{Column view}).
+properties are like tags, but with a value.  Imagine maintaining
+a file where you document bugs and plan releases for a piece of
+software.  Instead of using tags like @samp{release_1}, @samp{release_2}, you
+can use a property, say @samp{Release}, that in different subtrees has
+different values, such as @samp{1.0} or @samp{2.0}.  Second, you can use
+properties to implement (very basic) database capabilities in an Org
+buffer.  Imagine keeping track of your music CDs, where properties
+could be things such as the album, artist, date of release, number of
+tracks, and so on.
+
+Properties can be conveniently edited and viewed in column view (see
+@ref{Column View}).
 
 @menu
-* Property syntax::             How properties are spelled out
-* Special properties::          Access to other Org mode features
-* Property searches::           Matching property values
-* Property inheritance::        Passing values down the tree
-* Column view::                 Tabular viewing and editing
-* Property API::                Properties for Lisp programmers
+* Property Syntax::              How properties are spelled out.
+* Special Properties::           Access to other Org mode features.
+* Property Searches::            Matching property values.
+* Property Inheritance::         Passing values down a tree.
+* Column View::                  Tabular viewing and editing.
 @end menu
 
-@node Property syntax
-@section Property syntax
+@node Property Syntax
+@section Property Syntax
+
 @cindex property syntax
 @cindex drawer, for properties
 
-Properties are key-value pairs.  When they are associated with a single entry
-or with a tree they need to be inserted into a special drawer
-(@pxref{Drawers}) with the name @code{PROPERTIES}, which has to be located
-right below a headline, and its planning line (@pxref{Deadlines and
-scheduling}) when applicable.  Each property is specified on a single line,
-with the key (surrounded by colons) first, and the value after it.  Keys are
-case-insensitive.  Here is an example:
+Properties are key--value pairs.  When they are associated with
+a single entry or with a tree they need to be inserted into a special
+drawer (see @ref{Drawers}) with the name @samp{PROPERTIES}, which has to be
+located right below a headline, and its planning line (see @ref{Deadlines and 
Scheduling}) when applicable.  Each property is specified on
+a single line, with the key---surrounded by colons---first, and the
+value after it.  Keys are case-insensitive.  Here is an example:
 
 @example
 * CD collection
@@ -5291,23 +5594,23 @@ case-insensitive.  Here is an example:
     :PROPERTIES:
     :Title:     Goldberg Variations
     :Composer:  J.S. Bach
-    :Artist:    Glen Gould
+    :Artist:    Glenn Gould
     :Publisher: Deutsche Grammophon
     :NDisks:    1
     :END:
 @end example
 
-Depending on the value of @code{org-use-property-inheritance}, a property set
-this way will either be associated with a single entry, or the subtree
-defined by the entry, see @ref{Property inheritance}.
+Depending on the value of @code{org-use-property-inheritance}, a property
+set this way is associated either with a single entry, or with the
+sub-tree defined by the entry, see @ref{Property Inheritance}.
 
-You may define the allowed values for a particular property @samp{:Xyz:}
-by setting a property @samp{:Xyz_ALL:}.  This special property is
-@emph{inherited}, so if you set it in a level 1 entry, it will apply to
-the entire tree.  When allowed values are defined, setting the
-corresponding property becomes easier and is less prone to typing
-errors.  For the example with the CD collection, we can predefine
-publishers and the number of disks in a box like this:
+You may define the allowed values for a particular property @samp{Xyz} by
+setting a property @samp{Xyz_ALL}.  This special property is @emph{inherited},
+so if you set it in a level 1 entry, it applies to the entire tree.
+When allowed values are defined, setting the corresponding property
+becomes easier and is less prone to typing errors.  For the example
+with the CD collection, we can pre-define publishers and the number of
+disks in a box like this:
 
 @example
 * CD collection
@@ -5317,235 +5620,295 @@ publishers and the number of disks in a box like this:
   :END:
 @end example
 
-If you want to set properties that can be inherited by any entry in a
-file, use a line like
-@cindex property, @code{_ALL}
-@cindex @code{#+PROPERTY}
+If you want to set properties that can be inherited by any entry in
+a file, use a line like:
+
+@cindex @samp{_ALL} suffix, in properties
+@cindex @samp{PROPERTY}, keyword
 @example
 #+PROPERTY: NDisks_ALL 1 2 3 4
 @end example
 
-Contrary to properties set from a special drawer, you have to refresh the
-buffer with @kbd{C-c C-c} to activate this change.
 
-If you want to add to the value of an existing property, append a @code{+} to
-the property name.  The following results in the property @code{var} having
-the value ``foo=1 bar=2''.
-@cindex property, @code{+}
+@cindex @samp{+} suffix, in properties
+If you want to add to the value of an existing property, append a @samp{+}
+to the property name.  The following results in the property @samp{var}
+having the value @samp{foo=1 bar=2}.
+
 @example
 #+PROPERTY: var  foo=1
 #+PROPERTY: var+ bar=2
 @end example
 
 It is also possible to add to the values of inherited properties.  The
-following results in the @code{genres} property having the value ``Classic
-Baroque'' under the @code{Goldberg Variations} subtree.
-@cindex property, @code{+}
+following results in the @samp{Genres} property having the value @samp{Classic
+Baroque} under the @samp{Goldberg Variations} subtree.
+
 @example
 * CD collection
 ** Classic
     :PROPERTIES:
-    :GENRES: Classic
+    :Genres: Classic
     :END:
 *** Goldberg Variations
     :PROPERTIES:
     :Title:     Goldberg Variations
     :Composer:  J.S. Bach
-    :Artist:    Glen Gould
+    :Artist:    Glenn Gould
     :Publisher: Deutsche Grammophon
     :NDisks:    1
-    :GENRES+:   Baroque
+    :Genres+:   Baroque
     :END:
 @end example
-Note that a property can only have one entry per Drawer.
+
+Note that a property can only have one entry per drawer.
 
 @vindex org-global-properties
-Property values set with the global variable
-@code{org-global-properties} can be inherited by all entries in all
-Org files.
+Property values set with the global variable @code{org-global-properties}
+can be inherited by all entries in all Org files.
 
-@noindent
 The following commands help to work with properties:
 
-@table @kbd
-@orgcmd{M-@key{TAB},pcomplete}
-After an initial colon in a line, complete property keys.  All keys used
-in the current file will be offered as possible completions.
-@orgcmd{C-c C-x p,org-set-property}
+@table @asis
+@item @kbd{M-@key{TAB}} (@code{pcomplete})
+@kindex M-TAB
+@findex pcomplete
+After an initial colon in a line, complete property keys.  All keys
+used in the current file are offered as possible completions.
+
+@item @kbd{C-c C-x p} (@code{org-set-property})
+@kindex C-c C-x p
+@findex org-set-property
 Set a property.  This prompts for a property name and a value.  If
 necessary, the property drawer is created as well.
-@item C-u M-x org-insert-drawer @key{RET}
-@cindex @code{org-insert-drawer}
-Insert a property drawer into the current entry.  The drawer will be
+
+@item @kbd{C-u M-x org-insert-drawer}
+@findex org-insert-drawer
+Insert a property drawer into the current entry.  The drawer is
 inserted early in the entry, but after the lines with planning
 information like deadlines.
-@orgcmd{C-c C-c,org-property-action}
-With the cursor in a property drawer, this executes property commands.
-@orgcmd{C-c C-c s,org-set-property}
-Set a property in the current entry.  Both the property and the value
-can be inserted using completion.
-@orgcmdkkcc{S-@key{RIGHT},S-@key{LEFT},org-property-next-allowed-value,org-property-previous-allowed-value}
+
+@item @kbd{C-c C-c} (@code{org-property-action})
+@kindex C-c C-c
+@findex org-property-action
+With point in a property drawer, this executes property commands.
+
+@item @kbd{C-c C-c s} (@code{org-set-property})
+@kindex C-c C-c s
+@findex org-set-property
+Set a property in the current entry.  Both the property and the
+value can be inserted using completion.
+
+@item @kbd{S-@key{RIGHT}} (@code{org-property-next-allowed-values})
+@itemx @kbd{S-@key{LEFT}} (@code{org-property-previous-allowed-value})
+@kindex S-RIGHT
+@kindex S-LEFT
 Switch property at point to the next/previous allowed value.
-@orgcmd{C-c C-c d,org-delete-property}
+
+@item @kbd{C-c C-c d} (@code{org-delete-property})
+@kindex C-c C-c d
+@findex org-delete-property
 Remove a property from the current entry.
-@orgcmd{C-c C-c D,org-delete-property-globally}
+
+@item @kbd{C-c C-c D} (@code{org-delete-property-globally})
+@kindex C-c C-c D
+@findex org-delete-property-globally
 Globally remove a property, from all entries in the current file.
-@orgcmd{C-c C-c c,org-compute-property-at-point}
+
+@item @kbd{C-c C-c c} (@code{org-compute-property-at-point})
+@kindex C-c C-c c
+@findex org-compute-property-at-point
 Compute the property at point, using the operator and scope from the
 nearest column format definition.
 @end table
 
-@node Special properties
-@section Special properties
+@node Special Properties
+@section Special Properties
+
 @cindex properties, special
 
-Special properties provide an alternative access method to Org mode features,
-like the TODO state or the priority of an entry, discussed in the previous
-chapters.  This interface exists so that you can include these states in
-a column view (@pxref{Column view}), or to use them in queries.  The
-following property names are special and should not be used as keys in the
-properties drawer:
-
-@cindex property, special, @code{ALLTAGS}
-@cindex property, special, @code{BLOCKED}
-@cindex property, special, @code{CLOCKSUM}
-@cindex property, special, @code{CLOCKSUM_T}
-@cindex property, special, @code{CLOSED}
-@cindex property, special, @code{DEADLINE}
-@cindex property, special, @code{FILE}
-@cindex property, special, @code{ITEM}
-@cindex property, special, @code{PRIORITY}
-@cindex property, special, @code{SCHEDULED}
-@cindex property, special, @code{TAGS}
-@cindex property, special, @code{TIMESTAMP}
-@cindex property, special, @code{TIMESTAMP_IA}
-@cindex property, special, @code{TODO}
-@example
-ALLTAGS      @r{All tags, including inherited ones.}
-BLOCKED      @r{"t" if task is currently blocked by children or siblings.}
-CLOCKSUM     @r{The sum of CLOCK intervals in the subtree.  
@code{org-clock-sum}}
-             @r{must be run first to compute the values in the current buffer.}
-CLOCKSUM_T   @r{The sum of CLOCK intervals in the subtree for today.}
-             @r{@code{org-clock-sum-today} must be run first to compute the}
-             @r{values in the current buffer.}
-CLOSED       @r{When was this entry closed?}
-DEADLINE     @r{The deadline time string, without the angular brackets.}
-FILE         @r{The filename the entry is located in.}
-ITEM         @r{The headline of the entry.}
-PRIORITY     @r{The priority of the entry, a string with a single letter.}
-SCHEDULED    @r{The scheduling timestamp, without the angular brackets.}
-TAGS         @r{The tags defined directly in the headline.}
-TIMESTAMP    @r{The first keyword-less timestamp in the entry.}
-TIMESTAMP_IA @r{The first inactive timestamp in the entry.}
-TODO         @r{The TODO keyword of the entry.}
-@end example
-
-@node Property searches
-@section Property searches
+Special properties provide an alternative access method to Org mode
+features, like the TODO state or the priority of an entry, discussed
+in the previous chapters.  This interface exists so that you can
+include these states in a column view (see @ref{Column View}), or to use
+them in queries.  The following property names are special and should
+not be used as keys in the properties drawer:
+
+@cindex @samp{ALLTAGS}, special property
+@cindex @samp{BLOCKED}, special property
+@cindex @samp{CLOCKSUM}, special property
+@cindex @samp{CLOCKSUM_T}, special property
+@cindex @samp{CLOSED}, special property
+@cindex @samp{DEADLINE}, special property
+@cindex @samp{FILE}, special property
+@cindex @samp{ITEM}, special property
+@cindex @samp{PRIORITY}, special property
+@cindex @samp{SCHEDULED}, special property
+@cindex @samp{TAGS}, special property
+@cindex @samp{TIMESTAMP}, special property
+@cindex @samp{TIMESTAMP_IA}, special property
+@cindex @samp{TODO}, special property
+@multitable {aaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{ALLTAGS}
+@tab All tags, including inherited ones.
+@item @samp{BLOCKED}
+@tab @code{t} if task is currently blocked by children or siblings.
+@item @samp{CATEGORY}
+@tab The category of an entry.
+@item @samp{CLOCKSUM}
+@tab The sum of CLOCK intervals in the subtree.  @code{org-clock-sum}
+@item
+@tab must be run first to compute the values in the current buffer.
+@item @samp{CLOCKSUM_T}
+@tab The sum of CLOCK intervals in the subtree for today.
+@item
+@tab @code{org-clock-sum-today} must be run first to compute the
+@item
+@tab values in the current buffer.
+@item @samp{CLOSED}
+@tab When was this entry closed?
+@item @samp{DEADLINE}
+@tab The deadline time string, without the angular brackets.
+@item @samp{FILE}
+@tab The filename the entry is located in.
+@item @samp{ITEM}
+@tab The headline of the entry.
+@item @samp{PRIORITY}
+@tab The priority of the entry, a string with a single letter.
+@item @samp{SCHEDULED}
+@tab The scheduling timestamp, without the angular brackets.
+@item @samp{TAGS}
+@tab The tags defined directly in the headline.
+@item @samp{TIMESTAMP}
+@tab The first keyword-less timestamp in the entry.
+@item @samp{TIMESTAMP_IA}
+@tab The first inactive timestamp in the entry.
+@item @samp{TODO}
+@tab The TODO keyword of the entry.
+@end multitable
+
+@node Property Searches
+@section Property Searches
+
 @cindex properties, searching
 @cindex searching, of properties
 
-To create sparse trees and special lists with selection based on properties,
-the same commands are used as for tag searches (@pxref{Tag searches}).
-
-@table @kbd
-@orgcmdkkc{C-c / m,C-c \\,org-match-sparse-tree}
-Create a sparse tree with all matching entries.  With a
-@kbd{C-u} prefix argument, ignore headlines that are not a TODO line.
-@orgcmd{C-c a m,org-tags-view}
-Create a global list of tag/property  matches from all agenda files.
-@xref{Matching tags and properties}.
-@orgcmd{C-c a M,org-tags-view}
+To create sparse trees and special lists with selection based on
+properties, the same commands are used as for tag searches (see @ref{Tag 
Searches}).
+
+@table @asis
+@item @kbd{C-c / m} or @kbd{C-c \} (@code{org-match-sparse-tree})
+@kindex C-c / m
+@kindex C-c \
+@findex org-match-sparse-tree
+Create a sparse tree with all matching entries.  With
+a @kbd{C-u} prefix argument, ignore headlines that are not
+a TODO line.
+
+@item @kbd{M-x org-agenda m}, @code{org-tags-view}
+@kindex m @r{(Agenda dispatcher)}
+@findex org-tags-view
+Create a global list of tag/property matches from all agenda files.
+
+@item @kbd{M-x org-agenda M} (@code{org-tags-view})
+@kindex M @r{(Agenda dispatcher)}
 @vindex org-tags-match-list-sublevels
 Create a global list of tag matches from all agenda files, but check
 only TODO items and force checking of subitems (see the option
 @code{org-tags-match-list-sublevels}).
 @end table
 
-The syntax for the search string is described in @ref{Matching tags and
-properties}.
+The syntax for the search string is described in @ref{Matching tags and 
properties}.
 
 There is also a special command for creating sparse trees based on a
 single property:
 
-@table @kbd
-@orgkey{C-c / p}
+@table @asis
+@item @kbd{C-c / p}
+@kindex C-c / p
 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 in curly braces, it is interpreted as
-a regular expression and matched against the property values.
+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 in curly braces, it is
+interpreted as a regular expression and matched against the property
+values.
 @end table
 
-@node Property inheritance
+@node Property Inheritance
 @section Property Inheritance
+
 @cindex properties, inheritance
 @cindex inheritance, of properties
 
 @vindex org-use-property-inheritance
-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
-significantly and is often not needed.  However, if you find inheritance
-useful, you can turn it on by setting the variable
-@code{org-use-property-inheritance}.  It may be set to @code{t} to make
-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 @code{nil}, this is
-interpreted as an explicit undefine of the property, so that inheritance
-search will stop at this value and return @code{nil}.
+The outline structure of Org 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
+significantly and is often not needed.  However, if you find
+inheritance useful, you can turn it on by setting the variable
+@code{org-use-property-inheritance}.  It may be set to @code{t} to make 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 @code{nil}, this is interpreted as
+an explicit un-define of the property, so that inheritance search
+stops at this value and returns @code{nil}.
 
 Org mode has a few properties for which inheritance is hard-coded, at
 least for the special applications for which they are used:
 
-@cindex property, @code{COLUMNS}
-@table @code
-@item COLUMNS
-The @code{:COLUMNS:} property defines the format of column view
-(@pxref{Column view}).  It is inherited in the sense that the level
-where a @code{:COLUMNS:} property is defined is used as the starting
-point for a column view table, independently of the location in the
-subtree from where columns view is turned on.
-@item CATEGORY
-@cindex property, @code{CATEGORY}
-For agenda view, a category set through a @code{:CATEGORY:} property
+@table @asis
+@item @code{COLUMNS}
+@cindex @samp{COLUMNS}, property
+The @samp{COLUMNS} property defines the format of column view (see
+@ref{Column View}).  It is inherited in the sense that the level where
+a @samp{COLUMNS} property is defined is used as the starting point for
+a column view table, independently of the location in the subtree
+from where columns view is turned on.
+
+@item @code{CATEGORY}
+@cindex @samp{CATEGORY}, property
+For agenda view, a category set through a @samp{CATEGORY} property
 applies to the entire subtree.
-@item ARCHIVE
-@cindex property, @code{ARCHIVE}
-For archiving, the @code{:ARCHIVE:} property may define the archive
-location for the entire subtree (@pxref{Moving subtrees}).
-@item LOGGING
-@cindex property, @code{LOGGING}
-The @code{LOGGING} property may define logging settings for an entry or a
-subtree (@pxref{Tracking TODO state changes}).
+
+@item @code{ARCHIVE}
+@cindex @samp{ARCHIVE}, property
+For archiving, the @samp{ARCHIVE} property may define the archive
+location for the entire subtree (see @ref{Moving subtrees}).
+
+@item @code{LOGGING}
+@cindex @samp{LOGGING}, property
+The @samp{LOGGING} property may define logging settings for an entry or
+a subtree (see @ref{Tracking TODO state changes}).
 @end table
 
-@node Column view
-@section Column view
-
-A great way to view and edit properties in an outline tree is
-@emph{column view}.  In column view, each outline node is turned into a
-table row.  Columns in this table provide access to properties of the
-entries.  Org mode implements columns by overlaying a tabular structure
-over the headline of each item.  While the headlines have been turned
-into a table row, you can still change the visibility of the outline
-tree.  For example, you get a compact table by switching to CONTENTS
-view (@kbd{S-@key{TAB} S-@key{TAB}}, or simply @kbd{c} while column view
-is active), but you can still open, read, and edit the entry below each
-headline.  Or, you can switch to column view after executing a sparse
-tree command and in this way get a table only for the selected items.
-Column view also works in agenda buffers (@pxref{Agenda views}) where
-queries have collected selected items, possibly from a number of files.
+@node Column View
+@section Column View
+
+A great way to view and edit properties in an outline tree is @emph{column
+view}.  In column view, each outline node is turned into a table row.
+Columns in this table provide access to properties of the entries.
+Org mode implements columns by overlaying a tabular structure over the
+headline of each item.  While the headlines have been turned into
+a table row, you can still change the visibility of the outline tree.
+For example, you get a compact table by switching to ``contents''
+view---@kbd{S-@key{TAB}} @kbd{S-@key{TAB}}, or simply @kbd{c}
+while column view is active---but you can still open, read, and edit
+the entry below each headline.  Or, you can switch to column view
+after executing a sparse tree command and in this way get a table only
+for the selected items.  Column view also works in agenda buffers (see
+@ref{Agenda Views}) where queries have collected selected items, possibly
+from a number of files.
 
 @menu
-* Defining columns::            The COLUMNS format property
-* Using column view::           How to create and use column view
-* Capturing column view::       A dynamic block for column view
+* Defining columns::             The COLUMNS format property.
+* Using column view::            How to create and use column view.
+* Capturing column view::        A dynamic block for column view.
 @end menu
 
 @node Defining columns
 @subsection Defining columns
+
 @cindex column view, for properties
 @cindex properties, column view
 
@@ -5554,21 +5917,22 @@ done by defining a column format line.
 
 @menu
 * Scope of column definitions::  Where defined, where valid?
-* Column attributes::           Appearance and content of a column
+* Column attributes::            Appearance and content of a column.
 @end menu
 
 @node Scope of column definitions
 @subsubsection Scope of column definitions
 
-To define a column format for an entire file, use a line like
+To define a column format for an entire file, use a line like:
 
-@cindex @code{#+COLUMNS}
+@cindex @samp{COLUMNS}, keyword
 @example
 #+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO
 @end example
 
-To specify a format that only applies to a specific tree, add a
-@code{:COLUMNS:} property to the top node of that tree, for example:
+
+To specify a format that only applies to a specific tree, add
+a @samp{COLUMNS} property to the top node of that tree, for example:
 
 @example
 ** Top node for columns view
@@ -5577,96 +5941,117 @@ To specify a format that only applies to a specific 
tree, add a
    :END:
 @end example
 
-If a @code{:COLUMNS:} property is present in an entry, it defines columns
-for the entry itself, and for the entire subtree below it.  Since the
-column definition is part of the hierarchical structure of the document,
-you can define columns on level 1 that are general enough for all
-sublevels, and more specific columns further down, when you edit a
-deeper part of the tree.
+If a @samp{COLUMNS} property is present in an entry, it defines columns for
+the entry itself, and for the entire subtree below it.  Since the
+column definition is part of the hierarchical structure of the
+document, you can define columns on level 1 that are general enough
+for all sublevels, and more specific columns further down, when you
+edit a deeper part of the tree.
 
 @node Column attributes
 @subsubsection Column attributes
+
 A column definition sets the attributes of a column.  The general
 definition looks like this:
 
 @example
- %[@var{width}]@var{property}[(@var{title})][@{@var{summary-type}@}]
+%[WIDTH]PROPERTY[(TITLE)][@{SUMMARY-TYPE@}]
 @end example
 
+
 @noindent
 Except for the percent sign and the property name, all items are
 optional.  The individual parts have the following meaning:
 
-@example
-@var{width}           @r{An integer specifying the width of the column in 
characters.}
-                @r{If omitted, the width will be determined automatically.}
-@var{property}        @r{The property that should be edited in this column.}
-                @r{Special properties representing meta data are allowed here}
-                @r{as well (@pxref{Special properties})}
-@var{title}           @r{The header text for the column.  If omitted, the 
property}
-                @r{name is used.}
-@{@var{summary-type}@}  @r{The summary type.  If specified, the column values 
for}
-                @r{parent nodes are computed from the children@footnote{If
-                more than one summary type apply to the property, the parent
-                values are computed according to the first of them.}.}
-                @r{Supported summary types are:}
-                @{+@}       @r{Sum numbers in this column.}
-                @{+;%.1f@}  @r{Like @samp{+}, but format result with 
@samp{%.1f}.}
-                @{$@}       @r{Currency, short for @samp{+;%.2f}.}
-                @{min@}     @r{Smallest number in column.}
-                @{max@}     @r{Largest number.}
-                @{mean@}    @r{Arithmetic mean of numbers.}
-                @{X@}       @r{Checkbox status, @samp{[X]} if all children are 
@samp{[X]}.}
-                @{X/@}      @r{Checkbox status, @samp{[n/m]}.}
-                @{X%@}      @r{Checkbox status, @samp{[n%]}.}
-                @{:@}       @r{Sum times, HH:MM, plain numbers are
-                hours@footnote{A time can also be a duration, using effort
-                modifiers defined in @code{org-effort-durations}, e.g.,
-                @samp{3d 1h}.  If any value in the column is as such, the
-                summary will also be an effort duration.}.}
-                @{:min@}    @r{Smallest time value in column.}
-                @{:max@}    @r{Largest time value.}
-                @{:mean@}   @r{Arithmetic mean of time values.}
-                @{@@min@}    @r{Minimum age@footnote{An age is defined as
-                a duration since a given time-stamp (@pxref{Timestamps}).  It
-                can  also be expressed as days, hours, minutes and seconds,
-                identified by @samp{d}, @samp{h}, @samp{m} and @samp{s}
-                suffixes, all mandatory, e.g., @samp{0d 13h 0m 10s}.} (in
-                days/hours/mins/seconds).}
-                @{@@max@}    @r{Maximum age (in days/hours/mins/seconds).}
-                @{@@mean@}   @r{Arithmetic mean of ages (in 
days/hours/mins/seconds).}
-                @{est+@}    @r{Add @samp{low-high} estimates.}
-@end example
-
-The @code{est+} summary type requires further explanation.  It is used for
-combining estimates, expressed as @samp{low-high} ranges or plain numbers.
-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
-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.
-
-When combining a set of such estimates, simply adding the lows and highs
-produces an unrealistically wide result.  Instead, @code{est+} adds the
-statistical mean and variance of the sub-tasks, generating a final estimate
-from the sum.  For example, suppose you had ten tasks, each of which was
-estimated at 0.5 to 2 days of work.  Straight addition produces an estimate
-of 5 to 20 days, representing what to expect if everything goes either
-extremely well or extremely poorly.  In contrast, @code{est+} estimates the
-full job more realistically, at 10--15 days.
-
-Numbers are right-aligned when a format specifier with an explicit width like
-@code{%5d} or @code{%5.1f} is used.
+@table @asis
+@item @var{WIDTH}
+An integer specifying the width of the column in characters.  If
+omitted, the width is determined automatically.
+
+@item @var{PROPERTY}
+The property that should be edited in this column.  Special
+properties representing meta data are allowed here as well (see
+@ref{Special Properties}).
+
+@item @var{TITLE}
+The header text for the column.  If omitted, the property name is
+used.
+
+@item @var{SUMMARY-TYPE}
+The summary type.  If specified, the column values for parent nodes
+are computed from the children@footnote{If more than one summary type applies 
to the same property,
+the parent values are computed according to the first of them.}.
+
+Supported summary types are:
+
+@multitable {aaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{+}
+@tab Sum numbers in this column.
+@item @samp{+;%.1f}
+@tab Like @samp{+}, but format result with @samp{%.1f}.
+@item @samp{$}
+@tab Currency, short for @samp{+;%.2f}.
+@item @samp{min}
+@tab Smallest number in column.
+@item @samp{max}
+@tab Largest number.
+@item @samp{mean}
+@tab Arithmetic mean of numbers.
+@item @samp{X}
+@tab Checkbox status, @samp{[X]} if all children are @samp{[X]}.
+@item @samp{X/}
+@tab Checkbox status, @samp{[n/m]}.
+@item @samp{X%}
+@tab Checkbox status, @samp{[n%]}.
+@item @samp{:}
+@tab Sum times, HH:MM, plain numbers are minutes.
+@item @samp{:min}
+@tab Smallest time value in column.
+@item @samp{:max}
+@tab Largest time value.
+@item @samp{:mean}
+@tab Arithmetic mean of time values.
+@item @samp{@@min}
+@tab Minimum age@footnote{An age can be defined as a duration, using units 
defined in
+@code{org-duration-units}, e.g., @samp{3d 1h}.  If any value in the column is 
as
+such, the summary is also expressed as a duration.} (in 
days/hours/mins/seconds).
+@item @samp{@@max}
+@tab Maximum age (in days/hours/mins/seconds).
+@item @samp{@@mean}
+@tab Arithmetic mean of ages (in days/hours/mins/seconds).
+@item @samp{est+}
+@tab Add low-high estimates.
+@end multitable
 
 @vindex org-columns-summary-types
 You can also define custom summary types by setting
-@code{org-columns-summary-types}, which see.
-
-Here is an example for a complete columns definition, along with allowed
-values.
+@code{org-columns-summary-types}.
+@end table
 
-@example
-:COLUMNS:  %25ITEM %9Approved(Approved?)@{X@} %Owner %11Status 
\@footnote{Please note that the COLUMNS definition must be on a single 
line---it is wrapped here only because of formatting constraints.}
+The @samp{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
+work is required, or 1--10 days if you do not really know what needs
+to be done.  Both ranges average at 5.5 days, but the first represents
+a more predictable delivery.
+
+When combining a set of such estimates, simply adding the lows and
+highs produces an unrealistically wide result.  Instead, @samp{est+} adds
+the statistical mean and variance of the subtasks, generating a final
+estimate from the sum.  For example, suppose you had ten tasks, each
+of which was estimated at 0.5 to 2 days of work.  Straight addition
+produces an estimate of 5 to 20 days, representing what to expect if
+everything goes either extremely well or extremely poorly.  In
+contrast, @samp{est+} estimates the full job more realistically, at 10--15
+days.
+
+Here is an example for a complete columns definition, along with
+allowed values@footnote{Please note that the @samp{COLUMNS} definition must be 
on a single
+line; it is wrapped here only because of formatting constraints.}.
+
+@example
+:COLUMNS:  %25ITEM %9Approved(Approved?)@{X@} %Owner %11Status \
                    %10Time_Estimate@{:@} %CLOCKSUM %CLOCKSUM_T
 :Owner_ALL:    Tammy Mark Karl Lisa Don
 :Status_ALL:   "In progress" "Not started yet" "Finished" ""
@@ -5674,78 +6059,129 @@ values.
 @end example
 
 @noindent
-The first column, @samp{%25ITEM}, means the first 25 characters of the
-item itself, i.e., of the headline.  You probably always should start the
+The first column, @samp{%25ITEM}, means the first 25 characters of the item
+itself, i.e., of the headline.  You probably always should start the
 column definition with the @samp{ITEM} specifier.  The other specifiers
 create columns @samp{Owner} with a list of names as allowed values, for
-@samp{Status} with four different possible values, and for a checkbox
-field @samp{Approved}.  When no width is given after the @samp{%}
-character, the column will be exactly as wide as it needs to be in order
-to fully display all values.  The @samp{Approved} column does have a
-modified title (@samp{Approved?}, with a question mark).  Summaries will
-be created for the @samp{Time_Estimate} column by adding time duration
-expressions like HH:MM, and for the @samp{Approved} column, by providing
-an @samp{[X]} status if all children have been checked.  The
-@samp{CLOCKSUM} and @samp{CLOCKSUM_T} columns are special, they lists the
-sums of CLOCK intervals in the subtree, either for all clocks or just for
-today.
+@samp{Status} with four different possible values, and for a checkbox field
+@samp{Approved}.  When no width is given after the @samp{%} character, the
+column is exactly as wide as it needs to be in order to fully display
+all values.  The @samp{Approved} column does have a modified title
+(@samp{Approved?}, with a question mark).  Summaries are created for the
+@samp{Time_Estimate} column by adding time duration expressions like HH:MM,
+and for the @samp{Approved} column, by providing an @samp{[X]} status if all
+children have been checked.  The @samp{CLOCKSUM} and @samp{CLOCKSUM_T} columns
+are special, they lists the sums of CLOCK intervals in the subtree,
+either for all clocks or just for today.
 
 @node Using column view
 @subsection Using column view
 
-@table @kbd
-@tsubheading{Turning column view on and off}
-@orgcmd{C-c C-x C-c,org-columns}
+
+
+@anchor{Turning column view on or off}
+@subsubheading Turning column view on or off
+
+@table @asis
+@item @kbd{C-c C-x C-c} (@code{org-columns})
+@kindex C-c C-x C-c
+@vindex org-columns
 @vindex org-columns-default-format
-Turn on column view.  If the cursor is before the first headline in the file,
-or the function called with the universal prefix argument, column view is
-turned on for the entire file, using the @code{#+COLUMNS} definition.  If the
-cursor is somewhere inside the outline, this command searches the hierarchy,
-up from point, for a @code{:COLUMNS:} property that defines a format.  When
-one is found, the column view table is established for the tree starting at
-the entry that contains the @code{:COLUMNS:} property.  If no such property
-is found, the format is taken from the @code{#+COLUMNS} line or from the
-variable @code{org-columns-default-format}, and column view is established
-for the current entry and its subtree.
-@orgcmd{r,org-columns-redo}
-Recreate the column view, to include recent changes made in the buffer.
-@orgcmd{g,org-columns-redo}
-Same as @kbd{r}.
-@orgcmd{q,org-columns-quit}
+Turn on column view.  If point is before the first headline in the
+file, column view is turned on for the entire file, using the
+@samp{#+COLUMNS} definition.  If point is somewhere inside the outline,
+this command searches the hierarchy, up from point, for a @samp{COLUMNS}
+property that defines a format.  When one is found, the column view
+table is established for the tree starting at the entry that
+contains the @samp{COLUMNS} property.  If no such property is found, the
+format is taken from the @samp{#+COLUMNS} line or from the variable
+@code{org-columns-default-format}, and column view is established for the
+current entry and its subtree.
+
+@item @kbd{r} or @kbd{g} (@code{org-columns-redo})
+@kindex r
+@kindex g
+@findex org-columns-redo
+Recreate the column view, to include recent changes made in the
+buffer.
+
+@item @kbd{q} (@code{org-columns-quit})
+@kindex q
+@findex org-columns-quit
 Exit column view.
-@tsubheading{Editing values}
-@item @key{LEFT} @key{RIGHT} @key{UP} @key{DOWN}
+@end table
+
+@anchor{Editing values}
+@subsubheading Editing values
+
+@table @asis
+@item @kbd{@key{LEFT}}, @kbd{@key{RIGHT}}, @kbd{@key{UP}}, @kbd{@key{DOWN}}
 Move through the column view from field to field.
-@kindex S-LEFT
+
+@item @kbd{1..9,0}
+@kindex 1..9,0
+Directly select the Nth allowed value, @kbd{0} selects the
+10th value.
+
+@item @kbd{n} or @kbd{S-@key{RIGHT}} (@code{org-columns-next-allowed-value})
+@itemx @kbd{p} or @kbd{S-@key{LEFT}} 
(@code{org-columns-previous-allowed-value})
+@kindex n
 @kindex S-RIGHT
-@item  S-@key{LEFT}/@key{RIGHT}
-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.
-@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}
-Edit the property at point.  For the special properties, this will
-invoke the same interface that you normally use to change that
-property.  For example, when editing a TAGS property, the tag completion
-or fast selection interface will pop up.
-@orgcmd{C-c C-c,org-columns-set-tags-or-toggle}
+@kindex p
+@kindex S-LEFT
+@findex org-columns-next-allowed-value
+@findex org-columns-previous-allowed-value
+Switch to the next/previous allowed value of the field.  For this,
+you have to have specified allowed values for a property.
+
+@item @kbd{e} (@code{org-columns-edit-value})
+@kindex e
+@findex org-columns-edit-value
+Edit the property at point.  For the special properties, this
+invokes the same interface that you normally use to change that
+property.  For example, the tag completion or fast selection
+interface pops up when editing a @samp{TAGS} property.
+
+@item @kbd{C-c C-c} (@code{org-columns-set-tags-or-toggle})
+@kindex C-c C-c
+@findex org-columns-set-tags-or-toggle
 When there is a checkbox at point, toggle it.
-@orgcmd{v,org-columns-show-value}
-View the full value of this property.  This is useful if the width of
-the column is smaller than that of the value.
-@orgcmd{a,org-columns-edit-allowed}
-Edit the list of allowed values for this property.  If the list is found
-in the hierarchy, the modified value is stored there.  If no list is
-found, the new value is stored in the first entry that is part of the
-current column view.
-@tsubheading{Modifying the table structure}
-@orgcmdkkcc{<,>,org-columns-narrow,org-columns-widen}
+
+@item @kbd{v} (@code{org-columns-show-value})
+@kindex v
+@findex org-columns-show-value
+View the full value of this property.  This is useful if the width
+of the column is smaller than that of the value.
+
+@item @kbd{a} (@code{org-columns-edit-allowed})
+@kindex a
+@findex org-columns-edit-allowed
+Edit the list of allowed values for this property.  If the list is
+found in the hierarchy, the modified values is stored there.  If no
+list is found, the new value is stored in the first entry that is
+part of the current column view.
+@end table
+
+@anchor{Modifying column view on-the-fly}
+@subsubheading Modifying column view on-the-fly
+
+@table @asis
+@item @kbd{<} (@code{org-columns-narrow})
+@itemx @kbd{>} (@code{org-columns-widen})
+@kindex <
+@kindex >
+@findex org-columns-narrow
+@findex org-columns-widen
 Make the column narrower/wider by one character.
-@orgcmd{S-M-@key{RIGHT},org-columns-new}
+
+@item @kbd{S-M-@key{RIGHT}} (@code{org-columns-new})
+@kindex S-M-RIGHT
+@findex org-columns-new
 Insert a new column, to the left of the current column.
-@orgcmd{S-M-@key{LEFT},org-columns-delete}
+
+@item @kbd{S-M-@key{LEFT}} (@code{org-columns-delete})
+@kindex S-M-LEFT
+@findex org-columns-delete
 Delete the current column.
 @end table
 
@@ -5753,11 +6189,11 @@ Delete the current column.
 @subsection Capturing column view
 
 Since column view is just an overlay over a buffer, it cannot be
-exported or printed directly.  If you want to capture a column view, use
-a @code{columnview} dynamic block (@pxref{Dynamic blocks}).  The frame
-of this block looks like this:
+exported or printed directly.  If you want to capture a column view,
+use a @samp{columnview} dynamic block (see @ref{Dynamic Blocks}).  The frame of
+this block looks like this:
 
-@cindex @code{#+BEGIN}, columnview
+@cindex @samp{BEGIN columnview}
 @example
 * The column view
 #+BEGIN: columnview :hlines 1 :id "label"
@@ -5765,129 +6201,147 @@ of this block looks like this:
 #+END:
 @end example
 
-@noindent This dynamic block has the following parameters:
-
-@table @code
-@item :id
-This is the most important parameter.  Column view is a feature that is
-often localized to a certain (sub)tree, and the capture block might be
-at a different location in the file.  To identify the tree whose view to
-capture, you can use 4 values:
-@cindex property, @code{ID}
-@example
-local     @r{use the tree in which the capture block is located}
-global    @r{make a global view, including all headings in the file}
-"file:@var{path-to-file}"
-          @r{run column view at the top of this file}
-"@var{ID}"      @r{call column view in the tree that has an @code{:ID:}}
-          @r{property with the value @i{label}.  You can use}
-          @r{@kbd{M-x org-id-copy @key{RET}} to create a globally unique 
@code{ID} for}
-          @r{the current entry and copy it to the kill-ring.}
-@end example
-@item :hlines
-When @code{t}, insert an hline after every line.  When a number @var{N}, insert
-an hline before each headline with level @code{<= @var{N}}.
-@item :vlines
-When set to @code{t}, force column groups to get vertical lines.
-@item :maxlevel
-When set to a number, don't capture entries below this level.
-@item :skip-empty-rows
-When set to @code{t}, skip rows where the only non-empty specifier of the
-column view is @code{ITEM}.
-@item :indent
-When non-@code{nil}, indent each @code{ITEM} field according to its level.
+This dynamic block has the following parameters:
+
+@table @asis
+@item @samp{:id}
+This is the most important parameter.  Column view is a feature that
+is often localized to a certain (sub)tree, and the capture block
+might be at a different location in the file.  To identify the tree
+whose view to capture, you can use four values:
+
+@table @asis
+@item @samp{local}
+Use the tree in which the capture block is located.
+
+@item @samp{global}
+Make a global view, including all headings in the file.
+
+@item @samp{file:FILENAME}
+Run column view at the top of the @var{FILENAME} file.
 
+@item @samp{LABEL}
+@cindex @samp{ID}, property
+Call column view in the tree that has an @samp{ID} property with the
+value @var{LABEL}.  You can use @kbd{M-x org-id-copy} to
+create a globally unique ID for the current entry and copy it to
+the kill-ring.
+@end table
+
+@item @samp{:hlines}
+When @code{t}, insert an hline after every line.  When a number N, insert
+an hline before each headline with level @code{<= N}.
+
+@item @samp{:vlines}
+When non-@code{nil}, force column groups to get vertical lines.
+
+@item @samp{:maxlevel}
+When set to a number, do not capture entries below this level.
+
+@item @samp{:skip-empty-rows}
+When non-@code{nil}, skip rows where the only non-empty specifier of
+the column view is @samp{ITEM}.
+
+@item @samp{:exclude-tags}
+List of tags to exclude from column view table: entries with these
+tags will be excluded from the column view.
+
+@item @samp{:indent}
+When non-@code{nil}, indent each @samp{ITEM} field according to its level.
+
+@item @samp{:format}
+Specify a column attribute (see @ref{Column attributes}) for the dynamic
+block.
 @end table
 
-@noindent
 The following commands insert or update the dynamic block:
 
-@table @kbd
-@orgcmd{C-c C-x i,org-insert-columns-dblock}
-Insert a dynamic block capturing a column view.  You will be prompted
-for the scope or @code{ID} of the view.
-@orgcmdkkc{C-c C-c,C-c C-x C-u,org-dblock-update}
-Update dynamic block at point.
-@orgcmd{C-u C-c C-x C-u,org-update-all-dblocks}
-Update all dynamic blocks (@pxref{Dynamic blocks}).  This is useful if
-you have several clock table blocks, column-capturing blocks or other dynamic
-blocks in a buffer.
+@table @asis
+@item @kbd{C-c C-x i} (@code{org-insert-columns-dblock})
+@kindex C-c C-x i
+@findex org-insert-columns-dblock
+Insert a dynamic block capturing a column view.  Prompt for the
+scope or ID of the view.
+
+@item @kbd{C-c C-c} @kbd{C-c C-x C-u} (@code{org-dblock-update})
+@kindex C-c C-c
+@kindex C-c C-x C-u
+@findex org-dblock-update
+Update dynamic block at point.  point needs to be in the @samp{#+BEGIN}
+line of the dynamic block.
+
+@item @kbd{C-u C-c C-x C-u} (@code{org-update-all-dblocks})
+@kindex C-u C-c C-x C-u
+Update all dynamic blocks (see @ref{Dynamic Blocks}).  This is useful if
+you have several clock table blocks, column-capturing blocks or
+other dynamic blocks in a buffer.
 @end table
 
 You can add formulas to the column view table and you may add plotting
-instructions in front of the table---these will survive an update of the
-block.  If there is a @code{#+TBLFM:} after the table, the table will
-actually be recalculated automatically after an update.
-
-An alternative way to capture and process property values into a table is
-provided by Eric Schulte's @file{org-collector.el} which is a contributed
-package@footnote{Contributed packages are not part of Emacs, but are
-distributed with the main distribution of Org (visit
-@uref{https://orgmode.org}).}.  It provides a general API to collect
-properties from entries in a certain scope, and arbitrary Lisp expressions to
-process these values before inserting them into a table or a dynamic block.
-
-@node Property API
-@section The Property API
-@cindex properties, API
-@cindex API, for properties
+instructions in front of the table---these survive an update of the
+block.  If there is a @samp{TBLFM} keyword after the table, the table is
+recalculated automatically after an update.
+
+An alternative way to capture and process property values into a table
+is provided by Eric Schulte's @samp{org-collector.el}, which is
+a contributed package@footnote{Contributed packages are not part of Emacs, but 
are
+distributed with the main distribution of Org---visit
+@uref{https://orgmode.org}.}.  It provides a general API to collect
+properties from entries in a certain scope, and arbitrary Lisp
+expressions to process these values before inserting them into a table
+or a dynamic block.
+
+@node Dates and Times
+@chapter Dates and Times
 
-There is a full API for accessing and changing properties.  This API can
-be used by Emacs Lisp programs to work with properties and to implement
-features based on them.  For more information see @ref{Using the
-property API}.
-
-@node Dates and times
-@chapter Dates and times
 @cindex dates
 @cindex times
 @cindex timestamp
 @cindex date stamp
 
-To assist project planning, TODO items can be labeled with a date and/or
-a time.  The specially formatted string carrying the date and time
-information is called a @emph{timestamp} in Org mode.  This may be a
-little confusing because timestamp is often used to indicate when
+To assist project planning, TODO items can be labeled with a date
+and/or a time.  The specially formatted string carrying the date and
+time information is called a @emph{timestamp} in Org mode.  This may be
+a little confusing because timestamp is often used as indicating when
 something was created or last changed.  However, in Org mode this term
 is used in a much wider sense.
 
 @menu
-* Timestamps::                  Assigning a time to a tree entry
-* Creating timestamps::         Commands which insert timestamps
-* Deadlines and scheduling::    Planning your work
-* Clocking work time::          Tracking how long you spend on a task
-* Effort estimates::            Planning work effort in advance
-* Timers::                      Notes with a running timer
+* Timestamps::                   Assigning a time to a tree entry.
+* Creating Timestamps::          Commands to insert timestamps.
+* Deadlines and Scheduling::     Planning your work.
+* Clocking Work Time::           Tracking how long you spend on a task.
+* Effort Estimates::             Planning work effort in advance.
+* Timers::                       Notes with a running timer.
 @end menu
 
-
 @node Timestamps
-@section Timestamps, deadlines, and scheduling
+@section Timestamps
+
 @cindex timestamps
 @cindex ranges, time
 @cindex date stamps
 @cindex deadlines
 @cindex scheduling
 
-A timestamp is a specification of a date (possibly with a time or a range of
-times) in a special format, either @samp{<2003-09-16 Tue>}@footnote{In this
-simplest form, the day name is optional when you type the date yourself.
-However, any dates inserted or modified by Org will add that day name, for
-reading convenience.} or @samp{<2003-09-16 Tue 09:39>} or @samp{<2003-09-16
-Tue 12:00-12:30>}@footnote{This is inspired by the standard ISO 8601
-date/time format.  To use an alternative format, see @ref{Custom time
-format}.}.  A timestamp can appear anywhere in the headline or body of an Org
-tree entry.  Its presence causes entries to be shown on specific dates in the
-agenda (@pxref{Weekly/daily agenda}).  We distinguish:
-
-@table @var
+A timestamp is a specification of a date (possibly with a time or
+a range of times) in a special format, either @samp{<2003-09-16 Tue>} or
+@samp{<2003-09-16 Tue 09:39>} or @samp{<2003-09-16 Tue 
12:00-12:30>}@footnote{The Org date format is inspired by the standard ISO 8601
+date/time format.  To use an alternative format, see @ref{Custom time format}. 
 The day name is optional when you type the date yourself.
+However, any date inserted or modified by Org adds that day name, for
+reading convenience.}.
+A timestamp can appear anywhere in the headline or body of an Org tree
+entry.  Its presence causes entries to be shown on specific dates in
+the agenda (see @ref{Weekly/daily agenda}).  We distinguish:
+
+@table @asis
 @item Plain timestamp; Event; Appointment
 @cindex timestamp
 @cindex appointment
-A simple timestamp just assigns a date/time to an item.  This is just like
-writing down an appointment or event in a paper agenda.  In the agenda
-display, the headline of an entry associated with a plain timestamp will be
-shown exactly on that date.
+A simple timestamp just assigns a date/time to an item.  This is
+just like writing down an appointment or event in a paper agenda.
+In the agenda display, the headline of an entry associated with
+a plain timestamp is shown exactly on that date.
 
 @example
 * Meet Peter at the movies
@@ -5899,30 +6353,31 @@ shown exactly on that date.
 @item Timestamp with repeater interval
 @cindex timestamp, with repeater interval
 A timestamp may contain a @emph{repeater interval}, indicating that it
-applies not only on the given date, but again and again after a certain
-interval of N days (d), weeks (w), months (m), or years (y).  The
-following will show up in the agenda every Wednesday:
+applies not only on the given date, but again and again after
+a certain interval of N days (d), weeks (w), months (m), or years
+(y).  The following shows up in the agenda every Wednesday:
 
 @example
 * Pick up Sam at school
   <2007-05-16 Wed 12:30 +1w>
 @end example
 
-@item Diary-style sexp entries
-For more complex date specifications, Org mode supports using the special
-sexp diary entries implemented in the Emacs calendar/diary
-package@footnote{When working with the standard diary sexp functions, you
-need to be very careful with the order of the arguments.  That order depends
-evilly on the variable @code{calendar-date-style} (or, for older Emacs
-versions, @code{european-calendar-style}).  For example, to specify a date
-December 1, 2005, the call might look like @code{(diary-date 12 1 2005)} or
-@code{(diary-date 1 12 2005)} or @code{(diary-date 2005 12 1)}, depending on
-the settings.  This has been the source of much confusion.  Org mode users
-can resort to special versions of these functions like @code{org-date} or
-@code{org-anniversary}.  These work just like the corresponding @code{diary-}
-functions, but with stable ISO order of arguments (year, month, day) wherever
-applicable, independent of the value of @code{calendar-date-style}.}.  For
-example with optional time
+@item Diary-style expression entries
+@cindex diary style timestamps
+@cindex sexp timestamps
+For more complex date specifications, Org mode supports using the
+special expression diary entries implemented in the Emacs Calendar
+package@footnote{When working with the standard diary expression functions, you
+need to be very careful with the order of the arguments.  That order
+depends evilly on the variable @code{calendar-date-style}.  For example, to
+specify a date December 12, 2005, the call might look like
+@samp{(diary-date 12 1 2005)} or @samp{(diary-date 1 12 2005)} or 
@samp{(diary-date
+2005 12 1)}, depending on the settings.  This has been the source of
+much confusion.  Org mode users can resort to special versions of
+these functions like @code{org-date} or @code{org-anniversary}.  These work 
just
+like the corresponding @code{diary-} functions, but with stable ISO order
+of arguments (year, month, day) wherever applicable, independent of
+the value of @code{calendar-date-style}.}.  For example, with optional time:
 
 @example
 * 22:00-23:00 The nerd meeting on every 2nd Thursday of the month
@@ -5932,9 +6387,9 @@ example with optional time
 @item Time/Date range
 @cindex timerange
 @cindex date range
-Two timestamps connected by @samp{--} denote a range.  The headline
-will be shown on the first and last day of the range, and on any dates
-that are displayed and fall in the range.  Here is an example:
+Two timestamps connected by @samp{--} denote a range.  The headline is
+shown on the first and last day of the range, and on any dates that
+are displayed and fall in the range.  Here is an example:
 
 @example
 ** Meeting in Amsterdam
@@ -5945,182 +6400,228 @@ that are displayed and fall in the range.  Here is an 
example:
 @cindex timestamp, inactive
 @cindex inactive timestamp
 Just like a plain timestamp, but with square brackets instead of
-angular ones.  These timestamps are inactive in the sense that they do
-@emph{not} trigger an entry to show up in the agenda.
+angular ones.  These timestamps are inactive in the sense that they
+do @emph{not} trigger an entry to show up in the agenda.
 
 @example
 * Gillian comes late for the fifth time
   [2006-11-01 Wed]
 @end example
-
 @end table
 
-@node Creating timestamps
-@section Creating timestamps
-@cindex creating timestamps
-@cindex timestamps, creating
+@node Creating Timestamps
+@section Creating Timestamps
 
 For Org mode to recognize timestamps, they need to be in the specific
 format.  All commands listed below produce timestamps in the correct
 format.
 
-@table @kbd
-@orgcmd{C-c .,org-time-stamp}
-Prompt for a date and insert a corresponding timestamp.  When the cursor is
-at an existing timestamp in the buffer, the command is used to modify this
-timestamp instead of inserting a new one.  When this command is used twice in
-succession, a time range is inserted.
-@c
-@orgcmd{C-c !,org-time-stamp-inactive}
-Like @kbd{C-c .}, but insert an inactive timestamp that will not cause
-an agenda entry.
-@c
+@table @asis
+@item @kbd{C-c .} (@code{org-time-stamp})
+@kindex C-c .
+@findex org-time-stamp
+Prompt for a date and insert a corresponding timestamp.  When point
+is at an existing timestamp in the buffer, the command is used to
+modify this timestamp instead of inserting a new one.  When this
+command is used twice in succession, a time range is inserted.
+
 @kindex C-u C-c .
-@kindex C-u C-c !
-@item C-u C-c .
-@itemx C-u C-c !
 @vindex org-time-stamp-rounding-minutes
-Like @kbd{C-c .} and @kbd{C-c !}, but use the alternative format which
-contains date and time.  The default time can be rounded to multiples of 5
-minutes, see the option @code{org-time-stamp-rounding-minutes}.
-@c
-@orgkey{C-c C-c}
-Normalize timestamp, insert/fix day name if missing or wrong.
-@c
-@orgcmd{C-c <,org-date-from-calendar}
-Insert a timestamp corresponding to the cursor date in the Calendar.
-@c
-@orgcmd{C-c >,org-goto-calendar}
-Access the Emacs calendar for the current date.  If there is a
-timestamp in the current line, go to the corresponding date
+When called with a prefix argument, use the alternative format which
+contains date and time.  The default time can be rounded to
+multiples of 5 minutes.  See the option
+@code{org-time-stamp-rounding-minutes}.
+
+@kindex C-u C-u C-c .
+With two prefix arguments, insert an active timestamp with the
+current time without prompting.
+
+@item @kbd{C-c !} (@code{org-time-stamp-inactive})
+@kindex C-c !
+@kindex C-u C-c !
+@kindex C-u C-u C-c !
+@findex org-time-stamp-inactive
+Like @kbd{C-c .}, but insert an inactive timestamp that does
+not cause an agenda entry.
+
+@item @kbd{C-c C-c}
+@kindex C-c C-c
+Normalize timestamp, insert or fix day name if missing or wrong.
+
+@item @kbd{C-c <} (@code{org-date-from-calendar})
+@kindex C-c <
+@findex org-date-from-calendar
+Insert a timestamp corresponding to point date in the calendar.
+
+@item @kbd{C-c >} (@code{org-goto-calendar})
+@kindex C-c >
+@findex org-goto-calendar
+Access the Emacs calendar for the current date.  If there is
+a timestamp in the current line, go to the corresponding date
 instead.
-@c
-@orgcmd{C-c C-o,org-open-at-point}
+
+@item @kbd{C-c C-o} (@code{org-open-at-point})
+@kindex C-c C-o
+@findex org-open-at-point
 Access the agenda for the date given by the timestamp or -range at
-point (@pxref{Weekly/daily agenda}).
-@c
-@orgcmdkkcc{S-@key{LEFT},S-@key{RIGHT},org-timestamp-down-day,org-timestamp-up-day}
-Change date at cursor by one day.  These key bindings conflict with
-shift-selection and related modes (@pxref{Conflicts}).
-@c
-@orgcmdkkcc{S-@key{UP},S-@key{DOWN},org-timestamp-up,org-timestamp-down-down}
-Change the item under the cursor in a timestamp.  The cursor can be on a
-year, month, day, hour or minute.  When the timestamp contains a time range
-like @samp{15:30-16:30}, modifying the first time will also shift the second,
-shifting the time block with constant length.  To change the length, modify
-the second time.  Note that if the cursor is in a headline and not at a
-timestamp, these same keys modify the priority of an item.
-(@pxref{Priorities}).  The key bindings also conflict with shift-selection and
-related modes (@pxref{Conflicts}).
-@c
-@orgcmd{C-c C-y,org-evaluate-time-range}
+point (see @ref{Weekly/daily agenda}).
+
+@item @kbd{S-@key{LEFT}} (@code{org-timestamp-down-day})
+@itemx @kbd{S-@key{RIGHT}} (@code{org-timestamp-up-day})
+@kindex S-LEFT
+@kindex S-RIGHT
+@findex org-timestamp-down-day
+@findex org-timestamp-up-day
+Change date at point by one day.  These key bindings conflict with
+shift-selection and related modes (see @ref{Conflicts}).
+
+@item @kbd{S-@key{UP}} (@code{org-timestamp-up})
+@itemx @kbd{S-@key{DOWN}} (@code{org-timestamp-down})
+@kindex S-UP
+@kindex S-DOWN
+On the beginning or enclosing bracket of a timestamp, change its
+type.  Within a timestamp, change the item under point.  Point can
+be on a year, month, day, hour or minute.  When the timestamp
+contains a time range like @samp{15:30-16:30}, modifying the first time
+also shifts the second, shifting the time block with constant
+length.  To change the length, modify the second time.  Note that if
+point is in a headline and not at a timestamp, these same keys
+modify the priority of an item (see @ref{Priorities}).  The key bindings
+also conflict with shift-selection and related modes (see @ref{Conflicts}).
+
+@item @kbd{C-c C-y} (@code{org-evaluate-time-range})
+@kindex C-c C-y
+@findex org-evaluate-time-range
 @cindex evaluate time range
-Evaluate a time range by computing the difference between start and end.
-With a prefix argument, insert result after the time range (in a table: into
-the following column).
+Evaluate a time range by computing the difference between start and
+end.  With a prefix argument, insert result after the time range (in
+a table: into the following column).
 @end table
 
-
 @menu
-* The date/time prompt::        How Org mode helps you entering date and time
-* Custom time format::          Making dates look different
+* The date/time prompt::         How Org mode helps you enter dates and times.
+* Custom time format::           Making dates look different.
 @end menu
 
 @node The date/time prompt
 @subsection The date/time prompt
+
 @cindex date, reading in minibuffer
 @cindex time, reading in minibuffer
 
 @vindex org-read-date-prefer-future
 When Org mode prompts for a date/time, the default is shown in default
 date/time format, and the prompt therefore seems to ask for a specific
-format.  But it will in fact accept date/time information in a variety of
-formats.  Generally, the information should start at the beginning of the
-string.  Org mode will find whatever information is in
-there and derive anything you have not specified from the @emph{default date
-and time}.  The default is usually the current date and time, but when
-modifying an existing timestamp, or when entering the second stamp of a
-range, it is taken from the stamp in the buffer.  When filling in
-information, Org mode assumes that most of the time you will want to enter a
-date in the future: if you omit the month/year and the given day/month is
-@i{before} today, it will assume that you mean a future date@footnote{See the
-variable @code{org-read-date-prefer-future}.  You may set that variable to
-the symbol @code{time} to even make a time before now shift the date to
-tomorrow.}.  If the date has been automatically shifted into the future, the
-time prompt will show this with @samp{(=>F).}
-
-For example, let's assume that today is @b{June 13, 2006}.  Here is how
-various inputs will be interpreted, the items filled in by Org mode are
-in @b{bold}.
-
-@example
-3-2-5         @result{} 2003-02-05
-2/5/3         @result{} 2003-02-05
-14            @result{} @b{2006}-@b{06}-14
-12            @result{} @b{2006}-@b{07}-12
-2/5           @result{} @b{2007}-02-05
-Fri           @result{} nearest Friday after the default date
-sep 15        @result{} @b{2006}-09-15
-feb 15        @result{} @b{2007}-02-15
-sep 12 9      @result{} 2009-09-12
-12:45         @result{} @b{2006}-@b{06}-@b{13} 12:45
-22 sept 0:34  @result{} @b{2006}-09-22 00:34
-w4            @result{} ISO week four of the current year @b{2006}
-2012 w4 fri   @result{} Friday of ISO week 4 in 2012
-2012-w04-5    @result{} Same as above
-@end example
+format.  But it in fact accepts date/time information in a variety of
+formats.  Generally, the information should start at the beginning of
+the string.  Org mode finds whatever information is in there and
+derives anything you have not specified from the @emph{default date and
+time}.  The default is usually the current date and time, but when
+modifying an existing timestamp, or when entering the second stamp of
+a range, it is taken from the stamp in the buffer.  When filling in
+information, Org mode assumes that most of the time you want to enter
+a date in the future: if you omit the month/year and the given
+day/month is @emph{before} today, it assumes that you mean a future
+date@footnote{See the variable @code{org-read-date-prefer-future}.  You may set
+that variable to the symbol @code{time} to even make a time before now
+shift the date to tomorrow.}.  If the date has been automatically shifted into 
the
+future, the time prompt shows this with @samp{(=>F)}.
+
+For example, let's assume that today is @strong{June 13, 2006}.  Here is how
+various inputs are interpreted, the items filled in by Org mode are in
+@strong{bold}.
+
+@multitable {aaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{3-2-5}
+@tab @result{} 2003-02-05
+@item @samp{2/5/3}
+@tab @result{} 2003-02-05
+@item @samp{14}
+@tab @result{} @strong{2006}-@strong{06}-14
+@item @samp{12}
+@tab @result{} @strong{2006}-@strong{07}-12
+@item @samp{2/5}
+@tab @result{} @strong{2007}-02-05
+@item @samp{Fri}
+@tab @result{} nearest Friday (default date or later)
+@item @samp{sep 15}
+@tab @result{} @strong{2006}-09-15
+@item @samp{feb 15}
+@tab @result{} @strong{2007}-02-15
+@item @samp{sep 12 9}
+@tab @result{} 2009-09-12
+@item @samp{12:45}
+@tab @result{} @strong{2006}-@strong{06}-@strong{13} 12:45
+@item @samp{22 sept 0:34}
+@tab @result{} @strong{2006}-09-22 0:34
+@item @samp{w4}
+@tab @result{} ISO week for of the current year @strong{2006}
+@item @samp{2012 w4 fri}
+@tab @result{} Friday of ISO week 4 in 2012
+@item @samp{2012-w04-5}
+@tab @result{} Same as above
+@end multitable
 
 Furthermore you can specify a relative date by giving, as the @emph{first}
-thing in the input: a plus/minus sign, a number and a letter ([hdwmy]) to
-indicate change in hours, 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.:
-
-@example
-+0            @result{} today
-.             @result{} today
-+4d           @result{} four days from today
-+4            @result{} same as above
-+2w           @result{} two weeks from today
-++5           @result{} five days from default date
-+2tue         @result{} second Tuesday from now
--wed          @result{} last Wednesday
-@end example
+thing in the input: a plus/minus sign, a number and a letter---@samp{d},
+@samp{w}, @samp{m} or @samp{y}---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 is the Nth such day, e.g.:
+
+@multitable {aaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{+0}
+@tab @result{} today
+@item @samp{.}
+@tab @result{} today
+@item @samp{+4d}
+@tab @result{} four days from today
+@item @samp{+4}
+@tab @result{} same as +4d
+@item @samp{+2w}
+@tab @result{} two weeks from today
+@item @samp{++5}
+@tab @result{} five days from default date
+@item @samp{+2tue}
+@tab @result{} second Tuesday from now
+@end multitable
 
 @vindex parse-time-months
 @vindex parse-time-weekdays
 The function understands English month and weekday abbreviations.  If
-you want to use unabbreviated names and/or other languages, configure
+you want to use un-abbreviated names and/or other languages, configure
 the variables @code{parse-time-months} and @code{parse-time-weekdays}.
 
 @vindex org-read-date-force-compatible-dates
-Not all dates can be represented in a given Emacs implementation.  By default
-Org mode forces dates into the compatibility range 1970--2037 which works on
-all Emacs implementations.  If you want to use dates outside of this range,
-read the docstring of the variable
+Not all dates can be represented in a given Emacs implementation.  By
+default Org mode forces dates into the compatibility range 1970--2037
+which works on all Emacs implementations.  If you want to use dates
+outside of this range, read the docstring of the variable
 @code{org-read-date-force-compatible-dates}.
 
-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 one or two dash(es) as the
-separator in the former case and use '+' as the separator in the latter
-case, e.g.:
-
-@example
-11am-1:15pm    @result{} 11:00-13:15
-11am--1:15pm   @result{} same as above
-11am+2:15      @result{} same as above
-@end example
+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 one or two
+dash(es) as the separator in the former case and use @samp{+} as the
+separator in the latter case, e.g.:
+
+@multitable {aaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaa}
+@item @samp{11am-1:15pm}
+@tab @result{} 11:00-13:15
+@item @samp{11am--1:15pm}
+@tab @result{} same as above
+@item @samp{11am+2:15}
+@tab @result{} same as above
+@end multitable
 
 @cindex calendar, for selecting date
 @vindex org-popup-calendar-for-date-prompt
-Parallel to the minibuffer prompt, a calendar is popped up@footnote{If
-you don't need/want the calendar, configure the variable
-@code{org-popup-calendar-for-date-prompt}.}.  When you exit the date
-prompt, either by clicking on a date in the calendar, or by pressing
-@key{RET}, the date selected in the calendar will be combined with the
-information entered at the prompt.  You can control the calendar fully
-from the minibuffer:
+Parallel to the minibuffer prompt, a calendar is popped up@footnote{If you do 
not need/want the calendar, configure the variable
+@code{org-popup-calendar-for-date-prompt}.}.
+When you exit the date prompt, either by clicking on a date in the
+calendar, or by pressing @kbd{@key{RET}}, the date selected in the
+calendar is combined with the information entered at the prompt.  You
+can control the calendar fully from the minibuffer:
 
 @kindex <
 @kindex >
@@ -6134,30 +6635,44 @@ from the minibuffer:
 @kindex M-S-RIGHT
 @kindex M-S-LEFT
 @kindex RET
-@kindex M-S-DOWN
-@kindex M-S-UP
-
-@example
-@key{RET}              @r{Choose date at cursor in calendar.}
-mouse-1            @r{Select date by clicking on it.}
-S-@key{RIGHT}/@key{LEFT}   @r{One day forward/backward.}
-S-@key{DOWN}/@key{UP}      @r{One week forward/backward.}
-M-S-@key{RIGHT}/@key{LEFT} @r{One month forward/backward.}
-> / <              @r{Scroll calendar forward/backward by one month.}
-M-v / C-v          @r{Scroll calendar forward/backward by 3 months.}
-M-S-@key{DOWN}/@key{UP}    @r{Scroll calendar forward/backward by one year.}
-@end example
+@multitable @columnfractions 0.25 0.55
+@item @kbd{@key{RET}}
+@tab Choose date at point in calendar.
+@item @kbd{mouse-1}
+@tab Select date by clicking on it.
+@item @kbd{S-@key{RIGHT}}
+@tab One day forward.
+@item @kbd{S-@key{LEFT}}
+@tab One day backward.
+@item @kbd{S-@key{DOWN}}
+@tab One week forward.
+@item @kbd{S-@key{UP}}
+@tab One week backward.
+@item @kbd{M-S-@key{RIGHT}}
+@tab One month forward.
+@item @kbd{M-S-@key{LEFT}}
+@tab One month backward.
+@item @kbd{>}
+@tab Scroll calendar forward by one month.
+@item @kbd{<}
+@tab Scroll calendar backward by one month.
+@item @kbd{M-v}
+@tab Scroll calendar forward by 3 months.
+@item @kbd{C-v}
+@tab Scroll calendar backward by 3 months.
+@end multitable
 
 @vindex org-read-date-display-live
-The actions of the date/time prompt may seem complex, but I assure you they
-will grow on you, and you will start getting annoyed by pretty much any other
-way of entering a date/time out there.  To help you understand what is going
-on, the current interpretation of your input will be displayed live in the
-minibuffer@footnote{If you find this distracting, turn the display off with
+The actions of the date/time prompt may seem complex, but I assure you
+they will grow on you, and you will start getting annoyed by pretty
+much any other way of entering a date/time out there.  To help you
+understand what is going on, the current interpretation of your input
+is displayed live in the minibuffer@footnote{If you find this distracting, 
turn off the display with
 @code{org-read-date-display-live}.}.
 
 @node Custom time format
 @subsection Custom time format
+
 @cindex custom date/time format
 @cindex time format, custom
 @cindex date format, custom
@@ -6165,66 +6680,70 @@ minibuffer@footnote{If you find this distracting, turn 
the display off with
 @vindex org-display-custom-times
 @vindex org-time-stamp-custom-formats
 Org mode uses the standard ISO notation for dates and times as it is
-defined in ISO 8601.  If you cannot get used to this and require another
-representation of date and time to keep you happy, you can get it by
-customizing the options @code{org-display-custom-times} and
+defined in ISO 8601.  If you cannot get used to this and require
+another representation of date and time to keep you happy, you can get
+it by customizing the variables @code{org-display-custom-times} and
 @code{org-time-stamp-custom-formats}.
 
-@table @kbd
-@orgcmd{C-c C-x C-t,org-toggle-time-stamp-overlays}
+@table @asis
+@item @kbd{C-c C-x C-t} (@code{org-toggle-time-stamp-overlays})
+@kindex C-c C-x C-t
+@findex org-toggle-time-stamp-overlays
 Toggle the display of custom formats for dates and times.
 @end table
 
-@noindent
-Org mode needs the default format for scanning, so the custom date/time
-format does not @emph{replace} the default format---instead it is put
-@emph{over} the default format using text properties.  This has the
+Org mode needs the default format for scanning, so the custom
+date/time format does not @emph{replace} the default format.  Instead, it
+is put @emph{over} the default format using text properties.  This has the
 following consequences:
-@itemize @bullet
+
+@itemize
 @item
-You cannot place the cursor onto a timestamp anymore, only before or
+You cannot place point onto a timestamp anymore, only before or
 after.
+
 @item
-The @kbd{S-@key{UP}/@key{DOWN}} keys can no longer be used to adjust
-each component of a timestamp.  If the cursor is at the beginning of
-the stamp, @kbd{S-@key{UP}/@key{DOWN}} will change the stamp by one day,
-just like @kbd{S-@key{LEFT}/@key{RIGHT}}.  At the end of the stamp, the
-time will be changed by one minute.
+The @kbd{S-@key{UP}} and @kbd{S-@key{DOWN}} keys can no longer be used
+to adjust each component of a timestamp.  If point is at the
+beginning of the stamp, @kbd{S-@key{UP}} and @kbd{S-@key{DOWN}} change
+the stamp by one day, just like @kbd{S-@key{LEFT}}
+@kbd{S-@key{RIGHT}}.  At the end of the stamp, change the time by one
+minute.
+
 @item
-If the timestamp contains a range of clock times or a repeater, these
-will not be overlaid, but remain in the buffer as they were.
+If the timestamp contains a range of clock times or a repeater,
+these are not 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
+When you delete a timestamp character-by-character, it only
+disappears from the buffer after @emph{all} (invisible) characters
 belonging to the ISO timestamp have been removed.
+
 @item
-If the custom timestamp format is longer than the default and you are
-using dates in tables, table alignment will be messed up.  If the custom
-format is shorter, things do work as expected.
+If the custom timestamp format is longer than the default and you
+are using dates in tables, table alignment will be messed up.  If
+the custom format is shorter, things do work as expected.
 @end itemize
 
+@node Deadlines and Scheduling
+@section Deadlines and Scheduling
 
-@node Deadlines and scheduling
-@section Deadlines and scheduling
-
-A timestamp may be preceded by special keywords to facilitate planning.  Both
-the timestamp and the keyword have to be positioned immediately after the task
-they refer to.
-
-@table @var
-@item DEADLINE
-@cindex @code{DEADLINE} keyword
+A timestamp may be preceded by special keywords to facilitate
+planning.  Both the timestamp and the keyword have to be positioned
+immediately after the task they refer to.
 
-Meaning: the task (most likely a TODO item, though not necessarily) is supposed
-to be finished on that date.
+@table @asis
+@item @samp{DEADLINE}
+@cindex @samp{DEADLINE} marker
+Meaning: the task---most likely a TODO item, though not
+necessarily---is supposed to be finished on that date.
 
 @vindex org-deadline-warning-days
-@vindex org-agenda-skip-deadline-prewarning-if-scheduled
-On the deadline date, the task will be listed in the agenda.  In
-addition, the agenda for @emph{today} will carry a warning about the
-approaching or missed deadline, starting
-@code{org-deadline-warning-days} before the due date, and continuing
-until the entry is marked DONE@.  An example:
+On the deadline date, the task is listed in the agenda.  In
+addition, the agenda for @emph{today} carries a warning about the
+approaching or missed deadline, starting @code{org-deadline-warning-days}
+before the due date, and continuing until the entry is marked as
+done.  An example:
 
 @example
 *** TODO write article about the Earth for the Guide
@@ -6232,25 +6751,25 @@ until the entry is marked DONE@.  An example:
     The editor in charge is [[bbdb:Ford Prefect]]
 @end example
 
+@vindex org-agenda-skip-deadline-prewarning-if-scheduled
 You can specify a different lead time for warnings for a specific
-deadline using the following syntax.  Here is an example with a warning
-period of 5 days @code{DEADLINE: <2004-02-29 Sun -5d>}.  This warning is
-deactivated if the task gets scheduled and you set
+deadlines using the following syntax.  Here is an example with
+a warning period of 5 days @samp{DEADLINE: <2004-02-29 Sun -5d>}.  This
+warning is deactivated if the task gets scheduled and you set
 @code{org-agenda-skip-deadline-prewarning-if-scheduled} to @code{t}.
 
-@item SCHEDULED
-@cindex @code{SCHEDULED} keyword
-
+@item @samp{SCHEDULED}
+@cindex @samp{SCHEDULED} marker
 Meaning: you are planning to start working on that task on the given
 date.
 
 @vindex org-agenda-skip-scheduled-if-done
-The headline will be listed under the given date@footnote{It will still
-be listed on that date after it has been marked DONE@.  If you don't like
-this, set the variable @code{org-agenda-skip-scheduled-if-done}.}.  In
-addition, a reminder that the scheduled date has passed will be present
-in the compilation for @emph{today}, until the entry is marked DONE, i.e.,
-the task will automatically be forwarded until completed.
+The headline is listed under the given date@footnote{It will still be listed 
on that date after it has been marked
+as done.  If you do not like this, set the variable
+@code{org-agenda-skip-scheduled-if-done}.}.  In addition,
+a reminder that the scheduled date has passed is present in the
+compilation for @emph{today}, until the entry is marked as done, i.e.,
+the task is automatically forwarded until completed.
 
 @example
 *** TODO Call Trillian for a date on New Years Eve.
@@ -6260,321 +6779,394 @@ the task will automatically be forwarded until 
completed.
 @vindex org-scheduled-delay-days
 @vindex org-agenda-skip-scheduled-delay-if-deadline
 If you want to @emph{delay} the display of this task in the agenda, use
-@code{SCHEDULED: <2004-12-25 Sat -2d>}: the task is still scheduled on the
-25th but will appear two days later.  In case the task contains a repeater,
-the delay is considered to affect all occurrences; if you want the delay to
-only affect the first scheduled occurrence of the task, use @code{--2d}
-instead.  See @code{org-scheduled-delay-days} and
+@samp{SCHEDULED: <2004-12-25 Sat -2d>}: the task is still scheduled on
+the 25th but will appear two days later.  In case the task contains
+a repeater, the delay is considered to affect all occurrences; if
+you want the delay to only affect the first scheduled occurrence of
+the task, use @samp{--2d} instead.  See @code{org-scheduled-delay-days} and
 @code{org-agenda-skip-scheduled-delay-if-deadline} for details on how to
 control this globally or per agenda.
 
-@noindent
-@b{Important:} Scheduling an item in Org mode should @i{not} be
-understood in the same way that we understand @i{scheduling a meeting}.
-Setting a date for a meeting is just a simple appointment, you should
-mark this entry with a simple plain timestamp, to get this item shown
-on the date where it applies.  This is a frequent misunderstanding by
-Org users.  In Org mode, @i{scheduling} means setting a date when you
-want to start working on an action item.
+@quotation Important
+Scheduling an item in Org mode should @emph{not} be understood in the
+same way that we understand @emph{scheduling a meeting}.  Setting a date
+for a meeting is just a simple appointment, you should mark this
+entry with a simple plain timestamp, to get this item shown on the
+date where it applies.  This is a frequent misunderstanding by Org
+users.  In Org mode, @emph{scheduling} means setting a date when you want
+to start working on an action item.
+
+@end quotation
 @end table
 
 You may use timestamps with repeaters in scheduling and deadline
-entries.  Org mode will issue early and late warnings based on the
-assumption that the timestamp represents the @i{nearest instance} of
-the repeater.  However, the use of diary sexp entries like
-@c
-@code{<%%(diary-float t 42)>}
-@c
+entries.  Org mode issues early and late warnings based on the
+assumption that the timestamp represents the @emph{nearest instance} of the
+repeater.  However, the use of diary expression entries like
+
+@example
+<%%(diary-float t 42)>
+@end example
+
+
+@noindent
 in scheduling and deadline timestamps is limited.  Org mode does not
-know enough about the internals of each sexp function to issue early and
-late warnings.  However, it will show the item on each day where the
-sexp entry matches.
+know enough about the internals of each function to issue early and
+late warnings.  However, it shows the item on each day where the
+expression entry matches.
 
 @menu
-* Inserting deadline/schedule::  Planning items
-* Repeated tasks::              Items that show up again and again
+* Inserting deadline/schedule::  Planning items.
+* Repeated tasks::               Items that show up again and again.
 @end menu
 
 @node Inserting deadline/schedule
 @subsection Inserting deadlines or schedules
 
-The following commands allow you to quickly insert a deadline or to schedule
-an item:
-
-@table @kbd
-@c
-@orgcmd{C-c C-d,org-deadline}
-Insert @code{DEADLINE} keyword along with a stamp.  Any CLOSED timestamp will
-be removed.  When called with a prefix arg, an existing deadline will be
-removed from the entry.  Depending on the variable
-@code{org-log-redeadline}@footnote{with corresponding @code{#+STARTUP}
-keywords @code{logredeadline}, @code{lognoteredeadline}, and
-@code{nologredeadline}}, a note will be taken when changing an existing
-deadline.
+The following commands allow you to quickly insert a deadline or to
+schedule an item:@footnote{The @samp{SCHEDULED} and @samp{DEADLINE} dates are 
inserted on the line
+right below the headline.  Do not put any text between this line and
+the headline.}
 
-@orgcmd{C-c C-s,org-schedule}
-Insert @code{SCHEDULED} keyword along with a stamp.  Any CLOSED timestamp
-will be removed.  When called with a prefix argument, remove the scheduling
-date from the entry.  Depending on the variable
-@code{org-log-reschedule}@footnote{with corresponding @code{#+STARTUP}
-keywords @code{logreschedule}, @code{lognotereschedule}, and
-@code{nologreschedule}}, a note will be taken when changing an existing
-scheduling time.
-@c
-@orgcmd{C-c / d,org-check-deadlines}
+@table @asis
+@item @kbd{C-c C-d} (@code{org-deadline})
+@kindex C-c C-d
+@findex org-deadline
+@vindex org-log-redeadline
+Insert @samp{DEADLINE} keyword along with a stamp.  The insertion happens
+in the line directly following the headline.  Remove any @samp{CLOSED}
+timestamp .  When called with a prefix argument, also remove any
+existing deadline from the entry.  Depending on the variable
+@code{org-log-redeadline}, take a note when changing an existing
+deadline@footnote{Note the corresponding @samp{STARTUP} options 
@samp{logredeadline},
+@samp{lognoteredeadline}, and @samp{nologredeadline}.}.
+
+@item @kbd{C-c C-s} (@code{org-schedule})
+@kindex C-c C-s
+@findex org-schedule
+@vindex org-log-reschedule
+Insert @samp{SCHEDULED} keyword along with a stamp.  The insertion
+happens in the line directly following the headline.  Remove any
+@samp{CLOSED} timestamp.  When called with a prefix argument, also remove
+the scheduling date from the entry.  Depending on the variable
+@code{org-log-reschedule}, take a note when changing an existing
+scheduling time@footnote{Note the corresponding @samp{STARTUP} options 
@samp{logreschedule},
+@samp{lognotereschedule}, and @samp{nologreschedule}.}.
+
+@item @kbd{C-c / d} (@code{org-check-deadlines})
+@kindex C-c / d
+@findex org-check-deadlines
 @cindex sparse tree, for deadlines
 @vindex org-deadline-warning-days
 Create a sparse tree with all deadlines that are either past-due, or
-which will become due within @code{org-deadline-warning-days}.
-With @kbd{C-u} prefix, show all deadlines in the file.  With a numeric
-prefix, check that many days.  For example, @kbd{C-1 C-c / d} shows
-all deadlines due tomorrow.
-@c
-@orgcmd{C-c / b,org-check-before-date}
+which will become due within @code{org-deadline-warning-days}.  With
+@kbd{C-u} prefix, show all deadlines in the file.  With
+a numeric prefix, check that many days.  For example, @kbd{C-1 C-c / d} shows 
all deadlines due tomorrow.
+
+@item @kbd{C-c / b} (@code{org-check-before-date})
+@kindex C-c / b
+@findex org-check-before-date
 Sparse tree for deadlines and scheduled items before a given date.
-@c
-@orgcmd{C-c / a,org-check-after-date}
+
+@item @kbd{C-c / a} (@code{org-check-after-date})
+@kindex C-c / a
+@findex org-check-after-date
 Sparse tree for deadlines and scheduled items after a given date.
 @end table
 
-Note that @code{org-schedule} and @code{org-deadline} supports
-setting the date by indicating a relative time: e.g., +1d will set
-the date to the next day after today, and --1w will set the date
-to the previous week before any current timestamp.
+Note that @code{org-schedule} and @code{org-deadline} supports setting the date
+by indicating a relative time e.g., @samp{+1d} sets the date to the next
+day after today, and @samp{--1w} sets the date to the previous week before
+any current timestamp.
 
 @node Repeated tasks
 @subsection Repeated tasks
+
 @cindex tasks, repeated
 @cindex repeated tasks
 
-Some tasks need to be repeated again and again.  Org mode helps to organize
-such tasks using a so-called repeater in a @code{DEADLINE}, @code{SCHEDULED},
-or plain timestamp.  In the following example
+Some tasks need to be repeated again and again.  Org mode helps to
+organize such tasks using a so-called repeater in a @samp{DEADLINE},
+@samp{SCHEDULED}, or plain timestamps@footnote{Org does not repeat inactive 
timestamps, however.  See
+@ref{Timestamps}.}.  In the following example:
+
 @example
 ** TODO Pay the rent
    DEADLINE: <2005-10-01 Sat +1m>
 @end example
+
 @noindent
-the @code{+1m} is a repeater; the intended interpretation is that the task
-has a deadline on <2005-10-01> and repeats itself every (one) month starting
-from that time.  You can use yearly, monthly, weekly, daily and hourly repeat
-cookies by using the @code{y/w/m/d/h} letters.  If you need both a repeater
-and a special warning period in a deadline entry, the repeater should come
-first and the warning period last: @code{DEADLINE: <2005-10-01 Sat +1m -3d>}.
+the @samp{+1m} is a repeater; the intended interpretation is that the task
+has a deadline on @samp{<2005-10-01>} and repeats itself every (one) month
+starting from that time.  You can use yearly, monthly, weekly, daily
+and hourly repeat cookies by using the @samp{y}, @samp{w}, @samp{m}, @samp{d} 
and @samp{h}
+letters.  If you need both a repeater and a special warning period in
+a deadline entry, the repeater should come first and the warning
+period last
+
+@example
+DEADLINE: <2005-10-01 Sat +1m -3d>
+@end example
+
 
 @vindex org-todo-repeat-to-state
-Deadlines and scheduled items produce entries in the agenda when they are
-over-due, so it is important to be able to mark such an entry as completed
-once you have done so.  When you mark a @code{DEADLINE} or a @code{SCHEDULED}
-with the TODO keyword DONE, it will no longer produce entries in the agenda.
-The problem with this is, however, that then also the @emph{next} instance of
-the repeated entry will not be active.  Org mode deals with this in the
-following way: When you try to mark such an entry DONE (using @kbd{C-c C-t}),
-it will shift the base date of the repeating timestamp by the repeater
-interval, and immediately set the entry state back to TODO@footnote{In fact,
-the target state is taken from, in this sequence, the @code{REPEAT_TO_STATE}
-property or the variable @code{org-todo-repeat-to-state}.  If neither of
-these is specified, the target state defaults to the first state of the TODO
-state sequence.}.  In the example above, setting the state to DONE would
-actually switch the date like this:
+Deadlines and scheduled items produce entries in the agenda when they
+are over-due, so it is important to be able to mark such an entry as
+done once you have done so.  When you mark a @samp{DEADLINE} or
+a @samp{SCHEDULED} with the TODO keyword @samp{DONE}, it no longer produces
+entries in the agenda.  The problem with this is, however, is that
+then also the @emph{next} instance of the repeated entry will not be
+active.  Org mode deals with this in the following way: when you try
+to mark such an entry as done, using @kbd{C-c C-t}, it shifts the
+base date of the repeating timestamp by the repeater interval, and
+immediately sets the entry state back to TODO@footnote{In fact, the target 
state is taken from, in this sequence, the
+@samp{REPEAT_TO_STATE} property, the variable @code{org-todo-repeat-to-state} 
if
+it is a string, the previous TODO state if @code{org-todo-repeat-to-state}
+is @code{t}, or the first state of the TODO state sequence.}.  In the example
+above, setting the state to @samp{DONE} would actually switch the date like
+this:
 
 @example
 ** TODO Pay the rent
    DEADLINE: <2005-11-01 Tue +1m>
 @end example
 
-To mark a task with a repeater as @code{DONE}, use @kbd{C-- 1 C-c C-t}
-(i.e., @code{org-todo} with a numeric prefix argument of -1.)
+To mark a task with a repeater as DONE, use @kbd{C-- 1 C-c C-t},
+i.e., @code{org-todo} with a numeric prefix argument of @samp{-1}.
 
 @vindex org-log-repeat
-A timestamp@footnote{You can change this using the option
-@code{org-log-repeat}, or the @code{#+STARTUP} options @code{logrepeat},
-@code{lognoterepeat}, and @code{nologrepeat}.  With @code{lognoterepeat}, you
-will also be prompted for a note.} will be added under the deadline, to keep
-a record that you actually acted on the previous instance of this deadline.
-
-As a consequence of shifting the base date, this entry will no longer be
-visible in the agenda when checking past dates, but all future instances
-will be visible.
-
-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 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
+A timestamp@footnote{You can change this using the option 
@code{org-log-repeat}, or the
+@samp{STARTUP} options @samp{logrepeat}, @samp{lognoterepeat}, and 
@samp{nologrepeat}.
+With @samp{lognoterepeat}, you will also be prompted for a note.} is added 
under the deadline, to keep a record that
+you actually acted on the previous instance of this deadline.
+
+As a consequence of shifting the base date, this entry is no longer
+visible in the agenda when checking past dates, but all future
+instances will be visible.
+
+With the @samp{+1m} cookie, the date shift is always exactly one month.  So
+if you have not paid the rent for three months, marking this entry
+DONE still keeps 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 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
-special repeaters  @samp{++} and @samp{.+}.  For example:
+@emph{after} the last time you did it.  For these tasks, Org mode has
+special repeaters @samp{++} and @samp{.+}.  For example:
 
 @example
 ** TODO Call Father
    DEADLINE: <2008-02-10 Sun ++1w>
-   Marking this DONE will shift the date by at least one week,
-   but also by as many weeks as it takes to get this date into
-   the future.  However, it stays on a Sunday, even if you called
-   and marked it done on Saturday.
+   Marking this DONE shifts the date by at least one week, but also
+   by as many weeks as it takes to get this date into the future.
+   However, it stays on a Sunday, even if you called and marked it
+   done on Saturday.
+
 ** TODO Empty kitchen trash
    DEADLINE: <2008-02-08 Fri 20:00 ++1d>
-   Marking this DONE will shift the date by at least one day, and
-   also by as many days as it takes to get the timestamp into the
-   future.  Since there is a time in the timestamp, the next
-   deadline in the future will be on today's date if you
-   complete the task before 20:00.
+   Marking this DONE shifts the date by at least one day, and also
+   by as many days as it takes to get the timestamp into the future.
+   Since there is a time in the timestamp, the next deadline in the
+   future will be on today's date if you complete the task before
+   20:00.
+
 ** TODO Check the batteries in the smoke detectors
    DEADLINE: <2005-11-01 Tue .+1m>
-   Marking this DONE will shift the date to one month after
-   today.
+   Marking this DONE will shift the date to one month after today.
 @end example
 
 @vindex org-agenda-skip-scheduled-if-deadline-is-shown
-You may have both scheduling and deadline information for a specific task.
-If the repeater is set for the scheduling information only, you probably want
-the repeater to be ignored after the deadline.  If so, set the variable
-@code{org-agenda-skip-scheduled-if-deadline-is-shown} to
-@code{repeated-after-deadline}.  However, any scheduling information without
-a repeater is no longer relevant once the task is done, and thus, removed
-upon repeating the task.  If you want both scheduling and deadline
-information to repeat after the same interval, set the same repeater for both
-timestamps.
-
-An alternative to using a repeater is to create a number of copies of a task
-subtree, with dates shifted in each copy.  The command @kbd{C-c C-x c} was
-created for this purpose, it is described in @ref{Structure editing}.
-
-
-@node Clocking work time
-@section Clocking work time
+You may have both scheduling and deadline information for a specific
+task.  If the repeater is set for the scheduling information only, you
+probably want the repeater to be ignored after the deadline.  If so,
+set the variable @code{org-agenda-skip-scheduled-if-deadline-is-shown} to
+@code{repeated-after-deadline}.  However, any scheduling information
+without a repeater is no longer relevant once the task is done, and
+thus, removed upon repeating the task.  If you want both scheduling
+and deadline information to repeat after the same interval, set the
+same repeater for both timestamps.
+
+An alternative to using a repeater is to create a number of copies of
+a task subtree, with dates shifted in each copy.  The command
+@kbd{C-c C-x c} was created for this purpose; it is described in
+@ref{Structure Editing}.
+
+@node Clocking Work Time
+@section Clocking Work Time
+
 @cindex clocking time
 @cindex time clocking
 
-Org mode allows you to clock the time you spend on specific tasks in a
-project.  When you start working on an item, you can start the clock.  When
-you stop working on that task, or when you mark the task done, the clock is
-stopped and the corresponding time interval is recorded.  It also computes
-the total time spent on each subtree@footnote{Clocking only works if all
-headings are indented with less than 30 stars.  This is a hardcoded
-limitation of @code{lmax} in @code{org-clock-sum}.} of a project.
-And it remembers a history or tasks recently clocked, so that you can jump
-quickly between a number of tasks absorbing your time.
-
-To save the clock history across Emacs sessions, use
+Org mode allows you to clock the time you spend on specific tasks in
+a project.  When you start working on an item, you can start the
+clock.  When you stop working on that task, or when you mark the task
+done, the clock is stopped and the corresponding time interval is
+recorded.  It also computes the total time spent on each
+subtree@footnote{Clocking only works if all headings are indented with less
+than 30 stars.  This is a hard-coded limitation of @code{lmax} in
+@code{org-clock-sum}.} of a project.  And it remembers a history or tasks
+recently clocked, to that you can jump quickly between a number of
+tasks absorbing your time.
+
+To save the clock history across Emacs sessions, use:
+
 @lisp
 (setq org-clock-persist 'history)
 (org-clock-persistence-insinuate)
 @end lisp
+
+@vindex org-clock-persist
 When you clock into a new task after resuming Emacs, the incomplete
 clock@footnote{To resume the clock under the assumption that you have worked
-on this task while outside Emacs, use @code{(setq org-clock-persist t)}.}
-will be found (@pxref{Resolving idle time}) and you will be prompted about
-what to do with it.
+on this task while outside Emacs, use @samp{(setq org-clock-persist t)}.} is 
retrieved (see @ref{Resolving idle time (1)}) and you are
+prompted about what to do with it.
 
 @menu
-* Clocking commands::           Starting and stopping a clock
-* The clock table::             Detailed reports
-* Resolving idle time::         Resolving time when you've been idle
+* Clocking commands::            Starting and stopping a clock.
+* The clock table::              Detailed reports.
+* Resolving idle time::          Resolving time when you've been idle.
 @end menu
 
 @node Clocking commands
 @subsection Clocking commands
 
-@table @kbd
-@orgcmd{C-c C-x C-i,org-clock-in}
+@table @asis
+@item @kbd{C-c C-x C-i} (@code{org-clock-in})
+@kindex C-c C-x C-i
+@findex org-clock-in
 @vindex org-clock-into-drawer
 @vindex org-clock-continuously
-@cindex property, @code{LOG_INTO_DRAWER}
-!Start the clock on the current item (clock-in).  This inserts the
-@code{CLOCK} keyword together with a timestamp.  If this is not the first
-clocking of this item, the multiple @code{CLOCK} lines will be wrapped into a
-@code{:LOGBOOK:} drawer (see also the variable @code{org-clock-into-drawer}).
-You can also overrule the setting of this variable for a subtree by setting a
-@code{CLOCK_INTO_DRAWER} or @code{LOG_INTO_DRAWER} property.  When called
-with a @kbd{C-u} prefix argument, select the task from a list of recently
-clocked tasks.  With two @kbd{C-u C-u} prefixes, clock into the task at point
-and mark it as the default task; the default task will then always be
-available with letter @kbd{d} when selecting a clocking task.  With three
-@kbd{C-u C-u C-u} prefixes, force continuous clocking by starting the clock
-when the last clock stopped.@*
-@cindex property, @code{CLOCK_MODELINE_TOTAL}
-@cindex property, @code{LAST_REPEAT}
-@vindex org-clock-modeline-total
-While the clock is running, the current clocking time is shown in the mode
-line, along with the title of the task.  The clock time shown will be all
-time ever clocked for this task and its children.  If the task has an effort
-estimate (@pxref{Effort estimates}), the mode line displays the current
-clocking time against it@footnote{To add an effort estimate ``on the fly'',
-hook a function doing this to @code{org-clock-in-prepare-hook}.}  If the task
-is a repeating one (@pxref{Repeated tasks}), only the time since the last
-reset of the task @footnote{as recorded by the @code{LAST_REPEAT} property}
-will be shown.  More control over what time is shown can be exercised with
-the @code{CLOCK_MODELINE_TOTAL} property.  It may have the values
-@code{current} to show only the current clocking instance, @code{today} to
-show all time clocked on this task today (see also the variable
-@code{org-extend-today-until}), @code{all} to include all time, or
-@code{auto} which is the default@footnote{See also the variable
-@code{org-clock-modeline-total}.}.@* Clicking with @kbd{mouse-1} onto the
-mode line entry will pop up a menu with clocking options.
-@c
-@orgcmd{C-c C-x C-o,org-clock-out}
+@cindex @samp{LOG_INTO_DRAWER}, property
+Start the clock on the current item (clock-in).  This inserts the
+@samp{CLOCK} keyword together with a timestamp.  If this is not the first
+clocking of this item, the multiple @samp{CLOCK} lines are wrapped into
+a @samp{LOGBOOK} drawer (see also the variable @code{org-clock-into-drawer}).
+You can also overrule the setting of this variable for a subtree by
+setting a @samp{CLOCK_INTO_DRAWER} or @samp{LOG_INTO_DRAWER} property.  When
+called with a @kbd{C-u} prefix argument, select the task from
+a list of recently clocked tasks.  With two @kbd{C-u C-u}
+prefixes, clock into the task at point and mark it as the default
+task; the default task is always be available with letter
+@kbd{d} when selecting a clocking task.  With three @kbd{C-u C-u C-u} 
prefixes, force continuous clocking by starting the
+clock when the last clock stopped.
+
+@cindex @samp{CLOCK_MODELINE_TOTAL}, property
+@cindex @samp{LAST_REPEAT}, property
+@vindex org-clock-mode-line-total
+@vindex org-clock-in-prepare-hook
+While the clock is running, Org shows the current clocking time in
+the mode line, along with the title of the task.  The clock time
+shown is all time ever clocked for this task and its children.  If
+the task has an effort estimate (see @ref{Effort Estimates}), the mode
+line displays the current clocking time against it@footnote{To add an effort 
estimate ``on the fly'', hook a function doing
+this to @code{org-clock-in-prepare-hook}.}.  If the
+task is a repeating one (see @ref{Repeated tasks}), show only the time
+since the last reset of the task@footnote{The last reset of the task is 
recorded by the @samp{LAST_REPEAT}
+property.}.  You can exercise more
+control over show time with the @samp{CLOCK_MODELINE_TOTAL} property.  It
+may have the values @samp{current} to show only the current clocking
+instance, @samp{today} to show all time clocked on this tasks today---see
+also the variable @code{org-extend-today-until}, @code{all} to include all
+time, or @code{auto} which is the default@footnote{See also the variable 
@code{org-clock-mode-line-total}.}.  Clicking with
+@kbd{mouse-1} onto the mode line entry pops up a menu with
+clocking options.
+
+@item @kbd{C-c C-x C-o} (@code{org-clock-out})
+@kindex C-c C-x C-o
+@findex org-clock-out
 @vindex org-log-note-clock-out
-Stop the clock (clock-out).  This inserts another timestamp at the same
-location where the clock was last started.  It also directly computes
-the resulting time and inserts it after the time range as @samp{=>
-HH:MM}.  See the variable @code{org-log-note-clock-out} for the
+Stop the clock (clock-out).  This inserts another timestamp at the
+same location where the clock was last started.  It also directly
+computes the resulting time in inserts it after the time range as
+@samp{=>HH:MM}.  See the variable @code{org-log-note-clock-out} for the
 possibility to record an additional note together with the clock-out
-timestamp@footnote{The corresponding in-buffer setting is:
-@code{#+STARTUP: lognoteclock-out}}.
-@orgcmd{C-c C-x C-x,org-clock-in-last}
+timestamp@footnote{The corresponding in-buffer setting is: @samp{#+STARTUP:
+lognoteclock-out}.}.
+
+@item @kbd{C-c C-x C-x} (@code{org-clock-in-last})
+@kindex C-c C-x C-x
+@findex org-clock-in-last
 @vindex org-clock-continuously
-Reclock the last clocked task.  With one @kbd{C-u} prefix argument,
-select the task from the clock history.  With two @kbd{C-u} prefixes,
-force continuous clocking by starting the clock when the last clock
-stopped.
-@orgcmd{C-c C-x C-e,org-clock-modify-effort-estimate}
+Re-clock the last clocked task.  With one @kbd{C-u} prefix
+argument, select the task from the clock history.  With two
+@kbd{C-u} prefixes, force continuous clocking by starting the
+clock when the last clock stopped.
+
+@item @kbd{C-c C-x C-e} (@code{org-clock-modify-effort-estimate})
+@kindex C-c C-x C-e
+@findex org-clock-modify-effort-estimate
 Update the effort estimate for the current clock task.
-@kindex C-c C-y
+
+@item @kbd{C-c C-c} or @kbd{C-c C-y} (@code{org-evaluate-time-range})
 @kindex C-c C-c
-@orgcmdkkc{C-c C-c,C-c C-y,org-evaluate-time-range}
-Recompute the time interval after changing one of the timestamps.  This
-is only necessary if you edit the timestamps directly.  If you change
-them with @kbd{S-@key{cursor}} keys, the update is automatic.
-@orgcmd{C-S-@key{up/down},org-clock-timestamps-up/down}
-On @code{CLOCK} log lines, increase/decrease both timestamps so that the
-clock duration keeps the same.
-@orgcmd{S-M-@key{up/down},org-timestamp-up/down}
-On @code{CLOCK} log lines, increase/decrease the timestamp at point and
-the one of the previous (or the next clock) timestamp by the same duration.
-For example, if you hit @kbd{S-M-@key{UP}} to increase a clocked-out timestamp
-by five minutes, then the clocked-in timestamp of the next clock will be
-increased by five minutes.
-@orgcmd{C-c C-t,org-todo}
-Changing the TODO state of an item to DONE automatically stops the clock
-if it is running in this same item.
-@orgcmd{C-c C-x C-q,org-clock-cancel}
+@kindex C-c C-y
+@findex org-evaluate-time-range
+Recompute the time interval after changing one of the timestamps.
+This is only necessary if you edit the timestamps directly.  If you
+change them with @kbd{S-<cursor>} keys, the update is
+automatic.
+
+@item @kbd{C-S-@key{UP}} (@code{org-clock-timestamps-up})
+@itemx @kbd{C-S-@key{DOWN}} (@code{org-clock-timestamps-down})
+@kindex C-S-UP
+@findex org-clock-timestamps-up
+@kindex C-S-DOWN
+@findex org-clock-timestamps-down
+On CLOCK log lines, increase/decrease both timestamps so that the
+clock duration keeps the same value.
+
+@item @kbd{S-M-@key{UP}} (@code{org-timestamp-up})
+@itemx @kbd{S-M-@key{DOWN}} (@code{org-timestamp-down})
+@kindex S-M-UP
+@findex org-clock-timestamp-up
+@kindex S-M-DOWN
+@findex org-clock-timestamp-down
+On @samp{CLOCK} log lines, increase/decrease the timestamp at point and
+the one of the previous, or the next, clock timestamp by the same
+duration.  For example, if you hit @kbd{S-M-@key{UP}} to increase
+a clocked-out timestamp by five minutes, then the clocked-in
+timestamp of the next clock is increased by five minutes.
+
+@item @kbd{C-c C-t} (@code{org-todo})
+@kindex C-c C-t
+@findex org-todo
+Changing the TODO state of an item to DONE automatically stops the
+clock if it is running in this same item.
+
+@item @kbd{C-c C-x C-q} (@code{org-clock-cancel})
+@kindex C-c C-x C-q
+@findex org-clock-cancel
 Cancel the current clock.  This is useful if a clock was started by
 mistake, or if you ended up working on something else.
-@orgcmd{C-c C-x C-j,org-clock-goto}
-Jump to the headline of the currently clocked in task.  With a @kbd{C-u}
-prefix arg, select the target task from a list of recently clocked tasks.
-@orgcmd{C-c C-x C-d,org-clock-display}
+
+@item @kbd{C-c C-x C-j} (@code{org-clock-goto})
+@kindex C-c C-x C-j
+@findex or-clock-goto
+Jump to the headline of the currently clocked in task.  With
+a @kbd{C-u} prefix argument, select the target task from a list
+of recently clocked tasks.
+
+@item @kbd{C-c C-x C-d} (@code{org-clock-display})
+@kindex C-c C-x C-d
+@findex org-clock-display
 @vindex org-remove-highlights-with-change
-Display time summaries for each subtree in the current buffer.  This puts
-overlays at the end of each headline, showing the total time recorded under
-that heading, including the time of any subheadings.  You can use visibility
-cycling to study the tree, but the overlays disappear when you change the
-buffer (see variable @code{org-remove-highlights-with-change}) or press
-@kbd{C-c C-c}.
+Display time summaries for each subtree in the current buffer.  This
+puts overlays at the end of each headline, showing the total time
+recorded under that heading, including the time of any subheadings.
+You can use visibility cycling to study the tree, but the overlays
+disappear when you change the buffer (see variable
+@code{org-remove-highlights-with-change}) or press @kbd{C-c C-c}.
 @end table
 
-The @kbd{l} key may be used the agenda (@pxref{Weekly/daily agenda}) to show
-which tasks have been worked on or closed during a day.
+The @kbd{l} key may be used in the agenda (see @ref{Weekly/daily agenda}) to 
show which tasks have been worked on or closed during
+a day.
 
-@strong{Important:} note that both @code{org-clock-out} and
-@code{org-clock-in-last} can have a global key binding and will not
-modify the window disposition.
+@strong{Important:} note that both @code{org-clock-out} and 
@code{org-clock-in-last}
+can have a global keybinding and do not modify the window disposition.
 
 @node The clock table
 @subsection The clock table
+
 @cindex clocktable, dynamic block
 @cindex report, of clocked time
 
@@ -6582,143 +7174,259 @@ Org mode can produce quite complex reports based on 
the time clocking
 information.  Such a report is called a @emph{clock table}, because it is
 formatted as one or several Org tables.
 
-@table @kbd
-@orgcmd{C-c C-x C-r,org-clock-report}
-Insert a dynamic block (@pxref{Dynamic blocks}) containing a clock
-report as an Org mode table into the current file.  When the cursor is
-at an existing clock table, just update it.  When called with a prefix
-argument, jump to the first clock report in the current document and
-update it.  The clock table always includes also trees with
-@code{:ARCHIVE:} tag.
-@orgcmdkkc{C-c C-c,C-c C-x C-u,org-dblock-update}
-Update dynamic block at point.
-@orgkey{C-u C-c C-x C-u}
-Update all dynamic blocks (@pxref{Dynamic blocks}).  This is useful if
+You can insert, or update, a clock table through Org dynamic blocks
+insert command (see @ref{Dynamic Blocks}), by pressing @kbd{C-c C-x x c l o c 
k t a b l e @key{RET}}.  When called with a prefix argument,
+jump to the first clock table in the current document and update it.
+The clock table includes archived trees.
+
+@table @asis
+@item @kbd{C-c C-c} or @kbd{C-c C-x C-u} (@code{org-dblock-update})
+@kindex C-c C-c
+@kindex C-c C-x C-u
+@findex org-dblock-update
+Update dynamic block at point.  Point needs to be in the @samp{BEGIN}
+line of the dynamic block.
+
+@item @kbd{C-u C-c C-x C-u}
+@kindex C-u C-c C-x C-u
+Update all dynamic blocks (see @ref{Dynamic Blocks}).  This is useful if
 you have several clock table blocks in a buffer.
-@orgcmdkxkc{S-@key{LEFT},S-@key{RIGHT},org-clocktable-try-shift}
-Shift the current @code{:block} interval and update the table.  The cursor
-needs to be in the @code{#+BEGIN: clocktable} line for this command.  If
-@code{:block} is @code{today}, it will be shifted to @code{today-1} etc.
-@end table
 
+@item @kbd{S-@key{LEFT}}
+@itemx @kbd{S-@key{RIGHT}} (@code{org-clocktable-try-shift})
+@kindex S-LEFT
+@kindex S-RIGHT
+@findex org-clocktable-try-shift
+Shift the current @samp{:block} interval and update the table.  Point
+needs to be in the @samp{#+BEGIN: clocktable} line for this command.  If
+@samp{:block} is @samp{today}, it is shifted to @samp{today-1}, etc.
+@end table
 
-Here is an example of the frame for a clock table as it is inserted into the
-buffer with the @kbd{C-c C-x C-r} command:
+Here is an example of the frame for a clock table as it is inserted
+into the buffer with the @kbd{C-c C-x C-r} command:
 
-@cindex @code{#+BEGIN}, clocktable
+@cindex @samp{BEGIN clocktable}
 @example
 #+BEGIN: clocktable :maxlevel 2 :emphasize nil :scope file
 #+END: clocktable
 @end example
-@noindent
+
 @vindex org-clocktable-defaults
-The @samp{BEGIN} line specifies a number of options to define the scope,
-structure, and formatting of the report.  Defaults for all these options can
-be configured in the variable @code{org-clocktable-defaults}.
+The @samp{#+BEGIN} line and specify a number of options to define the
+scope, structure, and formatting of the report.  Defaults for all
+these options can be configured in the variable
+@code{org-clocktable-defaults}.
 
-@noindent First there are options that determine which clock entries are to
+First there are options that determine which clock entries are to
 be selected:
-@example
-:maxlevel    @r{Maximum level depth to which times are listed in the table.}
-             @r{Clocks at deeper levels will be summed into the upper level.}
-:scope       @r{The scope to consider.  This can be any of the following:}
-             nil        @r{the current buffer or narrowed region}
-             file       @r{the full current buffer}
-             subtree    @r{the subtree where the clocktable is located}
-             tree@var{N}      @r{the surrounding level @var{N} tree, for 
example @code{tree3}}
-             tree       @r{the surrounding level 1 tree}
-             agenda     @r{all agenda files}
-             ("file"..) @r{scan these files}
-             function   @r{the list of files returned by a function of no 
argument}
-             file-with-archives    @r{current file and its archives}
-             agenda-with-archives  @r{all agenda files, including archives}
-:block       @r{The time block to consider.  This block is specified either}
-             @r{absolutely, or relative to the current time and may be any of}
-             @r{these formats:}
-             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}
-             thismonth, lastmonth, thismonth-@var{N}  @r{a relative month}
-             thisyear, lastyear, thisyear-@var{N}     @r{a relative year}
-             untilnow
-             @r{Use @kbd{S-@key{LEFT}/@key{RIGHT}} keys to shift the time 
interval.}
-:tstart      @r{A time string specifying when to start considering times.}
-             @r{Relative times like @code{"<-2w>"} can also be used.  See}
-             @r{@ref{Matching tags and properties} for relative time syntax.}
-:tend        @r{A time string specifying when to stop considering times.}
-             @r{Relative times like @code{"<now>"} can also be used.  See}
-             @r{@ref{Matching tags and properties} for relative time syntax.}
-:wstart      @r{The starting day of the week.  The default is 1 for monday.}
-:mstart      @r{The starting day of the month.  The default 1 is for the first}
-             @r{day of the month.}
-:step        @r{@code{week} or @code{day}, to split the table into chunks.}
-             @r{To use this, @code{:block} or @code{:tstart}, @code{:tend} are 
needed.}
-:stepskip0   @r{Do not show steps that have zero time.}
-:fileskip0   @r{Do not show table sections from files which did not 
contribute.}
-:tags        @r{A tags match to select entries that should contribute.  See}
-             @r{@ref{Matching tags and properties} for the match syntax.}
-@end example
-
-Then there are options which determine the formatting of the table.  These
-options are interpreted by the function @code{org-clocktable-write-default},
-but you can specify your own function using the @code{:formatter} parameter.
-@example
-:emphasize   @r{When @code{t}, emphasize level one and level two items.}
-:lang        @r{Language@footnote{Language terms can be set through the 
variable @code{org-clock-clocktable-language-setup}.} to use for descriptive 
cells like "Task".}
-:link        @r{Link the item headlines in the table to their origins.}
-:narrow      @r{An integer to limit the width of the headline column in}
-             @r{the org table.  If you write it like @samp{50!}, then the}
-             @r{headline will also be shortened in export.}
-:indent      @r{Indent each headline field according to its level.}
-:tcolumns    @r{Number of columns to be used for times.  If this is smaller}
-             @r{than @code{:maxlevel}, lower levels will be lumped into one 
column.}
-:level       @r{Should a level number column be included?}
-:sort        @r{A cons cell like containing the column to sort and a sorting 
type.}
-             @r{E.g., @code{:sort (1 . ?a)} sorts the first column 
alphabetically.}
-:compact     @r{Abbreviation for @code{:level nil :indent t :narrow 40! 
:tcolumns 1}}
-             @r{All are overwritten except if there is an explicit 
@code{:narrow}}
-:timestamp   @r{A timestamp for the entry, when available.  Look for 
@code{SCHEDULED},}
-             @r{@code{DEADLINE}, @code{TIMESTAMP} and @code{TIMESTAMP_IA}, in 
this order.}
-:properties  @r{List of properties that should be shown in the table.  Each}
-             @r{property will get its own column.}
-:inherit-props @r{When this flag is @code{t}, the values for 
@code{:properties} will be inherited.}
-: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{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
-To get a clock summary of the current level 1 tree, for the current
-day, you could write
-@example
-#+BEGIN: clocktable :maxlevel 2 :block today :scope tree1 :link t
-#+END: clocktable
-@end example
-@noindent
-and to use a specific time range you could write@footnote{Note that all
-parameters must be specified in a single line---the line is broken here
-only to fit it into the manual.}
-@example
-#+BEGIN: clocktable :tstart "<2006-08-10 Thu 10:00>"
-                    :tend "<2006-08-10 Thu 12:00>"
-#+END: clocktable
-@end example
-A range starting a week ago and ending right now could be written as
-@example
-#+BEGIN: clocktable :tstart "<-1w>" :tend "<now>"
-#+END: clocktable
-@end example
-A summary of the current subtree with % times would be
-@example
-#+BEGIN: clocktable :scope subtree :link t :formula %
-#+END: clocktable
-@end example
-A horizontally compact representation of everything clocked during last week
-would be
+
+@table @asis
+@item @samp{:maxlevel}
+Maximum level depth to which times are listed in the table.  Clocks
+at deeper levels are summed into the upper level.
+
+@item @samp{:scope}
+The scope to consider.  This can be any of the following:
+
+@multitable {aaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{nil}
+@tab the current buffer or narrowed region
+@item @samp{file}
+@tab the full current buffer
+@item @samp{subtree}
+@tab the subtree where the clocktable is located
+@item @samp{treeN}
+@tab the surrounding level N tree, for example @samp{tree3}
+@item @samp{tree}
+@tab the surrounding level 1 tree
+@item @samp{agenda}
+@tab all agenda files
+@item @samp{("file" ...)}
+@tab scan these files
+@item @samp{FUNCTION}
+@tab scan files returned by calling @var{FUNCTION} with no argument
+@item @samp{file-with-archives}
+@tab current file and its archives
+@item @samp{agenda-with-archives}
+@tab all agenda files, including archives
+@end multitable
+
+@item @samp{:block}
+The time block to consider.  This block is specified either
+absolutely, or relative to the current time and may be any of these
+formats:
+
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaa}
+@item @samp{2007-12-31}
+@tab New year eve 2007
+@item @samp{2007-12}
+@tab December 2007
+@item @samp{2007-W50}
+@tab ISO-week 50 in 2007
+@item @samp{2007-Q2}
+@tab 2nd quarter in 2007
+@item @samp{2007}
+@tab the year 2007
+@item @samp{today}, @samp{yesterday}, @samp{today-N}
+@tab a relative day
+@item @samp{thisweek}, @samp{lastweek}, @samp{thisweek-N}
+@tab a relative week
+@item @samp{thismonth}, @samp{lastmonth}, @samp{thismonth-N}
+@tab a relative month
+@item @samp{thisyear}, @samp{lastyear}, @samp{thisyear-N}
+@tab a relative year
+@item @samp{untilnow}@footnote{When using @code{:step}, @code{untilnow} starts 
from the beginning of
+2003, not the beginning of time.}
+@tab all clocked time ever
+@end multitable
+
+@vindex org-clock-display-default-range
+When this option is not set, Org falls back to the value in
+@code{org-clock-display-default-range}, which defaults to the current
+year.
+
+Use @kbd{S-@key{LEFT}} or @kbd{S-@key{RIGHT}} to shift the time
+interval.
+
+@item @samp{:tstart}
+A time string specifying when to start considering times.  Relative
+times like @samp{"<-2w>"} can also be used.  See @ref{Matching tags and 
properties} for relative time syntax.
+
+@item @samp{:tend}
+A time string specifying when to stop considering times.  Relative
+times like @samp{"<now>"} can also be used.  See @ref{Matching tags and 
properties} for relative time syntax.
+
+@item @samp{:wstart}
+The starting day of the week.  The default is 1 for Monday.
+
+@item @samp{:mstart}
+The starting day of the month.  The default is 1 for the first.
+
+@item @samp{:step}
+Set to @samp{day}, @samp{week}, @samp{month} or @samp{year} to split the table 
into
+chunks.  To use this, either @samp{:block}, or @samp{:tstart} and @samp{:tend} 
are
+required.
+
+@item @samp{:stepskip0}
+When non-@code{nil}, do not show steps that have zero time.
+
+@item @samp{:fileskip0}
+When non-@code{nil}, do not show table sections from files which did not
+contribute.
+
+@item @samp{:match}
+A tags match to select entries that should contribute.  See
+@ref{Matching tags and properties} for the match syntax.
+@end table
+
+@findex org-clocktable-write-default
+Then there are options that determine the formatting of the table.
+There options are interpreted by the function
+@code{org-clocktable-write-default}, but you can specify your own function
+using the @samp{:formatter} parameter.
+
+@table @asis
+@item @samp{:emphasize}
+When non-@code{nil}, emphasize level one and level two items.
+
+@item @samp{:lang}
+Language@footnote{Language terms can be set through the variable
+@code{org-clock-clocktable-language-setup}.} to use for descriptive cells like 
``Task''.
+
+@item @samp{:link}
+Link the item headlines in the table to their origins.
+
+@item @samp{:narrow}
+An integer to limit the width of the headline column in the Org
+table.  If you write it like @samp{50!}, then the headline is also
+shortened in export.
+
+@item @samp{:indent}
+Indent each headline field according to its level.
+
+@item @samp{:hidefiles}
+Hide the file column when multiple files are used to produce the
+table.
+
+@item @samp{:tcolumns}
+Number of columns to be used for times.  If this is smaller than
+@samp{:maxlevel}, lower levels are lumped into one column.
+
+@item @samp{:level}
+Should a level number column be included?
+
+@item @samp{:sort}
+A cons cell containing the column to sort and a sorting type.  E.g.,
+@samp{:sort (1 . ?a)} sorts the first column alphabetically.
+
+@item @samp{:compact}
+Abbreviation for @samp{:level nil :indent t :narrow 40! :tcolumns 1}.
+All are overwritten except if there is an explicit @samp{:narrow}.
+
+@item @samp{:timestamp}
+A timestamp for the entry, when available.  Look for @samp{SCHEDULED},
+@samp{DEADLINE}, @samp{TIMESTAMP} and @samp{TIMESTAMP_IA} special properties 
(see
+@ref{Special Properties}), in this order.
+
+@item @samp{:tags}
+When this flag is non-@code{nil}, show the headline's tags.
+
+@item @samp{:properties}
+List of properties shown in the table.  Each property gets its own
+column.
+
+@item @samp{:inherit-props}
+When this flag is non-@code{nil}, the values for @samp{:properties} are
+inherited.
+
+@item @samp{:formula}
+Content of a @samp{TBLFM} keyword to be added and evaluated.  As
+a special case, @samp{:formula %} adds a column with % time.  If you do
+not specify a formula here, any existing formula below the clock
+table survives updates and is evaluated.
+
+@item @samp{:formatter}
+A function to format clock data and insert it into the buffer.
+@end table
+
+To get a clock summary of the current level 1 tree, for the current
+day, you could write:
+
+@example
+#+BEGIN: clocktable :maxlevel 2 :block today :scope tree1 :link t
+#+END: clocktable
+@end example
+
+@noindent
+To use a specific time range you could write@footnote{Note that all parameters 
must be specified in a single
+line---the line is broken here only to fit it into the manual.}
+
+@example
+#+BEGIN: clocktable :tstart "<2006-08-10 Thu 10:00>"
+                    :tend "<2006-08-10 Thu 12:00>"
+#+END: clocktable
+@end example
+
+@noindent
+A range starting a week ago and ending right now could be written as
+
+@example
+#+BEGIN: clocktable :tstart "<-1w>" :tend "<now>"
+#+END: clocktable
+@end example
+
+@noindent
+A summary of the current subtree with % times would be
+
+@example
+#+BEGIN: clocktable :scope subtree :link t :formula %
+#+END: clocktable
+@end example
+
+@noindent
+A horizontally compact representation of everything clocked during
+last week would be
+
 @example
 #+BEGIN: clocktable :scope agenda :block lastweek :compact t
 #+END: clocktable
@@ -6727,116 +7435,147 @@ would be
 @node Resolving idle time
 @subsection Resolving idle time and continuous clocking
 
+
+
+@anchor{Resolving idle time (1)}
 @subsubheading Resolving idle time
-@cindex resolve idle time
-@vindex org-clock-x11idle-program-name
 
+@cindex resolve idle time
 @cindex idle, resolve, dangling
+
 If you clock in on a work item, and then walk away from your
-computer---perhaps to take a phone call---you often need to ``resolve'' the
-time you were away by either subtracting it from the current clock, or
-applying it to another one.
+computer---perhaps to take a phone call---you often need to
+``resolve'' the time you were away by either subtracting it from the
+current clock, or applying it to another one.
 
 @vindex org-clock-idle-time
-By customizing the variable @code{org-clock-idle-time} to some integer, such
-as 10 or 15, Emacs can alert you when you get back to your computer after
-being idle for that many minutes@footnote{On computers using macOS,
-idleness is based on actual user idleness, not just Emacs' idle time.  For
-X11, you can install a utility program @file{x11idle.c}, available in the
-@code{contrib/scripts} directory of the Org git distribution, or install the
-@file{xprintidle} package and set it to the variable
-@code{org-clock-x11idle-program-name} if you are running Debian, to get the
-same general treatment of idleness.  On other systems, idle time refers to
-Emacs idle time only.}, and ask what you want to do with the idle time.
-There will be a question waiting for you when you get back, indicating how
-much idle time has passed (constantly updated with the current amount), as
-well as a set of choices to correct the discrepancy:
-
-@table @kbd
-@item k
-To keep some or all of the minutes and stay clocked in, press @kbd{k}.  Org
-will ask how many of the minutes to keep.  Press @key{RET} to keep them all,
-effectively changing nothing, or enter a number to keep that many minutes.
-@item K
-If you use the shift key and press @kbd{K}, it will keep however many minutes
-you request and then immediately clock out of that task.  If you keep all of
-the minutes, this is the same as just clocking out of the current task.
-@item s
-To keep none of the minutes, use @kbd{s} to subtract all the away time from
-the clock, and then check back in from the moment you returned.
-@item S
-To keep none of the minutes and just clock out at the start of the away time,
-use the shift key and press @kbd{S}.  Remember that using shift will always
-leave you clocked out, no matter which option you choose.
-@item C
-To cancel the clock altogether, use @kbd{C}.  Note that if instead of
-canceling you subtract the away time, and the resulting clock amount is less
-than a minute, the clock will still be canceled rather than clutter up the
-log with an empty entry.
-@end table
+@vindex org-clock-x11idle-program-name
+By customizing the variable @code{org-clock-idle-time} to some integer,
+such as 10 or 15, Emacs can alert you when you get back to your
+computer after being idle for that many minutes@footnote{On computers using 
macOS, idleness is based on actual user
+idleness, not just Emacs' idle time.  For X11, you can install
+a utility program @samp{x11idle.c}, available in the @samp{contrib/scripts/}
+directory of the Org Git distribution, or install the xprintidle
+package and set it to the variable @code{org-clock-x11idle-program-name} if
+you are running Debian, to get the same general treatment of idleness.
+On other systems, idle time refers to Emacs idle time only.}, and ask what
+you want to do with the idle time.  There will be a question waiting
+for you when you get back, indicating how much idle time has passed
+constantly updated with the current amount, as well as a set of
+choices to correct the discrepancy:
 
-What if you subtracted those away minutes from the current clock, and now
-want to apply them to a new clock?  Simply clock in to any task immediately
-after the subtraction.  Org will notice that you have subtracted time ``on
-the books'', so to speak, and will ask if you want to apply those minutes to
-the next task you clock in on.
-
-There is one other instance when this clock resolution magic occurs.  Say you
-were clocked in and hacking away, and suddenly your cat chased a mouse who
-scared a hamster that crashed into your UPS's power button!  You suddenly
-lose all your buffers, but thanks to auto-save you still have your recent Org
-mode changes, including your last clock in.
-
-If you restart Emacs and clock into any task, Org will notice that you have a
-dangling clock which was never clocked out from your last session.  Using
-that clock's starting time as the beginning of the unaccounted-for period,
-Org will ask how you want to resolve that time.  The logic and behavior is
-identical to dealing with away time due to idleness; it is just happening due
-to a recovery event rather than a set amount of idle time.
-
-You can also check all the files visited by your Org agenda for dangling
-clocks at any time using @kbd{M-x org-resolve-clocks @key{RET}} (or @kbd{C-c
-C-x C-z}).
+@table @asis
+@item @kbd{k}
+@kindex k
+To keep some or all of the minutes and stay clocked in, press
+@kbd{k}.  Org asks how many of the minutes to keep.  Press
+@kbd{@key{RET}} to keep them all, effectively changing nothing, or
+enter a number to keep that many minutes.
+
+@item @kbd{K}
+@kindex K
+If you use the shift key and press @kbd{K}, it keeps however
+many minutes you request and then immediately clock out of that
+task.  If you keep all of the minutes, this is the same as just
+clocking out of the current task.
+
+@item @kbd{s}
+@kindex s
+To keep none of the minutes, use @kbd{s} to subtract all the
+away time from the clock, and then check back in from the moment you
+returned.
+
+@item @kbd{S}
+@kindex S
+To keep none of the minutes and just clock out at the start of the
+away time, use the shift key and press @kbd{S}.  Remember that
+using shift always leave you clocked out, no matter which option you
+choose.
+
+@item @kbd{C}
+@kindex C
+To cancel the clock altogether, use @kbd{C}.  Note that if
+instead of canceling you subtract the away time, and the resulting
+clock amount is less than a minute, the clock is still canceled
+rather than cluttering up the log with an empty entry.
+@end table
 
+What if you subtracted those away minutes from the current clock, and
+now want to apply them to a new clock?  Simply clock in to any task
+immediately after the subtraction.  Org will notice that you have
+subtracted time ``on the books'', so to speak, and will ask if you want
+to apply those minutes to the next task you clock in on.
+
+There is one other instance when this clock resolution magic occurs.
+Say you were clocked in and hacking away, and suddenly your cat chased
+a mouse who scared a hamster that crashed into your UPS's power
+button!  You suddenly lose all your buffers, but thanks to auto-save
+you still have your recent Org mode changes, including your last clock
+in.
+
+If you restart Emacs and clock into any task, Org will notice that you
+have a dangling clock which was never clocked out from your last
+session.  Using that clock's starting time as the beginning of the
+unaccounted-for period, Org will ask how you want to resolve that
+time.  The logic and behavior is identical to dealing with away time
+due to idleness; it is just happening due to a recovery event rather
+than a set amount of idle time.
+
+You can also check all the files visited by your Org agenda for
+dangling clocks at any time using @kbd{M-x org-resolve-clocks @key{RET}} (or 
@kbd{C-c C-x C-z}).
+
+@anchor{Continuous clocking}
 @subsubheading Continuous clocking
+
 @cindex continuous clocking
-@vindex org-clock-continuously
 
+@vindex org-clock-continuously
 You may want to start clocking from the time when you clocked out the
-previous task.  To enable this systematically, set 
@code{org-clock-continuously}
-to @code{t}.  Each time you clock in, Org retrieves the clock-out time of the
-last clocked entry for this session, and start the new clock from there.
+previous task.  To enable this systematically, set
+@code{org-clock-continuously} to non-@code{nil}.  Each time you clock in, Org
+retrieves the clock-out time of the last clocked entry for this
+session, and start the new clock from there.
 
-If you only want this from time to time, use three universal prefix arguments
-with @code{org-clock-in} and two @kbd{C-u C-u} with @code{org-clock-in-last}.
+If you only want this from time to time, use three universal prefix
+arguments with @code{org-clock-in} and two @kbd{C-u C-u} with
+@code{org-clock-in-last}.
+
+@node Effort Estimates
+@section Effort Estimates
 
-@node Effort estimates
-@section Effort estimates
 @cindex effort estimates
+@cindex @samp{EFFORT}, property
+@vindex org-effort-property
+
+If you want to plan your work in a very detailed way, or if you need
+to produce offers with quotations of the estimated work effort, you
+may want to assign effort estimates to entries.  If you are also
+clocking your work, you may later want to compare the planned effort
+with the actual working time, a great way to improve planning
+estimates.  Effort estimates are stored in a special property
+@samp{EFFORT}.  You can set the effort for an entry with the following
+commands:
 
-@cindex property, @code{EFFORT}
-If you want to plan your work in a very detailed way, or if you need to
-produce offers with quotations of the estimated work effort, you may want to
-assign effort estimates to entries.  If you are also clocking your work, you
-may later want to compare the planned effort with the actual working time,
-a great way to improve planning estimates.  Effort estimates are stored in
-a special property @code{EFFORT}.  You can set the effort 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
-accessible from the agenda with the @kbd{e} key.
-@orgcmd{C-c C-x C-e,org-clock-modify-effort-estimate}
+@table @asis
+@item @kbd{C-c C-x e}  (@code{org-set-effort})
+@kindex C-c C-x e
+@findex org-set-effort
+Set the effort estimate for the current entry.  With a prefix
+argument, set it to the next allowed value---see below.  This
+command is also accessible from the agenda with the @kbd{e}
+key.
+
+@item @kbd{C-c C-x C-e} (@code{org-clock-modify-effort-estimate})
+@kindex C-c C-x C-e
+@findex org-clock-modify-effort-estimate
 Modify the effort estimate of the item currently being clocked.
 @end table
 
-Clearly the best way to work with effort estimates is through column view
-(@pxref{Column view}).  You should start by setting up discrete values for
-effort estimates, and a @code{COLUMNS} format that displays these values
-together with clock sums (if you want to clock your time).  For a specific
-buffer you can use
+Clearly the best way to work with effort estimates is through column
+view (see @ref{Column View}).  You should start by setting up discrete
+values for effort estimates, and a @samp{COLUMNS} format that displays
+these values together with clock sums---if you want to clock your
+time.  For a specific buffer you can use:
 
 @example
 #+PROPERTY: Effort_ALL 0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00
@@ -6846,258 +7585,536 @@ buffer you can use
 @noindent
 @vindex org-global-properties
 @vindex org-columns-default-format
-or, even better, you can set up these values globally by customizing the
-variables @code{org-global-properties} and @code{org-columns-default-format}.
-In particular if you want to use this setup also in the agenda, a global
-setup may be advised.
+or, even better, you can set up these values globally by customizing
+the variables @code{org-global-properties} and
+@code{org-columns-default-format}.  In particular if you want to use this
+setup also in the agenda, a global setup may be advised.
 
-The way to assign estimates to individual items is then to switch to column
-mode, and to use @kbd{S-@key{RIGHT}} and @kbd{S-@key{LEFT}} to change the
-value.  The values you enter will immediately be summed up in the hierarchy.
-In the column next to it, any clocked time will be displayed.
+The way to assign estimates to individual items is then to switch to
+column mode, and to use @kbd{S-@key{RIGHT}} and @kbd{S-@key{LEFT}} to
+change the value.  The values you enter are immediately summed up in
+the hierarchy.  In the column next to it, any clocked time is
+displayed.
 
 @vindex org-agenda-columns-add-appointments-to-effort-sum
-If you switch to column view in the daily/weekly agenda, the effort column
-will summarize the estimated work effort for each day@footnote{Please note
-the pitfalls of summing hierarchical data in a flat list (@pxref{Agenda
-column view}).}, and you can use this to find space in your schedule.  To get
-an overview of the entire part of the day that is committed, you can set the
+If you switch to column view in the daily/weekly agenda, the effort
+column summarizes the estimated work effort for each day@footnote{Please note 
the pitfalls of summing hierarchical data in
+a flat list (see @ref{Agenda Column View}).}, and
+you can use this to find space in your schedule.  To get an overview
+of the entire part of the day that is committed, you can set the
 option @code{org-agenda-columns-add-appointments-to-effort-sum}.  The
-appointments on a day that take place over a specified time interval will
-then also be added to the load estimate of the day.
+appointments on a day that take place over a specified time interval
+are then also added to the load estimate of the day.
 
-Effort estimates can be used in secondary agenda filtering that is triggered
-with the @kbd{/} key in the agenda (@pxref{Agenda commands}).  If you have
-these estimates defined consistently, two or three key presses will narrow
-down the list to stuff that fits into an available time slot.
+Effort estimates can be used in secondary agenda filtering that is
+triggered with the @kbd{/} key in the agenda (see @ref{Agenda Commands}).  If 
you have these estimates defined consistently,
+two or three key presses narrow down the list to stuff that fits into
+an available time slot.
 
 @node Timers
-@section Taking notes with a timer
+@section Taking Notes with a Relative Timer
+
 @cindex relative timer
 @cindex countdown timer
-@kindex ;
 
-Org provides two types of timers.  There is a relative timer that counts up,
-which can be useful when taking notes during, for example, a meeting or
-a video viewing.  There is also a countdown timer.
+Org provides two types of timers.  There is a relative timer that
+counts up, which can be useful when taking notes during, for example,
+a meeting or a video viewing.  There is also a countdown timer.
 
 The relative and countdown are started with separate commands.
 
-@table @kbd
-@orgcmd{C-c C-x 0,org-timer-start}
-Start or reset the relative timer.  By default, the timer is set to 0.  When
-called with a @kbd{C-u} prefix, prompt the user for a starting offset.  If
-there is a timer string at point, this is taken as the default, providing a
-convenient way to restart taking notes after a break in the process.  When
-called with a double prefix argument @kbd{C-u C-u}, change all timer strings
-in the active region by a certain amount.  This can be used to fix timer
+@table @asis
+@item @kbd{C-c C-x 0} (@code{org-timer-start})
+@kindex C-c C-x 0
+@findex org-timer-start
+Start or reset the relative timer.  By default, the timer is set
+to 0.  When called with a @kbd{C-u} prefix, prompt the user for
+a starting offset.  If there is a timer string at point, this is
+taken as the default, providing a convenient way to restart taking
+notes after a break in the process.  When called with a double
+prefix argument @kbd{C-u C-u}, change all timer strings in the
+active region by a certain amount.  This can be used to fix timer
 strings if the timer was not started at exactly the right moment.
-@orgcmd{C-c C-x ;,org-timer-set-timer}
+
+@item @kbd{C-c C-x ;} (@code{org-timer-set-timer})
+@kindex C-c C-x ;
+@findex org-timer-set-timer
+@vindex org-timer-default-timer
 Start a countdown timer.  The user is prompted for a duration.
 @code{org-timer-default-timer} sets the default countdown value.  Giving
-a numeric prefix argument overrides this default value.  This command is
-available as @kbd{;} in agenda buffers.
+a numeric prefix argument overrides this default value.  This
+command is available as @kbd{;} in agenda buffers.
 @end table
 
-Once started, relative and countdown timers are controlled with the same
-commands.
-
-@table @kbd
-@orgcmd{C-c C-x .,org-timer}
-Insert the value of the current relative or countdown timer into the buffer.
-If no timer is running, the relative timer will be started.  When called with
-a prefix argument, the relative timer is restarted.
-@orgcmd{C-c C-x -,org-timer-item}
-Insert a description list item with the value of the current relative or
-countdown timer.  With a prefix argument, first reset the relative timer to
-0.
-@orgcmd{M-@key{RET},org-insert-heading}
-Once the timer list is started, you can also use @kbd{M-@key{RET}} to insert
-new timer items.
-@orgcmd{C-c C-x @comma{},org-timer-pause-or-continue}
+Once started, relative and countdown timers are controlled with the
+same commands.
+
+@table @asis
+@item @kbd{C-c C-x .} (@code{org-timer})
+@kindex C-c C-x .
+@findex org-timer
+Insert a relative time into the buffer.  The first time you use
+this, the timer starts.  Using a prefix argument restarts it.
+
+@item @kbd{C-c C-x -} (@code{org-timer-item})
+@kindex C-c C-x -
+@findex org-timer-item
+Insert a description list item with the current relative time.  With
+a prefix argument, first reset the timer to 0.
+
+@item @kbd{M-@key{RET}} (@code{org-insert-heading})
+@kindex M-RET
+@findex org-insert-heading
+Once the timer list is started, you can also use @kbd{M-@key{RET}} to
+insert new timer items.
+
+@item @kbd{C-c C-x ,} (@code{org-timer-pause-or-continue})
+@kindex C-c C-x ,
+@findex org-timer-pause-or-continue
 Pause the timer, or continue it if it is already paused.
-@orgcmd{C-c C-x _,org-timer-stop}
-Stop the timer.  After this, you can only start a new timer, not continue the
-old one.  This command also removes the timer from the mode line.
+
+@item @kbd{C-c C-x _} (@code{org-timer-stop})
+@kindex C-c C-x _
+@findex org-timer-stop
+Stop the timer.  After this, you can only start a new timer, not
+continue the old one.  This command also removes the timer from the
+mode line.
+@end table
+
+@node Refiling and Archiving
+@chapter Refiling and Archiving
+
+@cindex refiling notes
+@cindex copying notes
+@cindex archiving
+
+Once information is in the system, it may need to be moved around.
+Org provides Refile, Copy and Archive commands for this.  Refile and
+Copy helps with moving and copying outlines.  Archiving helps to keep
+the system compact and fast.
+
+@menu
+* Refile and Copy::              Moving/copying a tree from one place to 
another.
+* Archiving::                    What to do with finished products.
+@end menu
+
+@node Refile and Copy
+@section Refile and Copy
+
+@cindex refiling notes
+@cindex copying notes
+
+When reviewing the captured data, you may want to refile or to copy
+some of the entries into a different list, for example into a project.
+Cutting, finding the right location, and then pasting the note is
+cumbersome.  To simplify this process, you can use the following
+special command:
+
+@table @asis
+@item @kbd{C-c C-w} (@code{org-refile})
+@kindex C-c C-w
+@findex org-refile
+@vindex org-reverse-note-order
+@vindex org-refile-targets
+@vindex org-refile-use-outline-path
+@vindex org-outline-path-complete-in-steps
+@vindex org-refile-allow-creating-parent-nodes
+@vindex org-log-refile
+Refile the entry or region at point.  This command offers possible
+locations for refiling the entry and lets you select one with
+completion.  The item (or all items in the region) is filed below
+the target heading as a subitem.  Depending on
+@code{org-reverse-note-order}, it is either the first or last subitem.
+
+By default, all level 1 headlines in the current buffer are
+considered to be targets, but you can have more complex definitions
+across a number of files.  See the variable @code{org-refile-targets} for
+details.  If you would like to select a location via
+a file-path-like completion along the outline path, see the
+variables @code{org-refile-use-outline-path} and
+@code{org-outline-path-complete-in-steps}.  If you would like to be able
+to create new nodes as new parents for refiling on the fly, check
+the variable @code{org-refile-allow-creating-parent-nodes}.  When the
+variable @code{org-log-refile}@footnote{Note the corresponding @samp{STARTUP} 
options @samp{logrefile},
+@samp{lognoterefile}, and @samp{nologrefile}.} is set, a timestamp or a note is
+recorded whenever an entry is refiled.
+
+@item @kbd{C-u C-c C-w}
+@kindex C-u C-c C-w
+Use the refile interface to jump to a heading.
+
+@item @kbd{C-u C-u C-c C-w} (@code{org-refile-goto-last-stored})
+@kindex C-u C-u C-c C-w
+@findex org-refile-goto-last-stored
+Jump to the location where @code{org-refile} last moved a tree to.
+
+@item @kbd{C-2 C-c C-w}
+@kindex C-2 C-c C-w
+Refile as the child of the item currently being clocked.
+
+@item @kbd{C-3 C-c C-w}
+@kindex C-3 C-c C-w
+@vindex org-refile-keep
+Refile and keep the entry in place.  Also see @code{org-refile-keep} to
+make this the default behavior, and beware that this may result in
+duplicated @samp{ID} properties.
+
+@item @kbd{C-0 C-c C-w} or @kbd{C-u C-u C-u C-c C-w} 
(@code{org-refile-cache-clear})
+@kindex C-u C-u C-u C-c C-w
+@kindex C-0 C-c C-w
+@findex org-refile-cache-clear
+@vindex org-refile-use-cache
+Clear the target cache.  Caching of refile targets can be turned on
+by setting @code{org-refile-use-cache}.  To make the command see new
+possible targets, you have to clear the cache with this command.
+
+@item @kbd{C-c M-w} (@code{org-copy})
+@kindex C-c M-w
+@findex org-copy
+Copying works like refiling, except that the original note is not
+deleted.
+@end table
+
+@node Archiving
+@section Archiving
+
+@cindex archiving
+
+When a project represented by a (sub)tree is finished, you may want to
+move the tree out of the way and to stop it from contributing to the
+agenda.  Archiving is important to keep your working files compact and
+global searches like the construction of agenda views fast.
+
+@table @asis
+@item @kbd{C-c C-x C-a} (@code{org-archive-subtree-default})
+@kindex C-c C-x C-a
+@findex org-archive-subtree-default
+@vindex org-archive-default-command
+Archive the current entry using the command specified in the
+variable @code{org-archive-default-command}.
+@end table
+
+@menu
+* Moving subtrees::              Moving a tree to an archive file.
+* Internal archiving::           Switch off a tree but keep it in the file.
+@end menu
+
+@node Moving subtrees
+@subsection Moving a tree to an archive file
+
+@cindex external archiving
+
+The most common archiving action is to move a project tree to another
+file, the archive file.
+
+@table @asis
+@item @kbd{C-c C-x C-s} or short @kbd{C-c $} (@code{org-archive-subtree})
+@kindex C-c C-x C-s
+@kindex C-c $
+@findex org-archive-subtree
+@vindex org-archive-location
+Archive the subtree starting at point position to the location given
+by @code{org-archive-location}.
+
+@item @kbd{C-u C-c C-x C-s}
+@kindex C-u C-c C-x C-s
+Check if any direct children of the current headline could be moved
+to the archive.  To do this, check each subtree for open TODO
+entries.  If none is found, the command offers to move it to the
+archive location.  If point is @emph{not} on a headline when this command
+is invoked, check level 1 trees.
+
+@item @kbd{C-u C-u C-c C-x C-s}
+@kindex C-u C-u C-c C-x C-s
+As above, but check subtree for timestamps instead of TODO entries.
+The command offers to archive the subtree if it @emph{does} contain
+a timestamp, and that timestamp is in the past.
+@end table
+
+@cindex archive locations
+The default archive location is a file in the same directory as the
+current file, with the name derived by appending @samp{_archive} to the
+current file name.  You can also choose what heading to file archived
+items under, with the possibility to add them to a datetree in a file.
+For information and examples on how to specify the file and the
+heading, see the documentation string of the variable
+@code{org-archive-location}.
+
+There is also an in-buffer option for setting this variable, for
+example:
+
+@cindex @samp{ARCHIVE}, keyword
+@example
+#+ARCHIVE: %s_done::
+@end example
+
+
+@cindex ARCHIVE, property
+If you would like to have a special archive location for a single
+entry or a (sub)tree, give the entry an @samp{ARCHIVE} property with the
+location as the value (see @ref{Properties and Columns}).
+
+@vindex org-archive-save-context-info
+When a subtree is moved, it receives a number of special properties
+that record context information like the file from where the entry
+came, its outline path the archiving time etc.  Configure the variable
+@code{org-archive-save-context-info} to adjust the amount of information
+added.
+
+@node Internal archiving
+@subsection Internal archiving
+
+@cindex @samp{ARCHIVE}, tag
+If you want to just switch off---for agenda views---certain subtrees
+without moving them to a different file, you can use the @samp{ARCHIVE}
+tag.
+
+A headline that is marked with the @samp{ARCHIVE} tag (see @ref{Tags}) stays at
+its location in the outline tree, but behaves in the following way:
+
+@itemize
+@item
+@vindex org-cycle-open-archived-trees
+It does not open when you attempt to do so with a visibility cycling
+command (see @ref{Visibility Cycling}).  You can force cycling archived
+subtrees with @kbd{C-@key{TAB}}, or by setting the option
+@code{org-cycle-open-archived-trees}.  Also normal outline commands, like
+@code{outline-show-all}, open archived subtrees.
+
+@item
+@vindex org-sparse-tree-open-archived-trees
+During sparse tree construction (see @ref{Sparse Trees}), matches in
+archived subtrees are not exposed, unless you configure the option
+@code{org-sparse-tree-open-archived-trees}.
+
+@item
+@vindex org-agenda-skip-archived-trees
+During agenda view construction (see @ref{Agenda Views}), the content of
+archived trees is ignored unless you configure the option
+@code{org-agenda-skip-archived-trees}, in which case these trees are
+always included.  In the agenda you can press @kbd{v a} to get
+archives temporarily included.
+
+@item
+@vindex org-export-with-archived-trees
+Archived trees are not exported (see @ref{Exporting}), only the headline
+is.  Configure the details using the variable
+@code{org-export-with-archived-trees}.
+
+@item
+@vindex org-columns-skip-archived-trees
+Archived trees are excluded from column view unless the variable
+@code{org-columns-skip-archived-trees} is configured to @code{nil}.
+@end itemize
+
+The following commands help manage the @samp{ARCHIVE} tag:
+
+@table @asis
+@item @kbd{C-c C-x a} (@code{org-toggle-archive-tag})
+@kindex C-c C-x a
+@findex org-toggle-archive-tag
+Toggle the archive tag for the current headline.  When the tag is
+set, the headline changes to a shadowed face, and the subtree below
+it is hidden.
+
+@item @kbd{C-u C-c C-x a}
+@kindex C-u C-c C-x a
+Check if any direct children of the current headline should be
+archived.  To do this, check each subtree for open TODO entries.  If
+none is found, the command offers to set the @samp{ARCHIVE} tag for the
+child.  If point is @emph{not} on a headline when this command is
+invoked, check the level 1 trees.
+
+@item @kbd{C-@key{TAB}} (@code{org-force-cycle-archived})
+@kindex C-TAB
+Cycle a tree even if it is tagged with @samp{ARCHIVE}.
+
+@item @kbd{C-c C-x A} (@code{org-archive-to-archive-sibling})
+@kindex C-c C-x A
+@findex org-archive-to-archive-sibling
+Move the current entry to the @emph{Archive Sibling}.  This is a sibling
+of the entry with the heading @samp{Archive} and the archive tag.  The
+entry becomes a child of that sibling and in this way retains a lot
+of its original context, including inherited tags and approximate
+position in the outline.
 @end table
 
-@node Capture - Refile - Archive
-@chapter Capture - Refile - Archive
+@node Capture and Attachments
+@chapter Capture and Attachments
+
 @cindex capture
+@cindex attachments
+@cindex RSS feeds
+@cindex Atom feeds
+@cindex protocols, for external access
 
 An important part of any organization system is the ability to quickly
-capture new ideas and tasks, and to associate reference material with them.
-Org does this using a process called @i{capture}.  It also can store files
-related to a task (@i{attachments}) in a special directory.  Once in the
-system, tasks and projects need to be moved around.  Moving completed project
-trees to an archive file keeps the system compact and fast.
+capture new ideas and tasks, and to associate reference material with
+them.  Org does this using a process called @emph{capture}.  It also can
+store files related to a task (@emph{attachments}) in a special directory.
+Finally, it can parse RSS feeds for information.  To learn how to let
+external programs (for example a web browser) trigger Org to capture
+material, see @ref{Protocols}.
 
 @menu
-* Capture::                     Capturing new stuff
-* Attachments::                 Add files to tasks
-* RSS feeds::                   Getting input from RSS feeds
-* Protocols::                   External (e.g., Browser) access to Emacs and 
Org
-* Refile and copy::             Moving/copying a tree from one place to another
-* Archiving::                   What to do with finished projects
+* Capture::                      Capturing new stuff.
+* Attachments::                  Attach files to outlines.
+* RSS Feeds::                    Getting input from RSS feeds.
 @end menu
 
 @node Capture
 @section Capture
-@cindex capture
 
-Capture lets you quickly store notes with little interruption of your work
-flow.  Org's method for capturing new items is heavily inspired by John
-Wiegley excellent @file{remember.el} package.  Up to version 6.36, Org
-used a special setup for @file{remember.el}, then replaced it with
-@file{org-remember.el}.  As of version 8.0, @file{org-remember.el} has
-been completely replaced by @file{org-capture.el}.
+@cindex capture
 
-If your configuration depends on @file{org-remember.el}, you need to update
-it and use the setup described below.  To convert your
-@code{org-remember-templates}, run the command
-@example
-@kbd{M-x org-capture-import-remember-templates @key{RET}}
-@end example
-@noindent and then customize the new variable with @kbd{M-x
-customize-variable org-capture-templates}, check the result, and save the
-customization.
+Capture lets you quickly store notes with little interruption of your
+work flow.  Org's method for capturing new items is heavily inspired
+by John Wiegley's excellent Remember package.
 
 @menu
-* Setting up capture::          Where notes will be stored
-* Using capture::               Commands to invoke and terminate capture
-* Capture templates::           Define the outline of different note types
+* Setting up capture::           Where notes will be stored.
+* Using capture::                Commands to invoke and terminate capture.
+* Capture templates::            Define the outline of different note types.
 @end menu
 
 @node Setting up capture
 @subsection Setting up capture
 
-The following customization sets a default target file for notes, and defines
-a global key@footnote{Please select your own key, @kbd{C-c c} is only a
-suggestion.}  for capturing new material.
+The following customization sets a default target file for notes.
 
 @vindex org-default-notes-file
-@smalllisp
-@group
+@lisp
 (setq org-default-notes-file (concat org-directory "/notes.org"))
-(define-key global-map "\C-cc" 'org-capture)
-@end group
-@end smalllisp
+@end lisp
+
+You may also define a global key for capturing new material (see
+@ref{Activation}).
 
 @node Using capture
 @subsection Using capture
 
-@table @kbd
-@orgcmd{C-c c,org-capture}
-Call the command @code{org-capture}.  Note that this key binding is global and
-not active by default: you need to install it.  If you have templates
+@table @asis
+@item @kbd{M-x org-capture} (@code{org-capture})
+@findex org-capture
 @cindex date tree
-defined @pxref{Capture templates}, it will offer these templates for
-selection or use a new Org outline node as the default template.  It will
-insert the template into the target file and switch to an indirect buffer
-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.  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{Refile and copy}) 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.  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}
+Display the capture templates menu.  If you have templates defined
+(see @ref{Capture templates}), it offers these templates for selection or
+use a new Org outline node as the default template.  It inserts the
+template into the target file and switch to an indirect buffer
+narrowed to this new node.  You may then insert the information you
+want.
+
+@item @kbd{C-c C-c} (@code{org-capture-finalize})
+@kindex C-c C-c @r{(Capture buffer)}
+@findex org-capture-finalize
+Once you have finished entering information into the capture buffer,
+@kbd{C-c C-c} returns you to the window configuration before
+the capture process, so that you can resume your work without
+further distraction.  When called with a prefix argument, finalize
+and then jump to the captured item.
+
+@item @kbd{C-c C-w} (@code{org-capture-refile})
+@kindex C-c C-w @r{(Capture buffer)}
+@findex org-capture-refile
+Finalize the capture process by refiling the note to a different
+place (see @ref{Refile and Copy}).  Please realize that this is a normal
+refiling command that will be executed---so point position at the
+moment you run this command is important.  If you have inserted
+a tree with a parent and children, first move point back to the
+parent.  Any prefix argument given to this command is passed on to
+the @code{org-refile} command.
+
+@item @kbd{C-c C-k} (@code{org-capture-kill})
+@kindex C-c C-k @r{(Capture buffer)}
+@findex 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
-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.
+@kindex k c @r{(Agenda)}
+You can also call @code{org-capture} in a special way from the agenda,
+using the @kbd{k c} key combination.  With this access, any
+timestamps inserted by the selected capture template defaults to the
+date at point 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:
+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 capture template.  You get to select the
-template in the usual way.
-@orgkey{C-u C-u C-c c}
+@table @asis
+@item @kbd{C-u M-x org-capture}
+Visit the target location of a capture template.  You get to select
+the template in the usual way.
+
+@item @kbd{C-u C-u M-x org-capture}
 Visit the last stored capture item in its buffer.
 @end table
 
 @vindex org-capture-bookmark
-@cindex @code{org-capture-last-stored}
-You can also jump to the bookmark @code{org-capture-last-stored}, which will
-automatically be created unless you set @code{org-capture-bookmark} to
-@code{nil}.
+@vindex org-capture-last-stored
+You can also jump to the bookmark @code{org-capture-last-stored}, which is
+automatically created unless you set @code{org-capture-bookmark} to @code{nil}.
 
-To insert the capture at point in an Org buffer, call @code{org-capture} with
-a @code{C-0} prefix argument.
+To insert the capture at point in an Org buffer, call @code{org-capture}
+with a @kbd{C-0} prefix argument.
 
 @node Capture templates
 @subsection Capture templates
+
 @cindex templates, for Capture
 
-You can use templates for different types of capture items, and
-for different target locations.  The easiest way to create such templates is
-through the customize interface.
+You can use templates for different types of capture items, and for
+different target locations.  The easiest way to create such templates
+is through the customize interface.
 
-@table @kbd
-@orgkey{C-c c C}
+@table @asis
+@item @kbd{C}
+@kindex C @r{(Capture menu}
 @vindex org-capture-templates
 Customize the variable @code{org-capture-templates}.
 @end table
 
-Before we give the formal description of template definitions, let's look at
-an example.  Say you would like to use one template to create general TODO
-entries, and you want to put these entries under the heading @samp{Tasks} in
-your file @file{~/org/gtd.org}.  Also, a date tree in the file
-@file{journal.org} should capture journal entries.  A possible configuration
-would look like:
+Before we give the formal description of template definitions, let's
+look at an example.  Say you would like to use one template to create
+general TODO entries, and you want to put these entries under the
+heading @samp{Tasks} in your file @samp{~/org/gtd.org}.  Also, a date tree in
+the file @samp{journal.org} should capture journal entries.  A possible
+configuration would look like:
 
-@smalllisp
-@group
+@lisp
 (setq org-capture-templates
- '(("t" "Todo" entry (file+headline "~/org/gtd.org" "Tasks")
-        "* TODO %?\n  %i\n  %a")
-   ("j" "Journal" entry (file+olp+datetree "~/org/journal.org")
-        "* %?\nEntered on %U\n  %i\n  %a")))
-@end group
-@end smalllisp
+      '(("t" "Todo" entry (file+headline "~/org/gtd.org" "Tasks")
+         "* TODO %?\n  %i\n  %a")
+        ("j" "Journal" entry (file+datetree "~/org/journal.org")
+         "* %?\nEntered on %U\n  %i\n  %a")))
+@end lisp
+
+If you then press @kbd{t} from the capture menu, Org will prepare
+the template for you like this:
 
-@noindent If you then press @kbd{C-c c t}, Org will prepare the template
-for you like this:
 @example
 * TODO
-  [[file:@var{link to where you initiated capture}]]
+  [[file:LINK TO WHERE YOU INITIATED CAPTURE]]
 @end example
 
 @noindent
-During expansion of the template, @code{%a} has been replaced by a link to
+During expansion of the template, @samp{%a} has been replaced by a link to
 the location from where you called the capture command.  This can be
-extremely useful for deriving tasks from emails, for example.  You fill in
-the task definition, press @kbd{C-c C-c} and Org returns you to the same
-place where you started the capture process.
+extremely useful for deriving tasks from emails, for example.  You
+fill in the task definition, press @kbd{C-c C-c} and Org returns
+you to the same place where you started the capture process.
 
-To define special keys to capture to a particular template without going
-through the interactive template selection, you can create your key binding
-like this:
+To define special keys to capture to a particular template without
+going through the interactive template selection, you can create your
+key binding like this:
 
 @lisp
 (define-key global-map "\C-cx"
-   (lambda () (interactive) (org-capture nil "x")))
+  (lambda () (interactive) (org-capture nil "x")))
 @end lisp
 
 @menu
-* Template elements::           What is needed for a complete template entry
-* Template expansion::          Filling in information about time and context
-* Templates in contexts::       Only show a template in a specific context
+* Template elements::            What is needed for a complete template entry.
+* Template expansion::           Filling in information about time and context.
+* Templates in contexts::        Only show a template in a specific context.
 @end menu
 
 @node Template elements
@@ -7106,1080 +8123,994 @@ like this:
 Now lets look at the elements of a template definition.  Each entry in
 @code{org-capture-templates} is a list with the following items:
 
-@table @var
+@table @asis
 @item keys
-The keys that will select the template, as a string, characters
-only, for example @code{"a"} for a template to be selected with a
-single key, or @code{"bt"} for selection with two keys.  When using
-several keys, keys using the same prefix key must be sequential
-in the list and preceded by a 2-element entry explaining the
-prefix key, for example
-@smalllisp
-         ("b" "Templates for marking stuff to buy")
-@end smalllisp
-@noindent If you do not define a template for the @kbd{C} key, this key will
-be used to open the customize buffer for this complex variable.
+The keys that selects the template, as a string, characters only,
+for example @samp{"a"}, for a template to be selected with a single key,
+or @samp{"bt"} for selection with two keys.  When using several keys,
+keys using the same prefix key must be sequential in the list and
+preceded by a 2-element entry explaining the prefix key, for
+example:
+
+@lisp
+("b" "Templates for marking stuff to buy")
+@end lisp
+
+If you do not define a template for the @kbd{C} key, this key
+opens the Customize buffer for this complex variable.
 
 @item description
-A short string describing the template, which will be shown during
-selection.
+A short string describing the template, shown during selection.
 
 @item type
 The type of entry, a symbol.  Valid values are:
 
-@table @code
-@item entry
-An Org mode node, with a headline.  Will be filed as the child of the target
-entry or as a top-level entry.  The target file should be an Org mode file.
-@item item
-A plain list item, placed in the first plain  list at the target
+@table @asis
+@item @code{entry}
+An Org mode node, with a headline.  Will be filed as the child of
+the target entry or as a top-level entry.  The target file should
+be an Org file.
+
+@item @code{item}
+A plain list item, placed in the first plain list at the target
 location.  Again the target file should be an Org file.
-@item checkitem
-A checkbox item.  This only differs from the plain list item by the
-default template.
-@item table-line
-a new line in the first table at the target location.  Where exactly the
-line will be inserted depends on the properties @code{:prepend} and
-@code{:table-line-pos} (see below).
-@item plain
+
+@item @code{checkitem}
+A checkbox item.  This only differs from the plain list item by
+the default template.
+
+@item @code{table-line}
+A new line in the first table at the target location.  Where
+exactly the line will be inserted depends on the properties
+@code{:prepend} and @code{:table-line-pos} (see below).
+
+@item @code{plain}
 Text to be inserted as it is.
 @end table
 
 @item target
 @vindex org-default-notes-file
-Specification of where the captured item should be placed.  In Org mode
-files, targets usually define a node.  Entries will become children of this
-node.  Other types will be added to the table or list in the body of this
-node.  Most target specifications contain a file name.  If that file name is
-the empty string, it defaults to @code{org-default-notes-file}.  A file can
-also be given as a variable or as a function called with no argument.  When
-an absolute path is not specified for a target, it is taken as relative to
-@code{org-directory}.
+@vindex org-directory
+Specification of where the captured item should be placed.  In Org
+files, targets usually define a node.  Entries will become children
+of this node.  Other types will be added to the table or list in the
+body of this node.  Most target specifications contain a file name.
+If that file name is the empty string, it defaults to
+@code{org-default-notes-file}.  A file can also be given as a variable or
+as a function called with no argument.  When an absolute path is not
+specified for a target, it is taken as relative to @code{org-directory}.
 
 Valid values are:
 
-@table @code
-@item (file "path/to/file")
+@table @asis
+@item @samp{(file "path/to/file")}
 Text will be placed at the beginning or end of that file.
 
-@item (id "id of existing org entry")
+@item @samp{(id "id of existing org entry")}
 Filing as child of this entry, or in the body of the entry.
 
-@item (file+headline "path/to/file" "node headline")
+@item @samp{(file+headline "filename" "node headline")}
 Fast configuration if the target heading is unique in the file.
 
-@item (file+olp "path/to/file" "Level 1 heading" "Level 2" ...)
+@item @samp{(file+olp "filename" "Level 1 heading" "Level 2" ...)}
 For non-unique headings, the full path is safer.
 
-@item (file+regexp  "path/to/file" "regexp to find location")
-Use a regular expression to position the cursor.
-
-@item (file+olp+datetree "path/to/file" [ "Level 1 heading" ....])
-This target@footnote{Org used to offer four different targets for date/week
-tree capture.  Now, Org automatically translates these to use
-@code{file+olp+datetree}, applying the @code{:time-prompt} and
-@code{:tree-type} properties.  Please rewrite your date/week-tree targets
-using @code{file+olp+datetree} since the older targets are now deprecated.}
-will create a heading in a date tree@footnote{A date tree is an outline
-structure with years on the highest level, months or ISO-weeks as sublevels
-and then dates on the lowest level.  Tags are allowed in the tree structure.}
-for today's date.  If the optional outline path is given, the tree will be
-built under the node it is pointing to, instead of at top level.  Check out
-the @code{:time-prompt} and @code{:tree-type} properties below for additional
-options.
-
-@item (file+function "path/to/file" function-finding-location)
+@item @samp{(file+regexp "filename" "regexp to find location")}
+Use a regular expression to position point.
+
+@item @samp{(file+olp+datetree "filename" [ "Level 1 heading" ...])}
+This target@footnote{Org used to offer four different targets for date/week 
tree
+capture.  Now, Org automatically translates these to use
+@code{file+olp+datetree}, applying the @code{:time-prompt} and 
@code{:tree-type}
+properties.  Please rewrite your date/week-tree targets using
+@code{file+olp+datetree} since the older targets are now deprecated.} creates 
a heading in a date tree@footnote{A date tree is an outline structure with 
years on the highest
+level, months or ISO weeks as sublevels and then dates on the lowest
+level.  Tags are allowed in the tree structure.} for
+today's date.  If the optional outline path is given, the tree
+will be built under the node it is pointing to, instead of at top
+level.  Check out the @code{:time-prompt} and @code{:tree-type} properties
+below for additional options.
+
+@item @samp{(file+function "filename" function-finding-location)}
 A function to find the right location in the file.
 
-@item (clock)
+@item @samp{(clock)}
 File to the entry that is currently being clocked.
 
-@item (function function-finding-location)
-Most general way: write your own function which both visits
-the file and moves point to the right location.
+@item @samp{(function function-finding-location)}
+Most general way: write your own function which both visits the
+file and moves point to the right location.
 @end table
 
 @item template
-The template for creating the capture item.  If you leave this empty, an
-appropriate default template will be used.  Otherwise this is a string with
-escape codes, which will be replaced depending on time and context of the
-capture call.  The string with escapes may be loaded from a template file,
-using the special syntax @code{(file "path/to/template")}.  See below for
-more details.
+The template for creating the capture item.  If you leave this
+empty, an appropriate default template will be used.  Otherwise this
+is a string with escape codes, which will be replaced depending on
+time and context of the capture call.  The string with escapes may
+be loaded from a template file, using the special syntax @samp{(file
+  "template filename")}.  See below for more details.
 
 @item properties
 The rest of the entry is a property list of additional options.
 Recognized properties are:
 
-@table @code
-@item :prepend
-Normally new captured information will be appended at
-the target location (last child, last table line, last list item...).
-Setting this property will change that.
-
-@item :immediate-finish
-When set, do not offer to edit the information, just
-file it away immediately.  This makes sense if the template only needs
+@table @asis
+@item @code{:prepend}
+Normally new captured information will be appended at the target
+location (last child, last table line, last list item, @dots{}).
+Setting this property changes that.
+
+@item @code{:immediate-finish}
+When set, do not offer to edit the information, just file it away
+immediately.  This makes sense if the template only needs
 information that can be added automatically.
 
-@item :empty-lines
-Set this to the number of lines to insert
-before and after the new item.  Default 0, only common other value is 1.
+@item @code{:empty-lines}
+Set this to the number of lines to insert before and after the new
+item.  Default 0, and the only other common value is 1.
 
-@item :clock-in
+@item @code{:clock-in}
 Start the clock in this item.
 
-@item :clock-keep
+@item @code{:clock-keep}
 Keep the clock running when filing the captured entry.
 
-@item :clock-resume
-If starting the capture interrupted a clock, restart that clock when finished
-with the capture.  Note that @code{:clock-keep} has precedence over
-@code{:clock-resume}.  When setting both to @code{t}, the current clock will
-run and the previous one will not be resumed.
-
-@item :time-prompt
-Prompt for a date/time to be used for date/week trees and when filling the
-template.  Without this property, capture uses the current date and time.
-Even if this property has not been set, you can force the same behavior by
-calling @code{org-capture} with a @kbd{C-1} prefix argument.
-
-@item :tree-type
-When `week', make a week tree instead of the month tree, i.e. place the
-headings for each day under a heading with the current iso week.
-
-@item :unnarrowed
-Do not narrow the target buffer, simply show the full buffer.  Default is to
-narrow it so that you only see the new material.
-
-@item :table-line-pos
-Specification of the location in the table where the new line should be
-inserted. It can be a string, a variable holding a string or a function
-returning a string. The string should look like @code{"II-3"} meaning that
-the new line should become the third line before the second horizontal
-separator line.
-
-@item :kill-buffer
-If the target file was not yet visited when capture was invoked, kill the
-buffer again after capture is completed.
+@item @code{:clock-resume}
+If starting the capture interrupted a clock, restart that clock
+when finished with the capture.  Note that @code{:clock-keep} has
+precedence over @code{:clock-resume}.  When setting both to non-@code{nil},
+the current clock will run and the previous one will not be
+resumed.
+
+@item @code{:time-prompt}
+Prompt for a date/time to be used for date/week trees and when
+filling the template.  Without this property, capture uses the
+current date and time.  Even if this property has not been set,
+you can force the same behavior by calling @code{org-capture} with
+a @kbd{C-1} prefix argument.
+
+@item @code{:tree-type}
+When @code{week}, make a week tree instead of the month tree, i.e.,
+place the headings for each day under a heading with the current
+ISO week.
+
+@item @code{:unnarrowed}
+Do not narrow the target buffer, simply show the full buffer.
+Default is to narrow it so that you only see the new material.
+
+@item @code{:table-line-pos}
+Specification of the location in the table where the new line
+should be inserted.  It should be a string like @samp{II-3} meaning
+that the new line should become the third line before the second
+horizontal separator line.
+
+@item @code{:kill-buffer}
+If the target file was not yet visited when capture was invoked,
+kill the buffer again after capture is completed.
+
+@item @code{:no-save}
+Do not save the target file after finishing the capture.
 @end table
 @end table
 
 @node Template expansion
 @subsubsection Template expansion
 
-In the template itself, special @kbd{%}-escapes@footnote{If you need one of
-these sequences literally, escape the @kbd{%} with a backslash.} allow
-dynamic insertion of content.  The templates are expanded in the order given 
here:
-
-@smallexample
-%[@var{file}]     @r{Insert the contents of the file given by @var{file}.}
-%(@var{sexp})     @r{Evaluate Elisp @var{sexp} and replace with the result.}
-                  @r{For convenience, %:keyword (see below) placeholders}
-                  @r{within the expression will be expanded prior to this.}
-                  @r{The sexp must return a string.}
-%<...>      @r{The result of format-time-string on the ... format 
specification.}
-%t          @r{Timestamp, date only.}
-%T          @r{Timestamp, with date and time.}
-%u, %U      @r{Like the above, but inactive timestamps.}
-%i          @r{Initial content, the region when capture is called while the}
-            @r{region is active.}
-            @r{The entire text will be indented like @code{%i} itself.}
-%a          @r{Annotation, normally the link created with 
@code{org-store-link}.}
-%A          @r{Like @code{%a}, but prompt for the description part.}
-%l          @r{Like %a, but only insert the literal link.}
-%c          @r{Current kill ring head.}
-%x          @r{Content of the X clipboard.}
-%k          @r{Title of the currently clocked task.}
-%K          @r{Link to the currently clocked task.}
-%n          @r{User name (taken from @code{user-full-name}).}
-%f          @r{File visited by current buffer when org-capture was called.}
-%F          @r{Full path of the file or directory visited by current buffer.}
-%:keyword   @r{Specific information for certain link types, see below.}
-%^g         @r{Prompt for tags, with completion on tags in target file.}
-%^G         @r{Prompt for tags, with completion all tags in all agenda files.}
-%^t         @r{Like @code{%t}, but prompt for date.  Similarly @code{%^T}, 
@code{%^u}, @code{%^U}.}
-            @r{You may define a prompt like @code{%^@{Birthday@}t}.}
-%^C         @r{Interactive selection of which kill or clip to use.}
-%^L         @r{Like @code{%^C}, but insert as link.}
-%^@{@var{prop}@}p   @r{Prompt the user for a value for property @var{prop}.}
-%^@{@var{prompt}@}  @r{prompt the user for a string and replace this sequence 
with it.}
-            @r{You may specify a default value and a completion table with}
-            @r{%^@{prompt|default|completion2|completion3...@}.}
-            @r{The arrow keys access a prompt-specific history.}
-%\1 @dots{} %\N @r{Insert the text entered at the Nth %^@{@var{prompt}@}, 
where @code{N} is}
-            @r{a number, starting from 1.@footnote{As required in Emacs
-               Lisp, it is necessary to escape any backslash character in
-               a string with another backslash.  So, in order to use
-               @samp{%\1} placeholder, you need to write @samp{%\\1} in
-               the template.}}
-%?          @r{After completing the template, position cursor here.}
-@end smallexample
+In the template itself, special ``%-escapes''@footnote{If you need one of 
these sequences literally, escape the @samp{%}
+with a backslash.} allow dynamic
+insertion of content.  The templates are expanded in the order given
+here:
 
-@noindent
-For specific link types, the following keywords will be
-defined@footnote{If you define your own link types (@pxref{Adding
-hyperlink types}), any property you store with
-@code{org-store-link-props} can be accessed in capture templates in a
-similar way.}:
-
-@vindex org-from-is-user-regexp
-@smallexample
-Link type                        |  Available keywords
----------------------------------+----------------------------------------------
-bbdb                             |  %:name %:company
-irc                              |  %:server %:port %:nick
-vm, vm-imap, wl, mh, mew, rmail, |  %:type %:subject %:message-id
-gnus, notmuch                    |  %:from %:fromname %:fromaddress
-                                 |  %:to   %:toname   %:toaddress
-                                 |  %:date @r{(message date header field)}
-                                 |  %:date-timestamp @r{(date as active 
timestamp)}
-                                 |  %:date-timestamp-inactive @r{(date as 
inactive timestamp)}
-                                 |  %:fromto @r{(either "to NAME" or "from 
NAME")@footnote{This will always be the other, not the user.  See the variable 
@code{org-from-is-user-regexp}.}}
-gnus                             |  %:group, @r{for messages also all email 
fields}
-eww, w3, w3m                     |  %:url
-info                             |  %:file %:node
-calendar                         |  %:date
-org-protocol                     |  %:link %:description %:annotation
-@end smallexample
+@table @asis
+@item @samp{%[FILE]}
+Insert the contents of the file given by @var{FILE}.
 
-@noindent
-To place the cursor after template expansion use:
+@item @samp{%(EXP)}
+Evaluate Elisp expression @var{EXP} and replace it with the
+result.  The @var{EXP} form must return a string.  Only
+placeholders pre-existing within the template, or introduced with
+@samp{%[file]}, are expanded this way.  Since this happens after
+expanding non-interactive ``%-escapes'', those can be used to fill the
+expression.
 
-@smallexample
-%?          @r{After completing the template, position cursor here.}
-@end smallexample
+@item @samp{%<FORMAT>}
+The result of format-time-string on the @var{FORMAT}
+specification.
 
-@node Templates in contexts
-@subsubsection Templates in contexts
+@item @samp{%t}
+Timestamp, date only.
 
-@vindex org-capture-templates-contexts
-To control whether a capture template should be accessible from a specific
-context, you can customize @code{org-capture-templates-contexts}.  Let's say
-for example that you have a capture template @code{"p"} for storing Gnus
-emails containing patches.  Then you would configure this option like this:
+@item @samp{%T}
+Timestamp, with date and time.
 
-@smalllisp
-(setq org-capture-templates-contexts
-      '(("p" (in-mode . "message-mode"))))
-@end smalllisp
+@item @samp{%u}, @samp{%U}
+Like @samp{%t}, @samp{%T} above, but inactive timestamps.
 
-You can also tell that the command key @code{"p"} should refer to another
-template.  In that case, add this command key like this:
+@item @samp{%i}
+Initial content, the region when capture is called while the region
+is active.  If there is text before @samp{%i} on the same line, such as
+indentation, and @samp{%i} is not inside a @samp{%(exp)} form, that prefix is
+added before every line in the inserted text.
 
-@smalllisp
-(setq org-capture-templates-contexts
-      '(("p" "q" (in-mode . "message-mode"))))
-@end smalllisp
+@item @samp{%a}
+Annotation, normally the link created with @code{org-store-link}.
 
-See the docstring of the variable for more information.
+@item @samp{%A}
+Like @samp{%a}, but prompt for the description part.
 
-@node Attachments
-@section Attachments
-@cindex attachments
+@item @samp{%l}
+Like @samp{%a}, but only insert the literal link.
 
-@vindex org-attach-directory
-It is often useful to associate reference material with an outline node/task.
-Small chunks of plain text can simply be stored in the subtree of a project.
-Hyperlinks (@pxref{Hyperlinks}) can establish associations with
-files that live elsewhere on your computer or in the cloud, like emails or
-source code files belonging to a project.  Another method is @i{attachments},
-which are files located in a directory belonging to an outline node.  Org
-uses directories named by the unique ID of each entry.  These directories are
-located in the @file{data} directory which lives in the same directory where
-your Org file lives@footnote{If you move entries or Org files from one
-directory to another, you may want to configure @code{org-attach-directory}
-to contain an absolute path.}.  If you initialize this directory with
-@code{git init}, Org will automatically commit changes when it sees them.
-The attachment system has been contributed to Org by John Wiegley.
-
-In cases where it seems better to do so, you can also attach a directory of 
your
-choice to an entry.  You can also make children inherit the attachment
-directory from a parent, so that an entire subtree uses the same attached
-directory.
+@item @samp{%c}
+Current kill ring head.
 
-@noindent The following commands deal with attachments:
+@item @samp{%x}
+Content of the X clipboard.
 
-@table @kbd
-@orgcmd{C-c C-a,org-attach}
-The dispatcher for commands related to the attachment system.  After these
-keys, a list of commands is displayed and you must press an additional key
-to select a command:
+@item @samp{%k}
+Title of the currently clocked task.
 
-@table @kbd
-@orgcmdtkc{a,C-c C-a a,org-attach-attach}
-@vindex org-attach-method
-Select a file and move it into the task's attachment directory.  The file
-will be copied, moved, or linked, depending on @code{org-attach-method}.
-Note that hard links are not supported on all systems.
+@item @samp{%K}
+Link to the currently clocked task.
 
-@kindex C-c C-a c
-@kindex C-c C-a m
-@kindex C-c C-a l
-@item c/m/l
-Attach a file using the copy/move/link method.
-Note that hard links are not supported on all systems.
+@item @samp{%n}
+User name (taken from @code{user-full-name}).
 
-@orgcmdtkc{u,C-c C-a u,org-attach-url}
-Attach a file from URL
+@item @samp{%f}
+File visited by current buffer when org-capture was called.
 
-@orgcmdtkc{n,C-c C-a n,org-attach-new}
-Create a new attachment as an Emacs buffer.
+@item @samp{%F}
+Full path of the file or directory visited by current buffer.
 
-@orgcmdtkc{z,C-c C-a z,org-attach-sync}
-Synchronize the current task with its attachment directory, in case you added
-attachments yourself.
+@item @samp{%:keyword}
+Specific information for certain link types, see below.
 
-@orgcmdtkc{o,C-c C-a o,org-attach-open}
-@vindex org-file-apps
-Open current task's attachment.  If there is more than one, prompt for a
-file name first.  Opening will follow the rules set by @code{org-file-apps}.
-For more details, see the information on following hyperlinks
-(@pxref{Handling links}).
+@item @samp{%^g}
+Prompt for tags, with completion on tags in target file.
 
-@orgcmdtkc{O,C-c C-a O,org-attach-open-in-emacs}
-Also open the attachment, but force opening the file in Emacs.
+@item @samp{%^G}
+Prompt for tags, with completion all tags in all agenda files.
 
-@orgcmdtkc{f,C-c C-a f,org-attach-reveal}
-Open the current task's attachment directory.
+@item @samp{%^t}
+Like @samp{%t}, but prompt for date.  Similarly @samp{%^T}, @samp{%^u}, 
@samp{%^U}.  You
+may define a prompt like @samp{%^@{Birthday@}t}.
 
-@orgcmdtkc{F,C-c C-a F,org-attach-reveal-in-emacs}
-Also open the directory, but force using @command{dired} in Emacs.
+@item @samp{%^C}
+Interactive selection of which kill or clip to use.
 
-@orgcmdtkc{d,C-c C-a d,org-attach-delete-one}
-Select and delete a single attachment.
+@item @samp{%^L}
+Like @samp{%^C}, but insert as link.
 
-@orgcmdtkc{D,C-c C-a D,org-attach-delete-all}
-Delete all of a task's attachments.  A safer way is to open the directory in
-@command{dired} and delete from there.
+@item @samp{%^@{PROP@}p}
+Prompt the user for a value for property @var{PROP}.
 
-@orgcmdtkc{s,C-c C-a s,org-attach-set-directory}
-@cindex property, @code{ATTACH_DIR}
-Set a specific directory as the entry's attachment directory.  This works by
-putting the directory path into the @code{ATTACH_DIR} property.
+@item @samp{%^@{PROMPT@}}
+Prompt the user for a string and replace this sequence with it.  You
+may specify a default value and a completion table with
+@samp{%^@{prompt|default|completion2|completion3...@}}.  The arrow keys
+access a prompt-specific history.
 
-@orgcmdtkc{i,C-c C-a i,org-attach-set-inherit}
-@cindex property, @code{ATTACH_DIR_INHERIT}
-Set the @code{ATTACH_DIR_INHERIT} property, so that children will use the
-same directory for attachments as the parent does.
-@end table
-@end table
+@item @samp{%\N}
+Insert the text entered at the @var{N}th @samp{%^@{PROMPT@}}, where
+@var{N} is a number, starting from 1.
 
-@node RSS feeds
-@section RSS feeds
-@cindex RSS feeds
-@cindex Atom feeds
+@item @samp{%?}
+After completing the template, position point here.
+@end table
 
-Org can add and change entries based on information found in RSS feeds and
-Atom feeds.  You could use this to make a task out of each new podcast in a
-podcast feed.  Or you could use a phone-based note-creating service on the
-web to import tasks into Org.  To access feeds, configure the variable
-@code{org-feed-alist}.  The docstring of this variable has detailed
-information.  Here is just an example:
+@vindex org-store-link-props
+For specific link types, the following keywords are defined@footnote{If you 
define your own link types (see @ref{Adding Hyperlink Types}), any property you 
store with @code{org-store-link-props} can be
+accessed in capture templates in a similar way.}:
+
+@vindex org-link-from-user-regexp
+@multitable {aaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@headitem Link type
+@tab Available keywords
+@item bbdb
+@tab @samp{%:name}, @samp{%:company}
+@item irc
+@tab @samp{%:server}, @samp{%:port}, @samp{%:nick}
+@item mh, rmail
+@tab @samp{%:type}, @samp{%:subject}, @samp{%:message-id}
+@item
+@tab @samp{%:from}, @samp{%:fromname}, @samp{%:fromaddress}
+@item
+@tab @samp{%:to}, @samp{%:toname}, @samp{%:toaddress}
+@item
+@tab @samp{%:date} (message date header field)
+@item
+@tab @samp{%:date-timestamp} (date as active timestamp)
+@item
+@tab @samp{%:date-timestamp-inactive} (date as inactive timestamp)
+@item
+@tab @samp{%:fromto} (either ``to NAME'' or ``from NAME'')@footnote{This is 
always the other, not the user.  See the variable
+@code{org-link-from-user-regexp}.}
+@item gnus
+@tab @samp{%:group}, for messages also all email fields
+@item w3, w3m
+@tab @samp{%:url}
+@item info
+@tab @samp{%:file}, @samp{%:node}
+@item calendar
+@tab @samp{%:date}
+@item org-protocol
+@tab @samp{%:link}, @samp{%:description}, @samp{%:annotation}
+@end multitable
 
-@smalllisp
-@group
-(setq org-feed-alist
-     '(("Slashdot"
-         "http://rss.slashdot.org/Slashdot/slashdot";
-         "~/txt/org/feeds.org" "Slashdot Entries")))
-@end group
-@end smalllisp
+@node Templates in contexts
+@subsubsection Templates in contexts
 
-@noindent
-will configure that new items from the feed provided by
-@code{rss.slashdot.org} will result in new entries in the file
-@file{~/org/feeds.org} under the heading @samp{Slashdot Entries}, whenever
-the following command is used:
-
-@table @kbd
-@orgcmd{C-c C-x g,org-feed-update-all}
-@item C-c C-x g
-Collect items from the feeds configured in @code{org-feed-alist} and act upon
-them.
-@orgcmd{C-c C-x G,org-feed-goto-inbox}
-Prompt for a feed name and go to the inbox configured for this feed.
-@end table
+@vindex org-capture-templates-contexts
+To control whether a capture template should be accessible from
+a specific context, you can customize
+@code{org-capture-templates-contexts}.  Let's say, for example, that you
+have a capture template ``p'' for storing Gnus emails containing
+patches.  Then you would configure this option like this:
 
-Under the same headline, Org will create a drawer @samp{FEEDSTATUS} in which
-it will store information about the status of items in the feed, to avoid
-adding the same item several times.
+@lisp
+(setq org-capture-templates-contexts
+      '(("p" (in-mode . "message-mode"))))
+@end lisp
 
-For more information, including how to read atom feeds, see
-@file{org-feed.el} and the docstring of @code{org-feed-alist}.
+You can also tell that the command key @kbd{p} should refer to
+another template.  In that case, add this command key like this:
 
-@node Protocols
-@section Protocols for external access
-@cindex protocols, for external access
+@lisp
+(setq org-capture-templates-contexts
+      '(("p" "q" (in-mode . "message-mode"))))
+@end lisp
 
-Org protocol is a mean to trigger custom actions in Emacs from external
-applications.  Any application that supports calling external programs with
-an URL as argument may be used with this functionality.  For example, you can
-configure bookmarks in your web browser to send a link to the current page to
-Org and create a note from it using capture (@pxref{Capture}).  You can also
-create a bookmark that tells Emacs to open the local source file of a remote
-website you are browsing.
+See the docstring of the variable for more information.
 
-@cindex Org protocol, set-up
-@cindex Installing Org protocol
-In order to use Org protocol from an application, you need to register
-@samp{org-protocol://} as a valid scheme-handler.  External calls are passed
-to Emacs through the @code{emacsclient} command, so you also need to ensure
-an Emacs server is running.  More precisely, when the application calls
+@node Attachments
+@section Attachments
 
-@example
-emacsclient org-protocol://PROTOCOL?key1=val1&key2=val2
-@end example
+@cindex attachments
 
-@noindent
-Emacs calls the handler associated to @samp{PROTOCOL} with argument
-@samp{(:key1 val1 :key2 val2)}.
+It is often useful to associate reference material with an outline
+node.  Small chunks of plain text can simply be stored in the subtree
+of a project.  Hyperlinks (see @ref{Hyperlinks}) can establish associations
+with files that live elsewhere on your computer or in the cloud, like
+emails or source code files belonging to a project.
 
-@cindex protocol, new protocol
-@cindex defining new protocols
-Org protocol comes with three predefined protocols, detailed in the following
-sections.  Configure @code{org-protocol-protocol-alist} to define your own.
+Another method is @emph{attachments}, which are files located in a
+directory belonging to an outline node.  Org uses directories either
+named by a unique ID of each entry, or by a @samp{DIR} property.
 
 @menu
-* @code{store-link} protocol::  Store a link, push URL to kill-ring.
-* @code{capture} protocol::     Fill a buffer with external information.
-* @code{open-source} protocol::  Edit published contents.
+* Attachment defaults and dispatcher:: How to access attachment commands
+* Attachment options::           Configuring the attachment system
+* Attachment links::             Hyperlink access to attachments
+* Automatic version-control with Git:: Everything safely stored away
+* Attach from Dired::            Using dired to select an attachment
 @end menu
 
-@node @code{store-link} protocol
-@subsection @code{store-link} protocol
-@cindex store-link protocol
-@cindex protocol, store-link
-
-Using @code{store-link} handler, you can copy links, insertable through
-@kbd{M-x org-insert-link} or yanking thereafter.  More precisely, the command
+@node Attachment defaults and dispatcher
+@subsection Attachment defaults and dispatcher
 
-@example
-emacsclient org-protocol://store-link?url=URL&title=TITLE
-@end example
+By default, org-attach will use ID properties when adding attachments
+to outline nodes.  This makes working with attachments fully
+automated.  There is no decision needed for folder-name or location.
+ID-based directories are by default located in the @samp{data/} directory,
+which lives in the same directory where your Org file lives@footnote{If you 
move entries or Org files from one directory to
+another, you may want to configure @code{org-attach-id-dir} to contain
+an absolute path.}.
+For more control over the setup, see @ref{Attachment options}.
 
-@noindent
-stores the following link:
+When attachments are made using @code{org-attach} a default tag @samp{ATTACH} 
is
+added to the node that gets the attachments.
 
-@example
-[[URL][TITLE]]
-@end example
+The following commands deal with attachments:
 
-In addition, @samp{URL} is pushed on the kill-ring for yanking.  You need to
-encode @samp{URL} and @samp{TITLE} if they contain slashes, and probably
-quote those for the shell.
+@table @asis
+@item @kbd{C-c C-a} (@code{org-attach})
+@kindex C-c C-a
+@findex org-attach
+The dispatcher for commands related to the attachment system.  After
+these keys, a list of commands is displayed and you must press an
+additional key to select a command:
 
-To use this feature from a browser, add a bookmark with an arbitrary name,
-e.g., @samp{Org: store-link} and enter this as @emph{Location}:
+@table @asis
+@item @kbd{a} (@code{org-attach-attach})
+@kindex C-c C-a a
+@findex org-attach-attach
+@vindex org-attach-method
+Select a file and move it into the task's attachment directory.
+The file is copied, moved, or linked, depending on
+@code{org-attach-method}.  Note that hard links are not supported on
+all systems.
 
-@example
-javascript:location.href='org-protocol://store-link?url='+
-      encodeURIComponent(location.href);
-@end example
+@item @kbd{c}/@kbd{m}/@kbd{l}
+@kindex C-c C-a c
+@kindex C-c C-a m
+@kindex C-c C-a l
+Attach a file using the copy/move/link method.  Note that hard
+links are not supported on all systems.
 
-@node @code{capture} protocol
-@subsection @code{capture} protocol
-@cindex capture protocol
-@cindex protocol, capture
+@item @kbd{b} (@code{org-attach-buffer})
+@kindex C-c C-a b
+@findex org-attach-buffer
+Select a buffer and save it as a file in the task's attachment
+directory.
 
-Activating @code{capture} handler pops up a @samp{Capture} buffer and fills
-the capture template associated to the @samp{X} key with them.
+@item @kbd{n} (@code{org-attach-new})
+@kindex C-c C-a n
+@findex org-attach-new
+Create a new attachment as an Emacs buffer.
 
-@example
-emacsclient org-protocol://capture?template=X?url=URL?title=TITLE?body=BODY
-@end example
+@item @kbd{z} (@code{org-attach-sync})
+@kindex C-c C-a z
+@findex org-attach-sync
+Synchronize the current task with its attachment directory, in
+case you added attachments yourself.
 
-To use this feature, add a bookmark with an arbitrary name, e.g.  @samp{Org:
-capture} and enter this as @samp{Location}:
+@item @kbd{o} (@code{org-attach-open})
+@kindex C-c C-a o
+@findex org-attach-open
+@vindex org-file-apps
+Open current task's attachment.  If there is more than one, prompt
+for a file name first.  Opening follows the rules set by
+@code{org-file-apps}.  For more details, see the information on
+following hyperlinks (see @ref{Handling Links}).
+
+@item @kbd{O} (@code{org-attach-open-in-emacs})
+@kindex C-c C-a O
+@findex org-attach-open-in-emacs
+Also open the attachment, but force opening the file in Emacs.
 
-@example
-javascript:location.href='org-protocol://template=x'+
-      '&url='+encodeURIComponent(window.location.href)+
-      '&title='+encodeURIComponent(document.title)+
-      '&body='+encodeURIComponent(window.getSelection());
-@end example
+@item @kbd{f} (@code{org-attach-reveal})
+@kindex C-c C-a f
+@findex org-attach-reveal
+Open the current task's attachment directory.
 
-@vindex org-protocol-default-template-key
-The result depends on the capture template used, which is set in the bookmark
-itself, as in the example above, or in
-@code{org-protocol-default-template-key}.
+@item @kbd{F} (@code{org-attach-reveal-in-emacs})
+@kindex C-c C-a F
+@findex org-attach-reveal-in-emacs
+Also open the directory, but force using Dired in Emacs.
 
-@cindex capture, %:link placeholder
-@cindex %:link template expansion in capture
-@cindex capture, %:description placeholder
-@cindex %:description template expansion in capture
-@cindex capture, %:annotation placeholder
-@cindex %:annotation template expansion in capture
-The following template placeholders are available:
+@item @kbd{d} (@code{org-attach-delete-one})
+@kindex C-c C-a d
+Select and delete a single attachment.
 
-@example
-%:link          The URL
-%:description   The webpage title
-%:annotation    Equivalent to [[%:link][%:description]]
-%i              The selected text
-@end example
+@item @kbd{D} (@code{org-attach-delete-all})
+@kindex C-c C-a D
+Delete all of a task's attachments.  A safer way is to open the
+directory in Dired and delete from there.
 
-@node @code{open-source} protocol
-@subsection @code{open-source} protocol
-@cindex open-source protocol
-@cindex protocol, open-source
+@item @kbd{s} (@code{org-attach-set-directory})
+@kindex C-c C-a s
+@cindex @samp{DIR}, property
+Set a specific directory as the entry's attachment directory.
+This works by putting the directory path into the @samp{DIR}
+property.
 
-The @code{open-source} handler is designed to help with editing local sources
-when reading a document.  To that effect, you can use a bookmark with the
-following location:
+@item @kbd{S} (@code{org-attach-unset-directory})
+@kindex C-c C-a S
+@cindex @samp{DIR}, property
+Remove the attachment directory.  This command removes the @samp{DIR}
+property and asks the user to either move content inside that
+folder, if an @samp{ID} property is set, delete the content, or to
+leave the attachment directory as is but no longer attached to the
+outline node.
+@end table
+@end table
 
-@example
-javascript:location.href='org-protocol://open-source?&url='+
-      encodeURIComponent(location.href)
-@end example
+@node Attachment options
+@subsection Attachment options
 
-@cindex protocol, open-source, @code{:base-url} property
-@cindex @code{:base-url} property in open-source protocol
-@cindex protocol, open-source, @code{:working-directory} property
-@cindex @code{:working-directory} property in open-source protocol
-@cindex protocol, open-source, @code{:online-suffix} property
-@cindex @code{:online-suffix} property in open-source protocol
-@cindex protocol, open-source, @code{:working-suffix} property
-@cindex @code{:working-suffix} property in open-source protocol
-@vindex org-protocol-project-alist
-The variable @code{org-protocol-project-alist} maps URLs to local file names,
-by stripping URL parameters from the end and replacing the @code{:base-url}
-with @code{:working-directory} and @code{:online-suffix} with
-@code{:working-suffix}.  For example, assuming you own a local copy of
-@url{https://orgmode.org/worg/} contents at @file{/home/user/worg}, you can
-set @code{org-protocol-project-alist} to the following
+There are a couple of options for attachments that are worth
+mentioning.
 
-@lisp
-(setq org-protocol-project-alist
-      '(("Worg"
-        :base-url "https://orgmode.org/worg/";
-        :working-directory "/home/user/worg/"
-        :online-suffix ".html"
-        :working-suffix ".org")))
-@end lisp
+@table @asis
+@item @code{org-attach-id-dir}
+@vindex org-attach-id-dir
+The directory where attachments are stored when @samp{ID} is used as
+method.
+
+@item @code{org-attach-dir-relative}
+@vindex org-attach-dir-relative
+When setting the @samp{DIR} property on a node using @kbd{C-c C-a s}
+(@code{org-attach-set-directory}), absolute links are entered by default.
+This option changes that to relative links.
+
+@item @code{org-attach-use-inheritance}
+@vindex org-attach-use-inheritance
+By default folders attached to an outline node are inherited from
+parents according to @code{org-use-property-inheritance}.  If one instead
+want to set inheritance specifically for org-attach that can be done
+using @code{org-attach-use-inheritance}.  Inheriting documents through
+the node hierarchy makes a lot of sense in most cases. Especially
+since the introduction of @ref{Attachment links}.  The following example
+shows one use case for attachment inheritance:
+
+@example
+* Chapter A ...
+  :PROPERTIES:
+  :DIR: Chapter A/
+  :END:
+** Introduction
+Some text
 
-@noindent
-If you are now browsing
-@url{https://orgmode.org/worg/org-contrib/org-protocol.html} and find a typo
-or have an idea about how to enhance the documentation, simply click the
-bookmark and start editing.
+#+NAME: Image 1
+[[Attachment:image 1.jpg]]
+@end example
 
-@cindex handle rewritten URL in open-source protocol
-@cindex protocol, open-source rewritten URL
-However, such mapping may not yield the desired results.  Suppose you
-maintain an online store located at @url{http://example.com/}.  The local
-sources reside in @file{/home/user/example/}.  It is common practice to serve
-all products in such a store through one file and rewrite URLs that do not
-match an existing file on the server.  That way, a request to
-@url{http://example.com/print/posters.html} might be rewritten on the server
-to something like
-@url{http://example.com/shop/products.php/posters.html.php}.  The
-@code{open-source} handler probably cannot find a file named
-@file{/home/user/example/print/posters.html.php} and fails.
+Without inheritance one would not be able to resolve the link to
+image @samp{1.jpg}, since the link is inside a sub-heading to @samp{Chapter
+  A}.
 
-@cindex protocol, open-source, @code{:rewrites} property
-@cindex @code{:rewrites property} in open-source protocol
-Such an entry in @code{org-protocol-project-alist} may hold an additional
-property @code{:rewrites}.  This property is a list of cons cells, each of
-which maps a regular expression to a path relative to the
-@code{:working-directory}.
+Inheritance works the same way for both @samp{ID} and @samp{DIR} property.  If
+both properties are defined on the same headline then @samp{DIR} takes
+precedance.  This is also true if inheritance is enabled.  If @samp{DIR}
+is inherited from a parent node in the outline, that property still
+takes precedence over an @samp{ID} property defined on the node itself.
 
-Now map the URL to the path @file{/home/user/example/products.php} by adding
-@code{:rewrites} rules like this:
+@item @code{org-attach-method}
+@vindex org-attach-method
+When attaching files using the dispatcher @kbd{C-c C-a} it
+defaults to copying files.  The behaviour can be changed by
+customizing @code{org-attach-method}.  Options are Copy, Move/Rename,
+Hard link or Symbolic link.
+
+@item @code{org-attach-preferred-new-method}
+@vindex org-attach-preferred-new-method
+This customization lets you choose the default way to attach to
+nodes without existing @samp{ID} and @samp{DIR} property.  It defaults to 
@code{id}
+but can also be set to @code{dir}, @code{ask} or @code{nil}.
+
+@item @code{org-attach-archive-delete}
+@vindex org-attach-archive-delete
+Configure this to determine if attachments should be deleted or not
+when a subtree that has attachments is archived.
+
+@item @code{org-attach-auto-tag}
+@vindex org-attach-auto-tag
+When attaching files to a heading it will be assigned a tag
+according to what is set here.
+
+@item @code{org-attach-id-to-path-function-list}
+@vindex org-attach-id-to-path-function-list
+When @samp{ID} is used for attachments, the ID is parsed into a part of a
+directory-path.  See @code{org-attach-id-uuid-folder-format} for the
+default function.  Define a new one and add it as first element in
+@code{org-attach-id-to-path-function-list} if you want the folder
+structure in any other way.  All functions in this list will be
+tried when resolving existing ID's into paths, to maintain backward
+compatibility with existing folders in your system.
+
+@item @code{org-attach-expert}
+@vindex org-attach-expert
+Do not show the splash buffer with the attach dispatcher when
+@code{org-attach-expert} is set to non-@code{nil}.
+@end table
 
-@lisp
-(setq org-protocol-project-alist
-      '(("example.com"
-         :base-url "http://example.com/";
-         :working-directory "/home/user/example/"
-         :online-suffix ".php"
-         :working-suffix ".php"
-         :rewrites (("example.com/print/" . "products.php")
-                    ("example.com/$" . "index.php")))))
-@end lisp
+See customization group @samp{Org Attach} if you want to change the
+default settings.
 
-@noindent
-Since @samp{example.com/$} is used as a regular expression, it maps
-@url{http://example.com/}, @url{https://example.com},
-@url{http://www.example.com/} and similar to
-@file{/home/user/example/index.php}.
+@node Attachment links
+@subsection Attachment links
 
-The @code{:rewrites} rules are searched as a last resort if and only if no
-existing file name is matched.
+Attached files and folders can be referenced using attachment links.
+This makes it easy to refer to the material added to an outline node.
+Especially if it was attached using the unique ID of the entry!
 
-@cindex protocol, open-source, set-up mapping
-@cindex set-up mappings in open-source protocol
-@findex org-protocol-create
-@findex org-protocol-create-for-org
-Two functions can help you filling @code{org-protocol-project-alist} with
-valid contents: @code{org-protocol-create} and
-@code{org-protocol-create-for-org}.  The latter is of use if you're editing
-an Org file that is part of a publishing project.
+@example
+* TODO Some task
+  :PROPERTIES:
+  :ID:       95d50008-c12e-479f-a4f2-cc0238205319
+  :END:
+See attached document for more information: [[attachment:info.org]]
+@end example
 
-@node Refile and copy
-@section Refile and copy
-@cindex refiling notes
-@cindex copying notes
+See @ref{External Links} for more information about these links.
 
-When reviewing the captured data, you may want to refile or to copy some of
-the entries into a different list, for example into a project.  Cutting,
-finding the right location, and then pasting the note is cumbersome.  To
-simplify this process, you can use the following special command:
+@node Automatic version-control with Git
+@subsection Automatic version-control with Git
 
-@table @kbd
-@orgcmd{C-c M-w,org-copy}
-@findex org-copy
-Copying works like refiling, except that the original note is not deleted.
-@orgcmd{C-c C-w,org-refile}
-@findex org-refile
-@vindex org-reverse-note-order
-@vindex org-refile-targets
-@vindex org-refile-use-outline-path
-@vindex org-outline-path-complete-in-steps
-@vindex org-refile-allow-creating-parent-nodes
-@vindex org-log-refile
-@vindex org-refile-use-cache
-@vindex org-refile-keep
-Refile the entry or region at point.  This command offers possible locations
-for refiling the entry and lets you select one with completion.  The item (or
-all items in the region) is filed below the target heading as a subitem.
-Depending on @code{org-reverse-note-order}, it will be either the first or
-last subitem.@*
-By default, all level 1 headlines in the current buffer are considered to be
-targets, but you can have more complex definitions across a number of files.
-See the variable @code{org-refile-targets} for details.  If you would like to
-select a location via a file-path-like completion along the outline path, see
-the variables @code{org-refile-use-outline-path} and
-@code{org-outline-path-complete-in-steps}.  If you would like to be able to
-create new nodes as new parents for refiling on the fly, check the
-variable @code{org-refile-allow-creating-parent-nodes}.
-When the variable @code{org-log-refile}@footnote{with corresponding
-@code{#+STARTUP} keywords @code{logrefile}, @code{lognoterefile},
-and @code{nologrefile}} is set, a timestamp or a note will be
-recorded when an entry has been refiled.
-@orgkey{C-u C-c C-w}
-Use the refile interface to jump to a heading.
-@orgcmd{C-u C-u C-c C-w,org-refile-goto-last-stored}
-Jump to the location where @code{org-refile} last moved a tree to.
-@item C-2 C-c C-w
-Refile as the child of the item currently being clocked.
-@item C-3 C-c C-w
-Refile and keep the entry in place.  Also see @code{org-refile-keep} to make
-this the default behavior, and beware that this may result in duplicated
-@code{ID} properties.
-@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 see new possible
-targets, you have to clear the cache with this command.
-@end table
+If the directory attached to an outline node is a Git repository, Org
+can be configured to automatically commit changes to that repository
+when it sees them.
 
-@node Archiving
-@section Archiving
-@cindex archiving
+To make Org mode take care of versioning of attachments for you, add
+the following to your Emacs config:
 
-When a project represented by a (sub)tree is finished, you may want
-to move the tree out of the way and to stop it from contributing to the
-agenda.  Archiving is important to keep your working files compact and global
-searches like the construction of agenda views fast.
+@lisp
+(require 'org-attach-git)
+@end lisp
 
-@table @kbd
-@orgcmd{C-c C-x C-a,org-archive-subtree-default}
-@vindex org-archive-default-command
-Archive the current entry using the command specified in the variable
-@code{org-archive-default-command}.
-@end table
+@node Attach from Dired
+@subsection Attach from Dired
 
-@menu
-* Moving subtrees::             Moving a tree to an archive file
-* Internal archiving::          Switch off a tree but keep it in the file
-@end menu
+@cindex attach from Dired
+@findex org-attach-dired-to-subtree
+It is possible to attach files to a subtree from a Dired buffer.  To
+use this feature, have one window in Dired mode containing the file(s)
+to be attached and another window with point in the subtree that shall
+get the attachments.  In the Dired window, with point on a file,
+@kbd{M-x org-attach-dired-to-subtree} attaches the file to the
+subtree using the attachment method set by variable
+@code{org-attach-method}.  When files are marked in the Dired window then
+all marked files get attached.
 
-@node Moving subtrees
-@subsection Moving a tree to the archive file
-@cindex external archiving
+Add the following lines to the Emacs init file to have @kbd{C-c C-x a} attach 
files in Dired buffers.
 
-The most common archiving action is to move a project tree to another file,
-the archive file.
+@lisp
+(add-hook 'dired-mode-hook
+          (lambda ()
+            (define-key dired-mode-map
+              (kbd "C-c C-x a")
+              #'org-attach-dired-to-subtree)))
+@end lisp
 
-@table @kbd
-@orgcmdkskc{C-c C-x C-s,C-c $,org-archive-subtree}
-@vindex org-archive-location
-Archive the subtree starting at the cursor position to the location
-given by @code{org-archive-location}.
-@orgkey{C-u C-c C-x C-s}
-Check if any direct children of the current headline could be moved to
-the archive.  To do this, each subtree is checked for open TODO entries.
-If none are found, the command offers to move it to the archive
-location.  If the cursor is @emph{not} on a headline when this command
-is invoked, the level 1 trees will be checked.
-@orgkey{C-u C-u C-c C-x C-s}
-As above, but check subtree for timestamps instead of TODO entries.  The
-command will offer to archive the subtree if it @emph{does} contain a
-timestamp, and that timestamp is in the past.
-@end table
+The following code shows how to bind the previous command with
+a specific attachment method.
 
-@cindex archive locations
-The default archive location is a file in the same directory as the
-current file, with the name derived by appending @file{_archive} to the
-current file name.  You can also choose what heading to file archived
-items under, with the possibility to add them to a datetree in a file.
-For information and examples on how to specify the file and the heading,
-see the documentation string of the variable
-@code{org-archive-location}.
+@lisp
+(add-hook 'dired-mode-hook
+          (lambda ()
+            (define-key dired-mode-map (kbd "C-c C-x c")
+              (lambda ()
+                (interactive)
+                (let ((org-attach-method 'cp))
+                  (call-interactively #'org-attach-dired-to-subtree))))))
+@end lisp
 
-There is also an in-buffer option for setting this variable, for example:
+@node RSS Feeds
+@section RSS Feeds
 
-@cindex @code{#+ARCHIVE}
-@example
-#+ARCHIVE: %s_done::
-@end example
+@cindex RSS feeds
+@cindex Atom feeds
 
-@cindex property, @code{ARCHIVE}
-@noindent
-If you would like to have a special ARCHIVE location for a single entry
-or a (sub)tree, give the entry an @code{:ARCHIVE:} property with the
-location as the value (@pxref{Properties and columns}).
+Org can add and change entries based on information found in RSS feeds
+and Atom feeds.  You could use this to make a task out of each new
+podcast in a podcast feed.  Or you could use a phone-based
+note-creating service on the web to import tasks into Org.  To access
+feeds, configure the variable @code{org-feed-alist}.  The docstring of this
+variable has detailed information.  With the following
 
-@vindex org-archive-save-context-info
-When a subtree is moved, it receives a number of special properties that
-record context information like the file from where the entry came, its
-outline path the archiving time etc.  Configure the variable
-@code{org-archive-save-context-info} to adjust the amount of information
-added.
+@lisp
+(setq org-feed-alist
+      '(("Slashdot"
+         "http://rss.slashdot.org/Slashdot/slashdot";
+         "~/txt/org/feeds.org" "Slashdot Entries")))
+@end lisp
 
+@noindent
+new items from the feed provided by @samp{rss.slashdot.org} result in new
+entries in the file @samp{~/org/feeds.org} under the heading @samp{Slashdot
+Entries}, whenever the following command is used:
 
-@node Internal archiving
-@subsection Internal archiving
+@table @asis
+@item @kbd{C-c C-x g} (@code{org-feed-update-all})
+@kindex C-c C-x g
+Collect items from the feeds configured in @code{org-feed-alist} and act
+upon them.
 
-@cindex archive tag
-If you want to just switch off---for agenda views---certain subtrees without
-moving them to a different file, you can use the archive tag.
+@item @kbd{C-c C-x G} (@code{org-feed-goto-inbox})
+@kindex C-c C-x G
+Prompt for a feed name and go to the inbox configured for this feed.
+@end table
 
-A headline that is marked with the @samp{:ARCHIVE:} tag (@pxref{Tags}) stays
-at its location in the outline tree, but behaves in the following way:
-@itemize @minus
-@item
-@vindex org-cycle-open-archived-trees
-It does not open when you attempt to do so with a visibility cycling
-command (@pxref{Visibility cycling}).  You can force cycling archived
-subtrees with @kbd{C-@key{TAB}}, or by setting the option
-@code{org-cycle-open-archived-trees}.  Also normal outline commands like
-@code{show-all} will open archived subtrees.
-@item
-@vindex org-sparse-tree-open-archived-trees
-During sparse tree construction (@pxref{Sparse trees}), matches in
-archived subtrees are not exposed, unless you configure the option
-@code{org-sparse-tree-open-archived-trees}.
-@item
-@vindex org-agenda-skip-archived-trees
-During agenda view construction (@pxref{Agenda views}), the content of
-archived trees is ignored unless you configure the option
-@code{org-agenda-skip-archived-trees}, in which case these trees will always
-be included.  In the agenda you can press @kbd{v a} to get archives
-temporarily included.
-@item
-@vindex org-export-with-archived-trees
-Archived trees are not exported (@pxref{Exporting}), only the headline
-is.  Configure the details using the variable
-@code{org-export-with-archived-trees}.
-@item
-@vindex org-columns-skip-archived-trees
-Archived trees are excluded from column view unless the variable
-@code{org-columns-skip-archived-trees} is configured to @code{nil}.
-@end itemize
+Under the same headline, Org creates a drawer @samp{FEEDSTATUS} in which it
+stores information about the status of items in the feed, to avoid
+adding the same item several times.
 
-The following commands help manage the ARCHIVE tag:
-
-@table @kbd
-@orgcmd{C-c C-x a,org-toggle-archive-tag}
-Toggle the ARCHIVE tag for the current headline.  When the tag is set,
-the headline changes to a shadowed face, and the subtree below it is
-hidden.
-@orgkey{C-u C-c C-x a}
-Check if any direct children of the current headline should be archived.
-To do this, each subtree is checked for open TODO entries.  If none are
-found, the command offers to set the ARCHIVE tag for the child.  If the
-cursor is @emph{not} on a headline when this command is invoked, the
-level 1 trees will be checked.
-@orgcmd{C-@key{TAB},org-force-cycle-archived}
-Cycle a tree even if it is tagged with ARCHIVE.
-@orgcmd{C-c C-x A,org-archive-to-archive-sibling}
-Move the current entry to the @emph{Archive Sibling}.  This is a sibling of
-the entry with the heading @samp{Archive} and the tag @samp{ARCHIVE}.  The
-entry becomes a child of that sibling and in this way retains a lot of its
-original context, including inherited tags and approximate position in the
-outline.
-@end table
+For more information, including how to read atom feeds, see
+@samp{org-feed.el} and the docstring of @code{org-feed-alist}.
 
+@node Agenda Views
+@chapter Agenda Views
 
-@node Agenda views
-@chapter Agenda views
 @cindex agenda views
 
-Due to the way Org works, TODO items, time-stamped items, and
-tagged headlines can be scattered throughout a file or even a number of
+Due to the way Org works, TODO items, time-stamped items, and tagged
+headlines can be scattered throughout a file or even a number of
 files.  To get an overview of open action items, or of events that are
 important for a particular date, this information must be collected,
 sorted and displayed in an organized way.
 
-Org can select items based on various criteria and display them
-in a separate buffer.  Six different view types are provided:
+Org can select items based on various criteria and display them in
+a separate buffer.  Six different view types are provided:
 
-@itemize @bullet
+@itemize
 @item
-an @emph{agenda} that is like a calendar and shows information
-for specific dates,
+an @emph{agenda} that is like a calendar and shows information for
+specific dates,
+
 @item
-a @emph{TODO list} that covers all unfinished
-action items,
+a @emph{TODO list} that covers all unfinished action items,
+
 @item
-a @emph{match view}, showings headlines based on the tags, properties, and
-TODO state associated with them,
+a @emph{match view}, showings headlines based on the tags, properties,
+and TODO state associated with them,
+
 @item
-a @emph{text search view} that shows all entries from multiple files
-that contain specified keywords,
+a @emph{text search view} that shows all entries from multiple files that
+contain specified keywords,
+
 @item
-a @emph{stuck projects view} showing projects that currently don't move
+a @emph{stuck projects view} showing projects that currently do not move
 along, and
+
 @item
-@emph{custom views} that are special searches and combinations of different
-views.
+@emph{custom views} that are special searches and combinations of
+different views.
 @end itemize
 
-@noindent
-The extracted information is displayed in a special @emph{agenda
-buffer}.  This buffer is read-only, but provides commands to visit the
-corresponding locations in the original Org files, and even to
-edit these files remotely.
+The extracted information is displayed in a special @emph{agenda buffer}.
+This buffer is read-only, but provides commands to visit the
+corresponding locations in the original Org files, and even to edit
+these files remotely.
 
 @vindex org-agenda-skip-comment-trees
 @vindex org-agenda-skip-archived-trees
 @cindex commented entries, in agenda views
 @cindex archived entries, in agenda views
-By default, the report ignores commented (@pxref{Comment lines}) and archived
-(@pxref{Internal archiving}) entries.  You can override this by setting
-@code{org-agenda-skip-comment-trees} and
+By default, the report ignores commented (see @ref{Comment Lines}) and
+archived (see @ref{Internal archiving}) entries.  You can override this by
+setting @code{org-agenda-skip-comment-trees} and
 @code{org-agenda-skip-archived-trees} to @code{nil}.
 
 @vindex org-agenda-window-setup
 @vindex org-agenda-restore-windows-after-quit
-Two variables control how the agenda buffer is displayed and whether the
-window configuration is restored when the agenda exits:
-@code{org-agenda-window-setup} and
-@code{org-agenda-restore-windows-after-quit}.
+Two variables control how the agenda buffer is displayed and whether
+the window configuration is restored when the agenda exits:
+@code{org-agenda-window-setup} and 
@code{org-agenda-restore-windows-after-quit}.
 
 @menu
-* Agenda files::                Files being searched for agenda information
-* Agenda dispatcher::           Keyboard access to agenda views
-* Built-in agenda views::       What is available out of the box?
-* Presentation and sorting::    How agenda items are prepared for display
-* Agenda commands::             Remote editing of Org trees
-* Custom agenda views::         Defining special searches and views
-* Exporting agenda views::      Writing a view to a file
-* Agenda column view::          Using column view for collected entries
+* Agenda Files::                 Files being searched for agenda information.
+* Agenda Dispatcher::            Keyboard access to agenda views.
+* Built-in Agenda Views::        What is available out of the box?
+* Presentation and Sorting::     How agenda items are prepared for display.
+* Agenda Commands::              Remote editing of Org trees.
+* Custom Agenda Views::          Defining special searches and views.
+* Exporting Agenda Views::       Writing a view to a file.
+* Agenda Column View::           Using column view for collected entries.
 @end menu
 
-@node Agenda files
-@section Agenda files
+@node Agenda Files
+@section Agenda Files
+
 @cindex agenda files
 @cindex files for agenda
 
 @vindex org-agenda-files
 The information to be shown is normally collected from all @emph{agenda
-files}, the files listed in the variable
-@code{org-agenda-files}@footnote{If the value of that variable is not a
-list, but a single file name, then the list of agenda files will be
-maintained in that external file.}.  If a directory is part of this list,
-all files with the extension @file{.org} in this directory will be part
-of the list.
+files}, the files listed in the variable @code{org-agenda-files}@footnote{If 
the value of that variable is not a list, but a single file
+name, then the list of agenda files in maintained in that external
+file.}.
+If a directory is part of this list, all files with the extension
+@samp{.org} in this directory are part of the list.
 
 Thus, even if you only work with a single Org file, that file should
-be put into the list@footnote{When using the dispatcher, pressing
-@kbd{<} before selecting a command will actually limit the command to
-the current file, and ignore @code{org-agenda-files} until the next
-dispatcher command.}.  You can customize @code{org-agenda-files}, but
-the easiest way to maintain it is through the following commands
+be put into the list@footnote{When using the dispatcher, pressing @kbd{<} 
before
+selecting a command actually limits the command to the current file,
+and ignores @code{org-agenda-files} until the next dispatcher command.}.  You 
can customize @code{org-agenda-files},
+but the easiest way to maintain it is through the following commands
 
+@table @asis
+@item @kbd{C-c [} (@code{org-agenda-file-to-front})
+@kindex C-c [
+@findex org-agenda-file-to-front
 @cindex files, adding to agenda list
-@table @kbd
-@orgcmd{C-c [,org-agenda-file-to-front}
 Add current file to the list of agenda files.  The file is added to
-the front of the list.  If it was already in the list, it is moved to
-the front.  With a prefix argument, file is added/moved to the end.
-@orgcmd{C-c ],org-remove-file}
+the front of the list.  If it was already in the list, it is moved
+to the front.  With a prefix argument, file is added/moved to the
+end.
+
+@item @kbd{C-c ]} (@code{org-remove-file})
+@kindex C-c ]
+@findex org-remove-file
 Remove current file from the list of agenda files.
+
+@item @kbd{C-'}
+@itemx @kbd{C-,} (@code{org-cycle-agenda-files})
+@kindex C-'
 @kindex C-,
+@findex org-cycle-agenda-files
 @cindex cycling, of agenda files
-@orgcmd{C-',org-cycle-agenda-files}
-@itemx C-,
 Cycle through agenda file list, visiting one file after the other.
-@item M-x org-switchb @key{RET}
-Command to use an @code{iswitchb}-like interface to switch to and between Org
-buffers.
+
+@item @kbd{M-x org-switchb}
+@findex org-switchb
+Command to use an Iswitchb-like interface to switch to and between
+Org buffers.
 @end table
 
 @noindent
-The Org menu contains the current list of files and can be used
-to visit any of them.
+The Org menu contains the current list of files and can be used to
+visit any of them.
 
 If you would like to focus the agenda temporarily on a file not in
-this list, or on just one file in the list, or even on only a subtree in a
-file, then this can be done in different ways.  For a single agenda command,
-you may press @kbd{<} once or several times in the dispatcher
-(@pxref{Agenda dispatcher}).  To restrict the agenda scope for an
-extended period, use the following commands:
-
-@table @kbd
-@orgcmd{C-c C-x <,org-agenda-set-restriction-lock}
-Permanently restrict the agenda to the current subtree.  When with a
-prefix argument, or with the cursor before the first headline in a file,
-the agenda scope is set to the entire file.  This restriction remains in
-effect until removed with @kbd{C-c C-x >}, or by typing either @kbd{<}
-or @kbd{>} in the agenda dispatcher.  If there is a window displaying an
-agenda view, the new restriction takes effect immediately.
-@orgcmd{C-c C-x >,org-agenda-remove-restriction-lock}
-Remove the permanent restriction created by @kbd{C-c C-x <}.
+this list, or on just one file in the list, or even on only a subtree
+in a file, then this can be done in different ways.  For a single
+agenda command, you may press @kbd{<} once or several times in
+the dispatcher (see @ref{Agenda Dispatcher}).  To restrict the agenda
+scope for an extended period, use the following commands:
+
+@table @asis
+@item @kbd{C-c C-x <} (@code{org-agenda-set-restriction-lock})
+@kindex C-c C-x <
+@findex org-agenda-set-restriction-lock
+Restrict the agenda to the current subtree.  If there already is
+a restriction at point, remove it.  When called with a universal
+prefix argument or with point before the first headline in a file,
+set the agenda scope to the entire file.  This restriction remains
+in effect until removed with @kbd{C-c C-x >}, or by typing
+either @kbd{<} or @kbd{>} in the agenda dispatcher.  If
+there is a window displaying an agenda view, the new restriction
+takes effect immediately.
+
+@item @kbd{C-c C-x >} (@code{org-agenda-remove-restriction-lock})
+@kindex C-c C-x >
+@findex org-agenda-remove-restriction-lock
+Remove the restriction created by @kbd{C-c C-x <}.
 @end table
 
-@noindent
-When working with @file{speedbar.el}, you can use the following commands in
-the Speedbar frame:
-
-@table @kbd
-@orgcmdtkc{< @r{in the speedbar frame},<,org-speedbar-set-agenda-restriction}
-Permanently restrict the agenda to the item---either an Org file or a subtree
-in such a file---at the cursor in the Speedbar frame.
-If there is a window displaying an agenda view, the new restriction takes
-effect immediately.
-@orgcmdtkc{> @r{in the speedbar frame},>,org-agenda-remove-restriction-lock}
-Lift the restriction.
+When working with Speedbar, you can use the following commands in the
+Speedbar frame:
+
+@table @asis
+@item @kbd{<} (@code{org-speedbar-set-agenda-restriction})
+@findex org-speedbar-set-agenda-restriction
+Restrict the agenda to the item---either an Org file or a subtree in
+such a file---at point in the Speedbar frame.  If agenda is already
+restricted there, remove the restriction.  If there is a window
+displaying an agenda view, the new restriction takes effect
+immediately.
+
+@item @kbd{>} (@code{org-agenda-remove-restriction-lock})
+@findex org-agenda-remove-restriction-lock
+Remove the restriction.
 @end table
 
-@node Agenda dispatcher
-@section The agenda dispatcher
+@node Agenda Dispatcher
+@section The Agenda Dispatcher
+
 @cindex agenda dispatcher
 @cindex dispatching agenda commands
-The views are created through a dispatcher, which should be bound to a
-global key---for example @kbd{C-c a} (@pxref{Activation}).  In the
-following we will assume that @kbd{C-c a} is indeed how the dispatcher
-is accessed and list keyboard access to commands accordingly.  After
-pressing @kbd{C-c a}, an additional letter is required to execute a
-command.  The dispatcher offers the following default commands:
-
-@table @kbd
-@item a
-Create the calendar-like agenda (@pxref{Weekly/daily agenda}).
-@item t @r{/} T
-Create a list of all TODO items (@pxref{Global TODO list}).
-@item m @r{/} M
-Create a list of headlines matching a TAGS expression (@pxref{Matching
-tags and properties}).
-@item s
-Create a list of entries selected by a boolean expression of keywords
-and/or regular expressions that must or must not occur in the entry.
-@item /
-@vindex org-agenda-text-search-extra-files
-Search for a regular expression in all agenda files and additionally in
-the files listed in @code{org-agenda-text-search-extra-files}.  This
-uses the Emacs command @code{multi-occur}.  A prefix argument can be
-used to specify the number of context lines for each match, default is
-1.
-@item # @r{/} !
-Create a list of stuck projects (@pxref{Stuck projects}).
-@item <
-Restrict an agenda command to the current buffer@footnote{For backward
-compatibility, you can also press @kbd{1} to restrict to the current
-buffer.}.  After pressing @kbd{<}, you still need to press the character
-selecting the command.
-@item < <
-If there is an active region, restrict the following agenda command to
-the region.  Otherwise, restrict it to the current subtree@footnote{For
-backward compatibility, you can also press @kbd{0} to restrict to the
-current region/subtree.}.  After pressing @kbd{< <}, you still need to press 
the
-character selecting the command.
-
-@item *
-@cindex agenda, sticky
+
+The views are created through a dispatcher, accessible with @kbd{M-x 
org-agenda}, or, better, bound to a global key (see @ref{Activation}).
+It displays a menu from which an additional letter is required to
+execute a command.  The dispatcher offers the following default
+commands:
+
+@table @asis
+@item @kbd{a}
+Create the calendar-like agenda (see @ref{Weekly/daily agenda}).
+
+@item @kbd{t}
+@itemx @kbd{T}
+Create a list of all TODO items (see @ref{Global TODO list}).
+
+@item @kbd{m}
+@itemx @kbd{M}
+Create a list of headlines matching a given expression (see
+@ref{Matching tags and properties}).
+
+@item @kbd{s}
+@kindex s @r{(Agenda dispatcher)}
+Create a list of entries selected by a boolean expression of
+keywords and/or regular expressions that must or must not occur in
+the entry.
+
+@item @kbd{/}
+@kindex / @r{(Agenda dispatcher)}
+@vindex org-agenda-text-search-extra-files
+Search for a regular expression in all agenda files and additionally
+in the files listed in @code{org-agenda-text-search-extra-files}.  This
+uses the Emacs command @code{multi-occur}.  A prefix argument can be used
+to specify the number of context lines for each match, default is
+@enumerate
+@item
+@end enumerate
+
+@item @kbd{#}
+@itemx @kbd{!}
+Create a list of stuck projects (see @ref{Stuck projects}).
+
+@item @kbd{<}
+@kindex < @r{(Agenda dispatcher)}
+Restrict an agenda command to the current buffer@footnote{For backward 
compatibility, you can also press @kbd{1} to
+restrict to the current buffer.}.  If
+narrowing is in effect restrict to the narrowed part of the buffer.
+After pressing @kbd{<}, you still need to press the character
+selecting the command.
+
+@item @kbd{< <}
+@kindex < < @r{(Agenda dispatcher)}
+If there is an active region, restrict the following agenda command
+to the region.  Otherwise, restrict it to the current
+subtree@footnote{For backward compatibility, you can also press @kbd{0} to
+restrict to the current region/subtree.}.  After pressing @kbd{< <}, you still 
need to
+press the character selecting the command.
+
+@item @kbd{*}
+@kindex * @r{(Agenda dispatcher)}
 @vindex org-agenda-sticky
-Toggle sticky agenda views.  By default, Org maintains only a single agenda
-buffer and rebuilds it each time you change the view, to make sure everything
-is always up to date.  If you often switch between agenda views and the build
-time bothers you, you can turn on sticky agenda buffers or make this the
-default by customizing the variable @code{org-agenda-sticky}.  With sticky
-agendas, the agenda dispatcher will not recreate agenda views from scratch,
-it will only switch to the selected one, and you need to update the agenda by
-hand with @kbd{r} or @kbd{g} when needed.  You can toggle sticky agenda view
-any time with @code{org-toggle-sticky-agenda}.
+@findex org-toggle-sticky-agenda
+Toggle sticky agenda views.  By default, Org maintains only a single
+agenda buffer and rebuilds it each time you change the view, to make
+sure everything is always up to date.  If you switch between views
+often and the build time bothers you, you can turn on sticky agenda
+buffers (make this the default by customizing the variable
+@code{org-agenda-sticky}).  With sticky agendas, the dispatcher only
+switches to the selected view, you need to update it by hand with
+@kbd{r} or @kbd{g}.  You can toggle sticky agenda view any
+time with @code{org-toggle-sticky-agenda}.
 @end table
 
-You can also define custom commands that will be accessible through the
+You can also define custom commands that are accessible through the
 dispatcher, just like the default commands.  This includes the
 possibility to create extended agenda buffers that contain several
-blocks together, for example the weekly agenda, the global TODO list and
-a number of special tags matches.  @xref{Custom agenda views}.
+blocks together, for example the weekly agenda, the global TODO list
+and a number of special tags matches.  See @ref{Custom Agenda Views}.
 
-@node Built-in agenda views
-@section The built-in agenda views
+@node Built-in Agenda Views
+@section The Built-in Agenda Views
 
 In this section we describe the built-in views.
 
 @menu
-* Weekly/daily agenda::         The calendar page with current tasks
-* Global TODO list::            All unfinished action items
-* Matching tags and properties::  Structured information with fine-tuned search
-* Search view::                 Find entries by searching for text
-* Stuck projects::              Find projects you need to review
+* Weekly/daily agenda::          The calendar page with current tasks.
+* Global TODO list::             All unfinished action items.
+* Matching tags and properties:: Structured information with fine-tuned search.
+* Search view::                  Find entries by searching for text.
+* Stuck projects::               Find projects you need to review.
 @end menu
 
 @node Weekly/daily agenda
-@subsection The weekly/daily agenda
+@subsection Weekly/daily agenda
+
 @cindex agenda
 @cindex weekly agenda
 @cindex daily agenda
 
-The purpose of the weekly/daily @emph{agenda} is to act like a page of a
-paper agenda, showing all the tasks for the current week or day.
-
-@table @kbd
-@cindex @code{org-agenda}, command
-@orgcmd{C-c a a,org-agenda-list}
-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.
+The purpose of the weekly/daily @emph{agenda} is to act like a page of
+a paper agenda, showing all the tasks for the current week or day.
+
+@table @asis
+@item @kbd{M-x org-agenda a} (@code{org-agenda-list})
+@kindex a @r{(Agenda dispatcher)}
+@findex org-agenda-list
+@cindex org-agenda, command
+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
+argument@footnote{For backward compatibility, the universal prefix argument
+@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 (see @ref{Block agenda}).}---like @kbd{C-u 2 1 M-x org-agenda 
a}---you may
+set the number of days to be displayed.
 @end table
 
 @vindex org-agenda-span
-@vindex org-agenda-ndays
 @vindex org-agenda-start-day
 @vindex org-agenda-start-on-weekday
-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 as @code{day}, @code{week}, @code{month} or
-@code{year}.  For weekly agendas, the default is to start on the previous
-monday (see @code{org-agenda-start-on-weekday}).  You can also set the start
-date using a date shift: @code{(setq org-agenda-start-day "+10d")} will
-start the agenda ten days from today in the future.
+The default number of days displayed in the agenda is set by the
+variable @code{org-agenda-span}.  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}.  For weekly agendas, 
the default
+is to start on the previous Monday (see
+@code{org-agenda-start-on-weekday}).  You can also set the start date using
+a date shift: @samp{(setq org-agenda-start-day "+10d")} starts the agenda
+ten days from today in the future.
 
 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
-commands}.
+The commands available in the Agenda buffer are listed in @ref{Agenda 
Commands}.
 
+@anchor{Calendar/Diary integration}
 @subsubheading Calendar/Diary integration
+
 @cindex calendar integration
 @cindex diary integration
 
-Emacs contains the calendar and diary by Edward M. Reingold.  The
+Emacs contains the calendar and diary by Edward@tie{}M@.@tie{}Reingold.  The
 calendar displays a three-month calendar with holidays from different
 countries and cultures.  The diary allows you to keep track of
 anniversaries, lunar phases, sunrise/set, recurrent appointments
 (weekly, monthly) and more.  In this way, it is quite complementary to
-Org.  It can be very useful to combine output from Org with
-the diary.
+Org.  It can be very useful to combine output from Org with the diary.
 
 In order to include entries from the Emacs diary into Org mode's
 agenda, you only need to customize the variable
@@ -8188,25 +9119,28 @@ agenda, you only need to customize the variable
 (setq org-agenda-include-diary t)
 @end lisp
 
-@noindent After that, everything will happen automatically.  All diary
-entries including holidays, anniversaries, etc., will be included in the
-agenda buffer created by Org mode.  @key{SPC}, @key{TAB}, and
-@key{RET} can be used from the agenda buffer to jump to the diary
-file in order to edit existing diary entries.  The @kbd{i} command to
-insert new entries for the current date works in the agenda buffer, as
-well as the commands @kbd{S}, @kbd{M}, and @kbd{C} to display
-Sunrise/Sunset times, show lunar phases and to convert to other
-calendars, respectively.  @kbd{c} can be used to switch back and forth
-between calendar and agenda.
-
-If you are using the diary only for sexp entries and holidays, it is
-faster to not use the above setting, but instead to copy or even move
-the entries into an Org file.  Org mode evaluates diary-style sexp
-entries, and does it faster because there is no overhead for first
-creating the diary display.  Note that the sexp entries must start at
-the left margin, no whitespace is allowed before them.  For example,
-the following segment of an Org file will be processed and entries
-will be made in the agenda:
+@noindent
+After that, everything happens automatically.  All diary entries
+including holidays, anniversaries, etc., are included in the agenda
+buffer created by Org mode.  @kbd{@key{SPC}}, @kbd{@key{TAB}}, and
+@kbd{@key{RET}} can be used from the agenda buffer to jump to the diary
+file in order to edit existing diary entries.  The @kbd{i}
+command to insert new entries for the current date works in the agenda
+buffer, as well as the commands @kbd{S}, @kbd{M}, and
+@kbd{C} to display Sunrise/Sunset times, show lunar phases and to
+convert to other calendars, respectively.  @kbd{c} can be used to
+switch back and forth between calendar and agenda.
+
+If you are using the diary only for expression entries and holidays,
+it is faster to not use the above setting, but instead to copy or even
+move the entries into an Org file.  Org mode evaluates diary-style
+expression entries, and does it faster because there is no overhead
+for first creating the diary display.  Note that the expression
+entries must start at the left margin, no whitespace is allowed before
+them, as seen in the following segment of an Org file:@footnote{The variable 
@code{org-anniversary} used in the example is just
+like @code{diary-anniversary}, but the argument order is always according
+to ISO and therefore independent of the value of
+@code{calendar-date-style}.}
 
 @example
 * Holidays
@@ -8219,19 +9153,22 @@ will be made in the agenda:
   :PROPERTIES:
   :CATEGORY: Ann
   :END:
-%%(org-anniversary 1956  5 14)@footnote{@code{org-anniversary} is just like 
@code{diary-anniversary}, but the argument order is always according to ISO and 
therefore independent of the value of @code{calendar-date-style}.} Arthur Dent 
is %d years old
+%%(org-anniversary 1956  5 14) Arthur Dent is %d years old
 %%(org-anniversary 1869 10  2) Mahatma Gandhi would be %d years old
 @end example
 
+@anchor{Anniversaries from BBDB}
 @subsubheading Anniversaries from BBDB
+
 @cindex BBDB, anniversaries
 @cindex anniversaries, from BBDB
 
-If you are using the Big Brothers Database to store your contacts, you will
-very likely prefer to store anniversaries in BBDB rather than in a
-separate Org or diary file.  Org supports this and will show BBDB
-anniversaries as part of the agenda.  All you need to do is to add the
-following to one of your agenda files:
+@findex org-bbdb-anniversaries
+If you are using the Insidious Big Brother Database to store your
+contacts, you very likely prefer to store anniversaries in BBDB rather
+than in a separate Org or diary file.  Org supports this and can show
+BBDB anniversaries as part of the agenda.  All you need to do is to
+add the following to one of your agenda files:
 
 @example
 * Anniversaries
@@ -8241,29 +9178,30 @@ following to one of your agenda files:
 %%(org-bbdb-anniversaries)
 @end example
 
-You can then go ahead and define anniversaries for a BBDB record.  Basically,
-you need to press @kbd{C-o anniversary @key{RET}} with the cursor in a BBDB
-record and then add the date in the format @code{YYYY-MM-DD} or @code{MM-DD},
-followed by a space and the class of the anniversary (@samp{birthday} or
-@samp{wedding}, or a format string).  If you omit the class, it will default to
+You can then go ahead and define anniversaries for a BBDB record.
+Basically, you need a field named @samp{anniversary} for the BBDB record
+which contains the date in the format @samp{YYYY-MM-DD} or @samp{MM-DD},
+followed by a space and the class of the anniversary (@samp{birthday},
+@samp{wedding}, or a format string).  If you omit the class, it defaults to
 @samp{birthday}.  Here are a few examples, the header for the file
-@file{org-bbdb.el} contains more detailed information.
+@samp{ol-bbdb.el} contains more detailed information.
 
 @example
 1973-06-22
 06-22
 1955-08-02 wedding
-2008-04-14 %s released version 6.01 of org mode, %d years ago
+2008-04-14 %s released version 6.01 of Org mode, %d years ago
 @end example
 
-After a change to BBDB, or for the first agenda display during an Emacs
-session, the agenda display will suffer a short delay as Org updates its
-hash with anniversaries.  However, from then on things will be very fast---much
-faster in fact than a long list of @samp{%%(diary-anniversary)} entries
-in an Org or Diary file.
+After a change to BBDB, or for the first agenda display during an
+Emacs session, the agenda display suffers a short delay as Org updates
+its hash with anniversaries.  However, from then on things will be
+very fast, much faster in fact than a long list of
+@samp{%%(diary-anniversary)} entries in an Org or Diary file.
 
-If you would like to see upcoming anniversaries with a bit of forewarning,
-you can use the following instead:
+@findex org-bbdb-anniversaries-future
+If you would like to see upcoming anniversaries with a bit of
+forewarning, you can use the following instead:
 
 @example
 * Anniversaries
@@ -8273,409 +9211,466 @@ you can use the following instead:
 %%(org-bbdb-anniversaries-future 3)
 @end example
 
-That will give you three days' warning: on the anniversary date itself and the
-two days prior.  The argument is optional: if omitted, it defaults to 7.
+That will give you three days' warning: on the anniversary date itself
+and the two days prior.  The argument is optional: if omitted, it
+defaults to 7.
 
+@anchor{Appointment reminders}
 @subsubheading Appointment reminders
+
 @cindex @file{appt.el}
 @cindex appointment reminders
 @cindex appointment
 @cindex reminders
 
-Org can interact with Emacs appointments notification facility.  To add the
-appointments of your agenda files, use the command @code{org-agenda-to-appt}.
-This command lets you filter through the list of your appointments and add
-only those belonging to a specific category or matching a regular expression.
-It also reads a @code{APPT_WARNTIME} property which will then override the
-value of @code{appt-message-warning-time} for this appointment.  See the
-docstring for details.
+@cindex APPT_WARNTIME, keyword
+Org can interact with Emacs appointments notification facility.  To
+add the appointments of your agenda files, use the command
+@code{org-agenda-to-appt}.  This command lets you filter through the list
+of your appointments and add only those belonging to a specific
+category or matching a regular expression.  It also reads
+a @samp{APPT_WARNTIME} property which overrides the value of
+@code{appt-message-warning-time} for this appointment.  See the docstring
+for details.
 
 @node Global TODO list
 @subsection The global TODO list
+
 @cindex global TODO list
 @cindex TODO list, global
 
 The global TODO list contains all unfinished TODO items formatted and
 collected into a single place.
 
-@table @kbd
-@orgcmd{C-c a t,org-todo-list}
-Show the global TODO list.  This collects the TODO items from all agenda
-files (@pxref{Agenda views}) into a single buffer.  By default, this lists
-items with a state the is not a DONE state.  The buffer is in
-@code{agenda-mode}, so there are commands to examine and manipulate the TODO
-entries directly from that buffer (@pxref{Agenda commands}).
-@orgcmd{C-c a T,org-todo-list}
+@table @asis
+@item @kbd{M-x org-agenda t} (@code{org-todo-list})
+@kindex t @r{(Agenda dispatcher)}
+@findex org-todo-list
+Show the global TODO list.  This collects the TODO items from all
+agenda files (see @ref{Agenda Views}) into a single buffer.  By default,
+this lists items with a state the is not a DONE state.  The buffer
+is in Agenda mode, so there are commands to examine and manipulate
+the TODO entries directly from that buffer (see @ref{Agenda Commands}).
+
+@item @kbd{M-x org-agenda T} (@code{org-todo-list})
+@kindex T @r{(Agenda dispatcher)}
+@findex org-todo-list
 @cindex TODO keyword matching
 @vindex org-todo-keywords
-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.
+Like the above, but allows selection of a specific TODO keyword.
+You can also do this by specifying a prefix argument to
+@kbd{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.
+
 @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,
-for example @kbd{3 r}.  If you often need a search for a specific
-keyword, define a custom command for it (@pxref{Agenda dispatcher}).@*
+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, for example @kbd{3 r}.  If you often need
+a search for a specific keyword, define a custom command for it (see
+@ref{Agenda Dispatcher}).
+
 Matching specific TODO keywords can also be done as part of a tags
-search (@pxref{Tag searches}).
+search (see @ref{Tag Searches}).
 @end table
 
-Remote editing of TODO items means that you can change the state of a
-TODO entry with a single key press.  The commands available in the
-TODO list are described in @ref{Agenda commands}.
+Remote editing of TODO items means that you can change the state of
+a TODO entry with a single key press.  The commands available in the
+TODO list are described in @ref{Agenda Commands}.
 
 @cindex sublevels, inclusion into TODO list
 Normally the global TODO list simply shows all headlines with TODO
 keywords.  This list can become very long.  There are two ways to keep
 it more compact:
-@itemize @minus
+
+@itemize
 @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},
-@code{org-agenda-todo-ignore-timestamp} and/or
-@code{org-agenda-todo-ignore-with-date} to exclude such items from the global
-TODO list.
+Some people view a TODO item that has been @emph{scheduled} for execution
+or have a @emph{deadline} (see @ref{Timestamps}) as no longer @emph{open}.
+Configure the variables @code{org-agenda-todo-ignore-scheduled} to
+exclude some or all scheduled items from the global TODO list,
+@code{org-agenda-todo-ignore-deadlines} to exclude some or all items with
+a deadline set, @code{org-agenda-todo-ignore-timestamp} to exclude some
+or all items with an active timestamp other than a DEADLINE or
+a SCHEDULED timestamp and/or @code{org-agenda-todo-ignore-with-date} to
+exclude items with at least one active timestamp.
+
 @item
 @vindex org-agenda-todo-list-sublevels
-TODO items may have sublevels to break up the task into subtasks.  In
-such cases it may be enough to list only the highest level TODO headline
-and omit the sublevels from the global list.  Configure the variable
-@code{org-agenda-todo-list-sublevels} to get this behavior.
+TODO items may have sublevels to break up the task into subtasks.
+In such cases it may be enough to list only the highest level TODO
+headline and omit the sublevels from the global list.  Configure the
+variable @code{org-agenda-todo-list-sublevels} to get this behavior.
 @end itemize
 
 @node Matching tags and properties
 @subsection Matching tags and properties
+
 @cindex matching, of tags
 @cindex matching, of properties
 @cindex tags view
 @cindex match view
 
-If headlines in the agenda files are marked with @emph{tags} (@pxref{Tags}),
-or have properties (@pxref{Properties and columns}), you can select headlines
-based on this metadata and collect them into an agenda buffer.  The match
-syntax described here also applies when creating sparse trees with @kbd{C-c /
-m}.
+If headlines in the agenda files are marked with @emph{tags} (see @ref{Tags}),
+or have properties (see @ref{Properties and Columns}), you can select
+headlines based on this metadata and collect them into an agenda
+buffer.  The match syntax described here also applies when creating
+sparse trees with @kbd{C-c / m}.
 
-@table @kbd
-@orgcmd{C-c a m,org-tags-view}
+@table @asis
+@item @kbd{M-x org-agenda m} (@code{org-tags-view})
+@kindex m @r{(Agenda dispatcher)}
+@findex org-tags-view
 Produce a list of all headlines that match a given set of tags.  The
 command prompts for a selection criterion, which is a boolean logic
-expression with tags, like @samp{+work+urgent-withboss} or
-@samp{work|home} (@pxref{Tags}).  If you often need a specific search,
-define a custom command for it (@pxref{Agenda dispatcher}).
-@orgcmd{C-c a M,org-tags-view}
+expression with tags, like @samp{+work+urgent-withboss} or @samp{work|home}
+(see @ref{Tags}).  If you often need a specific search, define a custom
+command for it (see @ref{Agenda Dispatcher}).
+
+@item @kbd{M-x org-agenda M} (@code{org-tags-view})
+@kindex M @r{(Agenda dispatcher)}
+@findex org-tags-view
 @vindex org-tags-match-list-sublevels
 @vindex org-agenda-tags-todo-honor-ignore-options
-Like @kbd{C-c a m}, but only select headlines that are also TODO items in a
-not-DONE state and force checking subitems (see variable
-@code{org-tags-match-list-sublevels}).  To exclude scheduled/deadline items,
-see the variable @code{org-agenda-tags-todo-honor-ignore-options}.  Matching
-specific TODO keywords together with a tags match is also possible, see
-@ref{Tag searches}.
+Like @kbd{m}, but only select headlines that are also TODO
+items and force checking subitems (see the variable
+@code{org-tags-match-list-sublevels}).  To exclude scheduled/deadline
+items, see the variable @code{org-agenda-tags-todo-honor-ignore-options}.
+Matching specific TODO keywords together with a tags match is also
+possible, see @ref{Tag Searches}.
 @end table
 
-The commands available in the tags list are described in @ref{Agenda
-commands}.
-
-@subsubheading Match syntax
-
-@cindex Boolean logic, for tag/property searches
-A search string can use Boolean operators @samp{&} for @code{AND} and
-@samp{|} for @code{OR}@.  @samp{&} binds more strongly than @samp{|}.
-Parentheses are not implemented.  Each element in the search is either a
-tag, a regular expression matching tags, or an expression like
-@code{PROPERTY OPERATOR VALUE} with a comparison operator, accessing a
-property value.  Each element may be preceded by @samp{-}, to select
-against it, and @samp{+} is syntactic sugar for positive selection.  The
-@code{AND} operator @samp{&} is optional when @samp{+} or @samp{-} is
-present.  Here are some examples, using only tags.
-
-@table @samp
-@item work
-Select headlines tagged @samp{:work:}.
-@item work&boss
-Select headlines tagged @samp{:work:} and @samp{:boss:}.
-@item +work-boss
-Select headlines tagged @samp{:work:}, but discard those also tagged
-@samp{:boss:}.
-@item work|laptop
-Selects lines tagged @samp{:work:} or @samp{:laptop:}.
-@item work|laptop+night
-Like before, but require the @samp{:laptop:} lines to be tagged also
-@samp{:night:}.
+The commands available in the tags list are described in @ref{Agenda Commands}.
+
+@cindex boolean logic, for agenda searches
+A search string can use Boolean operators @samp{&} for AND and @samp{|} for 
OR@.
+@samp{&} binds more strongly than @samp{|}.  Parentheses are currently not
+implemented.  Each element in the search is either a tag, a regular
+expression matching tags, or an expression like @samp{PROPERTY OPERATOR
+VALUE} with a comparison operator, accessing a property value.  Each
+element may be preceded by @samp{-} to select against it, and @samp{+} is
+syntactic sugar for positive selection.  The AND operator @samp{&} is
+optional when @samp{+} or @samp{-} is present.  Here are some examples, using
+only tags.
+
+@table @asis
+@item @samp{+work-boss}
+Select headlines tagged @samp{work}, but discard those also tagged
+@samp{boss}.
+
+@item @samp{work|laptop}
+Selects lines tagged @samp{work} or @samp{laptop}.
+
+@item @samp{work|laptop+night}
+Like before, but require the @samp{laptop} lines to be tagged also
+@samp{night}.
 @end table
 
 @cindex regular expressions, with tags search
-Instead of a tag, you may also specify a regular expression enclosed in curly
-braces.  For example,
-@samp{work+@{^boss.*@}} matches headlines that contain the tag
-@samp{:work:} and any tag @i{starting} with @samp{boss}.
+Instead of a tag, you may also specify a regular expression enclosed
+in curly braces.  For example, @samp{work+@{^boss.*@}} matches headlines that
+contain the tag @samp{:work:} and any tag @emph{starting} with @samp{boss}.
 
 @cindex group tags, as regular expressions
-Group tags (@pxref{Tag hierarchy}) are expanded as regular expressions.  E.g.,
-if @samp{:work:} is a group tag for the group @samp{:work:lab:conf:}, then
-searching for @samp{work} will search for @samp{@{\(?:work\|lab\|conf\)@}}
-and searching for @samp{-work} will search for all headlines but those with
-one of the tags in the group (i.e., @samp{-@{\(?:work\|lab\|conf\)@}}).
+Group tags (see @ref{Tag Hierarchy}) are expanded as regular expressions.
+E.g., if @samp{work} is a group tag for the group @samp{:work:lab:conf:}, then
+searching for @samp{work} also searches for @samp{@{\(?:work\|lab\|conf\)@}} 
and
+searching for @samp{-work} searches for all headlines but those with one of
+the tags in the group (i.e., @samp{-@{\(?:work\|lab\|conf\)@}}).
 
 @cindex TODO keyword matching, with tags search
-@cindex level, require for tags/property match
-@cindex category, require for tags/property match
+@cindex level, for tags/property match
+@cindex category, for tags/property match
 @vindex org-odd-levels-only
-You may also test for properties (@pxref{Properties and columns}) at the same
-time as matching tags.  The properties may be real properties, or special
-properties that represent other metadata (@pxref{Special properties}).  For
-example, the ``property'' @code{TODO} represents the TODO keyword of the
-entry and the ``property'' @code{PRIORITY} represents the PRIORITY keyword of
-the entry.
-
-In addition to the properties mentioned above, @code{LEVEL} represents the
-level of an entry.  So a search @samp{+LEVEL=3+boss-TODO="DONE"} lists all
-level three headlines that have the tag @samp{boss} and are @emph{not} marked
-with the TODO keyword DONE@.  In buffers with @code{org-odd-levels-only} set,
-@samp{LEVEL} does not count the number of stars, but @samp{LEVEL=2} will
-correspond to 3 stars etc.
+You may also test for properties (see @ref{Properties and Columns}) at the
+same time as matching tags.  The properties may be real properties, or
+special properties that represent other metadata (see @ref{Special 
Properties}).  For example, the property @samp{TODO} represents the TODO
+keyword of the entry.  Or, the property @samp{LEVEL} represents the level
+of an entry.  So searching @samp{+LEVEL=3+boss-TODO​="DONE"} lists all level
+three headlines that have the tag @samp{boss} and are @emph{not} marked with 
the
+TODO keyword @samp{DONE}.  In buffers with @code{org-odd-levels-only} set,
+@samp{LEVEL} does not count the number of stars, but @samp{LEVEL=2} corresponds
+to 3 stars etc.
 
 Here are more examples:
 
-@table @samp
-@item work+TODO="WAITING"
-Select @samp{:work:}-tagged TODO lines with the specific TODO
-keyword @samp{WAITING}.
-@item work+TODO="WAITING"|home+TODO="WAITING"
+@table @asis
+@item @samp{work+TODO​="WAITING"}
+Select @samp{work}-tagged TODO lines with the specific TODO keyword
+@samp{WAITING}.
+
+@item @samp{work+TODO​="WAITING"|home+TODO​="WAITING"}
 Waiting tasks both at work and at home.
 @end table
 
-When matching properties, a number of different operators can be used to test
-the value of a property.  Here is a complex example:
+When matching properties, a number of different operators can be used
+to test the value of a property.  Here is a complex example:
 
 @example
-+work-boss+PRIORITY="A"+Coffee="unlimited"+Effort<2         \
-         +With=@{Sarah\|Denny@}+SCHEDULED>="<2008-10-11>"
++work-boss+PRIORITY="A"+Coffee="unlimited"+Effort<2
+         +With=@{Sarah|Denny@}+SCHEDULED>="<2008-10-11>"
 @end example
 
 @noindent
-The type of comparison will depend on how the comparison value is written:
-@itemize @minus
+The type of comparison depends on how the comparison value is written:
+
+@itemize
 @item
-If the comparison value is a plain number, a numerical comparison is done,
-and the allowed operators are @samp{<}, @samp{=}, @samp{>}, @samp{<=},
-@samp{>=}, and @samp{<>}.
+If the comparison value is a plain number, a numerical comparison is
+done, and the allowed operators are @samp{<}, @samp{=}, @samp{>}, @samp{<=}, 
@samp{>=}, and
+@samp{<>}.
+
 @item
-If the comparison value is enclosed in double-quotes,
-a string comparison is done, and the same operators are allowed.
+If the comparison value is enclosed in double-quotes, a string
+comparison is done, and the same operators are allowed.
+
 @item
 If the comparison value is enclosed in double-quotes @emph{and} angular
-brackets (like @samp{DEADLINE<="<2008-12-24 18:30>"}), both values are
-assumed to be date/time specifications in the standard Org way, and the
-comparison will be done accordingly.  Special values that will be recognized
-are @code{"<now>"} for now (including time), and @code{"<today>"}, and
-@code{"<tomorrow>"} for these days at 00:00 hours, i.e., without a time
-specification.  Also strings like @code{"<+5d>"} or @code{"<-2m>"} with units
-@code{d}, @code{w}, @code{m}, and @code{y} for day, week, month, and year,
-respectively, can be used.
-@item
-If the comparison value is enclosed
-in curly braces, a regexp match is performed, with @samp{=} meaning that the
-regexp matches the property value, and @samp{<>} meaning that it does not
-match.
+brackets (like @samp{DEADLINE<​="<2008-12-24 18:30>"}), both values are
+assumed to be date/time specifications in the standard Org way, and
+the comparison is done accordingly.  Valid values also include
+@samp{"<now>"} for now (including time), @samp{"<today>"}, and 
@samp{"<tomorrow>"}
+for these days at 0:00 hours, i.e., without a time specification.
+You can also use strings like @samp{"<+5d>"} or @samp{"<-2m>"} with units 
@samp{d},
+@samp{w}, @samp{m}, and @samp{y} for day, week, month, and year, respectively.
+
+@item
+If the comparison value is enclosed in curly braces, a regexp match
+is performed, with @samp{=} meaning that the regexp matches the property
+value, and @samp{<>} meaning that it does not match.
 @end itemize
 
-So the search string in the example finds entries tagged @samp{:work:} but
-not @samp{:boss:}, which also have a priority value @samp{A}, a
-@samp{:Coffee:} property with the value @samp{unlimited}, an @samp{Effort}
-property that is numerically smaller than 2, a @samp{:With:} property that is
-matched by the regular expression @samp{Sarah\|Denny}, and that are scheduled
-on or after October 11, 2008.
-
-You can configure Org mode to use property inheritance during a search, but
-beware that this can slow down searches considerably.  See @ref{Property
-inheritance}, for details.
-
-For backward compatibility, and also for typing speed, there is also a
-different way to test TODO states in a search.  For this, terminate the
-tags/property part of the search string (which may include several terms
-connected with @samp{|}) with a @samp{/} and then specify a Boolean
-expression just for TODO keywords.  The syntax is then similar to that for
-tags, but should be applied with care: for example, a positive selection on
-several TODO keywords cannot meaningfully be combined with boolean AND@.
-However, @emph{negative selection} combined with AND can be meaningful.  To
-make sure that only lines are checked that actually have any TODO keyword
-(resulting in a speed-up), use @kbd{C-c a M}, or equivalently start the TODO
-part after the slash with @samp{!}.  Using @kbd{C-c a M} or @samp{/!} will
-not match TODO keywords in a DONE state.  Examples:
-
-@table @samp
-@item work/WAITING
-Same as @samp{work+TODO="WAITING"}
-@item work/!-WAITING-NEXT
-Select @samp{:work:}-tagged TODO lines that are neither @samp{WAITING}
-nor @samp{NEXT}
-@item work/!+WAITING|+NEXT
-Select @samp{:work:}-tagged TODO lines that are either @samp{WAITING} or
+So the search string in the example finds entries tagged @samp{work} but
+not @samp{boss}, which also have a priority value @samp{A}, a @samp{Coffee} 
property
+with the value @samp{unlimited}, an @samp{EFFORT} property that is numerically
+smaller than 2, a @samp{With} property that is matched by the regular
+expression @samp{Sarah|Denny}, and that are scheduled on or after October
+11, 2008.
+
+You can configure Org mode to use property inheritance during
+a search, but beware that this can slow down searches considerably.
+See @ref{Property Inheritance}, for details.
+
+For backward compatibility, and also for typing speed, there is also
+a different way to test TODO states in a search.  For this, terminate
+the tags/property part of the search string (which may include several
+terms connected with @samp{|}) with a @samp{/} and then specify a Boolean
+expression just for TODO keywords.  The syntax is then similar to that
+for tags, but should be applied with care: for example, a positive
+selection on several TODO keywords cannot meaningfully be combined
+with boolean AND@.  However, @emph{negative selection} combined with AND can
+be meaningful.  To make sure that only lines are checked that actually
+have any TODO keyword (resulting in a speed-up), use @kbd{M-x org-agenda M}, 
or equivalently start the TODO part after the slash
+with @samp{!}.  Using @kbd{M-x org-agenda M} or @samp{/!} does not match
+TODO keywords in a DONE state.  Examples:
+
+@table @asis
+@item @samp{work/WAITING}
+Same as @samp{work+TODO​="WAITING"}.
+
+@item @samp{work/!-WAITING-NEXT}
+Select @samp{work}-tagged TODO lines that are neither @samp{WAITING} nor
 @samp{NEXT}.
+
+@item @samp{work/!+WAITING|+NEXT}
+Select @samp{work}-tagged TODO lines that are either @samp{WAITING} or 
@samp{NEXT}.
 @end table
 
 @node Search view
 @subsection Search view
+
 @cindex search view
 @cindex text search
 @cindex searching, for text
 
-This agenda view is a general text search facility for Org mode entries.
-It is particularly useful to find notes.
+This agenda view is a general text search facility for Org mode
+entries.  It is particularly useful to find notes.
 
-@table @kbd
-@orgcmd{C-c a s,org-search-view}
-This is a special search that lets you select entries by matching a substring
-or specific words using a boolean logic.
+@table @asis
+@item @kbd{M-x org-agenda s} (@code{org-search-view})
+@kindex s @r{(Agenda dispatcher)}
+@findex org-search-view
+This is a special search that lets you select entries by matching
+a substring or specific words using a boolean logic.
 @end table
-For example, the search string @samp{computer equipment} will find entries
-that contain @samp{computer equipment} as a substring.  If the two words are
-separated by more space or a line break, the search will still match.
-Search view can also search for specific keywords in the entry, using Boolean
-logic.  The search string @samp{+computer +wifi -ethernet -@{8\.11[bg]@}}
-will search for note entries that contain the keywords @code{computer}
-and @code{wifi}, but not the keyword @code{ethernet}, and which are also
-not matched by the regular expression @code{8\.11[bg]}, meaning to
-exclude both 8.11b and 8.11g.  The first @samp{+} is necessary to turn on
-word search, other @samp{+} characters are optional.  For more details, see
-the docstring of the command @code{org-search-view}.
+
+For example, the search string @samp{computer equipment} matches entries
+that contain @samp{computer equipment} as a substring, even if the two
+words are separated by more space or a line break.
+
+Search view can also search for specific keywords in the entry, using
+Boolean logic.  The search string @samp{+computer
++wifi -ethernet -@{8\.11[bg]@}} matches note entries that contain the
+keywords @samp{computer} and @samp{wifi}, but not the keyword @samp{ethernet}, 
and
+which are also not matched by the regular expression @samp{8\.11[bg]},
+meaning to exclude both @samp{8.11b} and @samp{8.11g}.  The first @samp{+} is
+necessary to turn on boolean search, other @samp{+} characters are
+optional.  For more details, see the docstring of the command
+@code{org-search-view}.
+
+You can incrementally and conveniently adjust a boolean search from
+the agenda search view with the following keys
+
+@multitable @columnfractions 0.1 0.6
+@item @kbd{[}
+@tab Add a positive search word
+@item @kbd{]}
+@tab Add a negative search word
+@item @kbd{@{}
+@tab Add a positive regular expression
+@item @kbd{@}}
+@tab Add a negative regular expression
+@end multitable
 
 @vindex org-agenda-text-search-extra-files
-Note that in addition to the agenda files, this command will also search
+Note that in addition to the agenda files, this command also searches
 the files listed in @code{org-agenda-text-search-extra-files}.
 
 @node Stuck projects
 @subsection Stuck projects
+
 @pindex GTD, Getting Things Done
 
 If you are following a system like David Allen's GTD to organize your
 work, one of the ``duties'' you have is a regular review to make sure
-that all projects move along.  A @emph{stuck} project is a project that
-has no defined next actions, so it will never show up in the TODO lists
-Org mode produces.  During the review, you need to identify such
-projects and define next actions for them.
+that all projects move along.  A @emph{stuck} project is a project that has
+no defined next actions, so it never shows up in the TODO lists Org
+mode produces.  During the review, you need to identify such projects
+and define next actions for them.
 
-@table @kbd
-@orgcmd{C-c a #,org-agenda-list-stuck-projects}
+@table @asis
+@item @kbd{M-x org-agenda #} (@code{org-agenda-list-stuck-projects})
+@kindex # @r{(Agenda dispatcher)}
+@findex org-agenda-list-stuck-projects
 List projects that are stuck.
-@kindex C-c a !
-@item C-c a !
+
+@item @kbd{M-x org-agenda !}
+@kindex ! @r{(Agenda dispatcher)}
 @vindex org-stuck-projects
 Customize the variable @code{org-stuck-projects} to define what a stuck
 project is and how to find it.
 @end table
 
-You almost certainly will have to configure this view before it will
-work for you.  The built-in default assumes that all your projects are
-level-2 headlines, and that a project is not stuck if it has at least
-one entry marked with a TODO keyword TODO or NEXT or NEXTACTION.
+You almost certainly need to configure this view before it works for
+you.  The built-in default assumes that all your projects are level-2
+headlines, and that a project is not stuck if it has at least one
+entry marked with a TODO keyword @samp{TODO} or @samp{NEXT} or 
@samp{NEXTACTION}.
 
 Let's assume that you, in your own way of using Org mode, identify
-projects with a tag PROJECT, and that you use a TODO keyword MAYBE to
-indicate a project that should not be considered yet.  Let's further
-assume that the TODO keyword DONE marks finished projects, and that NEXT
-and TODO indicate next actions.  The tag @@SHOP indicates shopping and
-is a next action even without the NEXT tag.  Finally, if the project
-contains the special word IGNORE anywhere, it should not be listed
-either.  In this case you would start by identifying eligible projects
-with a tags/todo match@footnote{@xref{Tag searches}.}
-@samp{+PROJECT/-MAYBE-DONE}, and then check for TODO, NEXT, @@SHOP, and
-IGNORE in the subtree to identify projects that are not stuck.  The
-correct customization for this is
+projects with a tag @samp{:PROJECT:}, and that you use a TODO keyword
+@samp{MAYBE} to indicate a project that should not be considered yet.
+Let's further assume that the TODO keyword @samp{DONE} marks finished
+projects, and that @samp{NEXT} and @samp{TODO} indicate next actions.  The tag
+@samp{:@@shop:} indicates shopping and is a next action even without the
+NEXT tag.  Finally, if the project contains the special word @samp{IGNORE}
+anywhere, it should not be listed either.  In this case you would
+start by identifying eligible projects with a tags/TODO match (see
+@ref{Tag Searches}) @samp{+PROJECT/-MAYBE-DONE}, and then check for 
@samp{TODO},
+@samp{NEXT}, @samp{@@shop}, and @samp{IGNORE} in the subtree to identify 
projects that
+are not stuck.  The correct customization for this is:
 
 @lisp
 (setq org-stuck-projects
-      '("+PROJECT/-MAYBE-DONE" ("NEXT" "TODO") ("@@SHOP")
-                               "\\<IGNORE\\>"))
+      '("+PROJECT/-MAYBE-DONE" ("NEXT" "TODO") ("@@shop")
+        "\\<IGNORE\\>"))
 @end lisp
 
-Note that if a project is identified as non-stuck, the subtree of this entry
-will still be searched for stuck projects.
+Note that if a project is identified as non-stuck, the subtree of this
+entry is searched for stuck projects.
+
+@node Presentation and Sorting
+@section Presentation and Sorting
 
-@node Presentation and sorting
-@section Presentation and sorting
 @cindex presentation, of agenda items
 
 @vindex org-agenda-prefix-format
 @vindex org-agenda-tags-column
-Before displaying items in an agenda view, Org mode visually prepares the
-items and sorts them.  Each item occupies a single line.  The line starts
-with a @emph{prefix} that contains the @emph{category} (@pxref{Categories})
-of the item and other important information.  You can customize in which
-column tags will be displayed through @code{org-agenda-tags-column}.  You can
-also customize the prefix using the option @code{org-agenda-prefix-format}.
-This prefix is followed by a cleaned-up version of the outline headline
-associated with the item.
+Before displaying items in an agenda view, Org mode visually prepares
+the items and sorts them.  Each item occupies a single line.  The line
+starts with a @emph{prefix} that contains the @emph{category} (see 
@ref{Categories})
+of the item and other important information.  You can customize in
+which column tags are displayed through @code{org-agenda-tags-column}.  You
+can also customize the prefix using the option
+@code{org-agenda-prefix-format}.  This prefix is followed by a cleaned-up
+version of the outline headline associated with the item.
 
 @menu
-* Categories::                  Not all tasks are equal
-* Time-of-day specifications::  How the agenda knows the time
-* Sorting agenda items::        The order of things
-* Filtering/limiting agenda items::  Dynamically narrow the agenda
+* Categories::                   Not all tasks are equal.
+* Time-of-day specifications::   How the agenda knows the time.
+* Sorting of agenda items::      The order of things.
+* Filtering/limiting agenda items:: Dynamically narrow the agenda.
 @end menu
 
 @node Categories
 @subsection Categories
 
 @cindex category
-@cindex @code{#+CATEGORY}
-The category is a broad label assigned to each agenda item.  By default, the
-category is simply derived from the file name, but you can also specify it
-with a special line in the buffer, like this:
+@cindex @samp{CATEGORY}, keyword
+
+The category is a broad label assigned to each agenda item.  By
+default, the category is simply derived from the file name, but you
+can also specify it with a special line in the buffer, like
+this:
 
 @example
 #+CATEGORY: Thesis
 @end example
 
-@noindent
-@cindex property, @code{CATEGORY}
-If you would like to have a special @code{CATEGORY} for a single entry or a
-(sub)tree, give the entry a @code{:CATEGORY:} property with the
-special category you want to apply as the value.
 
-@noindent
-The display in the agenda buffer looks best if the category is not
-longer than 10 characters.
+@cindex @samp{CATEGORY}, property
+If you would like to have a special category for a single entry or
+a (sub)tree, give the entry a @samp{CATEGORY} property with the special
+category you want to apply as the value.
 
-@noindent
-You can set up icons for category by customizing the
-@code{org-agenda-category-icon-alist} variable.
+@vindex org-agenda-category-icon-alist
+The display in the agenda buffer looks best if the category is not
+longer than 10 characters.  You can set up icons for category by
+customizing the @code{org-agenda-category-icon-alist} variable.
 
 @node Time-of-day specifications
 @subsection Time-of-day specifications
+
 @cindex time-of-day specification
 
 Org mode checks each agenda item for a time-of-day specification.  The
 time can be part of the timestamp that triggered inclusion into the
-agenda, for example as in @w{@samp{<2005-05-10 Tue 19:00>}}.  Time
-ranges can be specified with two timestamps, like
-@c
-@w{@samp{<2005-05-10 Tue 20:30>--<2005-05-10 Tue 22:15>}}.
-
-In the headline of the entry itself, a time(range) may also appear as
-plain text (like @samp{12:45} or a @samp{8:30-1pm}).  If the agenda
-integrates the Emacs diary (@pxref{Weekly/daily agenda}), time
-specifications in diary entries are recognized as well.
-
-For agenda display, Org mode extracts the time and displays it in a
-standard 24 hour format as part of the prefix.  The example times in
+agenda, for example
+
+@example
+<2005-05-10 Tue 19:00>
+@end example
+
+
+@noindent
+Time ranges can be specified with two timestamps:
+
+@example
+<2005-05-10 Tue 20:30>--<2005-05-10 Tue 22:15>
+@end example
+
+
+@vindex org-agenda-search-headline-for-time
+In the headline of the entry itself, a time(range)---like @samp{12:45} or
+a @samp{8:30-1pm}---may also appear as plain text@footnote{You can, however, 
disable this by setting
+@code{org-agenda-search-headline-for-time} variable to a @code{nil} value.}.
+
+If the agenda integrates the Emacs diary (see @ref{Weekly/daily agenda}),
+time specifications in diary entries are recognized as well.
+
+For agenda display, Org mode extracts the time and displays it in
+a standard 24 hour format as part of the prefix.  The example times in
 the previous paragraphs would end up in the agenda like this:
 
 @example
-    8:30-13:00 Arthur Dent lies in front of the bulldozer
-   12:45...... Ford Prefect arrives and takes Arthur to the pub
-   19:00...... The Vogon reads his poem
-   20:30-22:15 Marvin escorts the Hitchhikers to the bridge
+ 8:30-13:00 Arthur Dent lies in front of the bulldozer
+12:45...... Ford Prefect arrives and takes Arthur to the pub
+19:00...... The Vogon reads his poem
+20:30-22:15 Marvin escorts the Hitchhikers to the bridge
 @end example
 
 @cindex time grid
@@ -8683,17 +9678,17 @@ If the agenda is in single-day mode, or for the display 
of today, the
 timed entries are embedded in a time grid, like
 
 @example
-    8:00...... ------------------
-    8:30-13:00 Arthur Dent lies in front of the bulldozer
-   10:00...... ------------------
-   12:00...... ------------------
-   12:45...... Ford Prefect arrives and takes Arthur to the pub
-   14:00...... ------------------
-   16:00...... ------------------
-   18:00...... ------------------
-   19:00...... The Vogon reads his poem
-   20:00...... ------------------
-   20:30-22:15 Marvin escorts the Hitchhikers to the bridge
+ 8:00...... ------------------
+ 8:30-13:00 Arthur Dent lies in front of the bulldozer
+10:00...... ------------------
+12:00...... ------------------
+12:45...... Ford Prefect arrives and takes Arthur to the pub
+14:00...... ------------------
+16:00...... ------------------
+18:00...... ------------------
+19:00...... The Vogon reads his poem
+20:00...... ------------------
+20:30-22:15 Marvin escorts the Hitchhikers to the bridge
 @end example
 
 @vindex org-agenda-use-time-grid
@@ -8702,763 +9697,1009 @@ The time grid can be turned on and off with the 
variable
 @code{org-agenda-use-time-grid}, and can be configured with
 @code{org-agenda-time-grid}.
 
-@node Sorting agenda items
-@subsection Sorting agenda items
+@node Sorting of agenda items
+@subsection Sorting of agenda items
+
 @cindex sorting, of agenda items
 @cindex priorities, of agenda items
+
 Before being inserted into a view, the items are sorted.  How this is
 done depends on the type of view.
-@itemize @bullet
+
+@itemize
 @item
 @vindex org-agenda-files
 For the daily/weekly agenda, the items for each day are sorted.  The
 default order is to first collect all items containing an explicit
-time-of-day specification.  These entries will be shown at the beginning
+time-of-day specification.  These entries are shown at the beginning
 of the list, as a @emph{schedule} for the day.  After that, items remain
 grouped in categories, in the sequence given by @code{org-agenda-files}.
-Within each category, items are sorted by priority (@pxref{Priorities}),
-which is composed of the base priority (2000 for priority @samp{A}, 1000
-for @samp{B}, and 0 for @samp{C}), plus additional increments for
-overdue scheduled or deadline items.
-@item
-For the TODO list, items remain in the order of categories, but within
-each category, sorting takes place according to priority
-(@pxref{Priorities}).  The priority used for sorting derives from the
-priority cookie, with additions depending on how close an item is to its due
-or scheduled date.
-@item
-For tags matches, items are not sorted at all, but just appear in the
-sequence in which they are found in the agenda files.
+Within each category, items are sorted by priority (see
+@ref{Priorities}), which is composed of the base priority (2000 for
+priority @samp{A}, 1000 for @samp{B}, and 0 for @samp{C}), plus additional
+increments for overdue scheduled or deadline items.
+
+@item
+For the TODO list, items remain in the order of categories, but
+within each category, sorting takes place according to priority (see
+@ref{Priorities}).  The priority used for sorting derives from the
+priority cookie, with additions depending on how close an item is to
+its due or scheduled date.
+
+@item
+For tags matches, items are not sorted at all, but just appear in
+the sequence in which they are found in the agenda files.
 @end itemize
 
 @vindex org-agenda-sorting-strategy
 Sorting can be customized using the variable
 @code{org-agenda-sorting-strategy}, and may also include criteria based on
-the estimated effort of an entry (@pxref{Effort estimates}).
+the estimated effort of an entry (see @ref{Effort Estimates}).
 
 @node Filtering/limiting agenda items
 @subsection Filtering/limiting agenda items
 
-Agenda built-in or customized commands are statically defined.  Agenda
-filters and limits provide two ways of dynamically narrowing down the list of
-agenda entries: @emph{filters} and @emph{limits}.  Filters only act on the
-display of the items, while limits take effect before the list of agenda
-entries is built.  Filters are more often used interactively, while limits are
-mostly useful when defined as local variables within custom agenda commands.
+@vindex org-agenda-category-filter-preset
+@vindex org-agenda-tag-filter-preset
+@vindex org-agenda-effort-filter-preset
+@vindex org-agenda-regexp-filter-preset
+Agenda built-in or custom commands are statically defined.  Agenda
+filters and limits allow to flexibly narrow down the list of agenda
+entries.
 
+@emph{Filters} only change the visibility of items, are very fast and are
+mostly used interactively@footnote{Custom agenda commands can preset a filter 
by binding one of
+the variables @code{org-agenda-tag-filter-preset},
+@code{org-agenda-category-filter-preset}, 
@code{org-agenda-effort-filter-preset}
+or @code{org-agenda-regexp-filter-preset} as an option.  This filter is
+then applied to the view and persists as a basic filter through
+refreshes and more secondary filtering.  The filter is a global
+property of the entire agenda view---in a block agenda, you should
+only set this in the global options section, not in the section of an
+individual block.}. You can switch quickly between
+different filters without having to recreate the agenda.  @emph{Limits} on
+the other hand take effect before the agenda buffer is populated, so
+they are mostly useful when defined as local variables within custom
+agenda commands.
+
+@anchor{Filtering in the agenda}
 @subsubheading Filtering in the agenda
-@cindex filtering, by tag, category, top headline and effort, in agenda
+
+@cindex agenda filtering
+@cindex filtering entries, in agenda
 @cindex tag filtering, in agenda
 @cindex category filtering, in agenda
 @cindex top headline filtering, in agenda
 @cindex effort filtering, in agenda
 @cindex query editing, in agenda
 
-@table @kbd
-@orgcmd{/,org-agenda-filter-by-tag}
-@vindex org-agenda-tag-filter-preset
-Filter the 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
-binding the variable @code{org-agenda-tag-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
-the entire agenda view---in a block agenda, you should only set this in the
-global options section, not in the section of an individual block.}
-
-You will be prompted for a tag selection letter; @key{SPC} will mean any tag
-at all.  Pressing @key{TAB} at that prompt will offer use completion to
-select a tag (including any tags that do not have a selection character).
-The command then hides all entries that do not contain or inherit this tag.
-When called with prefix arg, remove the entries that @emph{do} have the tag.
-A second @kbd{/} at the prompt will turn off the filter and unhide any hidden
-entries.  Pressing @kbd{+} or @kbd{-} switches between filtering and
-excluding the next tag.
-
-Org also supports automatic, context-aware tag filtering.  If the variable
-@code{org-agenda-auto-exclude-function} is set to a user-defined function,
-that function can decide which tags should be excluded from the agenda
-automatically.  Once this is set, the @kbd{/} command then accepts
-@kbd{@key{RET}} as a sub-option key and runs the auto exclusion logic.  For
-example, let's say you use a @code{Net} tag to identify tasks which need
-network access, an @code{Errand} tag for errands in town, and a @code{Call}
-tag for making phone calls.  You could auto-exclude these tags based on the
-availability of the Internet, and outside of business hours, with something
-like this:
-
-@smalllisp
-@group
-(defun org-my-auto-exclude-function (tag)
-  (and (cond
-        ((string= tag "Net")
-         (/= 0 (call-process "/sbin/ping" nil nil nil
-                             "-c1" "-q" "-t1" "mail.gnu.org")))
-        ((or (string= tag "Errand") (string= tag "Call"))
-         (let ((hour (nth 2 (decode-time))))
-           (or (< hour 8) (> hour 21)))))
-       (concat "-" tag)))
-
-(setq org-agenda-auto-exclude-function 'org-my-auto-exclude-function)
-@end group
-@end smalllisp
-
-@c
-@kindex [
-@kindex ]
-@kindex @{
-@kindex @}
-@item [ ] @{ @}
-@table @i
-@item @r{in} search view
-add new search words (@kbd{[} and @kbd{]}) or new regular expressions
-(@kbd{@{} and @kbd{@}}) to the query string.  The opening bracket/brace will
-add a positive search term prefixed by @samp{+}, indicating that this search
-term @i{must} occur/match in the entry.  The closing bracket/brace will add a
-negative search term which @i{must not} occur/match in the entry for it to be
-selected.
-@end table
-
-@orgcmd{<,org-agenda-filter-by-category}
-@vindex org-agenda-category-filter-preset
-
-Filter the current agenda view with respect to the category of the item at
-point.  Pressing @code{<} another time will remove this filter.  When called
-with a prefix argument exclude the category of the item at point from the
-agenda.
-
-You can add a filter preset in custom agenda commands through the option
-@code{org-agenda-category-filter-preset}.  @xref{Setting options}.
+The general filtering command is @code{org-agenda-filter}, bound to
+@kbd{/}.  Before we introduce it, we describe commands for
+individual filter types.  All filtering commands handle prefix
+arguments in the same way:  A single @kbd{C-u} prefix negates the
+filter, so it removes lines selected by the filter.  A double prefix
+adds the new filter condition to the one(s) already in place, so
+filter elements are accumulated.
 
-@orgcmd{^,org-agenda-filter-by-top-headline}
-Filter the current agenda view and only display the siblings and the parent
-headline of the one at point.
-
-@orgcmd{=,org-agenda-filter-by-regexp}
-@vindex org-agenda-regexp-filter-preset
-
-Filter the agenda view by a regular expression: only show agenda entries
-matching the regular expression the user entered.  When called with a prefix
-argument, it will filter @emph{out} entries matching the regexp.  With two
-universal prefix arguments, it will remove all the regexp filters, which can
-be accumulated.
-
-You can add a filter preset in custom agenda commands through the option
-@code{org-agenda-regexp-filter-preset}.  @xref{Setting options}.
+@table @asis
+@item @kbd{\} (@code{org-agenda-filter-by-tag})
+@findex org-agenda-filter-by-tag
+Filter the agenda view with respect to a tag.  You are prompted for
+a tag selection letter; @kbd{@key{SPC}} means any tag at all.
+Pressing @kbd{@key{TAB}} at that prompt offers completion to select a
+tag, including any tags that do not have a selection character.  The
+command then hides all entries that do not contain or inherit this
+tag.  Pressing @kbd{+} or @kbd{-} at the prompt switches
+between filtering for and against the next tag.  To clear the
+filter, press @kbd{\} twice (once to call the command again,
+and once at the prompt).
+
+@item @kbd{<} (@code{org-agenda-filter-by-category})
+@findex org-agenda-filter-by-category
+Filter by category of the line at point, and show only entries with
+this category.  When called with a prefix argument, hide all entries
+with the category at point.  To clear the filter, call this command
+again by pressing @kbd{<}.
+
+@item @kbd{=} (@code{org-agenda-filter-by-regexp})
+@findex org-agenda-filter-by-regexp
+Filter the agenda view by a regular expression: only show agenda
+entries matching the regular expression the user entered. To clear
+the filter, call the command again by pressing @kbd{=}.
+
+@item @kbd{_} (@code{org-agenda-filter-by-effort})
+@findex org-agenda-filter-by-effort
+Filter the agenda view with respect to effort estimates, so select
+tasks that take the right amount of time.  You first need to set up
+a list of efforts globally, for example
 
-@orgcmd{_,org-agenda-filter-by-effort}
-@vindex org-agenda-effort-filter-preset
-@vindex org-sort-agenda-noeffort-is-high
-Filter the agenda view with respect to effort estimates.
-You first need to set up allowed efforts globally, for example
 @lisp
 (setq org-global-properties
-    '(("Effort_ALL". "0 0:10 0:30 1:00 2:00 3:00 4:00")))
+      '(("Effort_ALL". "0 0:10 0:30 1:00 2:00 3:00 4:00")))
 @end lisp
-You can then filter for an effort by first typing an operator, one of
-@kbd{<}, @kbd{>}, and @kbd{=}, and then the one-digit index of an effort
-estimate in your array of allowed values, where @kbd{0} means the 10th value.
-The filter will then restrict to entries with effort smaller-or-equal, equal,
-or larger-or-equal than the selected value.  For application of the operator,
-entries without a defined effort will be treated according to the value of
-@code{org-sort-agenda-noeffort-is-high}.
-
-When called with a prefix argument, it will remove entries matching the
-condition.  With two universal prefix arguments, it will clear effort
-filters, which can be accumulated.
-
-You can add a filter preset in custom agenda commands through the option
-@code{org-agenda-effort-filter-preset}.  @xref{Setting options}.
-
-@orgcmd{|,org-agenda-filter-remove-all}
+
+@vindex org-sort-agenda-noeffort-is-high
+You can then filter for an effort by first typing an operator, one
+of @kbd{<}, @kbd{>} and @kbd{=}, and then the
+one-digit index of an effort estimate in your array of allowed
+values, where @kbd{0} means the 10th value.  The filter then
+restricts to entries with effort smaller-or-equal, equal, or
+larger-or-equal than the selected value.  For application of the
+operator, entries without a defined effort are treated according to
+the value of @code{org-sort-agenda-noeffort-is-high}.  To clear the
+filter, press @kbd{_} twice (once to call the command again,
+and once at the first prompt).
+
+@item @kbd{^} (@code{org-agenda-filter-by-top-headline})
+@findex org-agenda-filter-by-top-headline
+Filter the current agenda view and only display items that fall
+under the same top-level headline as the current entry.  To clear
+the filter, call this command again by pressing @kbd{^}.
+
+@item @kbd{/} (@code{org-agenda-filter})
+@findex org-agenda-filter
+This is the unified interface to four of the five filter methods
+described above.  At the prompt, specify different filter elements
+in a single string, with full completion support.  For example,
+
+@example
++work-John+<0:10-/plot/
+@end example
+
+selects entries with category `work' and effort estimates below 10
+minutes, and deselects entries with tag `John' or matching the
+regexp `plot'.  `+' can be left out if that does not lead to
+ambiguities.  The sequence of elements is arbitrary.  The filter
+syntax assumes that there is no overlap between categories and tags
+(tags will take priority).  If you reply to the prompt with the
+empty string, all filtering is removed.  If a filter is specified,
+it replaces all current filters.  But if you call the command with a
+double prefix argument, or if you add an additional `+'
+(e.g. `++work') to the front of the string, the new filter elements
+are added to the active ones.  A single prefix argument applies the
+entire filter in a negative sense.
+
+@item @kbd{|} (@code{org-agenda-filter-remove-all})
 Remove all filters in the current agenda view.
 @end table
 
+@anchor{Computed tag filtering}
+@subsubheading Computed tag filtering
+
+@vindex org-agenda-auto-exclude-function
+If the variable @code{org-agenda-auto-exclude-function} is set to a
+user-defined function, that function can select tags that should be
+used as a tag filter when requested.  The function will be called with
+lower-case versions of all tags represented in the current view. The
+function should the return @samp{"-tag"} if the filter should remove
+entries with that tag, @samp{"+tag"} if only entries with this tag should
+be kept, or @samp{nil} if that tag is irrelevant. For example, let's say
+you use a @samp{Net} tag to identify tasks which need network access, an
+@samp{Errand} tag for errands in town, and a @samp{Call} tag for making phone
+calls.  You could auto-exclude these tags based on the availability of
+the Internet, and outside of business hours, with something like this:
+
+@lisp
+(defun org-my-auto-exclude-fn (tag)
+  (if (cond
+       ((string= tag "net")
+        (/= 0 (call-process "/sbin/ping" nil nil nil
+                            "-c1" "-q" "-t1" "mail.gnu.org")))
+       ((member tag '("errand" "call"))
+        (let ((hr (nth 2 (decode-time))))
+          (or (< hr 8) (> hr 21)))))
+      (concat "-" tag)))
+
+(setq org-agenda-auto-exclude-function 'org-my-auto-exclude-fn)
+@end lisp
+
+You can apply this self-adapting filter by using a double prefix
+argument to @code{org-agenda-filter}, i.e. press @kbd{C-u C-u /}, or
+by pressing @kbd{@key{RET}} in @code{org-agenda-filter-by-tag}.
+
+@anchor{Setting limits for the agenda}
 @subsubheading Setting limits for the agenda
+
 @cindex limits, in agenda
-@vindex org-agenda-max-entries
-@vindex org-agenda-max-effort
-@vindex org-agenda-max-todos
-@vindex org-agenda-max-tags
 
-Here is a list of options that you can set, either globally, or locally in
-your custom agenda views (@pxref{Custom agenda views}).
+Here is a list of options that you can set, either globally, or
+locally in your custom agenda views (see @ref{Custom Agenda Views}).
 
-@table @code
-@item org-agenda-max-entries
+@table @asis
+@item @code{org-agenda-max-entries}
+@vindex org-agenda-max-entries
 Limit the number of entries.
-@item org-agenda-max-effort
+
+@item @code{org-agenda-max-effort}
+@vindex org-agenda-max-effort
 Limit the duration of accumulated efforts (as minutes).
-@item org-agenda-max-todos
+
+@item @code{org-agenda-max-todos}
+@vindex org-agenda-max-todos
 Limit the number of entries with TODO keywords.
-@item org-agenda-max-tags
+
+@item @code{org-agenda-max-tags}
+@vindex org-agenda-max-tags
 Limit the number of tagged entries.
 @end table
 
-When set to a positive integer, each option will exclude entries from other
-categories: for example, @code{(setq org-agenda-max-effort 100)} will limit
-the agenda to 100 minutes of effort and exclude any entry that has no effort
-property.  If you want to include entries with no effort property, use a
-negative value for @code{org-agenda-max-effort}.
-
-One useful setup is to use @code{org-agenda-max-entries} locally in a custom
-command.  For example, this custom command will display the next five entries
-with a @code{NEXT} TODO keyword.
+When set to a positive integer, each option excludes entries from
+other categories: for example, @samp{(setq org-agenda-max-effort 100)}
+limits the agenda to 100 minutes of effort and exclude any entry that
+has no effort property.  If you want to include entries with no effort
+property, use a negative value for @code{org-agenda-max-effort}.  One
+useful setup is to use @code{org-agenda-max-entries} locally in a custom
+command.  For example, this custom command displays the next five
+entries with a @samp{NEXT} TODO keyword.
 
-@smalllisp
+@lisp
 (setq org-agenda-custom-commands
       '(("n" todo "NEXT"
          ((org-agenda-max-entries 5)))))
-@end smalllisp
+@end lisp
 
-Once you mark one of these five entry as @code{DONE}, rebuilding the agenda
-will again the next five entries again, including the first entry that was
-excluded so far.
+Once you mark one of these five entry as DONE, rebuilding the agenda
+will again the next five entries again, including the first entry that
+was excluded so far.
 
-You can also dynamically set temporary limits, which will be lost when
+You can also dynamically set temporary limits, which are lost when
 rebuilding the agenda:
 
-@table @kbd
-@orgcmd{~,org-agenda-limit-interactively}
+@table @asis
+@item @kbd{~} (@code{org-agenda-limit-interactively})
+@findex org-agenda-limit-interactively
 This prompts for the type of limit to apply and its value.
 @end table
 
-@node Agenda commands
-@section Commands in the agenda buffer
+@node Agenda Commands
+@section Commands in the Agenda Buffer
+
 @cindex commands, in agenda buffer
 
 Entries in the agenda buffer are linked back to the Org file or diary
 file where they originate.  You are not allowed to edit the agenda
 buffer itself, but commands are provided to show and jump to the
-original entry location, and to edit the Org files ``remotely'' from
-the agenda buffer.  In this way, all information is stored only once,
+original entry location, and to edit the Org files ``remotely'' from the
+agenda buffer.  In this way, all information is stored only once,
 removing the risk that your agenda and note files may diverge.
 
 Some commands can be executed with mouse clicks on agenda lines.  For
-the other commands, the cursor needs to be in the desired line.
+the other commands, point needs to be in the desired line.
+
+@anchor{Motion (1)}
+@subheading Motion
 
-@table @kbd
-@tsubheading{Motion}
 @cindex motion commands in agenda
-@orgcmd{n,org-agenda-next-line}
-Next line (same as @key{DOWN} and @kbd{C-n}).
-@orgcmd{p,org-agenda-previous-line}
-Previous line (same as @key{UP} and @kbd{C-p}).
-@orgcmd{N,org-agenda-next-item}
-Next item: same as next line, but only consider items.
-@orgcmd{P,org-agenda-previous-item}
-Previous item: same as previous line, but only consider items.
-@tsubheading{View/Go to Org file}
-@orgcmdkkc{@key{SPC},mouse-3,org-agenda-show-and-scroll-up}
-Display the original location of the item in another window.  With prefix
-arg, make sure that drawers stay folded.
-@c
-@orgcmd{L,org-agenda-recenter}
+
+@table @asis
+@item @kbd{n} (@code{org-agenda-next-line})
+@kindex n
+@findex org-agenda-next-line
+Next line (same as @kbd{@key{DOWN}} and @kbd{C-n}).
+
+@item @kbd{p} (@code{org-agenda-previous-line})
+@kindex p
+@findex org-agenda-previous-line
+Previous line (same as @kbd{@key{UP}} and @kbd{C-p}).
+@end table
+
+@anchor{View/Go to Org file}
+@subheading View/Go to Org file
+
+@cindex view file commands in agenda
+
+@table @asis
+@item @kbd{@key{SPC}} or @kbd{mouse-3} (@code{org-agenda-show-and-scroll-up})
+@kindex SPC
+@kindex mouse-3
+@findex org-agenda-show-and-scroll-up
+Display the original location of the item in another window.
+With a prefix argument, make sure that drawers stay folded.
+
+@item @kbd{L} (@code{org-agenda-recenter})
+@findex org-agenda-recenter
 Display original location and recenter that window.
-@c
-@orgcmdkkc{@key{TAB},mouse-2,org-agenda-goto}
+
+@item @kbd{@key{TAB}} or @kbd{mouse-2} (@code{org-agenda-goto})
+@kindex TAB
+@kindex mouse-2
+@findex org-agenda-goto
 Go to the original location of the item in another window.
-@c
-@orgcmd{@key{RET},org-agenda-switch-to}
+
+@item @kbd{@key{RET}} (@code{org-agenda-switch-to})
+@kindex RET
+@findex org-agenda-switch-to
 Go to the original location of the item and delete other windows.
-@c
-@orgcmd{F,org-agenda-follow-mode}
+
+@item @kbd{F} (@code{org-agenda-follow-mode})
+@kindex F
+@findex org-agenda-follow-mode
 @vindex org-agenda-start-with-follow-mode
-Toggle Follow mode.  In Follow mode, as you move the cursor through
-the agenda buffer, the other window always shows the corresponding
+Toggle Follow mode.  In Follow mode, as you move point through the
+agenda buffer, the other window always shows the corresponding
 location in the Org file.  The initial setting for this mode in new
 agenda buffers can be set with the variable
 @code{org-agenda-start-with-follow-mode}.
-@c
-@orgcmd{C-c C-x b,org-agenda-tree-to-indirect-buffer}
-Display the entire subtree of the current item in an indirect buffer.  With a
-numeric prefix argument N, go up to level N and then take that tree.  If N is
-negative, go up that many levels.  With a @kbd{C-u} prefix, do not remove the
-previously used indirect buffer.
-
-@orgcmd{C-c C-o,org-agenda-open-link}
-Follow a link in the entry.  This will offer a selection of any links in the
-text belonging to the referenced Org node.  If there is only one link, it
-will be followed without a selection prompt.
-
-@tsubheading{Change display}
+
+@item @kbd{C-c C-x b} (@code{org-agenda-tree-to-indirect-buffer})
+@kindex C-c C-x b
+@findex org-agenda-tree-to-indirect-buffer
+Display the entire subtree of the current item in an indirect
+buffer.  With a numeric prefix argument N, go up to level N and then
+take that tree.  If N is negative, go up that many levels.  With
+a @kbd{C-u} prefix, do not remove the previously used indirect
+buffer.
+
+@item @kbd{C-c C-o} (@code{org-agenda-open-link})
+@kindex C-c C-o
+@findex org-agenda-open-link
+Follow a link in the entry.  This offers a selection of any links in
+the text belonging to the referenced Org node.  If there is only one
+link, follow it without a selection prompt.
+@end table
+
+@anchor{Change display}
+@subheading Change display
+
+@cindex change agenda display
 @cindex display changing, in agenda
+
+@table @asis
+@item @kbd{A}
 @kindex A
-@item A
-Interactively select another agenda view and append it to the current view.
-@c
+Interactively select another agenda view and append it to the
+current view.
+
+@item @kbd{o}
 @kindex o
-@item o
 Delete other windows.
-@c
-@orgcmdkskc{v d,d,org-agenda-day-view}
-@xorgcmdkskc{v w,w,org-agenda-week-view}
-@xorgcmd{v t,org-agenda-fortnight-view}
-@xorgcmd{v m,org-agenda-month-view}
-@xorgcmd{v y,org-agenda-year-view}
-@xorgcmd{v @key{SPC},org-agenda-reset-view}
+
+@item @kbd{v d} or short @kbd{d} (@code{org-agenda-day-view})
+@kindex v d
+@kindex d
+@findex org-agenda-day-view
+Switch to day view.  When switching to day view, this setting
+becomes the default for subsequent agenda refreshes.  A numeric
+prefix argument may be used to jump directly to a specific day of
+the year.  For example, @kbd{32 d} jumps to February 1st.  When
+setting day view, a year may be encoded in the prefix argument as
+well.  For example, @kbd{200712 d} jumps to January 12, 2007.
+If such a year specification has only one or two digits, it is
+expanded into one of the 30 next years or the last 69 years.
+
+@item @kbd{v w} or short @kbd{w} (@code{org-agenda-week-view})
+@kindex v w
+@kindex w
+@findex org-agenda-week-view
+Switch to week view.  When switching week view, this setting becomes
+the default for subsequent agenda refreshes.  A numeric prefix
+argument may be used to jump directly to a specific day of the ISO
+week.  For example @kbd{9 w} to ISO week number 9.  When
+setting week view, a year may be encoded in the prefix argument as
+well.  For example, @kbd{200712 w} jumps to week 12 in 2007.
+If such a year specification has only one or two digits, it is
+expanded into one of the 30 next years or the last 69 years.
+
+@item @kbd{v m} (@code{org-agenda-month-view})
+@kindex v m
+@findex org-agenda-month-view
+Switch to month view.  Because month views are slow to create, they
+do not become the default for subsequent agenda refreshes.
+A numeric prefix argument may be used to jump directly to a specific
+day of the month.  When setting month view, a year may be encoded in
+the prefix argument as well.  For example, @kbd{200712 m} jumps
+to December, 2007.  If such a year specification has only one or two
+digits, it is expanded into one of the 30 next years or the last 69
+years.
+
+@item @kbd{v y} (@code{org-agenda-year-view})
+@kindex v y
+@findex org-agenda-year-view
+Switch to year view.  Because year views are slow to create, they do
+not become the default for subsequent agenda refreshes.  A numeric
+prefix argument may be used to jump directly to a specific day of
+the year.
+
+@item @kbd{v @key{SPC}} (@code{org-agenda-reset-view})
+@kindex v SPC
+@findex org-agenda-reset-view
 @vindex org-agenda-span
-Switch to day/week/month/year view.  When switching to day or week view, this
-setting becomes the default for subsequent agenda refreshes.  Since month and
-year views are slow to create, they do not become the default.  A numeric
-prefix argument may be used to jump directly to a specific day of the year,
-ISO week, month, or year, respectively.  For example, @kbd{32 d} jumps to
-February 1st, @kbd{9 w} to ISO week number 9.  When setting day, week, or
-month view, a year may be encoded in the prefix argument as well.  For
-example, @kbd{200712 w} will jump to week 12 in 2007.  If such a year
-specification has only one or two digits, it will be mapped to the interval
-1938--2037.  @kbd{v @key{SPC}} will reset to what is set in
-@code{org-agenda-span}.
-@c
-@orgcmd{f,org-agenda-later}
-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-current-span} 
days.
-@c
-@orgcmd{b,org-agenda-earlier}
+Reset the current view to @code{org-agenda-span}.
+
+@item @kbd{f} (@code{org-agenda-later})
+@kindex f
+@findex org-agenda-later
+Go forward in time to display the span following the current one.
+For example, if the display covers a week, switch to the following
+week.  With a prefix argument, repeat that many times.
+
+@item @kbd{b} (@code{org-agenda-earlier})
+@kindex b
+@findex org-agenda-earlier
 Go backward in time to display earlier dates.
-@c
-@orgcmd{.,org-agenda-goto-today}
+
+@item @kbd{.} (@code{org-agenda-goto-today})
+@kindex .
+@findex org-agenda-goto-today
 Go to today.
-@c
-@orgcmd{j,org-agenda-goto-date}
+
+@item @kbd{j} (@code{org-agenda-goto-date})
+@kindex j
+@findex org-agenda-goto-date
 Prompt for a date and go there.
-@c
-@orgcmd{J,org-agenda-clock-goto}
-Go to the currently clocked-in task @i{in the agenda buffer}.
-@c
-@orgcmd{D,org-agenda-toggle-diary}
+
+@item @kbd{J} (@code{org-agenda-clock-goto})
+@kindex J
+@findex org-agenda-clock-goto
+Go to the currently clocked-in task @emph{in the agenda buffer}.
+
+@item @kbd{D} (@code{org-agenda-toggle-diary})
+@kindex D
+@findex org-agenda-toggle-diary
 Toggle the inclusion of diary entries.  See @ref{Weekly/daily agenda}.
-@c
-@orgcmdkskc{v l,l,org-agenda-log-mode}
+
+@item @kbd{v l} or @kbd{v L} or short @kbd{l} (@code{org-agenda-log-mode})
+@kindex v l
+@kindex l
 @kindex v L
+@findex org-agenda-log-mode
 @vindex org-log-done
 @vindex org-agenda-log-mode-items
-Toggle Logbook mode.  In Logbook mode, entries that were marked DONE while
-logging was on (variable @code{org-log-done}) are shown in the agenda, as are
-entries that have been clocked on that day.  You can configure the entry
-types that should be included in log mode using the variable
-@code{org-agenda-log-mode-items}.  When called with a @kbd{C-u} prefix, show
-all possible logbook entries, including state changes.  When called with two
-prefix arguments @kbd{C-u C-u}, show only logging information, nothing else.
-@kbd{v L} is equivalent to @kbd{C-u v l}.
-@c
-@orgcmdkskc{v [,[,org-agenda-manipulate-query-add}
-Include inactive timestamps into the current view.  Only for weekly/daily
-agenda.
-@c
-@orgcmd{v a,org-agenda-archives-mode}
-@xorgcmd{v A,org-agenda-archives-mode 'files}
-@cindex Archives mode
-Toggle Archives mode.  In Archives mode, trees that are marked
-@code{ARCHIVED} are also scanned when producing the agenda.  When you use the
-capital @kbd{A}, even all archive files are included.  To exit archives mode,
-press @kbd{v a} again.
-@c
-@orgcmdkskc{v R,R,org-agenda-clockreport-mode}
+Toggle Logbook mode.  In Logbook mode, entries that were marked as
+done while logging was on (see the variable @code{org-log-done}) are
+shown in the agenda, as are entries that have been clocked on that
+day.  You can configure the entry types that should be included in
+log mode using the variable @code{org-agenda-log-mode-items}.  When
+called with a @kbd{C-u} prefix argument, show all possible
+logbook entries, including state changes.  When called with two
+prefix arguments @kbd{C-u C-u}, show only logging information,
+nothing else.  @kbd{v L} is equivalent to @kbd{C-u v l}.
+
+@item @kbd{v [} or short @kbd{[} (@code{org-agenda-manipulate-query-add})
+@kindex v [
+@kindex [
+@findex org-agenda-manipulate-query-add
+Include inactive timestamps into the current view.  Only for
+weekly/daily agenda.
+
+@item @kbd{v a} (@code{org-agenda-archives-mode})
+@kindex v a
+@findex org-agenda-archives-mode
+Toggle Archives mode.  In Archives mode, trees that are archived
+(see @ref{Internal archiving}) are also scanned when producing the
+agenda.  To exit archives mode, press @kbd{v a} again.
+
+@item @kbd{v A}
+@kindex v A
+Toggle Archives mode.  Include all archive files as well.
+
+@item @kbd{v R} or short @kbd{R} (@code{org-agenda-clockreport-mode})
+@kindex v R
+@kindex R
+@findex org-agenda-clockreport-mode
 @vindex org-agenda-start-with-clockreport-mode
 @vindex org-clock-report-include-clocking-task
-Toggle Clockreport mode.  In Clockreport mode, the daily/weekly agenda will
-always show a table with the clocked times for the time span and file scope
-covered by the current agenda view.  The initial setting for this mode in new
-agenda buffers can be set with the variable
-@code{org-agenda-start-with-clockreport-mode}.  By using a prefix argument
-when toggling this mode (i.e., @kbd{C-u R}), the clock table will not show
-contributions from entries that are hidden by agenda filtering@footnote{Only
-tags filtering will be respected here, effort filtering is ignored.}.  See
-also the variable @code{org-clock-report-include-clocking-task}.
-@c
-@orgkey{v c}
+Toggle Clockreport mode.  In Clockreport mode, the daily/weekly
+agenda always shows a table with the clocked times for the time span
+and file scope covered by the current agenda view.  The initial
+setting for this mode in new agenda buffers can be set with the
+variable @code{org-agenda-start-with-clockreport-mode}.  By using
+a prefix argument when toggling this mode (i.e., @kbd{C-u R}),
+the clock table does not show contributions from entries that are
+hidden by agenda filtering@footnote{Only tags filtering is respected here, 
effort filtering is
+ignored.}.  See also the variable
+@code{org-clock-report-include-clocking-task}.
+
+@item @kbd{v c}
+@kindex v c
 @vindex org-agenda-clock-consistency-checks
-Show overlapping clock entries, clocking gaps, and other clocking problems in
-the current agenda range.  You can then visit clocking lines and fix them
-manually.  See the variable @code{org-agenda-clock-consistency-checks} for
-information on how to customize the definition of what constituted a clocking
-problem.  To return to normal agenda display, press @kbd{l} to exit Logbook
+Show overlapping clock entries, clocking gaps, and other clocking
+problems in the current agenda range.  You can then visit clocking
+lines and fix them manually.  See the variable
+@code{org-agenda-clock-consistency-checks} for information on how to
+customize the definition of what constituted a clocking problem.  To
+return to normal agenda display, press @kbd{l} to exit Logbook
 mode.
-@c
-@orgcmdkskc{v E,E,org-agenda-entry-text-mode}
+
+@item @kbd{v E} or short @kbd{E} (@code{org-agenda-entry-text-mode})
+@kindex v E
+@kindex E
+@findex org-agenda-entry-text-mode
 @vindex org-agenda-start-with-entry-text-mode
 @vindex org-agenda-entry-text-maxlines
-Toggle entry text mode.  In entry text mode, a number of lines from the Org
-outline node referenced by an agenda line will be displayed below the line.
-The maximum number of lines is given by the variable
-@code{org-agenda-entry-text-maxlines}.  Calling this command with a numeric
-prefix argument will temporarily modify that number to the prefix value.
-@c
-@orgcmd{G,org-agenda-toggle-time-grid}
+Toggle entry text mode.  In entry text mode, a number of lines from
+the Org outline node referenced by an agenda line are displayed
+below the line.  The maximum number of lines is given by the
+variable @code{org-agenda-entry-text-maxlines}.  Calling this command
+with a numeric prefix argument temporarily modifies that number to
+the prefix value.
+
+@item @kbd{G} (@code{org-agenda-toggle-time-grid})
+@kindex G
 @vindex org-agenda-use-time-grid
 @vindex org-agenda-time-grid
 Toggle the time grid on and off.  See also the variables
 @code{org-agenda-use-time-grid} and @code{org-agenda-time-grid}.
-@c
-@orgcmd{r,org-agenda-redo}
+
+@item @kbd{r} (@code{org-agenda-redo})
+@itemx @kbd{g}
+@kindex r
+@kindex g
+@findex org-agenda-redo
 Recreate the agenda buffer, for example to reflect the changes after
 modification of the timestamps of items with @kbd{S-@key{LEFT}} and
-@kbd{S-@key{RIGHT}}.  When the buffer is the global TODO list, a prefix
-argument is interpreted to create a selective list for a specific TODO
-keyword.
-@orgcmd{g,org-agenda-redo}
-Same as @kbd{r}.
-@c
-@orgcmdkskc{C-x C-s,s,org-save-all-org-buffers}
-Save all Org buffers in the current Emacs session, and also the locations of
-IDs.
-@c
-@orgcmd{C-c C-x C-c,org-agenda-columns}
+@kbd{S-@key{RIGHT}}.  When the buffer is the global TODO list,
+a prefix argument is interpreted to create a selective list for
+a specific TODO keyword.
+
+@item @kbd{C-x C-s} or short @kbd{s} (@code{org-save-all-org-buffers})
+@kindex C-x C-s
+@findex org-save-all-org-buffers
+@kindex s
+Save all Org buffers in the current Emacs session, and also the
+locations of IDs.
+
+@item @kbd{C-c C-x C-c} (@code{org-agenda-columns})
+@kindex C-c C-x C-c
+@findex org-agenda-columns
 @vindex org-columns-default-format
-Invoke column view (@pxref{Column view}) in the agenda buffer.  The column
-view format is taken from the entry at point, or (if there is no entry at
-point), from the first entry in the agenda view.  So whatever the format for
-that entry would be in the original buffer (taken from a property, from a
-@code{#+COLUMNS} line, or from the default variable
-@code{org-columns-default-format}), will be used in the agenda.
-
-@orgcmd{C-c C-x >,org-agenda-remove-restriction-lock}
-Remove the restriction lock on the agenda, if it is currently restricted to a
-file or subtree (@pxref{Agenda files}).
-
-@tsubheading{Secondary filtering and query editing}
-
-For a detailed description of these commands, @pxref{Filtering/limiting
-agenda items}.
-
-@orgcmd{/,org-agenda-filter-by-tag}
-Filter the agenda view with respect to a tag and/or effort estimates.
+Invoke column view (see @ref{Column View}) in the agenda buffer.  The
+column view format is taken from the entry at point, or, if there is
+no entry at point, from the first entry in the agenda view.  So
+whatever the format for that entry would be in the original buffer
+(taken from a property, from a @samp{COLUMNS} keyword, or from the
+default variable @code{org-columns-default-format}) is used in the
+agenda.
 
-@orgcmd{<,org-agenda-filter-by-category}
-Filter the current agenda view with respect to the category of the item at
-point.
+@item @kbd{C-c C-x >} (@code{org-agenda-remove-restriction-lock})
+@kindex C-c C-x >
+@findex org-agenda-remove-restriction-lock
+Remove the restriction lock on the agenda, if it is currently
+restricted to a file or subtree (see @ref{Agenda Files}).
 
-@orgcmd{^,org-agenda-filter-by-top-headline}
-Filter the current agenda view and only display the siblings and the parent
-headline of the one at point.
+@item @kbd{M-@key{UP}} (@code{org-agenda-drag-line-backward})
+@kindex M-UP
+@findex org-agenda-drag-line-backward
+Drag the line at point backward one line.  With a numeric prefix
+argument, drag backward by that many lines.
 
-@orgcmd{=,org-agenda-filter-by-regexp}
-Filter the agenda view by a regular expression.
+Moving agenda lines does not persist after an agenda refresh and
+does not modify the contributing Org files.
 
-@orgcmd{_,org-agenda-filter-by-effort}
-Filter the agenda view with respect to effort estimates.
+@item @kbd{M-@key{DOWN}} (@code{org-agenda-drag-line-forward})
+@kindex M-DOWN
+@findex org-agenda-drag-line-forward
+Drag the line at point forward one line.  With a numeric prefix
+argument, drag forward by that many lines.
+@end table
 
-@orgcmd{|,org-agenda-filter-remove-all}
-Remove all filters in the current agenda view.
+@anchor{Remote editing}
+@subheading Remote editing
 
-@tsubheading{Remote editing}
 @cindex remote editing, from agenda
 
-@item 0--9
+@table @asis
+@item @kbd{0--9}
 Digit argument.
-@c
+
+@item @kbd{C-_} (@code{org-agenda-undo})
+@kindex C-_
+@findex org-agenda-undo
 @cindex undoing remote-editing events
 @cindex remote editing, undo
-@orgcmd{C-_,org-agenda-undo}
 Undo a change due to a remote editing command.  The change is undone
 both in the agenda buffer and in the remote buffer.
-@c
-@orgcmd{t,org-agenda-todo}
+
+@item @kbd{t} (@code{org-agenda-todo})
+@kindex t
+@findex org-agenda-todo
 Change the TODO state of the item, both in the agenda and in the
-original org file.
-@c
-@orgcmd{C-S-@key{RIGHT},org-agenda-todo-nextset}
-@orgcmd{C-S-@key{LEFT},org-agenda-todo-previousset}
-Switch to the next/previous set of TODO keywords.
-@c
-@orgcmd{C-k,org-agenda-kill}
+original Org file. A prefix arg is passed through to the @code{org-todo}
+command, so for example a @kbd{C-u} prefix are will trigger
+taking a note to document the state change.
+
+@item @kbd{C-S-@key{RIGHT}} (@code{org-agenda-todo-nextset})
+@kindex C-S-RIGHT
+@findex org-agenda-todo-nextset
+Switch to the next set of TODO keywords.
+
+@item @kbd{C-S-@key{LEFT}}, @code{org-agenda-todo-previousset}
+@kindex C-S-LEFT
+Switch to the previous set of TODO keywords.
+
+@item @kbd{C-k} (@code{org-agenda-kill})
+@kindex C-k
+@findex org-agenda-kill
 @vindex org-agenda-confirm-kill
-Delete the current agenda item along with the entire subtree belonging
-to it in the original Org file.  If the text to be deleted remotely
-is longer than one line, the kill needs to be confirmed by the user.  See
-variable @code{org-agenda-confirm-kill}.
-@c
-@orgcmd{C-c C-w,org-agenda-refile}
+Delete the current agenda item along with the entire subtree
+belonging to it in the original Org file.  If the text to be deleted
+remotely is longer than one line, the kill needs to be confirmed by
+the user.  See variable @code{org-agenda-confirm-kill}.
+
+@item @kbd{C-c C-w} (@code{org-agenda-refile})
+@kindex C-c C-w
+@findex org-agenda-refile
 Refile the entry at point.
-@c
-@orgcmdkskc{C-c C-x C-a,a,org-agenda-archive-default-with-confirmation}
+
+@item @kbd{C-c C-x C-a} or short @kbd{a} 
(@code{org-agenda-archive-default-with-confirmation})
+@kindex C-c C-x C-a
+@kindex a
+@findex org-agenda-archive-default-with-confirmation
 @vindex org-archive-default-command
-Archive the subtree corresponding to the entry at point using the default
-archiving command set in @code{org-archive-default-command}.  When using the
-@code{a} key, confirmation will be required.
-@c
-@orgcmd{C-c C-x a,org-agenda-toggle-archive-tag}
-Toggle the ARCHIVE tag for the current headline.
-@c
-@orgcmd{C-c C-x A,org-agenda-archive-to-archive-sibling}
+Archive the subtree corresponding to the entry at point using the
+default archiving command set in @code{org-archive-default-command}.
+When using the @kbd{a} key, confirmation is required.
+
+@item @kbd{C-c C-x a} (@code{org-agenda-toggle-archive-tag})
+@kindex C-c C-x a
+@findex org-agenda-toggle-archive-tag
+Toggle the archive tag (see @ref{Internal archiving}) for the current
+headline.
+
+@item @kbd{C-c C-x A} (@code{org-agenda-archive-to-archive-sibling})
+@kindex C-c C-x A
+@findex org-agenda-archive-to-archive-sibling
 Move the subtree corresponding to the current entry to its @emph{archive
 sibling}.
-@c
-@orgcmdkskc{C-c C-x C-s,$,org-agenda-archive}
-Archive the subtree corresponding to the current headline.  This means the
-entry will be moved to the configured archive location, most likely a
-different file.
-@c
-@orgcmd{T,org-agenda-show-tags}
+
+@item @kbd{C-c C-x C-s} or short @kbd{$} (@code{org-agenda-archive})
+@kindex C-c C-x C-s
+@kindex $
+@findex org-agenda-archive
+Archive the subtree corresponding to the current headline.  This
+means the entry is moved to the configured archive location, most
+likely a different file.
+
+@item @kbd{T} (@code{org-agenda-show-tags})
+@kindex T
+@findex org-agenda-show-tags
 @vindex org-agenda-show-inherited-tags
-Show all tags associated with the current item.  This is useful if you have
-turned off @code{org-agenda-show-inherited-tags}, but still want to see all
-tags of a headline occasionally.
-@c
-@orgcmd{:,org-agenda-set-tags}
-Set tags for the current headline.  If there is an active region in the
-agenda, change a tag for all headings in the region.
-@c
+Show all tags associated with the current item.  This is useful if
+you have turned off @code{org-agenda-show-inherited-tags}, but still want
+to see all tags of a headline occasionally.
+
+@item @kbd{:} (@code{org-agenda-set-tags})
+@kindex :
+@findex org-agenda-set-tags
+Set tags for the current headline.  If there is an active region in
+the agenda, change a tag for all headings in the region.
+
+@item @kbd{,} (@code{org-agenda-priority})
 @kindex ,
-@item ,
-Set the priority for the current item (@command{org-agenda-priority}).
-Org mode prompts for the priority character.  If you reply with @key{SPC},
-the priority cookie is removed from the entry.
-@c
-@orgcmd{P,org-agenda-show-priority}
+@findex org-agenda-priority
+Set the priority for the current item.  Org mode prompts for the
+priority character.  If you reply with @kbd{@key{SPC}}, the priority
+cookie is removed from the entry.
+
+@item @kbd{P} (@code{org-agenda-show-priority})
+@kindex P
+@findex org-agenda-show-priority
 Display weighted priority of current item.
-@c
-@orgcmdkkc{+,S-@key{UP},org-agenda-priority-up}
-Increase the priority of the current item.  The priority is changed in
-the original buffer, but the agenda is not resorted.  Use the @kbd{r}
-key for this.
-@c
-@orgcmdkkc{-,S-@key{DOWN},org-agenda-priority-down}
+
+@item @kbd{+} or @kbd{S-@key{UP}} (@code{org-agenda-priority-up})
+@kindex +
+@kindex S-UP
+@findex org-agenda-priority-up
+Increase the priority of the current item.  The priority is changed
+in the original buffer, but the agenda is not resorted.  Use the
+@kbd{r} key for this.
+
+@item @kbd{-} or @kbd{S-@key{DOWN}} (@code{org-agenda-priority-down})
+@kindex -
+@kindex S-DOWN
+@findex org-agenda-priority-down
 Decrease the priority of the current item.
-@c
-@orgcmdkkc{z,C-c C-z,org-agenda-add-note}
+
+@item @kbd{C-c C-z} or short @kbd{z} (@code{org-agenda-add-note})
+@kindex z
+@kindex C-c C-z
+@findex org-agenda-add-note
 @vindex org-log-into-drawer
-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
+Add a note to the entry.  This note is recorded, and then filed to
+the same location where state change notes are put.  Depending on
 @code{org-log-into-drawer}, this may be inside a drawer.
-@c
-@orgcmd{C-c C-a,org-attach}
+
+@item @kbd{C-c C-a} (@code{org-attach})
+@kindex C-c C-a
+@findex org-attach
 Dispatcher for all command related to attachments.
-@c
-@orgcmd{C-c C-s,org-agenda-schedule}
-Schedule this item.  With prefix arg remove the scheduling timestamp
-@c
-@orgcmd{C-c C-d,org-agenda-deadline}
-Set a deadline for this item.  With prefix arg remove the deadline.
-@c
-@orgcmd{S-@key{RIGHT},org-agenda-do-date-later}
-Change the timestamp associated with the current line by one day into the
-future.  If the date is in the past, the first call to this command will move
-it to today.@*
-With a numeric prefix argument, change it by that many days.  For example,
-@kbd{3 6 5 S-@key{RIGHT}} will change it by a year.  With a @kbd{C-u} prefix,
-change the time by one hour.  If you immediately repeat the command, it will
-continue to change hours even without the prefix arg.  With a double @kbd{C-u
-C-u} prefix, do the same for changing minutes.@*
-The stamp is changed in the original Org file, but the change is not directly
-reflected in the agenda buffer.  Use @kbd{r} or @kbd{g} to update the buffer.
-@c
-@orgcmd{S-@key{LEFT},org-agenda-do-date-earlier}
+
+@item @kbd{C-c C-s} (@code{org-agenda-schedule})
+@kindex C-c C-s
+@findex org-agenda-schedule
+Schedule this item.  With a prefix argument, remove the
+scheduling timestamp
+
+@item @kbd{C-c C-d} (@code{org-agenda-deadline})
+@kindex C-c C-d
+@findex org-agenda-deadline
+Set a deadline for this item.  With a prefix argument, remove the
+deadline.
+
+@item @kbd{S-@key{RIGHT}} (@code{org-agenda-do-date-later})
+@kindex S-RIGHT
+@findex org-agenda-do-date-later
+Change the timestamp associated with the current line by one day
+into the future.  If the date is in the past, the first call to this
+command moves it to today.  With a numeric prefix argument, change
+it by that many days.  For example, @kbd{3 6 5 S-@key{RIGHT}} changes
+it by a year.  With a @kbd{C-u} prefix, change the time by one
+hour.  If you immediately repeat the command, it will continue to
+change hours even without the prefix argument.  With a double
+@kbd{C-u C-u} prefix, do the same for changing minutes.  The
+stamp is changed in the original Org file, but the change is not
+directly reflected in the agenda buffer.  Use @kbd{r} or
+@kbd{g} to update the buffer.
+
+@item @kbd{S-@key{LEFT}} (@code{org-agenda-do-date-earlier})
+@kindex S-LEFT
+@findex org-agenda-do-date-earlier
 Change the timestamp associated with the current line by one day
 into the past.
-@c
-@orgcmd{>,org-agenda-date-prompt}
-Change the timestamp associated with the current line.  The key @kbd{>} has
-been chosen, because it is the same as @kbd{S-.}  on my keyboard.
-@c
-@orgcmd{I,org-agenda-clock-in}
-Start the clock on the current item.  If a clock is running already, it
-is stopped first.
-@c
-@orgcmd{O,org-agenda-clock-out}
+
+@item @kbd{>} (@code{org-agenda-date-prompt})
+@kindex >
+@findex org-agenda-date-prompt
+Change the timestamp associated with the current line.  The key
+@kbd{>} has been chosen, because it is the same as
+@kbd{S-.}  on my keyboard.
+
+@item @kbd{I} (@code{org-agenda-clock-in})
+@kindex I
+@findex org-agenda-clock-in
+Start the clock on the current item.  If a clock is running already,
+it is stopped first.
+
+@item @kbd{O} (@code{org-agenda-clock-out})
+@kindex O
+@findex org-agenda-clock-out
 Stop the previously started clock.
-@c
-@orgcmd{X,org-agenda-clock-cancel}
+
+@item @kbd{X} (@code{org-agenda-clock-cancel})
+@kindex X
+@findex org-agenda-clock-cancel
 Cancel the currently running clock.
-@c
-@orgcmd{J,org-agenda-clock-goto}
+
+@item @kbd{J} (@code{org-agenda-clock-goto})
+@kindex J
+@findex org-agenda-clock-goto
 Jump to the running clock in another window.
-@c
-@orgcmd{k,org-agenda-capture}
-Like @code{org-capture}, but use the date at point as the default date for
-the capture template.  See @code{org-capture-use-agenda-date} to make this
-the default behavior of @code{org-capture}.
+
+@item @kbd{k} (@code{org-agenda-capture})
+@kindex k
+@findex org-agenda-capture
 @cindex capturing, from agenda
 @vindex org-capture-use-agenda-date
+Like @code{org-capture}, but use the date at point as the default date
+for the capture template.  See @code{org-capture-use-agenda-date} to make
+this the default behavior of @code{org-capture}.
+@end table
 
-@tsubheading{Dragging agenda lines forward/backward}
-@cindex dragging, agenda lines
-
-@orgcmd{M-<up>,org-agenda-drag-line-backward}
-Drag the line at point backward one line@footnote{Moving agenda lines does
-not persist after an agenda refresh and does not modify the contributing
-@file{.org} files}.  With a numeric prefix argument, drag backward by that
-many lines.
-
-@orgcmd{M-<down>,org-agenda-drag-line-forward}
-Drag the line at point forward one line.  With a numeric prefix argument,
-drag forward by that many lines.
+@anchor{Bulk remote editing selected entries}
+@subheading Bulk remote editing selected entries
 
-@tsubheading{Bulk remote editing selected entries}
 @cindex remote editing, bulk, from agenda
 @vindex org-agenda-bulk-custom-functions
 
-@orgcmd{m,org-agenda-bulk-mark}
-Mark the entry at point for bulk action.  With numeric prefix argument, mark
-that many successive entries.
-@c
-@orgcmd{*,org-agenda-bulk-mark-all}
+@table @asis
+@item @kbd{m} (@code{org-agenda-bulk-mark})
+@kindex m
+@findex org-agenda-bulk-mark
+
+Mark the entry at point for bulk action.  If there is an active
+region in the agenda, mark the entries in the region.  With numeric
+prefix argument, mark that many successive entries.
+
+@item @kbd{*} (@code{org-agenda-bulk-mark-all})
+@kindex *
+@findex org-agenda-bulk-mark-all
+
 Mark all visible agenda entries for bulk action.
-@c
-@orgcmd{u,org-agenda-bulk-unmark}
-Unmark entry at point for bulk action.
-@c
-@orgcmd{U,org-agenda-bulk-remove-all-marks}
+
+@item @kbd{u} (@code{org-agenda-bulk-unmark})
+@kindex u
+@findex org-agenda-bulk-unmark
+
+Unmark entry for bulk action.
+
+@item @kbd{U} (@code{org-agenda-bulk-remove-all-marks})
+@kindex U
+@findex org-agenda-bulk-remove-all-marks
+
 Unmark all marked entries for bulk action.
-@c
-@orgcmd{M-m,org-agenda-bulk-toggle}
+
+@item @kbd{M-m} (@code{org-agenda-bulk-toggle})
+@kindex M-m
+@findex org-agenda-bulk-toggle
+
 Toggle mark of the entry at point for bulk action.
-@c
-@orgcmd{M-*,org-agenda-bulk-toggle-all}
-Toggle marks of all visible entries for bulk action.
-@c
-@orgcmd{%,org-agenda-bulk-mark-regexp}
+
+@item @kbd{M-*} (@code{org-agenda-bulk-toggle-all})
+@kindex M-*
+@findex org-agenda-bulk-toggle-all
+
+Toggle mark of every entry for bulk action.
+
+@item @kbd{%} (@code{org-agenda-bulk-mark-regexp})
+@kindex %
+@findex org-agenda-bulk-mark-regexp
+
 Mark entries matching a regular expression for bulk action.
-@c
-@orgcmd{B,org-agenda-bulk-action}
-Bulk action: act on all marked entries in the agenda.  This will prompt for
-another key to select the action to be applied.  The prefix arg to @kbd{B}
-will be passed through to the @kbd{s} and @kbd{d} commands, to bulk-remove
-these special timestamps.  By default, marks are removed after the bulk.  If
-you want them to persist, set @code{org-agenda-persistent-marks} to @code{t}
-or hit @kbd{p} at the prompt.
-
-@table @kbd
-@item *
+
+@item @kbd{B} (@code{org-agenda-bulk-action})
+@kindex B
+@findex org-agenda-bulk-action
+@vindex org-agenda-bulk-persistent-marks
+
+Bulk action: act on all marked entries in the agenda.  This prompts
+for another key to select the action to be applied.  The prefix
+argument to @kbd{B} is passed through to the @kbd{s} and
+@kbd{d} commands, to bulk-remove these special timestamps.  By
+default, marks are removed after the bulk.  If you want them to
+persist, set @code{org-agenda-bulk-persistent-marks} to @code{t} or hit
+@kbd{p} at the prompt.
+
+@table @asis
+@item @kbd{p}
 Toggle persistent marks.
-@item $
+
+@item @kbd{$}
 Archive all selected entries.
-@item A
-Archive entries by moving them to their respective archive siblings.
-@item t
-Change TODO state.  This prompts for a single TODO keyword and changes the
-state of all selected entries, bypassing blocking and suppressing logging
-notes (but not timestamps).
-@item +
+
+@item @kbd{A}
+Archive entries by moving them to their respective archive
+siblings.
+
+@item @kbd{t}
+Change TODO state.  This prompts for a single TODO keyword and
+changes the state of all selected entries, bypassing blocking and
+suppressing logging notes---but not timestamps.
+
+@item @kbd{+}
 Add a tag to all selected entries.
-@item -
+
+@item @kbd{-}
 Remove a tag from all selected entries.
-@item s
-Schedule all items to a new date.  To shift existing schedule dates by a
-fixed number of days, use something starting with double plus at the prompt,
-for example @samp{++8d} or @samp{++2w}.
-@item d
+
+@item @kbd{s}
+Schedule all items to a new date.  To shift existing schedule
+dates by a fixed number of days, use something starting with
+double plus at the prompt, for example @samp{++8d} or @samp{++2w}.
+
+@item @kbd{d}
 Set deadline to a specific date.
-@item r
-Prompt for a single refile target and move all entries.  The entries will no
-longer be in the agenda; refresh (@kbd{g}) to bring them back.
-@item S
-Reschedule randomly into the coming N days.  N will be prompted for.  With
-prefix arg (@kbd{C-u B S}), scatter only across weekdays.
-@item f
-Apply a function@footnote{You can also create persistent custom functions
-through @code{org-agenda-bulk-custom-functions}.} to marked entries.  For
-example, the function below sets the CATEGORY property of the entries to web.
+
+@item @kbd{r}
+Prompt for a single refile target and move all entries.  The
+entries are no longer in the agenda; refresh (@kbd{g}) to
+bring them back.
+
+@item @kbd{S}
+Reschedule randomly into the coming N days.  N is prompted for.
+With a prefix argument (@kbd{C-u B S}), scatter only across
+weekdays.
+
+@item @kbd{f}
+@vindex org-agenda-bulk-custom-functions
+Apply a function@footnote{You can also create persistent custom functions 
through
+@code{org-agenda-bulk-custom-functions}.} to marked entries.  For example, the
+function below sets the @samp{CATEGORY} property of the entries to
+@samp{web}.
 
 @lisp
-@group
 (defun set-category ()
   (interactive "P")
-  (let* ((marker (or (org-get-at-bol 'org-hd-marker)
-                     (org-agenda-error)))
-         (buffer (marker-buffer marker)))
-    (with-current-buffer buffer
-      (save-excursion
-        (save-restriction
-          (widen)
-          (goto-char marker)
-          (org-back-to-heading t)
-          (org-set-property "CATEGORY" "web"))))))
-@end group
+  (let ((marker (or (org-get-at-bol 'org-hd-marker)
+                    (org-agenda-error))))
+    (org-with-point-at marker
+      (org-back-to-heading t)
+      (org-set-property "CATEGORY" "web"))))
 @end lisp
 @end table
+@end table
+
+@anchor{Calendar commands}
+@subheading Calendar commands
 
-@tsubheading{Calendar commands}
 @cindex calendar commands, from agenda
 
-@orgcmd{c,org-agenda-goto-calendar}
-Open the Emacs calendar and move to the date at the agenda cursor.
-@c
-@orgcmd{c,org-calendar-goto-agenda}
-When in the calendar, compute and show the Org mode agenda for the
-date at the cursor.
-@c
+@table @asis
+@item @kbd{c} (@code{org-agenda-goto-calendar})
+@kindex c
+@findex org-agenda-goto-calendar
+Open the Emacs calendar and go to the date at point in the agenda.
+
+@item @kbd{c} (@code{org-calendar-goto-agenda})
+@kindex c
+@findex org-calendar-goto-agenda
+When in the calendar, compute and show the Org agenda for the date
+at point.
+
+@item @kbd{i} (@code{org-agenda-diary-entry})
+@kindex i
+@findex org-agenda-diary-entry
+
 @cindex diary entries, creating from agenda
-@orgcmd{i,org-agenda-diary-entry}
-@vindex org-agenda-diary-file
-Insert a new entry into the diary, using the date at the cursor and (for
-block entries) the date at the mark.  This will add to the Emacs diary
+Insert a new entry into the diary, using the date at point and (for
+block entries) the date at the mark.  This adds to the Emacs diary
 file@footnote{This file is parsed for the agenda when
-@code{org-agenda-include-diary} is set.}, in a way similar to the @kbd{i}
-command in the calendar.  The diary file will pop up in another window, where
-you can add the entry.
-
-If you configure @code{org-agenda-diary-file} to point to an Org mode file,
-Org will create entries (in Org mode syntax) in that file instead.  Most
-entries will be stored in a date-based outline tree that will later make it
-easy to archive appointments from previous months/years.  The tree will be
-built under an entry with a @code{DATE_TREE} property, or else with years as
-top-level entries.  Emacs will prompt you for the entry text---if you specify
-it, the entry will be created in @code{org-agenda-diary-file} without further
-interaction.  If you directly press @key{RET} at the prompt without typing
-text, the target file will be shown in another window for you to finish the
-entry there.  See also the @kbd{k r} command.
-@c
-@orgcmd{M,org-agenda-phases-of-moon}
-Show the phases of the moon for the three months around current date.
-@c
-@orgcmd{S,org-agenda-sunrise-sunset}
-Show sunrise and sunset times.  The geographical location must be set
-with calendar variables, see the documentation for the Emacs calendar.
-@c
-@orgcmd{C,org-agenda-convert-date}
-Convert the date at cursor into many other cultural and historic
-calendars.
-@c
-@orgcmd{H,org-agenda-holidays}
-Show holidays for three months around the cursor date.
+@code{org-agenda-include-diary} is set.}, in a way similar to the @kbd{i} 
command in the
+calendar.  The diary file pops up in another window, where you can
+add the entry.
 
-@item M-x org-icalendar-combine-agenda-files @key{RET}
-Export a single iCalendar file containing entries from all agenda files.
-This is a globally available command, and also available in the agenda menu.
+@vindex org-agenda-diary-file
+If you configure @code{org-agenda-diary-file} to point to an Org file,
+Org creates entries in that file instead.  Most entries are stored
+in a date-based outline tree that will later make it easy to archive
+appointments from previous months/years.  The tree is built under an
+entry with a @samp{DATE_TREE} property, or else with years as top-level
+entries.  Emacs prompts you for the entry text---if you specify it,
+the entry is created in @code{org-agenda-diary-file} without further
+interaction.  If you directly press @kbd{@key{RET}} at the prompt
+without typing text, the target file is shown in another window for
+you to finish the entry there.  See also the @kbd{k r} command.
+
+@item @kbd{M} (@code{org-agenda-phases-of-moon})
+@kindex M
+@findex org-agenda-phases-of-moon
+Show the phases of the moon for the three months around current
+date.
+
+@item @kbd{S} (@code{org-agenda-sunrise-sunset})
+@kindex S
+@findex org-agenda-sunrise-sunset
+Show sunrise and sunset times.  The geographical location must be
+set with calendar variables, see the documentation for the Emacs
+calendar.
+
+@item @kbd{C} (@code{org-agenda-convert-date})
+@kindex C
+@findex org-agenda-convert-date
+Convert the date at point into many other cultural and historic
+calendars.
+
+@item @kbd{H} (@code{org-agenda-holidays})
+@kindex H
+@findex org-agenda-holidays
+Show holidays for three months around point date.
+@end table
+
+@anchor{Quit and exit}
+@subheading Quit and exit
+
+@table @asis
+@item @kbd{q} (@code{org-agenda-quit})
+@kindex q
+@findex org-agenda-quit
 
-@tsubheading{Exporting to a file}
-@orgcmd{C-x C-w,org-agenda-write}
-@cindex exporting agenda views
-@cindex agenda views, exporting
-@vindex org-agenda-exporter-settings
-Write the agenda view to a file.  Depending on the extension of the selected
-file name, the view will be exported as HTML (@file{.html} or @file{.htm}),
-Postscript (@file{.ps}), PDF (@file{.pdf}), Org (@file{.org}) and plain text
-(any other extension).  When exporting to Org, only the body of original
-headlines are exported, not subtrees or inherited tags.  When called with a
-@kbd{C-u} prefix argument, immediately open the newly created file.  Use the
-variable @code{org-agenda-exporter-settings} to set options for
-@file{ps-print} and for @file{htmlize} to be used during export.
-
-@tsubheading{Quit and Exit}
-@orgcmd{q,org-agenda-quit}
 Quit agenda, remove the agenda buffer.
-@c
+
+@item @kbd{x} (@code{org-agenda-exit})
+@kindex x
+@findex org-agenda-exit
+
 @cindex agenda files, removing buffers
-@orgcmd{x,org-agenda-exit}
-Exit agenda, remove the agenda buffer and all buffers loaded by Emacs
-for the compilation of the agenda.  Buffers created by the user to
-visit Org files will not be removed.
+Exit agenda, remove the agenda buffer and all buffers loaded by
+Emacs for the compilation of the agenda.  Buffers created by the
+user to visit Org files are not removed.
 @end table
 
+@node Custom Agenda Views
+@section Custom Agenda Views
 
-@node Custom agenda views
-@section Custom agenda views
 @cindex custom agenda views
 @cindex agenda views, custom
 
 Custom agenda commands serve two purposes: to store and quickly access
-frequently used TODO and tags searches, and to create special composite
-agenda buffers.  Custom agenda commands will be accessible through the
-dispatcher (@pxref{Agenda dispatcher}), just like the default commands.
+frequently used TODO and tags searches, and to create special
+composite agenda buffers.  Custom agenda commands are accessible
+through the dispatcher (see @ref{Agenda Dispatcher}), just like the
+default commands.
 
 @menu
-* Storing searches::            Type once, use often
-* Block agenda::                All the stuff you need in a single buffer
-* Setting options::             Changing the rules
+* Storing searches::             Type once, use often.
+* Block agenda::                 All the stuff you need in a single buffer.
+* Setting options::              Changing the rules.
 @end menu
 
 @node Storing searches
@@ -9466,9 +10707,10 @@ dispatcher (@pxref{Agenda dispatcher}), just like the 
default commands.
 
 The first application of custom searches is the definition of keyboard
 shortcuts for frequently used searches, either creating an agenda
-buffer, or a sparse tree (the latter covering of course only the current
-buffer).
-@kindex C-c a C
+buffer, or a sparse tree (the latter covering of course only the
+current buffer).
+
+@kindex C @r{(Agenda dispatcher)}
 @vindex org-agenda-custom-commands
 @cindex agenda views, main example
 @cindex agenda, as an agenda views
@@ -9479,15 +10721,13 @@ buffer).
 @cindex todo-tree
 @cindex occur-tree
 @cindex tags-tree
-
 Custom commands are configured in the variable
 @code{org-agenda-custom-commands}.  You can customize this variable, for
-example by pressing @kbd{C-c a C}.  You can also directly set it with Emacs
-Lisp in the Emacs init file.  The following example contains all valid agenda
+example by pressing @kbd{C} from the agenda dispatcher (see @ref{Agenda 
Dispatcher}).  You can also directly set it with Emacs Lisp in
+the Emacs init file.  The following example contains all valid agenda
 views:
 
 @lisp
-@group
 (setq org-agenda-custom-commands
       '(("x" agenda)
         ("y" agenda*)
@@ -9497,77 +10737,81 @@ views:
         ("v" tags-todo "+boss-urgent")
         ("U" tags-tree "+boss-urgent")
         ("f" occur-tree "\\<FIXME\\>")
-        ("h" . "HOME+Name tags searches") ; description for "h" prefix
+        ("h" . "HOME+Name tags searches") ;description for "h" prefix
         ("hl" tags "+home+Lisa")
         ("hp" tags "+home+Peter")
         ("hk" tags "+home+Kim")))
-@end group
 @end lisp
 
-@noindent
 The initial string in each entry defines the keys you have to press
-after the dispatcher command @kbd{C-c a} in order to access the command.
-Usually this will be just a single character, but if you have many
-similar commands, you can also define two-letter combinations where the
-first character is the same in several combinations and serves as a
-prefix key@footnote{You can provide a description for a prefix key by
-inserting a cons cell with the prefix and the description.}.  The second
-parameter is the search type, followed by the string or regular
-expression to be used for the matching.  The example above will
-therefore define:
-
-@table @kbd
-@item C-c a x
-as a global search for agenda entries planned@footnote{@emph{Planned} means
-here that these entries have some planning information attached to them, like
-a time-stamp, a scheduled or a deadline string.  See
-@code{org-agenda-entry-types} on how to set what planning information will be
-taken into account.} this week/day.
-@item C-c a y
-as a global search for agenda entries planned this week/day, but only those
-with an hour specification like @code{[h]h:mm}---think of them as appointments.
-@item C-c a w
+after the dispatcher command in order to access the command.  Usually
+this is just a single character, but if you have many similar
+commands, you can also define two-letter combinations where the first
+character is the same in several combinations and serves as a prefix
+key@footnote{You can provide a description for a prefix key by inserting
+a cons cell with the prefix and the description.}.  The second parameter is 
the search type, followed by the
+string or regular expression to be used for the matching.  The example
+above will therefore define:
+
+@table @asis
+@item @kbd{x}
+as a global search for agenda entries planned@footnote{@emph{Planned} means 
here that these entries have some planning
+information attached to them, like a time-stamp, a scheduled or
+a deadline string.  See @code{org-agenda-entry-types} on how to set what
+planning information is taken into account.} this week/day.
+
+@item @kbd{y}
+as the same search, but only for entries with an hour specification
+like @samp{[h]h:mm}---think of them as appointments.
+
+@item @kbd{w}
 as a global search for TODO entries with @samp{WAITING} as the TODO
-keyword
-@item C-c a W
-as the same search, but only in the current buffer and displaying the
-results as a sparse tree
-@item C-c a u
-as a global tags search for headlines marked @samp{:boss:} but not
-@samp{:urgent:}
-@item C-c a v
-as the same search as @kbd{C-c a u}, but limiting the search to
-headlines that are also TODO items
-@item C-c a U
-as the same search as @kbd{C-c a u}, but only in the current buffer and
-displaying the result as a sparse tree
-@item C-c a f
-to create a sparse tree (again: current buffer only) with all entries
-containing the word @samp{FIXME}
-@item C-c a h
-as a prefix command for a HOME tags search where you have to press an
-additional key (@kbd{l}, @kbd{p} or @kbd{k}) to select a name (Lisa,
-Peter, or Kim) as additional tag to match.
+keyword.
+
+@item @kbd{W}
+as the same search, but only in the current buffer and displaying
+the results as a sparse tree.
+
+@item @kbd{u}
+as a global tags search for headlines tagged @samp{boss} but not
+@samp{urgent}.
+
+@item @kbd{v}
+The same search, but limiting it to headlines that are also TODO
+items.
+
+@item @kbd{U}
+as the same search, but only in the current buffer and displaying
+the result as a sparse tree.
+
+@item @kbd{f}
+to create a sparse tree (again, current buffer only) with all
+entries containing the word @samp{FIXME}.
+
+@item @kbd{h}
+as a prefix command for a @samp{HOME} tags search where you have to press
+an additional key (@kbd{l}, @kbd{p} or @kbd{k}) to
+select a name (Lisa, Peter, or Kim) as additional tag to match.
 @end table
 
-Note that the @code{*-tree} agenda views need to be called from an
-Org buffer as they operate on the current buffer only.
+Note that @code{*-tree} agenda views need to be called from an Org buffer
+as they operate on the current buffer only.
 
 @node Block agenda
 @subsection Block agenda
+
 @cindex block agenda
 @cindex agenda, with block views
 
 Another possibility is the construction of agenda views that comprise
 the results of @emph{several} commands, each of which creates a block in
 the agenda buffer.  The available commands include @code{agenda} for the
-daily or weekly agenda (as created with @kbd{C-c a a}), @code{alltodo}
-for the global TODO list (as constructed with @kbd{C-c a t}), and the
-matching commands discussed above: @code{todo}, @code{tags}, and
-@code{tags-todo}.  Here are two examples:
+daily or weekly agenda (as created with @kbd{a}) , @code{alltodo} for
+the global TODO list (as constructed with @kbd{t}), and the
+matching commands discussed above: @code{todo}, @code{tags}, and 
@code{tags-todo}.
+Here are two examples:
 
 @lisp
-@group
 (setq org-agenda-custom-commands
       '(("h" "Agenda and Home-related tasks"
          ((agenda "")
@@ -9577,30 +10821,29 @@ matching commands discussed above: @code{todo}, 
@code{tags}, and
          ((agenda "")
           (tags-todo "work")
           (tags "office")))))
-@end group
 @end lisp
 
 @noindent
-This will define @kbd{C-c a h} to create a multi-block view for stuff
-you need to attend to at home.  The resulting agenda buffer will contain
-your agenda for the current week, all TODO items that carry the tag
-@samp{home}, and also all lines tagged with @samp{garden}.  Finally the
-command @kbd{C-c a o} provides a similar view for office tasks.
+This defines @kbd{h} to create a multi-block view for stuff you
+need to attend to at home.  The resulting agenda buffer contains your
+agenda for the current week, all TODO items that carry the tag @samp{home},
+and also all lines tagged with @samp{garden}.  Finally the command
+@kbd{o} provides a similar view for office tasks.
 
 @node Setting options
 @subsection Setting options for custom commands
+
 @cindex options, for custom agenda views
 
 @vindex org-agenda-custom-commands
 Org mode contains a number of variables regulating agenda construction
 and display.  The global variables define the behavior for all agenda
-commands, including the custom commands.  However, if you want to change
-some settings just for a single custom view, you can do so.  Setting
-options requires inserting a list of variable names and values at the
-right spot in @code{org-agenda-custom-commands}.  For example:
+commands, including the custom commands.  However, if you want to
+change some settings just for a single custom view, you can do so.
+Setting options requires inserting a list of variable names and values
+at the right spot in @code{org-agenda-custom-commands}.  For example:
 
 @lisp
-@group
 (setq org-agenda-custom-commands
       '(("w" todo "WAITING"
          ((org-agenda-sorting-strategy '(priority-down))
@@ -9610,32 +10853,28 @@ right spot in @code{org-agenda-custom-commands}.  For 
example:
         ("N" search ""
          ((org-agenda-files '("~org/notes.org"))
           (org-agenda-text-search-extra-files nil)))))
-@end group
 @end lisp
 
 @noindent
-Now the @kbd{C-c a w} command will sort the collected entries only by
-priority, and the prefix format is modified to just say @samp{  Mixed: }
+Now the @kbd{w} command sorts the collected entries only by
+priority, and the prefix format is modified to just say @samp{Mixed:}
 instead of giving the category of the entry.  The sparse tags tree of
-@kbd{C-c a U} will now turn out ultra-compact, because neither the
-headline hierarchy above the match, nor the headline following the match
-will be shown.  The command @kbd{C-c a N} will do a text search limited
-to only a single file.
-
-@vindex org-agenda-custom-commands
-For command sets creating a block agenda,
-@code{org-agenda-custom-commands} has two separate spots for setting
-options.  You can add options that should be valid for just a single
-command in the set, and options that should be valid for all commands in
-the set.  The former are just added to the command entry; the latter
-must come after the list of command entries.  Going back to the block
-agenda example (@pxref{Block agenda}), let's change the sorting strategy
-for the @kbd{C-c a h} commands to @code{priority-down}, but let's sort
-the results for GARDEN tags query in the opposite order,
-@code{priority-up}.  This would look like this:
+@kbd{U} now turns out ultra-compact, because neither the headline
+hierarchy above the match, nor the headline following the match are
+shown.  The command @kbd{N} does a text search limited to only
+a single file.
+
+For command sets creating a block agenda, @code{org-agenda-custom-commands}
+has two separate spots for setting options.  You can add options that
+should be valid for just a single command in the set, and options that
+should be valid for all commands in the set.  The former are just
+added to the command entry; the latter must come after the list of
+command entries.  Going back to the block agenda example (see @ref{Block 
agenda}), let's change the sorting strategy for the @kbd{h}
+commands to @code{priority-down}, but let's sort the results for @samp{garden}
+tags query in the opposite order, @code{priority-up}.  This would look like
+this:
 
 @lisp
-@group
 (setq org-agenda-custom-commands
       '(("h" "Agenda and Home-related tasks"
          ((agenda)
@@ -9647,30 +10886,31 @@ the results for GARDEN tags query in the opposite 
order,
          ((agenda)
           (tags-todo "work")
           (tags "office")))))
-@end group
 @end lisp
 
 As you see, the values and parentheses setting is a little complex.
 When in doubt, use the customize interface to set this variable---it
-fully supports its structure.  Just one caveat: when setting options in
-this interface, the @emph{values} are just Lisp expressions.  So if the
+fully supports its structure.  Just one caveat: when setting options
+in this interface, the @emph{values} are just Lisp expressions.  So if the
 value is a string, you need to add the double-quotes around the value
 yourself.
 
 @vindex org-agenda-custom-commands-contexts
-To control whether an agenda command should be accessible from a specific
-context, you can customize @code{org-agenda-custom-commands-contexts}.  Let's
-say for example that you have an agenda command @code{"o"} displaying a view
-that you only need when reading emails.  Then you would configure this option
-like this:
+To control whether an agenda command should be accessible from
+a specific context, you can customize
+@code{org-agenda-custom-commands-contexts}.  Let's say for example that you
+have an agenda command @kbd{o} displaying a view that you only
+need when reading emails.  Then you would configure this option like
+this:
 
 @lisp
 (setq org-agenda-custom-commands-contexts
       '(("o" (in-mode . "message-mode"))))
 @end lisp
 
-You can also tell that the command key @code{"o"} should refer to another
-command key @code{"r"}.  In that case, add this command key like this:
+You can also tell that the command key @kbd{o} should refer to
+another command key @kbd{r}.  In that case, add this command key
+like this:
 
 @lisp
 (setq org-agenda-custom-commands-contexts
@@ -9679,57 +10919,42 @@ command key @code{"r"}.  In that case, add this 
command key like this:
 
 See the docstring of the variable for more information.
 
-@node Exporting agenda views
-@section Exporting agenda views
+@node Exporting Agenda Views
+@section Exporting Agenda Views
+
 @cindex agenda views, exporting
 
-If you are away from your computer, it can be very useful to have a printed
-version of some agenda views to carry around.  Org mode can export custom
-agenda views as plain text, HTML@footnote{You need to install
-@file{htmlize.el} from @uref{https://github.com/hniksic/emacs-htmlize,Hrvoje
-Nikšić's repository.}}, Postscript, PDF@footnote{To create PDF output, the
-ghostscript @file{ps2pdf} utility must be installed on the system.  Selecting
-a PDF file will also create the postscript file.}, and iCalendar files.  If
-you want to do this only occasionally, use the command
-
-@table @kbd
-@orgcmd{C-x C-w,org-agenda-write}
+If you are away from your computer, it can be very useful to have
+a printed version of some agenda views to carry around.  Org mode can
+export custom agenda views as plain text, HTML@footnote{For HTML you need to 
install Hrvoje Nikšić's @samp{htmlize.el}
+as an Emacs package from MELPA or from 
@uref{https://github.com/hniksic/emacs-htmlize, Hrvoje Nikšić's repository}.}, 
Postscript,
+PDF@footnote{To create PDF output, the Ghostscript ps2pdf utility must be
+installed on the system.  Selecting a PDF file also creates the
+postscript file.}, and iCalendar files.  If you want to do this only
+occasionally, use the following command:
+
+@table @asis
+@item @kbd{C-x C-w} (@code{org-agenda-write})
+@kindex C-x C-w
+@findex org-agenda-write
 @cindex exporting agenda views
 @cindex agenda views, exporting
+
 @vindex org-agenda-exporter-settings
-Write the agenda view to a file.  Depending on the extension of the selected
-file name, the view will be exported as HTML (extension @file{.html} or
-@file{.htm}), Postscript (extension @file{.ps}), iCalendar (extension
-@file{.ics}), or plain text (any other extension).  Use the variable
-@code{org-agenda-exporter-settings} to set options for @file{ps-print} and
-for @file{htmlize} to be used during export, for example
-
-@vindex org-agenda-add-entry-text-maxlines
-@vindex htmlize-output-type
-@vindex ps-number-of-columns
-@vindex ps-landscape-mode
-@lisp
-(setq org-agenda-exporter-settings
-      '((ps-number-of-columns 2)
-        (ps-landscape-mode t)
-        (org-agenda-add-entry-text-maxlines 5)
-        (htmlize-output-type 'css)))
-@end lisp
+Write the agenda view to a file.
 @end table
 
-If you need to export certain agenda views frequently, you can associate
-any custom agenda command with a list of output file names
-@footnote{If you want to store standard views like the weekly agenda
-or the global TODO list as well, you need to define custom commands for
-them in order to be able to specify file names.}.  Here is an example
-that first defines custom commands for the agenda and the global
-TODO list, together with a number of files to which to export them.
-Then we define two block agenda commands and specify file names for them
-as well.  File names can be relative to the current working directory,
-or absolute.
+If you need to export certain agenda views frequently, you can
+associate any custom agenda command with a list of output file
+names@footnote{If you want to store standard views like the weekly agenda or
+the global TODO list as well, you need to define custom commands for
+them in order to be able to specify file names.}.  Here is an example that 
first defines custom commands
+for the agenda and the global TODO list, together with a number of
+files to which to export them.  Then we define two block agenda
+commands and specify file names for them as well.  File names can be
+relative to the current working directory, or absolute.
 
 @lisp
-@group
 (setq org-agenda-custom-commands
       '(("X" agenda "" nil ("agenda.html" "agenda.ps"))
         ("Y" alltodo "" nil ("todo.html" "todo.txt" "todo.ps"))
@@ -9745,16 +10970,15 @@ or absolute.
           (tags "office"))
          nil
          ("~/views/office.ps" "~/calendars/office.ics"))))
-@end group
 @end lisp
 
-The extension of the file name determines the type of export.  If it is
-@file{.html}, Org mode will try to use the @file{htmlize.el} package to
-convert the buffer to HTML and save it to this file name.  If the extension
-is @file{.ps}, @code{ps-print-buffer-with-faces} is used to produce
-Postscript output.  If the extension is @file{.ics}, iCalendar export is run
-export over all files that were used to construct the agenda, and limit the
-export to entries listed in the agenda.  Any other extension produces a plain
+The extension of the file name determines the type of export.  If it
+is @samp{.html}, Org mode uses the htmlize package to convert the buffer to
+HTML and save it to this file name.  If the extension is @samp{.ps},
+@code{ps-print-buffer-with-faces} is used to produce Postscript output.  If
+the extension is @samp{.ics}, iCalendar export is run export over all files
+that were used to construct the agenda, and limit the export to
+entries listed in the agenda.  Any other extension produces a plain
 ASCII file.
 
 The export files are @emph{not} created when you use one of those
@@ -9762,8 +10986,10 @@ commands interactively because this might use too much 
overhead.
 Instead, there is a special command to produce @emph{all} specified
 files in one step:
 
-@table @kbd
-@orgcmd{C-c a e,org-store-agenda-views}
+@table @asis
+@item @kbd{e} (@code{org-store-agenda-views})
+@kindex e @r{(Agenda dispatcher)}
+@findex org-store-agenda-views
 Export all agenda views that have export file names associated with
 them.
 @end table
@@ -9783,24 +11009,37 @@ set options for the export commands.  For example:
 @end lisp
 
 @noindent
+@vindex org-agenda-exporter-settings
 This command sets two options for the Postscript exporter, to make it
-print in two columns in landscape format---the resulting page can be cut
-in two and then used in a paper agenda.  The remaining settings modify
-the agenda prefix to omit category and scheduling information, and
-instead include a checkbox to check off items.  We also remove the tags
-to make the lines compact, and we don't want to use colors for the
-black-and-white printer.  Settings specified in
-@code{org-agenda-exporter-settings} will also apply, but the settings
-in @code{org-agenda-custom-commands} take precedence.
+print in two columns in landscape format---the resulting page can be
+cut in two and then used in a paper agenda.  The remaining settings
+modify the agenda prefix to omit category and scheduling information,
+and instead include a checkbox to check off items.  We also remove the
+tags to make the lines compact, and we do not want to use colors for
+the black-and-white printer.  Settings specified in
+@code{org-agenda-exporter-settings} also apply, e.g.,
+
+@lisp
+(setq org-agenda-exporter-settings
+      '((ps-number-of-columns 2)
+        (ps-landscape-mode t)
+        (org-agenda-add-entry-text-maxlines 5)
+        (htmlize-output-type 'css)))
+@end lisp
 
 @noindent
-From the command line you may also use
+but the settings in @code{org-agenda-custom-commands} take precedence.
+
+From the command line you may also use:
+
 @example
 emacs -eval (org-batch-store-agenda-views) -kill
 @end example
+
 @noindent
-or, if you need to modify some parameters@footnote{Quoting depends on the
-system you use, please check the FAQ for examples.}
+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-span (quote month)                     \
@@ -9809,114 +11048,129 @@ emacs -eval '(org-batch-store-agenda-views           
           \
               org-agenda-files (quote ("~/org/project.org")))'  \
       -kill
 @end example
+
 @noindent
-which will create the agenda views restricted to the file
-@file{~/org/project.org}, without diary entries and with a 30-day
-extent.
+which creates the agenda views restricted to the file
+@samp{~/org/project.org}, without diary entries and with a 30-day extent.
 
 You can also extract agenda information in a way that allows further
-processing by other programs.  See @ref{Extracting agenda information}, for
+processing by other programs.  See @ref{Extracting Agenda Information}, for
 more information.
 
+@node Agenda Column View
+@section Using Column View in the Agenda
 
-@node Agenda column view
-@section Using column view in the agenda
 @cindex column view, in agenda
 @cindex agenda, column view
 
-Column view (@pxref{Column view}) is normally used to view and edit
-properties embedded in the hierarchical structure of an Org file.  It can be
-quite useful to use column view also from the agenda, where entries are
-collected by certain criteria.
+Column view (see @ref{Column View}) is normally used to view and edit
+properties embedded in the hierarchical structure of an Org file.  It
+can be quite useful to use column view also from the agenda, where
+entries are collected by certain criteria.
+
+@table @asis
+@item @kbd{C-c C-x C-c} (@code{org-agenda-columns})
+@kindex C-c C-x C-c
+@findex org-agenda-columns
 
-@table @kbd
-@orgcmd{C-c C-x C-c,org-agenda-columns}
 Turn on column view in the agenda.
 @end table
 
-To understand how to use this properly, it is important to realize that the
-entries in the agenda are no longer in their proper outline environment.
-This causes the following issues:
+To understand how to use this properly, it is important to realize
+that the entries in the agenda are no longer in their proper outline
+environment.  This causes the following issues:
 
 @enumerate
 @item
+@vindex org-columns-default-format-for-agenda
 @vindex org-columns-default-format
-@vindex org-overriding-columns-format
-Org needs to make a decision which @code{COLUMNS} format to use.  Since the
-entries in the agenda are collected from different files, and different files
-may have different @code{COLUMNS} formats, this is a non-trivial problem.
-Org first checks if the variable @code{org-agenda-overriding-columns-format}
-is currently set, and if so, takes the format from there.  Otherwise it takes
-the format associated with the first item in the agenda, or, if that item
-does not have a specific format---defined in a property, or in its file---it
-uses @code{org-columns-default-format}.
-
-@item
-@cindex property, special, @code{CLOCKSUM}
-If any of the columns has a summary type defined (@pxref{Column attributes}),
-turning on column view in the agenda will visit all relevant agenda files and
-make sure that the computations of this property are up to date.  This is
-also true for the special @code{CLOCKSUM} property.  Org will then sum the
-values displayed in the agenda.  In the daily/weekly agenda, the sums will
-cover a single day; in all other views they cover the entire block.  It is
-vital to realize that the agenda may show the same entry @emph{twice}---for
-example as scheduled and as a deadline---and it may show two entries from the
-same hierarchy---for example a @emph{parent} and its @emph{child}.  In these
-cases, the summation in the agenda will lead to incorrect results because
-some values will count double.
-
-@item
-When the column view in the agenda shows the @code{CLOCKSUM}, that is always
-the entire clocked time for this item.  So even in the daily/weekly agenda,
-the clocksum listed in column view may originate from times outside the
-current view.  This has the advantage that you can compare these values with
-a column listing the planned total effort for a task---one of the major
-applications for column view in the agenda.  If you want information about
-clocked time in the displayed period use clock table mode (press @kbd{R} in
-the agenda).
-
-@item
-@cindex property, special, @code{CLOCKSUM_T}
-When the column view in the agenda shows the @code{CLOCKSUM_T}, that is
-always today's clocked time for this item.  So even in the weekly agenda, the
-clocksum listed in column view only originates from today.  This lets you
-compare the time you spent on a task for today, with the time already
-spent ---via @code{CLOCKSUM}---and with the planned total effort for it.
-@end enumerate
+Org needs to make a decision which columns format to use.  Since
+the entries in the agenda are collected from different files, and
+different files may have different columns formats, this is a
+non-trivial problem.  Org first checks if
+@code{org-overriding-columns-format} is currently set, and if so, takes
+the format from there.  You should set this variable only in the
+@emph{local settings section} of a custom agenda command (see @ref{Custom 
Agenda Views}) to make it valid for that specific agenda view.  If
+no such binding exists, it checks, in sequence,
+@code{org-columns-default-format-for-agenda}, the format associated with
+the first item in the agenda (through a property or a @samp{#+COLUMNS}
+setting in that buffer) and finally @code{org-columns-default-format}.
+
+@item
+@cindex @samp{CLOCKSUM}, special property
+If any of the columns has a summary type defined (see @ref{Column 
attributes}), turning on column view in the agenda visits all
+relevant agenda files and make sure that the computations of this
+property are up to date.  This is also true for the special
+@samp{CLOCKSUM} property.  Org then sums the values displayed in the
+agenda.  In the daily/weekly agenda, the sums cover a single day;
+in all other views they cover the entire block.
+
+It is important to realize that the agenda may show the same entry
+@emph{twice}---for example as scheduled and as a deadline---and it may
+show two entries from the same hierarchy (for example a @emph{parent}
+and its @emph{child}).  In these cases, the summation in the agenda
+leads to incorrect results because some values count double.
 
+@item
+When the column view in the agenda shows the @samp{CLOCKSUM} property,
+that is always the entire clocked time for this item.  So even in
+the daily/weekly agenda, the clocksum listed in column view may
+originate from times outside the current view.  This has the
+advantage that you can compare these values with a column listing
+the planned total effort for a task---one of the major
+applications for column view in the agenda.  If you want
+information about clocked time in the displayed period use clock
+table mode (press @kbd{R} in the agenda).
+
+@item
+@cindex @samp{CLOCKSUM_T}, special property
+When the column view in the agenda shows the @samp{CLOCKSUM_T} property,
+that is always today's clocked time for this item.  So even in the
+weekly agenda, the clocksum listed in column view only originates
+from today.  This lets you compare the time you spent on a task for
+today, with the time already spent---via @samp{CLOCKSUM}---and with
+the planned total effort for it.
+@end enumerate
 
-@node Markup
-@chapter Markup for rich export
+@node Markup for Rich Contents
+@chapter Markup for Rich Contents
 
-When exporting Org mode documents, the exporter tries to reflect the
-structure of the document as accurately as possible in the back-end.  Since
-export targets like HTML and @LaTeX{} allow much richer formatting, Org mode 
has
-rules on how to prepare text for rich export.  This section summarizes the
-markup rules used in an Org mode buffer.
+Org is primarily about organizing and searching through your
+plain-text notes.  However, it also provides a lightweight yet robust
+markup language for rich text formatting and more.  For instance, you
+may want to center or emphasize text.  Or you may need to insert
+a formula or image in your writing.  Org offers syntax for all of this
+and more.  Used in conjunction with the export framework (see
+@ref{Exporting}), you can author beautiful documents in Org---like the fine
+manual you are currently reading.
 
 @menu
-* Paragraphs::                  The basic unit of text
-* Emphasis and monospace::      Bold, italic, etc.
-* Horizontal rules::            Make a line
-* Images and tables::           Images, tables and caption mechanism
-* Literal examples::            Source code examples with special formatting
-* Special symbols::             Greek letters and other symbols
-* Subscripts and superscripts::  Simple syntax for raising/lowering text
-* Embedded @LaTeX{}::           LaTeX can be freely used inside Org documents
+* Paragraphs::                   The basic unit of text.
+* Emphasis and Monospace::       Bold, italic, etc.
+* Subscripts and Superscripts::  Simple syntax for raising/lowering text.
+* Special Symbols::              Greek letters and other symbols.
+* Embedded @LaTeX{}::            LaTeX can be freely used inside Org documents.
+* Literal Examples::             Source code examples with special formatting.
+* Images::                       Display an image.
+* Captions::                     Describe tables, images...
+* Horizontal Rules::             Make a line.
+* Creating Footnotes::           Edit and read footnotes.
 @end menu
 
 @node Paragraphs
-@section Paragraphs, line breaks, and quoting
-@cindex paragraphs, markup rules
+@section Paragraphs
 
-Paragraphs are separated by at least one empty line.  If you need to enforce
-a line break within a paragraph, use @samp{\\} at the end of a line.
+@cindex paragraphs, markup rules
+Paragraphs are separated by at least one empty line.  If you need to
+enforce a line break within a paragraph, use @samp{\\} at the end of
+a line.
 
-To preserve the line breaks, indentation and blank lines in a region, but
-otherwise use normal formatting, you can use this construct, which can also
-be used to format poetry.
+@cindex line breaks, markup rules
+To preserve the line breaks, indentation and blank lines in a region,
+but otherwise use normal formatting, you can use this construct, which
+can also be used to format poetry.
 
-@cindex @code{#+BEGIN_VERSE}
+@cindex @samp{BEGIN_VERSE}
 @cindex verse blocks
 @example
 #+BEGIN_VERSE
@@ -9924,25 +11178,26 @@ be used to format poetry.
  Tiny black birds rise and fall
  Snow covers Emacs
 
-     -- AlexSchroeder
+    ---AlexSchroeder
 #+END_VERSE
 @end example
 
-When quoting a passage from another document, it is customary to format this
-as a paragraph that is indented on both the left and the right margin.  You
-can include quotations in Org mode documents like this:
+When quoting a passage from another document, it is customary to
+format this as a paragraph that is indented on both the left and the
+right margin.  You can include quotations in Org documents like this:
 
-@cindex @code{#+BEGIN_QUOTE}
+@cindex @samp{BEGIN_QUOTE}
 @cindex quote blocks
 @example
 #+BEGIN_QUOTE
 Everything should be made as simple as possible,
-but not any simpler -- Albert Einstein
+but not any simpler ---Albert Einstein
 #+END_QUOTE
 @end example
 
 If you would like to center some text, do it like this:
-@cindex @code{#+BEGIN_CENTER}
+
+@cindex @samp{BEGIN_CENTER}
 @cindex center blocks
 @example
 #+BEGIN_CENTER
@@ -9951,8 +11206,8 @@ but not any simpler
 #+END_CENTER
 @end example
 
-@node Emphasis and monospace
-@section Emphasis and monospace
+@node Emphasis and Monospace
+@section Emphasis and Monospace
 
 @cindex underlined text, markup rules
 @cindex bold text, markup rules
@@ -9960,378 +11215,172 @@ but not any simpler
 @cindex verbatim text, markup rules
 @cindex code text, markup rules
 @cindex strike-through text, markup rules
-@vindex org-fontify-emphasized-text
-@vindex org-emphasis-regexp-components
-@vindex org-emphasis-alist
-You can make words @b{*bold*}, @i{/italic/}, _underlined_, @code{=verbatim=}
-and @code{~code~}, and, if you must, @samp{+strike-through+}.  Text
-in the code and verbatim string is not processed for Org mode specific
-syntax, it is exported verbatim.
 
+You can make words @samp{*bold*}, @samp{/italic/}, @samp{_underlined_}, 
@samp{=verbatim=}
+and @samp{~code~}, and, if you must, @samp{+strike-through+}.  Text in the code
+and verbatim string is not processed for Org specific syntax; it is
+exported verbatim.
+
+@vindex org-fontify-emphasized-text
 To turn off fontification for marked up text, you can set
 @code{org-fontify-emphasized-text} to @code{nil}.  To narrow down the list of
-available markup syntax, you can customize @code{org-emphasis-alist}.  To fine
-tune what characters are allowed before and after the markup characters, you
-can tweak @code{org-emphasis-regexp-components}.  Beware that changing one of
-the above variables will not take effect until you reload Org, for which you
-may need to restart Emacs.
-
-@node Horizontal rules
-@section Horizontal rules
-@cindex horizontal rules, markup rules
-A line consisting of only dashes, and at least 5 of them, will be exported as
-a horizontal line.
-
-@node Images and tables
-@section Images and Tables
-
-@cindex tables, markup rules
-@cindex @code{#+CAPTION}
-@cindex @code{#+NAME}
-Both the native Org mode tables (@pxref{Tables}) and tables formatted with
-the @file{table.el} package will be exported properly.  For Org mode tables,
-the lines before the first horizontal separator line will become table header
-lines.  You can use the following lines somewhere before the table to assign
-a caption and a label for cross references, and in the text you can refer to
-the object with @code{[[tab:basic-data]]} (@pxref{Internal links}):
-
-@example
-#+CAPTION: This is the caption for the next table (or link)
-#+NAME:   tab:basic-data
-   | ... | ...|
-   |-----|----|
-@end example
-
-Optionally, the caption can take the form:
-@example
-#+CAPTION[Caption for list of tables]: Caption for table.
-@end example
-
-@cindex inlined images, markup rules
-Some back-ends allow you to directly include images into the exported
-document.  Org does this, if a link to an image files does not have
-a description part, for example @code{[[./img/a.jpg]]}.  If you wish to
-define a caption for the image and maybe a label for internal cross
-references, make sure that the link is on a line by itself and precede it
-with @code{#+CAPTION} and @code{#+NAME} as follows:
-
-@example
-#+CAPTION: This is the caption for the next figure link (or table)
-#+NAME:   fig:SED-HR4049
-[[./img/a.jpg]]
-@end example
+available markup syntax, you can customize @code{org-emphasis-alist}.
 
-@noindent
-Such images can be displayed within the buffer.  @xref{Handling links,the
-discussion of image links}.
-
-Even though images and tables are prominent examples of captioned structures,
-the same caption mechanism can apply to many others (e.g., @LaTeX{}
-equations, source code blocks).  Depending on the export back-end, those may
-or may not be handled.
-
-@node Literal examples
-@section Literal examples
-@cindex literal examples, markup rules
-@cindex code line references, markup rules
-
-You can include literal examples that should not be subjected to
-markup.  Such examples will be typeset in monospace, so this is well suited
-for source code and similar examples.
-@cindex @code{#+BEGIN_EXAMPLE}
-
-@example
-#+BEGIN_EXAMPLE
-Some example from a text file.
-#+END_EXAMPLE
-@end example
-
-Note that such blocks may be @i{indented} in order to align nicely with
-indented text and in particular with plain list structure (@pxref{Plain
-lists}).  For simplicity when using small examples, you can also start the
-example lines with a colon followed by a space.  There may also be additional
-whitespace before the colon:
-
-@example
-Here is an example
-   : Some example from a text file.
-@end example
-
-@cindex formatting source code, markup rules
-@vindex org-latex-listings
-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 back-end (it requires version 1.34 of the @file{htmlize.el} package,
-which you need to install).  Fontified code chunks in @LaTeX{} can be
-achieved using either the
-@url{https://www.ctan.org/tex-archive/macros/latex/contrib/listings/?lang=en, 
listings,}
-or the
-@url{https://github.com/gpoore/minted, minted,} package.
-If you use minted or listing, you must load the packages manually, for
-example by adding the desired package to
-@code{org-latex-packages-alist}.  Refer to @code{org-latex-listings}
-for details.}.  This is done with the @samp{src} block, where you also need
-to specify the name of the major mode that should be used to fontify the
-example@footnote{Code in @samp{src} blocks may also be evaluated either
-interactively or on export.  @xref{Working with source code}, for more
-information on evaluating code blocks.}, see @ref{Easy templates} for
-shortcuts to easily insert code blocks.
-@cindex @code{#+BEGIN_SRC}
-
-@example
-#+BEGIN_SRC emacs-lisp
-  (defun org-xor (a b)
-     "Exclusive or."
-     (if a (not b) b))
-#+END_SRC
-@end example
-
-Both in @code{example} and in @code{src} snippets, you can add a @code{-n}
-switch to the end of the @code{BEGIN} line, to get the lines of the example
-numbered.  The @code{-n} takes an optional numeric argument specifying the
-starting line number of the block.  If you use a @code{+n} switch, the
-numbering from the previous numbered snippet will be continued in the current
-one.  The @code{+n} can also take a numeric argument.  The value of the
-argument will be added to the last line of the previous block to determine
-the starting line number.
-
-@example
-#+BEGIN_SRC emacs-lisp -n 20
- ;; this will export with line number 20
- (message "This is line 21")
-#+END_SRC
-#+BEGIN_SRC emacs-lisp +n 10
- ;; This will be listed as line 31
- (message "This is line 32")
-#+END_SRC
-@end example
+@node Subscripts and Superscripts
+@section Subscripts and Superscripts
 
-In literal examples, Org will interpret strings like @samp{(ref:name)} as
-labels, and use them as targets for special hyperlinks like @code{[[(name)]]}
-(i.e., the reference name enclosed in single parenthesis).  In HTML, hovering
-the mouse over such a link will remote-highlight the corresponding code line,
-which is kind of cool.
+@cindex subscript
+@cindex superscript
 
-You can also add a @code{-r} switch which @i{removes} the labels from the
-source code@footnote{Adding @code{-k} to @code{-n -r} will @i{keep} the
-labels in the source code while using line numbers for the links, which might
-be useful to explain those in an Org mode example code.}.  With the @code{-n}
-switch, links to these references will be labeled by the line numbers from
-the code listing, otherwise links will use the labels with no parentheses.
-Here is an example:
+@samp{^} and @samp{_} are used to indicate super- and subscripts.  To increase
+the readability of ASCII text, it is not necessary, but OK, to
+surround multi-character sub- and superscripts with curly braces.  For
+example
 
 @example
-#+BEGIN_SRC emacs-lisp -n -r
-(save-excursion                  (ref:sc)
-   (goto-char (point-min)))      (ref:jump)
-#+END_SRC
-In line [[(sc)]] we remember the current position.  [[(jump)][Line (jump)]]
-jumps to point-min.
+The radius of the sun is R_sun = 6.96 x 10^8 m.  On the other hand,
+the radius of Alpha Centauri is R_@{Alpha Centauri@} = 1.28 x R_@{sun@}.
 @end example
 
-@cindex indentation, in source blocks
-Finally, you can use @code{-i} to preserve the indentation of a specific code
-block (@pxref{Editing source code}).
-
-@vindex org-coderef-label-format
-If the syntax for the label format conflicts with the language syntax, use a
-@code{-l} switch to change the format, for example @samp{#+BEGIN_SRC pascal
--n -r -l "((%s))"}.  See also the variable @code{org-coderef-label-format}.
-
-HTML export also allows examples to be published as text areas (@pxref{Text
-areas in HTML export}).
-
-Because the @code{#+BEGIN_...} and @code{#+END_...} patterns need to be added
-so often, shortcuts are provided using the Easy templates facility
-(@pxref{Easy templates}).
+@vindex org-use-sub-superscripts
+If you write a text where the underscore is often used in a different
+context, Org's convention to always interpret these as subscripts can
+get in your way.  Configure the variable @code{org-use-sub-superscripts} to
+change this convention.  For example, when setting this variable to
+@code{@{@}}, @samp{a_b} is not interpreted as a subscript, but @samp{a_@{b@}} 
is.
 
-@table @kbd
-@kindex C-c '
-@item C-c '
-Edit the source code example at point in its native mode.  This works by
-switching to a temporary buffer with the source code.  You need to exit by
-pressing @kbd{C-c '} again@footnote{Upon exit, lines starting with @samp{*},
-@samp{,*}, @samp{#+} and @samp{,#+} will get a comma prepended, to keep them
-from being interpreted by Org as outline nodes or special syntax.  These
-commas will be stripped for editing with @kbd{C-c '}, and also for export.}.
-The edited version will then replace the old version in the Org buffer.
-Fixed-width regions (where each line starts with a colon followed by a space)
-will be edited using @code{artist-mode}@footnote{You may select
-a different-mode with the variable @code{org-edit-fixed-width-region-mode}.}
-to allow creating ASCII drawings easily.  Using this command in an empty line
-will create a new fixed-width region.
-@kindex C-c l
-@item C-c l
-Calling @code{org-store-link} while editing a source code example in a
-temporary buffer created with @kbd{C-c '} will prompt for a label.  Make sure
-that it is unique in the current buffer, and insert it with the proper
-formatting like @samp{(ref:label)} at the end of the current line.  Then the
-label is stored as a link @samp{(label)}, for retrieval with @kbd{C-c C-l}.
+@table @asis
+@item @kbd{C-c C-x \} (@code{org-toggle-pretty-entities})
+@kindex C-c C-x \
+@findex org-toggle-pretty-entities
+This command formats sub- and superscripts in a WYSIWYM way.
 @end table
 
-@node Special symbols
-@section Special symbols
-@cindex Org entities
+@node Special Symbols
+@section Special Symbols
+
 @cindex math symbols
 @cindex special symbols
-@cindex HTML entities
-@cindex @LaTeX{} entities
+@cindex entities
 
 You can use @LaTeX{}-like syntax to insert special symbols---named
-entities---like @samp{\alpha} to indicate the Greek letter, or @samp{\to} to
-indicate an arrow.  Completion for these symbols is available, just type
-@samp{\} and maybe a few letters, and press @kbd{M-@key{TAB}} to see possible
-completions.  If you need such a symbol inside a word, terminate it with
-a pair of curly brackets.  For example
+entities---like @samp{\alpha} to indicate the Greek letter, or @samp{\to} to 
indicate
+an arrow.  Completion for these symbols is available, just type @samp{\}
+and maybe a few letters, and press @kbd{M-@key{TAB}} to see possible
+completions.  If you need such a symbol inside a word, terminate it
+with a pair of curly brackets.  For example
 
 @example
-Pro tip: Given a circle \Gamma of diameter d, the length of its circumference
-is \pi@{@}d.
+Pro tip: Given a circle \Gamma of diameter d, the length of its
+circumference is \pi@{@}d.
 @end example
 
 @findex org-entities-help
 @vindex org-entities-user
-A large number of entities is provided, with names taken from both HTML and
-@LaTeX{}; you can comfortably browse the complete list from a dedicated
-buffer using the command @code{org-entities-help}.  It is also possible to
-provide your own special symbols in the variable @code{org-entities-user}.
+A large number of entities is provided, with names taken from both
+HTML and @LaTeX{}; you can comfortably browse the complete list from
+a dedicated buffer using the command @code{org-entities-help}.  It is also
+possible to provide your own special symbols in the variable
+@code{org-entities-user}.
 
-During export, these symbols are transformed into the native format of the
-exporter back-end.  Strings like @code{\alpha} are exported as @code{&alpha;}
-in the HTML output, and as @code{\(\alpha\)} in the @LaTeX{} output.
-Similarly, @code{\nbsp} becomes @code{&nbsp;} in HTML and @code{~} in
-@LaTeX{}.
-
-@cindex escaping characters
-Entities may also be used as a may to escape markup in an Org document, e.g.,
-@samp{\under@{@}not underlined\under} exports as @samp{_not underlined_}.
+During export, these symbols are transformed into the native format of
+the exporter back-end.  Strings like @samp{\alpha} are exported as 
@samp{&alpha;} in
+the HTML output, and as @samp{\(\alpha\)} in the @LaTeX{} output.  Similarly, 
@samp{\nbsp}
+becomes @samp{&nbsp;} in HTML and @samp{~} in @LaTeX{}.
 
 @cindex special symbols, in-buffer display
-If you would like to see entities displayed as UTF-8 characters, use the
-following command@footnote{You can turn this on by default by setting the
-variable @code{org-pretty-entities}, or on a per-file base with the
-@code{#+STARTUP} option @code{entitiespretty}.}:
+If you would like to see entities displayed as UTF-8 characters, use
+the following command@footnote{You can turn this on by default by setting the 
variable
+@code{org-pretty-entities}, or on a per-file base with the @samp{STARTUP} 
option
+@samp{entitiespretty}.}:
 
-@table @kbd
-@cindex @code{entitiespretty}, STARTUP keyword
+@table @asis
+@item @kbd{C-c C-x \} (@code{org-toggle-pretty-entities})
 @kindex C-c C-x \
-@item C-c C-x \
-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.
+@findex org-toggle-pretty-entities
+
+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
 
 @cindex shy hyphen, special symbol
 @cindex dash, special symbol
 @cindex ellipsis, special symbol
-In addition to regular entities defined above, Org exports in a special
-way@footnote{This behavior can be disabled with @code{-} export setting
-(@pxref{Export settings}).} the following commonly used character
-combinations: @samp{\-} is treated as a shy hyphen, @samp{--} and @samp{---}
-are converted into dashes, and @samp{...} becomes a compact set of dots.
-
-@node Subscripts and superscripts
-@section Subscripts and superscripts
-@cindex subscript
-@cindex superscript
-
-@samp{^} and @samp{_} are used to indicate super- and subscripts.  To
-increase the readability of ASCII text, it is not necessary---but OK---to
-surround multi-character sub- and superscripts with curly braces.  Those are,
-however, mandatory, when more than one word is involved.  For example
-
-@example
-The radius of the sun is R_sun = 6.96 x 10^8 m.  On the other hand, the
-radius of Alpha Centauri is R_@{Alpha Centauri@} = 1.28 x R_@{sun@}.
-@end example
-
-@vindex org-use-sub-superscripts
-If you write a text where the underscore is often used in a different
-context, Org's convention to always interpret these as subscripts can get in
-your way.  Configure the variable @code{org-use-sub-superscripts} to change
-this convention.  For example, when setting this variable to @code{@{@}},
-@samp{a_b} will not be interpreted as a subscript, but @samp{a_@{b@}} will.
-
-@table @kbd
-@kindex C-c C-x \
-@item C-c C-x \
-In addition to showing entities as UTF-8 characters, this command will also
-format sub- and superscripts in a WYSIWYM way.
-@end table
+In addition to regular entities defined above, Org exports in
+a special way@footnote{This behavior can be disabled with @samp{-} export 
setting (see
+@ref{Export Settings}).} the following commonly used character
+combinations: @samp{\-} is treated as a shy hyphen, @samp{--} and @samp{---} 
are
+converted into dashes, and @samp{...} becomes a compact set of dots.
 
 @node Embedded @LaTeX{}
 @section Embedded @LaTeX{}
+
 @cindex @TeX{} interpretation
 @cindex @LaTeX{} interpretation
 
-Plain ASCII is normally sufficient for almost all note taking.  Exceptions
-include scientific notes, which often require mathematical symbols and the
-occasional formula.  @LaTeX{}@footnote{@LaTeX{} is a macro system based on
-Donald E. Knuth's @TeX{} system.  Many of the features described here as
-``@LaTeX{}'' are really from @TeX{}, but for simplicity I am blurring this
-distinction.}  is widely used to typeset scientific documents.  Org mode
-supports embedding @LaTeX{} code into its files, because many academics are
-used to writing and reading @LaTeX{} source code, and because it can be
-readily processed to produce pretty output for a number of export back-ends.
+Plain ASCII is normally sufficient for almost all note taking.
+Exceptions include scientific notes, which often require mathematical
+symbols and the occasional formula.  @LaTeX{}@footnote{@LaTeX{} is a macro 
system based on Donald@tie{}E@.@tie{}Knuth's @TeX{}
+system.  Many of the features described here as ``@LaTeX{}'' are really
+from @TeX{}, but for simplicity I am blurring this distinction.} is widely 
used to
+typeset scientific documents.  Org mode supports embedding @LaTeX{} code
+into its files, because many academics are used to writing and reading
+@LaTeX{} source code, and because it can be readily processed to produce
+pretty output for a number of export back-ends.
 
 @menu
-* @LaTeX{} fragments::          Complex formulas made easy
-* Previewing @LaTeX{} fragments::  What will this snippet look like?
-* CDLaTeX mode::                Speed up entering of formulas
+* @LaTeX{} fragments::           Complex formulas made easy.
+* Previewing @LaTeX{} fragments:: What will this snippet look like?
+* CD@LaTeX{} mode::              Speed up entering of formulas.
 @end menu
 
 @node @LaTeX{} fragments
 @subsection @LaTeX{} fragments
+
 @cindex @LaTeX{} fragments
 
 @vindex org-format-latex-header
-Org mode can contain @LaTeX{} math fragments, and it supports ways to process
-these for several export back-ends.  When exporting to @LaTeX{}, the code is
-left as it is.  When exporting to HTML, Org can use either
-@uref{http://www.mathjax.org, MathJax} (@pxref{Math formatting in HTML
-export}) or transcode the math into images (@pxref{Previewing @LaTeX{}
-fragments}).
-
-@LaTeX{} fragments don't need any special marking at all.  The following
-snippets will be identified as @LaTeX{} source code:
-@itemize @bullet
-@item
-Environments of any kind@footnote{When MathJax is used, only the
-environments recognized by MathJax will be processed.  When
-@file{dvipng} program, @file{dvisvgm} program or @file{imagemagick} suite is
-used to create images, any @LaTeX{} environment will be handled.}.  The only
-requirement is that the @code{\begin} statement appears on a new line, at the
-beginning of the line or after whitespaces only.
-@item
-Text within the usual @LaTeX{} math delimiters.  To avoid conflicts with
-currency specifications, single @samp{$} characters are only recognized as
-math delimiters if the enclosed text contains at most two line breaks, is
-directly attached to the @samp{$} characters with no whitespace in between,
-and if the closing @samp{$} is followed by whitespace or punctuation
-(parentheses and quotes are considered to be punctuation in this
-context).  For the other delimiters, there is no such restriction, so when in
-doubt, use @samp{\(...\)} as inline math delimiters.
+Org mode can contain @LaTeX{} math fragments, and it supports ways to
+process these for several export back-ends.  When exporting to @LaTeX{},
+the code is left as it is.  When exporting to HTML, Org can use either
+@uref{http://www.mathjax.org, MathJax} (see @ref{Math formatting in HTML 
export}) or transcode the math
+into images (see @ref{Previewing @LaTeX{} fragments}).
+
+@LaTeX{} fragments do not need any special marking at all.  The following
+snippets are identified as @LaTeX{} source code:
+
+@itemize
+@item
+Environments of any kind@footnote{When MathJax is used, only the environments 
recognized by
+MathJax are processed.  When dvipng, dvisvgm, or ImageMagick suite is
+used to create images, any @LaTeX{} environment is handled.}.  The only 
requirement is that the
+@samp{\begin} statement appears on a new line, preceded by only
+whitespace.
+
+@item
+Text within the usual @LaTeX{} math delimiters.  To avoid conflicts
+with currency specifications, single @samp{$} characters are only
+recognized as math delimiters if the enclosed text contains at most
+two line breaks, is directly attached to the @samp{$} characters with no
+whitespace in between, and if the closing @samp{$} is followed by
+whitespace, punctuation or a dash.  For the other delimiters, there
+is no such restriction, so when in doubt, use @samp{\(...\)} as inline
+math delimiters.
 @end itemize
 
-@noindent For example:
+@noindent
+For example:
 
 @example
-\begin@{equation@}
-x=\sqrt@{b@}
-\end@{equation@}
+\begin@{equation@}                        % arbitrary environments,
+x=\sqrt@{b@}                              % even tables, figures
+\end@{equation@}                          % etc
 
 If $a^2=b$ and \( b=2 \), then the solution must be
 either $$ a=+\sqrt@{2@} $$ or \[ a=-\sqrt@{2@} \].
 @end example
 
-@c FIXME
-@c @noindent
-@c @vindex org-format-latex-options
-@c If you need any of the delimiter ASCII sequences for other purposes, you
-@c can configure the option @code{org-format-latex-options} to deselect the
-@c ones you do not wish to have interpreted by the @LaTeX{} converter.
-
 @vindex org-export-with-latex
 @LaTeX{} processing can be configured with the variable
 @code{org-export-with-latex}.  The default setting is @code{t} which means
@@ -10339,45 +11388,51 @@ MathJax for HTML, and no processing for ASCII and 
@LaTeX{} back-ends.
 You can also set this variable on a per-file basis using one of these
 lines:
 
-@example
-#+OPTIONS: tex:t          @r{Do the right thing automatically (MathJax)}
-#+OPTIONS: tex:nil        @r{Do not process @LaTeX{} fragments at all}
-#+OPTIONS: tex:verbatim   @r{Verbatim export, for jsMath or so}
-@end example
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{#+OPTIONS: tex:t}
+@tab Do the right thing automatically (MathJax)
+@item @samp{#+OPTIONS: tex:nil}
+@tab Do not process @LaTeX{} fragments at all
+@item @samp{#+OPTIONS: tex:verbatim}
+@tab Verbatim export, for jsMath or so
+@end multitable
 
 @node Previewing @LaTeX{} fragments
 @subsection Previewing @LaTeX{} fragments
+
 @cindex @LaTeX{} fragments, preview
 
 @vindex org-preview-latex-default-process
-If you have a working @LaTeX{} installation and @file{dvipng}, @file{dvisvgm}
-or @file{convert} installed@footnote{These are respectively available at
-@url{http://sourceforge.net/projects/dvipng/}, 
@url{http://dvisvgm.bplaced.net/}
-and from the @file{imagemagick} suite.  Choose the converter by setting the
-variable @code{org-preview-latex-default-process} accordingly.}, @LaTeX{}
-fragments can be processed to produce images of the typeset expressions to be
-used for inclusion while exporting to HTML (@pxref{@LaTeX{} fragments}),
-or for inline previewing within Org mode.
+If you have a working @LaTeX{} installation and @samp{dvipng}, @samp{dvisvgm} 
or
+@samp{convert} installed@footnote{These are respectively available at
+@uref{http://sourceforge.net/projects/dvipng/}, 
@uref{http://dvisvgm.bplaced.net/}
+and from the ImageMagick suite.  Choose the converter by setting the
+variable @code{org-preview-latex-default-process} accordingly.}, @LaTeX{} 
fragments can be processed to
+produce images of the typeset expressions to be used for inclusion
+while exporting to HTML (see @ref{@LaTeX{} fragments}), or for inline
+previewing within Org mode.
 
 @vindex org-format-latex-options
 @vindex org-format-latex-header
 You can customize the variables @code{org-format-latex-options} and
-@code{org-format-latex-header} to influence some aspects of the preview.  In
-particular, the @code{:scale} (and for HTML export, @code{:html-scale})
-property of the former can be used to adjust the size of the preview images.
+@code{org-format-latex-header} to influence some aspects of the preview.
+In particular, the @code{:scale} (and for HTML export, @code{:html-scale})
+property of the former can be used to adjust the size of the preview
+images.
 
-@table @kbd
+@table @asis
+@item @kbd{C-c C-x C-l} (@code{org-latex-preview})
 @kindex C-c C-x C-l
-@item C-c C-x C-l
-Produce a preview image of the @LaTeX{} fragment at point and overlay it
-over the source code.  If there is no fragment at point, process all
-fragments in the current entry (between two headlines).  When called
-with a prefix argument, process the entire subtree.  When called with
-two prefix arguments, or when the cursor is before the first headline,
-process the entire buffer.
-@kindex C-c C-c
-@item C-c C-c
-Remove the overlay preview images.
+@findex org-latex-preview
+
+Produce a preview image of the @LaTeX{} fragment at point and overlay
+it over the source code.  If there is no fragment at point, process
+all fragments in the current entry---between two headlines.
+
+When called with a single prefix argument, clear all images in the
+current entry.  Two prefix arguments produce a preview image for all
+fragments in the buffer, while three of them clear all the images in
+that buffer.
 @end table
 
 @vindex org-startup-with-latex-preview
@@ -10387,698 +11442,1173 @@ You can turn on the previewing of all @LaTeX{} 
fragments in a file with
 #+STARTUP: latexpreview
 @end example
 
+
 To disable it, simply use
 
 @example
 #+STARTUP: nolatexpreview
 @end example
 
-@node CDLaTeX mode
+@node CD@LaTeX{} mode
 @subsection Using CD@LaTeX{} to enter math
+
 @cindex CD@LaTeX{}
 
-CD@LaTeX{} mode is a minor mode that is normally used in combination with a
-major @LaTeX{} mode like AUC@TeX{} in order to speed-up insertion of
-environments and math templates.  Inside Org mode, you can make use of some
-of the features of CD@LaTeX{} mode.  You need to install @file{cdlatex.el}
-and @file{texmathp.el} (the latter comes also with AUC@TeX{}) from
-@url{https://staff.fnwi.uva.nl/c.dominik/Tools/cdlatex}.  Don't use
-CD@LaTeX{} mode itself under Org mode, but use the light version
-@code{org-cdlatex-mode} that comes as part of Org mode.  Turn it on for the
-current buffer with @kbd{M-x org-cdlatex-mode @key{RET}}, or for all Org
+CD@LaTeX{} mode is a minor mode that is normally used in combination with
+a major @LaTeX{} mode like AUC@TeX{} in order to speed-up insertion of
+environments and math templates.  Inside Org mode, you can make use of
+some of the features of CD@LaTeX{} mode.  You need to install
+@samp{cdlatex.el} and @samp{texmathp.el} (the latter comes also with AUC@TeX{})
+using @uref{https://melpa.org/, MELPA} with the 
@uref{https://www.gnu.org/software/emacs/manual/html_node/emacs/Package-Installation.html,
 Emacs packaging system} or alternatively from
+@uref{https://staff.fnwi.uva.nl/c.dominik/Tools/cdlatex/}.  Do not use
+CD@LaTeX{} mode itself under Org mode, but use the special version Org
+CD@LaTeX{} minor mode that comes as part of Org.  Turn it on for the
+current buffer with @kbd{M-x org-cdlatex-mode}, or for all Org
 files with
 
 @lisp
 (add-hook 'org-mode-hook 'turn-on-org-cdlatex)
 @end lisp
 
-When this mode is enabled, the following features are present (for more
-details see the documentation of CD@LaTeX{} mode):
-@itemize @bullet
+When this mode is enabled, the following features are present (for
+more details see the documentation of CD@LaTeX{} mode):
+
+@table @asis
+@item @kbd{C-c @{}
 @kindex C-c @{
-@item
-Environment templates can be inserted with @kbd{C-c @{}.
-@item
+
+Insert an environment template.
+
+@item @kbd{@key{TAB}}
 @kindex TAB
-The @key{TAB} key will do template expansion if the cursor is inside a
-@LaTeX{} fragment@footnote{Org mode has a method to test if the cursor is
-inside such a fragment, see the documentation of the function
-@code{org-inside-LaTeX-fragment-p}.}.  For example, @key{TAB} will
-expand @code{fr} to @code{\frac@{@}@{@}} and position the cursor
-correctly inside the first brace.  Another @key{TAB} will get you into
-the second brace.  Even outside fragments, @key{TAB} will expand
-environment abbreviations at the beginning of a line.  For example, if
-you write @samp{equ} at the beginning of a line and press @key{TAB},
-this abbreviation will be expanded to an @code{equation} environment.
-To get a list of all abbreviations, type @kbd{M-x cdlatex-command-help
-@key{RET}}.
-@item
+
+The @kbd{@key{TAB}} key expands the template if point is inside
+a @LaTeX{} fragment@footnote{Org mode has a method to test if point is inside 
such
+a fragment, see the documentation of the function
+@code{org-inside-LaTeX-fragment-p}.}.  For example, @kbd{@key{TAB}} expands 
@samp{fr}
+to @samp{\frac@{@}@{@}} and position point correctly inside the first brace.
+Another @kbd{@key{TAB}} gets you into the second brace.
+
+Even outside fragments, @kbd{@key{TAB}} expands environment
+abbreviations at the beginning of a line.  For example, if you write
+@samp{equ} at the beginning of a line and press @kbd{@key{TAB}}, this
+abbreviation is expanded to an @samp{equation} environment.  To get
+a list of all abbreviations, type @kbd{M-x cdlatex-command-help}.
+
+@item @kbd{^}
+@itemx @kbd{_}
 @kindex _
 @kindex ^
 @vindex cdlatex-simplify-sub-super-scripts
-Pressing @kbd{_} and @kbd{^} inside a @LaTeX{} fragment will insert these
-characters together with a pair of braces.  If you use @key{TAB} to move
-out of the braces, and if the braces surround only a single character or
-macro, they are removed again (depending on the variable
-@code{cdlatex-simplify-sub-super-scripts}).
-@item
-@kindex `
-Pressing the grave accent @kbd{`} followed by a character inserts math
-macros, also outside @LaTeX{} fragments.  If you wait more than 1.5 seconds
-after the grave accent, a help window will pop up.
-@item
-@kindex '
-Pressing the apostrophe @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 apostrophe, a help window will pop up.  Character
-modification will work only inside @LaTeX{} fragments; outside the quote
-is normal.
-@end itemize
 
-@node Exporting
-@chapter Exporting
-@cindex exporting
+Pressing @kbd{_} and @kbd{^} inside a @LaTeX{} fragment
+inserts these characters together with a pair of braces.  If you use
+@kbd{@key{TAB}} to move out of the braces, and if the braces surround
+only a single character or macro, they are removed again (depending
+on the variable @code{cdlatex-simplify-sub-super-scripts}).
 
-Sometimes, you may want to pretty print your notes, publish them on the web
-or even share them with people not using Org.  In these cases, the Org export
-facilities can be used to convert your documents to a variety of other
-formats, while retaining as much structure (@pxref{Document structure}) and
-markup (@pxref{Markup}) as possible.
+@item @kbd{`}
+@kindex `
 
-@cindex export back-end
-Libraries responsible for such translation are called back-ends.  Org ships
-with the following ones
+Pressing the backquote followed by a character inserts math macros,
+also outside @LaTeX{} fragments.  If you wait more than 1.5 seconds
+after the backquote, a help window pops up.
 
-@itemize
-@item ascii (ASCII format)
-@item beamer (@LaTeX{} Beamer format)
-@item html (HTML format)
-@item icalendar (iCalendar format)
-@item latex (@LaTeX{} format)
-@item md (Markdown format)
-@item odt (OpenDocument Text format)
-@item org (Org format)
-@item texinfo (Texinfo format)
-@item man (Man page format)
-@end itemize
+@item @kbd{'}
+@kindex '
 
-@noindent Org also uses additional libraries located in @code{contrib/}
-directory (@pxref{Installation}).  Users can install additional export
-libraries for additional formats from the Emacs packaging system.  For easy
-discovery, these packages have a common naming scheme: @file{ox-NAME}, where
-NAME is one of the formats.  For example, @file{ox-koma-letter} for
-@code{koma-letter} back-end.
+Pressing the single-quote 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 single-quote, a help window pops up.
+Character modification works only inside @LaTeX{} fragments; outside
+the quote is normal.
+@end table
 
-@vindex org-export-backends
-Org loads back-ends for the following formats by default: @code{ascii},
-@code{html}, @code{icalendar}, @code{latex} and @code{odt}.
+@node Literal Examples
+@section Literal Examples
 
-Org can load additional back-ends either of two ways: through the
-@code{org-export-backends} variable configuration; or, by requiring the
-library in the Emacs init file like this:
+@cindex literal examples, markup rules
+@cindex code line references, markup rules
 
-@lisp
-(require 'ox-md)
-@end lisp
+You can include literal examples that should not be subjected to
+markup.  Such examples are typeset in monospace, so this is well
+suited for source code and similar examples.
 
-@menu
-* The export dispatcher::       The main interface
-* Export settings::             Common export settings
-* Table of contents::           The if and where of the table of contents
-* Include files::               Include additional files into a document
-* Macro replacement::           Use macros to create templates
-* Comment lines::               What will not be exported
-* ASCII/Latin-1/UTF-8 export::  Exporting to flat files with encoding
-* Beamer export::               Exporting as a Beamer presentation
-* HTML export::                 Exporting to HTML
-* @LaTeX{} export::             Exporting to @LaTeX{}, and processing to PDF
-* Markdown export::             Exporting to Markdown
-* OpenDocument Text export::    Exporting to OpenDocument Text
-* Org export::                  Exporting to Org
-* Texinfo export::              Exporting to Texinfo
-* iCalendar export::            Exporting to iCalendar
-* Other built-in back-ends::    Exporting to a man page
-* Advanced configuration::      Fine-tuning the export output
-* Export in foreign buffers::   Author tables and lists in Org syntax
-@end menu
+@cindex @samp{BEGIN_EXAMPLE}
+@cindex example block
+@example
+#+BEGIN_EXAMPLE
+  Some example from a text file.
+#+END_EXAMPLE
+@end example
 
-@node The export dispatcher
-@section The export dispatcher
-@vindex org-export-dispatch-use-expert-ui
-@cindex Export, dispatcher
+@cindex comma escape, in literal examples
+There is one limitation, however.  You must insert a comma right
+before lines starting with either @samp{*}, @samp{,*}, @samp{#+} or 
@samp{,#+}, as those
+may be interpreted as outlines nodes or some other special syntax.
+Org transparently strips these additional commas whenever it accesses
+the contents of the block.
 
-The export dispatcher is the main interface for Org's exports.  A
-hierarchical menu presents the currently configured export formats.  Options
-are shown as easy toggle switches on the same screen.
+@example
+#+BEGIN_EXAMPLE
+,* I am no real headline
+#+END_EXAMPLE
+@end example
 
-Org also has a minimal prompt interface for the export dispatcher.  When the
-variable @code{org-export-dispatch-use-expert-ui} is set to a non-@code{nil}
-value, Org prompts in the minibuffer.  To switch back to the hierarchical
-menu, press @key{?}.
+For simplicity when using small examples, you can also start the
+example lines with a colon followed by a space.  There may also be
+additional whitespace before the colon:
 
-@table @asis
-@orgcmd{C-c C-e,org-export-dispatch}
+@example
+Here is an example
+   : Some example from a text file.
+@end example
 
-Invokes the export dispatcher interface.  The options show default settings.
-The @kbd{C-u} prefix argument preserves options from the previous export,
-including any sub-tree selections.
+@cindex formatting source code, markup rules
+@vindex org-latex-listings
+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 @samp{htmlize.el} package, which you need to install).
+Fontified code chunks in @LaTeX{} can be achieved using either the
+@uref{https://www.ctan.org/pkg/listings, listings} package or the 
@uref{https://www.ctan.org/pkg/minted, minted} package.  Refer to
+@code{org-export-latex-listings} for details.}.  This
+is done with the code block, where you also need to specify the name
+of the major mode that should be used to fontify the example@footnote{Source 
code in code blocks may also be evaluated either
+interactively or on export.  See @ref{Working with Source Code} for more
+information on evaluating code blocks.},
+see @ref{Structure Templates} for shortcuts to easily insert code blocks.
+
+@cindex @samp{BEGIN_SRC}
+@cindex source block
+@example
+#+BEGIN_SRC emacs-lisp
+  (defun org-xor (a b)
+    "Exclusive or."
+    (if a (not b) b))
+ #+END_SRC
+@end example
 
-@end table
+Both in @samp{example} and in @samp{src} snippets, you can add a @samp{-n} 
switch to
+the end of the @samp{#+BEGIN} line, to get the lines of the example
+numbered.  The @samp{-n} takes an optional numeric argument specifying the
+starting line number of the block.  If you use a @samp{+n} switch, the
+numbering from the previous numbered snippet is continued in the
+current one.  The @samp{+n} switch can also take a numeric argument.  This
+adds the value of the argument to the last line of the previous block
+to determine the starting line number.
 
-Org exports the entire buffer by default.  If the Org buffer has an active
-region, then Org exports just that region.
+@example
+#+BEGIN_SRC emacs-lisp -n 20
+  ;; This exports with line number 20.
+  (message "This is line 21")
+#+END_SRC
 
-These are the export options, the key combinations that toggle them
-(@pxref{Export settings}):
+#+BEGIN_SRC emacs-lisp +n 10
+  ;; This is listed as line 31.
+  (message "This is line 32")
+#+END_SRC
+@end example
 
-@table @kbd
-@item C-a
-@vindex org-export-async-init-file
-Toggles asynchronous export.  Asynchronous export uses an external Emacs
-process with a specially configured initialization file to complete the
-exporting process in the background thereby releasing the current interface.
-This is particularly useful when exporting long documents.
+In literal examples, Org interprets strings like @samp{(ref:name)} as
+labels, and use them as targets for special hyperlinks like
+@samp{[[(name)]]}---i.e., the reference name enclosed in single parenthesis.
+In HTML, hovering the mouse over such a link remote-highlights the
+corresponding code line, which is kind of cool.
 
-Output from an asynchronous export is saved on the ``the export stack''.  To
-view this stack, call the export dispatcher with a double @kbd{C-u} prefix
-argument.  If already in the export dispatcher menu, @kbd{&} displays the
-stack.
+You can also add a @samp{-r} switch which @emph{removes} the labels from the
+source code@footnote{Adding @samp{-k} to @samp{-n -r} @emph{keeps} the labels 
in the source code
+while using line numbers for the links, which might be useful to
+explain those in an Org mode example code.}.  With the @samp{-n} switch, links 
to these references
+are labeled by the line numbers from the code listing.  Otherwise
+links use the labels with no parentheses.  Here is an example:
 
-@vindex org-export-in-background
-To make the background export process the default, customize the variable,
-@code{org-export-in-background}.
+@example
+#+BEGIN_SRC emacs-lisp -n -r
+  (save-excursion                 (ref:sc)
+     (goto-char (point-min))      (ref:jump)
+#+END_SRC
+In line [[(sc)]] we remember the current position. [[(jump)][Line (jump)]]
+jumps to point-min.
+@end example
 
-@item C-b
-Toggle body-only export.  Useful for excluding headers and footers in the
-export.  Affects only those back-end formats that have such sections---like
-@code{<head>...</head>} in HTML.
+@cindex indentation, in source blocks
+Source code and examples may be @emph{indented} in order to align nicely
+with the surrounding text, and in particular with plain list structure
+(see @ref{Plain Lists}).  By default, Org only retains the relative
+indentation between lines, e.g., when exporting the contents of the
+block.  However, you can use the @samp{-i} switch to also preserve the
+global indentation, if it does matter.  See @ref{Editing Source Code}.
 
-@item C-s
-@vindex org-export-initial-scope
-Toggle sub-tree export.  When turned on, Org exports only the sub-tree starting
-from the cursor position at the time the export dispatcher was invoked.  Org
-uses the top heading of this sub-tree as the document's title.  If the cursor
-is not on a heading, Org uses the nearest enclosing header.  If the cursor is
-in the document preamble, Org signals an error and aborts export.
+@vindex org-coderef-label-format
+If the syntax for the label format conflicts with the language syntax,
+use a @samp{-l} switch to change the format, for example
 
-To make the sub-tree export the default, customize the variable,
+@example
+#+BEGIN_SRC pascal -n -r -l "((%s))"
+@end example
+
+
+@noindent
+See also the variable @code{org-coderef-label-format}.
+
+HTML export also allows examples to be published as text areas (see
+@ref{Text areas in HTML export}).
+
+Because the @samp{#+BEGIN} @dots{} @samp{#+END} patterns need to be added so 
often,
+a shortcut is provided (see @ref{Structure Templates}).
+
+@table @asis
+@item @kbd{C-c '} (@code{org-edit-special})
+@kindex C-c '
+@findex org-edit-special
+Edit the source code example at point in its native mode.  This
+works by switching to a temporary buffer with the source code.  You
+need to exit by pressing @kbd{C-c '} again.  The edited version
+then replaces the old version in the Org buffer.  Fixed-width
+regions---where each line starts with a colon followed by
+a space---are edited using Artist mode@footnote{You may select a different 
mode with the variable
+@code{org-edit-fixed-width-region-mode}.} to allow creating
+ASCII drawings easily.  Using this command in an empty line creates
+a new fixed-width region.
+@end table
+
+@cindex storing link, in a source code buffer
+Calling @code{org-store-link} (see @ref{Handling Links}) while editing a source
+code example in a temporary buffer created with @kbd{C-c '}
+prompts for a label.  Make sure that it is unique in the current
+buffer, and insert it with the proper formatting like @samp{(ref:label)} at
+the end of the current line.  Then the label is stored as a link
+@samp{(label)}, for retrieval with @kbd{C-c C-l}.
+
+@node Images
+@section Images
+
+@cindex inlining images
+@cindex images, markup rules
+An image is a link to an image file@footnote{What Emacs considers to be an 
image depends on
+@code{image-file-name-extensions} and @code{image-file-name-regexps}.} that 
does not have
+a description part, for example
+
+@example
+./img/cat.jpg
+@end example
+
+
+If you wish to define a caption for the image (see @ref{Captions}) and
+maybe a label for internal cross references (see @ref{Internal Links}),
+make sure that the link is on a line by itself and precede it with
+@samp{CAPTION} and @samp{NAME} keywords as follows:
+
+@example
+#+CAPTION: This is the caption for the next figure link (or table)
+#+NAME:   fig:SED-HR4049
+[[./img/a.jpg]]
+@end example
+
+Such images can be displayed within the buffer with the following
+command:
+
+@table @asis
+@item @kbd{C-c C-x C-v} (@code{org-toggle-inline-images})
+@kindex C-c C-x C-v
+@findex org-toggle-inline-images
+@vindex org-startup-with-inline-images
+Toggle the inline display of linked images.  When called with
+a prefix argument, also display images that do have a link
+description.  You can ask for inline images to be displayed at
+startup by configuring the variable
+@code{org-startup-with-inline-images}@footnote{The variable 
@code{org-startup-with-inline-images} can be set
+within a buffer with the @samp{STARTUP} options @samp{inlineimages} and
+@samp{noinlineimages}.}.
+@end table
+
+@node Captions
+@section Captions
+
+@cindex captions, markup rules
+@cindex @samp{CAPTION}, keyword
+
+You can assign a caption to a specific part of a document by inserting
+a @samp{CAPTION} keyword immediately before it:
+
+@example
+#+CAPTION: This is the caption for the next table (or link)
+| ... | ... |
+|-----+-----|
+@end example
+
+Optionally, the caption can take the form:
+
+@example
+#+CAPTION[Short caption]: Longer caption.
+@end example
+
+
+Even though images and tables are prominent examples of captioned
+structures, the same caption mechanism can apply to many
+others---e.g., @LaTeX{} equations, source code blocks.  Depending on the
+export back-end, those may or may not be handled.
+
+@node Horizontal Rules
+@section Horizontal Rules
+
+@cindex horizontal rules, markup rules
+A line consisting of only dashes, and at least 5 of them, is exported
+as a horizontal line.
+
+@node Creating Footnotes
+@section Creating Footnotes
+
+@cindex footnotes
+
+A footnote is started by a footnote marker in square brackets in
+column 0, no indentation allowed.  It ends at the next footnote
+definition, headline, or after two consecutive empty lines.  The
+footnote reference is simply the marker in square brackets, inside
+text.  Markers always start with @samp{fn:}.  For example:
+
+@example
+The Org homepage[fn:1] now looks a lot better than it used to.
+...
+[fn:1] The link is: https://orgmode.org
+@end example
+
+Org mode extends the number-based syntax to @emph{named} footnotes and
+optional inline definition.  Here are the valid references:
+
+@table @asis
+@item @samp{[fn:NAME]}
+A named footnote reference, where @var{NAME} is a unique
+label word, or, for simplicity of automatic creation, a number.
+
+@item @samp{[fn:: This is the inline definition of this footnote]}
+An anonymous footnote where the definition is given directly at the
+reference point.
+
+@item @samp{[fn:NAME: a definition]}
+An inline definition of a footnote, which also specifies a name for
+the note.  Since Org allows multiple references to the same note,
+you can then use @samp{[fn:NAME]} to create additional references.
+@end table
+
+@vindex org-footnote-auto-label
+Footnote labels can be created automatically, or you can create names
+yourself.  This is handled by the variable @code{org-footnote-auto-label}
+and its corresponding @samp{STARTUP} keywords.  See the docstring of that
+variable for details.
+
+The following command handles footnotes:
+
+@table @asis
+@item @kbd{C-c C-x f}
+The footnote action command.
+
+@kindex C-c C-x f
+When point is on a footnote reference, jump to the definition.  When
+it is at a definition, jump to the---first---reference.
+
+@vindex org-footnote-define-inline
+@vindex org-footnote-section
+Otherwise, create a new footnote.  Depending on the variable
+@code{org-footnote-define-inline}@footnote{The corresponding in-buffer setting 
is: @samp{#+STARTUP: fninline}
+or @samp{#+STARTUP: nofninline}.}, the definition is placed right
+into the text as part of the reference, or separately into the
+location determined by the variable @code{org-footnote-section}.
+
+When this command is called with a prefix argument, a menu of
+additional options is offered:
+
+@multitable @columnfractions 0.1 0.9
+@item @kbd{s}
+@tab Sort the footnote definitions by reference sequence.
+@item @kbd{r}
+@tab Renumber the simple @samp{fn:N} footnotes.
+@item @kbd{S}
+@tab Short for first @kbd{r}, then @kbd{s} action.
+@item @kbd{n}
+@tab Rename all footnotes into a @samp{fn:1} @dots{} @samp{fn:n} sequence.
+@item @kbd{d}
+@tab Delete the footnote at point, including definition and references.
+@end multitable
+
+@vindex org-footnote-auto-adjust
+Depending on the variable @code{org-footnote-auto-adjust}@footnote{The 
corresponding in-buffer options are @samp{#+STARTUP: fnadjust}
+and @samp{#+STARTUP: nofnadjust}.},
+renumbering and sorting footnotes can be automatic after each
+insertion or deletion.
+
+@item @kbd{C-c C-c}
+@kindex C-c C-c
+If point is on a footnote reference, jump to the definition.  If it
+is at the definition, jump back to the reference.  When called at
+a footnote location with a prefix argument, offer the same menu as
+@kbd{C-c C-x f}.
+
+@item @kbd{C-c C-o} or @kbd{mouse-1/2}
+@kindex C-c C-o
+@kindex mouse-1
+@kindex mouse-2
+Footnote labels are also links to the corresponding definition or
+reference, and you can use the usual commands to follow these links.
+@end table
+
+@node Exporting
+@chapter Exporting
+
+@cindex exporting
+
+At some point you might want to print your notes, publish them on the
+web, or share them with people not using Org.  Org can convert and
+export documents to a variety of other formats while retaining as much
+structure (see @ref{Document Structure}) and markup (see @ref{Markup for Rich 
Contents}) as possible.
+
+@cindex export back-end
+The libraries responsible for translating Org files to other formats
+are called @emph{back-ends}.  Org ships with support for the following
+back-ends:
+
+@itemize
+@item
+@emph{ascii} (ASCII format)
+@item
+@emph{beamer} (@LaTeX{} Beamer format)
+@item
+@emph{html} (HTML format)
+@item
+@emph{icalendar} (iCalendar format)
+@item
+@emph{latex} (@LaTeX{} format)
+@item
+@emph{md} (Markdown format)
+@item
+@emph{odt} (OpenDocument Text format)
+@item
+@emph{org} (Org format)
+@item
+@emph{texinfo} (Texinfo format)
+@item
+@emph{man} (Man page format)
+@end itemize
+
+Users can install libraries for additional formats from the Emacs
+packaging system. For easy discovery, these packages have a common
+naming scheme: @code{ox-NAME}, where @var{NAME} is a format.  For
+example, @code{ox-koma-letter} for @emph{koma-letter} back-end.  More libraries
+can be found in the @samp{contrib/} directory (see @ref{Installation}).
+
+@vindex org-export-backends
+Org only loads back-ends for the following formats by default: ASCII,
+HTML, iCalendar, @LaTeX{}, and ODT@.  Additional back-ends can be loaded
+in either of two ways: by configuring the @code{org-export-backends}
+variable, or by requiring libraries in the Emacs init file.  For
+example, to load the Markdown back-end, add this to your Emacs config:
+
+@lisp
+(require 'ox-md)
+@end lisp
+
+@menu
+* The Export Dispatcher::        The main interface.
+* Export Settings::              Common export settings.
+* Table of Contents::            The if and where of the table of contents.
+* Include Files::                Include additional files into a document.
+* Macro Replacement::            Use macros to create templates.
+* Comment Lines::                What will not be exported.
+* ASCII/Latin-1/UTF-8 export::   Exporting to flat files with encoding.
+* Beamer Export::                Producing presentations and slides.
+* HTML Export::                  Exporting to HTML.
+* @LaTeX{} Export::              Exporting to @LaTeX{} and processing to PDF.
+* Markdown Export::              Exporting to Markdown.
+* OpenDocument Text Export::     Exporting to OpenDocument Text.
+* Org Export::                   Exporting to Org.
+* Texinfo Export::               Exporting to Texinfo.
+* iCalendar Export::             Exporting to iCalendar.
+* Other Built-in Back-ends::     Exporting to a man page.
+* Advanced Export Configuration:: Fine-tuning the export output.
+* Export in Foreign Buffers::    Author tables and lists in Org syntax.
+@end menu
+
+@node The Export Dispatcher
+@section The Export Dispatcher
+
+@cindex dispatcher, for export commands
+@cindex export, dispatcher
+
+The export dispatcher is the main interface for Org's exports.
+A hierarchical menu presents the currently configured export formats.
+Options are shown as easy toggle switches on the same screen.
+
+@vindex org-export-dispatch-use-expert-ui
+Org also has a minimal prompt interface for the export dispatcher.
+When the variable @code{org-export-dispatch-use-expert-ui} is set to
+a non-@code{nil} value, Org prompts in the minibuffer.  To switch back to
+the hierarchical menu, press @kbd{?}.
+
+@table @asis
+@item @kbd{C-c C-e} (@code{org-export})
+@kindex C-c C-e
+@findex org-export
+
+Invokes the export dispatcher interface.  The options show default
+settings.  The @kbd{C-u} prefix argument preserves options from
+the previous export, including any sub-tree selections.
+@end table
+
+Org exports the entire buffer by default.  If the Org buffer has an
+active region, then Org exports just that region.
+
+Within the dispatcher interface, the following key combinations can
+further alter what is exported, and how.
+
+@table @asis
+@item @kbd{C-a}
+@kindex C-c C-e C-a
+
+Toggle asynchronous export.  Asynchronous export uses an external
+Emacs process with a specially configured initialization file to
+complete the exporting process in the background, without tying-up
+Emacs.  This is particularly useful when exporting long documents.
+
+Output from an asynchronous export is saved on the @emph{export stack}.
+To view this stack, call the export dispatcher with a double
+@kbd{C-u} prefix argument.  If already in the export dispatcher
+menu, @kbd{&} displays the stack.
+
+@vindex org-export-in-background
+You can make asynchronous export the default by setting
+@code{org-export-in-background}.
+
+@vindex org-export-async-init-file
+You can set the initialization file used by the background process
+by setting @code{org-export-async-init-file}.
+
+@item @kbd{C-b}
+@kindex C-c C-e C-b
+
+Toggle body-only export.  Useful for excluding headers and footers
+in the export.  Affects only those back-end formats that have
+sections like @samp{<head>...</head>} in HTML@.
+
+@item @kbd{C-s}
+@kindex C-c C-e C-s
+
+Toggle sub-tree export.  When turned on, Org exports only the
+sub-tree starting from point position at the time the export
+dispatcher was invoked.  Org uses the top heading of this sub-tree
+as the document's title.  If point is not on a heading, Org uses the
+nearest enclosing header.  If point is in the document preamble, Org
+signals an error and aborts export.
+
+@vindex org-export-initial-scope
+To make sub-tree export the default, customize the variable
 @code{org-export-initial-scope}.
 
-@item C-v
-Toggle visible-only export.  Useful for exporting only visible parts of an
-Org document by adjusting outline visibility settings.
+@item @kbd{C-v}
+@kindex C-c C-e C-v
+
+Toggle visible-only export.  This is useful for exporting only
+certain parts of an Org document by adjusting the visibility of
+particular headings.
 @end table
 
-@node Export settings
-@section Export settings
+@node Export Settings
+@section Export Settings
+
+@cindex options, for export
 @cindex Export, settings
 
-@cindex @code{#+OPTIONS}
-Export options can be set: globally with variables; for an individual file by
-making variables buffer-local with in-buffer settings (@pxref{In-buffer
-settings}), by setting individual keywords, or by specifying them in a
-compact form with the @code{#+OPTIONS} keyword; or for a tree by setting
-properties (@pxref{Properties and columns}).  Options set at a specific level
-override options set at a more general level.
+@cindex @samp{OPTIONS}, keyword
+Export options can be set: globally with variables; for an individual
+file by making variables buffer-local with in-buffer settings (see
+@ref{In-buffer Settings}); by setting individual keywords or
+specifying them in compact form with the @samp{OPTIONS} keyword; or for
+a tree by setting properties (see @ref{Properties and Columns}).  Options
+set at a specific level override options set at a more general level.
 
-@cindex @code{#+SETUPFILE}
+@cindex @samp{SETUPFILE}, keyword
 In-buffer settings may appear anywhere in the file, either directly or
-indirectly through a file included using @samp{#+SETUPFILE: filename or URL}
-syntax.  Option keyword sets tailored to a particular back-end can be
-inserted from the export dispatcher (@pxref{The export dispatcher}) using the
-@code{Insert template} command by pressing @kbd{#}.  To insert keywords
-individually, a good way to make sure the keyword is correct is to type
-@code{#+} and then to use @kbd{M-@key{TAB}}@footnote{Many desktops intercept
-@kbd{M-@key{TAB}} to switch windows.  Use @kbd{C-M-i} or @kbd{@key{ESC}
-@key{TAB}} instead.} for completion.
-
-The export keywords available for every back-end, and their equivalent global
-variables, include:
-
-@table @samp
-@item AUTHOR
-@cindex @code{#+AUTHOR}
+indirectly through a file included using @samp{#+SETUPFILE: filename or
+URL} syntax.  Option keyword sets tailored to a particular back-end
+can be inserted from the export dispatcher (see @ref{The Export Dispatcher}) 
using the @samp{Insert template} command by pressing
+@kbd{#}.  To insert keywords individually, a good way to make
+sure the keyword is correct is to type @samp{#+} and then to use
+@kbd{M-@key{TAB}}@footnote{Many desktops intercept @kbd{M-@key{TAB}} to switch 
windows.
+Use @kbd{C-M-i} or @kbd{@key{ESC} @key{TAB}} instead.} for completion.
+
+The export keywords available for every back-end, and their equivalent
+global variables, include:
+
+@table @asis
+@item @samp{AUTHOR}
+@cindex @samp{AUTHOR}, keyword
 @vindex user-full-name
 The document author (@code{user-full-name}).
 
-@item CREATOR
-@cindex @code{#+CREATOR}
-@vindex org-export-creator-string
-Entity responsible for output generation (@code{org-export-creator-string}).
+@item @samp{CREATOR}
+@cindex @samp{CREATOR}, keyword
+@vindex org-expot-creator-string
+Entity responsible for output generation
+(@code{org-export-creator-string}).
 
-@item DATE
-@cindex @code{#+DATE}
+@item @samp{DATE}
+@cindex @samp{DATE}, keyword
 @vindex org-export-date-timestamp-format
-A date or a time-stamp@footnote{The variable
-@code{org-export-date-timestamp-format} defines how this time-stamp will be
-exported.}.
+A date or a time-stamp@footnote{The variable 
@code{org-export-date-timestamp-format} defines how
+this timestamp are exported.}.
 
-@item EMAIL
-@cindex @code{#+EMAIL}
+@item @samp{EMAIL}
+@cindex @samp{EMAIL}, keyword
 @vindex user-mail-address
 The email address (@code{user-mail-address}).
 
-@item LANGUAGE
-@cindex @code{#+LANGUAGE}
+@item @samp{LANGUAGE}
+@cindex @samp{LANGUAGE}, keyword
 @vindex org-export-default-language
 Language to use for translating certain strings
 (@code{org-export-default-language}).  With @samp{#+LANGUAGE: fr}, for
-example, Org translates @emph{Table of contents} to the French @emph{Table
-des matières}.
+example, Org translates @samp{Table of contents} to the French @samp{Table des
+  matières}@footnote{For export to @LaTeX{} format---or @LaTeX{}-related 
formats such as
+Beamer---, the @samp{org-latex-package-alist} variable needs further
+configuration. See @ref{@LaTeX{} specific export settings}.}.
 
-@item SELECT_TAGS
-@cindex @code{#+SELECT_TAGS}
+@item @samp{SELECT_TAGS}
+@cindex @samp{SELECT_TAGS}, keyword
 @vindex org-export-select-tags
-The default value is @code{:export:}.  When a tree is tagged with
-@code{:export:} (@code{org-export-select-tags}), Org selects that tree and
-its sub-trees for export.  Org excludes trees with @code{:noexport:} tags,
-see below.  When selectively exporting files with @code{:export:} tags set,
-Org does not export any text that appears before the first headline.
-
-@item EXCLUDE_TAGS
-@cindex @code{#+EXCLUDE_TAGS}
+The default value is @samp{("export")}.  When a tree is tagged with
+@samp{export} (@code{org-export-select-tags}), Org selects that tree and its
+sub-trees for export.  Org excludes trees with @samp{noexport} tags, see
+below.  When selectively exporting files with @samp{export} tags set, Org
+does not export any text that appears before the first headline.
+
+@item @samp{EXCLUDE_TAGS}
+@cindex @samp{EXCLUDE_TAGS}, keyword
 @vindex org-export-exclude-tags
-The default value is @code{:noexport:}.  When a tree is tagged with
-@code{:noexport:} (@code{org-export-exclude-tags}), Org excludes that tree
-and its sub-trees from export.  Entries tagged with @code{:noexport:} will be
+The default value is @samp{("noexport")}.  When a tree is tagged with
+@samp{noexport} (@code{org-export-exclude-tags}), Org excludes that tree and
+its sub-trees from export.  Entries tagged with @samp{noexport} are
 unconditionally excluded from the export, even if they have an
-@code{:export:} tag.  Even if a sub-tree is not exported, Org will execute any
-code blocks contained in them.
+@samp{export} tag.  Even if a sub-tree is not exported, Org executes any
+code blocks contained there.
 
-@item TITLE
-@cindex @code{#+TITLE}
+@item @samp{TITLE}
+@cindex @samp{TITLE}, keyword
 @cindex document title
-Org displays this title.  For long titles, use multiple @code{#+TITLE} lines.
+Org displays this title.  For long titles, use multiple @samp{#+TITLE}
+lines.
 
-@item EXPORT_FILE_NAME
-@cindex @code{#+EXPORT_FILE_NAME}
-The name of the output file to be generated.  Otherwise, Org generates the
-file name based on the buffer name and the extension based on the back-end
-format.
+@item @samp{EXPORT_FILE_NAME}
+@cindex @samp{EXPORT_FILE_NAME}, keyword
+The name of the output file to be generated.  Otherwise, Org
+generates the file name based on the buffer name and the extension
+based on the back-end format.
 @end table
 
-The @code{#+OPTIONS} keyword is a compact form.  To configure multiple
-options, use several @code{#+OPTIONS} lines.  @code{#+OPTIONS} recognizes the
+The @samp{OPTIONS} keyword is a compact form.  To configure multiple
+options, use several @samp{OPTIONS} lines.  @samp{OPTIONS} recognizes the
 following arguments.
 
-@table @code
-@item ':
+@table @asis
+@item @code{'}
 @vindex org-export-with-smart-quotes
-Toggle smart quotes (@code{org-export-with-smart-quotes}).  Depending on the
-language used, when activated, Org treats pairs of double quotes as primary
-quotes, pairs of single quotes as secondary quotes, and single quote marks as
-apostrophes.
+Toggle smart quotes (@code{org-export-with-smart-quotes}).  Depending on
+the language used, when activated, Org treats pairs of double quotes
+as primary quotes, pairs of single quotes as secondary quotes, and
+single quote marks as apostrophes.
 
-@item *:
+@item @code{*}
+@vindex org-export-with-emphasize
 Toggle emphasized text (@code{org-export-with-emphasize}).
 
-@item -:
+@item @code{-}
 @vindex org-export-with-special-strings
 Toggle conversion of special strings
 (@code{org-export-with-special-strings}).
 
-@item ::
+@item @code{:}
 @vindex org-export-with-fixed-width
-Toggle fixed-width sections
-(@code{org-export-with-fixed-width}).
+Toggle fixed-width sections (@code{org-export-with-fixed-width}).
 
-@item <:
+@item @code{<}
 @vindex org-export-with-timestamps
 Toggle inclusion of time/date active/inactive stamps
 (@code{org-export-with-timestamps}).
 
-@item \n:
+@item @code{\n}
 @vindex org-export-preserve-breaks
-Toggles whether to preserve line breaks (@code{org-export-preserve-breaks}).
+Toggles whether to preserve line breaks
+(@code{org-export-preserve-breaks}).
 
-@item ^:
+@item @code{^}
 @vindex org-export-with-sub-superscripts
-Toggle @TeX{}-like syntax for sub- and superscripts.  If you write "^:@{@}",
-@samp{a_@{b@}} will be interpreted, but the simple @samp{a_b} will be left as
-it is (@code{org-export-with-sub-superscripts}).
+Toggle @TeX{}-like syntax for sub- and superscripts.  If you write
+@samp{^:@{@}}, @samp{a_@{b@}} is interpreted, but the simple @samp{a_b} is 
left as it
+is (@code{org-export-with-sub-superscripts}).
 
-@item arch:
+@item @code{arch}
 @vindex org-export-with-archived-trees
-Configure how archived trees are exported.  When set to @code{headline}, the
-export process skips the contents and processes only the headlines
-(@code{org-export-with-archived-trees}).
+Configure how archived trees are exported.  When set to @code{headline},
+the export process skips the contents and processes only the
+headlines (@code{org-export-with-archived-trees}).
 
-@item author:
+@item @code{author}
 @vindex org-export-with-author
 Toggle inclusion of author name into exported file
 (@code{org-export-with-author}).
 
-@item broken-links:
+@item @code{broken-links}
 @vindex org-export-with-broken-links
-Toggles if Org should continue exporting upon finding a broken internal link.
-When set to @code{mark}, Org clearly marks the problem link in the output
-(@code{org-export-with-broken-links}).
+Toggles if Org should continue exporting upon finding a broken
+internal link.  When set to @code{mark}, Org clearly marks the problem
+link in the output (@code{org-export-with-broken-links}).
 
-@item c:
+@item @code{c}
 @vindex org-export-with-clocks
-Toggle inclusion of CLOCK keywords (@code{org-export-with-clocks}).
+Toggle inclusion of @samp{CLOCK} keywords (@code{org-export-with-clocks}).
 
-@item creator:
+@item @code{creator}
 @vindex org-export-with-creator
 Toggle inclusion of creator information in the exported file
 (@code{org-export-with-creator}).
 
-@item d:
+@item @code{d}
 @vindex org-export-with-drawers
-Toggles inclusion of drawers, or list of drawers to include, or list of
-drawers to exclude (@code{org-export-with-drawers}).
+Toggles inclusion of drawers, or list of drawers to include, or list
+of drawers to exclude (@code{org-export-with-drawers}).
 
-@item date:
+@item @code{date}
 @vindex org-export-with-date
-Toggle inclusion of a date into exported file (@code{org-export-with-date}).
+Toggle inclusion of a date into exported file
+(@code{org-export-with-date}).
 
-@item e:
+@item @code{e}
 @vindex org-export-with-entities
 Toggle inclusion of entities (@code{org-export-with-entities}).
 
-@item email:
+@item @code{email}
 @vindex org-export-with-email
 Toggle inclusion of the author's e-mail into exported file
 (@code{org-export-with-email}).
 
-@item f:
+@item @code{f}
 @vindex org-export-with-footnotes
 Toggle the inclusion of footnotes (@code{org-export-with-footnotes}).
 
-@item H:
+@item @code{H}
 @vindex org-export-headline-levels
 Set the number of headline levels for export
-(@code{org-export-headline-levels}).  Below that level, headlines are treated
-differently.  In most back-ends, they become list items.
+(@code{org-export-headline-levels}).  Below that level, headlines are
+treated differently.  In most back-ends, they become list items.
 
-@item inline:
+@item @code{inline}
 @vindex org-export-with-inlinetasks
 Toggle inclusion of inlinetasks (@code{org-export-with-inlinetasks}).
 
-@item num:
+@item @code{num}
 @vindex org-export-with-section-numbers
-@cindex property, @code{UNNUMBERED}
-Toggle section-numbers (@code{org-export-with-section-numbers}).  When set to
-number @samp{n}, Org numbers only those headlines at level @samp{n} or above.
-Setting @code{UNNUMBERED} property to non-@code{nil} disables numbering of
-a heading.  Since subheadings inherit from this property, it affects their
-numbering, too.
-
-@item p:
+@cindex @samp{UNNUMBERED}, property
+Toggle section-numbers (@code{org-export-with-section-numbers}).  When
+set to number N, Org numbers only those headlines at level N or
+above.  Set @samp{UNNUMBERED} property to non-@code{nil} to disable numbering
+of heading and subheadings entirely.  Moreover, when the value is
+@samp{notoc} the headline, and all its children, do not appear in the
+table of contents either (see @ref{Table of Contents}).
+
+@item @code{p}
 @vindex org-export-with-planning
 Toggle export of planning information (@code{org-export-with-planning}).
-``Planning information'' comes from lines located right after the headline
-and contain any combination of these cookies: @code{SCHEDULED:},
-@code{DEADLINE:}, or @code{CLOSED:}.
+``Planning information'' comes from lines located right after the
+headline and contain any combination of these cookies: @samp{SCHEDULED},
+@samp{DEADLINE}, or @samp{CLOSED}.
 
-@item pri:
+@item @code{pri}
 @vindex org-export-with-priority
-Toggle inclusion of priority cookies (@code{org-export-with-priority}).
+Toggle inclusion of priority cookies
+(@code{org-export-with-priority}).
 
-@item prop:
+@item @code{prop}
 @vindex org-export-with-properties
-Toggle inclusion of property drawers, or list the properties to include
-(@code{org-export-with-properties}).
+Toggle inclusion of property drawers, or list the properties to
+include (@code{org-export-with-properties}).
 
-@item stat:
+@item @code{stat}
 @vindex org-export-with-statistics-cookies
 Toggle inclusion of statistics cookies
 (@code{org-export-with-statistics-cookies}).
 
-@item tags:
+@item @code{tags}
 @vindex org-export-with-tags
 Toggle inclusion of tags, may also be @code{not-in-toc}
 (@code{org-export-with-tags}).
 
-@item tasks:
+@item @code{tasks}
 @vindex org-export-with-tasks
-Toggle inclusion of tasks (TODO items); or @code{nil} to remove all tasks; or
-@code{todo} to remove DONE tasks; or list the keywords to keep
+Toggle inclusion of tasks (TODO items); or @code{nil} to remove all
+tasks; or @code{todo} to remove done tasks; or list the keywords to keep
 (@code{org-export-with-tasks}).
 
-@item tex:
+@item @code{tex}
 @vindex org-export-with-latex
-@code{nil} does not export; @code{t} exports; @code{verbatim} keeps
-everything in verbatim (@code{org-export-with-latex}).
+@code{nil} does not export; @code{t} exports; @code{verbatim} keeps everything 
in
+verbatim (@code{org-export-with-latex}).
 
-@item timestamp:
+@item @code{timestamp}
 @vindex org-export-time-stamp-file
 Toggle inclusion of the creation time in the exported file
 (@code{org-export-time-stamp-file}).
 
-@item title:
+@item @code{title}
 @vindex org-export-with-title
 Toggle inclusion of title (@code{org-export-with-title}).
 
-@item toc:
+@item @code{toc}
 @vindex org-export-with-toc
 Toggle inclusion of the table of contents, or set the level limit
 (@code{org-export-with-toc}).
 
-@item todo:
+@item @code{todo}
 @vindex org-export-with-todo-keywords
 Toggle inclusion of TODO keywords into exported text
 (@code{org-export-with-todo-keywords}).
 
-@item |:
+@item @code{|}
 @vindex org-export-with-tables
 Toggle inclusion of tables (@code{org-export-with-tables}).
-
 @end table
 
-When exporting sub-trees, special node properties in them can override the
-above keywords.  They are special because they have an @samp{EXPORT_} prefix.
-For example, @samp{DATE} and @samp{EXPORT_FILE_NAME} keywords become,
-respectively, @samp{EXPORT_DATE} and @samp{EXPORT_FILE_NAME}.  Except for
-@samp{SETUPFILE}, all other keywords listed above have an @samp{EXPORT_}
-equivalent.
+When exporting sub-trees, special node properties can override the
+above keywords.  These properties have an @samp{EXPORT_} prefix.  For
+example, @samp{DATE} becomes, @samp{EXPORT_DATE} when used for a specific
+sub-tree.  Except for @samp{SETUPFILE}, all other keywords listed above
+have an @samp{EXPORT_} equivalent.
 
-@cindex @code{#+BIND}
+@cindex @samp{BIND}, keyword
 @vindex org-export-allow-bind-keywords
-If @code{org-export-allow-bind-keywords} is non-@code{nil}, Emacs variables
-can become buffer-local during export by using the BIND keyword.  Its syntax
-is @samp{#+BIND: variable value}.  This is particularly useful for in-buffer
-settings that cannot be changed using keywords.
+If @code{org-export-allow-bind-keywords} is non-@code{nil}, Emacs variables can
+become buffer-local during export by using the @samp{BIND} keyword.  Its
+syntax is @samp{#+BIND: variable value}.  This is particularly useful for
+in-buffer settings that cannot be changed using keywords.
+
+@node Table of Contents
+@section Table of Contents
 
-@node Table of contents
-@section Table of contents
 @cindex table of contents
 @cindex list of tables
 @cindex list of listings
 
-@cindex @code{#+TOC}
+@cindex @samp{toc}, in @samp{OPTIONS} keyword
 @vindex org-export-with-toc
-Org normally inserts the table of contents directly before the first headline
-of the file.  Org sets the TOC depth the same as the headline levels in the
-file.  Use a lower number for lower TOC depth.  To turn off TOC entirely, use
-@code{nil}.  This is configured in the @code{org-export-with-toc} variable or
-as keywords in an Org file as:
+The table of contents includes all headlines in the document.  Its
+depth is therefore the same as the headline levels in the file.  If
+you need to use a different depth, or turn it off entirely, set the
+@code{org-export-with-toc} variable accordingly.  You can achieve the same
+on a per file basis, using the following @samp{toc} item in @samp{OPTIONS}
+keyword:
 
 @example
-#+OPTIONS: toc:2          @r{only include two levels in TOC}
-#+OPTIONS: toc:nil        @r{no default TOC at all}
+#+OPTIONS: toc:2          (only include two levels in TOC)
+#+OPTIONS: toc:nil        (no default TOC at all)
 @end example
 
-To move the table of contents to a different location, first turn off the
-default with @code{org-export-with-toc} variable or with @code{#+OPTIONS:
-toc:nil}.  Then insert @code{#+TOC: headlines N} at the desired location(s).
+@cindex excluding entries from table of contents
+@cindex table of contents, exclude entries
+Org includes both numbered and unnumbered headlines in the table of
+contents@footnote{At the moment, some export back-ends do not obey this
+specification.  For example, @LaTeX{} export excludes every unnumbered
+headline from the table of contents.}.  If you need to exclude an unnumbered 
headline,
+along with all its children, set the @samp{UNNUMBERED} property to @samp{notoc}
+value.
+
+@example
+* Subtree not numbered, not in table of contents either
+  :PROPERTIES:
+  :UNNUMBERED: notoc
+  :END:
+@end example
+
+@cindex @samp{TOC}, keyword
+Org normally inserts the table of contents directly before the first
+headline of the file.  To move the table of contents to a different
+location, first turn off the default with @code{org-export-with-toc}
+variable or with @samp{#+OPTIONS: toc:nil}.  Then insert @samp{#+TOC: headlines
+N} at the desired location(s).
 
 @example
-#+OPTIONS: toc:nil        @r{no default TOC}
+#+OPTIONS: toc:nil
 ...
-#+TOC: headlines 2        @r{insert TOC here, with two headline levels}
+#+TOC: headlines 2
 @end example
 
-To adjust the TOC depth for a specific section of the Org document, append an
-additional @samp{local} parameter.  This parameter becomes a relative depth
-for the current level.
+To adjust the table of contents depth for a specific section of the
+Org document, append an additional @samp{local} parameter.  This parameter
+becomes a relative depth for the current level.  The following example
+inserts a local table of contents, with direct children only.
 
-Note that for this feature to work properly in @LaTeX{} export, the Org file
-requires the inclusion of the @code{titletoc} package.  Because of
-compatibility issues, @code{titletoc} has to be loaded @emph{before}
-@code{hyperref}.  Customize the @code{org-latex-default-packages-alist}
-variable.
+@example
+* Section
+#+TOC: headlines 1 local
+@end example
+
+Note that for this feature to work properly in @LaTeX{} export, the Org
+file requires the inclusion of the titletoc package.  Because of
+compatibility issues, titletoc has to be loaded @emph{before} hyperref.
+Customize the @code{org-latex-default-packages-alist} variable.
+
+The following example inserts a table of contents that links to the
+children of the specified target.
 
 @example
-* Section #+TOC: headlines 1 local @r{insert local TOC, with direct children
-only}
+* Target
+  :PROPERTIES:
+  :CUSTOM_ID: TargetSection
+  :END:
+** Heading A
+** Heading B
+* Another section
+#+TOC: headlines 1 :target #TargetSection
 @end example
 
-Use the @code{TOC} keyword to generate list of tables (resp.@: all listings)
-with captions.
+The @samp{:target} attribute is supported in HTML, Markdown, ODT, and ASCII 
export.
+
+Use the @samp{TOC} keyword to generate list of tables---respectively, all
+listings---with captions.
 
 @example
-#+TOC: listings           @r{build a list of listings}
-#+TOC: tables             @r{build a list of tables}
+#+TOC: listings
+#+TOC: tables
 @end example
 
-@cindex property, @code{ALT_TITLE}
-Normally Org uses the headline for its entry in the table of contents.  But
-with @code{ALT_TITLE} property, a different entry can be specified for the
-table of contents.
+@cindex @samp{ALT_TITLE}, property
+Normally Org uses the headline for its entry in the table of contents.
+But with @samp{ALT_TITLE} property, a different entry can be specified for
+the table of contents.
+
+@node Include Files
+@section Include Files
 
-@node Include files
-@section Include files
 @cindex include files, during export
-Include other files during export.  For example, to include your @file{.emacs}
-file, you could use:
-@cindex @code{#+INCLUDE}
+@cindex export, include files
+@cindex @samp{INCLUDE}, keyword
+
+During export, you can include the content of another file.  For
+example, to include your @samp{.emacs} file, you could use:
 
 @example
 #+INCLUDE: "~/.emacs" src emacs-lisp
 @end example
 
+
 @noindent
 The first parameter is the file name to include.  The optional second
-parameter specifies the block type: @samp{example}, @samp{export} or
-@samp{src}.  The optional third parameter specifies the source code language
-to use for formatting the contents.  This is relevant to both @samp{export}
-and @samp{src} block types.
-
-If an include file is specified as having a markup language, Org neither
-checks for valid syntax nor changes the contents in any way.  For
-@samp{example} and @samp{src} blocks, Org code-escapes the contents before
+parameter specifies the block type: @samp{example}, @samp{export} or 
@samp{src}.  The
+optional third parameter specifies the source code language to use for
+formatting the contents.  This is relevant to both @samp{export} and @samp{src}
+block types.
+
+If an included file is specified as having a markup language, Org
+neither checks for valid syntax nor changes the contents in any way.
+For example and source blocks, Org code-escapes the contents before
 inclusion.
 
-If an include file is not specified as having any markup language, Org
-assumes it be in Org format and proceeds as usual with a few exceptions.  Org
-makes the footnote labels (@pxref{Footnotes}) in the included file local to
-that file.  The contents of the included file will belong to the same
-structure---headline, item---containing the @code{INCLUDE} keyword.  In
-particular, headlines within the file will become children of the current
-section.  That behavior can be changed by providing an additional keyword
-parameter, @code{:minlevel}.  It shifts the headlines in the included file to
-become the lowest level.  For example, this syntax makes the included file
-a sibling of the current top-level headline:
+@cindex @samp{minlevel}, include
+If an included file is not specified as having any markup language,
+Org assumes it be in Org format and proceeds as usual with a few
+exceptions.  Org makes the footnote labels (see @ref{Creating Footnotes})
+in the included file local to that file.  The contents of the included
+file belong to the same structure---headline, item---containing the
+@samp{INCLUDE} keyword.  In particular, headlines within the file become
+children of the current section.  That behavior can be changed by
+providing an additional keyword parameter, @samp{:minlevel}.  It shifts the
+headlines in the included file to become the lowest level.  For
+example, this syntax makes the included file a sibling of the current
+top-level headline:
 
 @example
 #+INCLUDE: "~/my-book/chapter2.org" :minlevel 1
 @end example
 
-Inclusion of only portions of files are specified using ranges parameter with
-@code{:lines} keyword.  The line at the upper end of the range will not be
-included.  The start and/or the end of the range may be omitted to use the
-obvious defaults.
+
+@cindex @samp{lines}, include
+Inclusion of only portions of files are specified using ranges
+parameter with @samp{:lines} keyword.  The line at the upper end of the
+range will not be included.  The start and/or the end of the range may
+be omitted to use the obvious defaults.
+
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{#+INCLUDE: "~/.emacs" :lines "5-10"}
+@tab Include lines 5 to 10, 10 excluded
+@item @samp{#+INCLUDE: "~/.emacs" :lines "-10"}
+@tab Include lines 1 to 10, 10 excluded
+@item @samp{#+INCLUDE: "~/.emacs" :lines "10-"}
+@tab Include lines from 10 to EOF
+@end multitable
+
+Inclusions may specify a file-link to extract an object matched by
+@code{org-link-search}@footnote{Note that 
@code{org-link-search-must-match-exact-headline} is
+locally bound to non-@code{nil}.  Therefore, @code{org-link-search} only 
matches
+headlines and named elements.} (see @ref{Search Options}).  The
+ranges for @samp{:lines} keyword are relative to the requested element.
+Therefore,
 
 @example
-#+INCLUDE: "~/.emacs" :lines "5-10"   @r{Include lines 5 to 10, 10 excluded}
-#+INCLUDE: "~/.emacs" :lines "-10"    @r{Include lines 1 to 10, 10 excluded}
-#+INCLUDE: "~/.emacs" :lines "10-"    @r{Include lines from 10 to EOF}
+#+INCLUDE: "./paper.org::*conclusion" :lines 1-20
 @end example
 
-Inclusions may specify a file-link to extract an object matched by
-@code{org-link-search}@footnote{Note that
-@code{org-link-search-must-match-exact-headline} is locally bound to
-non-@code{nil}.  Therefore, @code{org-link-search} only matches headlines and
-named elements.}  (@pxref{Search options}).
 
-To extract only the contents of the matched object, set @code{:only-contents}
-property to non-@code{nil}.  This will omit any planning lines or property
-drawers.  The ranges for @code{:lines} keyword are relative to the requested
-element.  Some examples:
+@noindent
+includes the first 20 lines of the headline named @samp{conclusion}.
+
+@cindex @samp{only-contents}, include
+To extract only the contents of the matched object, set
+@samp{:only-contents} property to non-@code{nil}.  This omits any planning 
lines
+or property drawers.  For example, to include the body of the heading
+with the custom ID @samp{theory}, you can use
 
 @example
 #+INCLUDE: "./paper.org::#theory" :only-contents t
-   @r{Include the body of the heading with the custom id @samp{theory}}
-#+INCLUDE: "./paper.org::mytable"  @r{Include named element.}
-#+INCLUDE: "./paper.org::*conclusion" :lines 1-20
-   @r{Include the first 20 lines of the headline named @samp{conclusion}.}
 @end example
 
-@table @kbd
+
+The following command allows navigating to the included document:
+
+@table @asis
+@item @kbd{C-c '} (@code{org-edit~special})
 @kindex C-c '
-@item C-c '
-Visit the include file at point.
+@findex org-edit-special
+
+Visit the included file at point.
 @end table
 
-@node Macro replacement
-@section Macro replacement
+@node Macro Replacement
+@section Macro Replacement
+
 @cindex macro replacement, during export
-@cindex @code{#+MACRO}
+@cindex @samp{MACRO}, keyword
 
 @vindex org-export-global-macros
-Macros replace text snippets during export.  Macros are defined globally in
-@code{org-export-global-macros}, or document-wise with the following syntax:
+Macros replace text snippets during export.  Macros are defined
+globally in @code{org-export-global-macros}, or document-wise with the
+following syntax:
+
+@example
+#+MACRO: name   replacement text; $1, $2 are arguments
+@end example
+
+
+@noindent
+which can be referenced using @samp{@{@{@{name(arg1, 
arg2)@}@}@}}@footnote{Since commas separate the arguments, commas within 
arguments
+have to be escaped with the backslash character.  So only those
+backslash characters before a comma need escaping with another
+backslash character.}.  For
+example
+
+@example
+#+MACRO: poem Rose is $1, violet's $2. Life's ordered: Org assists you.
+@{@{@{poem(red,blue)@}@}@}
+@end example
+
+@noindent
+becomes
+
+@example
+Rose is red, violet's blue. Life's ordered: Org assists you.
+@end example
+
+
+As a special case, Org parses any replacement text starting with
+@samp{(eval} as an Emacs Lisp expression and evaluates it accordingly.
+Within such templates, arguments become strings.  Thus, the following
+macro
 
 @example
-#+MACRO: name   replacement text $1, $2 are arguments
+#+MACRO: gnustamp (eval (concat "GNU/" (capitalize $1)))
 @end example
 
-@noindent which can be referenced using
-@code{@{@{@{name(arg1, arg2)@}@}@}}@footnote{Since commas separate the
-arguments, commas within arguments have to be escaped with the backslash
-character.  So only those backslash characters before a comma need escaping
-with another backslash character.}.
 
-Org recognizes macro references in following Org markup areas: paragraphs,
-headlines, verse blocks, tables cells and lists.  Org also recognizes macro
-references in keywords, such as @code{#+CAPTION}, @code{#+TITLE},
-@code{#+AUTHOR}, @code{#+DATE}, and for some back-end specific export
-options.
+@noindent
+turns @samp{@{@{@{gnustamp(linux)@}@}@}} into @samp{GNU/Linux} during export.
+
+Org recognizes macro references in following Org markup areas:
+paragraphs, headlines, verse blocks, tables cells and lists.  Org also
+recognizes macro references in keywords, such as @samp{CAPTION}, @samp{TITLE},
+@samp{AUTHOR}, @samp{DATE}, and for some back-end specific export options.
 
 Org comes with following pre-defined macros:
 
-@table @code
-@item @{@{@{title@}@}@}
-@itemx @{@{@{author@}@}@}
-@itemx @{@{@{email@}@}@}
-@cindex title, macro
-@cindex author, macro
-@cindex email, macro
-Org replaces these macro references with available information at the time of
-export.
-
-@item @{@{@{date@}@}@}
-@itemx @{@{@{date(@var{FORMAT})@}@}@}
-@cindex date, macro
-This macro refers to the @code{#+DATE} keyword.  @var{FORMAT} is an optional
-argument to the @code{@{@{@{date@}@}@}} macro that will be used only if
-@code{#+DATE} is a single timestamp.  @var{FORMAT} should be a format string
+@table @asis
+@item @samp{@{@{@{keyword(NAME)@}@}@}}
+@itemx @samp{@{@{@{title@}@}@}}
+@itemx @samp{@{@{@{author@}@}@}}
+@itemx @samp{@{@{@{email@}@}@}}
+@cindex @samp{keyword}, macro
+@cindex @samp{title}, macro
+@cindex @samp{author}, macro
+@cindex @samp{email}, macro
+The @samp{keyword} macro collects all values from @var{NAME}
+keywords throughout the buffer, separated with white space.
+@samp{title}, @samp{author} and @samp{email} macros are shortcuts for,
+respectively, @samp{@{@{@{keyword(TITLE)@}@}@}}, 
@samp{@{@{@{keyword(AUTHOR)@}@}@}} and
+@samp{@{@{@{keyword(EMAIL)@}@}@}}.
+
+@item @samp{@{@{@{date@}@}@}}
+@itemx @samp{@{@{@{date(FORMAT)@}@}@}}
+@cindex @samp{date}, macro
+This macro refers to the @samp{DATE} keyword.  @var{FORMAT} is an
+optional argument to the @samp{date} macro that is used only if @samp{DATE} is
+a single timestamp.  @var{FORMAT} should be a format string
 understood by @code{format-time-string}.
 
-@item @{@{@{time(@var{FORMAT})@}@}@}
-@itemx @{@{@{modification-time(@var{FORMAT}, @var{VC})@}@}@}
-@cindex time, macro
-@cindex modification time, macro
-These macros refer to the document's date and time of export and date and
-time of modification.  @var{FORMAT} is a string understood by
-@code{format-time-string}.  If the second argument to the
-@code{modification-time} macro is non-@code{nil}, Org uses @file{vc.el} to
-retrieve the document's modification time from the version control
-system.  Otherwise Org reads the file attributes.
-
-@item @{@{@{input-file@}@}@}
-@cindex input file, macro
+@item @samp{@{@{@{time(FORMAT)@}@}@}}
+@itemx @samp{@{@{@{modification-time(FORMAT, VC)@}@}@}}
+@cindex @samp{time}, macro
+@cindex @samp{modification-time}, macro
+These macros refer to the document's date and time of export and
+date and time of modification.  @var{FORMAT} is a string
+understood by @code{format-time-string}.  If the second argument to the
+@code{modification-time} macro is non-@code{nil}, Org uses @samp{vc.el} to 
retrieve
+the document's modification time from the version control system.
+Otherwise Org reads the file attributes.
+
+@item @samp{@{@{@{input-file@}@}@}}
+@cindex @samp{input-file}, macro
 This macro refers to the filename of the exported file.
 
-@item @{@{@{property(@var{PROPERTY-NAME})@}@}@}
-@itemx @{@{@{property(@var{PROPERTY-NAME},@var{SEARCH-OPTION})@}@}@}
-@cindex property, macro
-This macro returns the value of property @var{PROPERTY-NAME} in the current
-entry.  If @var{SEARCH-OPTION} (@pxref{Search options}) refers to a remote
-entry, that will be used instead.
-
-@item @{@{@{n@}@}@}
-@itemx @{@{@{n(@var{NAME})@}@}@}
-@itemx @{@{@{n(@var{NAME},@var{ACTION})@}@}@}
-@cindex n, macro
+@item @samp{@{@{@{property(PROPERTY-NAME)@}@}@}}
+@itemx @samp{@{@{@{property(PROPERTY-NAME, SEARCH OPTION)@}@}@}}
+@cindex @samp{property}, macro
+This macro returns the value of property @var{PROPERTY-NAME} in
+the current entry.  If @var{SEARCH-OPTION} (see @ref{Search Options}) refers 
to a remote entry, use it instead.
+
+@item @samp{@{@{@{n@}@}@}}
+@itemx @samp{@{@{@{n(NAME)@}@}@}}
+@itemx @samp{@{@{@{n(NAME, ACTION)@}@}@}}
+@cindex @samp{n}, macro
 @cindex counter, macro
-This macro implements custom counters by returning the number of times the
-macro has been expanded so far while exporting the buffer.  You can create
-more than one counter using different @var{NAME} values.  If @var{ACTION} is
-@code{-}, previous value of the counter is held, i.e. the specified counter
-is not incremented.  If the value is a number, the specified counter is set
-to that value.  If it is any other non-empty string, the specified counter is
-reset to 1.  You may leave @var{NAME} empty to reset the default counter.
+This macro implements custom counters by returning the number of
+times the macro has been expanded so far while exporting the buffer.
+You can create more than one counter using different @var{NAME}
+values.  If @var{ACTION} is @samp{-}, previous value of the counter
+is held, i.e., the specified counter is not incremented.  If the
+value is a number, the specified counter is set to that value.  If
+it is any other non-empty string, the specified counter is reset
+to 1.  You may leave @var{NAME} empty to reset the default
+counter.
 @end table
 
+@cindex @samp{results}, macro
+Moreover, inline source blocks (see @ref{Structure of Code Blocks}) use the
+special @samp{results} macro to mark their output.  As such, you are
+advised against re-defining it, unless you know what you are doing.
+
+@vindex org-hide-macro-markers
 The surrounding brackets can be made invisible by setting
-@code{org-hide-macro-markers} non-@code{nil}.
+@code{org-hide-macro-markers} to a non-@code{nil} value.
 
 Org expands macros at the very beginning of the export process.
 
-@node Comment lines
-@section Comment lines
+@node Comment Lines
+@section Comment Lines
+
 @cindex exporting, not
 
 @cindex comment lines
@@ -11086,83 +12616,108 @@ Lines starting with zero or more whitespace 
characters followed by one
 @samp{#} and a whitespace are treated as comments and, as such, are not
 exported.
 
-@cindex @code{#+BEGIN_COMMENT}
-Likewise, regions surrounded by @code{#+BEGIN_COMMENT}
-... @code{#+END_COMMENT} are not exported.
+@cindex @samp{BEGIN_COMMENT}
+@cindex comment block
+Likewise, regions surrounded by @samp{#+BEGIN_COMMENT} @dots{} 
@samp{#+END_COMMENT}
+are not exported.
 
 @cindex comment trees
-Finally, a @samp{COMMENT} keyword at the beginning of an entry, but after any
-other keyword or priority cookie, comments out the entire subtree.  In this
-case, the subtree is not exported and no code block within it is executed
-either@footnote{For a less drastic behavior, consider using a select tag
-(@pxref{Export settings}) instead.}.  The command below helps changing the
+Finally, a @samp{COMMENT} keyword at the beginning of an entry, but after
+any other keyword or priority cookie, comments out the entire subtree.
+In this case, the subtree is not exported and no code block within it
+is executed either@footnote{For a less drastic behavior, consider using a 
select tag (see
+@ref{Export Settings}) instead.}.  The command below helps changing the
 comment status of a headline.
 
-@table @kbd
+@table @asis
+@item @kbd{C-c ;} (@code{org-toggle-comment})
 @kindex C-c ;
-@item C-c ;
+@findex org-toggle-comment
+
 Toggle the @samp{COMMENT} keyword at the beginning of an entry.
 @end table
 
 @node ASCII/Latin-1/UTF-8 export
 @section ASCII/Latin-1/UTF-8 export
+
 @cindex ASCII export
 @cindex Latin-1 export
 @cindex UTF-8 export
 
-ASCII export produces an output file containing only plain ASCII characters.
-This is the most simplest and direct text output.  It does not contain any
-Org markup either.  Latin-1 and UTF-8 export use additional characters and
-symbols available in these encoding standards.  All three of these export
-formats offer the most basic of text output for maximum portability.
+ASCII export produces an output file containing only plain ASCII
+characters.  This is the simplest and most direct text output.  It
+does not contain any Org markup.  Latin-1 and UTF-8 export use
+additional characters and symbols available in these encoding
+standards.  All three of these export formats offer the most basic of
+text output for maximum portability.
 
 @vindex org-ascii-text-width
-On export, Org fills and justifies text according to the text width set in
-@code{org-ascii-text-width}.
+On export, Org fills and justifies text according to the text width
+set in @code{org-ascii-text-width}.
 
 @vindex org-ascii-links-to-notes
-Org exports links using a footnote-like style where the descriptive part is
-in the text and the link is in a note before the next heading.  See the
-variable @code{org-ascii-links-to-notes} for details.
+Org exports links using a footnote-like style where the descriptive
+part is in the text and the link is in a note before the next heading.
+See the variable @code{org-ascii-links-to-notes} for details.
 
+@anchor{ASCII export commands}
 @subheading ASCII export commands
 
-@table @kbd
-@orgcmd{C-c C-e t a/l/u,org-ascii-export-to-ascii}
-Export as an ASCII file with a @file{.txt} extension.  For @file{myfile.org},
-Org exports to @file{myfile.txt}, overwriting without warning.  For
-@file{myfile.txt}, Org exports to @file{myfile.txt.txt} in order to prevent
+@table @asis
+@item @kbd{C-c C-e t a} (@code{org-ascii-export-to-ascii})
+@itemx @kbd{C-c C-e t l}
+@itemx @kbd{C-c C-e t u}
+@kindex C-c C-e t a
+@kindex C-c C-e t l
+@kindex C-c C-e t u
+@findex org-ascii-export-to-ascii
+
+Export as an ASCII file with a @samp{.txt} extension.  For @samp{myfile.org},
+Org exports to @samp{myfile.txt}, overwriting without warning.  For
+@samp{myfile.txt}, Org exports to @samp{myfile.txt.txt} in order to prevent
 data loss.
-@orgcmd{C-c C-e t A/L/U,org-ascii-export-as-ascii}
+
+@item @kbd{C-c C-e t A} (@code{org-ascii-export-to-ascii})
+@itemx @kbd{C-c C-e t L}
+@itemx @kbd{C-c C-e t U}
+@kindex C-c C-e t A
+@kindex C-c C-e t L
+@kindex C-c C-e t U
+@findex org-ascii-export-as-ascii
+
 Export to a temporary buffer.  Does not create a file.
 @end table
 
+@anchor{ASCII specific export settings}
 @subheading ASCII specific export settings
-The ASCII export back-end has one extra keyword for customizing ASCII output.
-Setting this keyword works similar to the general options (@pxref{Export
-settings}).
-
-@table @samp
-@item SUBTITLE
-@cindex @code{#+SUBTITLE} (ASCII)
-The document subtitle.  For long subtitles, use multiple @code{#+SUBTITLE}
-lines in the Org file.  Org prints them on one continuous line, wrapping into
-multiple lines if necessary.
+
+The ASCII export back-end has one extra keyword for customizing ASCII
+output.  Setting this keyword works similar to the general options
+(see @ref{Export Settings}).
+
+@table @asis
+@item @samp{SUBTITLE}
+@cindex @samp{SUBTITLE}, keyword
+The document subtitle.  For long subtitles, use multiple
+@samp{#+SUBTITLE} lines in the Org file.  Org prints them on one
+continuous line, wrapping into multiple lines if necessary.
 @end table
 
+@anchor{Header and sectioning structure}
 @subheading Header and sectioning structure
 
-Org converts the first three outline levels into headlines for ASCII export.
-The remaining levels are turned into lists.  To change this cut-off point
-where levels become lists, @pxref{Export settings}.
+Org converts the first three outline levels into headlines for ASCII
+export.  The remaining levels are turned into lists.  To change this
+cut-off point where levels become lists, see @ref{Export Settings}.
 
+@anchor{Quoting ASCII text}
 @subheading Quoting ASCII text
 
 To insert text within the Org file by the ASCII back-end, use one the
 following constructs, inline, keyword, or export block:
 
-@cindex @code{#+ASCII}
-@cindex @code{#+BEGIN_EXPORT ascii}
+@cindex @samp{ASCII}, keyword
+@cindex @samp{BEGIN_EXPORT ascii}
 @example
 Inline text @@@@ascii:and additional text@@@@ within a paragraph.
 
@@ -11173,25 +12728,29 @@ Org exports text in this block only when using ASCII 
back-end.
 #+END_EXPORT
 @end example
 
+@anchor{ASCII specific attributes}
 @subheading ASCII specific attributes
-@cindex @code{#+ATTR_ASCII}
+
+@cindex @samp{ATTR_ASCII}, keyword
 @cindex horizontal rules, in ASCII export
 
-ASCII back-end recognizes only one attribute, @code{:width}, which specifies
-the width of a horizontal rule in number of characters.  The keyword and
-syntax for specifying widths is:
+ASCII back-end recognizes only one attribute, @samp{:width}, which
+specifies the width of a horizontal rule in number of characters.  The
+keyword and syntax for specifying widths is:
 
 @example
 #+ATTR_ASCII: :width 10
 -----
 @end example
 
+@anchor{ASCII special blocks}
 @subheading ASCII special blocks
+
 @cindex special blocks, in ASCII export
-@cindex @code{#+BEGIN_JUSTIFYLEFT}
-@cindex @code{#+BEGIN_JUSTIFYRIGHT}
+@cindex @samp{BEGIN_JUSTIFYLEFT}
+@cindex @samp{BEGIN_JUSTIFYRIGHT}
 
-Besides @code{#+BEGIN_CENTER} blocks (@pxref{Paragraphs}), ASCII back-end has
+Besides @samp{#+BEGIN_CENTER} blocks (see @ref{Paragraphs}), ASCII back-end has
 these two left and right justification blocks:
 
 @example
@@ -11204,212 +12763,234 @@ It's just a jump to the left...
 #+END_JUSTIFYRIGHT
 @end example
 
-@node Beamer export
-@section Beamer export
+@node Beamer Export
+@section Beamer Export
+
 @cindex Beamer export
 
-Org uses @emph{Beamer} export to convert an Org file tree structure into a
-high-quality interactive slides for presentations.  @emph{Beamer} is a
-@LaTeX{} document class for creating presentations in PDF, HTML, and other
+Org uses Beamer export to convert an Org file tree structure into
+high-quality interactive slides for presentations.  Beamer is a @LaTeX{}
+document class for creating presentations in PDF, HTML, and other
 popular display formats.
 
 @menu
-* Beamer export commands::      For creating Beamer documents.
-* Beamer specific export settings::  For customizing Beamer export.
-* Sectioning Frames and Blocks in Beamer::  For composing Beamer slides.
-* Beamer specific syntax::      For using in Org documents.
-* Editing support::             For using helper functions.
-* A Beamer example::            A complete presentation.
+* Beamer export commands::       For creating Beamer documents.
+* Beamer specific export settings:: For customizing Beamer export.
+* Frames and Blocks in Beamer::  For composing Beamer slides.
+* Beamer specific syntax::       For using in Org documents.
+* Editing support::              Editing support.
+* A Beamer example::             A complete presentation.
 @end menu
 
 @node Beamer export commands
 @subsection Beamer export commands
 
-@table @kbd
-@orgcmd{C-c C-e l b,org-beamer-export-to-latex}
-Export as @LaTeX{} file with a @file{.tex} extension.  For @file{myfile.org},
-Org exports to @file{myfile.tex}, overwriting without warning.
-@orgcmd{C-c C-e l B,org-beamer-export-as-latex}
+@table @asis
+@item @kbd{C-c C-e l b} (@code{org-beamer-export-to-latex})
+@kindex C-c C-e l b
+@findex org-beamer-export-to-latex
+
+Export as @LaTeX{} file with a @samp{.tex} extension.  For @samp{myfile.org}, 
Org
+exports to @samp{myfile.tex}, overwriting without warning.
+
+@item @kbd{C-c C-e l B} (@code{org-beamer-export-as-latex})
+@kindex C-c C-e l B
+@findex org-beamer-export-as-latex
+
 Export to a temporary buffer.  Does not create a file.
-@orgcmd{C-c C-e l P,org-beamer-export-to-pdf}
+
+@item @kbd{C-c C-e l P} (@code{org-beamer-export-to-pdf})
+@kindex C-c C-e l P
+@findex org-beamer-export-to-pdf
+
 Export as @LaTeX{} file and then convert it to PDF format.
-@item C-c C-e l O
-Export as @LaTeX{} file, convert it to PDF format, and then open the PDF
-file.
+
+@item @kbd{C-c C-e l O}
+@kindex C-c C-e l O
+
+Export as @LaTeX{} file, convert it to PDF format, and then open the
+PDF file.
 @end table
 
 @node Beamer specific export settings
 @subsection Beamer specific export settings
 
-Beamer export back-end has several additional keywords for customizing Beamer
-output.  These keywords work similar to the general options settings
-(@pxref{Export settings}).
+Beamer export back-end has several additional keywords for customizing
+Beamer output.  These keywords work similar to the general options
+settings (see @ref{Export Settings}).
 
-@table @samp
-@item BEAMER_THEME
-@cindex @code{#+BEAMER_THEME}
+@table @asis
+@item @samp{BEAMER_THEME}
+@cindex @samp{BEAMER_THEME}, keyword
 @vindex org-beamer-theme
-The Beamer layout theme (@code{org-beamer-theme}).  Use square brackets for
-options.  For example:
-@smallexample
+The Beamer layout theme (@code{org-beamer-theme}).  Use square brackets
+for options.  For example:
+
+@example
 #+BEAMER_THEME: Rochester [height=20pt]
-@end smallexample
+@end example
 
-@item BEAMER_FONT_THEME
-@cindex @code{#+BEAMER_FONT_THEME}
+@item @samp{BEAMER_FONT_THEME}
+@cindex @samp{BEAMER_FONT_THEME}, keyword
 The Beamer font theme.
 
-@item BEAMER_INNER_THEME
-@cindex @code{#+BEAMER_INNER_THEME}
+@item @samp{BEAMER_INNER_THEME}
+@cindex @samp{BEAMER_INNER_THEME}, keyword
 The Beamer inner theme.
 
-@item BEAMER_OUTER_THEME
-@cindex @code{#+BEAMER_OUTER_THEME}
+@item @samp{BEAMER_OUTER_THEME}
+@cindex @samp{BEAMER_OUTER_THEME}, keyword
 The Beamer outer theme.
 
-@item BEAMER_HEADER
-@cindex @code{#+BEAMER_HEADER}
+@item @samp{BEAMER_HEADER}
+@cindex @samp{BEAMER_HEADER}, keyword
 Arbitrary lines inserted in the preamble, just before the @samp{hyperref}
 settings.
 
-@item DESCRIPTION
-@cindex @code{#+DESCRIPTION} (Beamer)
+@item @samp{DESCRIPTION}
+@cindex @samp{DESCRIPTION}, keyword
 The document description.  For long descriptions, use multiple
-@code{#+DESCRIPTION} keywords.  By default, @samp{hyperref} inserts
-@code{#+DESCRIPTION} as metadata.  Use @code{org-latex-hyperref-template} to
-configure document metadata.  Use @code{org-latex-title-command} to configure
-typesetting of description as part of front matter.
-
-@item KEYWORDS
-@cindex @code{#+KEYWORDS} (Beamer)
-The keywords for defining the contents of the document.  Use multiple
-@code{#+KEYWORDS} lines if necessary.  By default, @samp{hyperref} inserts
-@code{#+KEYWORDS} as metadata.  Use @code{org-latex-hyperref-template} to
-configure document metadata.  Use @code{org-latex-title-command} to configure
-typesetting of keywords as part of front matter.
-
-@item SUBTITLE
-@cindex @code{#+SUBTITLE} (Beamer)
-@vindex org-beamer-subtitle-format
-Document's subtitle.  For typesetting, use @code{org-beamer-subtitle-format}
-string.  Use @code{org-latex-hyperref-template} to configure document
-metadata.  Use @code{org-latex-title-command} to configure typesetting of
-subtitle as part of front matter.
+@samp{DESCRIPTION} keywords.  By default, @samp{hyperref} inserts
+@samp{DESCRIPTION} as metadata.  Use @code{org-latex-hyperref-template} to
+configure document metadata.  Use @code{org-latex-title-command} to
+configure typesetting of description as part of front matter.
+
+@item @samp{KEYWORDS}
+@cindex @samp{KEYWORDS}, keyword
+The keywords for defining the contents of the document.  Use
+multiple @samp{KEYWORDS} lines if necessary.  By default, @samp{hyperref}
+inserts @samp{KEYWORDS} as metadata.  Use @code{org-latex-hyperref-template}
+to configure document metadata.  Use @code{org-latex-title-command} to
+configure typesetting of keywords as part of front matter.
+
+@item @samp{SUBTITLE}
+@cindex @samp{SUBTITLE}, keyword
+Document's subtitle.  For typesetting, use
+@code{org-beamer-subtitle-format} string.  Use
+@code{org-latex-hyperref-template} to configure document metadata.  Use
+@code{org-latex-title-command} to configure typesetting of subtitle as
+part of front matter.
 @end table
 
-@node Sectioning Frames and Blocks in Beamer
-@subsection Sectioning, Frames and Blocks in Beamer
+@node Frames and Blocks in Beamer
+@subsection Frames and Blocks in Beamer
 
-Org transforms heading levels into Beamer's sectioning elements, frames and
-blocks.  Any Org tree with a not-too-deep-level nesting should in principle
-be exportable as a Beamer presentation.
+Org transforms heading levels into Beamer's sectioning elements,
+frames and blocks.  Any Org tree with a not-too-deep-level nesting
+should in principle be exportable as a Beamer presentation.
 
-@itemize @minus
+@itemize
 @item
 @vindex org-beamer-frame-level
-Org headlines become Beamer frames when the heading level in Org is equal to
-@code{org-beamer-frame-level} or @code{H} value in an @code{OPTIONS} line
-(@pxref{Export settings}).
-
-@cindex property, @code{BEAMER_ENV}
-Org overrides headlines to frames conversion for the current tree of an Org
-file if it encounters the @code{BEAMER_ENV} property set to @code{frame} or
-@code{fullframe}.  Org ignores whatever @code{org-beamer-frame-level} happens
-to be for that headline level in the Org tree.  In Beamer terminology, a
-@code{fullframe} is a frame without its title.
+Org headlines become Beamer frames when the heading level in Org is
+equal to @code{org-beamer-frame-level} or @samp{H} value in a @samp{OPTIONS} 
line
+(see @ref{Export Settings}).
+
+@cindex @samp{BEAMER_ENV}, property
+Org overrides headlines to frames conversion for the current tree of
+an Org file if it encounters the @samp{BEAMER_ENV} property set to
+@samp{frame} or @samp{fullframe}.  Org ignores whatever
+@code{org-beamer-frame-level} happens to be for that headline level in
+the Org tree.  In Beamer terminology, a full frame is a frame
+without its title.
 
 @item
-@vindex org-beamer-environments-default
-@vindex org-beamer-environments-extra
-Org exports a Beamer frame's objects as @code{block} environments.  Org can
-enforce wrapping in special block types when @code{BEAMER_ENV} property is
-set@footnote{If @code{BEAMER_ENV} is set, Org export adds
-@code{:B_environment:} tag to make it visible.  The tag serves as a visual
-aid and has no semantic relevance.}.  For valid values see
+Org exports a Beamer frame's objects as block environments.  Org can
+enforce wrapping in special block types when @samp{BEAMER_ENV} property
+is set@footnote{If @samp{BEAMER_ENV} is set, Org export adds 
@samp{B_environment} tag
+to make it visible.  The tag serves as a visual aid and has no
+semantic relevance.}.  For valid values see
 @code{org-beamer-environments-default}.  To add more values, see
 @code{org-beamer-environments-extra}.
+@vindex org-beamer-environments-default
+@vindex org-beamer-environments-extra
 
 @item
-@cindex property, @code{BEAMER_REF}
-If @code{BEAMER_ENV} is set to @code{appendix}, Org exports the entry as an
-appendix.  When set to @code{note}, Org exports the entry as a note within
-the frame or between frames, depending on the entry's heading level.  When
-set to @code{noteNH}, Org exports the entry as a note without its title.
-When set to @code{againframe}, Org exports the entry with @code{\againframe}
-command, which makes setting the @code{BEAMER_REF} property mandatory because
-@code{\againframe} needs frame to resume.
-
-When @code{ignoreheading} is set, Org export ignores the entry's headline but
-not its content.  This is useful for inserting content between frames.  It is
-also useful for properly closing a @code{column} environment.
+@cindex @samp{BEAMER_REF}, property
+If @samp{BEAMER_ENV} is set to @samp{appendix}, Org exports the entry as an
+appendix.  When set to @samp{note}, Org exports the entry as a note
+within the frame or between frames, depending on the entry's heading
+level.  When set to @samp{noteNH}, Org exports the entry as a note
+without its title.  When set to @samp{againframe}, Org exports the entry
+with @samp{\againframe} command, which makes setting the @samp{BEAMER_REF}
+property mandatory because @samp{\againframe} needs frame to resume.
+
+When @samp{ignoreheading} is set, Org export ignores the entry's headline
+but not its content.  This is useful for inserting content between
+frames.  It is also useful for properly closing a @samp{column}
+environment.  @@end itemize
+
+@cindex @samp{BEAMER_ACT}, property
+@cindex @samp{BEAMER_OPT}, property
+When @samp{BEAMER_ACT} is set for a headline, Org export translates that
+headline as an overlay or action specification.  When enclosed in
+square brackets, Org export makes the overlay specification
+a default.  Use @samp{BEAMER_OPT} to set any options applicable to the
+current Beamer frame or block.  The Beamer export back-end wraps
+with appropriate angular or square brackets.  It also adds the
+@samp{fragile} option for any code that may require a verbatim block.
+
+@cindex @samp{BEAMER_COL}, property
+To create a column on the Beamer slide, use the @samp{BEAMER_COL}
+property for its headline in the Org file.  Set the value of
+@samp{BEAMER_COL} to a decimal number representing the fraction of the
+total text width.  Beamer export uses this value to set the column's
+width and fills the column with the contents of the Org entry.  If
+the Org entry has no specific environment defined, Beamer export
+ignores the heading.  If the Org entry has a defined environment,
+Beamer export uses the heading as title.  Behind the scenes, Beamer
+export automatically handles @LaTeX{} column separations for contiguous
+headlines.  To manually adjust them for any unique configurations
+needs, use the @samp{BEAMER_ENV} property.
 @end itemize
 
-@cindex property, @code{BEAMER_ACT}
-@cindex property, @code{BEAMER_OPT}
-When @code{BEAMER_ACT} is set for a headline, Org export translates that
-headline as an overlay or action specification.  When enclosed in square
-brackets, Org export makes the overlay specification a default.  Use
-@code{BEAMER_OPT} to set any options applicable to the current Beamer frame
-or block.  The Beamer export back-end wraps with appropriate angular or
-square brackets.  It also adds the @code{fragile} option for any code that may
-require a verbatim block.
-
-@cindex property, @code{BEAMER_COL}
-To create a column on the Beamer slide, use the @code{BEAMER_COL} property
-for its headline in the Org file.  Set the value of @code{BEAMER_COL} to a
-decimal number representing the fraction of the total text width.  Beamer
-export uses this value to set the column's width and fills the column with
-the contents of the Org entry.  If the Org entry has no specific environment
-defined, Beamer export ignores the heading.  If the Org entry has a defined
-environment, Beamer export uses the heading as title.  Behind the scenes,
-Beamer export automatically handles @LaTeX{} column separations for
-contiguous headlines.  To manually adjust them for any unique configurations
-needs, use the @code{BEAMER_ENV} property.
-
 @node Beamer specific syntax
 @subsection Beamer specific syntax
-Since Org's Beamer export back-end is an extension of the @LaTeX{} back-end,
-it recognizes other @LaTeX{} specific syntax---for example, @code{#+LATEX:}
-or @code{#+ATTR_LATEX:}.  @xref{@LaTeX{} export}, for details.
 
-Beamer export wraps the table of contents generated with @code{toc:t}
-@code{OPTION} keyword in a @code{frame} environment.  Beamer export does not
-wrap the table of contents generated with @code{TOC} keyword (@pxref{Table of
-contents}).  Use square brackets for specifying options.
+Since Org's Beamer export back-end is an extension of the @LaTeX{}
+back-end, it recognizes other @LaTeX{} specific syntax---for example,
+@samp{#+LATEX:} or @samp{#+ATTR_LATEX:}.  See @ref{@LaTeX{} Export}, for 
details.
+
+Beamer export wraps the table of contents generated with @samp{toc:t}
+@samp{OPTION} keyword in a @samp{frame} environment.  Beamer export does not
+wrap the table of contents generated with @samp{TOC} keyword (see @ref{Table 
of Contents}).  Use square brackets for specifying options.
 
 @example
 #+TOC: headlines [currentsection]
 @end example
 
+
 Insert Beamer-specific code using the following constructs:
 
-@cindex @code{#+BEAMER}
-@cindex @code{#+BEGIN_EXPORT beamer}
+@cindex @samp{BEAMER}, keyword
+@cindex @samp{BEGIN_EXPORT beamer}
 @example
 #+BEAMER: \pause
 
 #+BEGIN_EXPORT beamer
-Only Beamer export back-end will export this line.
+  Only Beamer export back-end exports this.
 #+END_BEAMER
 
 Text @@@@beamer:some code@@@@ within a paragraph.
 @end example
 
-Inline constructs, such as the last one above, are useful for adding overlay
-specifications to objects with @code{bold}, @code{item}, @code{link},
+Inline constructs, such as the last one above, are useful for adding
+overlay specifications to objects with @code{bold}, @code{item}, @code{link},
 @code{radio-target} and @code{target} types.  Enclose the value in angular
-brackets and place the specification at the beginning the object as shown in
-this example:
+brackets and place the specification at the beginning of the object as
+shown in this example:
 
 @example
 A *@@@@beamer:<2->@@@@useful* feature
 @end example
 
-@cindex @code{#+ATTR_BEAMER}
-Beamer export recognizes the @code{ATTR_BEAMER} keyword with the following
-attributes from Beamer configurations: @code{:environment} for changing local
-Beamer environment, @code{:overlay} for specifying Beamer overlays in angular
-or square brackets, and @code{:options} for inserting optional arguments.
+
+@cindex @samp{ATTR_BEAMER}, keyword
+Beamer export recognizes the @samp{ATTR_BEAMER} keyword with the following
+attributes from Beamer configurations: @samp{:environment} for changing
+local Beamer environment, @samp{:overlay} for specifying Beamer overlays in
+angular or square brackets, and @samp{:options} for inserting optional
+arguments.
 
 @example
 #+ATTR_BEAMER: :environment nonindentlist
@@ -11433,18 +13014,21 @@ a subgroup of $G$.  Then the order of $H$ divides the 
order of $G$.
 @node Editing support
 @subsection Editing support
 
-
-The @code{org-beamer-mode} is a special minor mode for faster editing of
-Beamer documents.
+Org Beamer mode is a special minor mode for faster editing of Beamer
+documents.
 
 @example
 #+STARTUP: beamer
 @end example
 
-@table @kbd
-@orgcmd{C-c C-b,org-beamer-select-environment}
-The @code{org-beamer-mode} provides this key for quicker selections in Beamer
-normal environments, and for selecting the @code{BEAMER_COL} property.
+
+@table @asis
+@item @kbd{C-c C-b} (@code{org-beamer-select-environment})
+@kindex C-c C-b
+@findex org-beamer-select-environment
+
+Org Beamer mode provides this key for quicker selections in Beamer
+normal environments, and for selecting the @samp{BEAMER_COL} property.
 @end table
 
 @node A Beamer example
@@ -11459,7 +13043,7 @@ Here is an example of an Org document ready for Beamer 
export.
 #+LATEX_CLASS: beamer
 #+LATEX_CLASS_OPTIONS: [presentation]
 #+BEAMER_THEME: Madrid
-#+COLUMNS: %45ITEM %10BEAMER_ENV(Env) %10BEAMER_ACT(Act) %4BEAMER_COL(Col) 
%8BEAMER_OPT(Opt)
+#+COLUMNS: %45ITEM %10BEAMER_ENV(Env) %10BEAMER_ACT(Act) %4BEAMER_COL(Col)
 
 * This is the first structural section
 
@@ -11486,115 +13070,122 @@ Here is an example of an Org document ready for 
Beamer export.
     Please test this stuff!
 @end example
 
-@node HTML export
-@section HTML export
+@node HTML Export
+@section HTML Export
+
 @cindex HTML export
 
-Org mode contains an HTML exporter with extensive HTML formatting compatible
-with XHTML 1.0 strict standard.
+Org mode contains an HTML exporter with extensive HTML formatting
+compatible with XHTML 1.0 strict standard.
 
 @menu
-* HTML Export commands::        Invoking HTML export
-* HTML Specific export settings::  Settings for HTML export
-* HTML doctypes::               Exporting various (X)HTML flavors
-* HTML preamble and postamble::  Inserting preamble and postamble
-* Quoting HTML tags::           Using direct HTML in Org files
-* Links in HTML export::        Interpreting and formatting links
-* Tables in HTML export::       Formatting and modifying tables
-* Images in HTML export::       Inserting figures with HTML output
-* Math formatting in HTML export::  Handling math equations
-* Text areas in HTML export::   Showing an alternate approach, an example
-* CSS support::                 Styling HTML output
-* JavaScript support::          Folding scripting in the web browser
+* HTML export commands::         Invoking HTML export.
+* HTML specific export settings:: Settings for HTML export.
+* HTML doctypes::                Exporting various (X)HTML flavors.
+* HTML preamble and postamble::  Inserting preamble and postamble.
+* Quoting HTML tags::            Using direct HTML in Org files.
+* Headlines in HTML export::     Formatting headlines.
+* Links in HTML export::         Inserting and formatting links.
+* Tables in HTML export::        How to modify the formatting of tables.
+* Images in HTML export::        How to insert figures into HTML output.
+* Math formatting in HTML export:: Beautiful math also on the web.
+* Text areas in HTML export::    An alternate way to show an example.
+* CSS support::                  Changing the appearance of the output.
+* JavaScript support::           Info and folding in a web browser.
 @end menu
 
-
-@node HTML Export commands
+@node HTML export commands
 @subsection HTML export commands
 
-@table @kbd
-@orgcmd{C-c C-e h h,org-html-export-to-html}
-Export as HTML file with a @file{.html} extension.  For @file{myfile.org},
-Org exports to @file{myfile.html}, overwriting without warning.  @kbd{C-c C-e
-h o} Exports to HTML and opens it in a web browser.
+@table @asis
+@item @kbd{C-c C-e h h} (@code{org-html-export-to-html})
+@kindex C-c C-e h h
+@kindex C-c C-e h o
+@findex org-html-export-to-html
+
+Export as HTML file with a @samp{.html} extension.  For @samp{myfile.org}, Org
+exports to @samp{myfile.html}, overwriting without warning.  @{@{@{kbd@{C-c
+C-e h o)@}@}@} exports to HTML and opens it in a web browser.
+
+@item @kbd{C-c C-e h H} (@code{org-html-export-as-html})
+@kindex C-c C-e h H
+@findex org-html-export-as-html
 
-@orgcmd{C-c C-e h H,org-html-export-as-html}
 Exports to a temporary buffer.  Does not create a file.
 @end table
 
-@node HTML Specific export settings
-@subsection HTML Specific export settings
-HTML export has a number of keywords, similar to the general options settings
-described in @ref{Export settings}.
-
-@table @samp
-@item DESCRIPTION
-@cindex @code{#+DESCRIPTION} (HTML)
-This is the document's description, which the HTML exporter inserts it as a
-HTML meta tag in the HTML file.  For long descriptions, use multiple
-@code{#+DESCRIPTION} lines.  The exporter takes care of wrapping the lines
-properly.
-
-@item HTML_DOCTYPE
-@cindex @code{#+HTML_DOCTYPE}
+@node HTML specific export settings
+@subsection HTML specific export settings
+
+HTML export has a number of keywords, similar to the general options
+settings described in @ref{Export Settings}.
+
+@table @asis
+@item @samp{DESCRIPTION}
+@cindex @samp{DESCRIPTION}, keyword
+This is the document's description, which the HTML exporter inserts
+it as a HTML meta tag in the HTML file.  For long descriptions, use
+multiple @samp{DESCRIPTION} lines.  The exporter takes care of wrapping
+the lines properly.
+
+@item @samp{HTML_DOCTYPE}
+@cindex @samp{HTML_DOCTYPE}, keyword
 @vindex org-html-doctype
 Specify the document type, for example: HTML5 (@code{org-html-doctype}).
 
-@item HTML_CONTAINER
-@cindex @code{#+HTML_CONTAINER}
+@item @samp{HTML_CONTAINER}
+@cindex @samp{HTML_CONTAINER}, keyword
 @vindex org-html-container-element
 Specify the HTML container, such as @samp{div}, for wrapping sections and
 elements (@code{org-html-container-element}).
 
-@item HTML_LINK_HOME
-@cindex @code{#+HTML_LINK_HOME}
+@item @samp{HTML_LINK_HOME}
+@cindex @samp{HTML_LINK_HOME}, keyword
 @vindex org-html-link-home
 The URL for home link (@code{org-html-link-home}).
 
-@item HTML_LINK_UP
-@cindex @code{#+HTML_LINK_UP}
+@item @samp{HTML_LINK_UP}
+@cindex @samp{HTML_LINK_UP}, keyword
 @vindex org-html-link-up
 The URL for the up link of exported HTML pages (@code{org-html-link-up}).
 
-@item HTML_MATHJAX
-@cindex @code{#+HTML_MATHJAX}
+@item @samp{HTML_MATHJAX}
+@cindex @samp{HTML_MATHJAX}, keyword
 @vindex org-html-mathjax-options
-Options for MathJax (@code{org-html-mathjax-options}).  MathJax is used to
-typeset @LaTeX{} math in HTML documents.  @xref{Math formatting in HTML
-export}, for an example.
+Options for MathJax (@code{org-html-mathjax-options}).  MathJax is used
+to typeset @LaTeX{} math in HTML documents.  See @ref{Math formatting in HTML 
export}, for an example.
 
-@item HTML_HEAD
-@cindex @code{#+HTML_HEAD}
+@item @samp{HTML_HEAD}
+@cindex @samp{HTML_HEAD}, keyword
 @vindex org-html-head
 Arbitrary lines for appending to the HTML document's head
 (@code{org-html-head}).
 
-@item HTML_HEAD_EXTRA
-@cindex @code{#+HTML_HEAD_EXTRA}
+@item @samp{HTML_HEAD_EXTRA}
+@cindex @samp{HTML_HEAD_EXTRA}, keyword
 @vindex org-html-head-extra
 More arbitrary lines for appending to the HTML document's head
 (@code{org-html-head-extra}).
 
-@item KEYWORDS
-@cindex @code{#+KEYWORDS} (HTML)
-Keywords to describe the document's content.  HTML exporter inserts these
-keywords as HTML meta tags.  For long keywords, use multiple
-@code{#+KEYWORDS} lines.
-
-@item LATEX_HEADER
-@cindex @code{#+LATEX_HEADER} (HTML)
-Arbitrary lines for appending to the preamble; HTML exporter appends when
-transcoding @LaTeX{} fragments to images (@pxref{Math formatting in HTML
-export}).
-
-@item SUBTITLE
-@cindex @code{#+SUBTITLE} (HTML)
-The document's subtitle.  HTML exporter formats subtitle if document type is
-@samp{HTML5} and the CSS has a @samp{subtitle} class.
+@item @samp{KEYWORDS}
+@cindex @samp{KEYWORDS}, keyword
+Keywords to describe the document's content.  HTML exporter inserts
+these keywords as HTML meta tags.  For long keywords, use multiple
+@samp{KEYWORDS} lines.
+
+@item @samp{LATEX_HEADER}
+@cindex @samp{LATEX_HEADER}, keyword
+Arbitrary lines for appending to the preamble; HTML exporter appends
+when transcoding @LaTeX{} fragments to images (see @ref{Math formatting in 
HTML export}).
+
+@item @samp{SUBTITLE}
+@cindex @samp{SUBTITLE}, keyword
+The document's subtitle.  HTML exporter formats subtitle if document
+type is @samp{HTML5} and the CSS has a @samp{subtitle} class.
 @end table
 
-Some of these keywords are explained in more detail in the following sections
-of the manual.
+Some of these keywords are explained in more detail in the following
+sections of the manual.
 
 @node HTML doctypes
 @subsection HTML doctypes
@@ -11605,47 +13196,52 @@ Org can export to various (X)HTML flavors.
 @vindex org-html-doctype-alist
 Set the @code{org-html-doctype} variable for different (X)HTML variants.
 Depending on the variant, the HTML exporter adjusts the syntax of HTML
-conversion accordingly.  Org includes the following ready-made variants:
+conversion accordingly.  Org includes the following ready-made
+variants:
 
 @itemize
 @item
-``html4-strict''
+@code{"html4-strict"}
 @item
-``html4-transitional''
+@code{"html4-transitional"}
 @item
-``html4-frameset''
+@code{"html4-frameset"}
 @item
-``xhtml-strict''
+@code{"xhtml-strict"}
 @item
-``xhtml-transitional''
+@code{"xhtml-transitional"}
 @item
-``xhtml-frameset''
+@code{"xhtml-frameset"}
 @item
-``xhtml-11''
+@code{"xhtml-11"}
 @item
-``html5''
+@code{"html5"}
 @item
-``xhtml5''
+@code{"xhtml5"}
 @end itemize
 
-@noindent See the variable @code{org-html-doctype-alist} for details.
-The default is ``xhtml-strict''.
+@noindent
+See the variable @code{org-html-doctype-alist} for details.  The default is
+@code{"xhtml-strict"}.
 
 @vindex org-html-html5-fancy
-@cindex HTML5, export new elements
-Org's HTML exporter does not by default enable new block elements introduced
-with the HTML5 standard.  To enable them, set @code{org-html-html5-fancy} to
-non-@code{nil}.  Or use an @code{OPTIONS} line in the file to set
-@code{html5-fancy}.  HTML5 documents can now have arbitrary @code{#+BEGIN}
-and @code{#+END} blocks.  For example:
+@cindex @samp{HTML5}, export new elements
+Org's HTML exporter does not by default enable new block elements
+introduced with the HTML5 standard.  To enable them, set
+@code{org-html-html5-fancy} to non-@code{nil}.  Or use an @samp{OPTIONS} line 
in the
+file to set @samp{html5-fancy}.
+
+HTML5 documents can now have arbitrary @samp{#+BEGIN} @dots{} @samp{#+END} 
blocks.
+For example:
 
 @example
 #+BEGIN_aside
-Lorem ipsum
+  Lorem ipsum
 #+END_aside
 @end example
 
-Will export to:
+@noindent
+exports to:
 
 @example
 <aside>
@@ -11653,7 +13249,8 @@ Will export to:
 </aside>
 @end example
 
-While this:
+@noindent
+while this:
 
 @example
 #+ATTR_HTML: :controls controls :width 350
@@ -11664,28 +13261,30 @@ Your browser does not support the video tag.
 #+END_video
 @end example
 
-Exports to:
+@noindent
+exports to:
 
 @example
 <video controls="controls" width="350">
   <source src="movie.mp4" type="video/mp4">
-  <source src="movie.ogg" type="video/ogg">
-  <p>Your browser does not support the video tag.</p>
+    <source src="movie.ogg" type="video/ogg">
+      <p>Your browser does not support the video tag.</p>
 </video>
 @end example
 
 @vindex org-html-html5-elements
-When special blocks do not have a corresponding HTML5 element, the HTML
-exporter reverts to standard translation (see
-@code{org-html-html5-elements}).  For example, @code{#+BEGIN_lederhosen}
-exports to @samp{<div class="lederhosen">}.
+When special blocks do not have a corresponding HTML5 element, the
+HTML exporter reverts to standard translation (see
+@code{org-html-html5-elements}).  For example, @samp{#+BEGIN_lederhosen} 
exports
+to @code{<div class="lederhosen">}.
 
-Special blocks cannot have headlines.  For the HTML exporter to wrap the
-headline and its contents in @samp{<section>} or @samp{<article>} tags, set
-the @code{HTML_CONTAINER} property for the headline.
+Special blocks cannot have headlines.  For the HTML exporter to wrap
+the headline and its contents in @code{<section>} or @code{<article>} tags, set
+the @samp{HTML_CONTAINER} property for the headline.
 
 @node HTML preamble and postamble
 @subsection HTML preamble and postamble
+
 @vindex org-html-preamble
 @vindex org-html-postamble
 @vindex org-html-preamble-format
@@ -11694,48 +13293,62 @@ the @code{HTML_CONTAINER} property for the headline.
 @vindex org-export-creator-string
 @vindex org-export-time-stamp-file
 
-The HTML exporter has delineations for preamble and postamble.  The default
-value for @code{org-html-preamble} is @code{t}, which makes the HTML exporter
-insert the preamble.  See the variable @code{org-html-preamble-format} for
-the format string.
+The HTML exporter has delineations for preamble and postamble.  The
+default value for @code{org-html-preamble} is @code{t}, which makes the HTML
+exporter insert the preamble.  See the variable
+@code{org-html-preamble-format} for the format string.
 
 Set @code{org-html-preamble} to a string to override the default format
-string.  If the string is a function, the HTML exporter expects the function
-to return a string upon execution.  The HTML exporter inserts this string in
-the preamble.  The HTML exporter will not insert a preamble if
-@code{org-html-preamble} is set @code{nil}.
-
-The default value for @code{org-html-postamble} is @code{auto}, which makes
-the HTML exporter build a postamble from looking up author's name, email
-address, creator's name, and date.  Set @code{org-html-postamble} to @code{t}
-to insert the postamble in the format specified in the
-@code{org-html-postamble-format} variable.  The HTML exporter will not insert
-a postamble if @code{org-html-postamble} is set to @code{nil}.
+string.  If the string is a function, the HTML exporter expects the
+function to return a string upon execution.  The HTML exporter inserts
+this string in the preamble.  The HTML exporter does not insert
+a preamble if @code{org-html-preamble} is set @code{nil}.
+
+The default value for @code{org-html-postamble} is @code{auto}, which makes the
+HTML exporter build a postamble from looking up author's name, email
+address, creator's name, and date.  Set @code{org-html-postamble} to @code{t} 
to
+insert the postamble in the format specified in the
+@code{org-html-postamble-format} variable.  The HTML exporter does not
+insert a postamble if @code{org-html-postamble} is set to @code{nil}.
 
 @node Quoting HTML tags
 @subsection Quoting HTML tags
 
-The HTML export back-end transforms @samp{<} and @samp{>} to @samp{&lt;} and
-@samp{&gt;}.  To include raw HTML code in the Org file so the HTML export
-back-end can insert that HTML code in the output, use this inline syntax:
-@samp{@@@@html:}.  For example: @samp{@@@@html:<b>@@@@bold
-text@@@@html:</b>@@@@}.  For larger raw HTML code blocks, use these HTML
-export code blocks:
+The HTML export back-end transforms @samp{<} and @samp{>} to @samp{&lt;} and 
@samp{&gt;}.
+To include raw HTML code in the Org file so the HTML export back-end
+can insert that HTML code in the output, use this inline syntax:
+@samp{@@@@html:...@@@@}.  For example:
 
-@cindex @code{#+HTML}
 @example
-#+HTML: Literal HTML code for export
+@@@@html:<b>@@@@bold text@@@@html:</b>@@@@
 @end example
 
-@noindent or
-@cindex @code{#+BEGIN_EXPORT html}
+
+@cindex @samp{HTML}, keyword
+@cindex @samp{BEGIN_EXPORT html}
+For larger raw HTML code blocks, use these HTML export code blocks:
 
 @example
+#+HTML: Literal HTML code for export
+
 #+BEGIN_EXPORT html
-All lines between these markers are exported literally
+  All lines between these markers are exported literally
 #+END_EXPORT
 @end example
 
+@node Headlines in HTML export
+@subsection Headlines in HTML export
+
+@cindex headlines, in HTML export
+
+Headlines are exported to @samp{<h1>}, @samp{<h2>}, etc.  Each headline gets 
the
+@samp{id} attribute from @samp{CUSTOM_ID} property, or a unique generated 
value,
+see @ref{Internal Links}.
+
+@vindex org-html-self-link-headlines
+When @code{org-html-self-link-headlines} is set to a non-@code{nil} value, the
+text of the headlines is also wrapped in @samp{<a>} tags.  These tags have
+a @samp{href} attribute making the headlines link to themselves.
 
 @node Links in HTML export
 @subsection Links in HTML export
@@ -11743,29 +13356,30 @@ All lines between these markers are exported literally
 @cindex links, in HTML export
 @cindex internal links, in HTML export
 @cindex external links, in HTML export
+
+The HTML export back-end transforms Org's internal links (see
+@ref{Internal Links}) to equivalent HTML links in the output.  The back-end
+similarly handles Org's automatic links created by radio targets (see
+@ref{Radio Targets}) similarly.  For Org links to external files, the
+back-end transforms the links to @emph{relative} paths.
+
 @vindex org-html-link-org-files-as-html
-The HTML export back-end transforms Org's internal links (@pxref{Internal
-links}) to equivalent HTML links in the output.  The back-end similarly
-handles Org's automatic links created by radio targets (@pxref{Radio
-targets}) similarly.  For Org links to external files, the back-end
-transforms the links to @emph{relative} paths.
-
-For Org links to other @file{.org} files, the back-end automatically changes
-the file extension to @file{.html} and makes file paths relative.  If the
-@file{.org} files have an equivalent @file{.html} version at the same
-location, then the converted links should work without any further manual
-intervention.  However, to disable this automatic path translation, set
-@code{org-html-link-org-files-as-html} to @code{nil}.  When disabled, the
-HTML export back-end substitutes the @samp{id:}-based links in the HTML
-output.  For more about linking files when publishing to a directory,
-@pxref{Publishing links}.
-
-Org files can also have special directives to the HTML export back-end.  For
-example, by using @code{#+ATTR_HTML} lines to specify new format attributes
-to @code{<a>} or @code{<img>} tags.  This example shows changing the link's
-@code{title} and @code{style}:
-
-@cindex @code{#+ATTR_HTML}
+For Org links to other @samp{.org} files, the back-end automatically
+changes the file extension to @samp{.html} and makes file paths relative.
+If the @samp{.org} files have an equivalent @samp{.html} version at the same
+location, then the converted links should work without any further
+manual intervention.  However, to disable this automatic path
+translation, set @code{org-html-link-org-files-as-html} to @code{nil}.  When
+disabled, the HTML export back-end substitutes the ID-based links in
+the HTML output.  For more about linking files when publishing to
+a directory, see @ref{Publishing links}.
+
+Org files can also have special directives to the HTML export
+back-end.  For example, by using @samp{#+ATTR_HTML} lines to specify new
+format attributes to @code{<a>} or @code{<img>} tags.  This example shows
+changing the link's title and style:
+
+@cindex @samp{ATTR_HTML}, keyword
 @example
 #+ATTR_HTML: :title The Org mode homepage :style color:red;
 [[https://orgmode.org]]
@@ -11773,53 +13387,55 @@ to @code{<a>} or @code{<img>} tags.  This example 
shows changing the link's
 
 @node Tables in HTML export
 @subsection Tables in HTML export
+
 @cindex tables, in HTML
-@vindex org-html-table-default-attributes
+@vindex org-export-html-table-tag
 
 The HTML export back-end uses @code{org-html-table-default-attributes} when
-exporting Org tables to HTML.  By default, the exporter does not draw frames
-and cell borders.  To change for this for a table, use the following lines
-before the table in the Org file:
+exporting Org tables to HTML@.  By default, the exporter does not draw
+frames and cell borders.  To change for this for a table, use the
+following lines before the table in the Org file:
 
-@cindex @code{#+CAPTION}
-@cindex @code{#+ATTR_HTML}
+@cindex @samp{CAPTION}, keyword
+@cindex @samp{ATTR_HTML}, keyword
 @example
 #+CAPTION: This is a table with lines around and between cells
-#+ATTR_HTML: :border 2 :rules all :frame border
+#+ATTR_HTML: border="2" rules="all" frame="border"
 @end example
 
-The HTML export back-end preserves column groupings in Org tables
-(@pxref{Column groups}) when exporting to HTML.
+The HTML export back-end preserves column groupings in Org tables (see
+@ref{Column Groups}) when exporting to HTML@.
 
-Additional options for customizing tables for  HTML export.
+Additional options for customizing tables for HTML export.
 
-@table @code
+@table @asis
+@item @code{org-html-table-align-individual-fields}
 @vindex org-html-table-align-individual-fields
-@item org-html-table-align-individual-fields
-Non-@code{nil} attaches style attributes for alignment to each table field.
+Non-@code{nil} attaches style attributes for alignment to each table
+field.
 
+@item @code{org-html-table-caption-above}
 @vindex org-html-table-caption-above
-@item org-html-table-caption-above
 Non-@code{nil} places caption string at the beginning of the table.
 
+@item @code{org-html-table-data-tags}
 @vindex org-html-table-data-tags
-@item org-html-table-data-tags
 Opening and ending tags for table data fields.
 
+@item @code{org-html-table-default-attributes}
 @vindex org-html-table-default-attributes
-@item org-html-table-default-attributes
 Default attributes and values for table tags.
 
+@item @code{org-html-table-header-tags}
 @vindex org-html-table-header-tags
-@item org-html-table-header-tags
 Opening and ending tags for table's header fields.
 
+@item @code{org-html-table-row-tags}
 @vindex org-html-table-row-tags
-@item org-html-table-row-tags
 Opening and ending tags for table rows.
 
+@item @code{org-html-table-use-header-tags-for-first-column}
 @vindex org-html-table-use-header-tags-for-first-column
-@item org-html-table-use-header-tags-for-first-column
 Non-@code{nil} formats column one in tables with header tags.
 @end table
 
@@ -11828,85 +13444,97 @@ Non-@code{nil} formats column one in tables with 
header tags.
 
 @cindex images, inline in HTML
 @cindex inlining images in HTML
-@vindex org-html-inline-images
 
-The HTML export back-end has features to convert Org image links to HTML
-inline images and HTML clickable image links.
+The HTML export back-end has features to convert Org image links to
+HTML inline images and HTML clickable image links.
 
-When the link in the Org file has no description, the HTML export back-end by
-default in-lines that image.  For example: @samp{[[file:myimg.jpg]]} is
-in-lined, while @samp{[[file:myimg.jpg][the image]]} links to the text,
-@samp{the image}.
-
-For more details, see the variable @code{org-html-inline-images}.
+@vindex org-html-inline-images
+When the link in the Org file has no description, the HTML export
+back-end by default in-lines that image.  For example:
+@samp{[[file:myimg.jpg]]} is in-lined, while @samp{[[file:myimg.jpg][the 
image]]} links to the text,
+@samp{the image}.  For more details, see the variable
+@code{org-html-inline-images}.
 
-On the other hand, if the description part of the Org link is itself another
-link, such as @code{file:} or @code{http:} URL pointing to an image, the HTML
-export back-end in-lines this image and links to the main image.  This Org
-syntax enables the back-end to link low-resolution thumbnail to the
-high-resolution version of the image, as shown in this example:
+On the other hand, if the description part of the Org link is itself
+another link, such as @samp{file:} or @samp{http:} URL pointing to an image, 
the
+HTML export back-end in-lines this image and links to the main image.
+This Org syntax enables the back-end to link low-resolution thumbnail
+to the high-resolution version of the image, as shown in this example:
 
 @example
 [[file:highres.jpg][file:thumb.jpg]]
 @end example
 
-To change attributes of in-lined images, use @code{#+ATTR_HTML} lines in the
-Org file.  This example shows realignment to right, and adds @code{alt} and
-@code{title} attributes in support of text viewers and modern web accessibility
-standards.
 
-@cindex @code{#+CAPTION}
-@cindex @code{#+ATTR_HTML}
+To change attributes of in-lined images, use @samp{#+ATTR_HTML} lines in
+the Org file.  This example shows realignment to right, and adds @code{alt}
+and @code{title} attributes in support of text viewers and modern web
+accessibility standards.
+
+@cindex @samp{CAPTION}, keyword
+@cindex @samp{ATTR_HTML}, keyword
 @example
 #+CAPTION: A black cat stalking a spider
 #+ATTR_HTML: :alt cat/spider image :title Action! :align right
 [[./img/a.jpg]]
 @end example
 
-@noindent
-The HTML export back-end copies the @code{http} links from the Org file as
-is.
+The HTML export back-end copies the @samp{http} links from the Org file
+as-is.
 
 @node Math formatting in HTML export
 @subsection Math formatting in HTML export
+
 @cindex MathJax
 @cindex dvipng
 @cindex dvisvgm
-@cindex imagemagick
-
-@LaTeX{} math snippets (@pxref{@LaTeX{} fragments}) can be displayed in two
-different ways on HTML pages.  The default is to use
-@uref{http://www.mathjax.org, MathJax} which should work out of the box with
-Org@footnote{By default Org loads MathJax from @uref{https://cdnjs.com, 
cdnjs.com} as
-recommended by @uref{http://www.mathjax.org, MathJax}.}.  Some MathJax display
-options can be configured via @code{org-html-mathjax-options}, or in the
-buffer.  For example, with the following settings,
-@smallexample
+@cindex ImageMagick
+
+@vindex org-html-mathjax-options~
+@LaTeX{} math snippets (see @ref{@LaTeX{} fragments}) can be displayed in two
+different ways on HTML pages.  The default is to use the 
@uref{http://www.mathjax.org, MathJax},
+which should work out of the box with Org@footnote{By default Org loads 
MathJax from @uref{https://cdnjs.com, cdnjs.com} as recommended by
+@uref{http://www.mathjax.org, MathJax}.}@footnote{Please note that exported 
formulas are part of an HTML
+document, and that signs such as @samp{<}, @samp{>}, or @samp{&} have special
+meanings.  See 
@uref{http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-in-html-documents,
 MathJax @TeX{} and @LaTeX{} support}.}.  Some MathJax
+display options can be configured via @code{org-html-mathjax-options}, or
+in the buffer.  For example, with the following settings,
+
+@example
 #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler
-@end smallexample
-equation labels will be displayed on the left margin and equations will be
-five ems from the left margin.
+#+HTML_MATHJAX: cancel.js noErrors.js
+@end example
+
+@noindent
+equation labels are displayed on the left margin and equations are
+five em from the left margin.  In addition, it loads the two MathJax
+extensions @samp{cancel.js} and @samp{noErrors.js}@footnote{See 
@uref{http://docs.mathjax.org/en/latest/tex.html#tex-extensions, @TeX{} and 
@LaTeX{} extensions} in the @uref{http://docs.mathjax.org, MathJax manual} to 
learn
+about extensions.}.
 
-@noindent See the docstring of
-@code{org-html-mathjax-options} for all supported variables.  The MathJax
-template can be configure via @code{org-html-mathjax-template}.
+@vindex org-html-mathjax-template
+See the docstring of @code{org-html-mathjax-options} for all supported
+variables.  The MathJax template can be configure via
+@code{org-html-mathjax-template}.
 
 If you prefer, you can also request that @LaTeX{} fragments are processed
-into small images that will be inserted into the browser page.  Before the
-availability of MathJax, this was the default method for Org files.  This
-method requires that the @file{dvipng} program, @file{dvisvgm} or
-@file{imagemagick} suite is available on your system.  You can still get
-this processing with
+into small images that will be inserted into the browser page.  Before
+the availability of MathJax, this was the default method for Org
+files.  This method requires that the dvipng program, dvisvgm or
+ImageMagick suite is available on your system.  You can still get this
+processing with
 
 @example
 #+OPTIONS: tex:dvipng
 @end example
 
+
 @example
 #+OPTIONS: tex:dvisvgm
 @end example
 
-or:
+
+@noindent
+or
 
 @example
 #+OPTIONS: tex:imagemagick
@@ -11916,20 +13544,20 @@ or:
 @subsection Text areas in HTML export
 
 @cindex text areas, in HTML
-Before Org mode's Babel, one popular approach to publishing code in HTML was
-by using @code{:textarea}.  The advantage of this approach was that copying
-and pasting was built into browsers with simple JavaScript commands.  Even
-editing before pasting was made simple.
+Before Org mode's Babel, one popular approach to publishing code in
+HTML was by using @samp{:textarea}.  The advantage of this approach was
+that copying and pasting was built into browsers with simple
+JavaScript commands.  Even editing before pasting was made simple.
 
 The HTML export back-end can create such text areas.  It requires an
-@code{#+ATTR_HTML:} line as shown in the example below with the
-@code{:textarea} option.  This must be followed by either an
-@code{example} or a @code{src} code block.  Other Org block types will not
-honor the @code{:textarea} option.
+@samp{#+ATTR_HTML} line as shown in the example below with the @samp{:textarea}
+option.  This must be followed by either an example or a source code
+block.  Other Org block types do not honor the @samp{:textarea} option.
 
-By default, the HTML export back-end creates a text area 80 characters wide
-and height just enough to fit the content.  Override these defaults with
-@code{:width} and @code{:height} options on the @code{#+ATTR_HTML:} line.
+By default, the HTML export back-end creates a text area 80 characters
+wide and height just enough to fit the content.  Override these
+defaults with @samp{:width} and @samp{:height} options on the 
@samp{#+ATTR_HTML}
+line.
 
 @example
 #+ATTR_HTML: :textarea t :width 40
@@ -11940,297 +13568,387 @@ and height just enough to fit the content.  
Override these defaults with
 #+END_EXAMPLE
 @end example
 
-
 @node CSS support
 @subsection CSS support
+
 @cindex CSS, for HTML export
 @cindex HTML export, CSS
 
-@vindex org-html-todo-kwd-class-prefix
-@vindex org-html-tag-class-prefix
-You can modify the CSS style definitions for the exported file.  The HTML
-exporter assigns the following special CSS classes@footnote{If the classes on
-TODO keywords and tags lead to conflicts, use the variables
-@code{org-html-todo-kwd-class-prefix} and @code{org-html-tag-class-prefix} to
-make them unique.} to appropriate parts of the document---your style
-specifications may change these, in addition to any of the standard classes
-like for headlines, tables, etc.
-@example
-p.author            @r{author information, including email}
-p.date              @r{publishing date}
-p.creator           @r{creator info, about org mode version}
-.title              @r{document title}
-.subtitle           @r{document subtitle}
-.todo               @r{TODO keywords, all not-done states}
-.done               @r{the DONE keywords, all states that count as done}
-.WAITING            @r{each TODO keyword also uses a class named after itself}
-.timestamp          @r{timestamp}
-.timestamp-kwd      @r{keyword associated with a timestamp, like 
@code{SCHEDULED}}
-.timestamp-wrapper  @r{span around keyword plus timestamp}
-.tag                @r{tag in a headline}
-._HOME              @r{each tag uses itself as a class, "@@" replaced by "_"}
-.target             @r{target for links}
-.linenr             @r{the line number in a code example}
-.code-highlighted   @r{for highlighting referenced code lines}
-div.outline-N       @r{div for outline level N (headline plus text))}
-div.outline-text-N  @r{extra div for text at outline level N}
-.section-number-N   @r{section number in headlines, different for each level}
-.figure-number      @r{label like "Figure 1:"}
-.table-number       @r{label like "Table 1:"}
-.listing-number     @r{label like "Listing 1:"}
-div.figure          @r{how to format an in-lined image}
-pre.src             @r{formatted source code}
-pre.example         @r{normal example}
-p.verse             @r{verse paragraph}
-div.footnotes       @r{footnote section headline}
-p.footnote          @r{footnote definition paragraph, containing a footnote}
-.footref            @r{a footnote reference number (always a <sup>)}
-.footnum            @r{footnote number in footnote definition (always <sup>)}
-.org-svg            @r{default class for a linked @file{.svg} image}
-@end example
+@vindex org-export-html-todo-kwd-class-prefix
+@vindex org-export-html-tag-class-prefix
+You can modify the CSS style definitions for the exported file.  The
+HTML exporter assigns the following special CSS classes@footnote{If the 
classes on TODO keywords and tags lead to conflicts,
+use the variables @code{org-html-todo-kwd-class-prefix} and
+@code{org-html-tag-class-prefix} to make them unique.} to
+appropriate parts of the document---your style specifications may
+change these, in addition to any of the standard classes like for
+headlines, tables, etc.
+
+@multitable {aaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{p.author}
+@tab author information, including email
+@item @code{p.date}
+@tab publishing date
+@item @code{p.creator}
+@tab creator info, about org mode version
+@item @code{.title}
+@tab document title
+@item @code{.subtitle}
+@tab document subtitle
+@item @code{.todo}
+@tab TODO keywords, all not-done states
+@item @code{.done}
+@tab the DONE keywords, all states that count as done
+@item @code{.WAITING}
+@tab each TODO keyword also uses a class named after itself
+@item @code{.timestamp}
+@tab timestamp
+@item @code{.timestamp-kwd}
+@tab keyword associated with a timestamp, like @samp{SCHEDULED}
+@item @code{.timestamp-wrapper}
+@tab span around keyword plus timestamp
+@item @code{.tag}
+@tab tag in a headline
+@item @code{._HOME}
+@tab each tag uses itself as a class, ``@@'' replaced by ``_''
+@item @code{.target}
+@tab target for links
+@item @code{.linenr}
+@tab the line number in a code example
+@item @code{.code-highlighted}
+@tab for highlighting referenced code lines
+@item @code{div.outline-N}
+@tab div for outline level N (headline plus text)
+@item @code{div.outline-text-N}
+@tab extra div for text at outline level N
+@item @code{.section-number-N}
+@tab section number in headlines, different for each level
+@item @code{.figure-number}
+@tab label like ``Figure 1:''
+@item @code{.table-number}
+@tab label like ``Table 1:''
+@item @code{.listing-number}
+@tab label like ``Listing 1:''
+@item @code{div.figure}
+@tab how to format an in-lined image
+@item @code{pre.src}
+@tab formatted source code
+@item @code{pre.example}
+@tab normal example
+@item @code{p.verse}
+@tab verse paragraph
+@item @code{div.footnotes}
+@tab footnote section headline
+@item @code{p.footnote}
+@tab footnote definition paragraph, containing a footnote
+@item @code{.footref}
+@tab a footnote reference number (always a <sup>)
+@item @code{.footnum}
+@tab footnote number in footnote definition (always <sup>)
+@item @code{.org-svg}
+@tab default class for a linked @samp{.svg} image
+@end multitable
 
 @vindex org-html-style-default
-@vindex org-html-head-include-default-style
 @vindex org-html-head
 @vindex org-html-head-extra
-@cindex @code{#+HTML_INCLUDE_STYLE}
-The HTML export back-end includes a compact default style in each exported
-HTML file.  To override the default style with another style, use these
-keywords in the Org file.  They will replace the global defaults the HTML
-exporter uses.
+@cindex @samp{HTML_INCLUDE_STYLE}, keyword
+The HTML export back-end includes a compact default style in each
+exported HTML file.  To override the default style with another style,
+use these keywords in the Org file.  They will replace the global
+defaults the HTML exporter uses.
 
-@cindex @code{#+HTML_HEAD}
-@cindex @code{#+HTML_HEAD_EXTRA}
+@cindex @samp{HTML_HEAD}, keyword
+@cindex @samp{HTML_HEAD_EXTRA}, keyword
 @example
 #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="style1.css" />
 #+HTML_HEAD_EXTRA: <link rel="alternate stylesheet" type="text/css" 
href="style2.css" />
 @end example
 
+@vindex org-html-head-include-default-style
 To just turn off the default style, customize
-@code{org-html-head-include-default-style} variable, or use this option line in
-the Org file.
+@code{org-html-head-include-default-style} variable, or use this option
+line in the Org file.
 
+@cindex @samp{html-style}, @samp{OPTIONS} item
 @example
 #+OPTIONS: html-style:nil
 @end example
 
-@noindent
-For longer style definitions, either use several @code{#+HTML_HEAD} and
-@code{#+HTML_HEAD_EXTRA} lines, or use @code{<style>} @code{</style>} blocks
-around them.  Both of these approaches can avoid referring to an external
-file.
 
-In order to add styles to a sub-tree, use the @code{:HTML_CONTAINER_CLASS:}
-property to assign a class to the tree.  In order to specify CSS styles for a
-particular headline, you can use the id specified in a @code{:CUSTOM_ID:}
-property.
+For longer style definitions, either use several @samp{HTML_HEAD} and
+@samp{HTML_HEAD_EXTRA} keywords, or use @code{<style> ... </style>} blocks
+around them.  Both of these approaches can avoid referring to an
+external file.
+
+@cindex @samp{HTML_CONTAINER_CLASS}, property
+@cindex @samp{HTML_HEADLINE_CLASS}, property
+In order to add styles to a sub-tree, use the @samp{HTML_CONTAINER_CLASS}
+property to assign a class to the tree.  In order to specify CSS
+styles for a particular headline, you can use the ID specified in
+a @samp{CUSTOM_ID} property.  You can also assign a specific class to
+a headline with the @samp{HTML_HEADLINE_CLASS} property.
 
 Never change the @code{org-html-style-default} constant.  Instead use other
 simpler ways of customizing as described above.
 
-
-@c FIXME: More about header and footer styles
-@c FIXME: Talk about links and targets.
-
 @node JavaScript support
 @subsection JavaScript supported display of web pages
 
-@cindex Rose, Sebastian
 Sebastian Rose has written a JavaScript program especially designed to
-enhance the web viewing experience of HTML files created with Org.  This
-program enhances large files in two different ways of viewing.  One is an
-@emph{Info}-like mode where each section is displayed separately and
-navigation can be done with the @kbd{n} and @kbd{p} keys (and some other keys
-as well, press @kbd{?} for an overview of the available keys).  The second
-one has a @emph{folding} view, much like Org provides inside Emacs.  The
-script is available at @url{https://orgmode.org/org-info.js} and the
-documentation at @url{https://orgmode.org/worg/code/org-info-js/}.  The script
-is hosted on @url{https://orgmode.org}, but for reliability, prefer installing
-it on your own web server.
+enhance the web viewing experience of HTML files created with Org.
+This program enhances large files in two different ways of viewing.
+One is an @emph{Info}-like mode where each section is displayed separately
+and navigation can be done with the @kbd{n} and @kbd{p}
+keys, and some other keys as well, press @kbd{?} for an overview
+of the available keys.  The second one has a @emph{folding} view, much like
+Org provides inside Emacs.  The script is available at
+@uref{https://orgmode.org/org-info.js} and the documentation at
+@uref{https://orgmode.org/worg/code/org-info-js/}.  The script is hosted on
+@uref{https://orgmode.org}, but for reliability, prefer installing it on your
+own web server.
 
 To use this program, just add this line to the Org file:
 
-@cindex @code{#+INFOJS_OPT}
+@cindex @samp{INFOJS_OPT}, keyword
 @example
 #+INFOJS_OPT: view:info toc:nil
 @end example
 
-@noindent
-The HTML header now has the code needed to automatically invoke the script.
-For setting options, use the syntax from the above line for options described
-below:
 
-@example
-path:    @r{The path to the script.  The default grabs the script from}
-         @r{@url{https://orgmode.org/org-info.js}, but you might want to have}
-         @r{a local copy and use a path like @samp{../scripts/org-info.js}.}
-view:    @r{Initial view when the website is first shown.  Possible values 
are:}
-         info      @r{Info-like interface with one section per page.}
-         overview  @r{Folding interface, initially showing only top-level.}
-         content   @r{Folding interface, starting with all headlines visible.}
-         showall   @r{Folding interface, all headlines and text visible.}
-sdepth:  @r{Maximum headline level that will still become an independent}
-         @r{section for info and folding modes.  The default is taken from}
-         @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 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"?}
-         @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.}
-mouse:   @r{Headings are highlighted when the mouse is over them.  Should be}
-         @r{@samp{underline} (default) or a background color like 
@samp{#cccccc}.}
-buttons: @r{Should view-toggle buttons be everywhere?  When @code{nil} (the}
-         @r{default), only one such button will be present.}
-@end example
 @noindent
-@vindex org-html-infojs-options
-@vindex org-html-use-infojs
-You can choose default values for these options by customizing the variable
-@code{org-html-infojs-options}.  If you want the script to always apply to
-your pages, configure the variable @code{org-html-use-infojs}.
-
-@node @LaTeX{} export
-@section @LaTeX{} export
+The HTML header now has the code needed to automatically invoke the
+script.  For setting options, use the syntax from the above line for
+options described below:
+
+@table @asis
+@item @samp{path:}
+The path to the script.  The default is to grab the script from
+@uref{https://orgmode.org/org-info.js}, but you might want to have a local
+copy and use a path like @samp{../scripts/org-info.js}.
+
+@item @samp{view:}
+Initial view when the website is first shown.  Possible values are:
+
+@multitable {aaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{info}
+@tab Info-like interface with one section per page
+@item @samp{overview}
+@tab Folding interface, initially showing only top-level
+@item @samp{content}
+@tab Folding interface, starting with all headlines visible
+@item @samp{showall}
+@tab Folding interface, all headlines and text visible
+@end multitable
+
+@item @samp{sdepth:}
+Maximum headline level still considered as an independent section
+for info and folding modes.  The default is taken from
+@code{org-export-headline-levels}, i.e., the @samp{H} switch in 
@samp{OPTIONS}.  If
+this is smaller than in @code{org-export-headline-levels}, each
+info/folding section can still contain child headlines.
+
+@item @samp{toc:}
+Should the table of contents @emph{initially} be visible?  Even when
+@samp{nil}, you can always get to the ``toc'' with @kbd{i}.
+
+@item @samp{tdepth:}
+The depth of the table of contents.  The defaults are taken from the
+variables @code{org-export-headline-levels} and @code{org-export-with-toc}.
+
+@item @samp{ftoc:}
+Does the CSS of the page specify a fixed position for the ``toc''?  If
+yes, the toc is displayed as a section.
+
+@item @samp{ltoc:}
+Should there be short contents (children) in each section?  Make
+this @samp{above} if the section should be above initial text.
+
+@item @samp{mouse:}
+Headings are highlighted when the mouse is over them.  Should be
+@samp{underline} (default) or a background color like @samp{#cccccc}.
+
+@item @samp{buttons:}
+Should view-toggle buttons be everywhere?  When @samp{nil} (the default),
+only one such button is present.
+@end table
+
+@vindex org-infojs-options
+@vindex org-export-html-use-infojs
+You can choose default values for these options by customizing the
+variable @code{org-infojs-options}.  If you always want to apply the script
+to your pages, configure the variable @code{org-export-html-use-infojs}.
+
+@node @LaTeX{} Export
+@section @LaTeX{} Export
+
 @cindex @LaTeX{} export
 @cindex PDF export
 
 The @LaTeX{} export back-end can handle complex documents, incorporate
 standard or custom @LaTeX{} document classes, generate documents using
-alternate @LaTeX{} engines, and produce fully linked PDF files with indexes,
-bibliographies, and tables of contents, destined for interactive online
-viewing or high-quality print publication.
+alternate @LaTeX{} engines, and produce fully linked PDF files with
+indexes, bibliographies, and tables of contents, destined for
+interactive online viewing or high-quality print publication.
 
-While the details are covered in-depth in this section, here are some quick
-references to variables for the impatient: for engines, see
+While the details are covered in-depth in this section, here are some
+quick references to variables for the impatient: for engines, see
 @code{org-latex-compiler}; for build sequences, see
 @code{org-latex-pdf-process}; for packages, see
 @code{org-latex-default-packages-alist} and @code{org-latex-packages-alist}.
 
 An important note about the @LaTeX{} export back-end: it is sensitive to
-blank lines in the Org document.  That's because @LaTeX{} itself depends on
-blank lines to tell apart syntactical elements, such as paragraphs.
+blank lines in the Org document.  That's because @LaTeX{} itself depends
+on blank lines to tell apart syntactical elements, such as paragraphs.
 
 @menu
-* @LaTeX{} export commands::    For producing @LaTeX{} and PDF documents.
-* @LaTeX{} specific export settings::  Unique to this @LaTeX{} back-end.
-* @LaTeX{} header and sectioning::  For file structure.
-* Quoting @LaTeX{} code::       Directly in the Org document.
-* Tables in @LaTeX{} export::   Attributes specific to tables.
-* Images in @LaTeX{} export::   Attributes specific to images.
-* Plain lists in @LaTeX{} export::  Attributes specific to lists.
-* Source blocks in @LaTeX{} export::  Attributes specific to source code 
blocks.
-* Example blocks in @LaTeX{} export::  Attributes specific to example blocks.
-* Special blocks in @LaTeX{} export::  Attributes specific to special blocks.
-* Horizontal rules in @LaTeX{} export::  Attributes specific to horizontal 
rules.
+* @LaTeX{}/PDF export commands:: For producing @LaTeX{} and PDF documents.
+* @LaTeX{} specific export settings:: Unique to this @LaTeX{} back-end.
+* @LaTeX{} header and sectioning:: Setting up the export file structure.
+* Quoting @LaTeX{} code::        Incorporating literal @LaTeX{} code.
+* Tables in @LaTeX{} export::    Options for exporting tables to @LaTeX{}.
+* Images in @LaTeX{} export::    How to insert figures into @LaTeX{} output.
+* Plain lists in @LaTeX{} export:: Attributes specific to lists.
+* Source blocks in @LaTeX{} export:: Attributes specific to source code blocks.
+* Example blocks in @LaTeX{} export:: Attributes specific to example blocks.
+* Special blocks in @LaTeX{} export:: Attributes specific to special blocks.
+* Horizontal rules in @LaTeX{} export:: Attributes specific to horizontal 
rules.
 @end menu
 
-@node @LaTeX{} export commands
-@subsection @LaTeX{} export commands
-
-@table @kbd
-@orgcmd{C-c C-e l l,org-latex-export-to-latex}
-Export as @LaTeX{} file with a @file{.tex} extension.  For @file{myfile.org},
-Org exports to @file{myfile.tex}, overwriting without warning.  @kbd{C-c C-e
-l l} Exports to @LaTeX{} file.
+@node @LaTeX{}/PDF export commands
+@subsection @LaTeX{}/PDF export commands
 
-@orgcmd{C-c C-e l L,org-latex-export-as-latex}
+@table @asis
+@item @kbd{C-c C-e l l} (@code{org-latex-export-to-latex})
+@kindex C-c C-e l l
+@findex org-latex-export-to-latex~
+Export to a @LaTeX{} file with a @samp{.tex} extension.  For @samp{myfile.org},
+Org exports to @samp{myfile.tex}, overwriting without warning.
+
+@item @kbd{C-c C-e l L} (@code{org-latex-export-as-latex})
+@kindex C-c C-e l L
+@findex org-latex-export-as-latex
 Export to a temporary buffer.  Do not create a file.
-@orgcmd{C-c C-e l p,org-latex-export-to-pdf}
+
+@item @kbd{C-c C-e l p} (@code{org-latex-export-to-pdf})
+@kindex C-c C-e l p
+@findex org-latex-export-to-pdf
 Export as @LaTeX{} file and convert it to PDF file.
-@item C-c C-e l o
-Export as @LaTeX{} file and convert it to PDF, then open the PDF using the 
default viewer.
+
+@item @kbd{C-c C-e l o}
+@kindex C-c C-e l o
+Export as @LaTeX{} file and convert it to PDF, then open the PDF using
+the default viewer.
+
+@item @kbd{M-x org-export-region-as-latex}
+Convert the region to @LaTeX{} under the assumption that it was in Org
+mode syntax before.  This is a global command that can be invoked in
+any buffer.
 @end table
 
 @vindex org-latex-compiler
 @vindex org-latex-bibtex-compiler
 @vindex org-latex-default-packages-alist
+@cindex pdflatex
+@cindex xelatex
+@cindex lualatex
+@cindex @samp{LATEX_COMPILER}, keyword
 The @LaTeX{} export back-end can use any of these @LaTeX{} engines:
-@samp{pdflatex}, @samp{xelatex}, and @samp{lualatex}.  These engines compile
-@LaTeX{} files with different compilers, packages, and output options.  The
+@samp{pdflatex}, @samp{xelatex}, and @samp{lualatex}.  These engines compile 
@LaTeX{}
+files with different compilers, packages, and output options.  The
 @LaTeX{} export back-end finds the compiler version to use from
-@code{org-latex-compiler} variable or the @code{#+LATEX_COMPILER} keyword in
-the Org file.  See the docstring for the
+@code{org-latex-compiler} variable or the @samp{#+LATEX_COMPILER} keyword in 
the
+Org file.  See the docstring for the
 @code{org-latex-default-packages-alist} for loading packages with certain
-compilers.  Also see @code{org-latex-bibtex-compiler} to set the bibliography
-compiler@footnote{This does not allow setting different bibliography
-compilers for different files.  However, ``smart'' @LaTeX{} compilation
-systems, such as @samp{latexmk}, can select the correct bibliography
-compiler.}.
+compilers.  Also see @code{org-latex-bibtex-compiler} to set the
+bibliography compiler@footnote{This does not allow setting different 
bibliography compilers
+for different files.  However, ``smart'' @LaTeX{} compilation systems, such
+as latexmk, can select the correct bibliography compiler.}.
 
 @node @LaTeX{} specific export settings
 @subsection @LaTeX{} specific export settings
 
-The @LaTeX{} export back-end has several additional keywords for customizing
-@LaTeX{} output.  Setting these keywords works similar to the general options
-(@pxref{Export settings}).
+The @LaTeX{} export back-end has several additional keywords for
+customizing @LaTeX{} output.  Setting these keywords works similar to the
+general options (see @ref{Export Settings}).
 
-@table @samp
-@item DESCRIPTION
-@cindex @code{#+DESCRIPTION} (@LaTeX{})
+@table @asis
+@item @samp{DESCRIPTION}
+@cindex @samp{DESCRIPTION}, keyword
+@vindex org-latex-hyperref-template
+@vindex org-latex-title-command
 The document's description.  The description along with author name,
-keywords, and related file metadata are inserted in the output file by the
-@samp{hyperref} package.  See @code{org-latex-hyperref-template} for
+keywords, and related file metadata are inserted in the output file
+by the hyperref package.  See @code{org-latex-hyperref-template} for
 customizing metadata items.  See @code{org-latex-title-command} for
-typesetting description into the document's front matter.  Use multiple
-@code{#+DESCRIPTION} lines for long descriptions.
+typesetting description into the document's front matter.  Use
+multiple @samp{DESCRIPTION} keywords for long descriptions.
+
+@item @samp{LANGUAGE}
+@cindex @samp{LANGUAGE}, keyword
+@vindex org-latex-packages-alist
+In order to be effective, the @samp{babel} or @samp{polyglossia}
+packages---according to the @LaTeX{} compiler used---must be loaded
+with the appropriate language as argument.  This can be accomplished
+by modifying the @code{org-latex-packages-alist} variable, e.g., with the
+following snippet:
+
+@lisp
+(add-to-list 'org-latex-packages-alist
+             '("AUTO" "babel" t ("pdflatex")))
+(add-to-list 'org-latex-packages-alist
+             '("AUTO" "polyglossia" t ("xelatex" "lualatex")))
+@end lisp
 
-@item LATEX_CLASS
-@cindex @code{#+LATEX_CLASS}
+@item @samp{LATEX_CLASS}
+@cindex @samp{LATEX_CLASS}, keyword
 @vindex org-latex-default-class
 @vindex org-latex-classes
-This is @LaTeX{} document class, such as @code{article}, @code{report},
-@code{book}, and so on, which contain predefined preamble and headline level
-mapping that the @LaTeX{} export back-end needs.  The back-end reads the
-default class name from the @code{org-latex-default-class} variable.  Org has
-@code{article} as the default class.  A valid default class must be an
-element of @code{org-latex-classes}.
-
-@item LATEX_CLASS_OPTIONS
-@cindex @code{#+LATEX_CLASS_OPTIONS}
-Options the @LaTeX{} export back-end uses when calling the @LaTeX{} document
-class.
-
-@item LATEX_COMPILER
-@cindex @code{#+LATEX_COMPILER}
+This is @LaTeX{} document class, such as @emph{article}, @emph{report}, 
@emph{book},
+and so on, which contain predefined preamble and headline level
+mapping that the @LaTeX{} export back-end needs.  The back-end reads
+the default class name from the @code{org-latex-default-class} variable.
+Org has @emph{article} as the default class.  A valid default class must
+be an element of @code{org-latex-classes}.
+
+@item @samp{LATEX_CLASS_OPTIONS}
+@cindex @samp{LATEX_CLASS_OPTIONS}, keyword
+Options the @LaTeX{} export back-end uses when calling the @LaTeX{}
+document class.
+
+@item @samp{LATEX_COMPILER}
+@cindex @samp{LATEX_COMPILER}, keyword
 @vindex org-latex-compiler
 The compiler, such as @samp{pdflatex}, @samp{xelatex}, @samp{lualatex}, for
-producing the PDF (@code{org-latex-compiler}).
-
-@item LATEX_HEADER
-@cindex @code{#+LATEX_HEADER}
-@vindex org-latex-classes
-Arbitrary lines to add to the document's preamble, before the @samp{hyperref}
-settings.  See @code{org-latex-classes} for adjusting the structure and order
-of the @LaTeX{} headers.
+producing the PDF@.  See @code{org-latex-compiler}.
 
-@item LATEX_HEADER_EXTRA
-@cindex @code{#+LATEX_HEADER_EXTRA}
+@item @samp{LATEX_HEADER}
+@itemx @samp{LATEX_HEADER_EXTRA}
+@cindex @samp{LATEX_HEADER}, keyword
+@cindex @samp{LATEX_HEADER_EXTRA}, keyword
 @vindex org-latex-classes
-Arbitrary lines to add to the document's preamble, before the @samp{hyperref}
-settings.  See @code{org-latex-classes} for adjusting the structure and order
-of the @LaTeX{} headers.
-
-@item KEYWORDS
-@cindex @code{#+KEYWORDS} (@LaTeX{})
-The keywords for the document.  The description along with author name,
-keywords, and related file metadata are inserted in the output file by the
-@samp{hyperref} package.  See @code{org-latex-hyperref-template} for
+Arbitrary lines to add to the document's preamble, before the
+hyperref settings.  See @code{org-latex-classes} for adjusting the
+structure and order of the @LaTeX{} headers.
+
+@item @samp{KEYWORDS}
+@cindex @samp{KEYWORDS}, keyword
+@vindex org-latex-hyperref-template
+@vindex org-latex-title-command
+The keywords for the document.  The description along with author
+name, keywords, and related file metadata are inserted in the output
+file by the hyperref package.  See @code{org-latex-hyperref-template} for
 customizing metadata items.  See @code{org-latex-title-command} for
-typesetting description into the document's front matter.  Use multiple
-@code{#+KEYWORDS} lines if necessary.
+typesetting description into the document's front matter.  Use
+multiple @samp{KEYWORDS} lines if necessary.
 
-@item SUBTITLE
-@cindex @code{#+SUBTITLE} (@LaTeX{})
+@item @samp{SUBTITLE}
+@cindex @samp{SUBTITLE}, keyword
 @vindex org-latex-subtitle-separate
 @vindex org-latex-subtitle-format
 The document's subtitle.  It is typeset as per
 @code{org-latex-subtitle-format}.  If @code{org-latex-subtitle-separate} is
-non-@code{nil}, it is typed as part of the @samp{\title}-macro.  See
+non-@code{nil}, it is typed outside of the @code{\title} macro.  See
 @code{org-latex-hyperref-template} for customizing metadata items.  See
 @code{org-latex-title-command} for typesetting description into the
 document's front matter.
@@ -12240,18 +13958,19 @@ The following sections have further details.
 
 @node @LaTeX{} header and sectioning
 @subsection @LaTeX{} header and sectioning structure
+
 @cindex @LaTeX{} class
 @cindex @LaTeX{} sectioning structure
 @cindex @LaTeX{} header
 @cindex header, for @LaTeX{} files
 @cindex sectioning structure, for @LaTeX{} export
 
-The @LaTeX{} export back-end converts the first three of Org's outline levels
-into @LaTeX{} headlines.  The remaining Org levels are exported as
-@code{itemize} or @code{enumerate} lists.  To change this globally for the
-cut-off point between levels and lists, (@pxref{Export settings}).
+The @LaTeX{} export back-end converts the first three of Org's outline
+levels into @LaTeX{} headlines.  The remaining Org levels are exported as
+lists.  To change this globally for the cut-off point between levels
+and lists, (see @ref{Export Settings}).
 
-By default, the @LaTeX{} export back-end uses the @code{article} class.
+By default, the @LaTeX{} export back-end uses the @emph{article} class.
 
 @vindex org-latex-default-class
 @vindex org-latex-classes
@@ -12259,34 +13978,36 @@ By default, the @LaTeX{} export back-end uses the 
@code{article} class.
 @vindex org-latex-packages-alist
 To change the default class globally, edit @code{org-latex-default-class}.
 To change the default class locally in an Org file, add option lines
-@code{#+LATEX_CLASS: myclass}.  To change the default class for just a part
-of the Org file, set a sub-tree property, @code{EXPORT_LATEX_CLASS}.  The
+@samp{#+LATEX_CLASS: myclass}.  To change the default class for just a part
+of the Org file, set a sub-tree property, @samp{EXPORT_LATEX_CLASS}.  The
 class name entered here must be valid member of @code{org-latex-classes}.
 This variable defines a header template for each class into which the
 exporter splices the values of @code{org-latex-default-packages-alist} and
 @code{org-latex-packages-alist}.  Use the same three variables to define
 custom sectioning or custom classes.
 
-@cindex @code{#+LATEX_CLASS}
-@cindex @code{#+LATEX_CLASS_OPTIONS}
-@cindex property, @code{EXPORT_LATEX_CLASS}
-@cindex property, @code{EXPORT_LATEX_CLASS_OPTIONS}
-The @LaTeX{} export back-end sends the @code{LATEX_CLASS_OPTIONS} keyword and
-@code{EXPORT_LATEX_CLASS_OPTIONS} property as options to the @LaTeX{}
-@code{\documentclass} macro.  The options and the syntax for specifying them,
-including enclosing them in square brackets, follow @LaTeX{} conventions.
+@cindex @samp{LATEX_CLASS}, keyword
+@cindex @samp{LATEX_CLASS_OPTIONS}, keyword
+@cindex @samp{EXPORT_LATEX_CLASS}, property
+@cindex @samp{EXPORT_LATEX_CLASS_OPTIONS}, property
+The @LaTeX{} export back-end sends the @samp{LATEX_CLASS_OPTIONS} keyword and
+@samp{EXPORT_LATEX_CLASS_OPTIONS} property as options to the @LaTeX{}
+@code{\documentclass} macro.  The options and the syntax for specifying
+them, including enclosing them in square brackets, follow @LaTeX{}
+conventions.
 
 @example
 #+LATEX_CLASS_OPTIONS: [a4paper,11pt,twoside,twocolumn]
 @end example
 
-@cindex @code{#+LATEX_HEADER}
-@cindex @code{#+LATEX_HEADER_EXTRA}
-The @LaTeX{} export back-end appends values from @code{LATEX_HEADER} and
-@code{LATEX_HEADER_EXTRA} keywords to the @LaTeX{} header.  The docstring for
+
+@cindex @samp{LATEX_HEADER}, keyword
+@cindex @samp{LATEX_HEADER_EXTRA}, keyword
+The @LaTeX{} export back-end appends values from @samp{LATEX_HEADER} and
+@samp{LATEX_HEADER_EXTRA} keywords to the @LaTeX{} header.  The docstring for
 @code{org-latex-classes} explains in more detail.  Also note that @LaTeX{}
-export back-end does not append @code{LATEX_HEADER_EXTRA} to the header when
-previewing @LaTeX{} snippets (@pxref{Previewing @LaTeX{} fragments}).
+export back-end does not append @samp{LATEX_HEADER_EXTRA} to the header
+when previewing @LaTeX{} snippets (see @ref{Previewing @LaTeX{} fragments}).
 
 A sample Org file with the above headers:
 
@@ -12304,106 +14025,121 @@ A sample Org file with the above headers:
 @node Quoting @LaTeX{} code
 @subsection Quoting @LaTeX{} code
 
-The @LaTeX{} export back-end can insert any arbitrary @LaTeX{} code,
-@pxref{Embedded @LaTeX{}}.  There are three ways to embed such code in the
-Org file and they all use different quoting syntax.
+The @LaTeX{} export back-end can insert any arbitrary @LaTeX{} code, see
+@ref{Embedded @LaTeX{}}.  There are three ways to embed such code in the Org
+file and they all use different quoting syntax.
 
-Inserting in-line quoted with @ symbols:
 @cindex inline, in @LaTeX{} export
+Inserting in-line quoted with @@ symbols:
+
 @example
 Code embedded in-line @@@@latex:any arbitrary LaTeX code@@@@ in a paragraph.
 @end example
 
+
+@cindex @samp{LATEX}, keyword
 Inserting as one or more keyword lines in the Org file:
-@cindex @code{#+LATEX}
+
 @example
 #+LATEX: any arbitrary LaTeX code
 @end example
 
-Inserting as an export block in the Org file, where the back-end exports any
-code between begin and end markers:
-@cindex @code{#+BEGIN_EXPORT latex}
+
+@cindex @samp{BEGIN_EXPORT latex}
+Inserting as an export block in the Org file, where the back-end
+exports any code between begin and end markers:
+
 @example
 #+BEGIN_EXPORT latex
-any arbitrary LaTeX code
+  any arbitrary LaTeX code
 #+END_EXPORT
 @end example
 
 @node Tables in @LaTeX{} export
 @subsection Tables in @LaTeX{} export
+
 @cindex tables, in @LaTeX{} export
-@cindex @code{#+ATTR_LATEX}, in tables
 
 The @LaTeX{} export back-end can pass several @LaTeX{} attributes for table
-contents and layout.  Besides specifying label and caption (@pxref{Images and
-tables}), the other valid @LaTeX{} attributes include:
+contents and layout.  Besides specifying a label (see @ref{Internal Links})
+and a caption (see @ref{Captions}), the other valid @LaTeX{} attributes
+include:
 
-@table @code
-@item :mode
+@table @asis
+@item @samp{:mode}
 @vindex org-latex-default-table-mode
-The @LaTeX{} export back-end wraps the table differently depending on the
-mode for accurate rendering of math symbols.  Mode is either @code{table},
-@code{math}, @code{inline-math} or @code{verbatim}.  For @code{math} or
-@code{inline-math} mode, @LaTeX{} export back-end wraps the table in a math
-environment, but every cell in it is exported as-is.  The @LaTeX{} export
-back-end determines the default mode from
-@code{org-latex-default-table-mode}.  For , The @LaTeX{} export back-end
-merges contiguous tables in the same mode into a single environment.
-@item :environment
+The @LaTeX{} export back-end wraps the table differently depending on
+the mode for accurate rendering of math symbols.  Mode is either
+@samp{table}, @samp{math}, @samp{inline-math} or @samp{verbatim}.
+
+For @samp{math} or @samp{inline-math} mode, @LaTeX{} export back-end wraps the
+table in a math environment, but every cell in it is exported as-is.
+The @LaTeX{} export back-end determines the default mode from
+@code{org-latex-default-table-mode}.  The @LaTeX{} export back-end merges
+contiguous tables in the same mode into a single environment.
+
+@item @samp{:environment}
 @vindex org-latex-default-table-environment
-Set the default @LaTeX{} table environment for the @LaTeX{} export back-end
-to use when exporting Org tables.  Common @LaTeX{} table environments are
-provided by these packages: @code{tabularx}, @code{longtable}, @code{array},
-@code{tabu}, and @code{bmatrix}.  For packages, such as @code{tabularx} and
-@code{tabu}, or any newer replacements, include them in the
+Set the default @LaTeX{} table environment for the @LaTeX{} export
+back-end to use when exporting Org tables.  Common @LaTeX{} table
+environments are provided by these packages: tabularx, longtable,
+array, tabu, and bmatrix.  For packages, such as tabularx and tabu,
+or any newer replacements, include them in the
 @code{org-latex-packages-alist} variable so the @LaTeX{} export back-end can
-insert the appropriate load package headers in the converted @LaTeX{} file.
-Look in the docstring for the @code{org-latex-packages-alist} variable for
-configuring these packages for @LaTeX{} snippet previews, if any.
-@item :caption
-Use @code{#+CAPTION} keyword to set a simple caption for a table
-(@pxref{Images and tables}).  For custom captions, use @code{:caption}
-attribute, which accepts raw @LaTeX{} code.  @code{:caption} value overrides
-@code{#+CAPTION} value.
-@item :float
-@itemx :placement
-The table environments by default are not floats in @LaTeX{}.  To make them
-floating objects use @code{:float} with one of the following options:
-@code{sideways}, @code{multicolumn}, @code{t}, and @code{nil}.  Note that
-@code{sidewaystable} has been deprecated since Org 8.3.  @LaTeX{} floats can
-also have additional layout @code{:placement} attributes.  These are the
-usual @code{[h t b p ! H]} permissions specified in square brackets.  Note
-that for @code{:float sideways} tables, the @LaTeX{} export back-end ignores
-@code{:placement} attributes.
-@item :align
-@itemx :font
-@itemx :width
-The @LaTeX{} export back-end uses these attributes for regular tables to set
-their alignments, fonts, and widths.
-@item :spread
-When @code{:spread} is non-@code{nil}, the @LaTeX{} export back-end spreads
-or shrinks the table by the @code{:width} for @code{tabu} and @code{longtabu}
-environments.  @code{:spread} has no effect if @code{:width} is not set.
-@item :booktabs
-@itemx :center
-@itemx :rmlines
+insert the appropriate load package headers in the converted @LaTeX{}
+file.  Look in the docstring for the @code{org-latex-packages-alist}
+variable for configuring these packages for @LaTeX{} snippet previews,
+if any.
+
+@item @samp{:caption}
+Use @samp{CAPTION} keyword to set a simple caption for a table (see
+@ref{Captions}).  For custom captions, use @samp{:caption} attribute, which
+accepts raw @LaTeX{} code.  @samp{:caption} value overrides @samp{CAPTION} 
value.
+
+@item @samp{:float}
+@itemx @samp{:placement}
+The table environments by default are not floats in @LaTeX{}.  To make
+them floating objects use @samp{:float} with one of the following
+options: @samp{sideways}, @samp{multicolumn}, @samp{t}, and @samp{nil}.
+
+@LaTeX{} floats can also have additional layout @samp{:placement}
+attributes.  These are the usual @samp{[h t b p ! H]} permissions
+specified in square brackets.  Note that for @samp{:float sideways}
+tables, the @LaTeX{} export back-end ignores @samp{:placement} attributes.
+
+@item @samp{:align}
+@itemx @samp{:font}
+@itemx @samp{:width}
+The @LaTeX{} export back-end uses these attributes for regular tables
+to set their alignments, fonts, and widths.
+
+@item @samp{:spread}
+When @samp{:spread} is non-@code{nil}, the @LaTeX{} export back-end spreads or
+shrinks the table by the @samp{:width} for tabu and longtabu
+environments.  @samp{:spread} has no effect if @samp{:width} is not set.
+
+@item @samp{:booktabs}
+@itemx @samp{:center}
+@itemx @samp{:rmlines}
 @vindex org-latex-tables-booktabs
 @vindex org-latex-tables-centered
-All three commands are toggles.  @code{:booktabs} brings in modern
-typesetting enhancements to regular tables.  The @code{booktabs} package has
-to be loaded through @code{org-latex-packages-alist}.  @code{:center} is for
-centering the table.  @code{:rmlines} removes all but the very first
-horizontal line made of ASCII characters from "table.el" tables only.
-@item :math-prefix
-@itemx :math-suffix
-@itemx :math-arguments
-The @LaTeX{} export back-end inserts @code{:math-prefix} string value in a
-math environment before the table.  The @LaTeX{} export back-end inserts
-@code{:math-suffix} string value in a math environment after the table.  The
-@LaTeX{} export back-end inserts @code{:math-arguments} string value between
-the macro name and the table's contents.  @code{:math-arguments} comes in use
-for matrix macros that require more than one argument, such as
-@code{qbordermatrix}.
+All three commands are toggles.  @samp{:booktabs} brings in modern
+typesetting enhancements to regular tables.  The booktabs package
+has to be loaded through @code{org-latex-packages-alist}.  @samp{:center} is
+for centering the table.  @samp{:rmlines} removes all but the very first
+horizontal line made of ASCII characters from ``table.el'' tables
+only.
+
+@item @samp{:math-prefix}
+@itemx @samp{:math-suffix}
+@itemx @samp{:math-arguments}
+The @LaTeX{} export back-end inserts @samp{:math-prefix} string value in
+a math environment before the table.  The @LaTeX{} export back-end
+inserts @samp{:math-suffix} string value in a math environment after the
+table.  The @LaTeX{} export back-end inserts @samp{:math-arguments} string
+value between the macro name and the table's contents.
+@samp{:math-arguments} comes in use for matrix macros that require more
+than one argument, such as @samp{qbordermatrix}.
 @end table
 
 @LaTeX{} table attributes help formatting tables for a wide range of
@@ -12411,8 +14147,8 @@ situations, such as matrix product or spanning multiple 
pages:
 
 @example
 #+ATTR_LATEX: :environment longtable :align l|lp@{3cm@}r|l
-| ..... | ..... |
-| ..... | ..... |
+| ... | ... |
+| ... | ... |
 
 #+ATTR_LATEX: :mode math :environment bmatrix :math-suffix \times
 | a | b |
@@ -12423,94 +14159,100 @@ situations, such as matrix product or spanning 
multiple pages:
 @end example
 
 Set the caption with the @LaTeX{} command
-@code{\bicaption@{HeadingA@}@{HeadingB@}}:
+@samp{\bicaption@{HeadingA@}@{HeadingB@}}:
 
 @example
 #+ATTR_LATEX: :caption \bicaption@{HeadingA@}@{HeadingB@}
-| ..... | ..... |
-| ..... | ..... |
+| ... | ... |
+| ... | ... |
 @end example
 
-
 @node Images in @LaTeX{} export
 @subsection Images in @LaTeX{} export
-@cindex images, inline in @LaTeX{}
-@cindex inlining images in @LaTeX{}
-@cindex @code{#+ATTR_LATEX}, in images
 
-The @LaTeX{} export back-end processes image links in Org files that do not
-have descriptions, such as these links @samp{[[file:img.jpg]]} or
+@cindex images, inline in LaTeX
+@cindex inlining images in LaTeX
+@cindex @samp{ATTR_LATEX}, keyword
+
+The @LaTeX{} export back-end processes image links in Org files that do
+not have descriptions, such as these links @samp{[[file:img.jpg]]} or
 @samp{[[./img.jpg]]}, as direct image insertions in the final PDF output.  In
-the PDF, they are no longer links but actual images embedded on the page.
-The @LaTeX{} export back-end uses @code{\includegraphics} macro to insert the
-image.  But for TikZ@footnote{@url{http://sourceforge.net/projects/pgf/}}
+the PDF, they are no longer links but actual images embedded on the
+page.  The @LaTeX{} export back-end uses @samp{\includegraphics} macro to
+insert the image.  But for TikZ (@uref{http://sourceforge.net/projects/pgf/})
 images, the back-end uses an @code{\input} macro wrapped within
 a @code{tikzpicture} environment.
 
-For specifying image @code{:width}, @code{:height}, and other
-@code{:options}, use this syntax:
+For specifying image @samp{:width}, @samp{:height}, @samp{:scale} and other 
@samp{:options},
+use this syntax:
 
 @example
 #+ATTR_LATEX: :width 5cm :options angle=90
 [[./img/sed-hr4049.pdf]]
 @end example
 
-For custom commands for captions, use the @code{:caption} attribute.  It will
-override the default @code{#+CAPTION} value:
+A @samp{:scale} attribute overrides both @samp{:width} and @samp{:height} 
attributes.
+
+For custom commands for captions, use the @samp{:caption} attribute.  It
+overrides the default @samp{#+CAPTION} value:
 
 @example
 #+ATTR_LATEX: :caption \bicaption@{HeadingA@}@{HeadingB@}
 [[./img/sed-hr4049.pdf]]
 @end example
 
-When captions follow the method as described in @ref{Images and tables}, the
-@LaTeX{} export back-end wraps the picture in a floating @code{figure}
-environment.  To float an image without specifying a caption, set the
-@code{:float} attribute to one of the following:
-@itemize @minus
-@item
-@code{t}: for a standard @samp{figure} environment; used by default whenever
-an image has a caption.
-@item
-@code{multicolumn}: to span the image across multiple columns of a page; the
-back-end wraps the image in a @code{figure*} environment.
-@item
-@code{wrap}: for text to flow around the image on the right; the figure
-occupies the left half of the page.
-@item
-@code{sideways}: for a new page with the image sideways, rotated ninety
-degrees, in a @code{sidewaysfigure} environment; overrides @code{:placement}
-setting.
-@item
-@code{nil}: to avoid a @code{:float} even if using a caption.
-@end itemize
-@noindent
-Use the @code{placement} attribute to modify a floating environment's 
placement.
+When captions follow the method as described in @ref{Captions}, the @LaTeX{}
+export back-end wraps the picture in a floating @samp{figure} environment.
+To float an image without specifying a caption, set the @samp{:float}
+attribute to one of the following:
+
+@table @asis
+@item @samp{t}
+For a standard @samp{figure} environment; used by default whenever an
+image has a caption.
+
+@item @samp{multicolumn}
+To span the image across multiple columns of a page; the back-end
+wraps the image in a @samp{figure*} environment.
+
+@item @samp{wrap}
+For text to flow around the image on the right; the figure occupies
+the left half of the page.
+
+@item @samp{sideways}
+For a new page with the image sideways, rotated ninety degrees, in
+a @samp{sidewaysfigure} environment; overrides @samp{:placement} setting.
+
+@item @samp{nil}
+To avoid a @samp{:float} even if using a caption.
+@end table
+
+Use the @samp{placement} attribute to modify a floating environment's
+placement.
 
 @example
-#+ATTR_LATEX: :float wrap :width 0.38\textwidth :placement
-@{r@}@{0.4\textwidth@} [[./img/hst.png]]
+#+ATTR_LATEX: :float wrap :width 0.38\textwidth :placement 
@{r@}@{0.4\textwidth@}
+[[./img/hst.png]]
 @end example
 
 @vindex org-latex-images-centered
-@cindex center image (@LaTeX{} export)
-@cindex image, centering (@LaTeX{} export)
-
+@cindex center image in LaTeX export
+@cindex image, centering in LaTeX export
 The @LaTeX{} export back-end centers all images by default.  Setting
-@code{:center} attribute to @code{nil} disables centering.  To disable
-centering globally, set @code{org-latex-images-centered} to @code{t}.
+@samp{:center} to @samp{nil} disables centering.  To disable centering 
globally,
+set @code{org-latex-images-centered} to @samp{t}.
 
-Set the @code{:comment-include} attribute to non-@code{nil} value for the
-@LaTeX{} export back-end to comment out the @code{\includegraphics} macro.
+Set the @samp{:comment-include} attribute to non-@code{nil} value for the 
@LaTeX{}
+export back-end to comment out the @samp{\includegraphics} macro.
 
 @node Plain lists in @LaTeX{} export
 @subsection Plain lists in @LaTeX{} export
-@cindex plain lists, in @LaTeX{} export
-@cindex @code{#+ATTR_LATEX}, in plain lists
 
-The @LaTeX{} export back-end accepts the @code{:environment} and
-@code{:options} attributes for plain lists.  Both attributes work together
-for customizing lists, as shown in the examples:
+@cindex plain lists, in @LaTeX{} export
+@cindex @samp{ATTR_LATEX}, keyword
+The @LaTeX{} export back-end accepts the @samp{environment} and @samp{options}
+attributes for plain lists.  Both attributes work together for
+customizing lists, as shown in the examples:
 
 @example
 #+LATEX_HEADER: \usepackage[inline]@{enumitem@}
@@ -12539,37 +14281,39 @@ four:
 
 @node Source blocks in @LaTeX{} export
 @subsection Source blocks in @LaTeX{} export
+
 @cindex source blocks, in @LaTeX{} export
-@cindex @code{#+ATTR_LATEX}, in source blocks
+@cindex @samp{ATTR_LATEX}, keyword
 
 The @LaTeX{} export back-end can make source code blocks into floating
-objects through the attributes @code{:float} and @code{:options}.  For
-@code{:float}:
+objects through the attributes @samp{:float} and @samp{:options}.  For 
@samp{:float}:
 
-@itemize @minus
-@item
-@code{t}: makes a source block float; by default floats any source block with
+@table @asis
+@item @samp{t}
+Makes a source block float; by default floats any source block with
 a caption.
-@item
-@code{multicolumn}: spans the source block across multiple columns of a page.
-@item
-@code{nil}: avoids a @code{:float} even if using a caption; useful for
-source code blocks that may not fit on a page.
-@end itemize
+
+@item @samp{multicolumn}
+Spans the source block across multiple columns of a page.
+
+@item @samp{nil}
+Avoids a @samp{:float} even if using a caption; useful for source code
+blocks that may not fit on a page.
+@end table
 
 @example
 #+ATTR_LATEX: :float nil
 #+BEGIN_SRC emacs-lisp
-Lisp code that may not fit in a single page.
+  Lisp code that may not fit in a single page.
 #+END_SRC
 @end example
 
 @vindex org-latex-listings-options
 @vindex org-latex-minted-options
-The @LaTeX{} export back-end passes string values in @code{:options} to
-@LaTeX{} packages for customization of that specific source block.  In the
-example below, the @code{:options} are set for Minted.  Minted is a source
-code highlighting @LaTeX{}package with many configurable options.
+The @LaTeX{} export back-end passes string values in @samp{:options} to 
@LaTeX{}
+packages for customization of that specific source block.  In the
+example below, the @samp{:options} are set for Minted.  Minted is a source
+code highlighting @LaTeX{} package with many configurable options.
 
 @example
 #+ATTR_LATEX: :options commentstyle=\bfseries
@@ -12579,51 +14323,53 @@ code highlighting @LaTeX{}package with many 
configurable options.
 #+END_SRC
 @end example
 
-To apply similar configuration options for all source blocks in a file, use
-the @code{org-latex-listings-options} and @code{org-latex-minted-options}
-variables.
+To apply similar configuration options for all source blocks in
+a file, use the @code{org-latex-listings-options} and
+@code{org-latex-minted-options} variables.
 
 @node Example blocks in @LaTeX{} export
 @subsection Example blocks in @LaTeX{} export
+
 @cindex example blocks, in @LaTeX{} export
 @cindex verbatim blocks, in @LaTeX{} export
-@cindex @code{#+ATTR_LATEX}, in example blocks
+@cindex @samp{ATTR_LATEX}, keyword
 
-The @LaTeX{} export back-end wraps the contents of example blocks in a
-@samp{verbatim} environment.  To change this behavior to use another
-environment globally, specify an appropriate export filter (@pxref{Advanced
-configuration}).  To change this behavior to use another environment for each
-block, use the @code{:environment} parameter to specify a custom environment.
+The @LaTeX{} export back-end wraps the contents of example blocks in
+a @samp{verbatim} environment.  To change this behavior to use another
+environment globally, specify an appropriate export filter (see
+@ref{Advanced Export Configuration}).  To change this behavior to use
+another environment for each block, use the @samp{:environment} parameter
+to specify a custom environment.
 
 @example
 #+ATTR_LATEX: :environment myverbatim
 #+BEGIN_EXAMPLE
-This sentence is false.
+  This sentence is false.
 #+END_EXAMPLE
 @end example
 
 @node Special blocks in @LaTeX{} export
 @subsection Special blocks in @LaTeX{} export
+
 @cindex special blocks, in @LaTeX{} export
 @cindex abstract, in @LaTeX{} export
 @cindex proof, in @LaTeX{} export
-@cindex @code{#+ATTR_LATEX}, in special blocks
-
+@cindex @samp{ATTR_LATEX}, keyword
 
-For other special blocks in the Org file, the @LaTeX{} export back-end makes
-a special environment of the same name.  The back-end also takes
-@code{:options}, if any, and appends as-is to that environment's opening
+For other special blocks in the Org file, the @LaTeX{} export back-end
+makes a special environment of the same name.  The back-end also takes
+@samp{:options}, if any, and appends as-is to that environment's opening
 string.  For example:
 
 @example
 #+BEGIN_abstract
-We demonstrate how to solve the Syracuse problem.
+  We demonstrate how to solve the Syracuse problem.
 #+END_abstract
 
 #+ATTR_LATEX: :options [Proof of important theorem]
 #+BEGIN_proof
-...
-Therefore, any even number greater than 2 is the sum of two primes.
+  ...
+  Therefore, any even number greater than 2 is the sum of two primes.
 #+END_proof
 @end example
 
@@ -12632,311 +14378,326 @@ exports to
 
 @example
 \begin@{abstract@}
-We demonstrate how to solve the Syracuse problem.
+  We demonstrate how to solve the Syracuse problem.
 \end@{abstract@}
 
 \begin@{proof@}[Proof of important theorem]
-...
-Therefore, any even number greater than 2 is the sum of two primes.
+  ...
+  Therefore, any even number greater than 2 is the sum of two primes.
 \end@{proof@}
 @end example
 
-If you need to insert a specific caption command, use @code{:caption}
-attribute.  It will override standard @code{#+CAPTION} value, if any.  For
+If you need to insert a specific caption command, use @samp{:caption}
+attribute.  It overrides standard @samp{CAPTION} value, if any.  For
 example:
 
 @example
 #+ATTR_LATEX: :caption \MyCaption@{HeadingA@}
 #+BEGIN_proof
-...
+  ...
 #+END_proof
 @end example
 
 @node Horizontal rules in @LaTeX{} export
 @subsection Horizontal rules in @LaTeX{} export
+
 @cindex horizontal rules, in @LaTeX{} export
-@cindex @code{#+ATTR_LATEX}, in horizontal rules
+@cindex @samp{ATTR_LATEX}, keyword
 
 The @LaTeX{} export back-end converts horizontal rules by the specified
-@code{:width} and @code{:thickness} attributes.  For example:
+@samp{:width} and @samp{:thickness} attributes.  For example:
 
 @example
 #+ATTR_LATEX: :width .6\textwidth :thickness 0.8pt
 -----
 @end example
 
-@node Markdown export
-@section Markdown export
+@node Markdown Export
+@section Markdown Export
+
 @cindex Markdown export
 
-The Markdown export back-end, @code{md}, converts an Org file to a Markdown
-format, as defined at @url{http://daringfireball.net/projects/markdown/}.
+The Markdown export back-end, ``md'', converts an Org file to Markdown
+format, as defined at @uref{http://daringfireball.net/projects/markdown/}.
 
-Since @code{md} is built on top of the HTML back-end, any Org constructs not
-supported by Markdown, such as tables, the underlying @code{html} back-end
-(@pxref{HTML export}) converts them.
+Since it is built on top of the HTML back-end (see @ref{HTML Export}), it
+converts every Org construct not defined in Markdown syntax, such as
+tables, to HTML@.
 
+@anchor{Markdown export commands}
 @subheading Markdown export commands
 
-@table @kbd
-@orgcmd{C-c C-e m m,org-md-export-to-markdown}
-Export to a text file with Markdown syntax.  For @file{myfile.org}, Org
-exports to @file{myfile.md}, overwritten without warning.
-@orgcmd{C-c C-e m M,org-md-export-as-markdown}
+@table @asis
+@item @kbd{C-c C-e m m} (@code{org-md-export-to-markdown})
+@kindex C-c C-c m m
+@findex org-md-export-to-markdown
+Export to a text file with Markdown syntax.  For @samp{myfile.org}, Org
+exports to @samp{myfile.md}, overwritten without warning.
+
+@item @kbd{C-c C-e m M} (@code{org-md-export-as-markdown})
+@kindex C-c C-c m M
+@findex org-md-export-as-markdown
 Export to a temporary buffer.  Does not create a file.
-@item C-c C-e m o
+
+@item @kbd{C-c C-e m o}
+@kindex C-c C-e m o
 Export as a text file with Markdown syntax, then open it.
 @end table
 
+@anchor{Header and sectioning structure (1)}
 @subheading Header and sectioning structure
 
 @vindex org-md-headline-style
-Based on @code{org-md-headline-style}, markdown export can generate headlines
-of both @code{atx} and @code{setext} types.  @code{atx} limits headline
-levels to two.  @code{setext} limits headline levels to six.  Beyond these
-limits, the export back-end converts headlines to lists.  To set a limit to a
-level before the absolute limit (@pxref{Export settings}).
+Based on @code{org-md-headline-style}, Markdown export can generate
+headlines of both @emph{atx} and @emph{setext} types.  @emph{atx} limits 
headline
+levels to two whereas @emph{setext} limits headline levels to six.  Beyond
+these limits, the export back-end converts headlines to lists.  To set
+a limit to a level before the absolute limit (see @ref{Export Settings}).
 
-@c begin opendocument
+@node OpenDocument Text Export
+@section OpenDocument Text Export
 
-@node OpenDocument Text export
-@section OpenDocument Text export
 @cindex ODT
 @cindex OpenDocument
 @cindex export, OpenDocument
 @cindex LibreOffice
 
-The ODT export back-end handles creating of OpenDocument Text (ODT) format
-files.  The format complies with @cite{OpenDocument-v1.2
-specification}@footnote{@url{http://docs.oasis-open.org/office/v1.2/OpenDocument-v1.2.html,
-Open Document Format for Office Applications (OpenDocument) Version 1.2}} and
-is compatible with LibreOffice 3.4.
+The ODT export back-end handles creating of OpenDocument Text (ODT)
+format.  Documents created by this exporter use the
+@cite{OpenDocument-v1.2 specification}@footnote{See 
@uref{http://docs.oasis-open.org/office/v1.2/OpenDocument-v1.2.html, Open 
Document Format for Office Applications
+(OpenDocument) Version 1.2}.} and are compatible
+with LibreOffice 3.4.
 
 @menu
-* Pre-requisites for ODT export::  Required packages.
-* ODT export commands::         Invoking export.
-* ODT specific export settings::  Configuration options.
-* Extending ODT export::        Producing @file{.doc}, @file{.pdf} files.
-* Applying custom styles::      Styling the output.
-* Links in ODT export::         Handling and formatting links.
-* Tables in ODT export::        Org table conversions.
-* Images in ODT export::        Inserting images.
-* Math formatting in ODT export::  Formatting @LaTeX{} fragments.
-* Labels and captions in ODT export::  Rendering objects.
-* Literal examples in ODT export::  For source code and example blocks.
-* Advanced topics in ODT export::  For power users.
+* Pre-requisites for ODT export:: Required packages.
+* ODT export commands::          Invoking export.
+* ODT specific export settings:: Configuration options.
+* Extending ODT export::         Producing DOC, PDF files.
+* Applying custom styles::       Styling the output.
+* Links in ODT export::          Handling and formatting links.
+* Tables in ODT export::         Org tables conversions.
+* Images in ODT export::         Inserting images.
+* Math formatting in ODT export:: Formatting @LaTeX{} fragments.
+* Labels and captions in ODT export:: Rendering objects.
+* Literal examples in ODT export:: For source code and example blocks.
+* Advanced topics in ODT export:: For power users.
 @end menu
 
 @node Pre-requisites for ODT export
 @subsection Pre-requisites for ODT export
+
 @cindex zip
-The ODT export back-end relies on the @file{zip} program to create the final
-compressed ODT output.  Check if @file{zip} is locally available and
-executable.  Without @file{zip}, export cannot finish.
+
+The ODT export back-end relies on the zip program to create the final
+compressed ODT output.  Check if @samp{zip} is locally available and
+executable.  Without it, export cannot finish.
 
 @node ODT export commands
 @subsection ODT export commands
-@anchor{x-export-to-odt}
-@cindex region, active
-@cindex active region
-@cindex @code{transient-mark-mode}
-@table @kbd
-@orgcmd{C-c C-e o o,org-odt-export-to-odt}
-@cindex property, @code{EXPORT_FILE_NAME}
 
+@table @asis
+@item @kbd{C-c C-e o o} (@code{org-export-to-odt})
+@kindex C-c C-e o o
+@findex org-export-to-odt
 Export as OpenDocument Text file.
 
+@cindex @samp{EXPORT_FILE_NAME}, property
 @vindex org-odt-preferred-output-format
+
 If @code{org-odt-preferred-output-format} is specified, the ODT export
 back-end automatically converts the exported file to that format.
-@xref{x-export-to-other-formats, , Automatically exporting to other formats}.
 
-For @file{myfile.org}, Org exports to @file{myfile.odt}, overwriting without
-warning.  The ODT export back-end exports a region only if a region was
-active.  Note for exporting active regions, the @code{transient-mark-mode}
-has to be turned on.
+For @samp{myfile.org}, Org exports to @samp{myfile.odt}, overwriting without
+warning.  The ODT export back-end exports a region only if a region
+was active.
 
-If the selected region is a single tree, the ODT export back-end makes the
-tree head the document title.  Incidentally, @kbd{C-c @@} selects the current
-sub-tree.  If the tree head entry has, or inherits, an
-@code{EXPORT_FILE_NAME} property, the ODT export back-end uses that for file
-name.
+If the selected region is a single tree, the ODT export back-end
+makes the tree head the document title.  Incidentally, @kbd{C-c @@} selects 
the current sub-tree.  If the tree head entry has, or
+inherits, an @samp{EXPORT_FILE_NAME} property, the ODT export back-end
+uses that for file name.
 
-@kbd{C-c C-e o O}
-Export to an OpenDocument Text file format and open it.
+@item @kbd{C-c C-e o O}
+@kindex C-c C-e o O
+Export as an OpenDocument Text file and open the resulting file.
 
-@vindex org-odt-preferred-output-format
-When @code{org-odt-preferred-output-format} is specified, open the converted
-file instead.  @xref{x-export-to-other-formats, , Automatically exporting to
-other formats}.
+@vindex org-export-odt-preferred-output-format
+If @code{org-export-odt-preferred-output-format} is specified, open the
+converted file instead.  See @ref{Automatically exporting to other formats}.
 @end table
 
 @node ODT specific export settings
 @subsection ODT specific export settings
-The ODT export back-end has several additional keywords for customizing ODT
-output.  Setting these keywords works similar to the general options
-(@pxref{Export settings}).
-
-@table @samp
-@item DESCRIPTION
-@cindex @code{#+DESCRIPTION} (ODT)
-This is the document's description, which the ODT export back-end inserts as
-document metadata.  For long descriptions, use multiple @code{#+DESCRIPTION}
-lines.
 
-@item KEYWORDS
-@cindex @code{#+KEYWORDS} (ODT)
+The ODT export back-end has several additional keywords for
+customizing ODT output.  Setting these keywords works similar to the
+general options (see @ref{Export Settings}).
+
+@table @asis
+@item @samp{DESCRIPTION}
+@cindex @samp{DESCRIPTION}, keyword
+This is the document's description, which the ODT export back-end
+inserts as document metadata.  For long descriptions, use multiple
+lines, prefixed with @samp{DESCRIPTION}.
+
+@item @samp{KEYWORDS}
+@cindex @samp{KEYWORDS}, keyword
 The keywords for the document.  The ODT export back-end inserts the
-description along with author name, keywords, and related file metadata as
-metadata in the output file.  Use multiple @code{#+KEYWORDS} lines if
+description along with author name, keywords, and related file
+metadata as metadata in the output file.  Use multiple @samp{KEYWORDS} if
 necessary.
 
-@item ODT_STYLES_FILE
-@cindex ODT_STYLES_FILE
+@item @samp{ODT_STYLES_FILE}
+@cindex @samp{ODT_STYLES_FILE}, keyword
 @vindex org-odt-styles-file
-The ODT export back-end uses the @code{org-odt-styles-file} by default.  See
-@ref{Applying custom styles} for details.
+The ODT export back-end uses the @code{org-odt-styles-file} by default.
+See @ref{Applying custom styles} for details.
 
-@item SUBTITLE
-@cindex SUBTITLE (ODT)
+@item @samp{SUBTITLE}
+@cindex @samp{SUBTITLE}, keyword
 The document subtitle.
 @end table
 
 @node Extending ODT export
 @subsection Extending ODT export
 
-The ODT export back-end can produce documents in other formats besides ODT
-using a specialized ODT converter process.  Its common interface works with
-popular converters to produce formats such as @samp{doc}, or convert a
-document from one format, say @samp{csv}, to another format, say @samp{xls}.
+The ODT export back-end can produce documents in other formats besides
+ODT using a specialized ODT converter process.  Its common interface
+works with popular converters to produce formats such as @samp{doc}, or
+convert a document from one format, say @samp{csv}, to another format, say
+@samp{xls}.
 
 @cindex @file{unoconv}
-@cindex LibreOffice
-
-Customize @code{org-odt-convert-process} variable to point to @code{unoconv},
-which is the ODT's preferred converter.  Working installations of LibreOffice
-would already have @code{unoconv} installed.  Alternatively, other converters
-may be substituted here.  @xref{Configuring a document converter}.
+@vindex org-odt-convert-process
+Customize @code{org-odt-convert-process} variable to point to @samp{unoconv},
+which is the ODT's preferred converter.  Working installations of
+LibreOffice would already have @samp{unoconv} installed.  Alternatively,
+other converters may be substituted here.  See @ref{Configuring a document 
converter}.
 
+@anchor{Automatically exporting to other formats}
 @subsubheading Automatically exporting to other formats
-@anchor{x-export-to-other-formats}
 
 @vindex org-odt-preferred-output-format
-If ODT format is just an intermediate step to get to other formats, such as
-@samp{doc}, @samp{docx}, @samp{rtf}, or @samp{pdf}, etc., then extend the ODT
-export back-end to directly produce that format.  Specify the final format in
-the @code{org-odt-preferred-output-format} variable.  This is one way to
-extend (@pxref{x-export-to-odt,,Exporting to ODT}).
+If ODT format is just an intermediate step to get to other formats,
+such as @samp{doc}, @samp{docx}, @samp{rtf}, or @samp{pdf}, etc., then extend 
the ODT
+export back-end to directly produce that format.  Specify the final
+format in the @code{org-odt-preferred-output-format} variable.  This is one
+way to extend (see @ref{ODT export commands}).
 
+@anchor{Converting between document formats}
 @subsubheading Converting between document formats
-@anchor{x-convert-to-other-formats}
-
-The Org export back-end is made to be inter-operable with a wide range of text
-document format converters.  Newer generation converters, such as LibreOffice
-and Pandoc, can handle hundreds of formats at once.  Org provides a
-consistent interaction with whatever converter is installed.  Here are some
-generic commands:
 
-@vindex org-odt-convert
-@table @kbd
+The Org export back-end is made to be inter-operable with a wide range
+of text document format converters.  Newer generation converters, such
+as LibreOffice and Pandoc, can handle hundreds of formats at once.
+Org provides a consistent interaction with whatever converter is
+installed.  Here are some generic commands:
 
-@item M-x org-odt-convert @key{RET}
-Convert an existing document from one format to another.  With a prefix
-argument, opens the newly produced file.
+@table @asis
+@item @kbd{M-x org-odt-convert}
+@findex org-odt-convert
+Convert an existing document from one format to another.  With
+a prefix argument, opens the newly produced file.
 @end table
 
 @node Applying custom styles
 @subsection Applying custom styles
+
 @cindex styles, custom
 @cindex template, custom
 
-The ODT export back-end comes with many OpenDocument styles (@pxref{Working
-with OpenDocument style files}).  To expand or further customize these
-built-in style sheets, either edit the style sheets directly or generate them
-using an application such as LibreOffice.  The example here shows creating a
-style using LibreOffice.
+The ODT export back-end comes with many OpenDocument styles (see
+@ref{Working with OpenDocument style files}).  To expand or further
+customize these built-in style sheets, either edit the style sheets
+directly or generate them using an application such as LibreOffice.
+The example here shows creating a style using LibreOffice.
 
+@anchor{Applying custom styles the easy way}
 @subsubheading Applying custom styles: the easy way
 
 @enumerate
 @item
-Create a sample @file{example.org} file with settings as shown below, and
-export it to ODT format.
+Create a sample @samp{example.org} file with settings as shown below,
+and export it to ODT format.
 
 @example
 #+OPTIONS: H:10 num:t
 @end example
 
 @item
-Open the above @file{example.odt} using LibreOffice.  Use the @file{Stylist}
-to locate the target styles, which typically have the @samp{Org} prefix.
-Open one, modify, and save as either OpenDocument Text (@file{.odt}) or
-OpenDocument Template (@file{.ott}) file.
+Open the above @samp{example.odt} using LibreOffice.  Use the @emph{Stylist}
+to locate the target styles, which typically have the ``Org'' prefix.
+Open one, modify, and save as either OpenDocument Text (ODT) or
+OpenDocument Template (OTT) file.
 
 @item
-@cindex @code{#+ODT_STYLES_FILE}
 @vindex org-odt-styles-file
 Customize the variable @code{org-odt-styles-file} and point it to the
-newly created file.  For additional configuration options
-@pxref{x-overriding-factory-styles,,Overriding factory styles}.
+newly created file.  For additional configuration options, see
+@ref{x-overriding-factory-styles, , Overriding factory styles}.
 
-To apply and ODT style to a particular file, use the @code{#+ODT_STYLES_FILE}
-option as shown in the example below:
+@cindex @samp{ODT_STYLES_FILE}, keyword
+To apply an ODT style to a particular file, use the
+@samp{ODT_STYLES_FILE} keyword as shown in the example below:
 
 @example
 #+ODT_STYLES_FILE: "/path/to/example.ott"
 @end example
 
+
+@noindent
 or
 
 @example
 #+ODT_STYLES_FILE: ("/path/to/file.ott" ("styles.xml" "image/hdr.png"))
 @end example
-
 @end enumerate
 
+@anchor{Using third-party styles and templates}
 @subsubheading Using third-party styles and templates
 
-The ODT export back-end relies on many templates and style names.  Using
-third-party styles and templates can lead to mismatches.  Templates derived
-from built in ODT templates and styles seem to have fewer problems.
+The ODT export back-end relies on many templates and style names.
+Using third-party styles and templates can lead to mismatches.
+Templates derived from built in ODT templates and styles seem to have
+fewer problems.
 
 @node Links in ODT export
 @subsection Links in ODT export
+
 @cindex links, in ODT export
 
-ODT export back-end creates native cross-references for internal links and
-Internet-style links for all other link types.
+ODT exporter creates native cross-references for internal links.  It
+creates Internet-style links for all other links.
 
-A link with no description and pointing to a regular---un-itemized---outline
-heading is replaced with a cross-reference and section number of the heading.
+A link with no description and pointing to a regular, un-itemized,
+outline heading is replaced with a cross-reference and section number
+of the heading.
 
-A @samp{\ref@{label@}}-style reference to an image, table etc.@: is replaced
-with a cross-reference and sequence number of the labeled entity.
-@xref{Labels and captions in ODT export}.
+A @samp{\ref@{label@}}-style reference to an image, table etc., is replaced
+with a cross-reference and sequence number of the labeled entity.  See
+@ref{Labels and captions in ODT export}.
 
 @node Tables in ODT export
 @subsection Tables in ODT export
+
 @cindex tables, in ODT export
 
-The ODT export back-end handles native Org mode tables (@pxref{Tables}) and
-simple @file{table.el} tables.  Complex @file{table.el} tables having column
-or row spans are not supported.  Such tables are stripped from the exported
-document.
+The ODT export back-end handles native Org mode tables (see @ref{Tables})
+and simple @samp{table.el} tables.  Complex @samp{table.el} tables having 
column
+or row spans are not supported.  Such tables are stripped from the
+exported document.
 
-By default, the ODT export back-end exports a table with top and bottom
-frames and with ruled lines separating row and column groups (@pxref{Column
-groups}).  All tables are typeset to occupy the same width.  The ODT export
-back-end honors any table alignments and relative widths for columns
-(@pxref{Column width and alignment}).
+By default, the ODT export back-end exports a table with top and
+bottom frames and with ruled lines separating row and column groups
+(see @ref{Column Groups}).  All tables are typeset to occupy the same
+width.  The ODT export back-end honors any table alignments and
+relative widths for columns (see @ref{Column Width and Alignment}).
 
 Note that the ODT export back-end interprets column widths as weighted
 ratios, the default weight being 1.
 
-@cindex @code{#+ATTR_ODT}
-
-Specifying @code{:rel-width} property on an @code{#+ATTR_ODT} line controls
-the width of the table.  For example:
+@cindex @samp{ATTR_ODT}, keyword
+Specifying @samp{:rel-width} property on an @samp{ATTR_ODT} line controls the
+width of the table.  For example:
 
 @example
 #+ATTR_ODT: :rel-width 50
@@ -12951,66 +14712,76 @@ the width of the table.  For example:
 | Sum           |    16 |   123 |  2560 |  2699 |
 @end example
 
-On export, the above table takes 50% of text width area.  The exporter sizes
-the columns in the ratio: 13:5:5:5:6.  The first column is left-aligned and
-rest of the columns, right-aligned.  Vertical rules separate the header and
-the last column.  Horizontal rules separate the header and the last row.
+On export, the above table takes 50% of text width area.  The exporter
+sizes the columns in the ratio: 13:5:5:5:6.  The first column is
+left-aligned and rest of the columns, right-aligned.  Vertical rules
+separate the header and the last column.  Horizontal rules separate
+the header and the last row.
 
-For even more customization, create custom table styles and associate them
-with a table using the @code{#+ATTR_ODT} line.  @xref{Customizing tables in
-ODT export}.
+For even more customization, create custom table styles and associate
+them with a table using the @samp{ATTR_ODT} keyword.  See @ref{Customizing 
tables in ODT export}.
 
 @node Images in ODT export
 @subsection Images in ODT export
+
 @cindex images, embedding in ODT
 @cindex embedding images in ODT
 
+@anchor{Embedding images}
 @subsubheading Embedding images
-The ODT export back-end processes image links in Org files that do not have
-descriptions, such as these links @samp{[[file:img.jpg]]} or
-@samp{[[./img.jpg]]}, as direct image insertions in the final output.  Either
-of these examples works:
+
+The ODT export back-end processes image links in Org files that do not
+have descriptions, such as these links @samp{[[file:img.jpg]]} or 
@samp{[[./img.jpg]]},
+as direct image insertions in the final output.  Either of these
+examples works:
 
 @example
 [[file:img.png]]
 @end example
 
+
 @example
 [[./img.png]]
 @end example
 
+@anchor{Embedding clickable images}
 @subsubheading Embedding clickable images
-For clickable images, provide a link whose description is another link to an
-image file.  For example, to embed an image @file{org-mode-unicorn.png} which
-when clicked jumps to @uref{https://orgmode.org} website, do the following
+
+For clickable images, provide a link whose description is another link
+to an image file.  For example, to embed an image
+@samp{org-mode-unicorn.png} which when clicked jumps to 
@uref{https://orgmode.org}
+website, do the following
 
 @example
 [[https://orgmode.org][./org-mode-unicorn.png]]
 @end example
 
+@anchor{Sizing and scaling of embedded images}
 @subsubheading Sizing and scaling of embedded images
 
-@cindex @code{#+ATTR_ODT}
-Control the size and scale of the embedded images with the @code{#+ATTR_ODT}
+@cindex @samp{ATTR_ODT}, keyword
+
+Control the size and scale of the embedded images with the @samp{ATTR_ODT}
 attribute.
 
 @cindex identify, ImageMagick
 @vindex org-odt-pixels-per-inch
-The ODT export back-end starts with establishing the size of the image in the
-final document.  The dimensions of this size is measured in centimeters.  The
-back-end then queries the image file for its dimensions measured in pixels.
-For this measurement, the back-end relies on ImageMagick's @file{identify}
-program or Emacs @code{create-image} and @code{image-size} API.  ImageMagick
-is the preferred choice for large file sizes or frequent batch operations.
-The back-end then converts the pixel dimensions using
-@code{org-odt-pixels-per-inch} into the familiar 72 dpi or 96 dpi.  The
-default value for this is in @code{display-pixels-per-inch}, which can be
-tweaked for better results based on the capabilities of the output device.
-Here are some common image scaling operations:
+The ODT export back-end starts with establishing the size of the image
+in the final document.  The dimensions of this size are measured in
+centimeters.  The back-end then queries the image file for its
+dimensions measured in pixels.  For this measurement, the back-end
+relies on ImageMagick's identify program or Emacs @code{create-image} and
+@code{image-size} API@.  ImageMagick is the preferred choice for large file
+sizes or frequent batch operations.  The back-end then converts the
+pixel dimensions using @code{org-odt-pixels-per-inch} into the familiar 72
+dpi or 96 dpi.  The default value for this is in
+@code{display-pixels-per-inch}, which can be tweaked for better results
+based on the capabilities of the output device.  Here are some common
+image scaling operations:
 
 @table @asis
 @item Explicitly size the image
-To embed @file{img.png} as a 10 cm x 10 cm image, do the following:
+To embed @samp{img.png} as a 10 cm x 10 cm image, do the following:
 
 @example
 #+ATTR_ODT: :width 10 :height 10
@@ -13018,7 +14789,7 @@ To embed @file{img.png} as a 10 cm x 10 cm image, do 
the following:
 @end example
 
 @item Scale the image
-To embed @file{img.png} at half its size, do the following:
+To embed @samp{img.png} at half its size, do the following:
 
 @example
 #+ATTR_ODT: :scale 0.5
@@ -13026,8 +14797,8 @@ To embed @file{img.png} at half its size, do the 
following:
 @end example
 
 @item Scale the image to a specific width
-To embed @file{img.png} with a width of 10 cm while retaining the original
-height:width ratio, do the following:
+To embed @samp{img.png} with a width of 10 cm while retaining the
+original height:width ratio, do the following:
 
 @example
 #+ATTR_ODT: :width 10
@@ -13035,8 +14806,8 @@ height:width ratio, do the following:
 @end example
 
 @item Scale the image to a specific height
-To embed @file{img.png} with a height of 10 cm while retaining the original
-height:width ratio, do the following
+To embed @samp{img.png} with a height of 10 cm while retaining the
+original height:width ratio, do the following:
 
 @example
 #+ATTR_ODT: :height 10
@@ -13044,60 +14815,61 @@ height:width ratio, do the following
 @end example
 @end table
 
+@anchor{Anchoring of images}
 @subsubheading Anchoring of images
 
-@cindex @code{#+ATTR_ODT}
-The ODT export back-end can anchor images to @samp{"as-char"},
-@samp{"paragraph"}, or @samp{"page"}.  Set the preferred anchor using the
-@code{:anchor} property of the @code{#+ATTR_ODT} line.
+@cindex @samp{ATTR_ODT}, keyword
+The ODT export back-end can anchor images to @samp{as-char}, @samp{paragraph},
+or @samp{page}.  Set the preferred anchor using the @samp{:anchor} property of
+the @samp{ATTR_ODT} line.
 
 To create an image that is anchored to a page:
+
 @example
-#+ATTR_ODT: :anchor "page"
+#+ATTR_ODT: :anchor page
 [[./img.png]]
 @end example
 
 @node Math formatting in ODT export
 @subsection Math formatting in ODT export
 
-The ODT export back-end has special support built-in for handling math.
+The ODT exporter has special support for handling math.
 
 @menu
-* Working with @LaTeX{} math snippets::  Embedding in @LaTeX{} format.
-* Working with MathML or OpenDocument formula files::  Embedding in native 
format.
+* @LaTeX{} math snippets::       Embedding in @LaTeX{} format.
+* MathML and OpenDocument formula files:: Embedding in native format.
 @end menu
 
-@node Working with @LaTeX{} math snippets
-@subsubheading Working with @LaTeX{} math snippets
+@node @LaTeX{} math snippets
+@subsubsection @LaTeX{} math snippets
 
-@LaTeX{} math snippets (@pxref{@LaTeX{} fragments}) can be embedded in an ODT
+@LaTeX{} math snippets (see @ref{@LaTeX{} fragments}) can be embedded in the 
ODT
 document in one of the following ways:
 
-@cindex MathML
-@enumerate
+@table @asis
 @item MathML
-
-Add this line to the Org file.  This option is activated on a per-file basis.
+@cindex MathML
+Add this line to the Org file.  This option is activated on
+a per-file basis.
 
 @example
-#+OPTIONS: LaTeX:t
+#+OPTIONS: tex:t
 @end example
 
+
 With this option, @LaTeX{} fragments are first converted into MathML
 fragments using an external @LaTeX{}-to-MathML converter program.  The
-resulting MathML fragments are then embedded as an OpenDocument Formula in
-the exported document.
+resulting MathML fragments are then embedded as an OpenDocument
+Formula in the exported document.
 
 @vindex org-latex-to-mathml-convert-command
 @vindex org-latex-to-mathml-jar-file
-
-To specify the @LaTeX{}-to-MathML converter, customize the variables
-@code{org-latex-to-mathml-convert-command} and
+You can specify the @LaTeX{}-to-MathML converter by customizing the
+variables @code{org-latex-to-mathml-convert-command} and
 @code{org-latex-to-mathml-jar-file}.
 
-To use MathToWeb@footnote{See
-@uref{http://www.mathtoweb.com/cgi-bin/mathtoweb_home.pl, MathToWeb}.} as the
-preferred converter, configure the above variables as
+If you prefer to use MathToWeb@footnote{See 
@uref{http://www.mathtoweb.com/cgi-bin/mathtoweb_home.pl, MathToWeb}.} as your 
converter, you can
+configure the above variables as shown below.
 
 @lisp
 (setq org-latex-to-mathml-convert-command
@@ -13105,63 +14877,74 @@ preferred converter, configure the above variables as
       org-latex-to-mathml-jar-file
       "/path/to/mathtoweb.jar")
 @end lisp
-To use @LaTeX{}ML@footnote{See @uref{http://dlmf.nist.gov/LaTeXML/}.} use
+
+@noindent
+or, to use @LaTeX{}​ML@footnote{See @uref{http://dlmf.nist.gov/LaTeXML/}.} 
instead,
+
 @lisp
 (setq org-latex-to-mathml-convert-command
       "latexmlmath \"%i\" --presentationmathml=%o")
 @end lisp
 
-To quickly verify the reliability of the @LaTeX{}-to-MathML converter, use
-the following commands:
+To quickly verify the reliability of the @LaTeX{}-to-MathML
+converter, use the following commands:
 
-@table @kbd
-@item M-x org-odt-export-as-odf @key{RET}
-Convert a @LaTeX{} math snippet to an OpenDocument formula (@file{.odf}) file.
+@table @asis
+@item @kbd{M-x org-export-as-odf}
+Convert a @LaTeX{} math snippet to an OpenDocument formula (@samp{.odf})
+file.
 
-@item M-x org-odt-export-as-odf-and-open @key{RET}
-Convert a @LaTeX{} math snippet to an OpenDocument formula (@file{.odf}) file
-and open the formula file with the system-registered application.
+@item @kbd{M-x org-export-as-odf-and-open}
+Convert a @LaTeX{} math snippet to an OpenDocument formula (@samp{.odf})
+file and open the formula file with the system-registered
+application.
 @end table
 
+@item PNG images
 @cindex dvipng
 @cindex dvisvgm
-@cindex imagemagick
-@item PNG images
-
-Add this line to the Org file.  This option is activated on a per-file basis.
+@cindex ImageMagick
+Add this line to the Org file.  This option is activated on
+a per-file basis.
 
 @example
 #+OPTIONS: tex:dvipng
 @end example
 
+
 @example
 #+OPTIONS: tex:dvisvgm
 @end example
 
-or:
+
+@noindent
+or
 
 @example
 #+OPTIONS: tex:imagemagick
 @end example
 
-Under this option, @LaTeX{} fragments are processed into PNG or SVG images
-and the resulting images are embedded in the exported document.  This method
-requires @file{dvipng} program, @file{dvisvgm} or @file{imagemagick}
-programs.
-@end enumerate
 
-@node Working with MathML or OpenDocument formula files
-@subsubheading Working with MathML or OpenDocument formula files
+Under this option, @LaTeX{} fragments are processed into PNG or SVG
+images and the resulting images are embedded in the exported
+document.  This method requires dvipng program, dvisvgm or
+ImageMagick programs.
+@end table
 
-When embedding @LaTeX{} math snippets in ODT documents is not reliable, there
-is one more option to try.  Embed an equation by linking to its MathML
-(@file{.mml}) source or its OpenDocument formula (@file{.odf}) file as shown
-below:
+@node MathML and OpenDocument formula files
+@subsubsection MathML and OpenDocument formula files
+
+When embedding @LaTeX{} math snippets in ODT documents is not reliable,
+there is one more option to try.  Embed an equation by linking to its
+MathML (@samp{.mml}) source or its OpenDocument formula (@samp{.odf}) file as
+shown below:
 
 @example
 [[./equation.mml]]
 @end example
 
+
+@noindent
 or
 
 @example
@@ -13173,13 +14956,14 @@ or
 
 ODT format handles labeling and captioning of objects based on their
 types.  Inline images, tables, @LaTeX{} fragments, and Math formulas are
-numbered and captioned separately.  Each object also gets a unique sequence
-number based on its order of first appearance in the Org file.  Each category
-has its own sequence.  A caption is just a label applied to these objects.
+numbered and captioned separately.  Each object also gets a unique
+sequence number based on its order of first appearance in the Org
+file.  Each category has its own sequence.  A caption is just a label
+applied to these objects.
 
 @example
 #+CAPTION: Bell curve
-#+LABEL:   fig:SED-HR4049
+#+NAME:   fig:SED-HR4049
 [[./img/a.png]]
 @end example
 
@@ -13189,10 +14973,11 @@ When rendered, it may show as follows in the exported 
document:
 Figure 2: Bell curve
 @end example
 
+
 @vindex org-odt-category-map-alist
 To modify the category component of the caption, customize the option
-@code{org-odt-category-map-alist}.  For example, to tag embedded images with
-the string @samp{Illustration} instead of the default string @samp{Figure},
+@code{org-odt-category-map-alist}.  For example, to tag embedded images
+with the string ``Illustration'' instead of the default string ``Figure'',
 use the following setting:
 
 @lisp
@@ -13209,12 +14994,11 @@ Illustration 2: Bell curve
 @node Literal examples in ODT export
 @subsection Literal examples in ODT export
 
-The ODT export back-end supports literal examples (@pxref{Literal examples})
-with full fontification.  Internally, the ODT export back-end relies on
-@file{htmlfontify.el} to generate the style definitions needed for fancy
-listings.  The auto-generated styles get @samp{OrgSrc} prefix and inherit
-colors from the faces used by Emacs @code{font-lock} library for that source
-language.
+The ODT export back-end supports literal examples (see @ref{Literal Examples}) 
with full fontification.  Internally, the ODT export
+back-end relies on @samp{htmlfontify.el} to generate the style definitions
+needed for fancy listings.  The auto-generated styles get @samp{OrgSrc}
+prefix and inherit colors from the faces used by Emacs Font Lock
+library for that source language.
 
 @vindex org-odt-fontify-srcblocks
 For custom fontification styles, customize the
@@ -13227,52 +15011,43 @@ To turn off fontification of literal examples, 
customize the
 @node Advanced topics in ODT export
 @subsection Advanced topics in ODT export
 
-The ODT export back-end has extensive features useful for power users and
-frequent uses of ODT formats.
-
-@menu
-* Configuring a document converter::  Registering a document converter.
-* Working with OpenDocument style files::  Exploring internals.
-* Creating one-off styles::     Customizing styles, highlighting.
-* Customizing tables in ODT export::  Defining table templates.
-* Validating OpenDocument XML::  Debugging corrupted OpenDocument files.
-@end menu
+The ODT export back-end has extensive features useful for power users
+and frequent uses of ODT formats.
 
-@node Configuring a document converter
+@anchor{Configuring a document converter}
 @subsubheading Configuring a document converter
+
 @cindex convert
 @cindex doc, docx, rtf
 @cindex converter
 
-The ODT export back-end works with popular converters with little or no extra
-configuration.  @xref{Extending ODT export}.  The following is for unsupported
-converters or tweaking existing defaults.
+The ODT export back-end works with popular converters with little or
+no extra configuration.  See @ref{Extending ODT export}.  The following is
+for unsupported converters or tweaking existing defaults.
 
-@enumerate
+@table @asis
 @item Register the converter
-
-@vindex org-odt-convert-processes
+@vindex org-export-odt-convert-processes
 Add the name of the converter to the @code{org-odt-convert-processes}
-variable.  Note that it also requires how the converter is invoked on the
-command line.  See the variable's docstring for details.
+variable.  Note that it also requires how the converter is invoked
+on the command line.  See the variable's docstring for details.
 
 @item Configure its capabilities
-
-@vindex org-odt-convert-capabilities
-@anchor{x-odt-converter-capabilities} Specify which formats the converter can
-handle by customizing the variable @code{org-odt-convert-capabilities}.  Use
-the entry for the default values in this variable for configuring the new
-converter.  Also see its docstring for details.
+@vindex org-export-odt-convert-capabilities
+Specify which formats the converter can handle by customizing the
+variable @code{org-odt-convert-capabilities}.  Use the entry for the
+default values in this variable for configuring the new converter.
+Also see its docstring for details.
 
 @item Choose the converter
+@vindex org-export-odt-convert-process
+Select the newly added converter as the preferred one by customizing
+the option @code{org-odt-convert-process}.
+@end table
 
-@vindex org-odt-convert-process
-Select the newly added converter as the preferred one by customizing the
-option @code{org-odt-convert-process}.
-@end enumerate
-
-@node Working with OpenDocument style files
+@anchor{Working with OpenDocument style files}
 @subsubheading Working with OpenDocument style files
+
 @cindex styles, custom
 @cindex template, custom
 
@@ -13280,109 +15055,88 @@ This section explores the internals of the ODT 
exporter; the means by which
 it produces styled documents; the use of automatic and custom OpenDocument
 styles.
 
-@anchor{x-factory-styles}
-@subsubheading a) Factory styles
-
-The ODT exporter relies on two files for generating its output.
-These files are bundled with the distribution under the directory pointed to
+The ODT exporter relies on two files for generating its output.  These
+files are bundled with the distribution under the directory pointed to
 by the variable @code{org-odt-styles-dir}.  The two files are:
 
-@itemize
-@anchor{x-orgodtstyles-xml}
-@item
-@file{OrgOdtStyles.xml}
-
-This file contributes to the @file{styles.xml} file of the final @samp{ODT}
+@table @asis
+@item @samp{OrgOdtStyles.xml} @anchor{x-orgodtstyles-xml}
+This file contributes to the @samp{styles.xml} file of the final ODT
 document.  This file gets modified for the following purposes:
-@enumerate
 
+@enumerate
 @item
-To control outline numbering based on user settings.
+To control outline numbering based on user settings;
 
 @item
-To add styles generated by @file{htmlfontify.el} for fontification of code
-blocks.
+To add styles generated by @samp{htmlfontify.el} for fontification of
+code blocks.
 @end enumerate
 
-@anchor{x-orgodtcontenttemplate-xml}
-@item
-@file{OrgOdtContentTemplate.xml}
-
-This file contributes to the @file{content.xml} file of the final @samp{ODT}
+@item @samp{OrgOdtContentTemplate.xml} @anchor{x-orgodtcontenttemplate-xml}
+This file contributes to the @samp{content.xml} file of the final ODT
 document.  The contents of the Org outline are inserted between the
-@samp{<office:text>}@dots{}@samp{</office:text>} elements of this file.
+@samp{<office:text>} @dots{} @samp{</office:text>} elements of this file.
 
-Apart from serving as a template file for the final @file{content.xml}, the
-file serves the following purposes:
-@enumerate
+Apart from serving as a template file for the final @samp{content.xml},
+the file serves the following purposes:
 
+@enumerate
 @item
-It contains automatic styles for formatting of tables which are referenced by
-the exporter.
+It contains automatic styles for formatting of tables which are
+referenced by the exporter;
 
 @item
-It contains @samp{<text:sequence-decl>}@dots{}@samp{</text:sequence-decl>}
-elements that control numbering of tables, images, equations, and similar
-entities.
+It contains @samp{<text:sequence-decl>} @dots{} @samp{</text:sequence-decl>}
+elements that control numbering of tables, images, equations, and
+similar entities.
 @end enumerate
-@end itemize
-
-@anchor{x-overriding-factory-styles}
-@subsubheading b) Overriding factory styles
-The following two variables control the location from where the ODT exporter
-picks up the custom styles and content template files.  Customize these
-variables to override the factory styles used by the exporter.
-
-@itemize
-@anchor{x-org-odt-styles-file}
-@item
-@code{org-odt-styles-file}
-
-The ODT export back-end uses the file pointed to by this variable, such as
-@file{styles.xml}, for the final output.  It can take one of the following
-values:
-
-@enumerate
-@item A @file{styles.xml} file
+@end table
 
-Use this file instead of the default @file{styles.xml}
+@anchor{x-overriding-factory-styles} The following two variables control
+the location from where the ODT exporter picks up the custom styles
+and content template files.  Customize these variables to override the
+factory styles used by the exporter.
 
-@item A @file{.odt} or @file{.ott} file
+@table @asis
+@item @code{org-odt-styles-file}
+The ODT export back-end uses the file pointed to by this variable,
+such as @samp{styles.xml}, for the final output.  It can take one of the
+following values:
 
-Use the @file{styles.xml} contained in the specified OpenDocument Text or
-Template file
+@table @asis
+@item @samp{FILE.xml}
+Use this file instead of the default @samp{styles.xml}
 
-@item A @file{.odt} or @file{.ott} file and a subset of files contained within 
them
+@item @samp{FILE.odt} or @samp{FILE.ott}
+Use the @samp{styles.xml} contained in the specified OpenDocument
+Text or Template file
 
-Use the @file{styles.xml} contained in the specified OpenDocument Text or
-Template file.  Additionally extract the specified member files and embed
-those within the final @samp{ODT} document.
+@item @samp{FILE.odt} or @samp{FILE.ott} and a subset of included files
+Use the @samp{styles.xml} contained in the specified OpenDocument Text
+or Template file.  Additionally extract the specified member files
+and embed those within the final ODT document.
 
-Use this option if the @file{styles.xml} file references additional files
-like header and footer images.
+Use this option if the @samp{styles.xml} file references additional
+files like header and footer images.
 
 @item @code{nil}
+Use the default @samp{styles.xml}.
+@end table
 
-Use the default @file{styles.xml}
-@end enumerate
-
-@anchor{x-org-odt-content-template-file}
-@item
-@code{org-odt-content-template-file}
-
-Use this variable to specify the blank @file{content.xml} that will be used
-in the final output.
-@end itemize
+@item @code{org-odt-content-template-file}
+Use this variable to specify the blank @samp{content.xml} used in the
+final output.
+@end table
 
-@node Creating one-off styles
+@anchor{Creating one-off styles}
 @subsubheading Creating one-off styles
 
-The ODT export back-end can read embedded raw OpenDocument XML from the Org
-file.  Such direct formatting are useful for one-off instances.
+The ODT export back-end can read embedded raw OpenDocument XML from
+the Org file.  Such direct formatting is useful for one-off instances.
 
-@enumerate
+@table @asis
 @item Embedding ODT tags as part of regular text
-
 Enclose OpenDocument syntax in @samp{@@@@odt:...@@@@} for inline markup.  For
 example, to highlight a region of text do the following:
 
@@ -13391,9 +15145,9 @@ example, to highlight a region of text do the following:
 text</text:span>@@@@.  But this is regular text.
 @end example
 
-@strong{Hint:} To see the above example in action, edit the @file{styles.xml}
-(@pxref{x-orgodtstyles-xml,,Factory styles}) and add a custom
-@samp{Highlight} style as shown below:
+@strong{Hint:} To see the above example in action, edit the @samp{styles.xml}
+(see @ref{x-orgodtstyles-xml, , Factory styles}) and add a custom 
@emph{Highlight} style as shown
+below:
 
 @example
 <style:style style:name="Highlight" style:family="text">
@@ -13402,17 +15156,17 @@ text</text:span>@@@@.  But this is regular text.
 @end example
 
 @item Embedding a one-line OpenDocument XML
-
-The ODT export back-end can read one-liner options with @code{#+ODT:}
-in the Org file.  For example, to force a page break:
+@cindex @samp{ODT}, keyword
+The ODT export back-end can read one-liner options with @samp{#+ODT:} in
+the Org file.  For example, to force a page break:
 
 @example
 #+ODT: <text:p text:style-name="PageBreak"/>
 @end example
 
 @strong{Hint:} To see the above example in action, edit your
-@file{styles.xml} (@pxref{x-orgodtstyles-xml,,Factory styles}) and add a
-custom @samp{PageBreak} style as shown below.
+@samp{styles.xml} (see @ref{x-orgodtstyles-xml, , Factory styles}) and add a 
custom @samp{PageBreak}
+style as shown below.
 
 @example
 <style:style style:name="PageBreak" style:family="paragraph"
@@ -13422,51 +15176,48 @@ custom @samp{PageBreak} style as shown below.
 @end example
 
 @item Embedding a block of OpenDocument XML
+The ODT export back-end can also read ODT export blocks for
+OpenDocument XML@.  Such blocks use the @samp{#+BEGIN_EXPORT odt}
+@dots{} @samp{#+END_EXPORT} constructs.
 
-The ODT export back-end can also read ODT export blocks for OpenDocument XML.
-Such blocks use the @code{#+BEGIN_EXPORT odt}@dots{}@code{#+END_EXPORT}
-constructs.
-
-For example, to create a one-off paragraph that uses bold text, do the
-following:
+For example, to create a one-off paragraph that uses bold text, do
+the following:
 
 @example
 #+BEGIN_EXPORT odt
-<text:p text:style-name="Text_20_body_20_bold">
-This paragraph is specially formatted and uses bold text.
-</text:p>
+  <text:p text:style-name="Text_20_body_20_bold">
+  This paragraph is specially formatted and uses bold text.
+  </text:p>
 #+END_EXPORT
 @end example
+@end table
 
-@end enumerate
-
-@node Customizing tables in ODT export
+@anchor{Customizing tables in ODT export}
 @subsubheading Customizing tables in ODT export
+
 @cindex tables, in ODT export
+@cindex @samp{ATTR_ODT}, keyword
 
-@cindex @code{#+ATTR_ODT}
-Override the default table format by specifying a custom table style with the
-@code{#+ATTR_ODT} line.  For a discussion on default formatting of tables
-@pxref{Tables in ODT export}.
+Override the default table format by specifying a custom table style
+with the @samp{#+ATTR_ODT} line.  For a discussion on default formatting of
+tables, see @ref{Tables in ODT export}.
 
 This feature closely mimics the way table templates are defined in the
-OpenDocument-v1.2
-specification.@footnote{@url{http://docs.oasis-open.org/office/v1.2/OpenDocument-v1.2.html,
-OpenDocument-v1.2 Specification}}
+OpenDocument-v1.2 
specification@footnote{@uref{http://docs.oasis-open.org/office/v1.2/OpenDocument-v1.2.html,
 OpenDocument-v1.2 Specification}}.
 
 @vindex org-odt-table-styles
 For quick preview of this feature, install the settings below and export the
 table that follows:
 
 @lisp
-(setq org-odt-table-styles
-      (append org-odt-table-styles
-            '(("TableWithHeaderRowAndColumn" "Custom"
-                ((use-first-row-styles . t)
-                 (use-first-column-styles . t)))
+(setq org-export-odt-table-styles
+      (append org-export-odt-table-styles
+              '(("TableWithHeaderRowAndColumn" "Custom"
+                 ((use-first-row-styles . t)
+                  (use-first-column-styles . t)))
                 ("TableWithFirstRowandLastRow" "Custom"
                  ((use-first-row-styles . t)
-                 (use-last-row-styles . t))))))
+                  (use-last-row-styles . t))))))
 @end lisp
 
 @example
@@ -13476,50 +15227,56 @@ table that follows:
 | Anna  |  4321 |  25 |
 @end example
 
-The example above used @samp{Custom} template and installed two table styles
-@samp{TableWithHeaderRowAndColumn} and @samp{TableWithFirstRowandLastRow}.
-@strong{Important:} The OpenDocument styles needed for producing the above
-template were pre-defined.  They are available in the section marked
-@samp{Custom Table Template} in @file{OrgOdtContentTemplate.xml}
-(@pxref{x-orgodtcontenttemplate-xml,,Factory styles}.  For adding new
-templates, define new styles here.
+The example above used @samp{Custom} template and installed two table
+styles @samp{TableWithHeaderRowAndColumn} and
+@samp{TableWithFirstRowandLastRow}.  @strong{Important:} The OpenDocument 
styles
+needed for producing the above template were pre-defined.  They are
+available in the section marked @samp{Custom Table Template} in
+@samp{OrgOdtContentTemplate.xml} (see @ref{x-orgodtcontenttemplate-xml, , 
Factory styles}).  For adding new
+templates, define new styles there.
 
 To use this feature proceed as follows:
 
 @enumerate
 @item
-Create a table template@footnote{See the @code{<table:table-template>}
-element of the OpenDocument-v1.2 specification}
+Create a table template@footnote{See the @samp{<table:table-template>} element 
of the
+OpenDocument-v1.2 specification.}.
 
 A table template is set of @samp{table-cell} and @samp{paragraph} styles for
 each of the following table cell categories:
 
-@itemize @minus
-@item Body
-@item First column
-@item Last column
-@item First row
-@item Last row
-@item Even row
-@item Odd row
-@item Even column
-@item Odd Column
+@itemize
+@item
+Body
+@item
+First column
+@item
+Last column
+@item
+First row
+@item
+Last row
+@item
+Even row
+@item
+Odd row
+@item
+Even column
+@item
+Odd Column
 @end itemize
 
-The names for the above styles must be chosen based on the name of the table
-template using a well-defined convention.
+The names for the above styles must be chosen based on the name of
+the table template using a well-defined convention.
 
-The naming convention is better illustrated with an example.  For a table
-template with the name @samp{Custom}, the needed style names are listed in
-the following table.
+The naming convention is better illustrated with an example.  For
+a table template with the name @samp{Custom}, the needed style names are
+listed in the following table.
 
-@multitable  {Table cell type} {CustomEvenColumnTableCell} 
{CustomEvenColumnTableParagraph}
-@headitem Table cell type
-@tab @code{table-cell} style
-@tab @code{paragraph} style
-@item
-@tab
-@tab
+@multitable {aaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@headitem Cell type
+@tab Cell style
+@tab Paragraph style
 @item Body
 @tab @samp{CustomTableCell}
 @tab @samp{CustomTableParagraph}
@@ -13550,36 +15307,37 @@ the following table.
 @end multitable
 
 To create a table template with the name @samp{Custom}, define the above
-styles in the
-@code{<office:automatic-styles>}...@code{</office:automatic-styles>} element
-of the content template file (@pxref{x-orgodtcontenttemplate-xml,,Factory
-styles}).
+styles in the @samp{<office:automatic-styles>} @dots{}
+@samp{</office:automatic-styles>} element of the content template file
+(see @ref{x-orgodtcontenttemplate-xml, , Factory styles}).
 
 @item
-Define a table style@footnote{See the attributes @code{table:template-name},
-@code{table:use-first-row-styles}, @code{table:use-last-row-styles},
-@code{table:use-first-column-styles}, @code{table:use-last-column-styles},
-@code{table:use-banding-rows-styles}, and
-@code{table:use-banding-column-styles} of the @code{<table:table>} element in
-the OpenDocument-v1.2 specification}
+Define a table style@footnote{See the attributes @samp{table:template-name},
+@samp{table:use-first-row-styles}, @samp{table:use-last-row-styles},
+@samp{table:use-first-column-styles}, @samp{table:use-last-column-styles},
+@samp{table:use-banding-rows-styles}, and 
@samp{table:use-banding-column-styles}
+of the @samp{<table:table>} element in the OpenDocument-v1.2 specification.}.
 
 @vindex org-odt-table-styles
-To define a table style, create an entry for the style in the variable
-@code{org-odt-table-styles} and specify the following:
+To define a table style, create an entry for the style in the
+variable @code{org-odt-table-styles} and specify the following:
 
-@itemize @minus
-@item the name of the table template created in step (1)
-@item the set of cell styles in that template that are to be activated
+@itemize
+@item
+the name of the table template created in step (1),
+@item
+the set of cell styles in that template that are to be activated.
 @end itemize
 
 For example, the entry below defines two different table styles
 @samp{TableWithHeaderRowAndColumn} and @samp{TableWithFirstRowandLastRow}
-based on the same template @samp{Custom}.  The styles achieve their intended
-effect by selectively activating the individual cell styles in that template.
+based on the same template @samp{Custom}.  The styles achieve their
+intended effect by selectively activating the individual cell
+styles in that template.
 
 @lisp
-(setq org-odt-table-styles
-      (append org-odt-table-styles
+(setq org-export-odt-table-styles
+      (append org-export-odt-table-styles
               '(("TableWithHeaderRowAndColumn" "Custom"
                  ((use-first-row-styles . t)
                   (use-first-column-styles . t)))
@@ -13589,194 +15347,199 @@ effect by selectively activating the individual 
cell styles in that template.
 @end lisp
 
 @item
-Associate a table with the table style
+Associate a table with the table style.
 
 To do this, specify the table style created in step (2) as part of
-the @code{ATTR_ODT} line as shown below.
+the @samp{ATTR_ODT} line as shown below.
 
 @example
-#+ATTR_ODT: :style "TableWithHeaderRowAndColumn"
+#+ATTR_ODT: :style TableWithHeaderRowAndColumn
 | Name  | Phone | Age |
 | Peter |  1234 |  17 |
 | Anna  |  4321 |  25 |
 @end example
 @end enumerate
 
-@node Validating OpenDocument XML
+@anchor{Validating OpenDocument XML}
 @subsubheading Validating OpenDocument XML
 
-Sometimes ODT format files may not open due to @file{.odt} file corruption.
-To verify if the @file{.odt} file is corrupt, validate it against the
-OpenDocument RELAX NG Compact Syntax---RNC---schema.  But first the
-@file{.odt} files have to be decompressed using @samp{zip}.  Note that
-@file{.odt} files are @samp{zip} archives: @inforef{File Archives,,emacs}.
-The contents of @file{.odt} files are in @file{.xml}.  For general help with
-validation---and schema-sensitive editing---of XML files:
-@inforef{Introduction,,nxml-mode}.
+Sometimes ODT format files may not open due to @samp{.odt} file corruption.
+To verify if such a file is corrupt, validate it against the
+OpenDocument Relax NG Compact (RNC) syntax schema.  But first the
+@samp{.odt} files have to be decompressed using @samp{zip}.  Note that 
@samp{.odt}
+files are ZIP archives: @ref{File Archives,,,emacs,}.  The contents of
+ODT files are in XML@.  For general help with validation---and
+schema-sensitive editing---of XML files: @ref{Introduction,,,nxml-mode,}.
 
-@vindex org-odt-schema-dir
-Customize @code{org-odt-schema-dir} to point to a directory with OpenDocument
-@file{.rnc} files and the needed schema-locating rules.  The ODT export
-back-end takes care of updating the @code{rng-schema-locating-files}.
+@vindex org-export-odt-schema-dir
+Customize @code{org-odt-schema-dir} to point to a directory with
+OpenDocument RNC files and the needed schema-locating rules.  The ODT
+export back-end takes care of updating the
+@code{rng-schema-locating-files}.
 
-@c end opendocument
+@node Org Export
+@section Org Export
 
-@node Org export
-@section Org export
 @cindex Org export
+@emph{org} export back-end creates a normalized version of the Org document
+in current buffer.  The exporter evaluates Babel code (see @ref{Evaluating 
Code Blocks}) and removes content specific to other back-ends.
 
-@code{org} export back-end creates a normalized version of the Org document
-in current buffer.  The exporter evaluates Babel code (@pxref{Evaluating code
-blocks}) and removes content specific to other back-ends.
-
+@anchor{Org export commands}
 @subheading Org export commands
 
-@table @kbd
-@orgcmd{C-c C-e O o,org-org-export-to-org}
-Export as an Org file with a @file{.org} extension.  For @file{myfile.org},
-Org exports to @file{myfile.org.org}, overwriting without warning.
-
-@orgcmd{C-c C-e O O,org-org-export-as-org}
-Export to a temporary buffer.  Does not create a file.
-@item C-c C-e O v
+@table @asis
+@item @kbd{C-c C-e O o} (@code{org-org-export-to-org})
+@kindex C-c C-e O o
+@findex org-org-export-to-org
+Export as an Org file with a @samp{.org} extension.  For @samp{myfile.org},
+Org exports to @samp{myfile.org.org}, overwriting without warning.
+
+@item @kbd{C-c C-e O v} (~~)
+@kindex C-c C-e O v
 Export to an Org file, then open it.
 @end table
 
-@node Texinfo export
-@section Texinfo export
-@cindex Texinfo export
-
-The @samp{texinfo} export back-end generates documents with Texinfo code that
-can compile to Info format.
+@node Texinfo Export
+@section Texinfo Export
 
 @menu
-* Texinfo export commands::     Invoking commands.
-* Texinfo specific export settings::  Setting the environment.
-* Texinfo file header::         Generating the header.
-* Texinfo title and copyright page::  Creating preamble pages.
-* Info directory file::     Installing a manual in Info file hierarchy.
-* Headings and sectioning structure::  Building document structure.
-* Indices::                     Creating indices.
-* Quoting Texinfo code::        Incorporating literal Texinfo code.
-* Plain lists in Texinfo export::  List attributes.
-* Tables in Texinfo export::    Table attributes.
-* Images in Texinfo export::    Image attributes.
-* Special blocks in Texinfo export::  Special block attributes.
-* A Texinfo example::           Processing Org to Texinfo.
+* Texinfo export commands::      Invoking commands.
+* Texinfo specific export settings:: Setting the environment.
+* Texinfo file header::          Generating the header.
+* Texinfo title and copyright page:: Creating preamble pages.
+* Info directory file::          Installing a manual in Info file hierarchy.
+* Headings and sectioning structure:: Building document structure.
+* Indices::                      Creating indices.
+* Quoting Texinfo code::         Incorporating literal Texinfo code.
+* Plain lists in Texinfo export:: List attributes.
+* Tables in Texinfo export::     Table attributes.
+* Images in Texinfo export::     Image attributes.
+* Quotations in Texinfo export:: Quote block attributes.
+* Special blocks in Texinfo export:: Special block attributes.
+* A Texinfo example::            Processing Org to Texinfo.
 @end menu
 
 @node Texinfo export commands
 @subsection Texinfo export commands
 
+@table @asis
+@item @kbd{C-c C-e i t} (@code{org-texinfo-export-to-texinfo})
+@kindex C-c C-e i t
+@findex org-texinfo-export-to-texinfo
+Export as a Texinfo file with @samp{.texi} extension.  For @samp{myfile.org},
+Org exports to @samp{myfile.texi}, overwriting without warning.
+
+@item @kbd{C-c C-e i i} (@code{org-texinfo-export-to-info})
+@kindex C-c C-e i i
+@findex org-texinfo-export-to-info
 @vindex org-texinfo-info-process
-@table @kbd
-@orgcmd{C-c C-e i t,org-texinfo-export-to-texinfo}
-Export as a Texinfo file with @file{.texi} extension.  For @file{myfile.org},
-Org exports to @file{myfile.texi}, overwriting without warning.
-@orgcmd{C-c C-e i i,org-texinfo-export-to-info}
-Export to Texinfo format first and then process it to make an Info file.  To
-generate other formats, such as DocBook, customize the
+Export to Texinfo format first and then process it to make an Info
+file.  To generate other formats, such as DocBook, customize the
 @code{org-texinfo-info-process} variable.
 @end table
 
 @node Texinfo specific export settings
 @subsection Texinfo specific export settings
-The Texinfo export back-end has several additional keywords for customizing
-Texinfo output.  Setting these keywords works similar to the general options
-(@pxref{Export settings}).
 
-@table @samp
+The Texinfo export back-end has several additional keywords for
+customizing Texinfo output.  Setting these keywords works similar to
+the general options (see @ref{Export Settings}).
 
-@item SUBTITLE
-@cindex @code{#+SUBTITLE} (Texinfo)
+@table @asis
+@item @samp{SUBTITLE}
+@cindex @samp{SUBTITLE}, keyword
 The document subtitle.
 
-@item SUBAUTHOR
-@cindex @code{#+SUBAUTHOR}
-The document subauthor.
+@item @samp{SUBAUTHOR}
+@cindex @samp{SUBAUTHOR}, keyword
+Additional authors for the document.
 
-@item TEXINFO_FILENAME
-@cindex @code{#+TEXINFO_FILENAME}
+@item @samp{TEXINFO_FILENAME}
+@cindex @samp{TEXINFO_FILENAME}, keyword
 The Texinfo filename.
 
-@item TEXINFO_CLASS
-@cindex @code{#+TEXINFO_CLASS}
+@item @samp{TEXINFO_CLASS}
+@cindex @samp{TEXINFO_CLASS}, keyword
 @vindex org-texinfo-default-class
-The default document class (@code{org-texinfo-default-class}), which must be
-a member of @code{org-texinfo-classes}.
+The default document class (@code{org-texinfo-default-class}), which must
+be a member of @code{org-texinfo-classes}.
 
-@item TEXINFO_HEADER
-@cindex @code{#+TEXINFO_HEADER}
+@item @samp{TEXINFO_HEADER}
+@cindex @samp{TEXINFO_HEADER}, keyword
 Arbitrary lines inserted at the end of the header.
 
-@item TEXINFO_POST_HEADER
-@cindex @code{#+TEXINFO_POST_HEADER}
+@item @samp{TEXINFO_POST_HEADER}
+@cindex @samp{TEXINFO_POST_HEADER}, keyword
 Arbitrary lines inserted after the end of the header.
 
-@item TEXINFO_DIR_CATEGORY
-@cindex @code{#+TEXINFO_DIR_CATEGORY}
+@item @samp{TEXINFO_DIR_CATEGORY}
+@cindex @samp{TEXINFO_DIR_CATEGORY}, keyword
 The directory category of the document.
 
-@item TEXINFO_DIR_TITLE
-@cindex @code{#+TEXINFO_DIR_TITLE}
+@item @samp{TEXINFO_DIR_TITLE}
+@cindex @samp{TEXINFO_DIR_TITLE}, keyword
 The directory title of the document.
 
-@item TEXINFO_DIR_DESC
-@cindex @code{#+TEXINFO_DIR_DESC}
+@item @samp{TEXINFO_DIR_DESC}
+@cindex @samp{TEXINFO_DIR_DESC}, keyword
 The directory description of the document.
 
-@item TEXINFO_PRINTED_TITLE
-@cindex @code{#+TEXINFO_PRINTED_TITLE}
+@item @samp{TEXINFO_PRINTED_TITLE}
+@cindex @samp{TEXINFO_PRINTED_TITLE}, keyword
 The printed title of the document.
 @end table
 
 @node Texinfo file header
 @subsection Texinfo file header
 
-@cindex @code{#+TEXINFO_FILENAME}
+@cindex @samp{TEXINFO_FILENAME}, keyword
 After creating the header for a Texinfo file, the Texinfo back-end
-automatically generates a name and destination path for the Info file.  To
-override this default with a more sensible path and name, specify the
-@code{#+TEXINFO_FILENAME} keyword.
+automatically generates a name and destination path for the Info file.
+To override this default with a more sensible path and name, specify
+the @samp{TEXINFO_FILENAME} keyword.
 
 @vindex org-texinfo-coding-system
-@vindex org-texinfo-classes
-@cindex @code{#+TEXINFO_HEADER}
-@cindex @code{#+TEXINFO_CLASS}
-Along with the output's file name, the Texinfo header also contains language
-details (@pxref{Export settings}) and encoding system as set in the
-@code{org-texinfo-coding-system} variable.  Insert @code{#+TEXINFO_HEADER}
+@cindex @samp{TEXINFO_HEADER}, keyword
+Along with the output's file name, the Texinfo header also contains
+language details (see @ref{Export Settings}) and encoding system as set in
+the @code{org-texinfo-coding-system} variable.  Insert @samp{TEXINFO_HEADER}
 keywords for each additional command in the header, for example:
-@@code@{@@synindex@}.
 
-Instead of repeatedly installing the same set of commands, define a class in
-@code{org-texinfo-classes} once, and then activate it in the document by
-setting the @code{#+TEXINFO_CLASS} keyword to that class.
+@example
+#+TEXINFO_HEADER: @@synindex
+@end example
+
+
+@cindex @samp{TEXINFO_CLASS}, keyword
+@vindex org-texinfo-classes
+Instead of repeatedly installing the same set of commands, define
+a class in @code{org-texinfo-classes} once, and then activate it in the
+document by setting the @samp{TEXINFO_CLASS} keyword to that class.
 
 @node Texinfo title and copyright page
 @subsection Texinfo title and copyright page
 
-@cindex @code{#+TEXINFO_PRINTED_TITLE}
+@cindex @samp{TEXINFO_PRINTED_TITLE}, keyword
 The default template for hard copy output has a title page with
-@code{#+TITLE} and @code{#+AUTHOR} (@pxref{Export settings}).  To replace the
-regular @code{#+TITLE} with something different for the printed version, use
-the @code{#+TEXINFO_PRINTED_TITLE} and @code{#+SUBTITLE} keywords.  Both
-expect raw Texinfo code for setting their values.
+@samp{TITLE} and @samp{AUTHOR} keywords (see @ref{Export Settings}).  To 
replace the
+regular title with something different for the printed version, use
+the @samp{TEXINFO_PRINTED_TITLE} and @samp{SUBTITLE} keywords.  Both expect raw
+Texinfo code for setting their values.
 
-@cindex @code{#+SUBAUTHOR}
-If one @code{#+AUTHOR} is not sufficient, add multiple @code{#+SUBAUTHOR}
+@cindex @samp{SUBAUTHOR}, keyword
+If one @samp{AUTHOR} line is not sufficient, add multiple @samp{SUBAUTHOR}
 keywords.  They have to be set in raw Texinfo code.
 
 @example
 #+AUTHOR: Jane Smith
 #+SUBAUTHOR: John Doe
-#+TEXINFO_PRINTED_TITLE: This Long Title@@inlinefmt@{tex,@@*@} Is Broken in 
@@TeX@{@}
+#+TEXINFO_PRINTED_TITLE: This Long Title@@@@inlinefmt@{tex,@@*@} Is Broken in 
@@TeX@{@}
 @end example
 
-@cindex property, @code{COPYING}
+@cindex @samp{COPYING}, property
 Copying material is defined in a dedicated headline with a non-@code{nil}
-@code{:COPYING:} property.  The back-end inserts the contents within a
-@code{@@copying} command at the beginning of the document.  The heading
+@samp{COPYING} property.  The back-end inserts the contents within
+a @samp{@@copying} command at the beginning of the document.  The heading
 itself does not appear in the structure of the document.
 
 Copyright information is printed on the back of the title page.
@@ -13789,26 +15552,24 @@ Copyright information is printed on the back of the 
title page.
 
   This is a short example of a complete Texinfo file, version 1.0.
 
-  Copyright \copy 2019 Free Software Foundation, Inc.
+  Copyright \copy 2016 Free Software Foundation, Inc.
 @end example
 
 @node Info directory file
 @subsection Info directory file
+
 @cindex @samp{dir} file, in Texinfo export
-@cindex Texinfo export, @samp{dir} file
 @cindex Info directory file, in Texinfo export
-@cindex Texinfo export, Info directory file
-@cindex @code{install-info} parameters, in Texinfo export
-@cindex Texinfo export, @code{install-info} parameters
-
-@cindex @code{#+TEXINFO_DIR_CATEGORY}
-@cindex @code{#+TEXINFO_DIR_TITLE}
-@cindex @code{#+TEXINFO_DIR_DESC}
-The end result of the Texinfo export process is the creation of an Info file.
-This Info file's metadata has variables for category, title, and description:
-@code{#+TEXINFO_DIR_CATEGORY}, @code{#+TEXINFO_DIR_TITLE}, and
-@code{#+TEXINFO_DIR_DESC} that establish where in the Info hierarchy the file
-fits.
+@cindex @code{install-info}, in Texinfo export
+
+@cindex @samp{TEXINFO_DIR_CATEGORY}, keyword
+@cindex @samp{TEXINFO_DIR_TITLE}, keyword
+@cindex @samp{TEXINFO_DIR_DESC}, keyword
+The end result of the Texinfo export process is the creation of an
+Info file.  This Info file's metadata has variables for category,
+title, and description: @samp{TEXINFO_DIR_CATEGORY}, @samp{TEXINFO_DIR_TITLE},
+and @samp{TEXINFO_DIR_DESC} keywords that establish where in the Info
+hierarchy the file fits.
 
 Here is an example that writes to the Info directory file:
 
@@ -13823,33 +15584,34 @@ Here is an example that writes to the Info directory 
file:
 
 @vindex org-texinfo-classes
 @vindex org-texinfo-default-class
-@cindex @code{#+TEXINFO_CLASS}
+@cindex @samp{TEXINFO_CLASS}, keyword
 The Texinfo export back-end uses a pre-defined scheme to convert Org
-headlines to an equivalent Texinfo structuring commands.  A scheme like this
-maps top-level headlines to numbered chapters tagged as @code{@@chapter} and
-lower-level headlines to unnumbered chapters tagged as @code{@@unnumbered}.
-To override such mappings to introduce @code{@@part} or other Texinfo
-structuring commands, define a new class in @code{org-texinfo-classes}.
-Activate the new class with the @code{#+TEXINFO_CLASS} keyword.  When no new
-class is defined and activated, the Texinfo export back-end defaults to the
+headlines to equivalent Texinfo structuring commands.  A scheme like
+this maps top-level headlines to numbered chapters tagged as
+@code{@@chapter} and lower-level headlines to unnumbered chapters tagged as
+@code{@@unnumbered}.  To override such mappings to introduce @code{@@part} or
+other Texinfo structuring commands, define a new class in
+@code{org-texinfo-classes}.  Activate the new class with the
+@samp{TEXINFO_CLASS} keyword.  When no new class is defined and activated,
+the Texinfo export back-end defaults to the
 @code{org-texinfo-default-class}.
 
-If an Org headline's level has no associated Texinfo structuring command, or
-is below a certain threshold (@pxref{Export settings}), then the Texinfo
-export back-end makes it into a list item.
+If an Org headline's level has no associated Texinfo structuring
+command, or is below a certain threshold (see @ref{Export Settings}), then
+the Texinfo export back-end makes it into a list item.
 
-@cindex property, @code{APPENDIX}
+@cindex @samp{APPENDIX}, property
 The Texinfo export back-end makes any headline with a non-@code{nil}
-@code{:APPENDIX:} property into an appendix.  This happens independent of the
-Org headline level or the @code{#+TEXINFO_CLASS}.
+@samp{APPENDIX} property into an appendix.  This happens independent of the
+Org headline level or the @samp{TEXINFO_CLASS} keyword.
 
-@cindex property, @code{DESCRIPTION}
-The Texinfo export back-end creates a menu entry after the Org headline for
-each regular sectioning structure.  To override this with a shorter menu
-entry, use the @code{:ALT_TITLE:} property (@pxref{Table of contents}).
-Texinfo menu entries also have an option for a longer @code{:DESCRIPTION:}
-property.  Here's an example that uses both to override the default menu
-entry:
+@cindex @samp{ALT_TITLE}, property
+@cindex @samp{DESCRIPTION}, property
+The Texinfo export back-end creates a menu entry after the Org
+headline for each regular sectioning structure.  To override this with
+a shorter menu entry, use the @samp{ALT_TITLE} property (see @ref{Table of 
Contents}).  Texinfo menu entries also have an option for a longer
+@samp{DESCRIPTION} property.  Here's an example that uses both to override
+the default menu entry:
 
 @example
 * Controlling Screen Display
@@ -13859,51 +15621,45 @@ entry:
   :END:
 @end example
 
-@cindex The Top node, in Texinfo export
-@cindex Texinfo export, Top node
-The text before the first headline belongs to the @samp{Top} node, i.e., the
-node in which a reader enters an Info manual.  As such, it is expected not to
-appear in printed output generated from the @file{.texi} file.  @inforef{The
-Top Node,,texinfo}, for more information.
+@cindex Top node, in Texinfo export
+The text before the first headline belongs to the @emph{Top} node, i.e.,
+the node in which a reader enters an Info manual.  As such, it is
+expected not to appear in printed output generated from the @samp{.texi}
+file.  See @ref{The Top Node,,,texinfo,}, for more information.
 
 @node Indices
 @subsection Indices
 
-@cindex @code{#+CINDEX}
+@cindex @samp{CINDEX}, keyword
 @cindex concept index, in Texinfo export
-@cindex Texinfo export, index, concept
-@cindex @code{#+FINDEX}
+@cindex @samp{FINDEX}, keyword
 @cindex function index, in Texinfo export
-@cindex Texinfo export, index, function
-@cindex @code{#+KINDEX}
+@cindex @samp{KINDEX}, keyword
 @cindex keystroke index, in Texinfo export
-@cindex Texinfo export, keystroke index
-@cindex @code{#+PINDEX}
+@cindex @samp{PINDEX}, keyword
 @cindex program index, in Texinfo export
-@cindex Texinfo export, program index
-@cindex @code{#+TINDEX}
+@cindex @samp{TINDEX}, keyword
 @cindex data type index, in Texinfo export
-@cindex Texinfo export, data type index
-@cindex @code{#+VINDEX}
+@cindex @samp{VINDEX}, keyword
 @cindex variable index, in Texinfo export
-@cindex Texinfo export, variable index
-The Texinfo export back-end recognizes these indexing keywords if used in the
-Org file: @code{#+CINDEX}, @code{#+FINDEX}, @code{#+KINDEX}, @code{#+PINDEX},
-@code{#+TINDEX}, and @code{#+VINDEX}.  Write their value as verbatim Texinfo
-code; in particular, @samp{@{}, @samp{@}} and @samp{@@} characters need to be
-escaped with @samp{@@} if they not belong to a Texinfo command.
+The Texinfo export back-end recognizes these indexing keywords if used
+in the Org file: @samp{CINDEX}, @samp{FINDEX}, @samp{KINDEX}, @samp{PINDEX}, 
@samp{TINDEX} and
+@samp{VINDEX}.  Write their value as verbatim Texinfo code; in particular,
+@samp{@{}, @samp{@}} and @samp{@@} characters need to be escaped with 
@samp{@@} if they do not
+belong to a Texinfo command.
 
 @example
 #+CINDEX: Defining indexing entries
 @end example
 
-@cindex property, @code{INDEX}
+
+@cindex @samp{INDEX}, property
 For the back-end to generate an index entry for a headline, set the
-@code{:INDEX:} property to @samp{cp} or @samp{vr}.  These abbreviations come
-from Texinfo that stand for concept index and variable index.  The Texinfo
+@samp{INDEX} property to @samp{cp} or @samp{vr}.  These abbreviations come from
+Texinfo that stand for concept index and variable index.  The Texinfo
 manual has abbreviations for all other kinds of indexes.  The back-end
-exports the headline as an unnumbered chapter or section command, and then
-inserts the index after its contents.
+exports the headline as an unnumbered chapter or section command, and
+then inserts the index after its contents.
 
 @example
 * Concept Index
@@ -13915,10 +15671,11 @@ inserts the index after its contents.
 @node Quoting Texinfo code
 @subsection Quoting Texinfo code
 
-Use any of the following three methods to insert or escape raw Texinfo code:
+Use any of the following three methods to insert or escape raw Texinfo
+code:
 
-@cindex @code{#+TEXINFO}
-@cindex @code{#+BEGIN_EXPORT texinfo}
+@cindex @samp{TEXINFO}, keyword
+@cindex @samp{BEGIN_EXPORT texinfo}
 @example
 Richard @@@@texinfo:@@sc@{@@@@Stallman@@@@texinfo:@}@@@@ commence' GNU.
 
@@ -13926,36 +15683,36 @@ Richard 
@@@@texinfo:@@sc@{@@@@Stallman@@@@texinfo:@}@@@@ commence' GNU.
 This paragraph is preceded by...
 
 #+BEGIN_EXPORT texinfo
-@@auindex Johnson, Mark
-@@auindex Lakoff, George
+  @@auindex Johnson, Mark
+  @@auindex Lakoff, George
 #+END_EXPORT
 @end example
 
 @node Plain lists in Texinfo export
 @subsection Plain lists in Texinfo export
-@cindex @code{#+ATTR_TEXINFO}, in plain lists
-@cindex Two-column tables, in Texinfo export
 
-@cindex @code{:table-type} attribute, in Texinfo export
-The Texinfo export back-end by default converts description lists in the Org
-file using the default command @code{@@table}, which results in a table with
-two columns.  To change this behavior, specify @code{:table-type} with
-@code{ftable} or @code{vtable} attributes.  For more information,
-@inforef{Two-column Tables,,texinfo}.
+@cindex @samp{ATTR_TEXINFO}, keyword
+@cindex two-column tables, in Texinfo export
+@cindex table-type, Texinfo attribute
+The Texinfo export back-end by default converts description lists in
+the Org file using the default command @samp{@@table}, which results in
+a table with two columns.  To change this behavior, set @samp{:table-type}
+attribute to either @samp{ftable} or @samp{vtable} value.  For more 
information,
+see @ref{Two-column Tables,,,texinfo,}.
 
 @vindex org-texinfo-table-default-markup
-@cindex @code{:indic} attribute, in Texinfo export
-The Texinfo export back-end by default also applies a text highlight based on
-the defaults stored in @code{org-texinfo-table-default-markup}.  To override
-the default highlight command, specify another one with the @code{:indic}
-attribute.
-
-@cindex Multiple entries in two-column tables, in Texinfo export
-@cindex @code{:sep} attribute, in Texinfo export
-Org syntax is limited to one entry per list item.  Nevertheless, the Texinfo
-export back-end can split that entry according to any text provided through
-the @code{:sep} attribute.  Each part then becomes a new entry in the first
-column of the table.
+@cindex indic, Texinfo attribute
+The Texinfo export back-end by default also applies a text highlight
+based on the defaults stored in @code{org-texinfo-table-default-markup}.
+To override the default highlight command, specify another one with
+the @samp{:indic} attribute.
+
+@cindex multiple items in Texinfo lists
+@cindex sep, Texinfo attribute
+Org syntax is limited to one entry per list item.  Nevertheless, the
+Texinfo export back-end can split that entry according to any text
+provided through the @samp{:sep} attribute.  Each part then becomes a new
+entry in the first column of the table.
 
 The following example illustrates all the attributes above:
 
@@ -13975,13 +15732,28 @@ This is the common text for variables foo and bar.
 @@end table
 @end example
 
+@cindex lettered lists, in Texinfo export
+@cindex enum, Texinfo attribute
+Ordered lists are numbered when exported to Texinfo format.  Such
+numbering obeys any counter (see @ref{Plain Lists}) in the first item of
+the list.  The @samp{:enum} attribute also let you start the list at
+a specific number, or switch to a lettered list, as illustrated here
+
+@example
+#+ATTR_TEXINFO: :enum A
+1. Alpha
+2. Bravo
+3. Charlie
+@end example
+
 @node Tables in Texinfo export
 @subsection Tables in Texinfo export
-@cindex @code{#+ATTR_TEXINFO}, in tables
 
-When exporting tables, the Texinfo export back-end uses the widest cell width
-in each column.  To override this and instead specify as fractions of line
-length, use the @code{:columns} attribute.  See example below.
+@cindex @samp{ATTR_TEXINFO}, keyword
+When exporting tables, the Texinfo export back-end uses the widest
+cell width in each column.  To override this and instead specify as
+fractions of line length, use the @samp{:columns} attribute.  See example
+below.
 
 @example
 #+ATTR_TEXINFO: :columns .5 .5
@@ -13990,32 +15762,60 @@ length, use the @code{:columns} attribute.  See 
example below.
 
 @node Images in Texinfo export
 @subsection Images in Texinfo export
-@cindex @code{#+ATTR_TEXINFO}, in images
 
-Insert a file link to the image in the Org file, and the Texinfo export
-back-end inserts the image.  These links must have the usual supported image
-extensions and no descriptions.  To scale the image, use @code{:width} and
-@code{:height} attributes.  For alternate text, use @code{:alt} and specify
-the text using Texinfo code, as shown in the example:
+@cindex @samp{ATTR_TEXINFO}, keyword
+Insert a file link to the image in the Org file, and the Texinfo
+export back-end inserts the image.  These links must have the usual
+supported image extensions and no descriptions.  To scale the image,
+use @samp{:width} and @samp{:height} attributes.  For alternate text, use 
@samp{:alt}
+and specify the text using Texinfo code, as shown in the example:
 
 @example
 #+ATTR_TEXINFO: :width 1in :alt Alternate @@i@{text@}
 [[ridt.pdf]]
 @end example
 
+@node Quotations in Texinfo export
+@subsection Quotations in Texinfo export
+
+@cindex @samp{ATTR_TEXINFO}, keyword
+You can write the text of a quotation within a quote block (see
+@ref{Paragraphs}).  You may also emphasize some text at the beginning of
+the quotation with the @samp{:tag} attribute.
+
+@example
+#+ATTR_TEXINFO: :tag Warning
+#+BEGIN_QUOTE
+Striking your thumb with a hammer may cause severe pain and discomfort.
+#+END_QUOTE
+@end example
+
+To specify the author of the quotation, use the @samp{:author} attribute.
+
+@example
+#+ATTR_TEXINFO: :author King Arthur
+#+BEGIN_QUOTE
+The Lady of the Lake, her arm clad in the purest shimmering samite,
+held aloft Excalibur from the bosom of the water, signifying by divine
+providence that I, Arthur, was to carry Excalibur. That is why I am
+your king.
+#+END_QUOTE
+@end example
+
 @node Special blocks in Texinfo export
-@subsection Special blocks
-@cindex @code{#+ATTR_TEXINFO}, in special blocks
+@subsection Special blocks in Texinfo export
+
+@cindex @samp{ATTR_TEXINFO}, keyword
 
-The Texinfo export back-end converts special blocks to commands with the same
-name.  It also adds any @code{:options} attributes to the end of the command,
-as shown in this example:
+The Texinfo export back-end converts special blocks to commands with
+the same name.  It also adds any @samp{:options} attributes to the end of
+the command, as shown in this example:
 
 @example
 #+ATTR_TEXINFO: :options org-org-export-to-org ...
-#+begin_defun
-A somewhat obsessive function.
-#+end_defun
+#+BEGIN_defun
+  A somewhat obsessive function name.
+#+END_defun
 @end example
 
 @noindent
@@ -14023,16 +15823,16 @@ becomes
 
 @example
 @@defun org-org-export-to-org ...
-A somewhat obsessive function.
+  A somewhat obsessive function name.
 @@end defun
 @end example
 
 @node A Texinfo example
 @subsection A Texinfo example
 
-Here is a more detailed example Org file.  See @ref{GNU Sample
-Texts,,,texinfo,GNU Texinfo Manual} for an equivalent example using Texinfo
-code.
+Here is a more detailed example Org file.  See
+@ref{GNU Sample Texts,,,texinfo,} for an equivalent example using
+Texinfo code.
 
 @example
 #+TITLE: GNU Sample @{@{@{version@}@}@}
@@ -14066,7 +15866,7 @@ This manual is for GNU Sample (version 
@{@{@{version@}@}@},
   This manual is for GNU Sample (version @{@{@{version@}@}@},
   @{@{@{updated@}@}@}), which is an example in the Texinfo documentation.
 
-  Copyright \copy 2019 Free Software Foundation, Inc.
+  Copyright \copy 2016 Free Software Foundation, Inc.
 
   #+BEGIN_QUOTE
   Permission is granted to copy, distribute and/or modify this
@@ -14091,7 +15891,7 @@ This manual is for GNU Sample (version 
@{@{@{version@}@}@},
   :APPENDIX: t
   :END:
 
-  #+TEXINFO: @@include fdl.texi
+  #+INCLUDE: fdl.org
 
 * Index
   :PROPERTIES:
@@ -14099,155 +15899,183 @@ This manual is for GNU Sample (version 
@{@{@{version@}@}@},
   :END:
 @end example
 
-@node iCalendar export
-@section iCalendar export
+@node iCalendar Export
+@section iCalendar Export
+
 @cindex iCalendar export
 
+A large part of Org mode's interoperability success is its ability to
+easily export to or import from external applications.  The iCalendar
+export back-end takes calendar data from Org files and exports to the
+standard iCalendar format.
+
 @vindex org-icalendar-include-todo
 @vindex org-icalendar-use-deadline
 @vindex org-icalendar-use-scheduled
+The iCalendar export back-end can also incorporate TODO entries based
+on the configuration of the @code{org-icalendar-include-todo} variable.
+The back-end exports plain timestamps as @samp{VEVENT}, TODO items as
+@samp{VTODO}, and also create events from deadlines that are in non-TODO
+items.  The back-end uses the deadlines and scheduling dates in Org
+TODO items for setting the start and due dates for the iCalendar TODO
+entry.  Consult the @code{org-icalendar-use-deadline} and
+@code{org-icalendar-use-scheduled} variables for more details.
+
 @vindex org-icalendar-categories
 @vindex org-icalendar-alarm-time
-A large part of Org mode's inter-operability success is its ability to easily
-export to or import from external applications.  The iCalendar export
-back-end takes calendar data from Org files and exports to the standard
-iCalendar format.
-
-The iCalendar export back-end can also incorporate TODO entries based on the
-configuration of the @code{org-icalendar-include-todo} variable.  The
-back-end exports plain timestamps as VEVENT, TODO items as VTODO, and also
-create events from deadlines that are in non-TODO items.  The back-end uses
-the deadlines and scheduling dates in Org TODO items for setting the start
-and due dates for the iCalendar TODO entry.  Consult the
-@code{org-icalendar-use-deadline} and @code{org-icalendar-use-scheduled}
-variables for more details.
-
-For tags on the headline, the iCalendar export back-end makes them into
-iCalendar categories.  To tweak the inheritance of tags and TODO states,
-configure the variable @code{org-icalendar-categories}.  To assign clock
-alarms based on time, configure the @code{org-icalendar-alarm-time} variable.
+For tags on the headline, the iCalendar export back-end makes them
+into iCalendar categories.  To tweak the inheritance of tags and TODO
+states, configure the variable @code{org-icalendar-categories}.  To assign
+clock alarms based on time, configure the @code{org-icalendar-alarm-time}
+variable.
 
 @vindex org-icalendar-store-UID
-@cindex property, @code{ID}
-The iCalendar format standard requires globally unique identifier---UID---for
-each entry.  The iCalendar export back-end creates UIDs during export.  To
-save a copy of the UID in the Org file set the variable
-@code{org-icalendar-store-UID}.  The back-end looks for the @code{:ID:}
-property of the entry for re-using the same UID for subsequent exports.
-
-Since a single Org entry can result in multiple iCalendar entries---as
-timestamp, deadline, scheduled item, or TODO item---Org adds prefixes to the
-UID, depending on which part of the Org entry triggered the creation of the
-iCalendar entry.  Prefixing ensures UIDs remains unique, yet enable
-synchronization programs trace the connections.
-
-@table @kbd
-@orgcmd{C-c C-e c f,org-icalendar-export-to-ics}
-Create iCalendar entries from the current Org buffer and store them in the
-same directory, using a file extension @file{.ics}.
-@orgcmd{C-c C-e c a, org-icalendar-export-agenda-files}
-@vindex org-agenda-files
-Create iCalendar entries from Org files in @code{org-agenda-files} and store
-in a separate iCalendar file for each Org file.
-@orgcmd{C-c C-e c c,org-icalendar-combine-agenda-files}
+@cindex @samp{ID}, property
+The iCalendar format standard requires globally unique identifier---or
+UID---for each entry.  The iCalendar export back-end creates UIDs
+during export.  To save a copy of the UID in the Org file set the
+variable @code{org-icalendar-store-UID}.  The back-end looks for the @samp{ID}
+property of the entry for re-using the same UID for subsequent
+exports.
+
+Since a single Org entry can result in multiple iCalendar
+entries---timestamp, deadline, scheduled item, or TODO item---Org adds
+prefixes to the UID, depending on which part of the Org entry
+triggered the creation of the iCalendar entry.  Prefixing ensures UIDs
+remains unique, yet enable synchronization programs trace the
+connections.
+
+@table @asis
+@item @kbd{C-c C-e c f} (@code{org-icalendar-export-to-ics})
+@kindex C-c C-e c f
+@findex org-icalendar-export-to-ics
+Create iCalendar entries from the current Org buffer and store them
+in the same directory, using a file extension @samp{.ics}.
+
+@item @kbd{C-c C-e c a} (@code{org-icalendar-export-agenda-files})
+@kindex C-c C-e c a
+@findex org-icalendar-export-agenda-files
+Create iCalendar entries from Org files in @code{org-agenda-files} and
+store in a separate iCalendar file for each Org file.
+
+@item @kbd{C-c C-e c c} (@code{org-icalendar-combine-agenda-files})
+@kindex C-c C-e c c
+@findex org-icalendar-combine-agenda-files
 @vindex org-icalendar-combined-agenda-file
-Create a combined iCalendar file from Org files in @code{org-agenda-files}
-and write it to @code{org-icalendar-combined-agenda-file} file name.
+Create a combined iCalendar file from Org files in
+@code{org-agenda-files} and write it to
+@code{org-icalendar-combined-agenda-file} file name.
 @end table
 
-@vindex org-use-property-inheritance
-@vindex org-icalendar-include-body
-@cindex property, @code{SUMMARY}
-@cindex property, @code{DESCRIPTION}
-@cindex property, @code{LOCATION}
-@cindex property, @code{TIMEZONE}
-The iCalendar export back-end includes @code{SUMMARY}, @code{DESCRIPTION},
-@code{LOCATION} and @code{TIMEZONE} properties from the Org entries when
-exporting.  To force the back-end to inherit the @code{LOCATION} and
-@code{TIMEZONE} properties, configure the @code{org-use-property-inheritance}
-variable.
+@cindex @samp{SUMMARY}, property
+@cindex @samp{DESCRIPTION}, property
+@cindex @samp{LOCATION}, property
+@cindex @samp{TIMEZONE}, property
+@cindex @samp{CLASS}, property
+The iCalendar export back-end includes @samp{SUMMARY}, @samp{DESCRIPTION},
+@samp{LOCATION}, @samp{TIMEZONE} and @samp{CLASS} properties from the Org 
entries
+when exporting.  To force the back-end to inherit the @samp{LOCATION},
+@samp{TIMEZONE} and @samp{CLASS} properties, configure the
+@code{org-use-property-inheritance} variable.
 
-When Org entries do not have @code{SUMMARY}, @code{DESCRIPTION} and
-@code{LOCATION} properties, the iCalendar export back-end derives the summary
-from the headline, and derives the description from the body of the Org item.
-The @code{org-icalendar-include-body} variable limits the maximum number of
-characters of the content are turned into its description.
+@vindex org-icalendar-include-body
+When Org entries do not have @samp{SUMMARY}, @samp{DESCRIPTION}, 
@samp{LOCATION} and
+@samp{CLASS} properties, the iCalendar export back-end derives the summary
+from the headline, and derives the description from the body of the
+Org item.  The @code{org-icalendar-include-body} variable limits the
+maximum number of characters of the content are turned into its
+description.
 
-The @code{TIMEZONE} property can be used to specify a per-entry time zone,
-and will be applied to any entry with timestamp information.  Time zones
-should be specified as per the IANA time zone database format, e.g.@:
-``Asia/Almaty''.  Alternately, the property value can be ``UTC'', to force
+The @samp{TIMEZONE} property can be used to specify a per-entry time zone,
+and is applied to any entry with timestamp information.  Time zones
+should be specified as per the IANA time zone database format, e.g.,
+@samp{Asia/Almaty}.  Alternately, the property value can be @samp{UTC}, to 
force
 UTC time for this entry only.
 
-Exporting to iCalendar format depends in large part on the capabilities of
-the destination application.  Some are more lenient than others.  Consult the
-Org mode FAQ for advice on specific applications.
+The @samp{CLASS} property can be used to specify a per-entry visibility
+class or access restrictions, and is applied to any entry with class
+information.  The iCalendar standard defines three visibility classes:
+@table @asis
+@item @samp{PUBLIC}
+The entry is publicly visible (this is the default).
+@item @samp{CONFIDENTIAL}
+Only a limited group of clients get access to the
+event.
+@item @samp{PRIVATE}
+The entry can be retrieved only by its owner.
+@end table
+The server should treat unknown class properties the same as
+@samp{PRIVATE}.
 
-@node Other built-in back-ends
-@section Other built-in back-ends
-@cindex export back-ends, built-in
-@vindex org-export-backends
+Exporting to iCalendar format depends in large part on the
+capabilities of the destination application.  Some are more lenient
+than others.  Consult the Org mode FAQ for advice on specific
+applications.
+
+@node Other Built-in Back-ends
+@section Other Built-in Back-ends
 
 Other export back-ends included with Org are:
 
 @itemize
-@item @file{ox-man.el}: export to a man page.
+@item
+@samp{ox-man.el}: Export to a man page.
 @end itemize
 
 To activate such back-ends, either customize @code{org-export-backends} or
-load directly with @code{(require 'ox-man)}.  On successful load, the
-back-end adds new keys in the export dispatcher (@pxref{The export
-dispatcher}).
+load directly with @samp{(require 'ox-man)}.  On successful load, the
+back-end adds new keys in the export dispatcher (see @ref{The Export 
Dispatcher}).
+
+Follow the comment section of such files, for example, @samp{ox-man.el},
+for usage and configuration details.
+
+@node Advanced Export Configuration
+@section Advanced Export Configuration
 
-Follow the comment section of such files, for example, @file{ox-man.el}, for
-usage and configuration details.
 
-@node Advanced configuration
-@section Advanced configuration
 
+@anchor{Hooks}
 @subheading Hooks
 
 @vindex org-export-before-processing-hook
 @vindex org-export-before-parsing-hook
-The export process executes two hooks before the actual exporting begins.
-The first hook, @code{org-export-before-processing-hook}, runs before any
-expansions of macros, Babel code, and include keywords in the buffer.  The
-second hook, @code{org-export-before-parsing-hook}, runs before the buffer is
-parsed.  Both hooks are specified as functions, see example below.  Their main
-use is for heavy duty structural modifications of the Org content.  For
-example, removing every headline in the buffer during export:
+The export process executes two hooks before the actual exporting
+begins.  The first hook, @code{org-export-before-processing-hook}, runs
+before any expansions of macros, Babel code, and include keywords in
+the buffer.  The second hook, @code{org-export-before-parsing-hook}, runs
+before the buffer is parsed.
+
+Functions added to these hooks are called with a single argument: the
+export back-end actually used, as a symbol.  You may use them for
+heavy duty structural modifications of the document.  For example, you
+can remove every headline in the buffer during export like this:
 
 @lisp
-@group
 (defun my-headline-removal (backend)
   "Remove all headlines in the current buffer.
 BACKEND is the export back-end being used, as a symbol."
   (org-map-entries
-   (lambda () (delete-region (point) (progn (forward-line) (point))))))
+   (lambda () (delete-region (point) (line-beginning-position 2)))))
 
 (add-hook 'org-export-before-parsing-hook 'my-headline-removal)
-@end group
 @end lisp
 
-Note that the hook function must have a mandatory argument that is a symbol
-for the back-end.
-
+@anchor{Filters}
 @subheading Filters
 
 @cindex Filters, exporting
-The Org export process relies on filters to process specific parts of
-conversion process.  Filters are just lists of functions to be applied to
-certain parts for a given back-end.  The output from the first function in
-the filter is passed on to the next function in the filter.  The final output
-is the output from the final function in the filter.
-
-The Org export process has many filter sets applicable to different types of
-objects, plain text, parse trees, export options, and final output formats.
-The filters are named after the element type or object type:
-@code{org-export-filter-TYPE-functions}, where @code{TYPE} is the type
-targeted by the filter.  Valid types are:
-
-@multitable @columnfractions .33 .33 .33
+Filters are lists of functions to be applied to certain parts for
+a given back-end.  The output from the first function in the filter is
+passed on to the next function in the filter.  The final output is the
+output from the final function in the filter.
+
+The Org export process has many filter sets applicable to different
+types of objects, plain text, parse trees, export options, and final
+output formats.  The filters are named after the element type or
+object type: @code{org-export-filter-TYPE-functions}, where @var{TYPE}
+is the type targeted by the filter.  Valid types are:
+
+@multitable @columnfractions 0.33 0.33 0.33
 @item body
 @tab bold
 @tab babel-call
@@ -14304,538 +16132,756 @@ targeted by the filter.  Valid types are:
 @tab verse-block
 @end multitable
 
-Here is an example filter that replaces non-breaking spaces @code{~} in the
-Org buffer with @code{_} for the @LaTeX{} back-end.
+Here is an example filter that replaces non-breaking spaces @code{ } in the
+Org buffer with @samp{~} for the @LaTeX{} back-end.
 
 @lisp
-@group
 (defun my-latex-filter-nobreaks (text backend info)
-  "Ensure \"_\" are properly handled in LaTeX export."
+  "Ensure \" \" are properly handled in LaTeX export."
   (when (org-export-derived-backend-p backend 'latex)
-        (replace-regexp-in-string "_" "~" text)))
+    (replace-regexp-in-string " " "~" text)))
 
 (add-to-list 'org-export-filter-plain-text-functions
              'my-latex-filter-nobreaks)
-@end group
 @end lisp
 
-A filter requires three arguments: the code to be transformed, the name of
-the back-end, and some optional information about the export process.  The
-third argument can be safely ignored.  Note the use of
-@code{org-export-derived-backend-p} predicate that tests for @code{latex}
-back-end or any other back-end, such as @code{beamer}, derived from
-@code{latex}.
+A filter requires three arguments: the code to be transformed, the
+name of the back-end, and some optional information about the export
+process.  The third argument can be safely ignored.  Note the use of
+@code{org-export-derived-backend-p} predicate that tests for @emph{latex}
+back-end or any other back-end, such as @emph{beamer}, derived from
+@emph{latex}.
 
+@anchor{Defining filters for individual files}
 @subheading Defining filters for individual files
 
-The Org export can filter not just for back-ends, but also for specific files
-through the @code{#+BIND} keyword.  Here is an example with two filters; one
-removes brackets from time stamps, and the other removes strike-through text.
-The filter functions are defined in a @samp{src} code block in the same Org
-file, which is a handy location for debugging.
+The Org export can filter not just for back-ends, but also for
+specific files through the @samp{BIND} keyword.  Here is an example with
+two filters; one removes brackets from time stamps, and the other
+removes strike-through text.  The filter functions are defined in
+a code block in the same Org file, which is a handy location for
+debugging.
 
 @example
 #+BIND: org-export-filter-timestamp-functions (tmp-f-timestamp)
 #+BIND: org-export-filter-strike-through-functions (tmp-f-strike-through)
-#+begin_src emacs-lisp :exports results :results none
+#+BEGIN_SRC emacs-lisp :exports results :results none
   (defun tmp-f-timestamp (s backend info)
     (replace-regexp-in-string "&[lg]t;\\|[][]" "" s))
   (defun tmp-f-strike-through (s backend info) "")
-#+end_src
+#+END_SRC
 @end example
 
+@anchor{Extending an existing back-end}
 @subheading Extending an existing back-end
 
-Some parts of the conversion process can be extended for certain elements so
-as to introduce a new or revised translation.  That is how the HTML export
-back-end was extended to handle Markdown format.  The extensions work
-seamlessly so any aspect of filtering not done by the extended back-end is
-handled by the original back-end.  Of all the export customization in Org,
-extending is very powerful as it operates at the parser level.
+Some parts of the conversion process can be extended for certain
+elements so as to introduce a new or revised translation.  That is how
+the HTML export back-end was extended to handle Markdown format.  The
+extensions work seamlessly so any aspect of filtering not done by the
+extended back-end is handled by the original back-end.  Of all the
+export customization in Org, extending is very powerful as it operates
+at the parser level.
 
-For this example, make the @code{ascii} back-end display the language used in
-a source code block.  Also make it display only when some attribute is
-non-@code{nil}, like the following:
+For this example, make the @emph{ascii} back-end display the language used
+in a source code block.  Also make it display only when some attribute
+is non-@code{nil}, like the following:
 
 @example
 #+ATTR_ASCII: :language t
 @end example
 
-Then extend @code{ascii} back-end with a custom @code{my-ascii} back-end.
+
+Then extend ASCII back-end with a custom ``my-ascii'' back-end.
 
 @lisp
-@group
 (defun my-ascii-src-block (src-block contents info)
   "Transcode a SRC-BLOCK element from Org to ASCII.
 CONTENTS is nil.  INFO is a plist used as a communication
 channel."
   (if (not (org-export-read-attribute :attr_ascii src-block :language))
-    (org-export-with-backend 'ascii src-block contents info)
-  (concat
-   (format ",--[ %s ]--\n%s`----"
-           (org-element-property :language src-block)
-           (replace-regexp-in-string
-            "^" "| "
-            (org-element-normalize-string
-             (org-export-format-code-default src-block info)))))))
+      (org-export-with-backend 'ascii src-block contents info)
+    (concat
+     (format ",--[ %s ]--\n%s`----"
+             (org-element-property :language src-block)
+             (replace-regexp-in-string
+              "^" "| "
+              (org-element-normalize-string
+               (org-export-format-code-default src-block info)))))))
 
 (org-export-define-derived-backend 'my-ascii 'ascii
   :translate-alist '((src-block . my-ascii-src-block)))
-@end group
 @end lisp
 
 The @code{my-ascii-src-block} function looks at the attribute above the
-current element.  If not true, hands over to @code{ascii} back-end.  If true,
-which it is in this example, it creates a box around the code and leaves room
-for the inserting a string for language.  The last form creates the new
-back-end that springs to action only when translating @code{src-block} type
-elements.
+current element.  If not true, hands over to @emph{ascii} back-end.  If
+true, which it is in this example, it creates a box around the code
+and leaves room for the inserting a string for language.  The last
+form creates the new back-end that springs to action only when
+translating @code{src-block} type elements.
 
-To use the newly defined back-end, call the following from an Org buffer:
+To use the newly defined back-end, evaluate the following from an Org
+buffer:
 
-@smalllisp
+@lisp
 (org-export-to-buffer 'my-ascii "*Org MY-ASCII Export*")
-@end smalllisp
+@end lisp
 
-Further steps to consider would be an interactive function, self-installing
-an item in the export dispatcher menu, and other user-friendly improvements.
+Further steps to consider would be an interactive function,
+self-installing an item in the export dispatcher menu, and other
+user-friendly improvements.
 
-@node Export in foreign buffers
-@section Export in foreign buffers
+@node Export in Foreign Buffers
+@section Export in Foreign Buffers
 
 The export back-ends in Org often include commands to convert selected
 regions.  A convenient feature of this in-place conversion is that the
-exported output replaces the original source.  Here are such functions:
+exported output replaces the original source.  Here are such
+functions:
 
-@table @code
-@item org-html-convert-region-to-html
-Convert the selected region into HTML.
-@item org-latex-convert-region-to-latex
+@table @asis
+@item @code{org-ascii-convert-region-to-ascii}
+@findex org-ascii-convert-region-to-ascii
+Convert the selected region into ASCII@.
+
+@item @code{org-ascii-convert-region-to-utf8}
+@findex org-ascii-convert-region-to-utf8
+Convert the selected region into UTF-8.
+
+@item @code{org-html-convert-region-to-html}
+@findex org-html-convert-region-to-html
+Convert the selected region into HTML@.
+
+@item @code{org-latex-convert-region-to-latex}
+@findex org-latex-convert-region-to-latex
 Convert the selected region into @LaTeX{}.
-@item org-texinfo-convert-region-to-texinfo
-Convert the selected region into @code{Texinfo}.
-@item org-md-convert-region-to-md
-Convert the selected region into @code{MarkDown}.
-@end table
 
-In-place conversions are particularly handy for quick conversion of tables
-and lists in foreign buffers.  For example, turn on the minor mode @code{M-x
-orgstruct-mode} in an HTML buffer, then use the convenient Org keyboard
-commands to create a list, select it, and covert it to HTML with @code{M-x
-org-html-convert-region-to-html @key{RET}}.
+@item @code{org-texinfo-convert-region-to-texinfo}
+@findex org-texinfo-convert-region-to-texinfo
+Convert the selected region into Texinfo.
+
+@item @code{org-md-convert-region-to-md}
+@findex org-md-convert-region-to-md
+Convert the selected region into Markdown.
+@end table
 
+In-place conversions are particularly handy for quick conversion of
+tables and lists in foreign buffers.  For example, in an HTML buffer,
+write a list in Org syntax, select it, and convert it to HTML with
+@kbd{M-x org-html-convert-region-to-html}.
 
 @node Publishing
 @chapter Publishing
+
 @cindex publishing
 
-Org includes a publishing management system that allows you to configure
-automatic HTML conversion of @emph{projects} composed of interlinked org
-files.  You can also configure Org to automatically upload your exported HTML
-pages and related attachments, such as images and source code files, to a web
-server.
+Org includes a publishing management system that allows you to
+configure automatic HTML conversion of @emph{projects} composed of
+interlinked Org files.  You can also configure Org to automatically
+upload your exported HTML pages and related attachments, such as
+images and source code files, to a web server.
 
-You can also use Org to convert files into PDF, or even combine HTML and PDF
-conversion so that files are available in both formats on the server.
+You can also use Org to convert files into PDF, or even combine HTML
+and PDF conversion so that files are available in both formats on the
+server.
 
 Publishing has been contributed to Org by David O'Toole.
 
 @menu
-* Configuration::               Defining projects
-* Uploading files::             How to get files up on the server
-* Sample configuration::        Example projects
-* Triggering publication::      Publication commands
+* Configuration::                Defining projects.
+* Uploading Files::              How to get files up on the server.
+* Sample Configuration::         Example projects.
+* Triggering Publication::       Publication commands.
 @end menu
 
 @node Configuration
 @section Configuration
 
-Publishing needs significant configuration to specify files, destination
-and many other properties of a project.
+Publishing needs significant configuration to specify files,
+destination and many other properties of a project.
 
 @menu
-* Project alist::               The central configuration variable
-* Sources and destinations::    From here to there
-* Selecting files::             What files are part of the project?
-* Publishing action::           Setting the function doing the publishing
-* Publishing options::          Tweaking HTML/@LaTeX{} export
-* Publishing links::            Which links keep working after publishing?
-* Sitemap::                     Generating a list of all pages
-* Generating an index::         An index that reaches across pages
+* Project alist::                The central configuration variable.
+* Sources and destinations::     From here to there.
+* Selecting files::              What files are part of the project?
+* Publishing action::            Setting the function doing the publishing.
+* Publishing options::           Tweaking HTML/@LaTeX{} export.
+* Publishing links::             Which links keep working after publishing?
+* Site map::                     Generating a list of all pages.
+* Generating an index::          An index that reaches across pages.
 @end menu
 
 @node Project alist
 @subsection The variable @code{org-publish-project-alist}
-@cindex @code{org-publish-project-alist}
+
 @cindex projects, for publishing
 
 @vindex org-publish-project-alist
-Publishing is configured almost entirely through setting the value of one
-variable, called @code{org-publish-project-alist}.  Each element of the list
-configures one project, and may be in one of the two following forms:
+Publishing is configured almost entirely through setting the value of
+one variable, called @code{org-publish-project-alist}.  Each element of the
+list configures one project, and may be in one of the two following
+forms:
 
 @lisp
-   ("project-name" :property value :property value ...)
-     @r{i.e., a well-formed property list with alternating keys and values}
-@r{or}
-   ("project-name" :components ("project-name" "project-name" ...))
+("project-name" :property value :property value ...)
+@end lisp
 
+@noindent
+i.e., a well-formed property list with alternating keys and values,
+or:
+
+@lisp
+("project-name" :components ("project-name" "project-name" ...))
 @end lisp
 
-In both cases, projects are configured by specifying property values.  A
-project defines the set of files that will be published, as well as the
-publishing configuration to use when publishing those files.  When a project
-takes the second form listed above, the individual members of the
-@code{:components} property are taken to be sub-projects, which group
-together files requiring different publishing options.  When you publish such
-a ``meta-project'', all the components will also be published, in the
-sequence given.
+In both cases, projects are configured by specifying property values.
+A project defines the set of files that are to be published, as well
+as the publishing configuration to use when publishing those files.
+When a project takes the second form listed above, the individual
+members of the @code{:components} property are taken to be sub-projects,
+which group together files requiring different publishing options.
+When you publish such a ``meta-project'', all the components are also
+published, in the sequence given.
 
 @node Sources and destinations
 @subsection Sources and destinations for files
+
 @cindex directories, for publishing
 
 Most properties are optional, but some should always be set.  In
-particular, Org needs to know where to look for source files,
-and where to put published files.
+particular, Org needs to know where to look for source files, and
+where to put published files.
 
-@multitable @columnfractions 0.3 0.7
+@table @asis
 @item @code{:base-directory}
-@tab Directory containing publishing source files
+Directory containing publishing source files.
+
 @item @code{:publishing-directory}
-@tab Directory where output files will be published.  You can directly
-publish to a web server using a file name syntax appropriate for
-the Emacs @file{tramp} package.  Or you can publish to a local directory and
-use external tools to upload your website (@pxref{Uploading files}).
+Directory where output files are published.  You can directly
+publish to a webserver using a file name syntax appropriate for the
+Emacs tramp package.  Or you can publish to a local directory and
+use external tools to upload your website (see @ref{Uploading Files}).
+
 @item @code{:preparation-function}
-@tab Function or list of functions to be called before starting the
-publishing process, for example, to run @code{make} for updating files to be
-published.  Each preparation function is called with a single argument, the
-project property list.
+Function or list of functions to be called before starting the
+publishing process, for example, to run @samp{make} for updating files to
+be published.  Each preparation function is called with a single
+argument, the project property list.
+
 @item @code{:completion-function}
-@tab Function or list of functions called after finishing the publishing
-process, for example, to change permissions of the resulting files.  Each
-completion function is called with a single argument, the project property
-list.
-@end multitable
-@noindent
+Function or list of functions called after finishing the publishing
+process, for example, to change permissions of the resulting files.
+Each completion function is called with a single argument, the
+project property list.
+@end table
 
 @node Selecting files
 @subsection Selecting files
+
 @cindex files, selecting for publishing
 
-By default, all files with extension @file{.org} in the base directory
-are considered part of the project.  This can be modified by setting the
-properties
-@multitable @columnfractions 0.25 0.75
+By default, all files with extension @samp{.org} in the base directory are
+considered part of the project.  This can be modified by setting the
+following properties
+
+@table @asis
 @item @code{:base-extension}
-@tab Extension (without the dot!) of source files.  This actually is a
-regular expression.  Set this to the symbol @code{any} if you want to get all
-files in @code{:base-directory}, even without extension.
+Extension---without the dot---of source files.  This actually is
+a regular expression.  Set this to the symbol @code{any} if you want to
+get all files in @code{:base-directory}, even without extension.
 
 @item @code{:exclude}
-@tab Regular expression to match file names that should not be
-published, even though they have been selected on the basis of their
-extension.
+Regular expression to match file names that should not be published,
+even though they have been selected on the basis of their extension.
 
 @item @code{:include}
-@tab List of files to be included regardless of @code{:base-extension}
-and @code{:exclude}.
+List of files to be included regardless of @code{:base-extension} and
+@code{:exclude}.
 
 @item @code{:recursive}
-@tab non-@code{nil} means, check base-directory recursively for files to 
publish.
-@end multitable
+Non-@code{nil} means, check base-directory recursively for files to
+publish.
+@end table
 
 @node Publishing action
 @subsection Publishing action
+
 @cindex action, for publishing
 
-Publishing means that a file is copied to the destination directory and
-possibly transformed in the process.  The default transformation is to export
-Org files as HTML files, and this is done by the function
-@code{org-html-publish-to-html}, which calls the HTML exporter (@pxref{HTML
-export}).  But you also can publish your content as PDF files using
-@code{org-latex-publish-to-pdf} or as @code{ascii}, @code{Texinfo}, etc.,
-using the corresponding functions.
-
-If you want to publish the Org file as an @code{.org} file but with the
-@i{archived}, @i{commented} and @i{tag-excluded} trees removed, use the
-function @code{org-org-publish-to-org}.  This will produce @file{file.org}
-and put it in the publishing directory.  If you want a htmlized version of
-this file, set the parameter @code{:htmlized-source} to @code{t}, it will
-produce @file{file.org.html} in the publishing directory@footnote{If the
-publishing directory is the same than the source directory, @file{file.org}
-will be exported as @file{file.org.org}, so probably don't want to do this.}.
-
-Other files like images only need to be copied to the publishing destination.
-For this you can use @code{org-publish-attachment}.  For non-org files, you
-always need to specify the publishing function:
+Publishing means that a file is copied to the destination directory
+and possibly transformed in the process.  The default transformation
+is to export Org files as HTML files, and this is done by the function
+@code{org-publish-org-to-html} which calls the HTML exporter (see @ref{HTML 
Export}).  But you can also publish your content as PDF files using
+@code{org-publish-org-to-pdf}, or as ASCII, Texinfo, etc., using the
+corresponding functions.
+
+If you want to publish the Org file as an @samp{.org} file but with
+@emph{archived}, @emph{commented}, and @emph{tag-excluded} trees removed, use
+@code{org-publish-org-to-org}.  This produces @samp{file.org} and put it in the
+publishing directory.  If you want a htmlized version of this file,
+set the parameter @code{:htmlized-source} to @code{t}.  It produces
+@samp{file.org.html} in the publishing directory@footnote{If the publishing 
directory is the same as the source
+directory, @samp{file.org} is exported as @samp{file.org.org}, so you probably
+do not want to do this.}.
+
+Other files like images only need to be copied to the publishing
+destination; for this you can use @code{org-publish-attachment}.  For
+non-Org files, you always need to specify the publishing function:
 
-@multitable @columnfractions 0.3 0.7
+@table @asis
 @item @code{:publishing-function}
-@tab Function executing the publication of a file.  This may also be a
-list of functions, which will all be called in turn.
+Function executing the publication of a file.  This may also be
+a list of functions, which are all called in turn.
+
 @item @code{:htmlized-source}
-@tab non-@code{nil} means, publish htmlized source.
-@end multitable
+Non-@code{nil} means, publish htmlized source.
+@end table
 
-The function must accept three arguments: a property list containing at least
-a @code{:publishing-directory} property, the name of the file to be published
-and the path to the publishing directory of the output file.  It should take
-the specified file, make the necessary transformation (if any) and place the
-result into the destination folder.
+The function must accept three arguments: a property list containing
+at least a @code{:publishing-directory} property, the name of the file to
+be published, and the path to the publishing directory of the output
+file.  It should take the specified file, make the necessary
+transformation, if any, and place the result into the destination
+folder.
 
 @node Publishing options
 @subsection Options for the exporters
+
 @cindex options, for publishing
+@cindex publishing options
 
-The property list can be used to set export options during the publishing
-process.  In most cases, these properties correspond to user variables in
-Org.  While some properties are available for all export back-ends, most of
-them are back-end specific.  The following sections list properties along
-with the variable they belong to.  See the documentation string of these
-options for details.
+The property list can be used to set many export options for the HTML
+and @LaTeX{} exporters.  In most cases, these properties correspond to
+user variables in Org.  The table below lists these properties along
+with the variable they belong to.  See the documentation string for
+the respective variable for details.
 
 @vindex org-publish-project-alist
 When a property is given a value in @code{org-publish-project-alist}, its
-setting overrides the value of the corresponding user variable (if any)
-during publishing.  Options set within a file (@pxref{Export settings}),
-however, override everything.
+setting overrides the value of the corresponding user variable, if
+any, during publishing.  Options set within a file (see @ref{Export 
Settings}), however, override everything.
 
+@anchor{Generic properties}
 @subsubheading Generic properties
 
-@multitable {@code{:with-sub-superscript}}  
{@code{org-export-with-sub-superscripts}}
-@item @code{:archived-trees}        @tab @code{org-export-with-archived-trees}
-@item @code{:exclude-tags}          @tab @code{org-export-exclude-tags}
-@item @code{:headline-levels}       @tab @code{org-export-headline-levels}
-@item @code{:language}              @tab @code{org-export-default-language}
-@item @code{:preserve-breaks}       @tab @code{org-export-preserve-breaks}
-@item @code{:section-numbers}       @tab @code{org-export-with-section-numbers}
-@item @code{:select-tags}           @tab @code{org-export-select-tags}
-@item @code{:with-author}           @tab @code{org-export-with-author}
-@item @code{:with-broken-links}     @tab @code{org-export-with-broken-links}
-@item @code{:with-clocks}           @tab @code{org-export-with-clocks}
-@item @code{:with-creator}          @tab @code{org-export-with-creator}
-@item @code{:with-date}             @tab @code{org-export-with-date}
-@item @code{:with-drawers}          @tab @code{org-export-with-drawers}
-@item @code{:with-email}            @tab @code{org-export-with-email}
-@item @code{:with-emphasize}        @tab @code{org-export-with-emphasize}
-@item @code{:with-fixed-width}      @tab @code{org-export-with-fixed-width}
-@item @code{:with-footnotes}        @tab @code{org-export-with-footnotes}
-@item @code{:with-latex}            @tab @code{org-export-with-latex}
-@item @code{:with-planning}         @tab @code{org-export-with-planning}
-@item @code{:with-priority}         @tab @code{org-export-with-priority}
-@item @code{:with-properties}       @tab @code{org-export-with-properties}
-@item @code{:with-special-strings}  @tab @code{org-export-with-special-strings}
-@item @code{:with-sub-superscript}  @tab 
@code{org-export-with-sub-superscripts}
-@item @code{:with-tables}           @tab @code{org-export-with-tables}
-@item @code{:with-tags}             @tab @code{org-export-with-tags}
-@item @code{:with-tasks}            @tab @code{org-export-with-tasks}
-@item @code{:with-timestamps}       @tab @code{org-export-with-timestamps}
-@item @code{:with-title}            @tab @code{org-export-with-title}
-@item @code{:with-toc}              @tab @code{org-export-with-toc}
-@item @code{:with-todo-keywords}    @tab @code{org-export-with-todo-keywords}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:archived-trees}
+@tab @code{org-export-with-archived-trees}
+@item @code{:exclude-tags}
+@tab @code{org-export-exclude-tags}
+@item @code{:headline-levels}
+@tab @code{org-export-headline-levels}
+@item @code{:language}
+@tab @code{org-export-default-language}
+@item @code{:preserve-breaks}
+@tab @code{org-export-preserve-breaks}
+@item @code{:section-numbers}
+@tab @code{org-export-with-section-numbers}
+@item @code{:select-tags}
+@tab @code{org-export-select-tags}
+@item @code{:with-author}
+@tab @code{org-export-with-author}
+@item @code{:with-broken-links}
+@tab @code{org-export-with-broken-links}
+@item @code{:with-clocks}
+@tab @code{org-export-with-clocks}
+@item @code{:with-creator}
+@tab @code{org-export-with-creator}
+@item @code{:with-date}
+@tab @code{org-export-with-date}
+@item @code{:with-drawers}
+@tab @code{org-export-with-drawers}
+@item @code{:with-email}
+@tab @code{org-export-with-email}
+@item @code{:with-emphasize}
+@tab @code{org-export-with-emphasize}
+@item @code{:with-fixed-width}
+@tab @code{org-export-with-fixed-width}
+@item @code{:with-footnotes}
+@tab @code{org-export-with-footnotes}
+@item @code{:with-latex}
+@tab @code{org-export-with-latex}
+@item @code{:with-planning}
+@tab @code{org-export-with-planning}
+@item @code{:with-priority}
+@tab @code{org-export-with-priority}
+@item @code{:with-properties}
+@tab @code{org-export-with-properties}
+@item @code{:with-special-strings}
+@tab @code{org-export-with-special-strings}
+@item @code{:with-sub-superscript}
+@tab @code{org-export-with-sub-superscripts}
+@item @code{:with-tables}
+@tab @code{org-export-with-tables}
+@item @code{:with-tags}
+@tab @code{org-export-with-tags}
+@item @code{:with-tasks}
+@tab @code{org-export-with-tasks}
+@item @code{:with-timestamps}
+@tab @code{org-export-with-timestamps}
+@item @code{:with-title}
+@tab @code{org-export-with-title}
+@item @code{:with-toc}
+@tab @code{org-export-with-toc}
+@item @code{:with-todo-keywords}
+@tab @code{org-export-with-todo-keywords}
 @end multitable
 
+@anchor{ASCII specific properties}
 @subsubheading ASCII specific properties
 
-@multitable {@code{:ascii-table-keep-all-vertical-lines}} 
{@code{org-ascii-table-keep-all-vertical-lines}}
-@item @code{:ascii-bullets}                       @tab @code{org-ascii-bullets}
-@item @code{:ascii-caption-above}                 @tab 
@code{org-ascii-caption-above}
-@item @code{:ascii-charset}                       @tab @code{org-ascii-charset}
-@item @code{:ascii-global-margin}                 @tab 
@code{org-ascii-global-margin}
-@item @code{:ascii-format-drawer-function}        @tab 
@code{org-ascii-format-drawer-function}
-@item @code{:ascii-format-inlinetask-function}    @tab 
@code{org-ascii-format-inlinetask-function}
-@item @code{:ascii-headline-spacing}              @tab 
@code{org-ascii-headline-spacing}
-@item @code{:ascii-indented-line-width}           @tab 
@code{org-ascii-indented-line-width}
-@item @code{:ascii-inlinetask-width}              @tab 
@code{org-ascii-inlinetask-width}
-@item @code{:ascii-inner-margin}                  @tab 
@code{org-ascii-inner-margin}
-@item @code{:ascii-links-to-notes}                @tab 
@code{org-ascii-links-to-notes}
-@item @code{:ascii-list-margin}                   @tab 
@code{org-ascii-list-margin}
-@item @code{:ascii-paragraph-spacing}             @tab 
@code{org-ascii-paragraph-spacing}
-@item @code{:ascii-quote-margin}                  @tab 
@code{org-ascii-quote-margin}
-@item @code{:ascii-table-keep-all-vertical-lines} @tab 
@code{org-ascii-table-keep-all-vertical-lines}
-@item @code{:ascii-table-use-ascii-art}           @tab 
@code{org-ascii-table-use-ascii-art}
-@item @code{:ascii-table-widen-columns}           @tab 
@code{org-ascii-table-widen-columns}
-@item @code{:ascii-text-width}                    @tab 
@code{org-ascii-text-width}
-@item @code{:ascii-underline}                     @tab 
@code{org-ascii-underline}
-@item @code{:ascii-verbatim-format}               @tab 
@code{org-ascii-verbatim-format}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:ascii-bullets}
+@tab @code{org-ascii-bullets}
+@item @code{:ascii-caption-above}
+@tab @code{org-ascii-caption-above}
+@item @code{:ascii-charset}
+@tab @code{org-ascii-charset}
+@item @code{:ascii-global-margin}
+@tab @code{org-ascii-global-margin}
+@item @code{:ascii-format-drawer-function}
+@tab @code{org-ascii-format-drawer-function}
+@item @code{:ascii-format-inlinetask-function}
+@tab @code{org-ascii-format-inlinetask-function}
+@item @code{:ascii-headline-spacing}
+@tab @code{org-ascii-headline-spacing}
+@item @code{:ascii-indented-line-width}
+@tab @code{org-ascii-indented-line-width}
+@item @code{:ascii-inlinetask-width}
+@tab @code{org-ascii-inlinetask-width}
+@item @code{:ascii-inner-margin}
+@tab @code{org-ascii-inner-margin}
+@item @code{:ascii-links-to-notes}
+@tab @code{org-ascii-links-to-notes}
+@item @code{:ascii-list-margin}
+@tab @code{org-ascii-list-margin}
+@item @code{:ascii-paragraph-spacing}
+@tab @code{org-ascii-paragraph-spacing}
+@item @code{:ascii-quote-margin}
+@tab @code{org-ascii-quote-margin}
+@item @code{:ascii-table-keep-all-vertical-lines}
+@tab @code{org-ascii-table-keep-all-vertical-lines}
+@item @code{:ascii-table-use-ascii-art}
+@tab @code{org-ascii-table-use-ascii-art}
+@item @code{:ascii-table-widen-columns}
+@tab @code{org-ascii-table-widen-columns}
+@item @code{:ascii-text-width}
+@tab @code{org-ascii-text-width}
+@item @code{:ascii-underline}
+@tab @code{org-ascii-underline}
+@item @code{:ascii-verbatim-format}
+@tab @code{org-ascii-verbatim-format}
 @end multitable
 
+@anchor{Beamer specific properties}
 @subsubheading Beamer specific properties
 
-@multitable {@code{:beamer-frame-default-options}} 
{@code{org-beamer-frame-default-options}}
-@item @code{:beamer-theme}                 @tab @code{org-beamer-theme}
-@item @code{:beamer-column-view-format}    @tab 
@code{org-beamer-column-view-format}
-@item @code{:beamer-environments-extra}    @tab 
@code{org-beamer-environments-extra}
-@item @code{:beamer-frame-default-options} @tab 
@code{org-beamer-frame-default-options}
-@item @code{:beamer-outline-frame-options} @tab 
@code{org-beamer-outline-frame-options}
-@item @code{:beamer-outline-frame-title}   @tab 
@code{org-beamer-outline-frame-title}
-@item @code{:beamer-subtitle-format}       @tab 
@code{org-beamer-subtitle-format}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:beamer-theme}
+@tab @code{org-beamer-theme}
+@item @code{:beamer-column-view-format}
+@tab @code{org-beamer-column-view-format}
+@item @code{:beamer-environments-extra}
+@tab @code{org-beamer-environments-extra}
+@item @code{:beamer-frame-default-options}
+@tab @code{org-beamer-frame-default-options}
+@item @code{:beamer-outline-frame-options}
+@tab @code{org-beamer-outline-frame-options}
+@item @code{:beamer-outline-frame-title}
+@tab @code{org-beamer-outline-frame-title}
+@item @code{:beamer-subtitle-format}
+@tab @code{org-beamer-subtitle-format}
 @end multitable
 
+@anchor{HTML specific properties}
 @subsubheading HTML specific properties
 
-@multitable {@code{:html-table-use-header-tags-for-first-column}} 
{@code{org-html-table-use-header-tags-for-first-column}}
-@item @code{:html-allow-name-attribute-in-anchors} @tab 
@code{org-html-allow-name-attribute-in-anchors}
-@item @code{:html-checkbox-type}              @tab 
@code{org-html-checkbox-type}
-@item @code{:html-container}                  @tab 
@code{org-html-container-element}
-@item @code{:html-divs}                       @tab @code{org-html-divs}
-@item @code{:html-doctype}                    @tab @code{org-html-doctype}
-@item @code{:html-extension}                  @tab @code{org-html-extension}
-@item @code{:html-footnote-format}            @tab 
@code{org-html-footnote-format}
-@item @code{:html-footnote-separator}         @tab 
@code{org-html-footnote-separator}
-@item @code{:html-footnotes-section}          @tab 
@code{org-html-footnotes-section}
-@item @code{:html-format-drawer-function}     @tab 
@code{org-html-format-drawer-function}
-@item @code{:html-format-headline-function}   @tab 
@code{org-html-format-headline-function}
-@item @code{:html-format-inlinetask-function} @tab 
@code{org-html-format-inlinetask-function}
-@item @code{:html-head-extra}                 @tab @code{org-html-head-extra}
-@item @code{:html-head-include-default-style} @tab 
@code{org-html-head-include-default-style}
-@item @code{:html-head-include-scripts}       @tab 
@code{org-html-head-include-scripts}
-@item @code{:html-head}                       @tab @code{org-html-head}
-@item @code{:html-home/up-format}             @tab 
@code{org-html-home/up-format}
-@item @code{:html-html5-fancy}                @tab @code{org-html-html5-fancy}
-@item @code{:html-indent}                     @tab @code{org-html-indent}
-@item @code{:html-infojs-options}             @tab 
@code{org-html-infojs-options}
-@item @code{:html-infojs-template}            @tab 
@code{org-html-infojs-template}
-@item @code{:html-inline-image-rules}         @tab 
@code{org-html-inline-image-rules}
-@item @code{:html-inline-images}              @tab 
@code{org-html-inline-images}
-@item @code{:html-link-home}                  @tab @code{org-html-link-home}
-@item @code{:html-link-org-files-as-html}     @tab 
@code{org-html-link-org-files-as-html}
-@item @code{:html-link-up}                    @tab @code{org-html-link-up}
-@item @code{:html-link-use-abs-url}           @tab 
@code{org-html-link-use-abs-url}
-@item @code{:html-mathjax-options}            @tab 
@code{org-html-mathjax-options}
-@item @code{:html-mathjax-template}           @tab 
@code{org-html-mathjax-template}
-@item @code{:html-metadata-timestamp-format}  @tab 
@code{org-html-metadata-timestamp-format}
-@item @code{:html-postamble-format}           @tab 
@code{org-html-postamble-format}
-@item @code{:html-postamble}                  @tab @code{org-html-postamble}
-@item @code{:html-preamble-format}            @tab 
@code{org-html-preamble-format}
-@item @code{:html-preamble}                   @tab @code{org-html-preamble}
-@item @code{:html-table-align-individual-fields} @tab 
@code{org-html-table-align-individual-fields}
-@item @code{:html-table-attributes}           @tab 
@code{org-html-table-default-attributes}
-@item @code{:html-table-caption-above}        @tab 
@code{org-html-table-caption-above}
-@item @code{:html-table-data-tags}            @tab 
@code{org-html-table-data-tags}
-@item @code{:html-table-header-tags}          @tab 
@code{org-html-table-header-tags}
-@item @code{:html-table-row-tags}             @tab 
@code{org-html-table-row-tags}
-@item @code{:html-table-use-header-tags-for-first-column} @tab 
@code{org-html-table-use-header-tags-for-first-column}
-@item @code{:html-tag-class-prefix}           @tab 
@code{org-html-tag-class-prefix}
-@item @code{:html-text-markup-alist}          @tab 
@code{org-html-text-markup-alist}
-@item @code{:html-todo-kwd-class-prefix}      @tab 
@code{org-html-todo-kwd-class-prefix}
-@item @code{:html-toplevel-hlevel}            @tab 
@code{org-html-toplevel-hlevel}
-@item @code{:html-use-infojs}                 @tab @code{org-html-use-infojs}
-@item @code{:html-validation-link}            @tab 
@code{org-html-validation-link}
-@item @code{:html-viewport}                   @tab @code{org-html-viewport}
-@item @code{:html-xml-declaration}            @tab 
@code{org-html-xml-declaration}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:html-allow-name-attribute-in-anchors}
+@tab @code{org-html-allow-name-attribute-in-anchors}
+@item @code{:html-checkbox-type}
+@tab @code{org-html-checkbox-type}
+@item @code{:html-container}
+@tab @code{org-html-container-element}
+@item @code{:html-divs}
+@tab @code{org-html-divs}
+@item @code{:html-doctype}
+@tab @code{org-html-doctype}
+@item @code{:html-extension}
+@tab @code{org-html-extension}
+@item @code{:html-footnote-format}
+@tab @code{org-html-footnote-format}
+@item @code{:html-footnote-separator}
+@tab @code{org-html-footnote-separator}
+@item @code{:html-footnotes-section}
+@tab @code{org-html-footnotes-section}
+@item @code{:html-format-drawer-function}
+@tab @code{org-html-format-drawer-function}
+@item @code{:html-format-headline-function}
+@tab @code{org-html-format-headline-function}
+@item @code{:html-format-inlinetask-function}
+@tab @code{org-html-format-inlinetask-function}
+@item @code{:html-head-extra}
+@tab @code{org-html-head-extra}
+@item @code{:html-head-include-default-style}
+@tab @code{org-html-head-include-default-style}
+@item @code{:html-head-include-scripts}
+@tab @code{org-html-head-include-scripts}
+@item @code{:html-head}
+@tab @code{org-html-head}
+@item @code{:html-home/up-format}
+@tab @code{org-html-home/up-format}
+@item @code{:html-html5-fancy}
+@tab @code{org-html-html5-fancy}
+@item @code{:html-indent}
+@tab @code{org-html-indent}
+@item @code{:html-infojs-options}
+@tab @code{org-html-infojs-options}
+@item @code{:html-infojs-template}
+@tab @code{org-html-infojs-template}
+@item @code{:html-inline-image-rules}
+@tab @code{org-html-inline-image-rules}
+@item @code{:html-inline-images}
+@tab @code{org-html-inline-images}
+@item @code{:html-link-home}
+@tab @code{org-html-link-home}
+@item @code{:html-link-org-files-as-html}
+@tab @code{org-html-link-org-files-as-html}
+@item @code{:html-link-up}
+@tab @code{org-html-link-up}
+@item @code{:html-link-use-abs-url}
+@tab @code{org-html-link-use-abs-url}
+@item @code{:html-mathjax-options}
+@tab @code{org-html-mathjax-options}
+@item @code{:html-mathjax-template}
+@tab @code{org-html-mathjax-template}
+@item @code{:html-metadata-timestamp-format}
+@tab @code{org-html-metadata-timestamp-format}
+@item @code{:html-postamble-format}
+@tab @code{org-html-postamble-format}
+@item @code{:html-postamble}
+@tab @code{org-html-postamble}
+@item @code{:html-preamble-format}
+@tab @code{org-html-preamble-format}
+@item @code{:html-preamble}
+@tab @code{org-html-preamble}
+@item @code{:html-self-link-headlines}
+@tab @code{org-html-self-link-headlines}
+@item @code{:html-table-align-individual-field}
+@tab @code{de@{org-html-table-align-individual-fields}
+@item @code{:html-table-attributes}
+@tab @code{org-html-table-default-attributes}
+@item @code{:html-table-caption-above}
+@tab @code{org-html-table-caption-above}
+@item @code{:html-table-data-tags}
+@tab @code{org-html-table-data-tags}
+@item @code{:html-table-header-tags}
+@tab @code{org-html-table-header-tags}
+@item @code{:html-table-row-tags}
+@tab @code{org-html-table-row-tags}
+@item @code{:html-table-use-header-tags-for-first-column}
+@tab @code{org-html-table-use-header-tags-for-first-column}
+@item @code{:html-tag-class-prefix}
+@tab @code{org-html-tag-class-prefix}
+@item @code{:html-text-markup-alist}
+@tab @code{org-html-text-markup-alist}
+@item @code{:html-todo-kwd-class-prefix}
+@tab @code{org-html-todo-kwd-class-prefix}
+@item @code{:html-toplevel-hlevel}
+@tab @code{org-html-toplevel-hlevel}
+@item @code{:html-use-infojs}
+@tab @code{org-html-use-infojs}
+@item @code{:html-validation-link}
+@tab @code{org-html-validation-link}
+@item @code{:html-viewport}
+@tab @code{org-html-viewport}
+@item @code{:html-wrap-src-lines}
+@tab @code{org-html-wrap-src-lines}
+@item @code{:html-xml-declaration}
+@tab @code{org-html-xml-declaration}
 @end multitable
 
+@anchor{@LaTeX{} specific properties}
 @subsubheading @LaTeX{} specific properties
 
-@multitable {@code{:latex-link-with-unknown-path-format}} 
{@code{org-latex-link-with-unknown-path-format}}
-@item @code{:latex-active-timestamp-format}    @tab 
@code{org-latex-active-timestamp-format}
-@item @code{:latex-caption-above}              @tab 
@code{org-latex-caption-above}
-@item @code{:latex-classes}                    @tab @code{org-latex-classes}
-@item @code{:latex-class}                      @tab 
@code{org-latex-default-class}
-@item @code{:latex-compiler}                   @tab @code{org-latex-compiler}
-@item @code{:latex-default-figure-position}    @tab 
@code{org-latex-default-figure-position}
-@item @code{:latex-default-table-environment}  @tab 
@code{org-latex-default-table-environment}
-@item @code{:latex-default-table-mode}         @tab 
@code{org-latex-default-table-mode}
-@item @code{:latex-diary-timestamp-format}     @tab 
@code{org-latex-diary-timestamp-format}
-@item @code{:latex-footnote-defined-format}    @tab 
@code{org-latex-footnote-defined-format}
-@item @code{:latex-footnote-separator}         @tab 
@code{org-latex-footnote-separator}
-@item @code{:latex-format-drawer-function}     @tab 
@code{org-latex-format-drawer-function}
-@item @code{:latex-format-headline-function}   @tab 
@code{org-latex-format-headline-function}
-@item @code{:latex-format-inlinetask-function} @tab 
@code{org-latex-format-inlinetask-function}
-@item @code{:latex-hyperref-template}          @tab 
@code{org-latex-hyperref-template}
-@item @code{:latex-image-default-height}       @tab 
@code{org-latex-image-default-height}
-@item @code{:latex-image-default-option}       @tab 
@code{org-latex-image-default-option}
-@item @code{:latex-image-default-width}        @tab 
@code{org-latex-image-default-width}
-@item @code{:latex-images-centered}            @tab 
@code{org-latex-images-centered}
-@item @code{:latex-inactive-timestamp-format}  @tab 
@code{org-latex-inactive-timestamp-format}
-@item @code{:latex-inline-image-rules}         @tab 
@code{org-latex-inline-image-rules}
-@item @code{:latex-link-with-unknown-path-format} @tab 
@code{org-latex-link-with-unknown-path-format}
-@item @code{:latex-listings-langs}             @tab 
@code{org-latex-listings-langs}
-@item @code{:latex-listings-options}           @tab 
@code{org-latex-listings-options}
-@item @code{:latex-listings}                   @tab @code{org-latex-listings}
-@item @code{:latex-minted-langs}               @tab 
@code{org-latex-minted-langs}
-@item @code{:latex-minted-options}             @tab 
@code{org-latex-minted-options}
-@item @code{:latex-prefer-user-labels}         @tab 
@code{org-latex-prefer-user-labels}
-@item @code{:latex-subtitle-format}            @tab 
@code{org-latex-subtitle-format}
-@item @code{:latex-subtitle-separate}          @tab 
@code{org-latex-subtitle-separate}
-@item @code{:latex-table-scientific-notation}  @tab 
@code{org-latex-table-scientific-notation}
-@item @code{:latex-tables-booktabs}            @tab 
@code{org-latex-tables-booktabs}
-@item @code{:latex-tables-centered}            @tab 
@code{org-latex-tables-centered}
-@item @code{:latex-text-markup-alist}          @tab 
@code{org-latex-text-markup-alist}
-@item @code{:latex-title-command}              @tab 
@code{org-latex-title-command}
-@item @code{:latex-toc-command}                @tab 
@code{org-latex-toc-command}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:latex-active-timestamp-format}
+@tab @code{org-latex-active-timestamp-format}
+@item @code{:latex-caption-above}
+@tab @code{org-latex-caption-above}
+@item @code{:latex-classes}
+@tab @code{org-latex-classes}
+@item @code{:latex-class}
+@tab @code{org-latex-default-class}
+@item @code{:latex-compiler}
+@tab @code{org-latex-compiler}
+@item @code{:latex-default-figure-position}
+@tab @code{org-latex-default-figure-position}
+@item @code{:latex-default-table-environment}
+@tab @code{org-latex-default-table-environment}
+@item @code{:latex-default-table-mode}
+@tab @code{org-latex-default-table-mode}
+@item @code{:latex-diary-timestamp-format}
+@tab @code{org-latex-diary-timestamp-format}
+@item @code{:latex-footnote-defined-format}
+@tab @code{org-latex-footnote-defined-format}
+@item @code{:latex-footnote-separator}
+@tab @code{org-latex-footnote-separator}
+@item @code{:latex-format-drawer-function}
+@tab @code{org-latex-format-drawer-function}
+@item @code{:latex-format-headline-function}
+@tab @code{org-latex-format-headline-function}
+@item @code{:latex-format-inlinetask-function}
+@tab @code{org-latex-format-inlinetask-function}
+@item @code{:latex-hyperref-template}
+@tab @code{org-latex-hyperref-template}
+@item @code{:latex-image-default-height}
+@tab @code{org-latex-image-default-height}
+@item @code{:latex-image-default-option}
+@tab @code{org-latex-image-default-option}
+@item @code{:latex-image-default-width}
+@tab @code{org-latex-image-default-width}
+@item @code{:latex-images-centered}
+@tab @code{org-latex-images-centered}
+@item @code{:latex-inactive-timestamp-format}
+@tab @code{org-latex-inactive-timestamp-format}
+@item @code{:latex-inline-image-rules}
+@tab @code{org-latex-inline-image-rules}
+@item @code{:latex-link-with-unknown-path-format}
+@tab @code{org-latex-link-with-unknown-path-format}
+@item @code{:latex-listings-langs}
+@tab @code{org-latex-listings-langs}
+@item @code{:latex-listings-options}
+@tab @code{org-latex-listings-options}
+@item @code{:latex-listings}
+@tab @code{org-latex-listings}
+@item @code{:latex-minted-langs}
+@tab @code{org-latex-minted-langs}
+@item @code{:latex-minted-options}
+@tab @code{org-latex-minted-options}
+@item @code{:latex-prefer-user-labels}
+@tab @code{org-latex-prefer-user-labels}
+@item @code{:latex-subtitle-format}
+@tab @code{org-latex-subtitle-format}
+@item @code{:latex-subtitle-separate}
+@tab @code{org-latex-subtitle-separate}
+@item @code{:latex-table-scientific-notation}
+@tab @code{org-latex-table-scientific-notation}
+@item @code{:latex-tables-booktabs}
+@tab @code{org-latex-tables-booktabs}
+@item @code{:latex-tables-centered}
+@tab @code{org-latex-tables-centered}
+@item @code{:latex-text-markup-alist}
+@tab @code{org-latex-text-markup-alist}
+@item @code{:latex-title-command}
+@tab @code{org-latex-title-command}
+@item @code{:latex-toc-command}
+@tab @code{org-latex-toc-command}
 @end multitable
 
+@anchor{Markdown specific properties}
 @subsubheading Markdown specific properties
 
-@multitable {@code{:md-footnotes-section}} {@code{org-md-footnotes-section}}
-@item @code{:md-footnote-format} @tab @code{org-md-footnote-format}
-@item @code{:md-footnotes-section} @tab @code{org-md-footnotes-section}
-@item @code{:md-headline-style} @tab @code{org-md-headline-style}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:md-footnote-format}
+@tab @code{org-md-footnote-format}
+@item @code{:md-footnotes-section}
+@tab @code{org-md-footnotes-section}
+@item @code{:md-headline-style}
+@tab @code{org-md-headline-style}
 @end multitable
 
+@anchor{ODT specific properties}
 @subsubheading ODT specific properties
 
-@multitable {@code{:odt-format-inlinetask-function}} 
{@code{org-odt-format-inlinetask-function}}
-@item @code{:odt-content-template-file}      @tab 
@code{org-odt-content-template-file}
-@item @code{:odt-display-outline-level}      @tab 
@code{org-odt-display-outline-level}
-@item @code{:odt-fontify-srcblocks}          @tab 
@code{org-odt-fontify-srcblocks}
-@item @code{:odt-format-drawer-function}     @tab 
@code{org-odt-format-drawer-function}
-@item @code{:odt-format-headline-function}   @tab 
@code{org-odt-format-headline-function}
-@item @code{:odt-format-inlinetask-function} @tab 
@code{org-odt-format-inlinetask-function}
-@item @code{:odt-inline-formula-rules}       @tab 
@code{org-odt-inline-formula-rules}
-@item @code{:odt-inline-image-rules}         @tab 
@code{org-odt-inline-image-rules}
-@item @code{:odt-pixels-per-inch}            @tab 
@code{org-odt-pixels-per-inch}
-@item @code{:odt-styles-file}                @tab @code{org-odt-styles-file}
-@item @code{:odt-table-styles}               @tab @code{org-odt-table-styles}
-@item @code{:odt-use-date-fields}            @tab 
@code{org-odt-use-date-fields}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:odt-content-template-file}
+@tab @code{org-odt-content-template-file}
+@item @code{:odt-display-outline-level}
+@tab @code{org-odt-display-outline-level}
+@item @code{:odt-fontify-srcblocks}
+@tab @code{org-odt-fontify-srcblocks}
+@item @code{:odt-format-drawer-function}
+@tab @code{org-odt-format-drawer-function}
+@item @code{:odt-format-headline-function}
+@tab @code{org-odt-format-headline-function}
+@item @code{:odt-format-inlinetask-function}
+@tab @code{org-odt-format-inlinetask-function}
+@item @code{:odt-inline-formula-rules}
+@tab @code{org-odt-inline-formula-rules}
+@item @code{:odt-inline-image-rules}
+@tab @code{org-odt-inline-image-rules}
+@item @code{:odt-pixels-per-inch}
+@tab @code{org-odt-pixels-per-inch}
+@item @code{:odt-styles-file}
+@tab @code{org-odt-styles-file}
+@item @code{:odt-table-styles}
+@tab @code{org-odt-table-styles}
+@item @code{:odt-use-date-fields}
+@tab @code{org-odt-use-date-fields}
 @end multitable
 
+@anchor{Texinfo specific properties}
 @subsubheading Texinfo specific properties
 
-@multitable {@code{:texinfo-link-with-unknown-path-format}} 
{@code{org-texinfo-link-with-unknown-path-format}}
-@item @code{:texinfo-active-timestamp-format}    @tab 
@code{org-texinfo-active-timestamp-format}
-@item @code{:texinfo-classes}                    @tab 
@code{org-texinfo-classes}
-@item @code{:texinfo-class}                      @tab 
@code{org-texinfo-default-class}
-@item @code{:texinfo-table-default-markup}       @tab 
@code{org-texinfo-table-default-markup}
-@item @code{:texinfo-diary-timestamp-format}     @tab 
@code{org-texinfo-diary-timestamp-format}
-@item @code{:texinfo-filename}                   @tab 
@code{org-texinfo-filename}
-@item @code{:texinfo-format-drawer-function}     @tab 
@code{org-texinfo-format-drawer-function}
-@item @code{:texinfo-format-headline-function}   @tab 
@code{org-texinfo-format-headline-function}
-@item @code{:texinfo-format-inlinetask-function} @tab 
@code{org-texinfo-format-inlinetask-function}
-@item @code{:texinfo-inactive-timestamp-format}  @tab 
@code{org-texinfo-inactive-timestamp-format}
-@item @code{:texinfo-link-with-unknown-path-format} @tab 
@code{org-texinfo-link-with-unknown-path-format}
-@item @code{:texinfo-node-description-column}    @tab 
@code{org-texinfo-node-description-column}
-@item @code{:texinfo-table-scientific-notation}  @tab 
@code{org-texinfo-table-scientific-notation}
-@item @code{:texinfo-tables-verbatim}            @tab 
@code{org-texinfo-tables-verbatim}
-@item @code{:texinfo-text-markup-alist}          @tab 
@code{org-texinfo-text-markup-alist}
+@multitable {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{:texinfo-active-timestamp-format}
+@tab @code{org-texinfo-active-timestamp-format}
+@item @code{:texinfo-classes}
+@tab @code{org-texinfo-classes}
+@item @code{:texinfo-class}
+@tab @code{org-texinfo-default-class}
+@item @code{:texinfo-table-default-markup}
+@tab @code{org-texinfo-table-default-markup}
+@item @code{:texinfo-diary-timestamp-format}
+@tab @code{org-texinfo-diary-timestamp-format}
+@item @code{:texinfo-filename}
+@tab @code{org-texinfo-filename}
+@item @code{:texinfo-format-drawer-function}
+@tab @code{org-texinfo-format-drawer-function}
+@item @code{:texinfo-format-headline-function}
+@tab @code{org-texinfo-format-headline-function}
+@item @code{:texinfo-format-inlinetask-function}
+@tab @code{org-texinfo-format-inlinetask-function}
+@item @code{:texinfo-inactive-timestamp-format}
+@tab @code{org-texinfo-inactive-timestamp-format}
+@item @code{:texinfo-link-with-unknown-path-format}
+@tab @code{org-texinfo-link-with-unknown-path-format}
+@item @code{:texinfo-node-description-column}
+@tab @code{org-texinfo-node-description-column}
+@item @code{:texinfo-table-scientific-notation}
+@tab @code{org-texinfo-table-scientific-notation}
+@item @code{:texinfo-tables-verbatim}
+@tab @code{org-texinfo-tables-verbatim}
+@item @code{:texinfo-text-markup-alist}
+@tab @code{org-texinfo-text-markup-alist}
 @end multitable
 
 @node Publishing links
-@subsection Links between published files
+@subsection Publishing links
+
 @cindex links, publishing
 
-To create a link from one Org file to another, you would use something like
-@samp{[[file:foo.org][The foo]]} or simply @samp{file:foo.org}
-(@pxref{External links}).  When published, this link becomes a link to
-@file{foo.html}.  You can thus interlink the pages of your ``org web''
-project and the links will work as expected when you publish them to HTML.
-If you also publish the Org source file and want to link to it, use an
-@code{http:} link instead of a @code{file:} link, because @code{file:} links
-are converted to link to the corresponding @file{html} file.
+To create a link from one Org file to another, you would use something
+like @samp{[[file:foo.org][The foo]]} or simply @samp{[[file:foo.org]]} (see 
@ref{External Links}).  When
+published, this link becomes a link to @samp{foo.html}.  You can thus
+interlink the pages of your ``Org web'' project and the links will work
+as expected when you publish them to HTML@.  If you also publish the
+Org source file and want to link to it, use an @samp{http} link instead of
+a @samp{file:} link, because @samp{file} links are converted to link to the
+corresponding @samp{.html} file.
 
-You may also link to related files, such as images.  Provided you are careful
-with relative file names, and provided you have also configured Org to upload
-the related files, these links will work too.  See @ref{Complex example}, for
-an example of this usage.
+You may also link to related files, such as images.  Provided you are
+careful with relative file names, and provided you have also
+configured Org to upload the related files, these links will work too.
+See @ref{Complex example}, for an example of this
+usage.
 
-Eventually, links between published documents can contain some search options
-(@pxref{Search options}), which will be resolved to the appropriate location
-in the linked file.  For example, once published to HTML, the following links
-all point to a dedicated anchor in @file{foo.html}.
+Eventually, links between published documents can contain some search
+options (see @ref{Search Options}), which will be resolved to
+the appropriate location in the linked file.  For example, once
+published to HTML, the following links all point to a dedicated anchor
+in @samp{foo.html}.
 
 @example
 [[file:foo.org::*heading]]
@@ -14843,144 +16889,160 @@ all point to a dedicated anchor in @file{foo.html}.
 [[file:foo.org::target]]
 @end example
 
-@node Sitemap
+@node Site map
 @subsection Generating a sitemap
+
 @cindex sitemap, of published pages
 
 The following properties may be used to control publishing of
 a map of files for a given project.
 
-@multitable @columnfractions 0.35 0.65
+@table @asis
 @item @code{:auto-sitemap}
-@tab When non-@code{nil}, publish a sitemap during 
@code{org-publish-current-project}
-or @code{org-publish-all}.
+When non-@code{nil}, publish a sitemap during
+@code{org-publish-current-project} or @code{org-publish-all}.
 
 @item @code{:sitemap-filename}
-@tab Filename for output of sitemap.  Defaults to @file{sitemap.org} (which
-becomes @file{sitemap.html}).
+Filename for output of sitemap.  Defaults to @samp{sitemap.org}, which
+becomes @samp{sitemap.html}.
 
 @item @code{:sitemap-title}
-@tab Title of sitemap page.  Defaults to name of file.
+Title of sitemap page.  Defaults to name of file.
 
 @item @code{:sitemap-format-entry}
-@tab With this option one can tell how a site-map entry is formatted in the
-site-map.  It is a function called with three arguments: the file or
-directory name relative to base directory of the project, the site-map style
-and the current project.  It is expected to return a string.  Default value
-turns file names into links and use document titles as descriptions.  For
-specific formatting needs, one can use @code{org-publish-find-date},
-@code{org-publish-find-title} and @code{org-publish-find-property}, to
-retrieve additional information about published documents.
+@findex org-publish-find-date
+@findex org-publish-find-property
+@findex org-publish-find-title
+With this option one can tell how a site-map entry is formatted in
+the site-map.  It is a function called with three arguments: the
+file or directory name relative to base directory of the project,
+the site-map style and the current project.  It is expected to
+return a string.  Default value turns file names into links and use
+document titles as descriptions.  For specific formatting needs, one
+can use @code{org-publish-find-date}, @code{org-publish-find-title} and
+@code{org-publish-find-property}, to retrieve additional information
+about published documents.
 
 @item @code{:sitemap-function}
-@tab Plug-in function to use for generation of the sitemap.  It is called
-with two arguments: the title of the site-map and a representation of the
-files and directories involved in the project as a radio list (@pxref{Radio
-lists}).  The latter can further be transformed using
-@code{org-list-to-generic}, @code{org-list-to-subtree} and alike.  Default
-value generates a plain list of links to all files in the project.
+Plug-in function to use for generation of the sitemap.  It is called
+with two arguments: the title of the site-map and a representation
+of the files and directories involved in the project as a nested
+list, which can further be transformed using @code{org-list-to-generic},
+@code{org-list-to-subtree} and alike.  Default value generates a plain
+list of links to all files in the project.
 
 @item @code{:sitemap-sort-folders}
-@tab Where folders should appear in the sitemap.  Set this to @code{first}
+Where folders should appear in the sitemap.  Set this to @code{first}
 (default) or @code{last} to display folders first or last, respectively.
-When set to @code{ignore}, folders are ignored altogether.  Any other value
-will mix files and folders.  This variable has no effect when site-map style
-is @code{tree}.
+When set to @code{ignore}, folders are ignored altogether.  Any other
+value mixes files and folders.  This variable has no effect when
+site-map style is @code{tree}.
 
 @item @code{:sitemap-sort-files}
-@tab How the files are sorted in the site map.  Set this to
+How the files are sorted in the site map.  Set this to
 @code{alphabetically} (default), @code{chronologically} or
 @code{anti-chronologically}.  @code{chronologically} sorts the files with
-older date first while @code{anti-chronologically} sorts the files with newer
-date first.  @code{alphabetically} sorts the files alphabetically.  The date of
-a file is retrieved with @code{org-publish-find-date}.
+older date first while @code{anti-chronologically} sorts the files with
+newer date first.  @code{alphabetically} sorts the files alphabetically.
+The date of a file is retrieved with @code{org-publish-find-date}.
 
 @item @code{:sitemap-ignore-case}
-@tab Should sorting be case-sensitive?  Default @code{nil}.
+Should sorting be case-sensitive?  Default @code{nil}.
+
+@item @code{:sitemap-file-entry-format}
+With this option one can tell how a sitemap's entry is formatted in
+the sitemap.  This is a format string with some escape sequences:
+@code{%t} stands for the title of the file, @code{%a} stands for the author of
+the file and @code{%d} stands for the date of the file.  The date is
+retrieved with the @code{org-publish-find-date} function and formatted
+with @code{org-publish-sitemap-date-format}.  Default @code{%t}.
 
 @item @code{:sitemap-date-format}
-@tab Format string for the @code{format-time-string} function that tells how
+Format string for the @code{format-time-string} function that tells how
 a sitemap entry's date is to be formatted.  This property bypasses
 @code{org-publish-sitemap-date-format} which defaults to @code{%Y-%m-%d}.
-
-@end multitable
+@end table
 
 @node Generating an index
 @subsection Generating an index
+
 @cindex index, in a publishing project
 
 Org mode can generate an index across the files of a publishing project.
 
-@multitable @columnfractions 0.25 0.75
+@table @asis
 @item @code{:makeindex}
-@tab When non-@code{nil}, generate in index in the file @file{theindex.org} and
-publish it as @file{theindex.html}.
-@end multitable
+When non-@code{nil}, generate in index in the file @samp{theindex.org} and
+publish it as @samp{theindex.html}.
+@end table
 
-The file will be created when first publishing a project with the
-@code{:makeindex} set.  The file only contains a statement @code{#+INCLUDE:
-"theindex.inc"}.  You can then build around this include statement by adding
-a title, style information, etc.
+The file is created when first publishing a project with the
+@code{:makeindex} set.  The file only contains a statement @samp{#+INCLUDE:
+"theindex.inc"}.  You can then build around this include statement by
+adding a title, style information, etc.
 
-@cindex @code{#+INDEX}
-Index entries are specified with @code{#+INDEX} keyword.  An entry that
-contains an exclamation mark will create a sub item.
+@cindex @samp{INDEX}, keyword
+Index entries are specified with @samp{INDEX} keyword.  An entry that
+contains an exclamation mark creates a sub item.
 
 @example
-* Curriculum Vitae
+*** Curriculum Vitae
 #+INDEX: CV
 #+INDEX: Application!CV
 @end example
 
-@node Uploading files
-@section Uploading files
+@node Uploading Files
+@section Uploading Files
+
 @cindex rsync
 @cindex unison
 
 For those people already utilizing third party sync tools such as
-@command{rsync} or @command{unison}, it might be preferable not to use the 
built in
-@i{remote} publishing facilities of Org mode which rely heavily on
-Tramp.  Tramp, while very useful and powerful, tends not to be
-so efficient for multiple file transfer and has been known to cause problems
-under heavy usage.
-
-Specialized synchronization utilities offer several advantages.  In addition
-to timestamp comparison, they also do content and permissions/attribute
-checks.  For this reason you might prefer to publish your web to a local
-directory (possibly even @i{in place} with your Org files) and then use
-@file{unison} or @file{rsync} to do the synchronization with the remote host.
-
-Since Unison (for example) can be configured as to which files to transfer to
-a certain remote destination, it can greatly simplify the project publishing
-definition.  Simply keep all files in the correct location, process your Org
-files with @code{org-publish} and let the synchronization tool do the rest.
-You do not need, in this scenario, to include attachments such as @file{jpg},
-@file{css} or @file{gif} files in the project definition since the 3rd party
-tool syncs them.
-
-Publishing to a local directory is also much faster than to a remote one, so
-that you can afford more easily to republish entire projects.  If you set
-@code{org-publish-use-timestamps-flag} to @code{nil}, you gain the main
-benefit of re-including any changed external files such as source example
-files you might include with @code{#+INCLUDE:}.  The timestamp mechanism in
-Org is not smart enough to detect if included files have been modified.
-
-@node Sample configuration
-@section Sample configuration
-
-Below we provide two example configurations.  The first one is a simple
-project publishing only a set of Org files.  The second example is
-more complex, with a multi-component project.
+Rsync or Unison, it might be preferable not to use the built-in remote
+publishing facilities of Org mode which rely heavily on Tramp.  Tramp,
+while very useful and powerful, tends not to be so efficient for
+multiple file transfer and has been known to cause problems under
+heavy usage.
+
+Specialized synchronization utilities offer several advantages.  In
+addition to timestamp comparison, they also do content and
+permissions/attribute checks.  For this reason you might prefer to
+publish your web to a local directory---possibly even @emph{in place} with
+your Org files---and then use Unison or Rsync to do the
+synchronization with the remote host.
+
+Since Unison, for example, can be configured as to which files to
+transfer to a certain remote destination, it can greatly simplify the
+project publishing definition.  Simply keep all files in the correct
+location, process your Org files with @code{org-publish} and let the
+synchronization tool do the rest.  You do not need, in this scenario,
+to include attachments such as JPG, CSS or PNG files in the project
+definition since the third-party tool syncs them.
+
+Publishing to a local directory is also much faster than to a remote
+one, so that you can afford more easily to republish entire projects.
+If you set @code{org-publish-use-timestamps-flag} to @code{nil}, you gain the
+main benefit of re-including any changed external files such as source
+example files you might include with @samp{INCLUDE} keyword.  The timestamp
+mechanism in Org is not smart enough to detect if included files have
+been modified.
+
+@node Sample Configuration
+@section Sample Configuration
+
+Below we provide two example configurations.  The first one is
+a simple project publishing only a set of Org files.  The second
+example is more complex, with a multi-component project.
 
 @menu
-* Simple example::              One-component publishing
-* Complex example::             A multi-component publishing example
+* Simple example::               One-component publishing.
+* Complex example::              A multi-component publishing example.
 @end menu
 
 @node Simple example
 @subsection Example: simple publishing configuration
 
-This example publishes a set of Org files to the @file{public_html}
+This example publishes a set of Org files to the @samp{public_html}
 directory on the local machine.
 
 @lisp
@@ -14988,12 +17050,11 @@ directory on the local machine.
       '(("org"
          :base-directory "~/org/"
          :publishing-directory "~/public_html"
-         :publishing-function org-html-publish-to-html
          :section-numbers nil
-         :with-toc nil
-         :html-head "<link rel=\"stylesheet\"
-                    href=\"../other/mystyle.css\"
-                    type=\"text/css\"/>")))
+         :table-of-contents nil
+         :style "<link rel=\"stylesheet\"
+                href=\"../other/mystyle.css\"
+                type=\"text/css\"/>")))
 @end lisp
 
 @node Complex example
@@ -15001,89 +17062,105 @@ directory on the local machine.
 
 This more complicated example publishes an entire website, including
 Org files converted to HTML, image files, Emacs Lisp source code, and
-style sheets.  The publishing directory is remote and private files are
-excluded.
+style sheets.  The publishing directory is remote and private files
+are excluded.
 
 To ensure that links are preserved, care should be taken to replicate
 your directory structure on the web server, and to use relative file
-paths.  For example, if your Org files are kept in @file{~/org} and your
-publishable images in @file{~/images}, you would link to an image with
-@c
+paths.  For example, if your Org files are kept in @samp{~/org/} and your
+publishable images in @samp{~/images/}, you would link to an image with
+
 @example
 file:../images/myimage.png
 @end example
-@c
-On the web server, the relative path to the image should be the
-same.  You can accomplish this by setting up an "images" folder in the
-right place on the web server, and publishing images to it.
+
+
+On the web server, the relative path to the image should be the same.
+You can accomplish this by setting up an @samp{images/} folder in the right
+place on the web server, and publishing images to it.
 
 @lisp
 (setq org-publish-project-alist
       '(("orgfiles"
-          :base-directory "~/org/"
-          :base-extension "org"
-          :publishing-directory "/ssh:user@@host:~/html/notebook/"
-          :publishing-function org-html-publish-to-html
-          :exclude "PrivatePage.org"   ;; regexp
-          :headline-levels 3
-          :section-numbers nil
-          :with-toc nil
-          :html-head "<link rel=\"stylesheet\"
+         :base-directory "~/org/"
+         :base-extension "org"
+         :publishing-directory "/ssh:user@@host:~/html/notebook/"
+         :publishing-function org-html-publish-to-html
+         :exclude "PrivatePage.org" ;; regexp
+         :headline-levels 3
+         :section-numbers nil
+         :with-toc nil
+         :html-head "<link rel=\"stylesheet\"
                   href=\"../other/mystyle.css\" type=\"text/css\"/>"
-          :html-preamble t)
-
-         ("images"
-          :base-directory "~/images/"
-          :base-extension "jpg\\|gif\\|png"
-          :publishing-directory "/ssh:user@@host:~/html/images/"
-          :publishing-function org-publish-attachment)
-
-         ("other"
-          :base-directory "~/other/"
-          :base-extension "css\\|el"
-          :publishing-directory "/ssh:user@@host:~/html/other/"
-          :publishing-function org-publish-attachment)
-         ("website" :components ("orgfiles" "images" "other"))))
+         :html-preamble t)
+
+        ("images"
+         :base-directory "~/images/"
+         :base-extension "jpg\\|gif\\|png"
+         :publishing-directory "/ssh:user@@host:~/html/images/"
+         :publishing-function org-publish-attachment)
+
+        ("other"
+         :base-directory "~/other/"
+         :base-extension "css\\|el"
+         :publishing-directory "/ssh:user@@host:~/html/other/"
+         :publishing-function org-publish-attachment)
+        ("website" :components ("orgfiles" "images" "other"))))
 @end lisp
 
-@node Triggering publication
-@section Triggering publication
+@node Triggering Publication
+@section Triggering Publication
 
 Once properly configured, Org can publish with the following commands:
 
-@table @kbd
-@orgcmd{C-c C-e P x,org-publish}
-Prompt for a specific project and publish all files that belong to it.
-@orgcmd{C-c C-e P p,org-publish-current-project}
+@table @asis
+@item @kbd{C-c C-e P x} (@code{org-publish})
+@kindex C-c C-e P x
+@findex org-publish
+Prompt for a specific project and publish all files that belong to
+it.
+
+@item @kbd{C-c C-e P p} (@code{org-publish-current-project})
+@kindex C-c C-e P p
+@findex org-publish-current-project
 Publish the project containing the current file.
-@orgcmd{C-c C-e P f,org-publish-current-file}
+
+@item @kbd{C-c C-e P f} (@code{org-publish-current-file})
+@kindex C-c C-e P f
+@findex org-publish-current-file
 Publish only the current file.
-@orgcmd{C-c C-e P a,org-publish-all}
+
+@item @kbd{C-c C-e P a} (@code{org-publish-all})
+@kindex C-c C-e P a
+@findex org-publish-all
 Publish every project.
 @end table
 
 @vindex org-publish-use-timestamps-flag
-Org uses timestamps to track when a file has changed.  The above functions
-normally only publish changed files.  You can override this and force
-publishing of all files by giving a prefix argument to any of the commands
-above, or by customizing the variable @code{org-publish-use-timestamps-flag}.
-This may be necessary in particular if files include other files via
-@code{#+SETUPFILE:} or @code{#+INCLUDE:}.
-
-
-@node Working with source code
-@chapter Working with source code
-@cindex Schulte, Eric
-@cindex Davison, Dan
+Org uses timestamps to track when a file has changed.  The above
+functions normally only publish changed files.  You can override this
+and force publishing of all files by giving a prefix argument to any
+of the commands above, or by customizing the variable
+@code{org-publish-use-timestamps-flag}.  This may be necessary in
+particular if files include other files via @samp{SETUPFILE} or @samp{INCLUDE}
+keywords.
+
+@node Working with Source Code
+@chapter Working with Source Code
+
 @cindex source code, working with
 
-Source code here refers to any code typed in Org mode documents.  Org can
-manage source code in any Org file once such code is tagged with begin and
-end markers.  Working with source code begins with tagging source code
-blocks.  Tagged @samp{src} code blocks are not restricted to the preamble or
-the end of an Org document; they can go anywhere---with a few exceptions,
-such as not inside comments and fixed width areas.  Here's a sample
-@samp{src} code block in emacs-lisp:
+Source code here refers to any plain text collection of computer
+instructions, possibly with comments, written using a human-readable
+programming language.  Org can manage source code in an Org document
+when the source code is identified with begin and end markers.
+Working with source code begins with identifying source code blocks.
+A source code block can be placed almost anywhere in an Org document;
+it is not restricted to the preamble or the end of the document.
+However, Org cannot manage a source code block if it is placed inside
+an Org comment or within a fixed width section.
+
+Here is an example source code block in the Emacs Lisp language:
 
 @example
 #+BEGIN_SRC emacs-lisp
@@ -15093,85 +17170,90 @@ such as not inside comments and fixed width areas.  
Here's a sample
 #+END_SRC
 @end example
 
-Org can take the code in the block between the @code{#+BEGIN_SRC} and
-@code{#+END_SRC} tags, and format, compile, execute, and show the results.
-Org can simplify many housekeeping tasks essential to modern code
-maintenance.  That's why these blocks in Org mode literature are sometimes
-referred to as @samp{live code} blocks (as compared to the static text and
-documentation around it).  Users can control how @samp{live} they want each
-block by tweaking the headers for compiling, execution, extraction.
-
-Org's @samp{src} code block type is one of many block types, such as quote,
-export, verse, latex, example, and verbatim.  This section pertains to
-@code{src} code blocks between @code{#+BEGIN_SRC} and @code{#+END_SRC}
-
-For editing @samp{src} code blocks, Org provides native Emacs major-modes.
-That leverages the latest Emacs features for that source code language mode.
-
-For exporting, Org can then extract @samp{src} code blocks into compilable
-source files (in a conversion process known as @dfn{tangling} in literate
-programming terminology).
-
-For publishing, Org's back-ends can handle the @samp{src} code blocks and the
-text for output to a variety of formats with native syntax highlighting.
-
-For executing the source code in the @samp{src} code blocks, Org provides
-facilities that glue the tasks of compiling, collecting the results of the
-execution, and inserting them back to the Org file.  Besides text output,
-results may include links to other data types that Emacs can handle: audio,
-video, and graphics.
-
-An important feature of Org's execution of the @samp{src} code blocks is
-passing variables, functions, and results between @samp{src} blocks.  Such
-interoperability uses a common syntax even if these @samp{src} blocks are in
-different source code languages.  The integration extends to linking the
-debugger's error messages to the line in the @samp{src} code block in the Org
-file.  That should partly explain why this functionality by the original
-contributors, Eric Schulte and Dan Davison, was called @samp{Org Babel}.
-
-In literate programming, the main appeal is code and documentation
-co-existing in one file.  Org mode takes this several steps further.  First
-by enabling execution, and then by inserting results of that execution back
-into the Org file.  Along the way, Org provides extensive formatting
-features, including handling tables.  Org handles multiple source code
-languages in one file, and provides a common syntax for passing variables,
-functions, and results between @samp{src} code blocks.
+Org can manage the source code in the block delimited by @samp{#+BEGIN_SRC}
+@dots{} @samp{#+END_SRC} in several ways that can simplify housekeeping tasks
+essential to modern source code maintenance.  Org can edit, format,
+extract, export, and publish source code blocks.  Org can also compile
+and execute a source code block, then capture the results.  The Org
+mode literature sometimes refers to source code blocks as @emph{live code}
+blocks because they can alter the content of the Org document or the
+material that it exports.  Users can control how live they want each
+source code block by tweaking the header arguments (see @ref{Using Header 
Arguments}) for compiling, execution, extraction, and
+exporting.
+
+Source code blocks are one of many Org block types, which also include
+``center'', ``comment'', ``dynamic'', ``example'', ``export'', ``quote'',
+``special'', and ``verse''.  This section pertains to blocks between
+@samp{#+BEGIN_SRC} and @samp{#+END_SRC}.
+
+For editing and formatting a source code block, Org uses an
+appropriate Emacs major mode that includes features specifically
+designed for source code in that language.
+
+Org can extract one or more source code blocks and write them to one
+or more source files---a process known as @emph{tangling} in literate
+programming terminology.
+
+For exporting and publishing, Org's back-ends can format a source code
+block appropriately, often with native syntax highlighting.
+
+For executing and compiling a source code block, the user can
+configure Org to select the appropriate compiler.  Org provides
+facilities to collect the result of the execution or compiler output,
+insert it into the Org document, and/or export it.  In addition to
+text results, Org can insert links to other data types, including
+audio, video, and graphics.  Org can also link a compiler error
+message to the appropriate line in the source code block.
+
+An important feature of Org's management of source code blocks is the
+ability to pass variables, functions, and results to one another using
+a common syntax for source code blocks in any language.  Although most
+literate programming facilities are restricted to one language or
+another, Org's language-agnostic approach lets the literate programmer
+match each programming task with the appropriate computer language and
+to mix them all together in a single Org document.  This
+interoperability among languages explains why Org's source code
+management facility was named @emph{Org Babel} by its originators, Eric
+Schulte and Dan Davison.
 
 Org mode fulfills the promise of easy verification and maintenance of
-publishing reproducible research by keeping all these in the same file: text,
-data, code, configuration settings of the execution environment, the results
-of the execution, and associated narratives, claims, references, and internal
-and external links.
+publishing reproducible research by keeping text, data, code,
+configuration settings of the execution environment, the results of
+the execution, and associated narratives, claims, references, and
+internal and external links in a single Org document.
 
-Details of Org's facilities for working with source code are shown next.
+Details of Org's facilities for working with source code are described
+in the following sections.
 
 @menu
-* Structure of code blocks::    Code block syntax described
-* Editing source code::         Language major-mode editing
-* Exporting code blocks::       Export contents and/or results
-* Extracting source code::      Create pure source code files
-* Evaluating code blocks::      Place results of evaluation in the Org mode 
buffer
-* Library of Babel::            Use and contribute to a library of useful code 
blocks
-* Languages::                   List of supported code block languages
-* Header arguments::            Configure code block functionality
-* Results of evaluation::       How evaluation results are handled
-* Noweb reference syntax::      Literate programming in Org mode
-* Key bindings and useful functions::  Work quickly with code blocks
-* Batch execution::             Call functions from the command line
+* Structure of Code Blocks::     Code block syntax described.
+* Using Header Arguments::       Different ways to set header arguments.
+* Environment of a Code Block::  Arguments, sessions, working directory...
+* Evaluating Code Blocks::       Place results of evaluation in the Org buffer.
+* Results of Evaluation::        Choosing a results type, post-processing...
+* Exporting Code Blocks::        Export contents and/or results.
+* Extracting Source Code::       Create pure source code files.
+* Languages::                    List of supported code block languages.
+* Editing Source Code::          Language major-mode editing.
+* Noweb Reference Syntax::       Literate programming in Org mode.
+* Library of Babel::             Use and contribute to a library of useful 
code blocks.
+* Key bindings and Useful Functions:: Work quickly with code blocks.
+* Batch Execution::              Call functions from the command line.
 @end menu
 
+@node Structure of Code Blocks
+@section Structure of Code Blocks
 
-@node Structure of code blocks
-@section Structure of code blocks
 @cindex code block, structure
 @cindex source code, block structure
-@cindex @code{#+NAME}
-@cindex @code{#+BEGIN_SRC}
+@cindex @samp{NAME} keyword, in source blocks
+@cindex @samp{BEGIN_SRC}
 
-Org offers two ways to structure source code in Org documents: in a
-@samp{src} block, and directly inline.  Both specifications are shown below.
+Org offers two ways to structure source code in Org documents: in
+a source code block, and directly inline.  Both specifications are
+shown below.
 
-A @samp{src} block conforms to this structure:
+A source code block conforms to this structure:
 
 @example
 #+NAME: <name>
@@ -15180,12 +17262,12 @@ A @samp{src} block conforms to this structure:
 #+END_SRC
 @end example
 
-Org mode's templates system (@pxref{Easy templates}) speeds up creating
-@samp{src} code blocks with just three keystrokes.  Do not be put-off by
-having to remember the source block syntax.  Org also works with other
-completion systems in Emacs, some of which predate Org and have custom
-domain-specific languages for defining templates.  Regular use of templates
-reduces errors, increases accuracy, and maintains consistency.
+Do not be put-off by having to remember the source block syntax.  Org
+mode offers a command for wrapping existing text in a block (see
+@ref{Structure Templates}).  Org also works with other completion systems
+in Emacs, some of which predate Org and have custom domain-specific
+languages for defining templates.  Regular use of templates reduces
+errors, increases accuracy, and maintains consistency.
 
 @cindex source code, inline
 An inline code block conforms to this structure:
@@ -15194,540 +17276,196 @@ An inline code block conforms to this structure:
 src_<language>@{<body>@}
 @end example
 
+
+@noindent
 or
 
 @example
 src_<language>[<header arguments>]@{<body>@}
 @end example
 
-@table @code
-@item #+NAME: <name>
-Optional.  Names the @samp{src} block so it can be called, like a function,
-from other @samp{src} blocks or inline blocks to evaluate or to capture the
-results.  Code from other blocks, other files, and from table formulas
-(@pxref{The spreadsheet}) can use the name to reference a @samp{src} block.
-This naming serves the same purpose as naming Org tables.  Org mode requires
-unique names.  For duplicate names, Org mode's behavior is undefined.
-@cindex @code{#+NAME}
-@item #+BEGIN_SRC
-@item #+END_SRC
-Mandatory.  They mark the start and end of a block that Org requires.  The
-@code{#+BEGIN_SRC} line takes additional arguments, as described next.
-@cindex begin block, end block
-@item <language>
-Mandatory for live code blocks.  It is the identifier of the source code
-language in the block.  @xref{Languages}, for identifiers of supported
-languages.
-@cindex source code, language
-@item <switches>
-Optional.  Switches provide finer control of the code execution, export, and
-format (see the discussion of switches in @ref{Literal examples})
-@cindex source code, switches
-@item <header arguments>
-Optional.  Heading arguments control many aspects of evaluation, export and
-tangling of code blocks (@pxref{Header arguments}).  Using Org's properties
-feature, header arguments can be selectively applied to the entire buffer or
-specific sub-trees of the Org document.
-@item source code, header arguments
-@item <body>
+
+@table @asis
+@item @samp{#+NAME: <name>}
+Optional.  Names the source block so it can be called, like
+a function, from other source blocks or inline code to evaluate or
+to capture the results.  Code from other blocks, other files, and
+from table formulas (see @ref{The Spreadsheet}) can use the name to
+reference a source block.  This naming serves the same purpose as
+naming Org tables.  Org mode requires unique names.  For duplicate
+names, Org mode's behavior is undefined.
+
+@item @samp{#+BEGIN_SRC} @dots{} @samp{#+END_SRC}
+Mandatory.  They mark the start and end of a block that Org
+requires.  The @samp{#+BEGIN_SRC} line takes additional arguments, as
+described next.
+
+@item @samp{<language>}
+@cindex language, in code blocks
+Mandatory.  It is the identifier of the source code language in the
+block.  See @ref{Languages}, for identifiers of supported languages.
+
+@item @samp{<switches>}
+@cindex switches, in code blocks
+Optional.  Switches provide finer control of the code execution,
+export, and format (see the discussion of switches in @ref{Literal Examples}).
+
+@item @samp{<header arguments>}
+@cindex header arguments, in code blocks
+Optional.  Heading arguments control many aspects of evaluation,
+export and tangling of code blocks (see @ref{Using Header Arguments}).
+Using Org's properties feature, header arguments can be selectively
+applied to the entire buffer or specific sub-trees of the Org
+document.
+
+@item @samp{<body>}
 Source code in the dialect of the specified language identifier.
 @end table
 
-@node Editing source code
-@section Editing source code
-@cindex code block, editing
-@cindex source code, editing
+@node Using Header Arguments
+@section Using Header Arguments
 
-@vindex org-edit-src-auto-save-idle-delay
-@vindex org-edit-src-turn-on-auto-save
-@kindex C-c '
-@kbd{C-c '} for editing the current code block.  It opens a new major-mode
-edit buffer containing the body of the @samp{src} code block, ready for any
-edits.  @kbd{C-c '} again to close the buffer and return to the Org buffer.
+Org comes with many header arguments common to all languages.  New
+header arguments are added for specific languages as they become
+available for use in source code blocks.  A header argument is
+specified with an initial colon followed by the argument's name in
+lowercase.
 
-@kbd{C-x C-s} saves the buffer and updates the contents of the Org buffer.
+Since header arguments can be set in several ways, Org prioritizes
+them in case of overlaps or conflicts by giving local settings
+a higher priority.  Header values in function calls, for example,
+override header values from global defaults.
 
-Set @code{org-edit-src-auto-save-idle-delay} to save the base buffer after
-a certain idle delay time.
+@anchor{System-wide header arguments}
+@subheading System-wide header arguments
 
-Set @code{org-edit-src-turn-on-auto-save} to auto-save this buffer into a
-separate file using @code{auto-save-mode}.
+@vindex org-babel-default-header-args
 
-@kbd{C-c '} to close the major-mode buffer and return back to the Org buffer.
+@vindex org-babel-default-header-args
+System-wide values of header arguments can be specified by customizing
+the @code{org-babel-default-header-args} variable, which defaults to the
+following values:
 
-While editing the source code in the major-mode, the @code{org-src-mode}
-minor mode remains active.  It provides these customization variables as
-described below.  For even more variables, look in the customization
-group @code{org-edit-structure}.
+@example
+:session    => "none"
+:results    => "replace"
+:exports    => "code"
+:cache      => "no"
+:noweb      => "no"
+@end example
 
-@table @code
-@item org-src-lang-modes
-If an Emacs major-mode named @code{<lang>-mode} exists, where @code{<lang>}
-is the language identifier from code block's header line, then the edit
-buffer uses that major-mode.  Use this variable to arbitrarily map language
-identifiers to major modes.
-@item org-src-window-setup
-For specifying Emacs window arrangement when the new edit buffer is created.
-@item org-src-preserve-indentation
-@cindex indentation, in source blocks
-Default is @code{nil}.  Source code is indented.  This indentation applies
-during export or tangling, and depending on the context, may alter leading
-spaces and tabs.  When non-@code{nil}, source code is aligned with the
-leftmost column.  No lines are modified during export or tangling, which is
-very useful for white-space sensitive languages, such as Python.
-@item org-src-ask-before-returning-to-edit-buffer
-When @code{nil}, Org returns to the edit buffer without further prompts.  The
-default prompts for a confirmation.
-@end table
+The example below sets @samp{:noweb} header arguments to @samp{yes}, which 
makes
+Org expand @samp{:noweb} references by default.
 
-Set @code{org-src-fontify-natively} to non-@code{nil} to turn on native code
-fontification in the @emph{Org} buffer.  Fontification of @samp{src} code
-blocks can give visual separation of text and code on the display page.  To
-further customize the appearance of @code{org-block} for specific languages,
-customize @code{org-src-block-faces}.  The following example shades the
-background of regular blocks, and colors source blocks only for Python and
-Emacs-Lisp languages.
 @lisp
-(require 'color)
-(set-face-attribute 'org-block nil :background
-                    (color-darken-name
-                     (face-attribute 'default :background) 3))
-
-(setq org-src-block-faces '(("emacs-lisp" (:background "#EEE2FF"))
-                            ("python" (:background "#E5FFB8"))))
+(setq org-babel-default-header-args
+      (cons '(:noweb . "yes")
+            (assq-delete-all :noweb org-babel-default-header-args)))
 @end lisp
 
-@node Exporting code blocks
-@section Exporting code blocks
-@cindex code block, exporting
-@cindex source code, exporting
-
-Org can flexibly export just the @emph{code} from the code blocks, just the
-@emph{results} of evaluation of the code block, @emph{both} the code and the
-results of the code block evaluation, or @emph{none}.  Org defaults to
-exporting @emph{code} for most languages.  For some languages, such as
-@code{ditaa}, Org defaults to @emph{results}.  To export just the body of
-code blocks, @pxref{Literal examples}.  To selectively export sub-trees of
-an Org document, @pxref{Exporting}.
-
-The @code{:exports} header arguments control exporting code blocks only and
-not inline code:
-
-@subsubheading Header arguments:
-
-@table @code
-@cindex @code{:exports}, src header argument
-@item :exports code
-This is the default for most languages where the body of the code block is
-exported.  See @ref{Literal examples} for more.
-@item :exports results
-On export, Org includes only the results and not the code block.  After each
-evaluation, Org inserts the results after the end of code block in the Org
-buffer.  By default, Org replaces any previous results.  Org can also append
-results.
-@item :exports both
-Org exports both the code block and the results.
-@item :exports none
-Org does not export the code block nor the results.
-@end table
-
-@vindex org-export-use-babel
-To stop Org from evaluating code blocks to speed exports, use the header
-argument @code{:eval never-export} (@pxref{eval}).  To stop Org from
-evaluating code blocks for greater security, set the
-@code{org-export-use-babel} variable to @code{nil}, but understand that
-header arguments will have no effect.
-
-Turning off evaluation comes in handy when batch processing.  For example,
-markup languages for wikis, which have a high risk of untrusted code.
-Stopping code block evaluation also stops evaluation of all header arguments
-of the code block.  This may not be desirable in some circumstances.  So
-during export, to allow evaluation of just the header arguments but not any
-code evaluation in the source block, set @code{:eval never-export}
-(@pxref{eval}).
-
-Org never evaluates code blocks in commented sub-trees when exporting
-(@pxref{Comment lines}).  On the other hand, Org does evaluate code blocks in
-sub-trees excluded from export (@pxref{Export settings}).
+@cindex language specific default header arguments
+@cindex default header arguments per language
+Each language can have separate default header arguments by
+customizing the variable @code{org-babel-default-header-args:<LANG>}, where
+@var{<LANG>} is the name of the language.  For details, see the
+language-specific online documentation at
+@uref{https://orgmode.org/worg/org-contrib/babel/}.
 
-@node Extracting source code
-@section Extracting source code
-@cindex tangling
-@cindex source code, extracting
-@cindex code block, extracting source code
-
-Extracting source code from code blocks is a basic task in literate
-programming.  Org has features to make this easy.  In literate programming
-parlance, documents on creation are @emph{woven} with code and documentation,
-and on export, the code is @emph{tangled} for execution by a computer.  Org
-facilitates weaving and tangling for producing, maintaining, sharing, and
-exporting literate programming documents.  Org provides extensive
-customization options for extracting source code.
-
-When Org tangles @samp{src} code blocks, it expands, merges, and transforms
-them.  Then Org recomposes them into one or more separate files, as
-configured through the options.  During this @emph{tangling} process, Org
-expands variables in the source code, and resolves any Noweb style references
-(@pxref{Noweb reference syntax}).
-
-@subsubheading Header arguments
-
-@table @code
-@cindex @code{:tangle}, src header argument
-@item :tangle no
-By default, Org does not tangle the @samp{src} code block on export.
-@item :tangle yes
-Org extracts the contents of the code block for the tangled output.  By
-default, the output file name is the same as the Org file but with a file
-extension derived from the language identifier of the @samp{src} code block.
-@item :tangle filename
-Override the default file name with this one for the tangled output.
-@end table
+@anchor{Header arguments in Org mode properties}
+@subheading Header arguments in Org mode properties
 
-@kindex  C-c C-v t
-@subsubheading Functions
-
-@table @code
-@item org-babel-tangle
-Tangle the current file.  Bound to @kbd{C-c C-v t}.
+For header arguments applicable to the buffer, use @samp{PROPERTY} keyword
+anywhere in the Org file (see @ref{Property Syntax}).
 
-With prefix argument only tangle the current @samp{src} code block.
-@item org-babel-tangle-file
-Choose a file to tangle.  Bound to @kbd{C-c C-v f}.
-@end table
+The following example makes all the R code blocks execute in the same
+session.  Setting @samp{:results} to @samp{silent} ignores the results of
+executions for all blocks, not just R code blocks; no results inserted
+for any block.
 
-@subsubheading Hooks
+@example
+#+PROPERTY: header-args:R  :session *R*
+#+PROPERTY: header-args    :results silent
+@end example
 
-@table @code
-@item org-babel-post-tangle-hook
-This hook runs from within code tangled by @code{org-babel-tangle}, making it
-suitable for post-processing, compilation, and evaluation of code in the
-tangled files.
-@end table
+@vindex org-use-property-inheritance
+Header arguments set through Org's property drawers (see @ref{Property 
Syntax}) apply at the sub-tree level on down.  Since these property
+drawers can appear anywhere in the file hierarchy, Org uses outermost
+call or source block to resolve the values.  Org ignores
+@code{org-use-property-inheritance} setting.
 
-@subsubheading Jumping between code and Org
+In this example, @samp{:cache} defaults to @samp{yes} for all code blocks in 
the
+sub-tree.
 
-Debuggers normally link errors and messages back to the source code.  But for
-tangled files, we want to link back to the Org file, not to the tangled
-source file.  To make this extra jump, Org uses
-@code{org-babel-tangle-jump-to-org} function with two additional source code
-block header arguments: One, set @code{padline} (@pxref{padline}) to true
-(the default setting).  Two, set @code{comments} (@pxref{comments}) to
-@code{link}, which makes Org insert links to the Org file.
+@example
+* sample header
+  :PROPERTIES:
+  :header-args:    :cache yes
+  :END:
+@end example
 
-@node Evaluating code blocks
-@section Evaluating code blocks
-@cindex code block, evaluating
-@cindex source code, evaluating
-@cindex @code{#+RESULTS}
+@kindex C-c C-x p
+@findex org-set-property
+Properties defined through @code{org-set-property} function, bound to
+@kbd{C-c C-x p}, apply to all active languages.  They override
+properties set in @code{org-babel-default-header-args}.
 
-A note about security: With code evaluation comes the risk of harm.  Org
-safeguards by prompting for user's permission before executing any code in
-the source block.  To customize this safeguard (or disable it) see @ref{Code
-evaluation security}.
+@cindex language specific header arguments properties
+@cindex header arguments per language
+Language-specific header arguments are also read from properties
+@samp{header-args:<LANG>} where @var{<LANG>} is the language
+identifier.  For example,
 
-Org captures the results of the @samp{src} code block evaluation and inserts
-them in the Org file, right after the @samp{src} code block.  The insertion
-point is after a newline and the @code{#+RESULTS} label.  Org creates the
-@code{#+RESULTS} label if one is not already there.
+@example
+* Heading
+  :PROPERTIES:
+  :header-args:clojure:    :session *clojure-1*
+  :header-args:R:          :session *R*
+  :END:
+** Subheading
+  :PROPERTIES:
+  :header-args:clojure:    :session *clojure-2*
+  :END:
+@end example
 
-By default, Org enables only @code{emacs-lisp} @samp{src} code blocks for
-execution.  See @ref{Languages} for identifiers to enable other languages.
+@noindent
+would force separate sessions for Clojure blocks in @samp{Heading} and
+@samp{Subheading}, but use the same session for all R blocks.  Blocks in
+@samp{Subheading} inherit settings from @samp{Heading}.
 
-@kindex C-c C-c
-Org provides many ways to execute @samp{src} code blocks.  @kbd{C-c C-c} or
-@kbd{C-c C-v e} with the point on a @samp{src} code block@footnote{The option
-@code{org-babel-no-eval-on-ctrl-c-ctrl-c} can be used to remove code
-evaluation from the @kbd{C-c C-c} key binding.} calls the
-@code{org-babel-execute-src-block} function, which executes the code in the
-block, collects the results, and inserts them in the buffer.
+@anchor{Code block specific header arguments}
+@subheading Code block specific header arguments
 
-@cindex @code{#+CALL}
-By calling a named code block@footnote{Actually, the constructs call_<name>()
-and src_<lang>@{@} are not evaluated when they appear in a keyword line
-(i.e. lines starting with @code{#+KEYWORD:}, @pxref{In-buffer settings}).}
-from an Org mode buffer or a table.  Org can call the named @samp{src} code
-blocks from the current Org mode buffer or from the ``Library of Babel''
-(@pxref{Library of Babel}).  Whether inline syntax or the @code{#+CALL:}
-syntax is used, the result is wrapped based on the variable
-@code{org-babel-inline-result-wrap}, which by default is set to @code{"=%s="}
-to produce verbatim text suitable for markup.
+Header arguments are most commonly set at the source code block level,
+on the @samp{#+BEGIN_SRC} line.  Arguments set at this level take
+precedence over those set in the @code{org-babel-default-header-args}
+variable, and also those set as header properties.
 
-The syntax for @code{#+CALL:} is
+In the following example, setting @samp{:results} to @samp{silent} makes it
+ignore results of the code execution.  Setting @samp{:exports} to @samp{code}
+exports only the body of the code block to HTML or @LaTeX{}.
 
 @example
-#+CALL: <name>(<arguments>)
-#+CALL: <name>[<inside header arguments>](<arguments>) <end header arguments>
+#+NAME: factorial
+#+BEGIN_SRC haskell :results silent :exports code :var n=0
+  fac 0 = 1
+  fac n = n * fac (n-1)
+#+END_SRC
 @end example
 
-The syntax for inline named code block is
+The same header arguments in an inline code block:
 
 @example
-... call_<name>(<arguments>) ...
-... call_<name>[<inside header arguments>](<arguments>)[<end header 
arguments>] ...
+src_haskell[:exports both]@{fac 5@}
 @end example
 
-@table @code
-@item <name>
-This is the name of the code block to be evaluated (@pxref{Structure of
-code blocks}).
-@item <arguments>
-Org passes arguments to the code block using standard function call syntax.
-For example, a @code{#+CALL:} line that passes @samp{4} to a code block named
-@code{double}, which declares the header argument @code{:var n=2}, would be
-written as @code{#+CALL: double(n=4)}.  Note how this function call syntax is
-different from the header argument syntax.
-@item <inside header arguments>
-Org passes inside header arguments to the named @samp{src} code block using
-the header argument syntax.  Inside header arguments apply to code block
-evaluation.  For example, @code{[:results output]} collects results printed
-to @code{STDOUT} during code execution of that block.  Note how this header
-argument syntax is different from the function call syntax.
-@item <end header arguments>
-End header arguments affect the results returned by the code block.  For
-example, @code{:results html} wraps the results in a @code{BEGIN_EXPORT html}
-block before inserting the results in the Org buffer.
-
-For more examples of header arguments for @code{#+CALL:} lines,
-@pxref{Arguments in function calls}.
-@end table
 
-@node Library of Babel
-@section Library of Babel
-@cindex babel, library of
-@cindex source code, library
-@cindex code block, library
+@cindex @samp{HEADER}, keyword
+Code block header arguments can span multiple lines using @samp{#+HEADER:}
+on each line.  Note that Org currently accepts the plural spelling of
+@samp{#+HEADER:} only as a convenience for backward-compatibility.  It may
+be removed at some point.
 
-The ``Library of Babel'' is a collection of code blocks.  Like a function
-library, these code blocks can be called from other Org files.  A collection
-of useful code blocks is available on
-@uref{https://orgmode.org/worg/library-of-babel.html,Worg}.  For remote code
-block evaluation syntax, @pxref{Evaluating code blocks}.
-
-@kindex C-c C-v i
-For any user to add code to the library, first save the code in regular
-@samp{src} code blocks of an Org file, and then load the Org file with
-@code{org-babel-lob-ingest}, which is bound to @kbd{C-c C-v i}.
-
-@node Languages
-@section Languages
-@cindex babel, languages
-@cindex source code, languages
-@cindex code block, languages
-
-Org supports the following languages for the @samp{src} code blocks:
-
-@multitable @columnfractions 0.25 0.25 0.25 0.25
-@headitem @b{Language} @tab @b{Identifier} @tab @b{Language} @tab 
@b{Identifier}
-@item Asymptote @tab asymptote @tab Awk @tab awk
-@item C @tab C @tab C++ @tab C++
-@item Clojure @tab clojure @tab CSS @tab css
-@item D @tab d @tab ditaa @tab ditaa
-@item Graphviz @tab dot @tab Emacs Calc @tab calc
-@item Emacs Lisp @tab emacs-lisp @tab Fortran @tab fortran
-@item gnuplot @tab gnuplot @tab Haskell @tab haskell
-@item Java @tab java @tab Javascript @tab js
-@item LaTeX @tab latex @tab Ledger @tab ledger
-@item Lisp @tab lisp @tab Lilypond @tab lilypond
-@item Lua @tab lua @tab MATLAB @tab matlab
-@item Mscgen @tab mscgen @tab Objective Caml @tab ocaml
-@item Octave @tab octave @tab Org mode @tab org
-@item Oz @tab oz @tab Perl @tab perl
-@item Plantuml @tab plantuml @tab Processing.js @tab processing
-@item Python @tab python @tab R @tab R
-@item Ruby @tab ruby @tab Sass @tab sass
-@item Scheme @tab scheme @tab GNU Screen @tab screen
-@item Sed @tab sed @tab shell @tab sh
-@item SQL @tab sql @tab SQLite @tab sqlite
-@item Vala @tab vala
-@end multitable
-
-Additional documentation for some languages are at
-@uref{https://orgmode.org/worg/org-contrib/babel/languages.html}.
-
-@vindex org-babel-load-languages
-By default, only @code{emacs-lisp} is enabled for evaluation.  To enable or
-disable other languages, customize the @code{org-babel-load-languages}
-variable either through the Emacs customization interface, or by adding code
-to the init file as shown next:
-
-In this example, evaluation is disabled for @code{emacs-lisp}, and enabled
-for @code{R}.
-
-@lisp
-(org-babel-do-load-languages
- 'org-babel-load-languages
- '((emacs-lisp . nil)
-   (R . t)))
-@end lisp
-
-Note that this is not the only way to enable a language.  Org also enables
-languages when loaded with @code{require} statement.  For example, the
-following enables execution of @code{clojure} code blocks:
-
-@lisp
-(require 'ob-clojure)
-@end lisp
-
-@node Header arguments
-@section Header arguments
-@cindex code block, header arguments
-@cindex source code, block header arguments
-
-Details of configuring header arguments are shown here.
-
-@menu
-* Using header arguments::      Different ways to set header arguments
-* Specific header arguments::   List of header arguments
-@end menu
-
-@node Using header arguments
-@subsection Using header arguments
-
-Since header arguments can be set in several ways, Org prioritizes them in
-case of overlaps or conflicts by giving local settings a higher priority.
-Header values in function calls, for example, override header values from
-global defaults.
-@menu
-* System-wide header arguments::  Set globally, language-specific
-* Language-specific header arguments::  Set in the Org file's headers
-* Header arguments in Org mode properties::  Set in the Org file
-* Language-specific mode properties::
-* Code block specific header arguments::  The most commonly used method
-* Arguments in function calls::  The most specific level, takes highest 
priority
-@end menu
-
-
-@node System-wide header arguments
-@subsubheading System-wide header arguments
-@vindex org-babel-default-header-args
-System-wide values of header arguments can be specified by adapting the
-@code{org-babel-default-header-args} variable:
-
-@cindex @code{:session}, src header argument
-@cindex @code{:results}, src header argument
-@cindex @code{:exports}, src header argument
-@cindex @code{:cache}, src header argument
-@cindex @code{:noweb}, src header argument
-@example
-:session    => "none"
-:results    => "replace"
-:exports    => "code"
-:cache      => "no"
-:noweb      => "no"
-@end example
-
-This example sets @code{:noweb} header arguments to @code{yes}, which makes
-Org expand @code{:noweb} references by default.
-
-@lisp
-(setq org-babel-default-header-args
-      (cons '(:noweb . "yes")
-            (assq-delete-all :noweb org-babel-default-header-args)))
-@end lisp
-
-@node Language-specific header arguments
-@subsubheading Language-specific header arguments
-Each language can have separate default header arguments by customizing the
-variable @code{org-babel-default-header-args:<lang>}, where @code{<lang>} is
-the name of the language.  For details, see the language-specific online
-documentation at @uref{https://orgmode.org/worg/org-contrib/babel/}.
-
-@node Header arguments in Org mode properties
-@subsubheading Header arguments in Org mode properties
-
-For header arguments applicable to the buffer, use @code{#+PROPERTY:} lines
-anywhere in the Org mode file (@pxref{Property syntax}).
-
-The following example sets only for @samp{R} code blocks to @code{session},
-making all the @samp{R} code blocks execute in the same session.  Setting
-@code{results} to @code{silent} ignores the results of executions for all
-blocks, not just @samp{R} code blocks; no results inserted for any block.
-
-@example
-#+PROPERTY: header-args:R  :session *R*
-#+PROPERTY: header-args    :results silent
-@end example
-
-@vindex org-use-property-inheritance
-Header arguments set through Org's property drawers (@pxref{Property syntax})
-apply at the sub-tree level on down.  Since these property drawers can appear
-anywhere in the file hierarchy, Org uses outermost call or source block to
-resolve the values.  Org ignores @code{org-use-property-inheritance} setting.
-
-In this example, @code{:cache} defaults to @code{yes} for all code blocks in
-the sub-tree starting with @samp{sample header}.
-
-@example
-* sample header
-  :PROPERTIES:
-  :header-args:    :cache yes
-  :END:
-@end example
-
-@kindex C-c C-x p
-@vindex org-babel-default-header-args
-Properties defined through @code{org-set-property} function, bound to
-@kbd{C-c C-x p}, apply to all active languages.  They override properties set
-in @code{org-babel-default-header-args}.
-
-@node Language-specific mode properties
-@subsubheading Language-specific mode properties
-
-Language-specific header arguments are also read from properties
-@code{header-args:<lang>} where @code{<lang>} is the language identifier.
-For example,
-
-@example
-* Heading
-  :PROPERTIES:
-  :header-args:clojure:    :session *clojure-1*
-  :header-args:R:          :session *R*
-  :END:
-** Subheading
-  :PROPERTIES:
-  :header-args:clojure:    :session *clojure-2*
-  :END:
-@end example
-
-would force separate sessions for clojure blocks in Heading and Subheading,
-but use the same session for all @samp{R} blocks.  Blocks in Subheading
-inherit settings from Heading.
-
-@node Code block specific header arguments
-@subsubheading Code block specific header arguments
-
-Header arguments are most commonly set at the @samp{src} code block level, on
-the @code{#+BEGIN_SRC} line.  Arguments set at this level take precedence
-over those set in the @code{org-babel-default-header-args} variable, and also
-those set as header properties.
-
-In the following example, setting @code{results} to @code{silent} makes it
-ignore results of the code execution.  Setting @code{:exports} to @code{code}
-exports only the body of the @samp{src} code block to HTML or @LaTeX{}.:
-
-@example
-#+NAME: factorial
-#+BEGIN_SRC haskell :results silent :exports code :var n=0
-fac 0 = 1
-fac n = n * fac (n-1)
-#+END_SRC
-@end example
-
-The same header arguments in an inline @samp{src} code block:
-
-@example
-src_haskell[:exports both]@{fac 5@}
-@end example
-
-Code block header arguments can span multiple lines using @code{#+HEADER:} on
-each line.  Note that Org currently accepts the plural spelling of
-@code{#+HEADER:} only as a convenience for backward-compatibility.  It may be
-removed at some point.
-
-@cindex @code{#+HEADER:}
-
-Multi-line header arguments on an unnamed @samp{src} code block:
+Multi-line header arguments on an unnamed code block:
 
 @example
 #+HEADER: :var data1=1
@@ -15739,7 +17477,7 @@ Multi-line header arguments on an unnamed @samp{src} 
code block:
 : data1:1, data2:2
 @end example
 
-Multi-line header arguments on a named @samp{src} code block:
+Multi-line header arguments on a named code block:
 
 @example
 #+NAME: named-block
@@ -15752,110 +17490,66 @@ Multi-line header arguments on a named @samp{src} 
code block:
   : data:2
 @end example
 
-@node Arguments in function calls
-@subsubheading Arguments in function calls
+@anchor{Header arguments in function calls}
+@subheading Header arguments in function calls
 
-Header arguments in function calls are the most specific and override all
-other settings in case of an overlap.  They get the highest priority.  Two
-@code{#+CALL:} examples are shown below.  For the complete syntax of
-@code{#+CALL:} lines, see @ref{Evaluating code blocks}.
+Header arguments in function calls are the most specific and override
+all other settings in case of an overlap.  They get the highest
+priority.  Two @samp{#+CALL:} examples are shown below.  For the complete
+syntax of @samp{CALL} keyword, see @ref{Evaluating Code Blocks}.
 
-In this example, @code{:exports results} header argument is applied to the
-evaluation of the @code{#+CALL:} line.
+In this example, @samp{:exports results} header argument is applied to the
+evaluation of the @samp{#+CALL:} line.
 
 @example
 #+CALL: factorial(n=5) :exports results
 @end example
 
-In this example, @code{:session special} header argument is applied to the
-evaluation of @code{factorial} code block.
+
+In this example, @samp{:session special} header argument is applied to the
+evaluation of @samp{factorial} code block.
 
 @example
 #+CALL: factorial[:session special](n=5)
 @end example
 
-@node Specific header arguments
-@subsection Specific header arguments
-Org comes with many header arguments common to all languages.  New header
-arguments are added for specific languages as they become available for use
-in @samp{src} code blocks.  A header argument is specified with an initial
-colon followed by the argument's name in lowercase.  Common header arguments
-are:
-
-@menu
-* var::                         Pass arguments to @samp{src} code blocks
-* results::                     Specify results type; how to collect
-* file::                        Specify a path for output file
-* file-desc::                   Specify a description for file results
-* file-ext::                    Specify an extension for file output
-* output-dir::                  Specify a directory for output file
-* dir::                         Specify the default directory for code block 
execution
-* exports::                     Specify exporting code, results, both, none
-* tangle::                      Toggle tangling; or specify file name
-* mkdirp::                      Toggle for parent directory creation for 
target files during tangling
-* comments::                    Toggle insertion of comments in tangled code 
files
-* padline::                     Control insertion of padding lines in tangled 
code files
-* no-expand::                   Turn off variable assignment and noweb 
expansion during tangling
-* session::                     Preserve the state of code evaluation
-* noweb::                       Toggle expansion of noweb references
-* noweb-ref::                   Specify block's noweb reference resolution 
target
-* noweb-sep::                   String to separate noweb references
-* cache::                       Avoid re-evaluating unchanged code blocks
-* sep::                         Delimiter for writing tabular results outside 
Org
-* hlines::                      Handle horizontal lines in tables
-* colnames::                    Handle column names in tables
-* rownames::                    Handle row names in tables
-* shebang::                     Make tangled files executable
-* tangle-mode::                 Set permission of tangled files
-* eval::                        Limit evaluation of specific code blocks
-* wrap::                        Mark source block evaluation results
-* post::                        Post processing of results of code block 
evaluation
-* prologue::                    Text to prepend to body of code block
-* epilogue::                    Text to append to body of code block
-@end menu
-
-For language-specific header arguments, see @ref{Languages}.
+@node Environment of a Code Block
+@section Environment of a Code Block
 
-@node var
-@subsubsection @code{:var}
-@cindex @code{:var}, src header argument
-Use @code{:var} for passing arguments to @samp{src} code blocks.  The
-specifics of variables in @samp{src} code blocks vary by the source language
-and are covered in the language-specific documentation.  The syntax for
-@code{:var}, however, is the same for all languages.  This includes declaring
-a variable, and assigning a default value.
 
-Arguments can take values as literals, or as references, or even as Emacs
-Lisp code (@pxref{var, Emacs Lisp evaluation of variables}).  References are
-names from the Org file from the lines @code{#+NAME:} or @code{#+RESULTS:}.
-References can also refer to tables, lists, @code{#+BEGIN_EXAMPLE} blocks,
-other types of @samp{src} code blocks, or the results of execution of
-@samp{src} code blocks.
 
-For better performance, Org can cache results of evaluations.  But caching
-comes with severe limitations (@pxref{cache}).
+@anchor{Passing arguments}
+@subheading Passing arguments
 
-Argument values are indexed like arrays (@pxref{var, Indexable variable
-values}).
+@cindex passing arguments to code blocks
+@cindex arguments, in code blocks
+@cindex @samp{var}, header argument
+Use @samp{var} for passing arguments to source code blocks.  The specifics
+of variables in code blocks vary by the source language and are
+covered in the language-specific documentation.  The syntax for @samp{var},
+however, is the same for all languages.  This includes declaring
+a variable, and assigning a default value.
 
-The following syntax is used to pass arguments to @samp{src} code blocks
-using the @code{:var} header argument.
+The following syntax is used to pass arguments to code blocks using
+the @samp{var} header argument.
 
 @example
-:var name=assign
+:var NAME=ASSIGN
 @end example
 
-The @code{assign} is a literal value, such as a string @samp{"string"}, a
-number @samp{9}, a reference to a table, a list, a literal example, another
-code block (with or without arguments), or the results from evaluating a code
-block.
 
-Here are examples of passing values by reference:
+@noindent
+@var{NAME} is the name of the variable bound in the code block
+body.  @var{ASSIGN} is a literal value, such as a string,
+a number, a reference to a table, a list, a literal example, another
+code block---with or without arguments---or the results of evaluating
+a code block.
 
-@table @dfn
+Here are examples of passing values by reference:
 
+@table @asis
 @item table
-an Org mode table named with either a @code{#+NAME:} line
+A table named with a @samp{NAME} keyword.
 
 @example
 #+NAME: example-table
@@ -15866,23 +17560,77 @@ an Org mode table named with either a @code{#+NAME:} 
line
 
 #+NAME: table-length
 #+BEGIN_SRC emacs-lisp :var table=example-table
-(length table)
+  (length table)
 #+END_SRC
 
 #+RESULTS: table-length
 : 4
 @end example
 
+When passing a table, you can treat specially the row, or the
+column, containing labels for the columns, or the rows, in the
+table.
+
+@cindex @samp{colnames}, header argument
+The @samp{colnames} header argument accepts @samp{yes}, @samp{no}, or 
@samp{nil} values.
+The default value is @samp{nil}: if an input table has column
+names---because the second row is a horizontal rule---then Org
+removes the column names, processes the table, puts back the column
+names, and then writes the table to the results block.  Using @samp{yes},
+Org does the same to the first row, even if the initial table does
+not contain any horizontal rule.  When set to @samp{no}, Org does not
+pre-process column names at all.
+
+@example
+#+NAME: less-cols
+| a |
+|---|
+| b |
+| c |
+
+#+BEGIN_SRC python :var tab=less-cols :colnames nil
+  return [[val + '*' for val in row] for row in tab]
+#+END_SRC
+
+#+RESULTS:
+| a  |
+|----|
+| b* |
+| c* |
+@end example
+
+@cindex @samp{rownames}, header argument
+Similarly, the @samp{rownames} header argument can take two values: @samp{yes}
+or @samp{no}.  When set to @samp{yes}, Org removes the first column, processes
+the table, puts back the first column, and then writes the table to
+the results block.  The default is @samp{no}, which means Org does not
+pre-process the first column.  Note that Emacs Lisp code blocks
+ignore @samp{rownames} header argument because of the ease of
+table-handling in Emacs.
+
+@example
+#+NAME: with-rownames
+| one | 1 | 2 | 3 | 4 |  5 |
+| two | 6 | 7 | 8 | 9 | 10 |
+
+#+BEGIN_SRC python :var tab=with-rownames :rownames yes
+  return [[val + 10 for val in row] for row in tab]
+#+END_SRC
+
+#+RESULTS:
+| one | 11 | 12 | 13 | 14 | 15 |
+| two | 16 | 17 | 18 | 19 | 20 |
+@end example
+
 @item list
-a simple list named with a @code{#+NAME:} line.  Note that only the top level
-list items are passed along.  Nested list items are ignored.
+A simple named list.
 
 @example
 #+NAME: example-list
-  - simple
-    - not
-    - nested
-  - list
+- simple
+  - not
+  - nested
+- list
 
 #+BEGIN_SRC emacs-lisp :var x=example-list
   (print x)
@@ -15892,13 +17640,16 @@ list items are passed along.  Nested list items are 
ignored.
 | simple | list |
 @end example
 
+Note that only the top level list items are passed along.  Nested
+list items are ignored.
+
 @item code block without arguments
-a code block name (from the example above), as assigned by @code{#+NAME:},
-optionally followed by parentheses
+A code block name, as assigned by @samp{NAME} keyword from the example
+above, optionally followed by parentheses.
 
 @example
 #+BEGIN_SRC emacs-lisp :var length=table-length()
-(* 2 length)
+  (* 2 length)
 #+END_SRC
 
 #+RESULTS:
@@ -15906,22 +17657,21 @@ optionally followed by parentheses
 @end example
 
 @item code block with arguments
-a @samp{src} code block name, as assigned by @code{#+NAME:}, followed by
-parentheses and optional arguments passed within the parentheses following
-the @samp{src} code block name using standard function call syntax
+A code block name, as assigned by @samp{NAME} keyword, followed by
+parentheses and optional arguments passed within the parentheses.
 
 @example
 #+NAME: double
 #+BEGIN_SRC emacs-lisp :var input=8
-(* 2 input)
+  (* 2 input)
 #+END_SRC
 
 #+RESULTS: double
 : 16
 
 #+NAME: squared
-#+BEGIN_SRC emacs-lisp :var input=double(input=2)
-(* input input)
+#+BEGIN_SRC emacs-lisp :var input=double(input=1)
+  (* input input)
 #+END_SRC
 
 #+RESULTS: squared
@@ -15929,37 +17679,34 @@ the @samp{src} code block name using standard 
function call syntax
 @end example
 
 @item literal example
-a literal example block named with a @code{#+NAME:} line
+A literal example block named with a @samp{NAME} keyword.
 
 @example
 #+NAME: literal-example
 #+BEGIN_EXAMPLE
-A literal example
-on two lines
+  A literal example
+  on two lines
 #+END_EXAMPLE
 
 #+NAME: read-literal-example
 #+BEGIN_SRC emacs-lisp :var x=literal-example
-  (concatenate 'string x " for you.")
+  (concatenate #'string x " for you.")
 #+END_SRC
 
 #+RESULTS: read-literal-example
 : A literal example
 : on two lines for you.
-
 @end example
-
 @end table
 
-@subsubheading Indexable variable values
-Indexing variable values enables referencing portions of a variable.  Indexes
-are 0 based with negative values counting backwards from the end.  If an
-index is separated by @code{,}s then each subsequent section will index as
-the next dimension.  Note that this indexing occurs @emph{before} other
-table-related header arguments are applied, such as @code{:hlines},
-@code{:colnames} and @code{:rownames}.  The following example assigns the
-last cell of the first row the table @code{example-table} to the variable
-@code{data}:
+Indexing variable values enables referencing portions of a variable.
+Indexes are 0 based with negative values counting backwards from the
+end.  If an index is separated by commas then each subsequent section
+indexes as the next dimension.  Note that this indexing occurs
+@emph{before} other table-related header arguments are applied, such as
+@samp{hlines}, @samp{colnames} and @samp{rownames}.  The following example 
assigns
+the last cell of the first row the table @samp{example-table} to the
+variable @samp{data}:
 
 @example
 #+NAME: example-table
@@ -15976,10 +17723,10 @@ last cell of the first row the table 
@code{example-table} to the variable
 : a
 @end example
 
-Ranges of variable values can be referenced using two integers separated by a
-@code{:}, in which case the entire inclusive range is referenced.  For
-example the following assigns the middle three rows of @code{example-table}
-to @code{data}.
+Two integers separated by a colon reference a range of variable
+values.  In that case the entire inclusive range is referenced.  For
+example the following assigns the middle three rows of @samp{example-table}
+to @samp{data}.
 
 @example
 #+NAME: example-table
@@ -16000,7 +17747,7 @@ to @code{data}.
 @end example
 
 To pick the entire range, use an empty index, or the single character
-@code{*}.  @code{0:-1} does the same thing.  Example below shows how to
+@samp{*}.  @samp{0:-1} does the same thing.  Example below shows how to
 reference the first column only.
 
 @example
@@ -16018,9 +17765,9 @@ reference the first column only.
 | 1 | 2 | 3 | 4 |
 @end example
 
-Index referencing can be used for tables and code blocks.  Index referencing
-can handle any number of dimensions.  Commas delimit multiple dimensions, as
-shown below.
+Index referencing can be used for tables and code blocks.  Index
+referencing can handle any number of dimensions.  Commas delimit
+multiple dimensions, as shown below.
 
 @example
 #+NAME: 3D
@@ -16038,15 +17785,18 @@ shown below.
 | 11 | 14 | 17 |
 @end example
 
-@subsubheading Emacs Lisp evaluation of variables
+Note that row names and column names are not removed prior to variable
+indexing.  You need to take them into account, even when @samp{colnames} or
+@samp{rownames} header arguments remove them.
 
-Emacs lisp code can set the values for variables.  To differentiate a value
-from lisp code, Org interprets any value starting with @code{(}, @code{[},
-@code{'} or @code{`} as Emacs Lisp code.  The result of evaluating that code
-is then assigned to the value of that variable.  The following example shows
-how to reliably query and pass file name of the Org mode buffer to a code
-block using headers.  We need reliability here because the file's name could
-change once the code in the block starts executing.
+Emacs lisp code can also set the values for variables.  To
+differentiate a value from Lisp code, Org interprets any value
+starting with @samp{(}, @samp{[}, @samp{'} or @samp{`} as Emacs Lisp code.  
The result of
+evaluating that code is then assigned to the value of that variable.
+The following example shows how to reliably query and pass the file
+name of the Org mode buffer to a code block using headers.  We need
+reliability here because the file's name could change once the code in
+the block starts executing.
 
 @example
 #+BEGIN_SRC sh :var filename=(buffer-file-name) :exports both
@@ -16054,8 +17804,8 @@ change once the code in the block starts executing.
 #+END_SRC
 @end example
 
-Note that values read from tables and lists will not be mistakenly evaluated
-as Emacs Lisp code, as illustrated in the following example.
+Note that values read from tables and lists are not mistakenly
+evaluated as Emacs Lisp code, as illustrated in the following example.
 
 @example
 #+NAME: table
@@ -16070,584 +17820,423 @@ as Emacs Lisp code, as illustrated in the following 
example.
 : (a b c)
 @end example
 
-@node results
-@subsubsection @code{:results}
-@cindex @code{:results}, src header argument
-
-There are four classes of @code{:results} header arguments.  Each @samp{src}
-code block can take only one option per class.
-
-@itemize @bullet
-@item
-@b{collection} for how the results should be collected from the @samp{src}
-code block
-@item
-@b{type} for which type of result the code block will return; affects how Org
-processes and inserts results in the Org buffer
-@item
-@b{format} for the result; affects how Org processes and inserts results in
-the Org buffer
-@item
-@b{handling} for processing results after evaluation of the @samp{src} code
-block
-@end itemize
-
-@subsubheading Collection
-Collection options specify the results.  Choose one of the options; they are
-mutually exclusive.
-
-@itemize @bullet
-@item @code{value}
-Default.  Functional mode.  Result is the value returned by the last
-statement in the @samp{src} code block.  Languages like Python may require an
-explicit @code{return} statement in the @samp{src} code block.  Usage
-example: @code{:results value}.
-@item @code{output}
-Scripting mode.  Result is collected from STDOUT during execution of the code
-in the @samp{src} code block.  Usage example: @code{:results output}.
-@end itemize
+@anchor{Using sessions}
+@subheading Using sessions
 
-@subsubheading Type
-Type tells what result types to expect from the execution of the code
-block.  Choose one of the options; they are mutually exclusive.  The default
-behavior is to automatically determine the result type.
-
-@itemize @bullet
-@item @code{table}, @code{vector}
-Interpret the results as an Org table.  If the result is a single value,
-create a table with one row and one column.  Usage example: @code{:results
-value table}.
-@item @code{list}
-Interpret the results as an Org list.  If the result is a single value,
-create a list of one element.
-@item @code{scalar}, @code{verbatim}
-Interpret literally and insert as quoted text.  Do not create a table.  Usage
-example: @code{:results value verbatim}.
-@item @code{file}
-Interpret as path to a file.  Inserts a link to the file.  Usage example:
-@code{:results value file}.
-@end itemize
+@cindex using sessions in code blocks
+@cindex @samp{session}, header argument
+Two code blocks can share the same environment.  The @samp{session} header
+argument is for running multiple source code blocks under one session.
+Org runs code blocks with the same session name in the same
+interpreter process.
 
-@subsubheading Format
-Format pertains to the type of the result returned by the @samp{src} code
-block.  Choose one of the options; they are mutually exclusive.  The default
-follows from the type specified above.
+@table @asis
+@item @samp{none}
+Default.  Each code block gets a new interpreter process to execute.
+The process terminates once the block is evaluated.
+
+@item @var{STRING}
+Any string besides @samp{none} turns that string into the name of that
+session.  For example, @samp{:session STRING} names it @samp{STRING}.  If
+@samp{session} has no value, then the session name is derived from the
+source language identifier.  Subsequent blocks with the same source
+code language use the same session.  Depending on the language,
+state variables, code from other blocks, and the overall interpreted
+environment may be shared.  Some interpreted languages support
+concurrent sessions when subsequent source code language blocks
+change session names.
+@end table
 
-@itemize @bullet
-@item @code{raw}
-Interpreted as raw Org mode.  Inserted directly into the buffer.  Aligned if
-it is a table.  Usage example: @code{:results value raw}.
-@item @code{org}
-Results enclosed in a @code{BEGIN_SRC org} block.  For comma-escape, either
-@key{TAB} in the block, or export the file.  Usage example: @code{:results
-value org}.
-@item @code{html}
-Results enclosed in a @code{BEGIN_EXPORT html} block.  Usage example:
-@code{:results value html}.
-@item @code{latex}
-Results enclosed in a @code{BEGIN_EXPORT latex} block.  Usage example:
-@code{:results value latex}.
-@item @code{code}
-Result enclosed in a @samp{src} code block.  Useful for parsing.  Usage
-example: @code{:results value code}.
-@item @code{pp}
-Result converted to pretty-print source code.  Enclosed in a @samp{src} code
-block.  Languages supported: Emacs Lisp, Python, and Ruby.  Usage example:
-@code{:results value pp}.
-@item @code{drawer}
-Result wrapped in a RESULTS drawer.  Useful for containing @code{raw} or
-@code{org} results for later scripting and automated processing.  Usage
-example: @code{:results value drawer}.
-@end itemize
+Only languages that provide interactive evaluation can have session
+support.  Not all languages provide this support, such as C and ditaa.
+Even languages, such as Python and Haskell, that do support
+interactive evaluation impose limitations on allowable language
+constructs that can run interactively.  Org inherits those limitations
+for those code blocks running in a session.
 
-@subsubheading Handling
-Handling options after collecting the results.
+@anchor{Choosing a working directory}
+@subheading Choosing a working directory
 
-@itemize @bullet
-@item @code{silent}
-Do not insert results in the Org mode buffer, but echo them in the
-minibuffer.  Usage example: @code{:results output silent}.
-@item @code{replace}
-Default.  Insert results in the Org buffer.  Remove previous results.  Usage
-example: @code{:results output replace}.
-@item @code{append}
-Append results to the Org buffer.  Latest results are at the bottom.  Does
-not remove previous results.  Usage example: @code{:results output append}.
-@item @code{prepend}
-Prepend results to the Org buffer.  Latest results are at the top.  Does not
-remove previous results.  Usage example: @code{:results output prepend}.
-@end itemize
+@cindex working directory, in a code block
+@cindex @samp{dir}, header argument
+@cindex @samp{mkdirp}, header argument
+The @samp{dir} header argument specifies the default directory during code
+block execution.  If it is absent, then the directory associated with
+the current buffer is used.  In other words, supplying @samp{:dir
+DIRECTORY} temporarily has the same effect as changing the current
+directory with @kbd{M-x cd @key{RET} DIRECTORY}, and then not setting
+@samp{dir}.  Under the surface, @samp{dir} simply sets the value of the Emacs
+variable @code{default-directory}.  Setting @samp{mkdirp} header argument to
+a non-@code{nil} value creates the directory, if necessary.
 
-@node file
-@subsubsection @code{:file}
-@cindex @code{:file}, src header argument
-
-An external @code{:file} that saves the results of execution of the code
-block.  The @code{:file} is either a file name or two strings, where the
-first is the file name and the second is the description.  A link to the file
-is inserted.  It uses an Org mode style @code{[[file:]]} link (@pxref{Link
-format}).  Some languages, such as @samp{R}, @samp{dot}, @samp{ditaa}, and
-@samp{gnuplot}, automatically wrap the source code in additional boilerplate
-code.  Such code wrapping helps recreate the output, especially graphics
-output, by executing just the @code{:file} contents.
-
-@node file-desc
-@subsubsection @code{:file-desc}
-
-A description of the results file.  Org uses this description for the link
-(see @ref{Link format}) it inserts in the Org file.  If the @code{:file-desc}
-has no value, Org will use file name for both the ``link'' and the
-``description'' portion of the Org mode link.
-
-@node file-ext
-@subsubsection @code{:file-ext}
-@cindex @code{:file-ext}, src header argument
-
-File name extension for the output file.  Org generates the file's complete
-name, and extension by combining @code{:file-ext}, @code{#+NAME:} of the
-source block, and the @ref{output-dir} header argument.  To override this
-auto generated file name, use the @code{:file} header argument.
-
-@node output-dir
-@subsubsection @code{:output-dir}
-@cindex @code{:output-dir}, src header argument
-
-Specifies the @code{:output-dir} for the results file.  Org accepts an
-absolute path (beginning with @code{/}) or a relative directory (without
-@code{/}).  The value can be combined with @code{#+NAME:} of the source block
-and @ref{file} or @ref{file-ext} header arguments.
-
-@node dir
-@subsubsection @code{:dir} and remote execution
-@cindex @code{:dir}, src header argument
-
-While the @code{:file} header argument can be used to specify the path to the
-output file, @code{:dir} specifies the default directory during @samp{src}
-code block execution.  If it is absent, then the directory associated with
-the current buffer is used.  In other words, supplying @code{:dir path}
-temporarily has the same effect as changing the current directory with
-@kbd{M-x cd path @key{RET}}, and then not supplying @code{:dir}.  Under the
-surface, @code{:dir} simply sets the value of the Emacs variable
-@code{default-directory}.
-
-When using @code{:dir}, relative paths (for example, @code{:file myfile.jpg}
-or @code{:file results/myfile.jpg}) become relative to the default directory.
-
-For example, to save the plot file in the @samp{Work} folder of the home
-directory (notice tilde is expanded):
+For example, to save the plot file in the @samp{Work/} folder of the home
+directory---notice tilde is expanded:
 
 @example
 #+BEGIN_SRC R :file myplot.png :dir ~/Work
-matplot(matrix(rnorm(100), 10), type="l")
+  matplot(matrix(rnorm(100), 10), type="l")
 #+END_SRC
 @end example
 
-@subsubheading Remote execution
-To evaluate the @samp{src} code block on a remote machine, supply a remote s
-directory name using @samp{Tramp} syntax.  For example:
+To evaluate the code block on a remote machine, supply a remote
+directory name using Tramp syntax.  For example:
 
 @example
 #+BEGIN_SRC R :file plot.png :dir /scp:dand@@yakuba.princeton.edu:
-plot(1:10, main=system("hostname", intern=TRUE))
+  plot(1:10, main=system("hostname", intern=TRUE))
 #+END_SRC
 @end example
 
-Org first captures the text results as usual for insertion in the Org file.
-Then Org also inserts a link to the remote file, thanks to Emacs
-@samp{Tramp}.  Org constructs the remote path to the file name from
-@code{:dir} and @code{default-directory}, as illustrated here:
+Org first captures the text results as usual for insertion in the Org
+file.  Then Org also inserts a link to the remote file, thanks to
+Emacs Tramp.  Org constructs the remote path to the file name from
+@samp{dir} and @code{default-directory}, as illustrated here:
 
 @example
 [[file:/scp:dand@@yakuba.princeton.edu:/home/dand/plot.png][plot.png]]
 @end example
 
 
-@subsubheading Some more warnings
+When @samp{dir} is used with @samp{session}, Org sets the starting directory 
for
+a new session.  But Org does not alter the directory of an already
+existing session.
 
-@itemize @bullet
-@item
-When @code{:dir} is used with @code{:session}, Org sets the starting
-directory for a new session.  But Org will not alter the directory of an
-already existing session.
-@item
-Do not use @code{:dir} with @code{:exports results} or with @code{:exports
-both} to avoid Org inserting incorrect links to remote files.  That is because
+Do not use @samp{dir} with @samp{:exports results} or with @samp{:exports 
both} to
+avoid Org inserting incorrect links to remote files.  That is because
 Org does not expand @code{default directory} to avoid some underlying
 portability issues.
-@end itemize
 
-@node exports
-@subsubsection @code{:exports}
-@cindex @code{:exports}, src header argument
-
-The @code{:exports} header argument is to specify if that part of the Org
-file is exported to, say, HTML or @LaTeX{} formats.  Note that
-@code{:exports} affects only @samp{src} code blocks and not inline code.
-
-@itemize @bullet
-@item @code{code}
-The default.  The body of code is included into the exported file.  Example:
-@code{:exports code}.
-@item @code{results}
-The results of evaluation of the code is included in the exported file.
-Example: @code{:exports results}.
-@item @code{both}
-Both the code and results of evaluation are included in the exported file.
-Example: @code{:exports both}.
-@item @code{none}
-Neither the code nor the results of evaluation is included in the exported
-file.  Whether the code is evaluated at all depends on other
-options.  Example: @code{:exports none}.
-@end itemize
+@anchor{Inserting headers and footers}
+@subheading Inserting headers and footers
 
-@node tangle
-@subsubsection @code{:tangle}
-@cindex @code{:tangle}, src header argument
-
-The @code{:tangle} header argument specifies if the @samp{src} code block is
-exported to source file(s).
-
-@itemize @bullet
-@item @code{tangle}
-Export the @samp{src} code block to source file.  The file name for the
-source file is derived from the name of the Org file, and the file extension
-is derived from the source code language identifier.  Example: @code{:tangle
-yes}.
-@item @code{no}
-The default.  Do not extract the code a source code file.  Example:
-@code{:tangle no}.
-@item other
-Export the @samp{src} code block to source file whose file name is derived
-from any string passed to the @code{:tangle} header argument.  Org derives
-the file name as being relative to the directory of the Org file's location.
-Example: @code{:tangle path}.
-@end itemize
+@cindex headers, in code blocks
+@cindex footers, in code blocks
+@cindex @samp{prologue}, header argument
+The @samp{prologue} header argument is for appending to the top of the code
+block for execution, like a reset instruction.  For example, you may
+use @samp{:prologue "reset"} in a Gnuplot code block or, for every such
+block:
 
-@node mkdirp
-@subsubsection @code{:mkdirp}
-@cindex @code{:mkdirp}, src header argument
+@lisp
+(add-to-list 'org-babel-default-header-args:gnuplot
+             '((:prologue . "reset")))
 
-The @code{:mkdirp} header argument creates parent directories for tangled
-files if the directory does not exist.  @code{yes} enables directory creation
-and @code{no} inhibits directory creation.
+@end lisp
 
-@node comments
-@subsubsection @code{:comments}
-@cindex @code{:comments}, src header argument
-Controls inserting comments into tangled files.  These are above and beyond
-whatever comments may already exist in the @samp{src} code block.
+@cindex @samp{epilogue}, header argument
+Likewise, the value of the @samp{epilogue} header argument is for appending
+to the end of the code block for execution.
 
-@itemize @bullet
-@item @code{no}
-The default.  Do not insert any extra comments during tangling.
-@item @code{link}
-Wrap the @samp{src} code block in comments.  Include links pointing back to
-the place in the Org file from where the code was tangled.
-@item @code{yes}
-Kept for backward compatibility; same as ``link''.
-@item @code{org}
-Nearest headline text from Org file is inserted as comment.  The exact text
-that is inserted is picked from the leading context of the source block.
-@item @code{both}
-Includes both ``link'' and ``org'' comment options.
-@item @code{noweb}
-Includes ``link'' comment option, expands noweb references, and wraps them in
-link comments inside the body of the @samp{src} code block.
-@end itemize
+@node Evaluating Code Blocks
+@section Evaluating Code Blocks
 
-@node padline
-@subsubsection @code{:padline}
-@cindex @code{:padline}, src header argument
-Control insertion of newlines to pad @samp{src} code blocks in the tangled
-file.
-@itemize @bullet
-@item @code{yes}
-Default.  Insert a newline before and after each @samp{src} code block in the
-tangled file.
-@item @code{no}
-Do not insert newlines to pad the tangled @samp{src} code blocks.
-@end itemize
+@cindex code block, evaluating
+@cindex source code, evaluating
+@cindex @samp{RESULTS}, keyword
 
-@node no-expand
-@subsubsection @code{:no-expand}
-@cindex @code{:no-expand}, src header argument
-
-By default Org expands @samp{src} code blocks during tangling.  The
-@code{:no-expand} header argument turns off such expansions.  Note that one
-side-effect of expansion by @code{org-babel-expand-src-block} also assigns
-values to @code{:var} (@pxref{var}) variables.  Expansions also replace Noweb
-references with their targets (@pxref{Noweb reference syntax}).  Some of
-these expansions may cause premature assignment, hence this option.  This
-option makes a difference only for tangling.  It has no effect when exporting
-since @samp{src} code blocks for execution have to be expanded anyway.
-
-@node session
-@subsubsection @code{:session}
-@cindex @code{:session}, src header argument
-
-The @code{:session} header argument is for running multiple source code
-blocks under one session.  Org runs @samp{src} code blocks with the same
-session name in the same interpreter process.
-
-@itemize @bullet
-@item @code{none}
-Default.  Each @samp{src} code block gets a new interpreter process to
-execute.  The process terminates once the block is evaluated.
-@item @code{other}
-Any string besides @code{none} turns that string into the name of that
-session.  For example, @code{:session mysession} names it @samp{mysession}.
-If @code{:session} has no argument, then the session name is derived from the
-source language identifier.  Subsequent blocks with the same source code
-language use the same session.  Depending on the language, state variables,
-code from other blocks, and the overall interpreted environment may be
-shared.  Some interpreted languages support concurrent sessions when
-subsequent source code language blocks change session names.
-@end itemize
+A note about security: With code evaluation comes the risk of harm.
+Org safeguards by prompting for user's permission before executing any
+code in the source block.  To customize this safeguard, or disable it,
+see @ref{Code Evaluation Security}.
 
-@node noweb
-@subsubsection @code{:noweb}
-@cindex @code{:noweb}, src header argument
+@anchor{How to evaluate source code}
+@subheading How to evaluate source code
 
-The @code{:noweb} header argument controls expansion of Noweb syntax
-references (@pxref{Noweb reference syntax}).  Expansions occur when source
-code blocks are evaluated, tangled, or exported.
+Org captures the results of the code block evaluation and inserts them
+in the Org file, right after the code block.  The insertion point is
+after a newline and the @samp{RESULTS} keyword.  Org creates the @samp{RESULTS}
+keyword if one is not already there.
 
-@itemize @bullet
-@item @code{no}
-Default.  No expansion of Noweb syntax references in the body of the code
-when evaluating, tangling, or exporting.
-@item @code{yes}
-Expansion of Noweb syntax references in the body of the @samp{src} code block
-when evaluating, tangling, or exporting.
-@item @code{tangle}
-Expansion of Noweb syntax references in the body of the @samp{src} code block
-when tangling.  No expansion when evaluating or exporting.
-@item @code{no-export}
-Expansion of Noweb syntax references in the body of the @samp{src} code block
-when evaluating or tangling.  No expansion when exporting.
-@item @code{strip-export}
-Expansion of Noweb syntax references in the body of the @samp{src} code block
-when expanding prior to evaluating or tangling.  Removes Noweb syntax
-references when exporting.
-@item @code{eval}
-Expansion of Noweb syntax references in the body of the @samp{src} code block
-only before evaluating.
-@end itemize
+By default, Org enables only Emacs Lisp code blocks for execution.
+See @ref{Languages} to enable other languages.
 
-@subsubheading Noweb prefix lines
-Noweb insertions now honor prefix characters that appear before the Noweb
-syntax reference.
+@kindex C-c C-c
+@kindex C-c C-v e
+@findex org-babel-execute-src-block
+Org provides many ways to execute code blocks.  @kbd{C-c C-c} or
+@kbd{C-c C-v e} with the point on a code block@footnote{The option 
@code{org-babel-no-eval-on-ctrl-c-ctrl-c} can be used
+to remove code evaluation from the @kbd{C-c C-c} key binding.} calls the
+@code{org-babel-execute-src-block} function, which executes the code in the
+block, collects the results, and inserts them in the buffer.
 
-This behavior is illustrated in the following example.  Because the
-@code{<<example>>} noweb reference appears behind the SQL comment syntax,
-each line of the expanded noweb reference will be commented.
+@cindex @samp{CALL}, keyword
+@vindex org-babel-inline-result-wrap
+By calling a named code block@footnote{Actually, the constructs 
@samp{call_<name>()} and @samp{src_<lang>@{@}}
+are not evaluated when they appear in a keyword (see @ref{In-buffer 
Settings}).} from an Org mode buffer or
+a table.  Org can call the named code blocks from the current Org mode
+buffer or from the ``Library of Babel'' (see @ref{Library of Babel}).
 
-With:
+The syntax for @samp{CALL} keyword is:
 
 @example
-#+NAME: example
-#+BEGIN_SRC text
-this is the
-multi-line body of example
-#+END_SRC
+#+CALL: <name>(<arguments>)
+#+CALL: <name>[<inside header arguments>](<arguments>) <end header arguments>
 @end example
 
-this @samp{src} code block:
+The syntax for inline named code blocks is:
 
 @example
-#+BEGIN_SRC sql :noweb yes
--- <<example>>
-#+END_SRC
+... call_<name>(<arguments>) ...
+... call_<name>[<inside header arguments>](<arguments>)[<end header 
arguments>] ...
 @end example
 
-expands to:
+When inline syntax is used, the result is wrapped based on the
+variable @code{org-babel-inline-result-wrap}, which by default is set to
+@code{"=%s="} to produce verbatim text suitable for markup.
+
+@table @asis
+@item @samp{<name>}
+This is the name of the code block (see @ref{Structure of Code Blocks})
+to be evaluated in the current document.  If the block is located in
+another file, start @samp{<name>} with the file name followed by
+a colon. For example, in order to execute a block named @samp{clear-data}
+in @samp{file.org}, you can write the following:
 
 @example
--- this is the
--- multi-line body of example
+#+CALL: file.org:clear-data()
 @end example
 
-Since this change will not affect noweb replacement text without newlines in
-them, inline noweb references are acceptable.
-
-This feature can also be used for management of indentation in exported code 
snippets.
-
-With:
+@item @samp{<arguments>}
+Org passes arguments to the code block using standard function call
+syntax.  For example, a @samp{#+CALL:} line that passes @samp{4} to a code
+block named @samp{double}, which declares the header argument @samp{:var n=2},
+would be written as:
 
 @example
-#+NAME: if-true
-#+BEGIN_SRC python :exports none
-print('Do things when True')
-#+END_SRC
-
-#+NAME: if-false
-#+BEGIN_SRC python :exports none
-print('Do things when False')
-#+END_SRC
+#+CALL: double(n=4)
 @end example
 
-this @samp{src} code block:
 
-@example
-#+BEGIN_SRC python :noweb yes :results output
-if True:
-    <<if-true>>
-else:
-    <<if-false>>
-#+END_SRC
-@end example
+@noindent
+Note how this function call syntax is different from the header
+argument syntax.
+
+@item @samp{<inside header arguments>}
+Org passes inside header arguments to the named code block using the
+header argument syntax.  Inside header arguments apply to code block
+evaluation.  For example, @samp{[:results output]} collects results
+printed to stdout during code execution of that block.  Note how
+this header argument syntax is different from the function call
+syntax.
+
+@item @samp{<end header arguments>}
+End header arguments affect the results returned by the code block.
+For example, @samp{:results html} wraps the results in a @samp{#+BEGIN_EXPORT
+  html} block before inserting the results in the Org buffer.
+@end table
 
-expands to:
+@anchor{Limit code block evaluation}
+@subheading Limit code block evaluation
 
-@example
-if True:
-    print('Do things when True')
-else:
-    print('Do things when False')
-@end example
+@cindex @samp{eval}, header argument
+@cindex control code block evaluation
+The @samp{eval} header argument can limit evaluation of specific code
+blocks and @samp{CALL} keyword.  It is useful for protection against
+evaluating untrusted code blocks by prompting for a confirmation.
 
-and evaluates to:
+@table @asis
+@item @samp{never} or @samp{no}
+Org never evaluates the source code.
 
-@example
-Do things when True
-@end example
+@item @samp{query}
+Org prompts the user for permission to evaluate the source code.
 
-@node noweb-ref
-@subsubsection @code{:noweb-ref}
-@cindex @code{:noweb-ref}, src header argument
+@item @samp{never-export} or @samp{no-export}
+Org does not evaluate the source code when exporting, yet the user
+can evaluate it interactively.
 
-When expanding Noweb style references, Org concatenates @samp{src} code
-blocks by matching the reference name to either the code block name or the
-@code{:noweb-ref} header argument.
+@item @samp{query-export}
+Org prompts the user for permission to evaluate the source code
+during export.
+@end table
 
-For simple concatenation, set this @code{:noweb-ref} header argument at the
-sub-tree or file level.  In the example Org file shown next, the body of the
-source code in each block is extracted for concatenation to a pure code file
-when tangled.
+If @samp{eval} header argument is not set, then Org determines whether to
+evaluate the source code from the @code{org-confirm-babel-evaluate}
+variable (see @ref{Code Evaluation Security}).
+
+@anchor{Cache results of evaluation}
+@subheading Cache results of evaluation
+
+@cindex @samp{cache}, header argument
+@cindex cache results of code evaluation
+The @samp{cache} header argument is for caching results of evaluating code
+blocks.  Caching results can avoid re-evaluating a code block that
+have not changed since the previous run.  To benefit from the cache
+and avoid redundant evaluations, the source block must have a result
+already present in the buffer, and neither the header
+arguments---including the value of @samp{var} references---nor the text of
+the block itself has changed since the result was last computed.  This
+feature greatly helps avoid long-running calculations.  For some edge
+cases, however, the cached results may not be reliable.
+
+The caching feature is best for when code blocks are pure functions,
+that is functions that return the same value for the same input
+arguments (see @ref{Environment of a Code Block}), and that do not have
+side effects, and do not rely on external variables other than the
+input arguments.  Functions that depend on a timer, file system
+objects, and random number generators are clearly unsuitable for
+caching.
 
-@example
- #+BEGIN_SRC sh :tangle yes :noweb yes :shebang #!/bin/sh
-   <<fullest-disk>>
- #+END_SRC
- * the mount point of the fullest disk
-   :PROPERTIES:
-   :header-args: :noweb-ref fullest-disk
-   :END:
+A note of warning: when @samp{cache} is used in a session, caching may
+cause unexpected results.
 
- ** query all mounted disks
- #+BEGIN_SRC sh
-   df \
- #+END_SRC
+When the caching mechanism tests for any source code changes, it does
+not expand Noweb style references (see @ref{Noweb Reference Syntax}).  For
+reasons why, see @uref{http://thread.gmane.org/gmane.emacs.orgmode/79046}.
 
- ** strip the header row
- #+BEGIN_SRC sh
-   |sed '1d' \
- #+END_SRC
+The @samp{cache} header argument can have one of two values: @samp{yes} or 
@samp{no}.
 
- ** output mount point of fullest disk
- #+BEGIN_SRC sh
-   |awk '@{if (u < +$5) @{u = +$5; m = $6@}@} END @{print m@}'
- #+END_SRC
+@table @asis
+@item @samp{no}
+Default.  No caching of results; code block evaluated every time.
+
+@item @samp{yes}
+Whether to run the code or return the cached results is determined
+by comparing the SHA1 hash value of the combined code block and
+arguments passed to it.  This hash value is packed on the
+@samp{#+RESULTS:} line from previous evaluation.  When hash values match,
+Org does not evaluate the code block.  When hash values mismatch,
+Org evaluates the code block, inserts the results, recalculates the
+hash value, and updates @samp{#+RESULTS:} line.
+@end table
+
+In this example, both functions are cached.  But @samp{caller} runs only if
+the result from @samp{random} has changed since the last run.
+
+@example
+#+NAME: random
+#+BEGIN_SRC R :cache yes
+  runif(1)
+#+END_SRC
+
+#+RESULTS[a2a72cd647ad44515fab62e144796432793d68e1]: random
+0.4659510825295
+
+#+NAME: caller
+#+BEGIN_SRC emacs-lisp :var x=random :cache yes
+  x
+#+END_SRC
+
+#+RESULTS[bec9c8724e397d5df3b696502df3ed7892fc4f5f]: caller
+0.254227238707244
 @end example
 
-@node noweb-sep
-@subsubsection @code{:noweb-sep}
-@cindex @code{:noweb-sep}, src header argument
+@node Results of Evaluation
+@section Results of Evaluation
 
-By default a newline separates each noweb reference concatenation.  To change
-this newline separator, edit the @code{:noweb-sep} (@pxref{noweb-sep}) header
-argument.
+@cindex code block, results of evaluation
+@cindex source code, results of evaluation
 
-@node cache
-@subsubsection @code{:cache}
-@cindex @code{:cache}, src header argument
-
-The @code{:cache} header argument is for caching results of evaluating code
-blocks.  Caching results can avoid re-evaluating @samp{src} code blocks that
-have not changed since the previous run.  To benefit from the cache and avoid
-redundant evaluations, the source block must have a result already present in
-the buffer, and neither the header arguments (including the value of
-@code{:var} references) nor the text of the block itself has changed since
-the result was last computed.  This feature greatly helps avoid long-running
-calculations.  For some edge cases, however, the cached results may not be
-reliable.
-
-The caching feature is best for when @samp{src} blocks are pure functions,
-that is functions that return the same value for the same input arguments
-(@pxref{var}), and that do not have side effects, and do not rely on external
-variables other than the input arguments.  Functions that depend on a timer,
-file system objects, and random number generators are clearly unsuitable for
-caching.
+@cindex @samp{results}, header argument
+How Org handles results of a code block execution depends on many
+header arguments working together.  The primary determinant, however,
+is the @samp{results} header argument.  It accepts four classes of options.
+Each code block can take only one option per class:
 
-A note of warning: when @code{:cache} is used for a @code{:session}, caching
-may cause unexpected results.
-
-When the caching mechanism tests for any source code changes, it will not
-expand Noweb style references (@pxref{Noweb reference syntax}).  For reasons
-why, see @uref{http://thread.gmane.org/gmane.emacs.orgmode/79046}.
-
-The @code{:cache} header argument can have one of two values: @code{yes} or
-@code{no}.
-
-@itemize @bullet
-@item @code{no}
-Default.  No caching of results; @samp{src} code block evaluated every time.
-@item @code{yes}
-Whether to run the code or return the cached results is determined by
-comparing the SHA1 hash value of the combined @samp{src} code block and
-arguments passed to it.  This hash value is packed on the @code{#+RESULTS:}
-line from previous evaluation.  When hash values match, Org does not evaluate
-the @samp{src} code block.  When hash values mismatch, Org evaluates the
-@samp{src} code block, inserts the results, recalculates the hash value, and
-updates @code{#+RESULTS:} line.
-@end itemize
+@table @asis
+@item Collection
+For how the results should be collected from the code block;
 
-In this example, both functions are cached.  But @code{caller} runs only if
-the result from @code{random} has changed since the last run.
+@item Type
+For which type of result the code block will return; affects how Org
+processes and inserts results in the Org buffer;
 
-@example
- #+NAME: random
- #+BEGIN_SRC R :cache yes
- runif(1)
- #+END_SRC
+@item Format
+For the result; affects how Org processes results;
 
- #+RESULTS[a2a72cd647ad44515fab62e144796432793d68e1]: random
- 0.4659510825295
+@item Handling
+For inserting results once they are properly formatted.
+@end table
 
- #+NAME: caller
- #+BEGIN_SRC emacs-lisp :var x=random :cache yes
- x
- #+END_SRC
+@anchor{Collection}
+@subheading Collection
+
+Collection options specify the results.  Choose one of the options;
+they are mutually exclusive.
+
+@table @asis
+@item @samp{value}
+Default.  Functional mode.  Org gets the value by wrapping the code
+in a function definition in the language of the source block.  That
+is why when using @samp{:results value}, code should execute like
+a function and return a value.  For languages like Python, an
+explicit @code{return} statement is mandatory when using @samp{:results
+  value}.  Result is the value returned by the last statement in the
+code block.
+
+When evaluating the code block in a session (see @ref{Environment of a Code 
Block}), Org passes the code to an interpreter running as an
+interactive Emacs inferior process. Org gets the value from the
+source code interpreter's last statement output.  Org has to use
+language-specific methods to obtain the value.  For example, from
+the variable @code{_} in Python and Ruby, and the value of @code{.Last.value}
+in R@.
+
+@item @samp{output}
+Scripting mode.  Org passes the code to an external process running
+the interpreter.  Org returns the contents of the standard output
+stream as text results.
+
+When using a session, Org passes the code to the interpreter running
+as an interactive Emacs inferior process.  Org concatenates any text
+output from the interpreter and returns the collection as a result.
+
+Note that this collection is not the same as that would be collected
+from stdout of a non-interactive interpreter running as an external
+process.  Compare for example these two blocks:
+
+@example
+#+BEGIN_SRC python :results output
+  print "hello"
+  2
+  print "bye"
+#+END_SRC
 
- #+RESULTS[bec9c8724e397d5df3b696502df3ed7892fc4f5f]: caller
- 0.254227238707244
+#+RESULTS:
+: hello
+: bye
 @end example
 
-@node sep
-@subsubsection @code{:sep}
-@cindex @code{:sep}, src header argument
+In the above non-session mode, the ``2'' is not printed; so it does
+not appear in results.
+
+@example
+#+BEGIN_SRC python :results output :session
+  print "hello"
+  2
+  print "bye"
+#+END_SRC
+
+#+RESULTS:
+: hello
+: 2
+: bye
+@end example
 
-The @code{:sep} header argument is the delimiter for saving results as tables
-to files (@pxref{file}) external to Org mode.  Org defaults to tab delimited
-output.  The function, @code{org-open-at-point}, which is bound to @kbd{C-c
-C-o}, also uses @code{:sep} for opening tabular results.
+In the above session, the interactive interpreter receives and
+prints ``2''.  Results show that.
+@end table
 
-@node hlines
-@subsubsection @code{:hlines}
-@cindex @code{:hlines}, src header argument
+@anchor{Type}
+@subheading Type
 
-In-between each table row or below the table headings, sometimes results have
-horizontal lines, which are also known as hlines.  The @code{:hlines}
-argument with the value @code{yes} accepts such lines.  The default is
-@code{no}.
+Type tells what result types to expect from the execution of the code
+block.  Choose one of the options; they are mutually exclusive.  The
+default behavior is to automatically determine the result type.
 
-@itemize @bullet
-@item @code{no}
-Strips horizontal lines from the input table.  For most code, this is
-desirable, or else those @code{hline} symbols raise unbound variable errors.
+@table @asis
+@item @samp{table}
+@itemx @samp{vector}
+Interpret the results as an Org table.  If the result is a single
+value, create a table with one row and one column.  Usage example:
+@samp{:results value table}.
 
-The default is @code{:hlines no}.  The example shows hlines removed from the
-input table.
+@cindex @samp{hlines}, header argument
+In-between each table row or below the table headings, sometimes
+results have horizontal lines, which are also known as ``hlines''.
+The @samp{hlines} argument with the default @samp{no} value strips such lines
+from the input table.  For most code, this is desirable, or else
+those @samp{hline} symbols raise unbound variable errors.  A @samp{yes}
+accepts such lines, as demonstrated in the following example.
 
 @example
 #+NAME: many-cols
@@ -16657,209 +18246,204 @@ input table.
 |---+---+---|
 | g | h | i |
 
-#+NAME: echo-table
-#+BEGIN_SRC python :var tab=many-cols
+#+NAME: no-hline
+#+BEGIN_SRC python :var tab=many-cols :hlines no
   return tab
 #+END_SRC
 
-#+RESULTS: echo-table
-| a | b | c |
-| d | e | f |
-| g | h | i |
-@end example
-
-@item @code{yes}
-For @code{:hlines yes}, the example shows hlines unchanged.
-
-@example
-#+NAME: many-cols
+#+RESULTS: no-hline
 | a | b | c |
-|---+---+---|
 | d | e | f |
-|---+---+---|
 | g | h | i |
 
-#+NAME: echo-table
+#+NAME: hlines
 #+BEGIN_SRC python :var tab=many-cols :hlines yes
   return tab
 #+END_SRC
 
-#+RESULTS: echo-table
+#+RESULTS: hlines
 | a | b | c |
 |---+---+---|
 | d | e | f |
 |---+---+---|
 | g | h | i |
 @end example
-@end itemize
 
-@node colnames
-@subsubsection @code{:colnames}
-@cindex @code{:colnames}, src header argument
+@item @samp{list}
+Interpret the results as an Org list.  If the result is a single
+value, create a list of one element.
 
-The @code{:colnames} header argument accepts @code{yes}, @code{no}, or
-@code{nil} values.  The default value is @code{nil}, which is unassigned.
-But this header argument behaves differently depending on the source code
-language.
+@item @samp{scalar}
+@itemx @samp{verbatim}
+Interpret literally and insert as quoted text.  Do not create
+a table.  Usage example: @samp{:results value verbatim}.
 
-@itemize @bullet
-@item @code{nil}
-If an input table has column names (because the second row is an hline), then
-Org removes the column names, processes the table, puts back the column
-names, and then writes the table to the results block.
+@item @samp{file}
+Interpret as a filename.  Save the results of execution of the code
+block to that file, then insert a link to it.  You can control both
+the filename and the description associated to the link.
 
-@example
-#+NAME: less-cols
-| a |
-|---|
-| b |
-| c |
+@cindex @samp{file}, header argument
+@cindex @samp{output-dir}, header argument
+Org first tries to generate the filename from the value of the
+@samp{file} header argument and the directory specified using the
+@samp{output-dir} header arguments.  If @samp{output-dir} is not specified,
+Org assumes it is the current directory.
 
-#+NAME: echo-table-again
-#+BEGIN_SRC python :var tab=less-cols
-  return [[val + '*' for val in row] for row in tab]
+@example
+#+BEGIN_SRC asymptote :results value file :file circle.pdf :output-dir img/
+  size(2cm);
+  draw(unitcircle);
 #+END_SRC
-
-#+RESULTS: echo-table-again
-| a  |
-|----|
-| b* |
-| c* |
 @end example
 
-Note that column names have to accounted for when using variable indexing
-(@pxref{var, Indexable variable values}) because column names are not removed
-for indexing.
+@cindex @samp{file-ext}, header argument
+If @samp{file} header argument is missing, Org generates the base name of
+the output file from the name of the code block, and its extension
+from the @samp{file-ext} header argument.  In that case, both the name
+and the extension are mandatory.
 
-@item @code{no}
-Do not pre-process column names.
+@example
+#+name: circle
+#+BEGIN_SRC asymptote :results value file :file-ext pdf
+  size(2cm);
+  draw(unitcircle);
+#+END_SRC
+@end example
 
-@item @code{yes}
-For an input table that has no hlines, process it like the @code{nil}
-value.  That is, Org removes the column names, processes the table, puts back
-the column names, and then writes the table to the results block.
-@end itemize
+@cindex @samp{file-desc}, header argument
+The @samp{file-desc} header argument defines the description (see
+@ref{Link Format}) for the link.  If @samp{file-desc} has no value, Org
+uses the generated file name for both the ``link'' and
+``description'' parts of the link.
 
-@node rownames
-@subsubsection @code{:rownames}
-@cindex @code{:rownames}, src header argument
+@cindex @samp{sep}, header argument
+By default, Org assumes that a table written to a file has
+TAB-delimited output.  You can choose a different separator with
+the @samp{sep} header argument.
+@end table
 
-The @code{:rownames} header argument can take on values @code{yes} or
-@code{no} values.  The default is @code{no}.  Note that @code{emacs-lisp}
-code blocks ignore @code{:rownames} header argument because of the ease of
-table-handling in Emacs.
+@anchor{Format}
+@subheading Format
 
-@itemize @bullet
-@item @code{no}
-Org will not pre-process row names.
+Format pertains to the type of the result returned by the code block.
+Choose one of the options; they are mutually exclusive.  The default
+follows from the type specified above.
 
-@item @code{yes}
-If an input table has row names, then Org removes the row names, processes
-the table, puts back the row names, and then writes the table to the results
-block.
+@table @asis
+@item @samp{code}
+Result enclosed in a code block.  Useful for parsing.  Usage
+example: @samp{:results value code}.
+
+@item @samp{drawer}
+Result wrapped in a @samp{RESULTS} drawer.  Useful for containing @samp{raw}
+or @samp{org} results for later scripting and automated processing.
+Usage example: @samp{:results value drawer}.
+
+@item @samp{html}
+Results enclosed in a @samp{BEGIN_EXPORT html} block.  Usage example:
+@samp{:results value html}.
+
+@item @samp{latex}
+Results enclosed in a @samp{BEGIN_EXPORT latex} block.  Usage example:
+@samp{:results value latex}.
+
+@item @samp{link}
+@itemx @samp{graphics}
+Result is a link to the file specified in @samp{:file} header argument.
+However, unlike plain @samp{:file}, nothing is written to the disk.  The
+block is used for its side-effects only, as in the following
+example:
 
 @example
-#+NAME: with-rownames
-| one | 1 | 2 | 3 | 4 |  5 |
-| two | 6 | 7 | 8 | 9 | 10 |
+#+begin_src shell :results link :file "download.tar.gz"
+wget -c "http://example.com/download.tar.gz";
+#+end_src
+@end example
 
-#+NAME: echo-table-once-again
-#+BEGIN_SRC python :var tab=with-rownames :rownames yes
-  return [[val + 10 for val in row] for row in tab]
+@item @samp{org}
+Results enclosed in a @samp{BEGIN_SRC org} block.  For comma-escape,
+either @kbd{@key{TAB}} in the block, or export the file.  Usage
+example: @samp{:results value org}.
+
+@item @samp{pp}
+Result converted to pretty-print source code.  Enclosed in a code
+block.  Languages supported: Emacs Lisp, Python, and Ruby.  Usage
+example: @samp{:results value pp}.
+
+@item @samp{raw}
+Interpreted as raw Org mode.  Inserted directly into the buffer.
+Aligned if it is a table.  Usage example: @samp{:results value raw}.
+@end table
+
+@cindex @samp{wrap}, header argument
+The @samp{wrap} header argument unconditionally marks the results block by
+appending strings to @samp{#+BEGIN_} and @samp{#+END_}.  If no string is
+specified, Org wraps the results in a @samp{#+BEGIN_results}
+@dots{} @samp{#+END_results} block.  It takes precedent over the @samp{results}
+value listed above.  E.g.,
+
+@example
+#+BEGIN_SRC emacs-lisp :results html :wrap EXPORT markdown
+"<blink>Welcome back to the 90's</blink>"
 #+END_SRC
 
-#+RESULTS: echo-table-once-again
-| one | 11 | 12 | 13 | 14 | 15 |
-| two | 16 | 17 | 18 | 19 | 20 |
+#+RESULTS:
+#+BEGIN_EXPORT markdown
+<blink>Welcome back to the 90's</blink>
+#+END_EXPORT
 @end example
 
-Note that row names have to accounted for when using variable indexing
-(@pxref{var, Indexable variable values}) because row names are not removed
-for indexing.
+@anchor{Handling}
+@subheading Handling
 
-@end itemize
+Handling options after collecting the results.
 
-@node shebang
-@subsubsection @code{:shebang}
-@cindex @code{:shebang}, src header argument
+@table @asis
+@item @samp{silent}
+Do not insert results in the Org mode buffer, but echo them in the
+minibuffer.  Usage example: @samp{:results output silent}.
 
-This header argument can turn results into executable script files.  By
-setting the @code{:shebang} header argument to a string value (for example,
-@code{:shebang "#!/bin/bash"}), Org inserts that string as the first line of
-the tangled file that the @samp{src} code block is extracted to.  Org then
-turns on the tangled file's executable permission.
+@item @samp{replace}
+Default.  Insert results in the Org buffer.  Remove previous
+results.  Usage example: @samp{:results output replace}.
 
-@node tangle-mode
-@subsubsection @code{:tangle-mode}
-@cindex @code{:tangle-mode}, src header argument
+@item @samp{append}
+Append results to the Org buffer.  Latest results are at the bottom.
+Does not remove previous results.  Usage example: @samp{:results output
+  append}.
 
-The @code{tangle-mode} header argument specifies what permissions to set for
-tangled files by @code{set-file-modes}.  For example, to make read-only
-tangled file, use @code{:tangle-mode (identity #o444)}.  To make it
-executable, use @code{:tangle-mode (identity #o755)}.
+@item @samp{prepend}
+Prepend results to the Org buffer.  Latest results are at the top.
+Does not remove previous results.  Usage example: @samp{:results output
+  prepend}.
+@end table
 
-On @samp{src} code blocks with @code{shebang} (@pxref{shebang}) header
-argument, Org will automatically set the tangled file to executable
-permissions.  But this can be overridden with custom permissions using
-@code{tangle-mode} header argument.
+@anchor{Post-processing}
+@subheading Post-processing
 
-When multiple @samp{src} code blocks tangle to a single file with different
-and conflicting @code{tangle-mode} header arguments, Org's behavior is
-undefined.
+@cindex @samp{post}, header argument
+@cindex @samp{*this*}, in @samp{post} header argument
+The @samp{post} header argument is for post-processing results from block
+evaluation.  When @samp{post} has any value, Org binds the results to
+@code{*this*} variable for easy passing to @samp{var} header argument
+specifications (see @ref{Environment of a Code Block}).  That makes results
+available to other code blocks, or even for direct Emacs Lisp code
+execution.
 
-@node eval
-@subsubsection @code{:eval}
-@cindex @code{:eval}, src header argument
-The @code{:eval} header argument can limit evaluation of specific code
-blocks.  It is useful for protection against evaluating untrusted @samp{src}
-code blocks by prompting for a confirmation.  This protection is independent
-of the @code{org-confirm-babel-evaluate} setting.
-
-@table @code
-@item never or no
-Org will never evaluate this @samp{src} code block.
-@item query
-Org prompts the user for permission to evaluate this @samp{src} code block.
-@item never-export or no-export
-Org will not evaluate this @samp{src} code block when exporting, yet the user
-can evaluate this source block interactively.
-@item query-export
-Org prompts the user for permission to export this @samp{src} code block.
-@end table
+The following two examples illustrate @samp{post} header argument in
+action.  The first one shows how to attach an @samp{ATTR_LATEX} keyword
+using @samp{post}.
 
-If @code{:eval} header argument is not set for a source block, then Org
-determines whether to evaluate from the @code{org-confirm-babel-evaluate}
-variable (@pxref{Code evaluation security}).
-
-@node wrap
-@subsubsection @code{:wrap}
-@cindex @code{:wrap}, src header argument
-The @code{:wrap} header argument marks the results block by appending strings
-to @code{#+BEGIN_} and @code{#+END_}.  If no string is specified, Org wraps
-the results in a @code{#+BEGIN/END_RESULTS} block.
-
-@node post
-@subsubsection @code{:post}
-@cindex @code{:post}, src header argument
-The @code{:post} header argument is for post-processing results from
-@samp{src} block evaluation.  When @code{:post} has any value, Org binds the
-results to @code{*this*} variable for easy passing to @ref{var} header
-argument specifications.  That makes results available to other @samp{src}
-code blocks, or for even direct Emacs Lisp code execution.
-
-The following two examples illustrate @code{:post} header argument in action.
-The first one shows how to attach @code{#+ATTR_LATEX:} line using
-@code{:post}.
-
-@example
-#+name: attr_wrap
-#+begin_src sh :var data="" :var width="\\textwidth" :results output
+@example
+#+NAME: attr_wrap
+#+BEGIN_SRC sh :var data="" :var width="\\textwidth" :results output
   echo "#+ATTR_LATEX: :width $width"
   echo "$data"
-#+end_src
+#+END_SRC
 
-#+header: :file /tmp/it.png
-#+begin_src dot :post attr_wrap(width="5cm", data=*this*) :results drawer
+#+HEADER: :file /tmp/it.png
+#+BEGIN_SRC dot :post attr_wrap(width="5cm", data=*this*) :results drawer
   digraph@{
           a -> b;
           b -> c;
@@ -16874,12 +18458,12 @@ The first one shows how to attach 
@code{#+ATTR_LATEX:} line using
 :END:
 @end example
 
-The second example shows use of @code{:colnames} in @code{:post} to pass
-data between @samp{src} code blocks.
+The second example shows use of @samp{colnames} header argument in @samp{post}
+to pass data between code blocks.
 
 @example
-#+name: round-tbl
-#+begin_src emacs-lisp :var tbl="" fmt="%.3f"
+#+NAME: round-tbl
+#+BEGIN_SRC emacs-lisp :var tbl="" fmt="%.3f"
   (mapcar (lambda (row)
             (mapcar (lambda (cell)
                       (if (numberp cell)
@@ -16889,10 +18473,10 @@ data between @samp{src} code blocks.
           tbl)
 #+end_src
 
-#+begin_src R :colnames yes :post round-tbl[:colnames yes](*this*)
-set.seed(42)
-data.frame(foo=rnorm(1))
-#+end_src
+#+BEGIN_SRC R :colnames yes :post round-tbl[:colnames yes](*this*)
+  set.seed(42)
+  data.frame(foo=rnorm(1))
+#+END_SRC
 
 #+RESULTS:
 |   foo |
@@ -16900,1268 +18484,2252 @@ data.frame(foo=rnorm(1))
 | 1.371 |
 @end example
 
-@node prologue
-@subsubsection @code{:prologue}
-@cindex @code{:prologue}, src header argument
-The @code{prologue} header argument is for appending to the top of the code
-block for execution.  For example, a clear or reset code at the start of new
-execution of a @samp{src} code block.  A @code{reset} for @samp{gnuplot}:
-@code{:prologue "reset"}.  See also @ref{epilogue}.
-
-@lisp
-(add-to-list 'org-babel-default-header-args:gnuplot
-             '((:prologue . "reset")))
-@end lisp
-
-@node epilogue
-@subsubsection @code{:epilogue}
-@cindex @code{:epilogue}, src header argument
-The value of the @code{epilogue} header argument is for appending to the end
-of the code block for execution.  See also @ref{prologue}.
+@node Exporting Code Blocks
+@section Exporting Code Blocks
 
-@node Results of evaluation
-@section Results of evaluation
-@cindex code block, results of evaluation
-@cindex source code, results of evaluation
+@cindex code block, exporting
+@cindex source code, exporting
 
-How Org handles results of a code block execution depends on many header
-arguments working together.  Here is only a summary of these.  For an
-enumeration of all the header arguments that affect results, see
-@ref{results}.
+It is possible to export the @emph{code} of code blocks, the @emph{results} of
+code block evaluation, @emph{both} the code and the results of code block
+evaluation, or @emph{none}.  Org defaults to exporting @emph{code} for most
+languages.  For some languages, such as ditaa, Org defaults to
+@emph{results}.  To export just the body of code blocks, see @ref{Literal 
Examples}.  To selectively export sub-trees of an Org document, see
+@ref{Exporting}.
 
-The primary determinant is the execution context.  Is it in a @code{:session}
-or not?  Orthogonal to that is if the expected result is a @code{:results
-value} or @code{:results output}, which is a concatenation of output from
-start to finish of the @samp{src} code block's evaluation.
+@cindex @samp{exports}, header argument
+The @samp{exports} header argument is to specify if that part of the Org
+file is exported to, say, HTML or @LaTeX{} formats.
 
-@multitable @columnfractions 0.26 0.33 0.41
-@item @tab @b{Non-session} @tab @b{Session}
-@item @code{:results value} @tab value of last expression @tab value of last 
expression
-@item @code{:results output} @tab contents of STDOUT @tab concatenation of 
interpreter output
-@end multitable
+@table @asis
+@item @samp{code}
+The default.  The body of code is included into the exported file.
+Example: @samp{:exports code}.
+
+@item @samp{results}
+The results of evaluation of the code is included in the exported
+file.  Example: @samp{:exports results}.
+
+@item @samp{both}
+Both the code and results of evaluation are included in the exported
+file.  Example: @samp{:exports both}.
+
+@item @samp{none}
+Neither the code nor the results of evaluation is included in the
+exported file.  Whether the code is evaluated at all depends on
+other options.  Example: @samp{:exports none}.
+@end table
 
-For @code{:session} and non-session, the @code{:results value} turns the
-results into an Org mode table format.  Single values are wrapped in a one
-dimensional vector.  Rows and columns of a table are wrapped in a
-two-dimensional vector.
-
-@subsection Non-session
-@subsubsection @code{:results value}
-@cindex @code{:results}, src header argument
-Default.  Org gets the value by wrapping the code in a function definition in
-the language of the @samp{src} block.  That is why when using @code{:results
-value}, code should execute like a function and return a value.  For
-languages like Python, an explicit @code{return} statement is mandatory when
-using @code{:results value}.
-
-This is one of four evaluation contexts where Org automatically wraps the
-code in a function definition.
-
-@subsubsection @code{:results output}
-@cindex @code{:results}, src header argument
-For @code{:results output}, the code is passed to an external process running
-the interpreter.  Org returns the contents of the standard output stream as
-as text results.
-
-@subsection Session
-@subsubsection @code{:results value}
-@cindex @code{:results}, src header argument
-For @code{:results value} from a @code{:session}, Org passes the code to an
-interpreter running as an interactive Emacs inferior process.  So only
-languages that provide interactive evaluation can have session support.  Not
-all languages provide this support, such as @samp{C} and @samp{ditaa}.  Even
-those that do support, such as @samp{Python} and @samp{Haskell}, they impose
-limitations on allowable language constructs that can run interactively.  Org
-inherits those limitations for those @samp{src} code blocks running in a
-@code{:session}.
-
-Org gets the value from the source code interpreter's last statement
-output.  Org has to use language-specific methods to obtain the value.  For
-example, from the variable @code{_} in @samp{Python} and @samp{Ruby}, and the
-value of @code{.Last.value} in @samp{R}).
-
-@subsubsection @code{:results output}
-@cindex @code{:results}, src header argument
-For @code{:results output}, Org passes the code to the interpreter running as
-an interactive Emacs inferior process.  Org concatenates whatever text output
-emitted by the interpreter to return the collection as a result.  Note that
-this collection is not the same as collected from @code{STDOUT} of a
-non-interactive interpreter running as an external process.  Compare for
-example these two blocks:
+@vindex org-export-use-babel
+To stop Org from evaluating code blocks to speed exports, use the
+header argument @samp{:eval never-export} (see @ref{Evaluating Code Blocks}).
+To stop Org from evaluating code blocks for greater security, set the
+@code{org-export-use-babel} variable to @code{nil}, but understand that header
+arguments will have no effect.
+
+Turning off evaluation comes in handy when batch processing.  For
+example, markup languages for wikis, which have a high risk of
+untrusted code.  Stopping code block evaluation also stops evaluation
+of all header arguments of the code block.  This may not be desirable
+in some circumstances.  So during export, to allow evaluation of just
+the header arguments but not any code evaluation in the source block,
+set @samp{:eval never-export} (see @ref{Evaluating Code Blocks}).
 
-@example
-#+BEGIN_SRC python :results output
- print "hello"
- 2
- print "bye"
-#+END_SRC
+Org never evaluates code blocks in commented sub-trees when exporting
+(see @ref{Comment Lines}).  On the other hand, Org does evaluate code
+blocks in sub-trees excluded from export (see @ref{Export Settings}).
 
-#+RESULTS:
-: hello
-: bye
-@end example
+@node Extracting Source Code
+@section Extracting Source Code
 
-In the above non-session mode, the ``2'' is not printed; so does not appear
-in results.
+@cindex tangling
+@cindex source code, extracting
+@cindex code block, extracting source code
 
-@example
-#+BEGIN_SRC python :results output :session
- print "hello"
- 2
- print "bye"
-#+END_SRC
+Extracting source code from code blocks is a basic task in literate
+programming.  Org has features to make this easy.  In literate
+programming parlance, documents on creation are @emph{woven} with code and
+documentation, and on export, the code is tangled for execution by
+a computer.  Org facilitates weaving and tangling for producing,
+maintaining, sharing, and exporting literate programming documents.
+Org provides extensive customization options for extracting source
+code.
 
-#+RESULTS:
-: hello
-: 2
-: bye
-@end example
+When Org tangles code blocks, it expands, merges, and transforms them.
+Then Org recomposes them into one or more separate files, as
+configured through the options.  During this tangling process, Org
+expands variables in the source code, and resolves any Noweb style
+references (see @ref{Noweb Reference Syntax}).
 
-In the above @code{:session} mode, the interactive interpreter receives and
-prints ``2''.  Results show that.
+@anchor{Header arguments}
+@subheading Header arguments
 
-@node Noweb reference syntax
-@section Noweb reference syntax
-@cindex code block, noweb reference
-@cindex syntax, noweb
-@cindex source code, noweb reference
+@cindex @samp{tangle}, header argument
+The @samp{tangle} header argument specifies if the code block is exported
+to source file(s).
 
-Org supports named blocks in Noweb style syntax.  For Noweb literate
-programming details, see @uref{http://www.cs.tufts.edu/~nr/noweb/}).
+@table @asis
+@item @samp{yes}
+Export the code block to source file.  The file name for the source
+file is derived from the name of the Org file, and the file
+extension is derived from the source code language identifier.
+Example: @samp{:tangle yes}.
+
+@item @samp{no}
+The default.  Do not extract the code in a source code file.
+Example: @samp{:tangle no}.
+
+@item @var{FILENAME}
+Export the code block to source file whose file name is derived from
+any string passed to the @samp{tangle} header argument.  Org derives the
+file name as being relative to the directory of the Org file's
+location.  Example: @samp{:tangle FILENAME}.
+@end table
 
-@example
-<<code-block-name>>
-@end example
+@cindex @samp{mkdirp}, header argument
+The @samp{mkdirp} header argument creates parent directories for tangled
+files if the directory does not exist.  A @samp{yes} value enables
+directory creation whereas @samp{no} inhibits it.
 
-For the header argument @code{:noweb yes}, Org expands Noweb style references
-in the @samp{src} code block before evaluation.
+@cindex @samp{comments}, header argument
+The @samp{comments} header argument controls inserting comments into
+tangled files.  These are above and beyond whatever comments may
+already exist in the code block.
 
-For the header argument @code{:noweb no}, Org does not expand Noweb style
-references in the @samp{src} code block before evaluation.
+@table @asis
+@item @samp{no}
+The default.  Do not insert any extra comments during tangling.
 
-The default is @code{:noweb no}.  Org defaults to @code{:noweb no} so as not
-to cause errors in languages where Noweb syntax is ambiguous.  Change Org's
-default to @code{:noweb yes} for languages where there is no risk of
-confusion.
+@item @samp{link}
+Wrap the code block in comments.  Include links pointing back to the
+place in the Org file from where the code was tangled.
 
-Org offers a more flexible way to resolve Noweb style references
-(@pxref{noweb-ref}).
+@item @samp{yes}
+Kept for backward compatibility; same as @samp{link}.
 
-Org can include the @emph{results} of a code block rather than its body.  To
-that effect, append parentheses, possibly including arguments, to the code
-block name, as show below.
+@item @samp{org}
+Nearest headline text from Org file is inserted as comment.  The
+exact text that is inserted is picked from the leading context of
+the source block.
 
-@example
-<<code-block-name(optional arguments)>>
-@end example
+@item @samp{both}
+Includes both @samp{link} and @samp{org} options.
 
-Note that when using the above approach to a code block's results, the code
-block name set by @code{#+NAME} keyword is required; the reference set by
-@code{:noweb-ref} will not work.
+@item @samp{noweb}
+Includes @samp{link} option, expands Noweb references (see @ref{Noweb 
Reference Syntax}), and wraps them in link comments inside the body
+of the code block.
+@end table
 
-Here is an example that demonstrates how the exported content changes when
-Noweb style references are used with parentheses versus without.
+@cindex @samp{padline}, header argument
+The @samp{padline} header argument controls insertion of newlines to pad
+source code in the tangled file.
 
-With:
+@table @asis
+@item @samp{yes}
+Default.  Insert a newline before and after each code block in the
+tangled file.
 
-@example
-#+NAME: some-code
-#+BEGIN_SRC python :var num=0 :results output :exports none
-print(num*10)
-#+END_SRC
-@end example
+@item @samp{no}
+Do not insert newlines to pad the tangled code blocks.
+@end table
 
-this code block:
+@cindex @samp{shebang}, header argument
+The @samp{shebang} header argument can turn results into executable script
+files.  By setting it to a string value---for example, @samp{:shebang
+"#!/bin/bash"}---Org inserts that string as the first line of the
+tangled file that the code block is extracted to.  Org then turns on
+the tangled file's executable permission.
+
+@cindex @samp{tangle-mode}, header argument
+The @samp{tangle-mode} header argument specifies what permissions to set
+for tangled files by @code{set-file-modes}.  For example, to make
+a read-only tangled file, use @samp{:tangle-mode (identity #o444)}.  To
+make it executable, use @samp{:tangle-mode (identity #o755)}.  It also
+overrides executable permission granted by @samp{shebang}.  When multiple
+source code blocks tangle to a single file with different and
+conflicting @samp{tangle-mode} header arguments, Org's behavior is
+undefined.
 
-@example
-#+BEGIN_SRC text :noweb yes
-<<some-code>>
-#+END_SRC
-@end example
+@cindex @samp{no-expand}, header argument
+By default Org expands code blocks during tangling.  The @samp{no-expand}
+header argument turns off such expansions.  Note that one side-effect
+of expansion by @code{org-babel-expand-src-block} also assigns values (see
+@ref{Environment of a Code Block}) to variables.  Expansions also replace
+Noweb references with their targets (see @ref{Noweb Reference Syntax}).
+Some of these expansions may cause premature assignment, hence this
+option.  This option makes a difference only for tangling.  It has no
+effect when exporting since code blocks for execution have to be
+expanded anyway.
 
-expands to:
+@anchor{Functions}
+@subheading Functions
 
-@example
-print(num*10)
-@end example
+@table @asis
+@item @code{org-babel-tangle}
+@findex org-babel-tangle
+@kindex C-c C-v t
+Tangle the current file.  Bound to @kbd{C-c C-v t}.
 
-Below, a similar Noweb style reference is used, but with parentheses, while
-setting a variable @code{num} to 10:
+With prefix argument only tangle the current code block.
 
-@example
-#+BEGIN_SRC text :noweb yes
-<<some-code(num=10)>>
-#+END_SRC
-@end example
+@item @code{org-babel-tangle-file}
+@findex org-babel-tangle-file
+@kindex C-c C-v f
+Choose a file to tangle.  Bound to @kbd{C-c C-v f}.
+@end table
 
-Note that now the expansion contains the @emph{results} of the code block
-@code{some-code}, not the code block itself:
+@anchor{Hooks (1)}
+@subheading Hooks
 
-@example
-100
-@end example
+@table @asis
+@item @code{org-babel-post-tangle-hook}
+@vindex org-babel-post-tangle-hook
+This hook is run from within code files tangled by
+@code{org-babel-tangle}, making it suitable for post-processing,
+compilation, and evaluation of code in the tangled files.
+@end table
 
-For faster tangling of large Org mode files, set
-@code{org-babel-use-quick-and-dirty-noweb-expansion} variable to @code{t}.
-The speedup comes at the expense of not correctly resolving inherited values
-of the @code{:noweb-ref} header argument.
+@anchor{Jumping between code and Org}
+@subheading Jumping between code and Org
 
+@findex org-babel-tangle-jump-to-org
+Debuggers normally link errors and messages back to the source code.
+But for tangled files, we want to link back to the Org file, not to
+the tangled source file.  To make this extra jump, Org uses
+@code{org-babel-tangle-jump-to-org} function with two additional source
+code block header arguments:
 
-@node Key bindings and useful functions
-@section Key bindings and useful functions
-@cindex code block, key bindings
+@enumerate
+@item
+Set @samp{padline} to true---this is the default setting.
+@item
+Set @samp{comments} to @samp{link}, which makes Org insert links to the Org
+file.
+@end enumerate
 
-Many common Org mode key sequences are re-bound depending on the context.
+@node Languages
+@section Languages
 
-Active key bindings in code blocks:
+@cindex babel, languages
+@cindex source code, languages
+@cindex code block, languages
 
-@multitable @columnfractions 0.25 0.75
-@kindex C-c C-c
-@item @kbd{C-c C-c} @tab @code{org-babel-execute-src-block}
-@kindex C-c C-o
-@item @kbd{C-c C-o} @tab @code{org-babel-open-src-block-result}
-@kindex M-UP
-@item @kbd{M-@key{UP}}    @tab @code{org-babel-load-in-session}
-@kindex M-DOWN
-@item @kbd{M-@key{DOWN}}  @tab @code{org-babel-switch-to-session}
+Code blocks in the following languages are supported.
+
+@multitable @columnfractions 0.20 0.35 0.20 0.20
+@headitem Language
+@tab Identifier
+@tab Language
+@tab Identifier
+@item Asymptote
+@tab @samp{asymptote}
+@tab Lisp
+@tab @samp{lisp}
+@item Awk
+@tab @samp{awk}
+@tab Lua
+@tab @samp{lua}
+@item C
+@tab @samp{C}
+@tab MATLAB
+@tab @samp{matlab}
+@item C++
+@tab @samp{C++}@footnote{C++ language is handled in @samp{ob-C.el}.  Even 
though the
+identifier for such source blocks is @samp{C++}, you activate it by loading
+the C language.}
+@tab Mscgen
+@tab @samp{mscgen}
+@item Clojure
+@tab @samp{clojure}
+@tab Objective Caml
+@tab @samp{ocaml}
+@item CSS
+@tab @samp{css}
+@tab Octave
+@tab @samp{octave}
+@item D
+@tab @samp{D}@footnote{D language is handled in @samp{ob-C.el}.  Even though 
the
+identifier for such source blocks is @samp{D}, you activate it by loading
+the C language.}
+@tab Org mode
+@tab @samp{org}
+@item ditaa
+@tab @samp{ditaa}
+@tab Oz
+@tab @samp{oz}
+@item Emacs Calc
+@tab @samp{calc}
+@tab Perl
+@tab @samp{perl}
+@item Emacs Lisp
+@tab @samp{emacs-lisp}
+@tab Plantuml
+@tab @samp{plantuml}
+@item Eshell
+@tab @samp{eshell}
+@tab Processing.js
+@tab @samp{processing}
+@item Fortran
+@tab @samp{fortran}
+@tab Python
+@tab @samp{python}
+@item Gnuplot
+@tab @samp{gnuplot}
+@tab R
+@tab @samp{R}
+@item GNU Screen
+@tab @samp{screen}
+@tab Ruby
+@tab @samp{ruby}
+@item Graphviz
+@tab @samp{dot}
+@tab Sass
+@tab @samp{sass}
+@item Haskell
+@tab @samp{haskell}
+@tab Scheme
+@tab @samp{scheme}
+@item Java
+@tab @samp{java}
+@tab Sed
+@tab @samp{sed}
+@item Javascript
+@tab @samp{js}
+@tab shell
+@tab @samp{sh}
+@item @LaTeX{}
+@tab @samp{latex}
+@tab SQL
+@tab @samp{sql}
+@item Ledger
+@tab @samp{ledger}
+@tab SQLite
+@tab @samp{sqlite}
+@item Lilypond
+@tab @samp{lilypond}
+@tab Vala
+@tab @samp{vala}
 @end multitable
 
-Active key bindings in Org mode buffer:
+Additional documentation for some languages is at
+@uref{https://orgmode.org/worg/org-contrib/babel/languages.html}.
 
-@multitable @columnfractions 0.5 0.5
-@kindex C-c C-v p
-@kindex C-c C-v C-p
-@item @kbd{C-c C-v p} @ @ @r{or} @ @ @kbd{C-c C-v C-p} @tab 
@code{org-babel-previous-src-block}
-@kindex C-c C-v n
-@kindex C-c C-v C-n
-@item @kbd{C-c C-v n} @ @ @r{or} @ @ @kbd{C-c C-v C-n} @tab 
@code{org-babel-next-src-block}
-@kindex C-c C-v e
-@kindex C-c C-v C-e
-@item @kbd{C-c C-v e} @ @ @r{or} @ @ @kbd{C-c C-v C-e} @tab 
@code{org-babel-execute-maybe}
-@kindex C-c C-v o
-@kindex C-c C-v C-o
-@item @kbd{C-c C-v o} @ @ @r{or} @ @ @kbd{C-c C-v C-o} @tab 
@code{org-babel-open-src-block-result}
-@kindex C-c C-v v
-@kindex C-c C-v C-v
-@item @kbd{C-c C-v v} @ @ @r{or} @ @ @kbd{C-c C-v C-v} @tab 
@code{org-babel-expand-src-block}
-@kindex C-c C-v u
-@kindex C-c C-v C-u
-@item @kbd{C-c C-v u} @ @ @r{or} @ @ @kbd{C-c C-v C-u} @tab 
@code{org-babel-goto-src-block-head}
-@kindex C-c C-v g
-@kindex C-c C-v C-g
-@item @kbd{C-c C-v g} @ @ @r{or} @ @ @kbd{C-c C-v C-g} @tab 
@code{org-babel-goto-named-src-block}
-@kindex C-c C-v r
-@kindex C-c C-v C-r
-@item @kbd{C-c C-v r} @ @ @r{or} @ @ @kbd{C-c C-v C-r} @tab 
@code{org-babel-goto-named-result}
-@kindex C-c C-v b
-@kindex C-c C-v C-b
-@item @kbd{C-c C-v b} @ @ @r{or} @ @ @kbd{C-c C-v C-b} @tab 
@code{org-babel-execute-buffer}
-@kindex C-c C-v s
-@kindex C-c C-v C-s
-@item @kbd{C-c C-v s} @ @ @r{or} @ @ @kbd{C-c C-v C-s} @tab 
@code{org-babel-execute-subtree}
-@kindex C-c C-v d
-@kindex C-c C-v C-d
-@item @kbd{C-c C-v d} @ @ @r{or} @ @ @kbd{C-c C-v C-d} @tab 
@code{org-babel-demarcate-block}
-@kindex C-c C-v t
-@kindex C-c C-v C-t
-@item @kbd{C-c C-v t} @ @ @r{or} @ @ @kbd{C-c C-v C-t} @tab 
@code{org-babel-tangle}
-@kindex C-c C-v f
-@kindex C-c C-v C-f
-@item @kbd{C-c C-v f} @ @ @r{or} @ @ @kbd{C-c C-v C-f} @tab 
@code{org-babel-tangle-file}
-@kindex C-c C-v c
-@kindex C-c C-v C-c
-@item @kbd{C-c C-v c} @ @ @r{or} @ @ @kbd{C-c C-v C-c} @tab 
@code{org-babel-check-src-block}
-@kindex C-c C-v j
-@kindex C-c C-v C-j
-@item @kbd{C-c C-v j} @ @ @r{or} @ @ @kbd{C-c C-v C-j} @tab 
@code{org-babel-insert-header-arg}
-@kindex C-c C-v l
-@kindex C-c C-v C-l
-@item @kbd{C-c C-v l} @ @ @r{or} @ @ @kbd{C-c C-v C-l} @tab 
@code{org-babel-load-in-session}
-@kindex C-c C-v i
-@kindex C-c C-v C-i
-@item @kbd{C-c C-v i} @ @ @r{or} @ @ @kbd{C-c C-v C-i} @tab 
@code{org-babel-lob-ingest}
-@kindex C-c C-v I
-@kindex C-c C-v C-I
-@item @kbd{C-c C-v I} @ @ @r{or} @ @ @kbd{C-c C-v C-I} @tab 
@code{org-babel-view-src-block-info}
-@kindex C-c C-v z
-@kindex C-c C-v C-z
-@item @kbd{C-c C-v z} @ @ @r{or} @ @ @kbd{C-c C-v C-z} @tab 
@code{org-babel-switch-to-session-with-code}
-@kindex C-c C-v a
-@kindex C-c C-v C-a
-@item @kbd{C-c C-v a} @ @ @r{or} @ @ @kbd{C-c C-v C-a} @tab 
@code{org-babel-sha1-hash}
-@kindex C-c C-v h
-@kindex C-c C-v C-h
-@item @kbd{C-c C-v h} @ @ @r{or} @ @ @kbd{C-c C-v C-h} @tab 
@code{org-babel-describe-bindings}
-@kindex C-c C-v x
-@kindex C-c C-v C-x
-@item @kbd{C-c C-v x} @ @ @r{or} @ @ @kbd{C-c C-v C-x} @tab 
@code{org-babel-do-key-sequence-in-edit-buffer}
-@end multitable
+@vindex org-babel-load-languages
+By default, only Emacs Lisp is enabled for evaluation.  To enable or
+disable other languages, customize the @code{org-babel-load-languages}
+variable either through the Emacs customization interface, or by
+adding code to the init file as shown next.
 
-@c Extended key bindings when control key is kept pressed:
-
-@c @multitable @columnfractions 0.25 0.75
-@c @item @kbd{C-c C-v C-a} @tab @code{org-babel-sha1-hash}
-@c @item @kbd{C-c C-v C-b} @tab @code{org-babel-execute-buffer}
-@c @item @kbd{C-c C-v C-f} @tab @code{org-babel-tangle-file}
-@c @item @kbd{C-c C-v C-l} @tab @code{org-babel-lob-ingest}
-@c @item @kbd{C-c C-v C-p} @tab @code{org-babel-expand-src-block}
-@c @item @kbd{C-c C-v C-s} @tab @code{org-babel-execute-subtree}
-@c @item @kbd{C-c C-v C-t} @tab @code{org-babel-tangle}
-@c @item @kbd{C-c C-v C-z} @tab @code{org-babel-switch-to-session}
-@c @end multitable
-
-@node Batch execution
-@section Batch execution
-@cindex code block, batch execution
-@cindex source code, batch execution
+In this example, evaluation is disabled for Emacs Lisp, and enabled
+for R@.
 
-Org mode features, including working with source code facilities can be
-invoked from the command line.  This enables building shell scripts for batch
-processing, running automated system tasks, and expanding Org mode's
-usefulness.
-
-The sample script shows batch processing of multiple files using
-@code{org-babel-tangle}.
+@lisp
+(org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((emacs-lisp . nil)
+   (R . t)))
+@end lisp
 
-@example
-#!/bin/sh
-# tangle files with org-mode
-#
-emacs -Q --batch --eval "
-    (progn
-      (require 'ob-tangle)
-      (dolist (file command-line-args-left)
-        (with-current-buffer (find-file-noselect file)
-          (org-babel-tangle))))
-  " "$@@"
-@end example
+Note that this is not the only way to enable a language.  Org also
+enables languages when loaded with @code{require} statement.  For example,
+the following enables execution of Clojure code blocks:
 
-@node Miscellaneous
-@chapter Miscellaneous
+@lisp
+(require 'ob-clojure)
+@end lisp
 
-@menu
-* Completion::                  M-@key{TAB} guesses completions
-* Easy templates::              Quick insertion of structural elements
-* Speed keys::                  Electric commands at the beginning of a 
headline
-* Code evaluation security::    Org mode files evaluate inline code
-* Customization::               Adapting Org to changing tastes
-* In-buffer settings::          Overview of the @code{#+KEYWORDS}
-* The very busy C-c C-c key::   When in doubt, press C-c C-c
-* Clean view::                  Getting rid of leading stars in the outline
-* TTY keys::                    Using Org on a tty
-* Interaction::                 With other Emacs packages
-* org-crypt::                   Encrypting Org files
-* Org Mobile::                  Viewing and capture on a mobile device
-@end menu
+@node Editing Source Code
+@section Editing Source Code
 
+@cindex code block, editing
+@cindex source code, editing
 
-@node Completion
-@section Completion
-@cindex completion, of @TeX{} symbols
-@cindex completion, of TODO keywords
-@cindex completion, of dictionary words
-@cindex completion, of option keywords
-@cindex completion, of tags
-@cindex completion, of property keys
-@cindex completion, of link abbreviations
-@cindex @TeX{} symbol completion
-@cindex TODO keywords completion
-@cindex dictionary word completion
-@cindex option keyword completion
-@cindex tag completion
-@cindex link abbreviations, completion of
+@kindex C-c '
+Use @kbd{C-c '} to edit the current code block.  It opens a new
+major mode edit buffer containing the body of the source code block,
+ready for any edits.  Use @kbd{C-c '} again to close the buffer
+and return to the Org buffer.
 
-Org has in-buffer completions.  Unlike minibuffer completions, which are
-useful for quick command interactions, Org's in-buffer completions are more
-suitable for content creation in Org documents.  Type one or more letters and
-invoke the hot key to complete the text in-place.  Depending on the context
-and the keys, Org will offer different types of completions.  No minibuffer
-is involved.  Such mode-specific hot keys have become an integral part of
-Emacs and Org provides several shortcuts.
+@kindex C-x C-s
+@vindex org-edit-src-auto-save-idle-delay
+@cindex auto-save, in code block editing
+@kbd{C-x C-s} saves the buffer and updates the contents of the
+Org buffer.  Set @code{org-edit-src-auto-save-idle-delay} to save the base
+buffer after a certain idle delay time.  Set
+@code{org-edit-src-turn-on-auto-save} to auto-save this buffer into
+a separate file using Auto-save mode.
+
+While editing the source code in the major mode, the Org Src minor
+mode remains active.  It provides these customization variables as
+described below.  For even more variables, look in the customization
+group @code{org-edit-structure}.
 
-@table @kbd
-@kindex M-TAB
-@item M-@key{TAB}
-Complete word at point
-@itemize @bullet
-@item
-At the beginning of a headline, complete TODO keywords.
-@item
-After @samp{\}, complete @TeX{} symbols supported by the exporter.
-@item
-After @samp{*}, complete headlines in the current buffer so that they
-can be used in search links like @samp{[[*find this headline]]}.
-@item
-After @samp{:} in a headline, complete tags.  The list of tags is taken
-from the variable @code{org-tag-alist} (possibly set through the
-@code{#+TAGS} in-buffer option, @pxref{Setting tags}), or it is created
-dynamically from all tags used in the current buffer.
-@item
-After @samp{:} and not in a headline, complete property keys.  The list
-of keys is constructed dynamically from all keys used in the current
-buffer.
-@item
-After @samp{[}, complete link abbreviations (@pxref{Link abbreviations}).
-@item
-After @samp{#+}, complete the special keywords like @samp{TYP_TODO} or
-file-specific @samp{OPTIONS}.  After option keyword is complete, pressing
-@kbd{M-@key{TAB}} again will insert example settings for that option.
-@item
-After @code{#+STARTUP:}, complete startup keywords.
-@item
-When the point is anywhere else, complete dictionary words using Ispell.
-@end itemize
-@kindex C-M-i
-If your desktop intercepts the combo @kbd{M-@key{TAB}} to switch windows, use
-@kbd{C-M-i} or @kbd{@key{ESC} @key{TAB}} as an alternative or customize your
-environment.
+@table @asis
+@item @code{org-src-lang-modes}
+@vindex org-src-lang-modes
+If an Emacs major-mode named @code{<LANG>-mode} exists, where
+@var{<LANG>} is the language identifier from code block's
+header line, then the edit buffer uses that major mode.  Use this
+variable to arbitrarily map language identifiers to major modes.
+
+@item @code{org-src-window-setup}
+@vindex org-src-window-setup
+For specifying Emacs window arrangement when the new edit buffer is
+created.
+
+@item @code{org-src-preserve-indentation}
+@cindex indentation, in code blocks
+@vindex org-src-preserve-indentation
+Default is @code{nil}.  Source code is indented.  This indentation
+applies during export or tangling, and depending on the context, may
+alter leading spaces and tabs.  When non-@code{nil}, source code is
+aligned with the leftmost column.  No lines are modified during
+export or tangling, which is very useful for white-space sensitive
+languages, such as Python.
+
+@item @code{org-src-ask-before-returning-to-edit-buffer}
+@vindex org-src-ask-before-returning-to-edit-buffer
+When @code{nil}, Org returns to the edit buffer without further prompts.
+The default prompts for a confirmation.
 @end table
 
-@node Easy templates
-@section Easy templates
-@cindex template insertion
-@cindex insertion, of templates
+@vindex org-src-fontify-natively
+@vindex org-src-block-faces
+Set @code{org-src-fontify-natively} to non-@code{nil} to turn on native code
+fontification in the @emph{Org} buffer.  Fontification of code blocks can
+give visual separation of text and code on the display page.  To
+further customize the appearance of @code{org-block} for specific
+languages, customize @code{org-src-block-faces}.  The following example
+shades the background of regular blocks, and colors source blocks only
+for Python and Emacs Lisp languages.
 
-With just a few keystrokes, Org's easy templates inserts empty pairs of
-structural elements, such as @code{#+BEGIN_SRC} and @code{#+END_SRC}.  Easy
-templates use an expansion mechanism, which is native to Org, in a process
-similar to @file{yasnippet} and other Emacs template expansion packages.
+@lisp
+(require 'color)
+(set-face-attribute 'org-block nil :background
+                    (color-darken-name
+                     (face-attribute 'default :background) 3))
 
-@kbd{<} @kbd{s} @kbd{@key{TAB}} expands to a @samp{src} code block.
+(setq org-src-block-faces '(("emacs-lisp" (:background "#EEE2FF"))
+                            ("python" (:background "#E5FFB8"))))
+@end lisp
 
-@kbd{<} @kbd{l} @kbd{@key{TAB}} expands to:
+@node Noweb Reference Syntax
+@section Noweb Reference Syntax
 
-#+BEGIN_EXPORT latex
+@cindex code block, Noweb reference
+@cindex syntax, Noweb
+@cindex source code, Noweb reference
 
-#+END_EXPORT
+Org supports named blocks in Noweb@footnote{For Noweb literate programming 
details, see
+@uref{http://www.cs.tufts.edu/~nr/noweb/}.} style syntax:
 
-Org comes with these pre-defined easy templates:
+@example
+<<CODE-BLOCK-ID>>
+@end example
 
-@multitable @columnfractions 0.1 0.9
-@item @kbd{s} @tab @code{#+BEGIN_SRC ... #+END_SRC}
-@item @kbd{e} @tab @code{#+BEGIN_EXAMPLE ... #+END_EXAMPLE}
-@item @kbd{q} @tab @code{#+BEGIN_QUOTE ... #+END_QUOTE}
-@item @kbd{v} @tab @code{#+BEGIN_VERSE ... #+END_VERSE}
-@item @kbd{c} @tab @code{#+BEGIN_CENTER ... #+END_CENTER}
-@item @kbd{C} @tab @code{#+BEGIN_COMMENT ... #+END_COMMENT}
-@item @kbd{l} @tab @code{#+BEGIN_EXPORT latex ... #+END_EXPORT}
-@item @kbd{L} @tab @code{#+LATEX:}
-@item @kbd{h} @tab @code{#+BEGIN_EXPORT html ... #+END_EXPORT}
-@item @kbd{H} @tab @code{#+HTML:}
-@item @kbd{a} @tab @code{#+BEGIN_EXPORT ascii ... #+END_EXPORT}
-@item @kbd{A} @tab @code{#+ASCII:}
-@item @kbd{i} @tab @code{#+INDEX:} line
-@item @kbd{I} @tab @code{#+INCLUDE:} line
-@end multitable
 
-More templates can added by customizing the variable
-@code{org-structure-template-alist}, whose docstring has additional details.
+Org can replace the construct with the source code, or the results of
+evaluation, of the code block identified as @var{CODE-BLOCK-ID}.
 
-@node Speed keys
-@section Speed keys
-@cindex speed keys
+@cindex @samp{noweb}, header argument
+The @samp{noweb} header argument controls expansion of Noweb syntax
+references.  Expansions occur when source code blocks are evaluated,
+tangled, or exported.
 
-Single keystrokes can execute custom commands in an Org file when the cursor
-is on a headline.  Without the extra burden of a meta or modifier key, Speed
-Keys can speed navigation or execute custom commands.  Besides faster
-navigation, Speed Keys may come in handy on small mobile devices that do not
-have full keyboards.  Speed Keys may also work on TTY devices known for their
-problems when entering Emacs keychords.
+@table @asis
+@item @samp{no}
+Default.  No expansion of Noweb syntax references in the body of the
+code when evaluating, tangling, or exporting.
 
-@vindex org-use-speed-commands
-By default, Org has Speed Keys disabled.  To activate Speed Keys, set the
-variable @code{org-use-speed-commands} to a non-@code{nil} value.  To trigger
-a Speed Key, the cursor must be at the beginning of an Org headline, before
-any of the stars.
+@item @samp{yes}
+Expansion of Noweb syntax references in the body of the code block
+when evaluating, tangling, or exporting.
 
-@vindex org-speed-commands-user
-@findex org-speed-command-help
-Org comes with a pre-defined list of Speed Keys.  To add or modify Speed
-Keys, customize the variable, @code{org-speed-commands-user}.  For more
-details, see the variable's docstring.  With Speed Keys activated, @kbd{M-x
-org-speed-command-help}, or @kbd{?} when cursor is at the beginning of an Org
-headline, shows currently active Speed Keys, including the user-defined ones.
+@item @samp{tangle}
+Expansion of Noweb syntax references in the body of the code block
+when tangling.  No expansion when evaluating or exporting.
 
+@item @samp{no-export}
+Expansion of Noweb syntax references in the body of the code block
+when evaluating or tangling.  No expansion when exporting.
 
-@node Code evaluation security
-@section Code evaluation and security issues
+@item @samp{strip-export}
+Expansion of Noweb syntax references in the body of the code block
+when expanding prior to evaluating or tangling.  Removes Noweb
+syntax references when exporting.
 
-Unlike plain text, running code comes with risk.  Each @samp{src} code block,
-in terms of risk, is equivalent to an executable file.  Org therefore puts a
-few confirmation prompts by default.  This is to alert the casual user from
-accidentally running untrusted code.
+@item @samp{eval}
+Expansion of Noweb syntax references in the body of the code block
+only before evaluating.
+@end table
 
-For users who do not run code blocks or write code regularly, Org's default
-settings should suffice.  However, some users may want to tweak the prompts
-for fewer interruptions.  To weigh the risks of automatic execution of code
-blocks, here are some details about code evaluation.
+In the following example,
 
-Org evaluates code in the following circumstances:
+@example
+#+NAME: initialization
+#+BEGIN_SRC emacs-lisp
+  (setq sentence "Never a foot too far, even.")
+#+END_SRC
 
-@table @i
-@item Source code blocks
-Org evaluates @samp{src} code blocks in an Org file during export.  Org also
-evaluates a @samp{src} code block with the @kbd{C-c C-c} key chord.  Users
-exporting or running code blocks must load files only from trusted sources.
-Be wary of customizing variables that remove or alter default security
-measures.
+#+BEGIN_SRC emacs-lisp :noweb yes
+  <<initialization>>
+  (reverse sentence)
+#+END_SRC
+@end example
 
-@defopt org-confirm-babel-evaluate
-When @code{t}, Org prompts the user for confirmation before executing each
-code block.  When @code{nil}, Org executes code blocks without prompting the
-user for confirmation.  When this option is set to a custom function, Org
-invokes the function with these two arguments: the source code language and
-the body of the code block.  The custom function must return either a
-@code{t} or @code{nil}, which determines if the user is prompted.  Each
-source code language can be handled separately through this function
-argument.
-@end defopt
+@noindent
+the second code block is expanded as
 
-For example, this function enables execution of @samp{ditaa} code +blocks
-without prompting:
+@example
+#+BEGIN_SRC emacs-lisp :noweb yes
+  (setq sentence "Never a foot too far, even.")
+  (reverse sentence)
+#+END_SRC
+@end example
 
-@lisp
-(defun my-org-confirm-babel-evaluate (lang body)
-  (not (string= lang "ditaa")))  ; don't ask for ditaa
-(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
-@end lisp
+Noweb insertions honor prefix characters that appear before the Noweb
+syntax reference.  This behavior is illustrated in the following
+example.  Because the @samp{<<example>>} Noweb reference appears behind the
+SQL comment syntax, each line of the expanded Noweb reference is
+commented.  With:
+
+@example
+#+NAME: example
+#+BEGIN_SRC text
+  this is the
+  multi-line body of example
+#+END_SRC
+@end example
 
-@item Following @code{shell} and @code{elisp} links
-Org has two link types that can also directly evaluate code (@pxref{External
-links}).  Because such code is not visible, these links have a potential
-risk.  Org therefore prompts the user when it encounters such links.  The
-customization variables are:
+@noindent
+this code block:
 
-@defopt org-confirm-shell-link-function
-Function that prompts the user before executing a shell link.
-@end defopt
-@defopt org-confirm-elisp-link-function
-Function that prompts the user before executing an Emacs Lisp link.
-@end defopt
+@example
+#+BEGIN_SRC sql :noweb yes
+ ---<<example>>
+#+END_SRC
+@end example
 
-@item Formulas in tables
-Org executes formulas in tables (@pxref{The spreadsheet}) either through the
-@emph{calc} or the @emph{Emacs Lisp} interpreters.
-@end table
+@noindent
+expands to:
 
-@node Customization
-@section Customization
-@cindex customization
-@cindex options, for customization
-@cindex variables, for customization
+@example
+#+BEGIN_SRC sql :noweb yes
+ ---this is the
+ ---multi-line body of example
+#+END_SRC
+@end example
 
-Org has more than 500 variables for customization.  They can be accessed
-through the usual @kbd{M-x org-customize @key{RET}} command.  Or through the
-Org menu, @code{Org->Customization->Browse Org Group}.  Org also has per-file
-settings for some variables (@pxref{In-buffer settings}).
+Since this change does not affect Noweb replacement text without
+newlines in them, inline Noweb references are acceptable.
 
-@node In-buffer settings
-@section Summary of in-buffer settings
-@cindex in-buffer settings
-@cindex special keywords
-In-buffer settings start with @samp{#+}, followed by a keyword, a colon, and
-then a word for each setting.  Org accepts multiple settings on the same
-line.  Org also accepts multiple lines for a keyword.  This manual describes
-these settings throughout.  A summary follows here.
+This feature can also be used for management of indentation in
+exported code snippets.  With:
 
-@kbd{C-c C-c} activates any changes to the in-buffer settings.  Closing and
-reopening the Org file in Emacs also activates the changes.
+@example
+#+NAME: if-true
+#+BEGIN_SRC python :exports none
+  print('do things when true')
+#+end_src
 
-@vindex org-archive-location
-@table @kbd
-@item #+ARCHIVE: %s_done::
-Sets the archive location of the agenda file.  This location applies to the
-lines until the next @code{#+ARCHIVE} line, if any, in the Org file.  The
-first archive location in the Org file also applies to any entries before it.
-The corresponding variable is @code{org-archive-location}.
-@item #+CATEGORY:
-Sets the category of the agenda file, which applies to the entire document.
-@item #+COLUMNS: %25ITEM ...
-@cindex property, @code{COLUMNS}
-Sets the default format for columns view.  Org uses this format for column
-views where there is no @code{COLUMNS} property.
-@item #+CONSTANTS: name1=value1 ...
-@vindex org-table-formula-constants
-@vindex org-table-formula
-Set file-local values for constants that table formulas can use.  This 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:
-Set tags that all entries in the file will inherit from here, including the
-top-level entries.
-@item #+LINK: linkword replace
-@vindex org-link-abbrev-alist
-Each line specifies one abbreviation for one link.  Use multiple
-@code{#+LINK:} lines for more, @pxref{Link abbreviations}.  The corresponding
-variable is @code{org-link-abbrev-alist}.
-@item #+PRIORITIES: highest lowest default
-@vindex org-highest-priority
-@vindex org-lowest-priority
-@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 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.
-@cindex @code{#+SETUPFILE}
-@item #+SETUPFILE: file or URL
-The setup file or a URL pointing to such file is for additional in-buffer
-settings.  Org loads this file and parses it for any settings in it only when
-Org opens the main file.  If URL is specified, the contents are downloaded
-and stored in a temporary file cache.  @kbd{C-c C-c} on the settings line
-will parse and load the file, and also reset the temporary file cache.  Org
-also parses and loads the document during normal exporting process.  Org
-parses the contents of this document as if it was included in the buffer.  It
-can be another Org file.  To visit the file (not a URL), @kbd{C-c '} while
-the cursor is on the line with the file name.
-@item #+STARTUP:
-@cindex @code{#+STARTUP}
-Startup options Org uses when first visiting a file.
+#+name: if-false
+#+begin_src python :exports none
+  print('do things when false')
+#+end_src
+@end example
 
-The first set of options deals with the initial visibility of the outline
-tree.  The corresponding variable for global default settings is
-@code{org-startup-folded} with a default value of @code{t}, which is the same
-as @code{overview}.
+@noindent
+this code block:
 
-@vindex org-startup-folded
-@cindex @code{overview}, STARTUP keyword
-@cindex @code{content}, STARTUP keyword
-@cindex @code{showall}, STARTUP keyword
-@cindex @code{showeverything}, STARTUP keyword
 @example
-overview         @r{top-level headlines only}
-content          @r{all headlines}
-showall          @r{no folding of any entries}
-showeverything   @r{show even drawer contents}
+#+begin_src python :noweb yes :results output
+  if true:
+      <<if-true>>
+  else:
+      <<if-false>>
+#+end_src
 @end example
 
-@vindex org-startup-indented
-@cindex @code{indent}, STARTUP keyword
-@cindex @code{noindent}, STARTUP keyword
-Dynamic virtual indentation is controlled by the variable
-@code{org-startup-indented}
+@noindent
+expands to:
+
 @example
-indent     @r{start with @code{org-indent-mode} turned on}
-noindent   @r{start with @code{org-indent-mode} turned off}
+if true:
+    print('do things when true')
+else:
+    print('do things when false')
 @end example
 
-@vindex org-startup-align-all-tables
-Aligns tables consistently upon visiting a file; useful for restoring
-narrowed table columns.  The corresponding variable is
-@code{org-startup-align-all-tables} with @code{nil} as default value.
+@cindex @samp{noweb-ref}, header argument
+When expanding Noweb style references, Org concatenates code blocks by
+matching the reference name to either the code block name or, if none
+is found, to the @samp{noweb-ref} header argument.
+
+For simple concatenation, set this @samp{noweb-ref} header argument at the
+sub-tree or file level.  In the example Org file shown next, the body
+of the source code in each block is extracted for concatenation to
+a pure code file when tangled.
 
-@cindex @code{align}, STARTUP keyword
-@cindex @code{noalign}, STARTUP keyword
 @example
-align      @r{align all tables}
-noalign    @r{don't align tables on startup}
+#+BEGIN_SRC sh :tangle yes :noweb yes :shebang #!/bin/sh
+  <<fullest-disk>>
+#+END_SRC
+* the mount point of the fullest disk
+  :PROPERTIES:
+  :header-args: :noweb-ref fullest-disk
+  :END:
+
+** query all mounted disks
+#+BEGIN_SRC sh
+  df \
+#+END_SRC
+
+** strip the header row
+#+BEGIN_SRC sh
+  |sed '1d' \
+#+END_SRC
+
+** output mount point of fullest disk
+#+BEGIN_SRC sh
+  |awk '@{if (u < +$5) @{u = +$5; m = $6@}@} END @{print m@}'
+#+END_SRC
 @end example
 
-@vindex org-startup-with-inline-images
-Whether Org should automatically display inline images.  The corresponding
-variable is @code{org-startup-with-inline-images}, with a default value
-@code{nil} to avoid delays when visiting a file.
-@cindex @code{inlineimages}, STARTUP keyword
-@cindex @code{noinlineimages}, STARTUP keyword
+@cindex @samp{noweb-sep}, header argument
+By default a newline separates each noweb reference concatenation.  To
+change this newline separator, edit the @samp{noweb-sep} header argument.
+
+Eventually, Org can include the results of a code block rather than
+its body.  To that effect, append parentheses, possibly including
+arguments, to the code block name, as shown below.
+
 @example
-inlineimages   @r{show inline images}
-noinlineimages @r{don't show inline images on startup}
+<<code-block-name(optional arguments)>>
 @end example
 
-@vindex org-startup-with-latex-preview
-Whether Org should automatically convert @LaTeX{} fragments to images.  The
-variable @code{org-startup-with-latex-preview}, which controls this setting,
-is set to @code{nil} by default to avoid startup delays.
-@cindex @code{latexpreview}, STARTUP keyword
-@cindex @code{nolatexpreview}, STARTUP keyword
+
+Note that when using the above approach to a code block's results, the
+code block name set by @samp{NAME} keyword is required; the reference set
+by @samp{noweb-ref} does not work in that case.
+
+Here is an example that demonstrates how the exported content changes
+when Noweb style references are used with parentheses versus without.
+With:
+
 @example
-latexpreview   @r{preview @LaTeX{} fragments}
-nolatexpreview @r{don't preview @LaTeX{} fragments}
+#+NAME: some-code
+#+BEGIN_SRC python :var num=0 :results output :exports none
+  print(num*10)
+#+END_SRC
 @end example
 
-@vindex org-log-done
-@vindex org-log-note-clock-out
-@vindex org-log-repeat
-Logging the closing and reopening of TODO items and clock intervals can be
-configured using these options (see variables @code{org-log-done},
-@code{org-log-note-clock-out} and @code{org-log-repeat})
-@cindex @code{logdone}, STARTUP keyword
-@cindex @code{lognotedone}, STARTUP keyword
-@cindex @code{nologdone}, STARTUP keyword
-@cindex @code{lognoteclock-out}, STARTUP keyword
-@cindex @code{nolognoteclock-out}, STARTUP keyword
-@cindex @code{logrepeat}, STARTUP keyword
-@cindex @code{lognoterepeat}, STARTUP keyword
-@cindex @code{nologrepeat}, STARTUP keyword
-@cindex @code{logreschedule}, STARTUP keyword
-@cindex @code{lognotereschedule}, STARTUP keyword
-@cindex @code{nologreschedule}, STARTUP keyword
-@cindex @code{logredeadline}, STARTUP keyword
-@cindex @code{lognoteredeadline}, STARTUP keyword
-@cindex @code{nologredeadline}, STARTUP keyword
-@cindex @code{logrefile}, STARTUP keyword
-@cindex @code{lognoterefile}, STARTUP keyword
-@cindex @code{nologrefile}, STARTUP keyword
-@cindex @code{logdrawer}, STARTUP keyword
-@cindex @code{nologdrawer}, STARTUP keyword
-@cindex @code{logstatesreversed}, STARTUP keyword
-@cindex @code{nologstatesreversed}, STARTUP keyword
-@example
-logdone             @r{record a timestamp when an item is marked DONE}
-lognotedone         @r{record timestamp and a note when DONE}
-nologdone           @r{don't record when items are marked DONE}
-logrepeat           @r{record a time when reinstating a repeating item}
-lognoterepeat       @r{record a note when reinstating a repeating item}
-nologrepeat         @r{do not record when reinstating repeating item}
-lognoteclock-out    @r{record a note when clocking out}
-nolognoteclock-out  @r{don't record a note when clocking out}
-logreschedule       @r{record a timestamp when scheduling time changes}
-lognotereschedule   @r{record a note when scheduling time changes}
-nologreschedule     @r{do not record when a scheduling date changes}
-logredeadline       @r{record a timestamp when deadline changes}
-lognoteredeadline   @r{record a note when deadline changes}
-nologredeadline     @r{do not record when a deadline date changes}
-logrefile           @r{record a timestamp when refiling}
-lognoterefile       @r{record a note when refiling}
-nologrefile         @r{do not record when refiling}
-logdrawer           @r{store log into drawer}
-nologdrawer         @r{store log outside of drawer}
-logstatesreversed   @r{reverse the order of states notes}
-nologstatesreversed @r{do not reverse the order of states notes}
+@noindent
+this code block:
+
+@example
+#+BEGIN_SRC text :noweb yes
+  <<some-code>>
+#+END_SRC
 @end example
 
-@vindex org-hide-leading-stars
-@vindex org-odd-levels-only
-These options hide leading stars in outline headings, and indent outlines.
-The corresponding variables are @code{org-hide-leading-stars} and
-@code{org-odd-levels-only}, both with a default setting of @code{nil}
-(meaning @code{showstars} and @code{oddeven}).
-@cindex @code{hidestars}, STARTUP keyword
-@cindex @code{showstars}, STARTUP keyword
-@cindex @code{odd}, STARTUP keyword
-@cindex @code{even}, STARTUP keyword
-@example
-hidestars  @r{hide all stars on the headline except one.}
-showstars  @r{show all stars on the headline}
-indent     @r{virtual indents according to the outline level}
-noindent   @r{no virtual indents}
-odd        @r{show odd outline levels only (1,3,...)}
-oddeven    @r{show all outline levels}
+@noindent
+expands to:
+
+@example
+print(num*10)
 @end example
 
-@vindex org-put-time-stamp-overlays
-@vindex org-time-stamp-overlay-formats
-To turn on custom format overlays over timestamps (variables
-@code{org-put-time-stamp-overlays} and
-@code{org-time-stamp-overlay-formats}), use
-@cindex @code{customtime}, STARTUP keyword
+
+Below, a similar Noweb style reference is used, but with parentheses,
+while setting a variable @samp{num} to 10:
+
 @example
-customtime @r{overlay custom time format}
+#+BEGIN_SRC text :noweb yes
+  <<some-code(num=10)>>
+#+END_SRC
 @end example
 
-@vindex constants-unit-system
-The following options influence the table spreadsheet (variable
-@code{constants-unit-system}).
-@cindex @code{constcgs}, STARTUP keyword
-@cindex @code{constSI}, STARTUP keyword
+@noindent
+Note that now the expansion contains the results of the code block
+@samp{some-code}, not the code block itself:
+
 @example
-constcgs   @r{@file{constants.el} should use the c-g-s unit system}
-constSI    @r{@file{constants.el} should use the SI unit system}
+100
 @end example
 
-@vindex org-footnote-define-inline
-@vindex org-footnote-auto-label
-@vindex org-footnote-auto-adjust
-For footnote settings, use the following keywords.  The corresponding
-variables are @code{org-footnote-define-inline},
-@code{org-footnote-auto-label}, and @code{org-footnote-auto-adjust}.
-@cindex @code{fninline}, STARTUP keyword
-@cindex @code{nofninline}, STARTUP keyword
-@cindex @code{fnlocal}, STARTUP keyword
-@cindex @code{fnprompt}, STARTUP keyword
-@cindex @code{fnauto}, STARTUP keyword
-@cindex @code{fnconfirm}, STARTUP keyword
-@cindex @code{fnplain}, STARTUP keyword
-@cindex @code{fnadjust}, STARTUP keyword
-@cindex @code{nofnadjust}, STARTUP keyword
-@example
-fninline    @r{define footnotes inline}
-fnnoinline  @r{define footnotes in separate section}
-fnlocal     @r{define footnotes near first reference, but not inline}
-fnprompt    @r{prompt for footnote labels}
-fnauto      @r{create @code{[fn:1]}-like labels automatically (default)}
-fnconfirm   @r{offer automatic label for editing or confirmation}
-fnplain     @r{create @code{[1]}-like labels automatically}
-fnadjust    @r{automatically renumber and sort footnotes}
-nofnadjust  @r{do not renumber and sort automatically}
-@end example
-
-@cindex @code{org-hide-block-startup}
-To hide blocks on startup, use these keywords.  The corresponding variable is
-@code{org-hide-block-startup}.
-@cindex @code{hideblocks}, STARTUP keyword
-@cindex @code{nohideblocks}, STARTUP keyword
-@example
-hideblocks   @r{Hide all begin/end blocks on startup}
-nohideblocks @r{Do not hide blocks on startup}
-@end example
-
-@cindex @code{org-pretty-entities}
-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 UTF-8 characters where possible}
-entitiesplain   @r{Leave entities plain}
-@end example
-
-@item #+TAGS:  TAG1(c1) TAG2(c2)
-@vindex org-tag-alist
-These lines specify valid tags for this file.  Org accepts multiple tags
-lines.  Tags could correspond to the @emph{fast tag selection} keys.  The
-corresponding variable is @code{org-tag-alist}.
-@cindex @code{#+TBLFM}
-@item #+TBLFM:
-This line is for formulas for the table directly above.  A table can have
-multiple @code{#+TBLFM:} lines.  On table recalculation, Org applies only the
-first @code{#+TBLFM:} line.  For details see @ref{Using multiple #+TBLFM
-lines} in @ref{Editing and debugging formulas}.
-@item #+TITLE:, #+AUTHOR:, #+EMAIL:, #+LANGUAGE:, #+DATE:,
-@itemx #+OPTIONS:, #+BIND:,
-@itemx #+SELECT_TAGS:, #+EXCLUDE_TAGS:
-These lines provide settings for exporting files.  For more details see
-@ref{Export settings}.
-@item #+TODO:    #+SEQ_TODO:   #+TYP_TODO:
-@vindex org-todo-keywords
-These lines set the TODO keywords and their significance to the current file.
-The corresponding variable is @code{org-todo-keywords}.
-@end table
+@node Library of Babel
+@section Library of Babel
 
-@node The very busy C-c C-c key
-@section The very busy C-c C-c key
-@kindex C-c C-c
-@cindex @kbd{C-c C-c}, overview
+@cindex babel, library of
+@cindex source code, library
+@cindex code block, library
 
-The @kbd{C-c C-c} key in Org serves many purposes depending on the context.
-It is probably the most over-worked, multi-purpose key combination in Org.
-Its uses are well-documented through out this manual, but here is a
-consolidated list for easy reference.
+The ``Library of Babel'' is a collection of code blocks.  Like
+a function library, these code blocks can be called from other Org
+files.  A collection of useful code blocks is available on 
@uref{https://orgmode.org/worg/library-of-babel.html, Worg}.  For
+remote code block evaluation syntax, see @ref{Evaluating Code Blocks}.
 
-@itemize @minus
-@item
-If any highlights shown in the buffer from the creation of a sparse tree, or
-from clock display, remove such highlights.
-@item
-If the cursor is in one of the special @code{#+KEYWORD} lines, scan the
-buffer for these lines and update the information.  Also reset the Org file
-cache used to temporary store the contents of URLs used as values for
-keywords like @code{#+SETUPFILE}.
-@item
-If the cursor is inside a table, realign the table.  The table realigns even
-if automatic table editor is turned off.
-@item
-If the cursor is on a @code{#+TBLFM} line, re-apply the formulas to
-the entire table.
-@item
-If the current buffer is a capture buffer, close the note and file it.  With
-a prefix argument, also jump to the target location after saving the note.
-@item
-If the cursor is on a @code{<<<target>>>}, update radio targets and
-corresponding links in this buffer.
-@item
-If the cursor is on a property line or at the start or end of a property
-drawer, offer property commands.
-@item
-If the cursor is at a footnote reference, go to the corresponding
-definition, and @emph{vice versa}.
-@item
-If the cursor is on a statistics cookie, update it.
-@item
-If the cursor is in a plain list item with a checkbox, toggle the status
-of the checkbox.
-@item
-If the cursor is on a numbered item in a plain list, renumber the
-ordered list.
-@item
-If the cursor is on the @code{#+BEGIN} line of a dynamic block, the
-block is updated.
-@item
-If the cursor is at a timestamp, fix the day name in the timestamp.
-@end itemize
+@kindex C-c C-v i
+@findex org-babel-lob-ingest
+For any user to add code to the library, first save the code in
+regular code blocks of an Org file, and then load the Org file with
+@code{org-babel-lob-ingest}, which is bound to @kbd{C-c C-v i}.
 
-@node Clean view
-@section A cleaner outline view
-@cindex hiding leading stars
-@cindex dynamic indentation
-@cindex odd-levels-only outlines
-@cindex clean outline view
+@node Key bindings and Useful Functions
+@section Key bindings and Useful Functions
 
-Org's default outline with stars and no indents can become too cluttered for
-short documents.  For @emph{book-like} long documents, the effect is not as
-noticeable.  Org provides an alternate stars and indentation scheme, as shown
-on the right in the following table.  It uses only one star and indents text
-to line with the heading:
+@cindex code block, key bindings
 
-@example
-@group
-* Top level headline             |    * Top level headline
-** Second level                  |      * Second level
-*** 3rd level                    |        * 3rd level
+Many common Org mode key sequences are re-bound depending on
+the context.
+
+Active key bindings in code blocks:
+
+@kindex C-c C-c
+@findex org-babel-execute-src-block
+@kindex C-c C-o
+@findex org-babel-open-src-block-result
+@kindex M-UP
+@findex org-babel-load-in-session
+@kindex M-DOWN
+@findex org-babel-pop-to-session
+@multitable @columnfractions 0.2 0.55
+@headitem Key binding
+@tab Function
+@item @kbd{C-c C-c}
+@tab @code{org-babel-execute-src-block}
+@item @kbd{C-c C-o}
+@tab @code{org-babel-open-src-block-result}
+@item @kbd{M-@key{UP}}
+@tab @code{org-babel-load-in-session}
+@item @kbd{M-@key{DOWN}}
+@tab @code{org-babel-pop-to-session}
+@end multitable
+
+Active key bindings in Org mode buffer:
+
+@kindex C-c C-v p
+@kindex C-c C-v C-p
+@kindex C-c C-v n
+@kindex C-c C-v C-n
+@kindex C-c C-v e
+@kindex C-c C-v C-e
+@kindex C-c C-v o
+@kindex C-c C-v C-o
+@kindex C-c C-v v
+@kindex C-c C-v C-v
+@kindex C-c C-v u
+@kindex C-c C-v C-u
+@kindex C-c C-v g
+@kindex C-c C-v C-g
+@kindex C-c C-v r
+@kindex C-c C-v C-r
+@kindex C-c C-v b
+@kindex C-c C-v C-b
+@kindex C-c C-v s
+@kindex C-c C-v C-s
+@kindex C-c C-v d
+@kindex C-c C-v C-d
+@kindex C-c C-v t
+@kindex C-c C-v C-t
+@kindex C-c C-v f
+@kindex C-c C-v C-f
+@kindex C-c C-v c
+@kindex C-c C-v C-c
+@kindex C-c C-v j
+@kindex C-c C-v C-j
+@kindex C-c C-v l
+@kindex C-c C-v C-l
+@kindex C-c C-v i
+@kindex C-c C-v C-i
+@kindex C-c C-v I
+@kindex C-c C-v C-I
+@kindex C-c C-v z
+@kindex C-c C-v C-z
+@kindex C-c C-v a
+@kindex C-c C-v C-a
+@kindex C-c C-v h
+@kindex C-c C-v C-h
+@kindex C-c C-v x
+@kindex C-c C-v C-x
+@findex org-babel-previous-src-block
+@findex org-babel-next-src-block
+@findex org-babel-execute-maybe
+@findex org-babel-open-src-block-result
+@findex org-babel-expand-src-block
+@findex org-babel-goto-src-block-head
+@findex org-babel-goto-named-src-block
+@findex org-babel-goto-named-result
+@findex org-babel-execute-buffer
+@findex org-babel-execute-subtree
+@findex org-babel-demarcate-block
+@findex org-babel-tangle
+@findex org-babel-tangle-file
+@findex org-babel-check-src-block
+@findex org-babel-insert-header-arg
+@findex org-babel-load-in-session
+@findex org-babel-lob-ingest
+@findex org-babel-view-src-block-info
+@findex org-babel-switch-to-session-with-code
+@findex org-babel-sha1-hash
+@findex org-babel-describe-bindings
+@findex org-babel-do-key-sequence-in-edit-buffer
+@multitable @columnfractions 0.45 0.55
+@headitem Key binding
+@tab Function
+@item @kbd{C-c C-v p} or @kbd{C-c C-v C-p}
+@tab @code{org-babel-previous-src-block}
+@item @kbd{C-c C-v n} or @kbd{C-c C-v C-n}
+@tab @code{org-babel-next-src-block}
+@item @kbd{C-c C-v e} or @kbd{C-c C-v C-e}
+@tab @code{org-babel-execute-maybe}
+@item @kbd{C-c C-v o} or @kbd{C-c C-v C-o}
+@tab @code{org-babel-open-src-block-result}
+@item @kbd{C-c C-v v} or @kbd{C-c C-v C-v}
+@tab @code{org-babel-expand-src-block}
+@item @kbd{C-c C-v u} or @kbd{C-c C-v C-u}
+@tab @code{org-babel-goto-src-block-head}
+@item @kbd{C-c C-v g} or @kbd{C-c C-v C-g}
+@tab @code{org-babel-goto-named-src-block}
+@item @kbd{C-c C-v r} or @kbd{C-c C-v C-r}
+@tab @code{org-babel-goto-named-result}
+@item @kbd{C-c C-v b} or @kbd{C-c C-v C-b}
+@tab @code{org-babel-execute-buffer}
+@item @kbd{C-c C-v s} or @kbd{C-c C-v C-s}
+@tab @code{org-babel-execute-subtree}
+@item @kbd{C-c C-v d} or @kbd{C-c C-v C-d}
+@tab @code{org-babel-demarcate-block}
+@item @kbd{C-c C-v t} or @kbd{C-c C-v C-t}
+@tab @code{org-babel-tangle}
+@item @kbd{C-c C-v f} or @kbd{C-c C-v C-f}
+@tab @code{org-babel-tangle-file}
+@item @kbd{C-c C-v c} or @kbd{C-c C-v C-c}
+@tab @code{org-babel-check-src-block}
+@item @kbd{C-c C-v j} or @kbd{C-c C-v C-j}
+@tab @code{org-babel-insert-header-arg}
+@item @kbd{C-c C-v l} or @kbd{C-c C-v C-l}
+@tab @code{org-babel-load-in-session}
+@item @kbd{C-c C-v i} or @kbd{C-c C-v C-i}
+@tab @code{org-babel-lob-ingest}
+@item @kbd{C-c C-v I} or @kbd{C-c C-v C-I}
+@tab @code{org-babel-view-src-block-info}
+@item @kbd{C-c C-v z} or @kbd{C-c C-v C-z}
+@tab @code{org-babel-switch-to-session-with-code}
+@item @kbd{C-c C-v a} or @kbd{C-c C-v C-a}
+@tab @code{org-babel-sha1-hash}
+@item @kbd{C-c C-v h} or @kbd{C-c C-v C-h}
+@tab @code{org-babel-describe-bindings}
+@item @kbd{C-c C-v x} or @kbd{C-c C-v C-x}
+@tab @code{org-babel-do-key-sequence-in-edit-buffer}
+@end multitable
+
+@node Batch Execution
+@section Batch Execution
+
+@cindex code block, batch execution
+@cindex source code, batch execution
+
+Org mode features, including working with source code facilities can
+be invoked from the command line.  This enables building shell scripts
+for batch processing, running automated system tasks, and expanding
+Org mode's usefulness.
+
+The sample script shows batch processing of multiple files using
+@code{org-babel-tangle}.
+
+@example
+#!/bin/sh
+# Tangle files with Org mode
+#
+emacs -Q --batch --eval "
+    (progn
+      (require 'ob-tangle)
+      (dolist (file command-line-args-left)
+        (with-current-buffer (find-file-noselect file)
+          (org-babel-tangle))))
+  " "$@@"
+@end example
+
+@node Miscellaneous
+@chapter Miscellaneous
+
+@menu
+* Completion::                   @kbd{M-@key{TAB}} guesses completions.
+* Structure Templates::          Quick insertion of structural elements.
+* Speed Keys::                   Electric commands at the beginning of a 
headline.
+* Clean View::                   Getting rid of leading stars in the outline.
+* Dynamic Headline Numbering::   Display and update outline numbering.
+* The Very Busy @kbd{C-c C-c} Key:: When in doubt, press @kbd{C-c C-c}.
+* In-buffer Settings::           Overview of keywords.
+* Org Syntax::                   Formal description of Org's syntax.
+* Documentation Access::         Read documentation about current syntax.
+* Escape Character::
+* Code Evaluation Security::     Org files evaluate in-line code.
+* Interaction::                  With other Emacs packages.
+* TTY Keys::                     Using Org on a tty.
+* Protocols::                    External access to Emacs and Org.
+* Org Crypt::                    Encrypting Org files.
+* Org Mobile::                   Viewing and capture on a mobile device.
+@end menu
+
+@node Completion
+@section Completion
+
+@cindex completion, of @TeX{} symbols
+@cindex completion, of TODO keywords
+@cindex completion, of dictionary words
+@cindex completion, of option keywords
+@cindex completion, of tags
+@cindex completion, of property keys
+@cindex completion, of link abbreviations
+@cindex @TeX{} symbol completion
+@cindex TODO keywords completion
+@cindex dictionary word completion
+@cindex option keyword completion
+@cindex tag completion
+@cindex link abbreviations, completion of
+
+Org has in-buffer completions.  Unlike minibuffer completions, which
+are useful for quick command interactions, Org's in-buffer completions
+are more suitable for content creation in Org documents.  Type one or
+more letters and invoke the hot key to complete the text in-place.
+Depending on the context and the keys, Org offers different types of
+completions.  No minibuffer is involved.  Such mode-specific hot keys
+have become an integral part of Emacs and Org provides several
+shortcuts.
+
+@table @asis
+@item @kbd{M-@key{TAB}}
+@kindex M-TAB
+
+Complete word at point.
+
+@itemize
+@item
+At the beginning of an empty headline, complete TODO keywords.
+
+@item
+After @samp{\}, complete @TeX{} symbols supported by the exporter.
+
+@item
+After @samp{*}, complete headlines in the current buffer so that they
+can be used in search links like: @samp{[[*find this headline]]}
+
+@item
+After @samp{:} in a headline, complete tags.  Org deduces the list of
+tags from the @samp{TAGS} in-buffer option (see @ref{Setting Tags}), the
+variable @code{org-tag-alist}, or from all tags used in the current
+buffer.
+
+@item
+After @samp{:} and not in a headline, complete property keys.  The list
+of keys is constructed dynamically from all keys used in the
+current buffer.
+
+@item
+After @samp{[}, complete link abbreviations (see @ref{Link Abbreviations}).
+
+@item
+After @samp{#+}, complete the special keywords like @samp{TYP_TODO} or
+file-specific @samp{OPTIONS}.  After option keyword is complete,
+pressing @kbd{M-@key{TAB}} again inserts example settings for this
+keyword.
+
+@item
+After @samp{STARTUP} keyword, complete startup items.
+
+@item
+When point is anywhere else, complete dictionary words using
+Ispell.
+@end itemize
+@end table
+
+@node Structure Templates
+@section Structure Templates
+
+@cindex template insertion
+@cindex insertion, of templates
+
+With just a few keystrokes, it is possible to insert empty structural
+blocks, such as @samp{#+BEGIN_SRC} @dots{} @samp{#+END_SRC}, or to wrap 
existing
+text in such a block.
+
+@table @asis
+@item @kbd{C-c C-,} (@code{org-insert-structure-template})
+@findex org-insert-structure-template
+@kindex C-c C-,
+Prompt for a type of block structure, and insert the block at point.
+If the region is active, it is wrapped in the block.  First prompts
+the user for keys, which are used to look up a structure type from
+the variable below.  If the key is @kbd{@key{TAB}}, @kbd{@key{RET}},
+or @kbd{@key{SPC}}, the user is prompted to enter a block type.
+@end table
+
+@vindex org-structure-template-alist
+Available structure types are defined in
+@code{org-structure-template-alist}, see the docstring for adding or
+changing values.
+
+@cindex Tempo
+@cindex template expansion
+@cindex insertion, of templates
+@vindex org-tempo-keywords-alist
+Org Tempo expands snippets to structures defined in
+@code{org-structure-template-alist} and @code{org-tempo-keywords-alist}.  For
+example, @kbd{< s @key{TAB}} creates a code block.  Enable it by
+customizing @code{org-modules} or add @samp{(require 'org-tempo)} to your Emacs
+init file@footnote{For more information, please refer to the commentary section
+in @samp{org-tempo.el}.}.
+
+@multitable @columnfractions 0.1 0.9
+@item @kbd{a}
+@tab @samp{#+BEGIN_EXPORT ascii} @dots{} @samp{#+END_EXPORT}
+@item @kbd{c}
+@tab @samp{#+BEGIN_CENTER} @dots{} @samp{#+END_CENTER}
+@item @kbd{C}
+@tab @samp{#+BEGIN_COMMENT} @dots{} @samp{#+END_COMMENT}
+@item @kbd{e}
+@tab @samp{#+BEGIN_EXAMPLE} @dots{} @samp{#+END_EXAMPLE}
+@item @kbd{E}
+@tab @samp{#+BEGIN_EXPORT} @dots{} @samp{#+END_EXPORT}
+@item @kbd{h}
+@tab @samp{#+BEGIN_EXPORT html} @dots{} @samp{#+END_EXPORT}
+@item @kbd{l}
+@tab @samp{#+BEGIN_EXPORT latex} @dots{} @samp{#+END_EXPORT}
+@item @kbd{q}
+@tab @samp{#+BEGIN_QUOTE} @dots{} @samp{#+END_QUOTE}
+@item @kbd{s}
+@tab @samp{#+BEGIN_SRC} @dots{} @samp{#+END_SRC}
+@item @kbd{v}
+@tab @samp{#+BEGIN_VERSE} @dots{} @samp{#+END_VERSE}
+@end multitable
+
+@node Speed Keys
+@section Speed Keys
+
+@cindex speed keys
+
+Single keystrokes can execute custom commands in an Org file when
+point is on a headline.  Without the extra burden of a meta or
+modifier key, Speed Keys can speed navigation or execute custom
+commands.  Besides faster navigation, Speed Keys may come in handy on
+small mobile devices that do not have full keyboards.  Speed Keys may
+also work on TTY devices known for their problems when entering Emacs
+key chords.
+
+@vindex org-use-speed-commands
+By default, Org has Speed Keys disabled.  To activate Speed Keys, set
+the variable @code{org-use-speed-commands} to a non-@code{nil} value.  To
+trigger a Speed Key, point must be at the beginning of an Org
+headline, before any of the stars.
+
+@vindex org-speed-commands-user
+@findex org-speed-command-help
+Org comes with a pre-defined list of Speed Keys.  To add or modify
+Speed Keys, customize the variable, @code{org-speed-commands-user}.  For
+more details, see the variable's docstring.  With Speed Keys
+activated, @kbd{M-x org-speed-command-help}, or @kbd{?} when
+point is at the beginning of an Org headline, shows currently active
+Speed Keys, including the user-defined ones.
+
+@node Clean View
+@section A Cleaner Outline View
+
+@cindex hiding leading stars
+@cindex dynamic indentation
+@cindex odd-levels-only outlines
+@cindex clean outline view
+
+Org's outline with stars and no indents can look cluttered for short
+documents.  For @emph{book-like} long documents, the effect is not as
+noticeable.  Org provides an alternate stars and indentation scheme,
+as shown on the right in the following table.  It displays only one
+star and indents text to line up with the heading:
+
+@example
+* Top level headline             |    * Top level headline
+** Second level                  |      * Second level
+*** Third level                  |        * Third level
 some text                        |          some text
-*** 3rd level                    |        * 3rd level
+*** Third level                  |        * Third level
 more text                        |          more text
 * Another top level headline     |    * Another top level headline
-@end group
 @end example
 
+Org can achieve this in two ways, (1) by just displaying the buffer in
+this way without changing it, or (2) by actually indenting every line
+in the desired amount with hard spaces and hiding leading stars.
+
+@menu
+* Org Indent Mode::
+* Hard indentation::
+@end menu
+
+@node Org Indent Mode
+@subsection Org Indent Mode
+
+@cindex Indent mode
+@findex org-indent-mode
+To display the buffer in the indented view, activate Org Indent minor
+mode, using @kbd{M-x org-indent-mode}.  Text lines that are not
+headlines are prefixed with virtual spaces to vertically align with
+the headline text@footnote{Org Indent mode also sets @code{wrap-prefix} 
correctly for
+indenting and wrapping long lines of headlines or text.  This minor
+mode also handles Visual Line mode and directly applied settings
+through @code{word-wrap}.}.
+
+@vindex org-indent-indentation-per-level
+To make more horizontal space, the headlines are shifted by two
+characters.  Configure @code{org-indent-indentation-per-level} variable for
+a different number.  Only one star on each headline is visible, the
+rest are masked with the same font color as the background@footnote{Note that 
turning on Org Indent mode sets
+@code{org-hide-leading-stars} to @code{t} and @code{org-adapt-indentation} to 
@code{nil}.}.
+
+@vindex org-startup-indented
+To globally turn on Org Indent mode for all files, customize the
+variable @code{org-startup-indented}.  To control it for individual files,
+use @samp{STARTUP} keyword as follows:
+
+@example
+#+STARTUP: indent
+#+STARTUP: noindent
+@end example
+
+@node Hard indentation
+@subsection Hard indentation
+
+It is possible to use hard spaces to achieve the indentation instead,
+if the bare ASCII file should have the indented look also outside
+Emacs@footnote{This works, but requires extra effort.  Org Indent mode is
+more convenient for most applications.}.  With Org's support, you have to 
indent all lines to
+line up with the outline headers.  You would use these settings:
+
+@lisp
+(setq org-adapt-indentation t
+      org-hide-leading-stars t
+      org-odd-levels-only t)
+@end lisp
+
+@table @asis
+@item @emph{Indentation of text below headlines} (@code{org-adapt-indentation})
+@vindex org-adapt-indentation
+The first setting modifies paragraph filling, line wrapping, and
+structure editing commands to preserving or adapting the indentation
+as appropriate.
+
+@item @emph{Hiding leading stars} (@code{org-hide-leading-stars})
+@vindex org-hide-leading-stars
+@vindex org-hide, face
+The second setting makes leading stars invisible by applying the
+face @code{org-hide} to them.  For per-file preference, use these file
+@samp{STARTUP} options:
+
+@example
+#+STARTUP: hidestars
+#+STARTUP: showstars
+@end example
+
+@item @emph{Odd levels} (@code{org-odd-levels-only})
+@vindex org-odd-levels-only
+The third setting makes Org use only odd levels, 1, 3, 5, @dots{}, in
+the outline to create more indentation.  On a  per-file level,
+control this with:
+
+@example
+#+STARTUP: odd
+#+STARTUP: oddeven
+@end example
+
+To convert a file between single and double stars layouts, use
+@kbd{M-x org-convert-to-odd-levels} and @kbd{M-x 
org-convert-to-oddeven-levels}.
+@end table
+
+@node Dynamic Headline Numbering
+@section Dynamic Headline Numbering
+
+@cindex Org Num mode
+@cindex number headlines
+The Org Num minor mode, toggled with @kbd{M-x org-num-mode},
+displays outline numbering on top of headlines.  It also updates it
+automatically upon changes to the structure of the document.
+
+@vindex org-num-max-level
+@vindex org-num-skip-tags
+@vindex org-num-skip-commented
+@vindex org-num-skip-unnumbered
+By default, all headlines are numbered.  You can limit numbering to
+specific headlines according to their level, tags, @samp{COMMENT} keyword,
+or @samp{UNNUMBERED} property.  Set @code{org-num-max-level},
+@code{org-num-skip-tags}, @code{org-num-skip-commented},
+@code{org-num-skip-unnumbered}, or @code{org-num-skip-footnotes} accordingly.
+
+@vindex org-num-skip-footnotes
+If @code{org-num-skip-footnotes} is non-@code{nil}, footnotes sections (see
+@ref{Creating Footnotes}) are not numbered either.
+
+@vindex org-num-face
+@vindex org-num-format-function
+You can control how the numbering is displayed by setting
+@code{org-num-face} and @code{org-num-format-function}.
+
+@node The Very Busy @kbd{C-c C-c} Key
+@section The Very Busy @kbd{C-c C-c} Key
+
+@kindex C-c C-c
+@cindex @kbd{C-c C-c}, overview
+
+The @kbd{C-c C-c} key in Org serves many purposes depending on
+the context.  It is probably the most over-worked, multi-purpose key
+combination in Org.  Its uses are well documented throughout this
+manual, but here is a consolidated list for easy reference.
+
+@itemize
+@item
+If any highlights shown in the buffer from the creation of a sparse
+tree, or from clock display, remove such highlights.
+
+@item
+If point is in one of the special @samp{KEYWORD} lines, scan the buffer
+for these lines and update the information.  Also reset the Org file
+cache used to temporary store the contents of URLs used as values
+for keywords like @samp{SETUPFILE}.
+
+@item
+If point is inside a table, realign the table.
+
+@item
+If point is on a @samp{TBLFM} keyword, re-apply the formulas to the
+entire table.
+
+@item
+If the current buffer is a capture buffer, close the note and file
+it.  With a prefix argument, also jump to the target location after
+saving the note.
+
+@item
+If point is on a @samp{<<<target>>>}, update radio targets and
+corresponding links in this buffer.
+
+@item
+If point is on a property line or at the start or end of a property
+drawer, offer property commands.
+
+@item
+If point is at a footnote reference, go to the corresponding
+definition, and @emph{vice versa}.
+
+@item
+If point is on a statistics cookie, update it.
+
+@item
+If point is in a plain list item with a checkbox, toggle the status
+of the checkbox.
+
+@item
+If point is on a numbered item in a plain list, renumber the ordered
+list.
+
+@item
+If point is on the @samp{#+BEGIN} line of a dynamic block, the block is
+updated.
+
+@item
+If point is at a timestamp, fix the day name in the timestamp.
+@end itemize
+
+@node In-buffer Settings
+@section Summary of In-Buffer Settings
+
+@cindex in-buffer settings
+@cindex special keywords
+
+In-buffer settings start with @samp{#+}, followed by a keyword, a colon,
+and then a word for each setting.  Org accepts multiple settings on
+the same line.  Org also accepts multiple lines for a keyword.  This
+manual describes these settings throughout.  A summary follows here.
+
+@cindex refresh set-up
+@kbd{C-c C-c} activates any changes to the in-buffer settings.
+Closing and reopening the Org file in Emacs also activates the
+changes.
+
+@table @asis
+@item @samp{#+ARCHIVE: %s_done}
+@cindex @samp{ARCHIVE}, keyword
+@vindex org-archive-location
+Sets the archive location of the agenda file.  The corresponding
+variable is @code{org-archive-location}.
+
+@item @samp{#+CATEGORY}
+@cindex @samp{CATEGORY}, keyword
+Sets the category of the agenda file, which applies to the entire
+document.
+
+@item @samp{#+COLUMNS: %25ITEM ...}
+@cindex @samp{COLUMNS}, property
+Set the default format for columns view.  This format applies when
+columns view is invoked in locations where no @samp{COLUMNS} property
+applies.
+
+@item @samp{#+CONSTANTS: name1=value1 ...}
+@cindex @samp{CONSTANTS}, keyword
+@vindex org-table-formula-constants
+@vindex org-table-formula
+Set file-local values for constants that table formulas can use.
+This line sets the local variable
+@code{org-table-formula-constants-local}.  The global version of this
+variable is @code{org-table-formula-constants}.
+
+@item @samp{#+FILETAGS: :tag1:tag2:tag3:}
+@cindex @samp{FILETAGS}, keyword
+Set tags that all entries in the file inherit from, including the
+top-level entries.
+
+@item @samp{#+LINK: linkword replace}
+@cindex @samp{LINK}, keyword
+@vindex org-link-abbrev-alist
+Each line specifies one abbreviation for one link.  Use multiple
+@samp{LINK} keywords for more, see @ref{Link Abbreviations}.  The
+corresponding variable is @code{org-link-abbrev-alist}.
+
+@item @samp{#+PRIORITIES: highest lowest default}
+@cindex @samp{PRIORITIES}, keyword
+@vindex org-highest-priority
+@vindex org-lowest-priority
+@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 than the lowest priority.
+
+@item @samp{#+PROPERTY: Property_Name Value}
+@cindex @samp{PROPERTY}, keyword
+This line sets a default inheritance value for entries in the
+current buffer, most useful for specifying the allowed values of
+a property.
+
+@item @samp{#+SETUPFILE: file}
+@cindex @samp{SETUPFILE}, keyword
+The setup file or a URL pointing to such file is for additional
+in-buffer settings.  Org loads this file and parses it for any
+settings in it only when Org opens the main file.  If URL is
+specified, the contents are downloaded and stored in a temporary
+file cache.  @kbd{C-c C-c} on the settings line parses and
+loads the file, and also resets the temporary file cache.  Org also
+parses and loads the document during normal exporting process.  Org
+parses the contents of this document as if it was included in the
+buffer.  It can be another Org file.  To visit the file---not
+a URL---use @kbd{C-c '} while point is on the line with the
+file name.
+
+@item @samp{#+STARTUP:}
+@cindex @samp{STARTUP}, keyword
+Startup options Org uses when first visiting a file.
+
+@vindex org-startup-folded
+The first set of options deals with the initial visibility of the
+outline tree.  The corresponding variable for global default
+settings is @code{org-startup-folded} with a default value of @code{t}, which
+is the same as @code{overview}.
+
+@multitable {aaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{overview}
+@tab Top-level headlines only.
+@item @samp{content}
+@tab All headlines.
+@item @samp{showall}
+@tab No folding on any entry.
+@item @samp{showeverything}
+@tab Show even drawer contents.
+@end multitable
+
+@vindex org-startup-indented
+Dynamic virtual indentation is controlled by the variable
+@code{org-startup-indented}@footnote{Note that Org Indent mode also sets the 
@code{wrap-prefix}
+property, such that Visual Line mode (or purely setting @code{word-wrap})
+wraps long lines, including headlines, correctly indented.}.
+
+@multitable {aaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{indent}
+@tab Start with Org Indent mode turned on.
+@item @samp{noindent}
+@tab Start with Org Indent mode turned off.
+@end multitable
+
+@vindex org-startup-align-all-tables
+Aligns tables consistently upon visiting a file.  The
+corresponding variable is @code{org-startup-align-all-tables} with
+@code{nil} as default value.
+
+@multitable {aaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{align}
+@tab Align all tables.
+@item @samp{noalign}
+@tab Do not align tables on startup.
+@end multitable
+
+@vindex org-startup-shrink-all-tables
+Shrink table columns with a width cookie.  The corresponding
+variable is @code{org-startup-shrink-all-tables} with @code{nil} as
+default value.
+
+@vindex org-startup-with-inline-images
+When visiting a file, inline images can be automatically
+displayed.  The corresponding variable is
+@code{org-startup-with-inline-images}, with a default value @code{nil} to
+avoid delays when visiting a file.
+
+@multitable {aaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{inlineimages}
+@tab Show inline images.
+@item @samp{noinlineimages}
+@tab Do not show inline images on startup.
+@end multitable
+
+@vindex org-log-done
+@vindex org-log-note-clock-out
+@vindex org-log-repeat
+Logging the closing and reopening of TODO items and clock
+intervals can be configured using these options (see variables
+@code{org-log-done}, @code{org-log-note-clock-out}, and @code{org-log-repeat}).
+
+@multitable {aaaaaaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{logdone}
+@tab Record a timestamp when an item is marked as done.
+@item @samp{lognotedone}
+@tab Record timestamp and a note when DONE@.
+@item @samp{nologdone}
+@tab Do not record when items are marked as done.
+@item @samp{logrepeat}
+@tab Record a time when reinstating a repeating item.
+@item @samp{lognoterepeat}
+@tab Record a note when reinstating a repeating item.
+@item @samp{nologrepeat}
+@tab Do not record when reinstating repeating item.
+@item @samp{lognoteclock-out}
+@tab Record a note when clocking out.
+@item @samp{nolognoteclock-out}
+@tab Do not record a note when clocking out.
+@item @samp{logreschedule}
+@tab Record a timestamp when scheduling time changes.
+@item @samp{lognotereschedule}
+@tab Record a note when scheduling time changes.
+@item @samp{nologreschedule}
+@tab Do not record when a scheduling date changes.
+@item @samp{logredeadline}
+@tab Record a timestamp when deadline changes.
+@item @samp{lognoteredeadline}
+@tab Record a note when deadline changes.
+@item @samp{nologredeadline}
+@tab Do not record when a deadline date changes.
+@item @samp{logrefile}
+@tab Record a timestamp when refiling.
+@item @samp{lognoterefile}
+@tab Record a note when refiling.
+@item @samp{nologrefile}
+@tab Do not record when refiling.
+@end multitable
+
+@vindex org-hide-leading-stars
+@vindex org-odd-levels-only
+Here are the options for hiding leading stars in outline
+headings, and for indenting outlines.  The corresponding
+variables are @code{org-hide-leading-stars} and
+@code{org-odd-levels-only}, both with a default setting @code{nil}
+(meaning @samp{showstars} and @samp{oddeven}).
+
+@multitable {aaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{hidestars}
+@tab Make all but one of the stars starting a headline invisible.
+@item @samp{showstars}
+@tab Show all stars starting a headline.
+@item @samp{indent}
+@tab Virtual indentation according to outline level.
+@item @samp{noindent}
+@tab No virtual indentation according to outline level.
+@item @samp{odd}
+@tab Allow only odd outline levels (1, 3, @dots{}).
+@item @samp{oddeven}
+@tab Allow all outline levels.
+@end multitable
+
+@vindex org-put-time-stamp-overlays
+@vindex org-time-stamp-overlay-formats
+To turn on custom format overlays over timestamps (variables
+@code{org-put-time-stamp-overlays} and
+@code{org-time-stamp-overlay-formats}), use:
+
+@multitable {aaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{customtime}
+@tab Overlay custom time format.
+@end multitable
+
+@vindex constants-unit-system
+The following options influence the table spreadsheet (variable
+@code{constants-unit-system}).
+
+@multitable {aaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{constcgs}
+@tab @samp{constants.el} should use the c-g-s unit system.
+@item @samp{constSI}
+@tab @samp{constants.el} should use the SI unit system.
+@end multitable
+
+@vindex org-footnote-define-inline
+@vindex org-footnote-auto-label
+@vindex org-footnote-auto-adjust
+To influence footnote settings, use the following keywords.  The
+corresponding variables are @code{org-footnote-define-inline},
+@code{org-footnote-auto-label}, and @code{org-footnote-auto-adjust}.
+
+@multitable {aaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{fninline}
+@tab Define footnotes inline.
+@item @samp{fnnoinline}
+@tab Define footnotes in separate section.
+@item @samp{fnlocal}
+@tab Define footnotes near first reference, but not inline.
+@item @samp{fnprompt}
+@tab Prompt for footnote labels.
+@item @samp{fnauto}
+@tab Create @samp{[fn:1]}-like labels automatically (default).
+@item @samp{fnconfirm}
+@tab Offer automatic label for editing or confirmation.
+@item @samp{fnadjust}
+@tab Automatically renumber and sort footnotes.
+@item @samp{nofnadjust}
+@tab Do not renumber and sort automatically.
+@end multitable
+
+@vindex org-hide-block-startup
+To hide blocks on startup, use these keywords.  The
+corresponding variable is @code{org-hide-block-startup}.
+
+@multitable {aaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{hideblocks}
+@tab Hide all begin/end blocks on startup.
+@item @samp{nohideblocks}
+@tab Do not hide blocks on startup.
+@end multitable
+
+@vindex org-pretty-entities
+The display of entities as UTF-8 characters is governed by the
+variable @code{org-pretty-entities} and the keywords
+
+@multitable {aaaaaaaaaaaaaaaa} 
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @samp{entitiespretty}
+@tab Show entities as UTF-8 characters where possible.
+@item @samp{entitiesplain}
+@tab Leave entities plain.
+@end multitable
+
+@item @samp{#+TAGS: TAG1(c1) TAG2(c2)}
+@cindex @samp{TAGS}, keyword
+@vindex org-tag-alist
+These lines (several such lines are allowed) specify the valid tags
+in this file, and (potentially) the corresponding @emph{fast tag
+selection} keys.  The corresponding variable is @code{org-tag-alist}.
+
+@item @samp{#+TODO:}
+@itemx @samp{#+SEQ_TODO:}
+@itemx @samp{#+TYP_TODO:}
+@cindex @samp{SEQ_TODO}, keyword
+@cindex @samp{TODO}, keyword
+@cindex @samp{TYP_TODO}, keyword
+@vindex org-todo-keywords
+These lines set the TODO keywords and their interpretation in the
+current file.  The corresponding variable is @code{org-todo-keywords}.
+@end table
+
+@node Org Syntax
+@section Org Syntax
+
+A reference document providing a formal description of Org's syntax is
+available as @uref{https://orgmode.org/worg/dev/org-syntax.html, a draft on 
Worg}, written and maintained by Nicolas
+Goaziou.  It defines Org's core internal concepts such as ``headlines'',
+``sections'', ``affiliated keywords'', ``(greater) elements'' and ``objects''.
+Each part of an Org document belongs to one of the previous
+categories.
+
+To explore the abstract structure of an Org buffer, run this in
+a buffer:
+
+@example
+M-: (org-element-parse-buffer) <RET>
+@end example
+
+
 @noindent
+It outputs a list containing the buffer's content represented as an
+abstract structure.  The export engine relies on the information
+stored in this list.  Most interactive commands---e.g., for structure
+editing---also rely on the syntactic meaning of the surrounding
+context.
+
+@cindex syntax checker
+@cindex linter
+@findex org-lint
+You can probe the syntax of your documents with the command
+
+@example
+M-x org-lint <RET>
+@end example
+
+
+@noindent
+It runs a number of checks to find common mistakes.  It then displays
+their location in a dedicated buffer, along with a description and
+a ``trust level'', since false-positive are possible.  From there, you
+can operate on the reports with the following keys:
+
+@multitable @columnfractions 0.22 0.78
+@item @kbd{C-j}, @kbd{@key{TAB}}
+@tab Display the offending line
+@item @kbd{@key{RET}}
+@tab Move point to the offending line
+@item @kbd{g}
+@tab Check the document again
+@item @kbd{h}
+@tab Hide all reports from the same checker
+@item @kbd{i}
+@tab Also remove them from all subsequent checks
+@item @kbd{S}
+@tab Sort reports by the column at point
+@end multitable
+
+@node Documentation Access
+@section Context Dependent Documentation
+
+@cindex documentation
+@cindex Info
+
+@findex org-info-find-node
+@kindex C-c C-x I
+@kbd{C-c C-x I} in an Org file tries to open a suitable section
+of the Org manual depending on the syntax at point.  For example,
+using it on a headline displays ``Document Structure'' section.
+
+@kbd{q} closes the Info window.
+
+@node Escape Character
+@section Escape Character
+
+@cindex escape character
+@cindex zero width space
+You may sometimes want to write text that looks like Org syntax, but
+should really read as plain text.  Org may use a specific escape
+character in some situations, e.g., a backslash in macros (see @ref{Macro 
Replacement}) or a comma in source and example blocks (see @ref{Literal 
Examples}).  In the general case, however, we suggest to use the zero
+width space.  You can insert one with any of the following:
+
+@example
+C-x 8 <RET> zero width space <RET>
+C-x 8 <RET> 200B <RET>
+@end example
+
+
+For example, in order to write @samp{[[1,2]]} as-is in your document, you
+may write instead
+
+@example
+[X[1,2]]
+@end example
+
+
+where @samp{X} denotes the zero width space character.
+
+@node Code Evaluation Security
+@section Code Evaluation and Security Issues
+
+Unlike plain text, running code comes with risk.  Each source code
+block, in terms of risk, is equivalent to an executable file.  Org
+therefore puts a few confirmation prompts by default.  This is to
+alert the casual user from accidentally running untrusted code.
+
+For users who do not run code blocks or write code regularly, Org's
+default settings should suffice.  However, some users may want to
+tweak the prompts for fewer interruptions.  To weigh the risks of
+automatic execution of code blocks, here are some details about code
+evaluation.
+
+Org evaluates code in the following circumstances:
+
+@table @asis
+@item @emph{Source code blocks}
+Org evaluates source code blocks in an Org file during export.  Org
+also evaluates a source code block with the @kbd{C-c C-c} key
+chord.  Users exporting or running code blocks must load files only
+from trusted sources.  Be wary of customizing variables that remove
+or alter default security measures.
+
+@defopt org-confirm-babel-evaluate
+When @code{t}, Org prompts the user for confirmation before executing
+each code block.  When @code{nil}, Org executes code blocks without
+prompting the user for confirmation.  When this option is set to
+a custom function, Org invokes the function with these two
+arguments: the source code language and the body of the code block.
+The custom function must return either a @code{t} or @code{nil}, which
+determines if the user is prompted.  Each source code language can
+be handled separately through this function argument.
+@end defopt
+
+For example, here is how to execute ditaa code blocks without
+prompting:
+
+@lisp
+(defun my-org-confirm-babel-evaluate (lang body)
+  (not (string= lang "ditaa")))  ;don't ask for ditaa
+(setq org-confirm-babel-evaluate #'my-org-confirm-babel-evaluate)
+@end lisp
+
+@item @emph{Following @samp{shell} and @samp{elisp} links}
+Org has two link types that can directly evaluate code (see
+@ref{External Links}).  Because such code is not visible, these links
+have a potential risk.  Org therefore prompts the user when it
+encounters such links.  The customization variables are:
+
+@defopt org-link-shell-confirm-function
+Function that prompts the user before executing a shell link.
+@end defopt
+
+@defopt org-link-elisp-confirm-function
+Function that prompts the user before executing an Emacs Lisp link.
+@end defopt
+
+@item @emph{Formulas in tables}
+Formulas in tables (see @ref{The Spreadsheet}) are code that is evaluated
+either by the Calc interpreter, or by the Emacs Lisp interpreter.
+@end table
+
+@node Interaction
+@section Interaction with Other Packages
+
+@cindex packages, interaction with other
+
+Org's compatibility and the level of interaction with other Emacs
+packages are documented here.
+
+@menu
+* Cooperation::                  Packages Org cooperates with.
+* Conflicts::                    Packages that lead to conflicts.
+@end menu
+
+@node Cooperation
+@subsection Packages that Org cooperates with
+
+@table @asis
+@item @samp{calc.el} by Dave Gillespie
+@cindex @file{calc.el}
+
+Org uses the Calc package for implementing spreadsheet functionality
+in its tables (see @ref{The Spreadsheet}).  Org also uses Calc for
+embedded calculations.  See @ref{Embedded Mode,GNU Emacs Calc Manual,,calc,}.
+
+@item @samp{constants.el} by Carsten Dominik
+@cindex @file{constants.el}
+@vindex org-table-formula-constants
+
+Org can use names for constants in formulas in tables.  Org can also
+use calculation suffixes for units, such as @samp{M} for @samp{Mega}.  For
+a standard collection of such constants, install the @samp{constants}
+package.  Install version 2.0 of this package, available at
+@uref{http://www.astro.uva.nl/~dominik/Tools}.  Org checks if the function
+@code{constants-get} has been autoloaded.  Installation instructions are
+in the file @samp{constants.el}.
+
+@item @samp{cdlatex.el} by Carsten Dominik
+@cindex @file{cdlatex.el}
+
+Org mode can make use of the CD@LaTeX{} package to efficiently enter
+@LaTeX{} fragments into Org files.  See @ref{CD@LaTeX{} mode}.
+
+@item @samp{imenu.el} by Ake Stenhoff and Lars Lindberg
+@cindex @file{imenu.el}
+
+Imenu creates dynamic menus based on an index of items in a file.
+Org mode supports Imenu menus.  Enable it with a mode hook as
+follows:
+
+@lisp
+(add-hook 'org-mode-hook
+          (lambda () (imenu-add-to-menubar "Imenu")))
+@end lisp
+
+@vindex org-imenu-depth
+By default the index is two levels deep---you can modify the
+depth using the option @code{org-imenu-depth}.
+
+@item @samp{speedbar.el} by Eric@tie{}M@.@tie{}Ludlam
+@cindex @file{speedbar.el}
+
+Speedbar package creates a special Emacs frame for displaying files
+and index items in files.  Org mode supports Speedbar; users can
+drill into Org files directly from the Speedbar.  The @kbd{<}
+in the Speedbar frame tweaks the agenda commands to that file or to
+a subtree.
+
+@item @samp{table.el} by Takaaki Ota
+@cindex table editor, @file{table.el}
+@cindex @file{table.el}
+
+Complex ASCII tables with automatic line wrapping, column- and
+row-spanning, and alignment can be created using the Emacs table
+package by Takaaki Ota.  Org mode recognizes such tables and exports
+them properly.  @kbd{C-c '} to edit these tables in a special
+buffer, much like Org's code blocks.  Because of interference with
+other Org mode functionality, Takaaki Ota tables cannot be edited
+directly in the Org buffer.
+
+@table @asis
+@item @kbd{C-c '} (@code{org-edit-special})
+@kindex C-c '
+@findex org-edit-special
+Edit a @samp{table.el} table.  Works when point is in a @samp{table.el}
+table.
+
+@item @kbd{C-c ~​} (@code{org-table-create-with-table.el})
+@kindex C-c ~
+@findex org-table-create-with-table.el
+Insert a @samp{table.el} table.  If there is already a table at point,
+this command converts it between the @samp{table.el} format and the Org
+mode format.  See the documentation string of the command
+@code{org-convert-table} for the restrictions under which this is
+possible.
+@end table
+@end table
+
+@node Conflicts
+@subsection Packages that conflict with Org mode
+
+@cindex shift-selection
+@vindex org-support-shift-select
+In Emacs, shift-selection combines motions of point with shift key to
+enlarge regions.  Emacs sets this mode by default.  This conflicts
+with Org's use of @kbd{S-<cursor>} commands to change timestamps,
+TODO keywords, priorities, and item bullet types, etc.  Since
+@kbd{S-<cursor>} commands outside of specific contexts do not do
+anything, Org offers the variable @code{org-support-shift-select} for
+customization.  Org mode accommodates shift selection by (i) making it
+available outside of the special contexts where special commands
+apply, and (ii) extending an existing active region even if point
+moves across a special context.
+
+@table @asis
+@item @samp{cua.el} by Kim@tie{}F@.@tie{}Storm
+@cindex @file{cua.el}
+@vindex org-replace-disputed-keys
+Org key bindings conflict with @kbd{S-<cursor>} keys used by
+CUA mode.  For Org to relinquish these bindings to CUA mode,
+configure the variable @code{org-replace-disputed-keys}.  When set, Org
+moves the following key bindings in Org files, and in the agenda
+buffer---but not during date selection.
+
+@multitable @columnfractions 0.4 0.4
+@item @kbd{S-@key{UP}}      @result{}  @kbd{M-p}
+@tab @kbd{S-@key{DOWN}}     @result{}  @kbd{M-n}
+@item @kbd{S-@key{LEFT}}    @result{}  @kbd{M--}
+@tab @kbd{S-@key{RIGHT}}    @result{}  @kbd{M-+}
+@item @kbd{C-S-@key{LEFT}}  @result{}  @kbd{M-S--}
+@tab @kbd{C-S-@key{RIGHT}}  @result{}  @kbd{M-S-+}
+@end multitable
+
+@vindex org-disputed-keys
+Yes, these are unfortunately more difficult to remember.  If you
+want to have other replacement keys, look at the variable
+@code{org-disputed-keys}.
+
+@item @samp{ecomplete.el} by Lars Magne Ingebrigtsen
+@cindex @file{ecomplete.el}
+Ecomplete provides ``electric'' address completion in address header
+lines in message buffers.  Sadly Orgtbl mode cuts Ecomplete's power
+supply: no completion happens when Orgtbl mode is enabled in message
+buffers while entering text in address header lines.  If one wants
+to use ecomplete one should @emph{not} follow the advice to automagically
+turn on Orgtbl mode in message buffers (see @ref{Orgtbl Mode}),
+but instead---after filling in the message headers---turn on Orgtbl
+mode manually when needed in the messages body.
+
+@item @samp{filladapt.el} by Kyle Jones
+@cindex @file{filladapt.el}
+Org mode tries to do the right thing when filling paragraphs, list
+items and other elements.  Many users reported problems using both
+@samp{filladapt.el} and Org mode, so a safe thing to do is to disable
+filladapt like this:
+
+@lisp
+(add-hook 'org-mode-hook 'turn-off-filladapt-mode)
+@end lisp
+
+@item @samp{viper.el} by Michael Kifer
+@cindex @file{viper.el}
+@kindex C-c /
+
+Viper uses @kbd{C-c /} and therefore makes this key not access
+the corresponding Org mode command @code{org-sparse-tree}.  You need to
+find another key for this command, or override the key in
+@code{viper-vi-global-user-map} with
+
+@lisp
+(define-key viper-vi-global-user-map "C-c /" 'org-sparse-tree)
+@end lisp
+
+@item @samp{windmove.el} by Hovav Shacham
+@cindex @file{windmove.el}
+
+This package also uses the @kbd{S-<cursor>} keys, so everything
+written in the paragraph above about CUA mode also applies here.  If
+you want to make the windmove function active in locations where Org
+mode does not have special functionality on @kbd{S-<cursor>},
+add this to your configuration:
+
+@lisp
+;; Make windmove work in Org mode:
+(add-hook 'org-shiftup-final-hook 'windmove-up)
+(add-hook 'org-shiftleft-final-hook 'windmove-left)
+(add-hook 'org-shiftdown-final-hook 'windmove-down)
+(add-hook 'org-shiftright-final-hook 'windmove-right)
+@end lisp
+
+@item @samp{yasnippet.el}
+@cindex @file{yasnippet.el}
+The way Org mode binds the @kbd{@key{TAB}} key (binding to @code{[tab]}
+instead of @code{"\t"}) overrules YASnippet's access to this key.  The
+following code fixed this problem:
+
+@lisp
+(add-hook 'org-mode-hook
+          (lambda ()
+            (setq-local yas/trigger-key [tab])
+            (define-key yas/keymap [tab] 'yas/next-field-or-maybe-expand)))
+@end lisp
+
+The latest version of YASnippet does not play well with Org mode.
+If the above code does not fix the conflict, start by defining
+the following function:
+
+@lisp
+(defun yas/org-very-safe-expand ()
+  (let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
+@end lisp
+
+Then, tell Org mode to use that function:
+
+@lisp
+(add-hook 'org-mode-hook
+          (lambda ()
+            (make-variable-buffer-local 'yas/trigger-key)
+            (setq yas/trigger-key [tab])
+            (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
+            (define-key yas/keymap [tab] 'yas/next-field)))
+@end lisp
+@end table
+
+@node TTY Keys
+@section Using Org on a TTY
+
+@cindex tty key bindings
+
+Org provides alternative key bindings for TTY and modern mobile
+devices that cannot perform movement commands on point and key
+bindings with modifier keys.  Some of these workarounds may be more
+cumbersome than necessary.  Users should look into customizing these
+further based on their usage needs.  For example, the normal
+@kbd{S-<cursor>} for editing timestamp might be better with
+@kbd{C-c .} chord.
 
-To turn this mode on, use the minor mode, @code{org-indent-mode}.  Text lines
-that are not headlines are prefixed with spaces to vertically align with the
-headline text@footnote{The @code{org-indent-mode} also sets the
-@code{wrap-prefix} correctly for indenting and wrapping long lines of
-headlines or text.  This minor mode handles @code{visual-line-mode} and
-directly applied settings through @code{word-wrap}.}.
+@multitable @columnfractions 0.2 0.28 0.15 0.21
+@headitem Default
+@tab Alternative 1
+@tab Speed key
+@tab Alternative 2
+@item @kbd{S-@key{TAB}}
+@tab @kbd{C-u @key{TAB}}
+@tab @kbd{C}
+@tab
+@item @kbd{M-@key{LEFT}}
+@tab @kbd{C-c C-x l}
+@tab @kbd{l}
+@tab @kbd{Esc @key{LEFT}}
+@item @kbd{M-S-@key{LEFT}}
+@tab @kbd{C-c C-x L}
+@tab @kbd{L}
+@tab
+@item @kbd{M-@key{RIGHT}}
+@tab @kbd{C-c C-x r}
+@tab @kbd{r}
+@tab @kbd{Esc @key{RIGHT}}
+@item @kbd{M-S-@key{RIGHT}}
+@tab @kbd{C-c C-x R}
+@tab @kbd{R}
+@tab
+@item @kbd{M-@key{UP}}
+@tab @kbd{C-c C-x u}
+@tab
+@tab @kbd{Esc @key{UP}}
+@item @kbd{M-S-@key{UP}}
+@tab @kbd{C-c C-x U}
+@tab @kbd{U}
+@tab
+@item @kbd{M-@key{DOWN}}
+@tab @kbd{C-c C-x d}
+@tab
+@tab @kbd{Esc @key{DOWN}}
+@item @kbd{M-S-@key{DOWN}}
+@tab @kbd{C-c C-x D}
+@tab @kbd{D}
+@tab
+@item @kbd{S-@key{RET}}
+@tab @kbd{C-c C-x c}
+@tab
+@tab
+@item @kbd{M-@key{RET}}
+@tab @kbd{C-c C-x m}
+@tab
+@tab @kbd{Esc @key{RET}}
+@item @kbd{M-S-@key{RET}}
+@tab @kbd{C-c C-x M}
+@tab
+@tab
+@item @kbd{S-@key{LEFT}}
+@tab @kbd{C-c @key{LEFT}}
+@tab
+@tab
+@item @kbd{S-@key{RIGHT}}
+@tab @kbd{C-c @key{RIGHT}}
+@tab
+@tab
+@item @kbd{S-@key{UP}}
+@tab @kbd{C-c @key{UP}}
+@tab
+@tab
+@item @kbd{S-@key{DOWN}}
+@tab @kbd{C-c @key{DOWN}}
+@tab
+@tab
+@item @kbd{C-S-@key{LEFT}}
+@tab @kbd{C-c C-x @key{LEFT}}
+@tab
+@tab
+@item @kbd{C-S-@key{RIGHT}}
+@tab @kbd{C-c C-x @key{RIGHT}}
+@tab
+@tab
+@end multitable
 
-To make more horizontal space, the headlines are shifted by two stars.  This
-can be configured by the @code{org-indent-indentation-per-level} variable.
-Only one star on each headline is visible, the rest are masked with the same
-font color as the background.  This font face can be configured with the
-@code{org-hide} variable.
+@node Protocols
+@section Protocols for External Access
 
-Note that turning on @code{org-indent-mode} sets
-@code{org-hide-leading-stars} to @code{t} and @code{org-adapt-indentation} to
-@code{nil}; @samp{2.} below shows how this works.
+@cindex protocols, for external access
 
-To globally turn on @code{org-indent-mode} for all files, customize the
-variable @code{org-startup-indented}.
+Org protocol is a tool to trigger custom actions in Emacs from
+external applications.  Any application that supports calling external
+programs with an URL as argument may be used with this functionality.
+For example, you can configure bookmarks in your web browser to send a
+link to the current page to Org and create a note from it using
+capture (see @ref{Capture}).  You can also create a bookmark that tells
+Emacs to open the local source file of a remote website you are
+browsing.
 
-To turn on indenting for individual files, use @code{#+STARTUP} option as
-follows:
+@cindex Org protocol, set-up
+@cindex Installing Org protocol
+In order to use Org protocol from an application, you need to register
+@samp{org-protocol://} as a valid scheme-handler.  External calls are
+passed to Emacs through the @samp{emacsclient} command, so you also need to
+ensure an Emacs server is running.  More precisely, when the
+application calls
 
 @example
-#+STARTUP: indent
+emacsclient org-protocol://PROTOCOL?key1=val1&key2=val2
 @end example
 
-Indent on startup makes Org use hard spaces to align text with headings as
-shown in examples below.
 
-@enumerate
-@item
-@emph{Indentation of text below headlines}@*
-Indent text to align with the headline.
+@noindent
+Emacs calls the handler associated to @var{PROTOCOL} with
+argument @samp{(:key1 val1 :key2 val2)}.
 
-@example
-*** 3rd level
-    more text, now indented
-@end example
+@cindex protocol, new protocol
+@cindex defining new protocols
+Org protocol comes with three predefined protocols, detailed in the
+following sections.  Configure @code{org-protocol-protocol-alist} to define
+your own.
 
-@vindex org-adapt-indentation
-Org adapts indentations with paragraph filling, line wrapping, and structure
-editing@footnote{Also see the variable @code{org-adapt-indentation}.}.
+@menu
+* The @code{store-link} protocol:: Store a link, push URL to kill-ring.
+* The @code{capture} protocol::  Fill a buffer with external information.
+* The @code{open-source} protocol:: Edit published contents.
+@end menu
 
-@item
-@vindex org-hide-leading-stars
-@emph{Hiding leading stars}@* Org can make leading stars invisible.  For
-global preference, configure the variable @code{org-hide-leading-stars}.  For
-per-file preference, use these file @code{#+STARTUP} options:
+@node The @code{store-link} protocol
+@subsection The @code{store-link} protocol
 
-@example
-#+STARTUP: hidestars
-#+STARTUP: showstars
-@end example
+@cindex store-link protocol
+@cindex protocol, store-link
 
-With stars hidden, the tree is shown as:
+Using the @code{store-link} handler, you can copy links, to that they can
+be inserted using @kbd{M-x org-insert-link} or yanking.  More
+precisely, the command
 
 @example
-@group
-* Top level headline
- * Second level
-  * 3rd level
-  ...
-@end group
+emacsclient org-protocol://store-link?url=URL&title=TITLE
 @end example
 
-@noindent
-@vindex org-hide @r{(face)}
-Because Org makes the font color same as the background color to hide to
-stars, sometimes @code{org-hide} face may need tweaking to get the effect
-right.  For some black and white combinations, @code{grey90} on a white
-background might mask the stars better.
 
-@item
-@vindex org-odd-levels-only
-Using stars for only odd levels, 1, 3, 5, @dots{}, can also clean up the
-clutter.  This removes two stars from each level@footnote{Because
-@samp{LEVEL=2} has 3 stars, @samp{LEVEL=3} has 4 stars, and so on}.  For Org
-to properly handle this cleaner structure during edits and exports, configure
-the variable @code{org-odd-levels-only}.  To set this per-file, use either
-one of the following lines:
+@noindent
+stores the following link:
 
 @example
-#+STARTUP: odd
-#+STARTUP: oddeven
+[[URL][TITLE]]
 @end example
 
-To switch between single and double stars layouts, use @kbd{M-x
-org-convert-to-odd-levels @key{RET}} and @kbd{M-x
-org-convert-to-oddeven-levels @key{RET}}.
-@end enumerate
-
-@node TTY keys
-@section Using Org on a tty
-@cindex tty key bindings
-
-Org provides alternative key bindings for TTY and modern mobile devices that
-cannot handle cursor keys and complex modifier key chords.  Some of these
-workarounds may be more cumbersome than necessary.  Users should look into
-customizing these further based on their usage needs.  For example, the
-normal @kbd{S-@key{cursor}} for editing timestamp might be better with
-@kbd{C-c .} chord.
-
-@multitable @columnfractions 0.15 0.2 0.1 0.2
-@item @b{Default} @tab @b{Alternative 1} @tab @b{Speed key} @tab 
@b{Alternative 2}
-@item @kbd{S-@key{TAB}}     @tab @kbd{C-u @key{TAB}}       @tab @kbd{C} @tab
-@item @kbd{M-@key{LEFT}}    @tab @kbd{C-c C-x l}           @tab @kbd{l} @tab 
@kbd{@key{Esc} @key{LEFT}}
-@item @kbd{M-S-@key{LEFT}}  @tab @kbd{C-c C-x L}           @tab @kbd{L} @tab
-@item @kbd{M-@key{RIGHT}}   @tab @kbd{C-c C-x r}           @tab @kbd{r} @tab 
@kbd{@key{Esc} @key{RIGHT}}
-@item @kbd{M-S-@key{RIGHT}} @tab @kbd{C-c C-x R}           @tab @kbd{R} @tab
-@item @kbd{M-@key{UP}}      @tab @kbd{C-c C-x u}           @tab @kbd{ } @tab 
@kbd{@key{Esc} @key{UP}}
-@item @kbd{M-S-@key{UP}}    @tab @kbd{C-c C-x U}           @tab @kbd{U} @tab
-@item @kbd{M-@key{DOWN}}    @tab @kbd{C-c C-x d}           @tab @kbd{ } @tab 
@kbd{@key{Esc} @key{DOWN}}
-@item @kbd{M-S-@key{DOWN}}  @tab @kbd{C-c C-x D}           @tab @kbd{D} @tab
-@item @kbd{S-@key{RET}}     @tab @kbd{C-c C-x c}           @tab @kbd{ } @tab
-@item @kbd{M-@key{RET}}     @tab @kbd{C-c C-x m}           @tab @kbd{ } @tab 
@kbd{@key{Esc} @key{RET}}
-@item @kbd{M-S-@key{RET}}   @tab @kbd{C-c C-x M}           @tab @kbd{ } @tab
-@item @kbd{S-@key{LEFT}}    @tab @kbd{C-c @key{LEFT}}      @tab @kbd{ } @tab
-@item @kbd{S-@key{RIGHT}}   @tab @kbd{C-c @key{RIGHT}}     @tab @kbd{ } @tab
-@item @kbd{S-@key{UP}}      @tab @kbd{C-c @key{UP}}        @tab @kbd{ } @tab
-@item @kbd{S-@key{DOWN}}    @tab @kbd{C-c @key{DOWN}}      @tab @kbd{ } @tab
-@item @kbd{C-S-@key{LEFT}}  @tab @kbd{C-c C-x @key{LEFT}}  @tab @kbd{ } @tab
-@item @kbd{C-S-@key{RIGHT}} @tab @kbd{C-c C-x @key{RIGHT}} @tab @kbd{ } @tab
-@end multitable
 
+In addition, @var{URL} is pushed on the kill-ring for yanking.
+You need to encode @var{URL} and @var{TITLE} if they contain
+slashes, and probably quote those for the shell.
 
-@node Interaction
-@section Interaction with other packages
-@cindex packages, interaction with other
-Org's compatibility and the level of interaction with other Emacs packages
-are documented here.
+To use this feature from a browser, add a bookmark with an arbitrary
+name, e.g., @samp{Org: store-link} and enter this as @emph{Location}:
 
+@example
+javascript:location.href='org-protocol://store-link?url='+
+      encodeURIComponent(location.href);
+@end example
 
-@menu
-* Cooperation::                 Packages Org cooperates with
-* Conflicts::                   Packages that lead to conflicts
-@end menu
+@node The @code{capture} protocol
+@subsection The @code{capture} protocol
 
-@node Cooperation
-@subsection Packages that Org cooperates with
+@cindex capture protocol
+@cindex protocol, capture
 
-@table @asis
-@cindex @file{calc.el}
-@cindex Gillespie, Dave
-@item @file{calc.el} by Dave Gillespie
-Org uses the Calc package for tables to implement spreadsheet functionality
-(@pxref{The spreadsheet}).  Org also uses Calc for embedded calculations.
-@xref{Embedded Mode, , Embedded Mode, calc, GNU Emacs Calc Manual}.
-@item @file{constants.el} by Carsten Dominik
-@cindex @file{constants.el}
-@cindex Dominik, Carsten
-@vindex org-table-formula-constants
-Org can use names for constants in formulas in tables.  Org can also use
-calculation suffixes for units, such as @samp{M} for @samp{Mega}.  For a
-standard collection of such constants, install the @file{constants} package.
-Install version 2.0 of this package, available at
-@url{https://staff.fnwi.uva.nl/c.dominik/Tools/}.  Org checks if the function
-@code{constants-get} has been autoloaded.  Installation instructions are in
-the file, @file{constants.el}.
-@item @file{cdlatex.el} by Carsten Dominik
-@cindex @file{cdlatex.el}
-@cindex Dominik, Carsten
-Org mode can use CD@LaTeX{} package to efficiently enter @LaTeX{} fragments
-into Org files (@pxref{CDLaTeX mode}).
-@item @file{imenu.el} by Ake Stenhoff and Lars Lindberg
-@cindex @file{imenu.el}
-Imenu creates dynamic menus based on an index of items in a file.  Org mode
-supports Imenu menus.  Enable it with a mode hook as follows:
-@lisp
-(add-hook 'org-mode-hook
-          (lambda () (imenu-add-to-menubar "Imenu")))
-@end lisp
-@vindex org-imenu-depth
-By default the Imenu index is two levels deep.  Change the index depth using
-the variable @code{org-imenu-depth}.
-@item @file{speedbar.el} by Eric M. Ludlam
-@cindex @file{speedbar.el}
-@cindex Ludlam, Eric M.
-Speedbar package creates a special Emacs frame for displaying files and index
-items in files.  Org mode supports Speedbar; users can drill into Org files
-directly from the Speedbar.  The @kbd{<} in the Speedbar frame tweaks the
-agenda commands to that file or to a subtree.
-@cindex @file{table.el}
-@item @file{table.el} by Takaaki Ota
-@kindex C-c C-c
-@cindex table editor, @file{table.el}
-@cindex @file{table.el}
-@cindex Ota, Takaaki
-
-Complex ASCII tables with automatic line wrapping, column- and row-spanning,
-and alignment can be created using the Emacs table package by Takaaki Ota.
-Org mode recognizes such tables and export them properly.  @kbd{C-c '} to
-edit these tables in a special buffer, much like Org's @samp{src} code
-blocks.  Because of interference with other Org mode functionality, Takaaki
-Ota tables cannot be edited directly in the Org buffer.
-@table @kbd
-@orgcmd{C-c ',org-edit-special}
-Edit a @file{table.el} table.  Works when the cursor is in a table.el table.
-@c
-@orgcmd{C-c ~,org-table-create-with-table.el}
-Insert a @file{table.el} table.  If there is already a table at point, this
-command converts it between the @file{table.el} format and the Org mode
-format.  See the documentation string of the command @code{org-convert-table}
-for details.
-@end table
-@end table
+Activating the ``capture'' handler pops up a @samp{Capture} buffer in Emacs,
+using acapture template.
 
-@node Conflicts
-@subsection Packages that conflict with Org mode
+@example
+emacsclient org-protocol://capture?template=X?url=URL?title=TITLE?body=BODY
+@end example
 
-@table @asis
 
-@cindex @code{shift-selection-mode}
-@vindex org-support-shift-select
-In Emacs, @code{shift-selection-mode} combines cursor motions with shift key
-to enlarge regions.  Emacs sets this mode by default.  This conflicts with
-Org's use of @kbd{S-@key{cursor}} commands to change timestamps, TODO
-keywords, priorities, and item bullet types, etc.  Since @kbd{S-@key{cursor}}
-commands outside of specific contexts don't do anything, Org offers the
-variable @code{org-support-shift-select} for customization.  Org mode
-accommodates shift selection by (i) making it available outside of the
-special contexts where special commands apply, and (ii) extending an
-existing active region even if the cursor moves across a special context.
-
-@item @file{CUA.el} by Kim. F. Storm
-@cindex @file{CUA.el}
-@cindex Storm, Kim. F.
-@vindex org-replace-disputed-keys
-Org key bindings conflict with @kbd{S-<cursor>} keys used by CUA mode.  For
-Org to relinquish these bindings to CUA mode, configure the variable
-@code{org-replace-disputed-keys}.  When set, Org moves the following key
-bindings in Org files, and in the agenda buffer (but not during date
-selection).
+To use this feature, add a bookmark with an arbitrary name, e.g.,
+@samp{Org: capture}, and enter this as @samp{Location}:
 
 @example
-S-@key{UP}      @result{}  M-p             S-@key{DOWN}     @result{}  M-n
-S-@key{LEFT}    @result{}  M--             S-@key{RIGHT}    @result{}  M-+
-C-S-@key{LEFT}  @result{}  M-S--           C-S-@key{RIGHT}  @result{}  M-S-+
+javascript:location.href='org-protocol://capture?template=x'+
+      '&url='+encodeURIComponent(window.location.href)+
+      '&title='+encodeURIComponent(document.title)+
+      '&body='+encodeURIComponent(window.getSelection());
 @end example
 
-@vindex org-disputed-keys
-Yes, these are unfortunately more difficult to remember.  To define a
-different replacement keys, look at the variable @code{org-disputed-keys}.
-
-@item @file{ecomplete.el} by Lars Magne Ingebrigtsen @email{larsi@@gnus.org}
-@cindex @file{ecomplete.el}
+@vindex org-protocol-default-template-key
+The capture template to be used can be specified in the bookmark (like
+@samp{X} above). If unspecified, the template key is set in the variable
+@code{org-protocol-default-template-key}. The following template
+placeholders are available:
 
-Ecomplete provides ``electric'' address completion in address header
-lines in message buffers.  Sadly Orgtbl mode cuts ecomplete's power
-supply: No completion happens when Orgtbl mode is enabled in message
-buffers while entering text in address header lines.  If one wants to
-use ecomplete one should @emph{not} follow the advice to automagically
-turn on Orgtbl mode in message buffers (see @ref{Orgtbl mode}), but
-instead---after filling in the message headers---turn on Orgtbl mode
-manually when needed in the messages body.
-
-@item @file{filladapt.el} by Kyle Jones
-@cindex @file{filladapt.el}
+@example
+%:link          The URL
+%:description   The webpage title
+%:annotation    Equivalent to [[%:link][%:description]]
+%i              The selected text
+@end example
 
-Org mode tries to do the right thing when filling paragraphs, list items and
-other elements.  Many users reported problems using both @file{filladapt.el}
-and Org mode, so a safe thing to do is to disable filladapt like this:
+@node The @code{open-source} protocol
+@subsection The @code{open-source} protocol
 
-@lisp
-(add-hook 'org-mode-hook 'turn-off-filladapt-mode)
-@end lisp
+@cindex open-source protocol
+@cindex protocol, open-source
 
-@item @file{yasnippet.el}
-@cindex @file{yasnippet.el}
-The way Org mode binds the @key{TAB} key (binding to @code{[tab]} instead of
-@code{"\t"}) overrules YASnippet's access to this key.  The following code
-fixed this problem:
+The @code{open-source} handler is designed to help with editing local
+sources when reading a document.  To that effect, you can use
+a bookmark with the following location:
 
-@lisp
-(add-hook 'org-mode-hook
-          (lambda ()
-            (setq-local yas/trigger-key [tab])
-            (define-key yas/keymap [tab] 'yas/next-field-or-maybe-expand)))
-@end lisp
+@example
+javascript:location.href='org-protocol://open-source?&url='+
+      encodeURIComponent(location.href)
+@end example
 
-The latest version of yasnippet doesn't play well with Org mode.  If the
-above code does not fix the conflict, first define the following function:
+@vindex org-protocol-project-alist
+The variable @code{org-protocol-project-alist} maps URLs to local file
+names, by stripping URL parameters from the end and replacing the
+@code{:base-url} with @code{:working-directory} and @code{:online-suffix} with
+@code{:working-suffix}.  For example, assuming you own a local copy of
+@samp{https://orgmode.org/worg/} contents at @samp{/home/user/worg}, you can 
set
+@code{org-protocol-project-alist} to the following
 
 @lisp
-(defun yas/org-very-safe-expand ()
-  (let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
+(setq org-protocol-project-alist
+      '(("Worg"
+         :base-url "https://orgmode.org/worg/";
+         :working-directory "/home/user/worg/"
+         :online-suffix ".html"
+         :working-suffix ".org")))
 @end lisp
 
-Then tell Org mode to use that function:
-
-@lisp
-(add-hook 'org-mode-hook
-          (lambda ()
-            (make-variable-buffer-local 'yas/trigger-key)
-            (setq yas/trigger-key [tab])
-            (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
-            (define-key yas/keymap [tab] 'yas/next-field)))
-@end lisp
+@noindent
+If you are now browsing
+@samp{https://orgmode.org/worg/org-contrib/org-protocol.html} and find
+a typo or have an idea about how to enhance the documentation, simply
+click the bookmark and start editing.
 
-@item @file{windmove.el} by Hovav Shacham
-@cindex @file{windmove.el}
-This package also uses the @kbd{S-<cursor>} keys, so everything written
-in the paragraph above about CUA mode also applies here.  If you want make
-the windmove function active in locations where Org mode does not have
-special functionality on @kbd{S-@key{cursor}}, add this to your
-configuration:
+@cindex rewritten URL in open-source protocol
+@cindex protocol, open-source rewritten URL
+However, such mapping may not always yield the desired results.
+Suppose you maintain an online store located at @samp{http://example.com/}.
+The local sources reside in @samp{/home/user/example/}.  It is common
+practice to serve all products in such a store through one file and
+rewrite URLs that do not match an existing file on the server.  That
+way, a request to @samp{http://example.com/print/posters.html} might be
+rewritten on the server to something like
+@samp{http://example.com/shop/products.php/posters.html.php}.  The
+@code{open-source} handler probably cannot find a file named
+@samp{/home/user/example/print/posters.html.php} and fails.
 
-@lisp
-;; Make windmove work in org-mode:
-(add-hook 'org-shiftup-final-hook 'windmove-up)
-(add-hook 'org-shiftleft-final-hook 'windmove-left)
-(add-hook 'org-shiftdown-final-hook 'windmove-down)
-(add-hook 'org-shiftright-final-hook 'windmove-right)
-@end lisp
+Such an entry in @code{org-protocol-project-alist} may hold an additional
+property @code{:rewrites}.  This property is a list of cons cells, each of
+which maps a regular expression to a path relative to the
+@code{:working-directory}.
 
-@item @file{viper.el} by Michael Kifer
-@cindex @file{viper.el}
-@kindex C-c /
-Viper uses @kbd{C-c /} and therefore makes this key not access the
-corresponding Org mode command @code{org-sparse-tree}.  You need to find
-another key for this command, or override the key in
-@code{viper-vi-global-user-map} with
+Now map the URL to the path @samp{/home/user/example/products.php} by
+adding @code{:rewrites} rules like this:
 
 @lisp
-(define-key viper-vi-global-user-map "C-c /" 'org-sparse-tree)
+(setq org-protocol-project-alist
+      '(("example.com"
+         :base-url "http://example.com/";
+         :working-directory "/home/user/example/"
+         :online-suffix ".php"
+         :working-suffix ".php"
+         :rewrites (("example.com/print/" . "products.php")
+                    ("example.com/$" . "index.php")))))
 @end lisp
 
+@noindent
+Since @samp{example.com/$} is used as a regular expression, it maps
+@samp{http://example.com/}, @samp{https://example.com},
+@samp{http://www.example.com/} and similar to
+@samp{/home/user/example/index.php}.
 
+The @code{:rewrites} rules are searched as a last resort if and only if no
+existing file name is matched.
 
-@end table
+@cindex protocol, open-source, set-up mapping
+@cindex mappings in open-source protocol
+@findex org-protocol-create
+@findex org-protocol-create-for-org
+Two functions can help you filling @code{org-protocol-project-alist} with
+valid contents: @code{org-protocol-create} and
+@code{org-protocol-create-for-org}.  The latter is of use if you're editing
+an Org file that is part of a publishing project.
 
-@node org-crypt
-@section org-crypt.el
-@cindex @file{org-crypt.el}
-@cindex @code{org-decrypt-entry}
+@node Org Crypt
+@section Org Crypt
 
-Org crypt encrypts the text of an Org entry, but not the headline, or
-properties.  Org crypt uses the Emacs EasyPG library to encrypt and decrypt.
+Org Crypt encrypts the text of an entry, but not the headline, or
+properties.  Behind the scene, it uses the Emacs EasyPG library to
+encrypt and decrypt files.
 
-Any text below a headline that has a @samp{:crypt:} tag will be automatically
-be encrypted when the file is saved.  To use a different tag, customize the
-@code{org-crypt-tag-matcher} variable.
+@vindex org-crypt-tag-matcher
+Any text below a headline that has a @samp{crypt} tag is automatically
+encrypted when the file is saved.  To use a different tag, customize
+the @code{org-crypt-tag-matcher} setting.
 
-Suggested Org crypt settings in Emacs init file:
+Here is a suggestion for Org Crypt settings in Emacs init file:
 
 @lisp
 (require 'org-crypt)
@@ -18169,22 +20737,31 @@ Suggested Org crypt settings in Emacs init file:
 (setq org-tags-exclude-from-inheritance '("crypt"))
 
 (setq org-crypt-key nil)
-  ;; GPG key to use for encryption
-  ;; Either the Key ID or set to nil to use symmetric encryption.
+;; GPG key to use for encryption
+;; Either the Key ID or set to nil to use symmetric encryption.
 
 (setq auto-save-default nil)
-  ;; Auto-saving does not cooperate with org-crypt.el: so you need
-  ;; to turn it off if you plan to use org-crypt.el quite often.
-  ;; Otherwise, you'll get an (annoying) message each time you
-  ;; start Org.
-
-  ;; To turn it off only locally, you can insert this:
-  ;;
-  ;; # -*- buffer-auto-save-file-name: nil; -*-
+;; Auto-saving does not cooperate with org-crypt.el: so you need to
+;; turn it off if you plan to use org-crypt.el quite often.  Otherwise,
+;; you'll get an (annoying) message each time you start Org.
+
+;; To turn it off only locally, you can insert this:
+;;
+;; # -*- buffer-auto-save-file-name: nil; -*-
 @end lisp
 
-Excluding the crypt tag from inheritance prevents encrypting previously
-encrypted text.
+It's possible to use different keys for different headings by
+specifying the respective key as property @samp{CRYPTKEY}, e.g.:
+
+@example
+* Totally secret :crypt:
+  :PROPERTIES:
+  :CRYPTKEY: 0x0123456789012345678901234567890123456789
+  :END:
+@end example
+
+Excluding the @samp{crypt} tag from inheritance prevents already encrypted
+text from being encrypted again.
 
 @node Org Mobile
 @section Org Mobile
@@ -18207,13 +20784,13 @@ These should cover all the important tags and TODO 
keywords, even if
 Org files use only some of them.  Though the mobile application is
 expected to support in-buffer settings, it is required to understand
 TODO states @emph{sets} (see @ref{Per-file keywords}) and
-@emph{mutually exclusive} tags (see @ref{Setting tags}) only for those set in
+@emph{mutually exclusive} tags (see @ref{Setting Tags}) only for those set in
 these variables.
 
 @menu
-* Setting up the staging area::  For the mobile device
-* Pushing to the mobile application::  Uploading Org files and agendas
-* Pulling from the mobile application::  Integrating captured and flagged items
+* Setting up the staging area::  For the mobile device.
+* Pushing to the mobile application:: Uploading Org files and agendas.
+* Pulling from the mobile application:: Integrating captured and flagged items.
 @end menu
 
 @node Setting up the staging area
@@ -18230,13 +20807,12 @@ locally just set the variable to point to that 
directory:
 (setq org-mobile-directory "~/orgmobile/")
 @end lisp
 
-@noindent
 Alternatively, by using TRAMP (see @ref{Top,TRAMP User Manual,,tramp,}),
 @code{org-mobile-directory} may point to a remote directory accessible
-through, for example, SSH and SCP:
+through, for example, SSH, SCP, or DAVS:
 
 @lisp
-(setq org-mobile-directory "/scpc:user@@remote.host:org/webdav/")
+(setq org-mobile-directory "/davs:user@@remote.host:/org/webdav/")
 @end lisp
 
 @vindex org-mobile-encryption
@@ -18264,8 +20840,8 @@ add other files.  File names are staged with paths 
relative to
 as their targets.}.
 
 Push creates a special Org file @samp{agendas.org} with custom agenda views
-defined by the user@footnote{While creating the agendas, Org mode forces ID 
properties on
-all referenced entries, so that these entries can be uniquely
+defined by the user@footnote{While creating the agendas, Org mode forces 
@samp{ID} properties
+on all referenced entries, so that these entries can be uniquely
 identified if Org Mobile flags them for further action.  To avoid
 setting properties configure the variable
 @code{org-mobile-force-id-on-agenda-items} to @code{nil}.  Org mode then relies
@@ -18314,12 +20890,13 @@ agenda item.
 
 @table @asis
 @item @kbd{?}
-Pressing @kbd{?} displays the entire flagged note in
-another window.  Org also pushes it to the kill ring.  To
-store flagged note as a normal note, use @kbd{? z C-y C-c C-c}.  Pressing 
@kbd{?} twice does these things: first
-it removes the @samp{FLAGGED} tag; second, it removes the flagged
-note from the property drawer; third, it signals that manual
-editing of the flagged entry is now finished.
+Pressing @kbd{?} displays the entire flagged note in another
+window.  Org also pushes it to the kill ring.  To store flagged
+note as a normal note, use @kbd{? z C-y C-c C-c}.  Pressing
+@kbd{?} twice does these things: first it removes the
+@samp{FLAGGED} tag; second, it removes the flagged note from the
+property drawer; third, it signals that manual editing of the
+flagged entry is now finished.
 @end table
 @end enumerate
 
@@ -18332,81 +20909,87 @@ pull, pull again.
 
 @node Hacking
 @appendix Hacking
+
 @cindex hacking
 
-This appendix covers some areas where users can extend the functionality of
-Org.
+This appendix describes some ways a user can extend the functionality
+of Org.
 
 @menu
-* Hooks::                       How to reach into Org's internals
-* Add-on packages::             Available extensions
-* Adding hyperlink types::      New custom link types
-* Adding export back-ends::     How to write new export back-ends
-* Context-sensitive commands::  How to add functionality to such commands
-* Tables in arbitrary syntax::  Orgtbl for @LaTeX{} and other programs
-* Dynamic blocks::              Automatically filled blocks
-* Special agenda views::        Customized views
-* Speeding up your agendas::    Tips on how to speed up your agendas
-* Extracting agenda information::  Post-processing of agenda information
-* Using the property API::      Writing programs that use entry properties
-* Using the mapping API::       Mapping over all or selected entries
+* Hooks: Hooks (2).              How to reach into Org's internals.
+* Add-on Packages::              Available extensions.
+* Adding Hyperlink Types::       New custom link types.
+* Adding Export Back-ends::      How to write new export back-ends.
+* Tables in Arbitrary Syntax::   Orgtbl for LaTeX and other programs.
+* Dynamic Blocks::               Automatically filled blocks.
+* Special Agenda Views::         Customized views.
+* Speeding Up Your Agendas::     Tips on how to speed up your agendas.
+* Extracting Agenda Information:: Post-processing agenda information.
+* Using the Property API::       Writing programs that use entry properties.
+* Using the Mapping API::        Mapping over all or selected entries.
 @end menu
 
-@node Hooks
-@section Hooks
+@node Hooks (2)
+@appendixsec Hooks
+
 @cindex hooks
 
-Org has a large number of hook variables for adding functionality.  This
-appendix illustrates using a few.  A complete list of hooks with
+Org has a large number of hook variables for adding functionality.
+This appendix illustrates using a few.  A complete list of hooks with
 documentation is maintained by the Worg project at
 @uref{https://orgmode.org/worg/doc.html#hooks}.
 
-@node Add-on packages
-@section Add-on packages
+@node Add-on Packages
+@appendixsec Add-on Packages
+
 @cindex add-on packages
 
 Various authors wrote a large number of add-on packages for Org.
 
-These packages are not part of Emacs, but they are distributed as contributed
-packages with the separate release available at @uref{https://orgmode.org}.
-See the @file{contrib/README} file in the source code directory for a list of
-contributed files.  Worg page with more information is at:
-@uref{https://orgmode.org/worg/org-contrib/}.
+These packages are not part of Emacs, but they are distributed as
+contributed packages with the separate release available at
+@uref{https://orgmode.org}.  See the @samp{contrib/README} file in the source 
code
+directory for a list of contributed files.  Worg page with more
+information is at: @uref{https://orgmode.org/worg/org-contrib/}.
+
+@node Adding Hyperlink Types
+@appendixsec Adding Hyperlink Types
 
-@node Adding hyperlink types
-@section Adding hyperlink types
 @cindex hyperlinks, adding new types
 
-Org has many built-in hyperlink types (@pxref{Hyperlinks}), and an interface
-for adding new link types.  The example file, @file{org-man.el}, shows the
-process of adding Org links to Unix man pages, which look like this:
-@samp{[[man:printf][The printf manpage]]}:
+Org has many built-in hyperlink types (see @ref{Hyperlinks}), and an
+interface for adding new link types.  The following example shows the
+process of adding Org links to Unix man pages, which look like this
 
-@lisp
-;;; org-man.el - Support for links to manpages in Org
+@example
+[[man:printf][The printf manual]]
+@end example
+
+
+@noindent
+The following @samp{org-man.el} file implements it
 
+@lisp
+;;; org-man.el - Support for links to man pages in Org mode
 (require 'org)
 
-(org-add-link-type "man" 'org-man-open)
-(add-hook 'org-store-link-functions 'org-man-store-link)
+(org-link-set-parameters "man"
+                         :follow org-man-command
+                         :export #'org-man-export
+                         :store #'org-man-store-link)
 
 (defcustom org-man-command 'man
   "The Emacs command to be used to display a man page."
   :group 'org-link
   :type '(choice (const man) (const woman)))
 
-(defun org-man-open (path)
-  "Visit the manpage on PATH.
-PATH should be a topic that can be thrown at the man command."
-  (funcall org-man-command path))
-
 (defun org-man-store-link ()
-  "Store a link to a manpage."
+  "Store a link to a man page."
   (when (memq major-mode '(Man-mode woman-mode))
-    ;; This is a man page, we do make this link
+    ;; This is a man page, we do make this link.
     (let* ((page (org-man-get-page-name))
            (link (concat "man:" page))
-           (description (format "Manpage for %s" page)))
+           (description (format "Man page for %s" page)))
       (org-store-link-props
        :type "man"
        :link link
@@ -18419,208 +21002,196 @@ PATH should be a topic that can be thrown at the 
man command."
       (match-string 1 (buffer-name))
     (error "Cannot create link to this man page")))
 
-(provide 'org-man)
+(defun org-man-export (link description format)
+  "Export a man page link from Org files."
+  (let ((path (format "http://man.he.net/?topic=%s&section=all"; link))
+        (desc (or description link)))
+    (pcase format
+      (`html (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
+      (`latex (format "\\href@{%s@}@{%s@}" path desc))
+      (`texinfo (format "@@uref@{%s,%s@}" path desc))
+      (`ascii (format "%s (%s)" desc path))
+      (t path))))
 
+(provide 'org-man)
 ;;; org-man.el ends here
 @end lisp
 
 @noindent
-To activate links to man pages in Org, enter this in the init file:
+To activate links to man pages in Org, enter this in the Emacs init
+file:
 
 @lisp
 (require 'org-man)
 @end lisp
 
 @noindent
-A review of @file{org-man.el}:
+A review of @samp{org-man.el}:
+
 @enumerate
 @item
-First, @code{(require 'org)} ensures @file{org.el} is loaded.
+First, @samp{(require 'org)} ensures @samp{org.el} is loaded.
+
 @item
-The @code{org-add-link-type} defines a new link type with @samp{man} prefix.
-The call contains the function to call that follows the link type.
+@findex org-link-set-parameters
+@vindex org-link-parameters
+Then @code{org-link-set-parameters} defines a new link type with @samp{man}
+prefix and associates functions for following, exporting and
+storing such links.  See the variable @code{org-link-parameters} for
+a complete list of possible associations.
+
 @item
-@vindex org-store-link-functions
-The next line adds a function to @code{org-store-link-functions} that records
-a useful link with the command @kbd{C-c l} in a buffer displaying a man page.
+The rest of the file implements necessary variables and functions.
+
+For example, @code{org-man-store-link} is responsible for storing a link
+when @code{org-store-link} (see @ref{Handling Links}) is called from a buffer
+displaying a man page.  It first checks if the major mode is
+appropriate.  If check fails, the function returns @code{nil}, which
+means it isn't responsible for creating a link to the current
+buffer.  Otherwise the function makes a link string by combining
+the @samp{man:} prefix with the man topic.  It also provides a default
+description.  The function @code{org-insert-link} can insert it back
+into an Org buffer later on.
 @end enumerate
 
-The rest of the file defines necessary variables and functions.  First is the
-customization variable @code{org-man-command}.  It has two options,
-@code{man} and @code{woman}.  Next is a function whose argument is the link
-path, which for man pages is the topic of the man command.  To follow the
-link, the function calls the @code{org-man-command} to display the man page.
+@node Adding Export Back-ends
+@appendixsec Adding Export Back-ends
 
+@cindex Export, writing back-ends
 
-@kbd{C-c l} constructs and stores the link.
+Org's export engine makes it easy for writing new back-ends.  The
+framework on which the engine was built makes it easy to derive new
+back-ends from existing ones.
 
-@kbd{C-c l} calls the function @code{org-man-store-link}, which first checks
-if the @code{major-mode} is appropriate.  If check fails, the function
-returns @code{nil}.  Otherwise the function makes a link string by combining
-the @samp{man:} prefix with the man topic.  The function then calls
-@code{org-store-link-props} with @code{:type} and @code{:link} properties.  A
-@code{:description} property is an optional string that is displayed when the
-function inserts the link in the Org buffer.
+@findex org-export-define-backend
+@findex org-export-define-derived-backend
+The two main entry points to the export engine are:
+@code{org-export-define-backend} and @code{org-export-define-derived-backend}.
+To grok these functions, see @samp{ox-latex.el} for an example of defining
+a new back-end from scratch, and @samp{ox-beamer.el} for an example of
+deriving from an existing engine.
 
-@kbd{C-c C-l} inserts the stored link.
+For creating a new back-end from scratch, first set its name as
+a symbol in an alist consisting of elements and export functions.  To
+make the back-end visible to the export dispatcher, set @code{:menu-entry}
+keyword.  For export options specific to this back-end, set the
+@code{:options-alist}.
 
-To define new link types, define a function that implements completion
-support with @kbd{C-c C-l}.  This function should not accept any arguments
-but return the appropriate prefix and complete link string.
+For creating a new back-end from an existing one, set
+@code{:translate-alist} to an alist of export functions.  This alist
+replaces the parent back-end functions.
 
-@node Adding export back-ends
-@section Adding export back-ends
-@cindex Export, writing back-ends
+For complete documentation, see 
@uref{https://orgmode.org/worg/dev/org-export-reference.html, the Org Export 
Reference on Worg}.
 
-Org's export engine makes it easy for writing new back-ends.  The framework
-on which the engine was built makes it easy to derive new back-ends from
-existing ones.
+@node Tables in Arbitrary Syntax
+@appendixsec Tables in Arbitrary Syntax
 
-The two main entry points to the export engine are:
-@code{org-export-define-backend} and
-@code{org-export-define-derived-backend}.  To grok these functions, see
-@file{ox-latex.el} for an example of defining a new back-end from scratch,
-and @file{ox-beamer.el} for an example of deriving from an existing engine.
-
-For creating a new back-end from scratch, first set its name as a symbol in
-an alist consisting of elements and export functions.  To make the back-end
-visible to the export dispatcher, set @code{:menu-entry} keyword.  For export
-options specific to this back-end, set the @code{:options-alist}.
-
-For creating a new back-end from an existing one, set @code{:translate-alist}
-to an alist of export functions.  This alist replaces the parent back-end
-functions.
-
-For complete documentation, see
-@url{https://orgmode.org/worg/dev/org-export-reference.html, the Org Export
-Reference on Worg}.
-
-@node Context-sensitive commands
-@section Context-sensitive commands
-@cindex context-sensitive commands, hooks
-@cindex add-ons, context-sensitive commands
-@vindex org-ctrl-c-ctrl-c-hook
-
-Org has facilities for building context sensitive commands.  Authors of Org
-add-ons can tap into this functionality.
-
-Some Org commands change depending on the context.  The most important
-example of this behavior is the @kbd{C-c C-c} (@pxref{The very busy C-c C-c
-key}).  Other examples are @kbd{M-cursor} and @kbd{M-S-cursor}.
-
-These context sensitive commands work by providing a function that detects
-special context for that add-on and executes functionality appropriate for
-that context.
-
-@node Tables in arbitrary syntax
-@section Tables and lists in arbitrary syntax
 @cindex tables, in other modes
 @cindex lists, in other modes
 @cindex Orgtbl mode
 
-Because of Org's success in handling tables with Orgtbl, a frequently asked
-feature is to Org's usability functions to other table formats native to
-other modem's, such as @LaTeX{}.  This would be hard to do in a general way
-without complicated customization nightmares.  Moreover, that would take Org
-away from its simplicity roots that Orgtbl has proven.  There is, however, an
-alternate approach to accomplishing the same.
+Due to Org's success in handling tables with Orgtbl, a frequently
+requested feature is the use of Org's table functions in other modes,
+e.g., @LaTeX{}.  This would be hard to do in a general way without
+complicated customization nightmares.  Moreover, that would take Org
+away from its simplicity roots that Orgtbl has proven.  There is,
+however, an alternate approach to accomplishing the same.
 
 This approach involves implementing a custom @emph{translate} function that
 operates on a native Org @emph{source table} to produce a table in another
-format.  This strategy would keep the excellently working Orgtbl simple and
-isolate complications, if any, confined to the translate function.  To add
-more alien table formats, we just add more translate functions.  Also the
-burden of developing custom translate functions for new table formats will be
-in the hands of those who know those formats best.
-
-For an example of how this strategy works, see Orgstruct mode.  In that mode,
-Bastien added the ability to use Org's facilities to edit and re-structure
-lists.  He did by turning @code{orgstruct-mode} on, and then exporting the
-list locally to another format, such as HTML, @LaTeX{} or Texinfo.
+format.  This strategy would keep the excellently working Orgtbl
+simple and isolate complications, if any, confined to the translate
+function.  To add more alien table formats, we just add more translate
+functions.  Also the burden of developing custom translate functions
+for new table formats is in the hands of those who know those formats
+best.
 
 @menu
-* Radio tables::                Sending and receiving radio tables
-* A @LaTeX{} example::          Step by step, almost a tutorial
-* Translator functions::        Copy and modify
-* Radio lists::                 Sending and receiving lists
+* Radio tables::                 Sending and receiving radio tables.
+* A @LaTeX{} example::           Step by step, almost a tutorial.
+* Translator functions::         Copy and modify.
 @end menu
 
 @node Radio tables
-@subsection Radio tables
+@appendixsubsec Radio tables
+
 @cindex radio tables
 
 Radio tables are target locations for translated tables that are not near
 their source.  Org finds the target location and inserts the translated
 table.
 
-The key to finding the target location are the magic words @code{BEGIN/END
-RECEIVE ORGTBL}.  They have to appear as comments in the current mode.  If
-the mode is C, then:
+The key to finding the target location is the magic words @samp{BEGIN/END
+RECEIVE ORGTBL}.  They have to appear as comments in the current mode.
+If the mode is C, then:
 
 @example
 /* BEGIN RECEIVE ORGTBL table_name */
 /* END RECEIVE ORGTBL table_name */
 @end example
 
-@noindent
-At the location of source, Org needs a special line to direct Orgtbl to
-translate and to find the target for inserting the translated table.  For
-example:
-@cindex @code{#+ORGTBL}
+At the location of source, Org needs a special line to direct Orgtbl
+to translate and to find the target for inserting the translated
+table.  For example:
+
+@cindex @samp{ORGTBL}, keyword
 @example
-#+ORGTBL: SEND table_name translation_function arguments...
+#+ORGTBL: SEND table_name translation_function arguments ...
 @end example
 
+
 @noindent
-@code{table_name} is the table's reference name, which is also used in the
-receiver lines, and the @code{translation_function} is the Lisp function that
-translates.  This line, in addition, may also contain alternating key and
-value arguments at the end.  The translation function gets these values as a
-property list.  A few standard parameters are already recognized and acted
-upon before the translation function is called:
-
-@table @code
-@item :skip N
-Skip the first N lines of the table.  Hlines do count; include them if they
-are to be skipped.
-
-@item :skipcols (n1 n2 ...)
-List of columns to be skipped.  First Org automatically discards columns with
-calculation marks and then sends the table to the translator function, which
-then skips columns as specified in @samp{skipcols}.
+@samp{table_name} is the table's reference name, which is also used in the
+receiver lines, and the @samp{translation_function} is the Lisp function
+that translates.  This line, in addition, may also contain alternating
+key and value arguments at the end.  The translation function gets
+these values as a property list.  A few standard parameters are
+already recognized and acted upon before the translation function is
+called:
+
+@table @asis
+@item @samp{:skip N}
+Skip the first N lines of the table.  Hlines do count; include them
+if they are to be skipped.
+
+@item @samp{:skipcols (n1 n2 ...)}
+List of columns to be skipped.  First Org automatically discards
+columns with calculation marks and then sends the table to the
+translator function, which then skips columns as specified in
+@samp{skipcols}.
 @end table
 
-@noindent
-To keep the source table intact in the buffer without being disturbed when
-the source file is compiled or otherwise being worked on, use one of these
-strategies:
+To keep the source table intact in the buffer without being disturbed
+when the source file is compiled or otherwise being worked on, use one
+of these strategies:
 
-@itemize @bullet
+@itemize
 @item
-Place the table in a block comment.  For example, in C mode you could wrap
-the table between @samp{/*} and @samp{*/} lines.
+Place the table in a block comment.  For example, in C mode you
+could wrap the table between @samp{/*} and @samp{*/} lines.
+
 @item
-Put the table after an @samp{END} statement.  For example @samp{\bye} in
-@TeX{} and @samp{\end@{document@}} in @LaTeX{}.
+Put the table after an ``end'' statement.  For example @code{\bye} in @TeX{}
+and @code{\end@{document@}} in @LaTeX{}.
+
 @item
-Comment and uncomment each line of the table during edits.  The @kbd{M-x
-orgtbl-toggle-comment @key{RET}} command makes toggling easy.
+Comment and un-comment each line of the table during edits.  The
+@kbd{M-x orgtbl-toggle-comment} command makes toggling easy.
 @end itemize
 
 @node A @LaTeX{} example
-@subsection A @LaTeX{} example of radio tables
+@appendixsubsec A @LaTeX{} example of radio tables
+
 @cindex @LaTeX{}, and Orgtbl mode
 
-To wrap a source table in @LaTeX{}, use the @code{comment} environment
-provided by @file{comment.sty}.  To activate it, put
-@code{\usepackage@{comment@}} in the document header.  Orgtbl mode inserts a
-radio table skeleton@footnote{By default this works only for @LaTeX{}, HTML,
-and Texinfo.  Configure the variable @code{orgtbl-radio-table-templates} to
-install templates for other export formats.}  with the command @kbd{M-x
-orgtbl-insert-radio-table @key{RET}}, which prompts for a table name.  For
+To wrap a source table in @LaTeX{}, use the @samp{comment} environment
+provided by 
@samp{comment.sty}@footnote{@uref{https://www.ctan.org/pkg/comment}}.  To 
activate it, put
+@code{\usepackage@{comment@}} in the document header.  Orgtbl mode inserts
+a radio table skeleton@footnote{By default this works only for @LaTeX{}, HTML, 
and Texinfo.
+Configure the variable @code{orgtbl-radio-table-templates} to install
+templates for other modes.} with the command @kbd{M-x 
orgtbl-insert-radio-table}, which prompts for a table name.  For
 example, if @samp{salesfigures} is the name, the template inserts:
 
-@cindex @code{#+ORGTBL}, @samp{SEND}
 @example
 % BEGIN RECEIVE ORGTBL salesfigures
 % END RECEIVE ORGTBL salesfigures
@@ -18630,19 +21201,19 @@ example, if @samp{salesfigures} is the name, the 
template inserts:
 \end@{comment@}
 @end example
 
+@vindex LaTeX-verbatim-environments
 @noindent
-@vindex @LaTeX{}-verbatim-environments
-The line @code{#+ORGTBL: SEND} tells Orgtbl mode to use the function
+The line @samp{#+ORGTBL: SEND} tells Orgtbl mode to use the function
 @code{orgtbl-to-latex} to convert the table to @LaTeX{} format, then insert
-the table at the target (receive) location named @code{salesfigures}.  Now
+the table at the target (receive) location named @samp{salesfigures}.  Now
 the table is ready for data entry.  It can even use spreadsheet
-features@footnote{If the @code{#+TBLFM} line contains an odd number of dollar
-characters, this may cause problems with font-lock in @LaTeX{} mode.  As
-shown in the example you can fix this by adding an extra line inside the
-@code{comment} environment that is used to balance the dollar expressions.
-If you are using AUC@TeX{} with the font-latex library, a much better
-solution is to add the @code{comment} environment to the variable
-@code{LaTeX-verbatim-environments}.}:
+features@footnote{If the @samp{TBLFM} keyword contains an odd number of dollar
+characters, this may cause problems with Font Lock in @LaTeX{} mode.  As
+shown in the example you can fix this by adding an extra line inside
+the @samp{comment} environment that is used to balance the dollar
+expressions.  If you are using AUC@TeX{} with the font-latex library,
+a much better solution is to add the @samp{comment} environment to the
+variable @code{LaTeX-verbatim-environments}.}:
 
 @example
 % BEGIN RECEIVE ORGTBL salesfigures
@@ -18655,17 +21226,16 @@ solution is to add the @code{comment} environment to 
the variable
 | Feb   |   21 |      16 |     0.8 |
 | March |   22 |     278 |    12.6 |
 #+TBLFM: $4=$3/$2;%.1f
-% $ (optional extra dollar to keep font-lock happy, see footnote)
+% $ (optional extra dollar to keep Font Lock happy, see footnote)
 \end@{comment@}
 @end example
 
-@noindent
-After editing, @kbd{C-c C-c} inserts translated table at the target location,
-between the two marker lines.
+After editing, @kbd{C-c C-c} inserts the translated table at the
+target location, between the two marker lines.
 
-For hand-made custom tables, note that the translator needs to skip the first
-two lines of the source table.  Also the command has to @emph{splice} out the
-target table without the header and footer.
+For hand-made custom tables, note that the translator needs to skip
+the first two lines of the source table.  Also the command has to
+@emph{splice} out the target table without the header and footer.
 
 @example
 \begin@{tabular@}@{lrrr@}
@@ -18686,58 +21256,69 @@ Month & \multicolumn@{1@}@{c@}@{Days@} & Nr.\ sold & 
per day\\
 @end example
 
 The @LaTeX{} translator function @code{orgtbl-to-latex} is already part of
-Orgtbl mode and uses @code{tabular} environment by default to typeset the
-table and mark the horizontal lines with @code{\hline}.  For additional
-parameters to control output, @pxref{Translator functions}:
-
-@table @code
-@item :splice nil/t
-When non-@code{nil}, returns only table body lines; not wrapped in tabular
-environment.  Default is @code{nil}.
-
-@item :fmt fmt
-Format to warp each field.  It should contain @code{%s} for the original
-field value.  For example, to wrap each field value in dollar symbol, you
-could use @code{:fmt "$%s$"}.  Format can also wrap a property list with
-column numbers and formats, for example @code{:fmt (2 "$%s$" 4 "%s\\%%")}.
-In place of a string, a function of one argument can be used; the function
-must return a formatted string.
-
-@item :efmt efmt
-Format numbers as exponentials.  The spec should have @code{%s} twice for
-inserting mantissa and exponent, for example @code{"%s\\times10^@{%s@}"}.
-This may also be a property list with column numbers and formats, for example
-@code{:efmt (2 "$%s\\times10^@{%s@}$" 4 "$%s\\cdot10^@{%s@}$")}.  After
-@code{efmt} has been applied to a value, @code{fmt} will also be applied.
-Functions with two arguments can be supplied instead of strings.  By default,
-no special formatting is applied.
+Orgtbl mode and uses a @samp{tabular} environment to typeset the table and
+marks horizontal lines with @code{\hline}.  For additional parameters to
+control output, see @ref{Translator functions}:
+
+@table @asis
+@item @samp{:splice BOOLEAN}
+When @{@{@{var(BOOLEAN@}@}@} is non-@code{nil}, return only table body lines;
+i.e., not wrapped in @samp{tabular} environment.  Default is @code{nil}.
+
+@item @samp{:fmt FMT}
+Format string to warp each field.  It should contain @samp{%s} for the
+original field value.  For example, to wrap each field value in
+dollar symbol, you could use @samp{:fmt "$%s$"}.  Format can also wrap
+a property list with column numbers and formats, for example @samp{:fmt
+  (2 "$%s$" 4 "%s\\%%")}.  In place of a string, a function of one
+argument can be used; the function must return a formatted string.
+
+@item @samp{:efmt EFMT}
+Format numbers as exponentials.  The spec should have @samp{%s} twice for
+inserting mantissa and exponent, for example @samp{"%s\\times10^@{%s@}"}.  This
+may also be a property list with column numbers and formats, for
+example @samp{:efmt (2 "$%s\\times10^@{%s@}$" 4 "$%s\\cdot10^@{%s@}$")}.  After
+@var{EFMT} has been applied to a value, @var{FMT}---see
+above---is also applied.  Functions with two arguments can be
+supplied instead of strings.  By default, no special formatting is
+applied.
 @end table
 
 @node Translator functions
-@subsection Translator functions
+@appendixsubsec Translator functions
+
 @cindex HTML, and Orgtbl mode
 @cindex translator function
 
+@findex orgtbl-to-csv
+@findex orgtbl-to-tsv
+@findex orgtbl-to-latex
+@findex orgtbl-to-html
+@findex orgtbl-to-texinfo
+@findex orgtbl-to-unicode
+@findex orgtbl-to-orgtbl
+@findex orgtbl-to-generic
 Orgtbl mode has built-in translator functions: @code{orgtbl-to-csv}
 (comma-separated values), @code{orgtbl-to-tsv} (TAB-separated values),
 @code{orgtbl-to-latex}, @code{orgtbl-to-html}, @code{orgtbl-to-texinfo},
 @code{orgtbl-to-unicode} and @code{orgtbl-to-orgtbl}.  They use the generic
-translator, @code{orgtbl-to-generic}, which delegates translations to various
-export back-ends.
+translator, @code{orgtbl-to-generic}, which delegates translations to
+various export back-ends.
 
 Properties passed to the function through the @samp{ORGTBL SEND} line take
-precedence over properties defined inside the function.  For example, this
-overrides the default @LaTeX{} line endings, @samp{\\}, with @samp{\\[2mm]}:
+precedence over properties defined inside the function.  For example,
+this overrides the default @LaTeX{} line endings, @code{\\}, with 
@code{\\[2mm]}:
 
 @example
 #+ORGTBL: SEND test orgtbl-to-latex :lend " \\\\[2mm]"
 @end example
 
-For a new language translator, define a converter function.  It can be a
-generic function, such as shown in this example.  It marks a beginning and
-ending of a table with @samp{!BTBL!} and @samp{!ETBL!}; a beginning and
-ending of lines with @samp{!BL!} and @samp{!EL!}; and uses a TAB for a field
-separator:
+
+For a new language translator, define a converter function.  It can be
+a generic function, such as shown in this example.  It marks
+a beginning and ending of a table with @samp{!BTBL!} and @samp{!ETBL!};
+a beginning and ending of lines with @samp{!BL!} and @samp{!EL!}; and uses a 
TAB
+for a field separator:
 
 @lisp
 (defun orgtbl-to-language (table params)
@@ -18750,104 +21331,73 @@ separator:
 @end lisp
 
 @noindent
-The documentation for the @code{orgtbl-to-generic} function shows a complete
-list of parameters, each of which can be passed through to
-@code{orgtbl-to-latex}, @code{orgtbl-to-texinfo}, and any other function
-using that generic function.
+The documentation for the @code{orgtbl-to-generic} function shows
+a complete list of parameters, each of which can be passed through to
+@code{orgtbl-to-latex}, @code{orgtbl-to-texinfo}, and any other function using
+that generic function.
 
 For complicated translations the generic translator function could be
-replaced by a custom translator function.  Such a custom function must take
-two arguments and return a single string containing the formatted table.  The
-first argument is the table whose lines are a list of fields or the symbol
-@code{hline}.  The second argument is the property list consisting of
-parameters specified in the @samp{#+ORGTBL: SEND} line.  Please share your
-translator functions by posting them to the Org users mailing list,
-@email{emacs-orgmode@@gnu.org}.
-
-@node Radio lists
-@subsection Radio lists
-@cindex radio lists
-@cindex @code{org-list-insert-radio-list}
-
-Call the @code{org-list-insert-radio-list} function to insert a radio list
-template in HTML, @LaTeX{}, and Texinfo mode documents.  Sending and
-receiving radio lists works is the same as for radio tables (@pxref{Radio
-tables}) except for these differences:
-
-@cindex @code{#+ORGLST}
-@itemize @minus
-@item
-Orgstruct mode must be active.
-@item
-Use @code{ORGLST} keyword instead of @code{ORGTBL}.
-@item
-@kbd{C-c C-c} works only on the first list item.
-@end itemize
-
-Built-in translators functions are: @code{org-list-to-latex},
-@code{org-list-to-html} and @code{org-list-to-texinfo}.  They use the
-@code{org-list-to-generic} translator function.  See its documentation for
-parameters for accurate customizations of lists.  Here is a @LaTeX{} example:
-
-@example
-% BEGIN RECEIVE ORGLST to-buy
-% END RECEIVE ORGLST to-buy
-\begin@{comment@}
-#+ORGLST: SEND to-buy org-list-to-latex
-- a new house
-- a new computer
-  + a new keyboard
-  + a new mouse
-- a new life
-\end@{comment@}
-@end example
+replaced by a custom translator function.  Such a custom function must
+take two arguments and return a single string containing the formatted
+table.  The first argument is the table whose lines are a list of
+fields or the symbol @code{hline}.  The second argument is the property
+list consisting of parameters specified in the @samp{#+ORGTBL: SEND} line.
+Please share your translator functions by posting them to the Org
+users mailing list, at @email{emacs-orgmode@@gnu.org}.
 
-@kbd{C-c C-c} on @samp{a new house} inserts the translated @LaTeX{} list
-in-between the BEGIN and END marker lines.
+@node Dynamic Blocks
+@appendixsec Dynamic Blocks
 
-@node Dynamic blocks
-@section Dynamic blocks
 @cindex dynamic blocks
 
-Org supports @emph{dynamic blocks} in Org documents.  They are inserted with
-begin and end markers like any other @samp{src} code block, but the contents
-are updated automatically by a user function.  For example, @kbd{C-c C-x C-r}
-inserts a dynamic table that updates the work time (@pxref{Clocking work
-time}).
+Org supports @emph{dynamic blocks} in Org documents.  They are inserted
+with begin and end markers like any other code block, but the contents
+are updated automatically by a user function.
+
+@kindex C-c C-x x
+@findex org-dynamic-block-insert-dblock
+You can insert a dynamic block with @code{org-dynamic-block-insert-dblock},
+which is bound to @kbd{C-c C-x x} by default.  For example,
+@kbd{C-c C-x x c l o c k t a b l e @key{RET}} inserts a table that
+updates the work time (see @ref{Clocking Work Time}).
 
-Dynamic blocks can have names and function parameters.  The syntax is similar
-to @samp{src} code block specifications:
+Dynamic blocks can have names and function parameters.  The syntax is
+similar to source code block specifications:
 
-@cindex @code{#+BEGIN}, dynamic block
 @example
 #+BEGIN: myblock :parameter1 value1 :parameter2 value2 ...
-
+  ...
 #+END:
 @end example
 
-These command update dynamic blocks:
+These commands update dynamic blocks:
 
-@table @kbd
-@orgcmd{C-c C-x C-u,org-dblock-update}
+@table @asis
+@item @kbd{C-c C-x C-u} (@code{org-dblock-update})
+@kindex C-c C-x C-u
+@findex org-dblock-update
 Update dynamic block at point.
-@orgkey{C-u C-c C-x C-u}
+
+@item @kbd{C-u C-c C-x C-u}
+@kindex C-u C-c C-x C-u
 Update all dynamic blocks in the current file.
 @end table
 
-Before updating a dynamic block, Org removes content between the BEGIN and
-END markers.  Org then reads the parameters on the BEGIN line for passing to
-the writer function.  If the function expects to access the removed content,
-then Org expects an extra parameter, @code{:content}, on the BEGIN line.
+Before updating a dynamic block, Org removes content between the
+@samp{BEGIN} and @samp{END} markers.  Org then reads the parameters on the
+@samp{BEGIN} line for passing to the writer function as a plist. The
+previous content of the dynamic block becomes erased from the buffer
+and appended to the plist under @code{:content}.
 
-To syntax for calling a writer function with a named block, @code{myblock}
-is: @code{org-dblock-write:myblock}.  Parameters come from the BEGIN line.
+The syntax for naming a writer function with a dynamic block labelled
+@samp{myblock} is: @code{org-dblock-write:myblock}.
 
 The following is an example of a dynamic block and a block writer function
 that updates the time when the function was last run:
 
 @example
 #+BEGIN: block-update-time :format "on %m/%d/%Y at %H:%M"
-
+  ...
 #+END:
 @end example
 
@@ -18866,35 +21416,36 @@ To keep dynamic blocks up-to-date in an Org file, use 
the function,
 @code{org-update-all-dblocks} function does not run if the file is not in
 Org mode.
 
+@findex org-narrow-to-block
 Dynamic blocks, like any other block, can be narrowed with
 @code{org-narrow-to-block}.
 
-@node Special agenda views
-@section Special agenda views
+@node Special Agenda Views
+@appendixsec Special Agenda Views
+
 @cindex agenda views, user-defined
 
 @vindex org-agenda-skip-function
 @vindex org-agenda-skip-function-global
 Org provides a special hook to further limit items in agenda views:
-@code{agenda}, @code{agenda*}@footnote{The @code{agenda*} view is the same as
-@code{agenda} except that it only considers @emph{appointments}, i.e.,
-scheduled and deadline items that have a time specification @samp{[h]h:mm} in
-their time-stamps.}, @code{todo}, @code{alltodo}, @code{tags},
-@code{tags-todo}, @code{tags-tree}.  Specify a custom function that tests
-inclusion of every matched item in the view.  This function can also
-skip as much as is needed.
+@code{agenda}, @code{agenda*}@footnote{The @code{agenda*} view is the same as 
@code{agenda} except that it
+only considers @emph{appointments}, i.e., scheduled and deadline items that
+have a time specification @samp{[h]h:mm} in their time-stamps.}, @code{todo}, 
@code{alltodo}, @code{tags}, @code{tags-todo},
+@code{tags-tree}.  Specify a custom function that tests inclusion of every
+matched item in the view.  This function can also skip as much as is
+needed.
 
 For a global condition applicable to agenda views, use the
-@code{org-agenda-skip-function-global} variable.  Org uses a global condition
-with @code{org-agenda-skip-function} for custom searching.
+@code{org-agenda-skip-function-global} variable.  Org uses a global
+condition with @code{org-agenda-skip-function} for custom searching.
 
-This example defines a function for a custom view showing TODO items with
-WAITING status.  Manually this is a multi step search process, but with a
-custom view, this can be automated as follows:
+This example defines a function for a custom view showing TODO items
+with @samp{waiting} status.  Manually this is a multi-step search process,
+but with a custom view, this can be automated as follows:
 
-The custom function searches the subtree for the WAITING tag and returns
-@code{nil} on match.  Otherwise it gives the location from where the search
-continues.
+The custom function searches the subtree for the @samp{waiting} tag and
+returns @code{nil} on match.  Otherwise it gives the location from where
+the search continues.
 
 @lisp
 (defun my-skip-unless-waiting ()
@@ -18920,41 +21471,48 @@ meaningful string suitable for the agenda view.
 
 @vindex org-odd-levels-only
 @vindex org-agenda-skip-function
-
-Search for entries with a limit set on levels for the custom search.  This is
-a general approach to creating custom searches in Org.  To include all
-levels, use @samp{LEVEL>0}@footnote{Note that, for
-@code{org-odd-levels-only}, a level number corresponds to order in the
-hierarchy, not to the number of stars.}.  Then to selectively pick the
-matched entries, use @code{org-agenda-skip-function}, which also accepts Lisp
-forms, such as @code{org-agenda-skip-entry-if} and
+Search for entries with a limit set on levels for the custom search.
+This is a general approach to creating custom searches in Org.  To
+include all levels, use @samp{LEVEL>0}@footnote{Note that, for 
@code{org-odd-levels-only}, a level number
+corresponds to order in the hierarchy, not to the number of stars.}.  Then to 
selectively pick
+the matched entries, use @code{org-agenda-skip-function}, which also
+accepts Lisp forms, such as @code{org-agenda-skip-entry-if} and
 @code{org-agenda-skip-subtree-if}.  For example:
 
-@table @code
-@item (org-agenda-skip-entry-if 'scheduled)
+@table @asis
+@item @samp{(org-agenda-skip-entry-if 'scheduled)}
 Skip current entry if it has been scheduled.
-@item (org-agenda-skip-entry-if 'notscheduled)
+
+@item @samp{(org-agenda-skip-entry-if 'notscheduled)}
 Skip current entry if it has not been scheduled.
-@item (org-agenda-skip-entry-if 'deadline)
+
+@item @samp{(org-agenda-skip-entry-if 'deadline)}
 Skip current entry if it has a deadline.
-@item (org-agenda-skip-entry-if 'scheduled 'deadline)
+
+@item @samp{(org-agenda-skip-entry-if 'scheduled 'deadline)}
 Skip current entry if it has a deadline, or if it is scheduled.
-@item (org-agenda-skip-entry-if 'todo '("TODO" "WAITING"))
-Skip current entry if the TODO keyword is TODO or WAITING.
-@item (org-agenda-skip-entry-if 'todo 'done)
+
+@item @samp{(org-agenda-skip-entry-if 'todo '("TODO" "WAITING"))}
+Skip current entry if the TODO keyword is TODO or WAITING@.
+
+@item @samp{(org-agenda-skip-entry-if 'todo 'done)}
 Skip current entry if the TODO keyword marks a DONE state.
-@item (org-agenda-skip-entry-if 'timestamp)
-Skip current entry if it has any timestamp, may also be deadline or scheduled.
-@anchor{x-agenda-skip-entry-regexp}
-@item (org-agenda-skip-entry-if 'regexp "regular expression")
+
+@item @samp{(org-agenda-skip-entry-if 'timestamp)}
+Skip current entry if it has any timestamp, may also be deadline or
+scheduled.
+
+@item @samp{(org-agenda-skip-entry-if 'regexp "regular expression")}
 Skip current entry if the regular expression matches in the entry.
-@item (org-agenda-skip-entry-if 'notregexp "regular expression")
+
+@item @samp{(org-agenda-skip-entry-if 'notregexp "regular expression")}
 Skip current entry unless the regular expression matches.
-@item (org-agenda-skip-subtree-if 'regexp "regular expression")
+
+@item @samp{(org-agenda-skip-subtree-if 'regexp "regular expression")}
 Same as above, but check and skip the entire subtree.
 @end table
 
-The following is an example of a search for @samp{WAITING} without the
+The following is an example of a search for @samp{waiting} without the
 special function:
 
 @lisp
@@ -18965,61 +21523,72 @@ special function:
     (org-agenda-overriding-header "Projects waiting for something: "))))
 @end lisp
 
-@node Speeding up your agendas
-@section Speeding up your agendas
+@node Speeding Up Your Agendas
+@appendixsec Speeding Up Your Agendas
+
 @cindex agenda views, optimization
 
-Some agenda commands slow down when the Org files grow in size or number.
-Here are tips to speed up:
+Some agenda commands slow down when the Org files grow in size or
+number.  Here are tips to speed up:
 
-@enumerate
+@itemize
 @item
 Reduce the number of Org agenda files to avoid slowdowns due to hard drive
 accesses.
+
 @item
-Reduce the number of @samp{DONE} and archived headlines so agenda operations
-that skip over these can finish faster.
+Reduce the number of DONE and archived headlines so agenda
+operations that skip over these can finish faster.
+
 @item
-@vindex org-agenda-dim-blocked-tasks
 Do not dim blocked tasks:
+@vindex org-agenda-dim-blocked-tasks
+
 @lisp
 (setq org-agenda-dim-blocked-tasks nil)
 @end lisp
+
 @item
+Stop preparing agenda buffers on startup:
 @vindex org-startup-folded
 @vindex org-agenda-inhibit-startup
-Stop preparing agenda buffers on startup:
+
 @lisp
-(setq org-agenda-inhibit-startup nil)
+(setq org-agenda-inhibit-startup t)
 @end lisp
+
 @item
+Disable tag inheritance for agendas:
 @vindex org-agenda-show-inherited-tags
 @vindex org-agenda-use-tag-inheritance
-Disable tag inheritance for agendas:
+
 @lisp
 (setq org-agenda-use-tag-inheritance nil)
 @end lisp
-@end enumerate
+@end itemize
 
-These options can be applied to selected agenda views.  For more details
-about generation of agenda views, see the docstrings for the relevant
-variables, and this @uref{https://orgmode.org/worg/agenda-optimization.html,
-dedicated Worg page} for agenda optimization.
+These options can be applied to selected agenda views.  For more
+details about generation of agenda views, see the docstrings for the
+relevant variables, and this 
@uref{https://orgmode.org/worg/agenda-optimization.html, dedicated Worg page} 
for agenda
+optimization.
+
+@node Extracting Agenda Information
+@appendixsec Extracting Agenda Information
 
-@node Extracting agenda information
-@section Extracting agenda information
 @cindex agenda, pipe
-@cindex Scripts, for agenda processing
+@cindex scripts, for agenda processing
 
-@vindex org-agenda-custom-commands
-Org provides commands to access agendas through Emacs batch mode.  Through
-this command-line interface, agendas are automated for further processing or
-printing.
+Org provides commands to access agendas through Emacs batch mode.
+Through this command-line interface, agendas are automated for further
+processing or printing.
 
+@vindex org-agenda-custom-commands
+@findex org-batch-agenda
 @code{org-batch-agenda} creates an agenda view in ASCII and outputs to
-STDOUT.  This command takes one string parameter.  When string length=1, Org
-uses it as a key to @code{org-agenda-custom-commands}.  These are the same
-ones available through @kbd{C-c a}.
+standard output.  This command takes one string parameter.  When
+string consists of a single character, Org uses it as a key to
+@code{org-agenda-custom-commands}.  These are the same ones available
+through the agenda dispatcher (see @ref{Agenda Dispatcher}).
 
 This example command line directly prints the TODO list to the printer:
 
@@ -19027,9 +21596,11 @@ This example command line directly prints the TODO 
list to the printer:
 emacs -batch -l ~/.emacs -eval '(org-batch-agenda "t")' | lpr
 @end example
 
-When the string parameter length is two or more characters, Org matches it
-with tags/TODO strings.  For example, this example command line prints items
-tagged with @samp{shop}, but excludes items tagged with @samp{NewYork}:
+
+When the string parameter length is two or more characters, Org
+matches it with tags/TODO strings.  For example, this example command
+line prints items tagged with @samp{shop}, but excludes items tagged with
+@samp{NewYork}:
 
 @example
 emacs -batch -l ~/.emacs                                      \
@@ -19042,52 +21613,76 @@ An example showing on-the-fly parameter modifications:
 @example
 emacs -batch -l ~/.emacs                                      \
    -eval '(org-batch-agenda "a"                               \
-            org-agenda-span (quote month)                     \
-            org-agenda-include-diary nil                      \
-            org-agenda-files (quote ("~/org/project.org")))'  \
+           org-agenda-span (quote month)                      \
+           org-agenda-include-diary nil                       \
+           org-agenda-files (quote ("~/org/project.org")))'   \
    | lpr
 @end example
 
 @noindent
-which will produce an agenda for the next 30 days from just the
-@file{~/org/projects.org} file.
+which produces an agenda for the next 30 days from just the
+@samp{~/org/projects.org} file.
 
+@findex org-batch-agenda-csv
 For structured processing of agenda output, use @code{org-batch-agenda-csv}
 with the following fields:
 
-@example
-category     @r{The category of the item}
-head         @r{The headline, without TODO keyword, TAGS and PRIORITY}
-type         @r{The type of the agenda entry, can be}
-                todo               @r{selected in TODO match}
-                tagsmatch          @r{selected in tags match}
-                diary              @r{imported from diary}
-                deadline           @r{a deadline}
-                scheduled          @r{scheduled}
-                timestamp          @r{appointment, selected by timestamp}
-                closed             @r{entry was closed on date}
-                upcoming-deadline  @r{warning about nearing deadline}
-                past-scheduled     @r{forwarded scheduled item}
-                block              @r{entry has date block including date}
-todo         @r{The TODO keyword, if any}
-tags         @r{All tags including inherited ones, separated by colons}
-date         @r{The relevant date, like 2007-2-14}
-time         @r{The time, like 15:00-16:50}
-extra        @r{String with extra planning info}
-priority-l   @r{The priority letter if any was given}
-priority-n   @r{The computed numerical priority}
-@end example
+@table @asis
+@item category
+The category of the item
+@item head
+The headline, without TODO keyword, TAGS and PRIORITY
+@item type
+The type of the agenda entry, can be
+
+@multitable {aaaaaaaaaaaaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
+@item @code{todo}
+@tab selected in TODO match
+@item @code{tagsmatch}
+@tab selected in tags match
+@item @code{diary}
+@tab imported from diary
+@item @code{deadline}
+@tab a deadline
+@item @code{scheduled}
+@tab scheduled
+@item @code{timestamp}
+@tab appointment, selected by timestamp
+@item @code{closed}
+@tab entry was closed on date
+@item @code{upcoming-deadline}
+@tab warning about nearing deadline
+@item @code{past-scheduled}
+@tab forwarded scheduled item
+@item @code{block}
+@tab entry has date block including date
+@end multitable
 
-@noindent
-If the selection of the agenda item was based on a timestamp, including those
-items with @code{DEADLINE} and @code{SCHEDULED} keywords, then Org includes
-date and time in the output.
+@item todo
+The TODO keyword, if any
+@item tags
+All tags including inherited ones, separated by colons
+@item date
+The relevant date, like @samp{2007-2-14}
+@item time
+The time, like @samp{15:00-16:50}
+@item extra
+String with extra planning info
+@item priority-l
+The priority letter if any was given
+@item priority-n
+The computed numerical priority
+@end table
+
+If the selection of the agenda item was based on a timestamp,
+including those items with @samp{DEADLINE} and @samp{SCHEDULED} keywords, then
+Org includes date and time in the output.
 
 If the selection of the agenda item was based on a timestamp  (or
 deadline/scheduled), then Org includes date and time in the output.
 
-Here is an example of a post-processing script in Perl.  It takes the CSV
-output from Emacs and prints with a checkbox:
+Here is an example of a post-processing script in Perl.  It takes the
+CSV output from Emacs and prints with a checkbox:
 
 @example
 #!/usr/bin/perl
@@ -19100,49 +21695,55 @@ $agenda = qx@{$cmd 2>/dev/null@};
 
 # loop over all lines
 foreach $line (split(/\n/,$agenda)) @{
-  # get the individual values
-  ($category,$head,$type,$todo,$tags,$date,$time,$extra,
-   $priority_l,$priority_n) = split(/,/,$line);
-  # process and print
-  print "[ ] $head\n";
+    # get the individual values
+    ($category,$head,$type,$todo,$tags,$date,$time,$extra,
+     $priority_l,$priority_n) = split(/,/,$line);
+    # process and print
+    print "[ ] $head\n";
 @}
 @end example
 
-@node Using the property API
-@section Using the property API
+@node Using the Property API
+@appendixsec Using the Property API
+
 @cindex API, for properties
 @cindex properties, API
 
-Functions for working with properties.
+Here is a description of the functions that can be used to work with
+properties.
 
 @defun org-entry-properties &optional pom which
-Get all properties of the entry at point-or-marker POM.@*
+Get all properties of the entry at point-or-marker @var{POM}.
 This includes the TODO keyword, the tags, time strings for deadline,
 scheduled, and clocking, and any additional properties defined in the
 entry.  The return value is an alist.  Keys may occur multiple times
-if the property key was used several times.@*
-POM may also be @code{nil}, in which case the current entry is used.
-If WHICH is @code{nil} or @code{all}, get all properties.  If WHICH is
-@code{special} or @code{standard}, only get that subclass.
+if the property key was used several times.  @var{POM} may also
+be @code{nil}, in which case the current entry is used.  If
+@var{WHICH} is @code{nil} or @code{all}, get all properties.  If
+@var{WHICH} is @code{special} or @code{standard}, only get that subclass.
 @end defun
 
 @vindex org-use-property-inheritance
 @findex org-insert-property-drawer
 @defun org-entry-get pom property &optional inherit
-Get value of @code{PROPERTY} for entry at point-or-marker @code{POM}@.  By
-default, this only looks at properties defined locally in the entry.  If
-@code{INHERIT} is non-@code{nil} and the entry does not have the property,
-then also check higher levels of the hierarchy.  If @code{INHERIT} is the
-symbol @code{selective}, use inheritance if and only if the setting of
-@code{org-use-property-inheritance} selects @code{PROPERTY} for inheritance.
+Get value of @var{PROPERTY} for entry at point-or-marker
+@var{POM}.  By default, this only looks at properties defined
+locally in the entry.  If @var{INHERIT} is non-@code{nil} and the
+entry does not have the property, then also check higher levels of the
+hierarchy.  If @var{INHERIT} is the symbol @code{selective}, use
+inheritance if and only if the setting of
+@code{org-use-property-inheritance} selects @var{PROPERTY} for
+inheritance.
 @end defun
 
 @defun org-entry-delete pom property
-Delete the property @code{PROPERTY} from entry at point-or-marker POM.
+Delete the property @var{PROPERTY} from entry at point-or-marker
+@var{POM}.
 @end defun
 
 @defun org-entry-put pom property value
-Set @code{PROPERTY} to @code{VALUE} for entry at point-or-marker POM.
+Set @var{PROPERTY} to @var{VALUES} for entry at
+point-or-marker POM@.
 @end defun
 
 @defun org-buffer-property-keys &optional include-specials
@@ -19150,123 +21751,148 @@ Get all property keys in the current buffer.
 @end defun
 
 @defun org-insert-property-drawer
-Insert a property drawer for the current entry.
+Insert a property drawer for the current entry.  Also
 @end defun
 
 @defun org-entry-put-multivalued-property pom property &rest values
-Set @code{PROPERTY} at point-or-marker @code{POM} to @code{VALUES}@.
-@code{VALUES} should be a list of strings.  They will be concatenated, with
-spaces as separators.
+Set @var{PROPERTY} at point-or-marker @var{POM} to
+@var{VALUES}.  @var{VALUES} should be a list of strings.
+They are concatenated, with spaces as separators.
 @end defun
 
 @defun org-entry-get-multivalued-property pom property
-Treat the value of the property @code{PROPERTY} as a whitespace-separated
-list of values and return the values as a list of strings.
+Treat the value of the property @var{PROPERTY} as
+a whitespace-separated list of values and return the values as a list
+of strings.
 @end defun
 
 @defun org-entry-add-to-multivalued-property pom property value
-Treat the value of the property @code{PROPERTY} as a whitespace-separated
-list of values and make sure that @code{VALUE} is in this list.
+Treat the value of the property @var{PROPERTY} as
+a whitespace-separated list of values and make sure that
+@var{VALUE} is in this list.
 @end defun
 
 @defun org-entry-remove-from-multivalued-property pom property value
-Treat the value of the property @code{PROPERTY} as a whitespace-separated
-list of values and make sure that @code{VALUE} is @emph{not} in this list.
+Treat the value of the property @var{PROPERTY} as
+a whitespace-separated list of values and make sure that
+@var{VALUE} is @emph{not} in this list.
 @end defun
 
 @defun org-entry-member-in-multivalued-property pom property value
-Treat the value of the property @code{PROPERTY} as a whitespace-separated
-list of values and check if @code{VALUE} is in this list.
+Treat the value of the property @var{PROPERTY} as
+a whitespace-separated list of values and check if @var{VALUE} is
+in this list.
 @end defun
 
 @defopt org-property-allowed-value-functions
 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
+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
 to be entered.  The functions must return @code{nil} if they are not
 responsible for this property.
 @end defopt
 
-@node Using the mapping API
-@section Using the mapping API
+@node Using the Mapping API
+@appendixsec Using the Mapping API
+
 @cindex API, for mapping
 @cindex mapping entries, API
 
-Org has sophisticated mapping capabilities for finding entries.  Org uses
-this functionality internally for generating agenda views.  Org also exposes
-an API for executing arbitrary functions for each selected entry.  The API's
-main entry point is:
+Org has sophisticated mapping capabilities to find all entries
+satisfying certain criteria.  Internally, this functionality is used
+to produce agenda views, but there is also an API that can be used to
+execute arbitrary functions for each or selected entries.  The main
+entry point for this API is:
 
 @defun org-map-entries func &optional match scope &rest skip
-Call @samp{FUNC} at each headline selected by @code{MATCH} in @code{SCOPE}.
-
-@samp{FUNC} is a function or a Lisp form.  With the cursor positioned at the
-beginning of the headline, call the function without arguments.  Org returns
-an alist of return values of calls to the function.
-
-To avoid preserving point, Org wraps the call to @code{FUNC} in
-save-excursion form.  After evaluation, Org moves the cursor to the end of
-the line that was just processed.  Search continues from that point forward.
-This may not always work as expected under some conditions, such as if the
-current sub-tree was removed by a previous archiving operation.  In such rare
-circumstances, Org skips the next entry entirely when it should not.  To stop
-Org from such skips, make @samp{FUNC} set the variable
-@code{org-map-continue-from} to a specific buffer position.
-
-@samp{MATCH} is a tags/property/TODO match.  Org iterates only matched
-headlines.  Org iterates over all headlines when @code{MATCH} is @code{nil}
-or @code{t}.
-
-@samp{SCOPE} determines the scope of this command.  It can be any of:
-
-@example
-nil     @r{the current buffer, respecting the restriction if any}
-tree    @r{the subtree started with the entry at point}
-region  @r{The entries within the active region, if any}
-file    @r{the current buffer, without restriction}
-file-with-archives
-        @r{the current buffer, and any archives associated with it}
-agenda  @r{all agenda files}
-agenda-with-archives
-        @r{all agenda files with any archive files associated with them}
-(file1 file2 ...)
-        @r{if this is a list, all files in the list will be scanned}
-@end example
+Call @var{FUNC} at each headline selected by @var{MATCH} in
+@var{SCOPE}.
+
+@var{FUNC} is a function or a Lisp form.  With point positioned
+at the beginning of the headline, call the function without arguments.
+Org returns an alist of return values of calls to the function.
+
+To avoid preserving point, Org wraps the call to @var{FUNC} in
+@code{save-excursion} form.  After evaluation, Org moves point to the end
+of the line that was just processed.  Search continues from that point
+forward.  This may not always work as expected under some conditions,
+such as if the current sub-tree was removed by a previous archiving
+operation.  In such rare circumstances, Org skips the next entry
+entirely when it should not.  To stop Org from such skips, make
+@var{FUNC} set the variable @code{org-map-continue-from} to a specific
+buffer position.
+
+@var{MATCH} is a tags/property/TODO match.  Org iterates only
+matched headlines.  Org iterates over all headlines when
+@var{MATCH} is @code{nil} or @code{t}.
+
+@var{SCOPE} determines the scope of this command.  It can be any
+of:
+
+@table @asis
+@item @code{nil}
+The current buffer, respecting the restriction, if any.
+
+@item @code{tree}
+The subtree started with the entry at point.
+
+@item @code{region}
+The entries within the active region, if any.
+
+@item @code{file}
+The current buffer, without restriction.
+
+@item @code{file-with-archives}
+The current buffer, and any archives associated with it.
+
+@item @code{agenda}
+All agenda files.
+
+@item @code{agenda-with-archives}
+All agenda files with any archive files associated with them.
+
+@item list of filenames
+If this is a list, all files in the list are scanned.
+@end table
+
 @noindent
-The remaining args are treated as settings for the scanner's skipping
-facilities.  Valid args are:
+The remaining arguments are treated as settings for the scanner's
+skipping facilities.  Valid arguments are:
 
+@table @asis
+@item @code{archive}
+Skip trees with the @samp{ARCHIVE} tag.
+
+@item @code{comment}
+Skip trees with the COMMENT keyword.
+
+@item function or Lisp form
 @vindex org-agenda-skip-function
-@example
-archive   @r{skip trees with the archive tag}
-comment   @r{skip trees with the COMMENT keyword}
-function or Lisp form
-          @r{will be used as value for @code{org-agenda-skip-function},}
-          @r{so whenever the function returns t, FUNC}
-          @r{will not be called for that entry and search will}
-          @r{continue from the point where the function leaves it}
-@end example
+Used as value for @code{org-agenda-skip-function}, so whenever the
+function returns @code{t}, @var{FUNC} is called for that entry and
+search continues from the point where the function leaves it.
+@end table
 @end defun
 
-The mapping routine can call any arbitrary function, even functions that
-change meta data or query the property API (@pxref{Using the property API}).
-Here are some handy functions:
+The mapping routine can call any arbitrary function, even functions
+that change meta data or query the property API (see @ref{Using the Property 
API}).  Here are some handy functions:
 
 @defun org-todo &optional arg
-Change the TODO state of the entry.  See the docstring of the functions for
-the many possible values for the argument @code{ARG}.
+Change the TODO state of the entry.  See the docstring of the
+functions for the many possible values for the argument
+@var{ARG}.
 @end defun
 
 @defun org-priority &optional action
-Change the priority of the entry.  See the docstring of this function for the
-possible values for @code{ACTION}.
+Change the priority of the entry.  See the docstring of this function
+for the possible values for @var{ACTION}.
 @end defun
 
 @defun org-toggle-tag tag &optional onoff
-Toggle the tag @code{TAG} in the current entry.  Setting @code{ONOFF} to
-either @code{on} or @code{off} will not toggle tag, but ensure that it is
-either on or off.
+Toggle the tag @var{TAG} in the current entry.  Setting
+@var{ONOFF} to either @code{on} or @code{off} does not toggle tag, but
+ensure that it is either on or off.
 @end defun
 
 @defun org-promote
@@ -19277,437 +21903,996 @@ Promote the current entry.
 Demote the current entry.
 @end defun
 
-This example turns all entries tagged with @code{TOMORROW} into TODO entries
-with keyword @code{UPCOMING}.  Org ignores entries in comment trees and
-archive trees.
+This example turns all entries tagged with @samp{TOMORROW} into TODO
+entries with keyword @samp{UPCOMING}.  Org ignores entries in comment trees
+and archive trees.
 
 @lisp
-(org-map-entries
- '(org-todo "UPCOMING")
- "+TOMORROW" 'file 'archive 'comment)
+(org-map-entries '(org-todo "UPCOMING")
+                 "+TOMORROW" 'file 'archive 'comment)
 @end lisp
 
 The following example counts the number of entries with TODO keyword
-@code{WAITING}, in all agenda files.
+@samp{WAITING}, in all agenda files.
 
 @lisp
 (length (org-map-entries t "/+WAITING" 'agenda))
 @end lisp
 
-@node History and acknowledgments
-@appendix History and acknowledgments
-@cindex acknowledgments
-@cindex history
-@cindex thanks
-
-@section From Carsten
-
-Org was born in 2003, out of frustration over the user interface of the Emacs
-Outline mode.  I was trying to organize my notes and projects, and using
-Emacs seemed to be the natural way to go.  However, having to remember eleven
-different commands with two or three keys per command, only to hide and show
-parts of the outline tree, that seemed entirely unacceptable.  Also, when
-using outlines to take notes, I constantly wanted to restructure the tree,
-organizing it paralleling my thoughts and plans.  @emph{Visibility cycling}
+@node History and Acknowledgments
+@appendix History and Acknowledgments
+
+
+
+@anchor{From Carsten}
+@appendixsec From Carsten
+
+Org was born in 2003, out of frustration over the user interface of
+the Emacs Outline mode.  I was trying to organize my notes and
+projects, and using Emacs seemed to be the natural way to go.
+However, having to remember eleven different commands with two or
+three keys per command, only to hide and show parts of the outline
+tree, that seemed entirely unacceptable to me.  Also, when using
+outlines to take notes, I constantly wanted to restructure the tree,
+organizing it parallel to my thoughts and plans.  @emph{Visibility cycling}
 and @emph{structure editing} were originally implemented in the package
-@file{outline-magic.el}, but quickly moved to the more general @file{org.el}.
-As this environment became comfortable for project planning, the next step
-was adding @emph{TODO entries}, basic @emph{timestamps}, and @emph{table
-support}.  These areas highlighted the two main goals that Org still has
-today: to be a new, outline-based, plain text mode with innovative and
-intuitive editing features, and to incorporate project planning functionality
-directly into a notes file.
-
-Since the first release, literally thousands of emails to me or to
-@email{emacs-orgmode@@gnu.org} have provided a constant stream of bug
-reports, feedback, new ideas, and sometimes patches and add-on code.
-Many thanks to everyone who has helped to improve this package.  I am
-trying to keep here a list of the people who had significant influence
-in shaping one or more aspects of Org.  The list may not be
-complete, if I have forgotten someone, please accept my apologies and
-let me know.
+@samp{outline-magic.el}, but quickly moved to the more general @samp{org.el}.
+As this environment became comfortable for project planning, the next
+step was adding @emph{TODO entries}, basic @emph{timestamps}, and @emph{table
+support}.  These areas highlighted the two main goals that Org still
+has today: to be a new, outline-based, plain text mode with innovative
+and intuitive editing features, and to incorporate project planning
+functionality directly into a notes file.
+
+Since the first release, literally thousands of emails to me or to the
+@email{emacs-orgmode@@gnu.org, mailing list} have provided a constant stream 
of bug reports, feedback,
+new ideas, and sometimes patches and add-on code.  Many thanks to
+everyone who has helped to improve this package.  I am trying to keep
+here a list of the people who had significant influence in shaping one
+or more aspects of Org.  The list may not be complete, if I have
+forgotten someone, please accept my apologies and let me know.
 
 Before I get to this list, a few special mentions are in order:
 
-@table @i
+@table @asis
 @item Bastien Guerry
-Bastien has written a large number of extensions to Org (most of them
-integrated into the core by now), including the @LaTeX{} exporter and the
-plain list parser.  His support during the early days was central to the
-success of this project.  Bastien also invented Worg, helped establishing the
-Web presence of Org, and sponsored hosting costs for the orgmode.org website.
-Bastien stepped in as maintainer of Org between 2011 and 2013, at a time when
-I desperately needed a break.
+Bastien has written a large number of extensions to Org (most of
+them integrated into the core by now), including the @LaTeX{} exporter
+and the plain list parser.  His support during the early days was
+central to the success of this project.  Bastien also invented Worg,
+helped establishing the Web presence of Org, and sponsored hosting
+costs for the orgmode.org website.  Bastien stepped in as maintainer
+of Org between 2011 and 2013, at a time when I desperately needed
+a break.
+
 @item Eric Schulte and Dan Davison
-Eric and Dan are jointly responsible for the Org-babel system, which turns
-Org into a multi-language environment for evaluating code and doing literate
-programming and reproducible research.  This has become one of Org's killer
-features that define what Org is today.
+Eric and Dan are jointly responsible for the Org Babel system, which
+turns Org into a multi-language environment for evaluating code and
+doing literate programming and reproducible research.  This has
+become one of Org's killer features that define what Org is today.
+
 @item John Wiegley
-John has contributed a number of great ideas and patches directly to Org,
-including the attachment system (@file{org-attach.el}), integration with
-Apple Mail (@file{org-mac-message.el}), hierarchical dependencies of TODO
-items, habit tracking (@file{org-habits.el}), and encryption
-(@file{org-crypt.el}).  Also, the capture system is really an extended copy
-of his great @file{remember.el}.
+John has contributed a number of great ideas and patches directly to
+Org, including the attachment system (@samp{org-attach.el}), integration
+with Apple Mail (@samp{org-mac-message.el}), hierarchical dependencies of
+TODO items, habit tracking (@samp{org-habits.el}), and encryption
+(@samp{org-crypt.el}).  Also, the capture system is really an extended
+copy of his great @samp{remember.el}.
+
 @item Sebastian Rose
-Without Sebastian, the HTML/XHTML publishing of Org would be the pitiful work
-of an ignorant amateur.  Sebastian has pushed this part of Org onto a much
-higher level.  He also wrote @file{org-info.js}, a Java script for displaying
-web pages derived from Org using an Info-like or a folding interface with
-single-key navigation.
+Without Sebastian, the HTML/XHTML publishing of Org would be the
+pitiful work of an ignorant amateur.  Sebastian has pushed this part
+of Org onto a much higher level.  He also wrote @samp{org-info.js},
+a JavaScript program for displaying webpages derived from Org using
+an Info-like or a folding interface with single-key navigation.
 @end table
 
-@noindent See below for the full list of contributions!  Again, please
-let me know what I am missing here!
+See below for the full list of contributions! Again, please let me
+know what I am missing here!
 
-@section From Bastien
+@anchor{From Bastien}
+@appendixsec From Bastien
 
-I (Bastien) have been maintaining Org between 2011 and 2013.  This appendix
-would not be complete without adding a few more acknowledgments and thanks.
+I (Bastien) have been maintaining Org between 2011 and 2013.  This
+appendix would not be complete without adding a few more
+acknowledgments and thanks.
 
 I am first grateful to Carsten for his trust while handing me over the
-maintainership of Org.  His unremitting support is what really helped me
-getting more confident over time, with both the community and the code.
+maintainership of Org.  His unremitting support is what really helped
+me getting more confident over time, with both the community and the
+code.
 
 When I took over maintainership, I knew I would have to make Org more
-collaborative than ever, as I would have to rely on people that are more
-knowledgeable than I am on many parts of the code.  Here is a list of the
-persons I could rely on, they should really be considered co-maintainers,
-either of the code or the community:
+collaborative than ever, as I would have to rely on people that are
+more knowledgeable than I am on many parts of the code.  Here is
+a list of the persons I could rely on, they should really be
+considered co-maintainers, either of the code or the community:
 
-@table @i
+@table @asis
 @item Eric Schulte
-Eric is maintaining the Babel parts of Org.  His reactivity here kept me away
-from worrying about possible bugs here and let me focus on other parts.
+Eric is maintaining the Babel parts of Org.  His reactivity here
+kept me away from worrying about possible bugs here and let me focus
+on other parts.
 
 @item Nicolas Goaziou
-Nicolas is maintaining the consistency of the deepest parts of Org.  His work
-on @file{org-element.el} and @file{ox.el} has been outstanding, and it opened
-the doors for many new ideas and features.  He rewrote many of the old
-exporters to use the new export engine, and helped with documenting this
-major change.  More importantly (if that's possible), he has been more than
-reliable during all the work done for Org 8.0, and always very reactive on
-the mailing list.
+Nicolas is maintaining the consistency of the deepest parts of Org.
+His work on @samp{org-element.el} and @samp{ox.el} has been outstanding, and
+it opened the doors for many new ideas and features.  He rewrote
+many of the old exporters to use the new export engine, and helped
+with documenting this major change.  More importantly (if that's
+possible), he has been more than reliable during all the work done
+for Org 8.0, and always very reactive on the mailing list.
 
 @item Achim Gratz
-Achim rewrote the building process of Org, turning some @emph{ad hoc} tools
-into a flexible and conceptually clean process.  He patiently coped with the
-many hiccups that such a change can create for users.
+Achim rewrote the building process of Org, turning some @emph{ad hoc}
+tools into a flexible and conceptually clean process.  He patiently
+coped with the many hiccups that such a change can create for users.
 
 @item Nick Dokos
-The Org mode mailing list would not be such a nice place without Nick, who
-patiently helped users so many times.  It is impossible to overestimate such
-a great help, and the list would not be so active without him.
+The Org mode mailing list would not be such a nice place without
+Nick, who patiently helped users so many times.  It is impossible to
+overestimate such a great help, and the list would not be so active
+without him.
 @end table
 
-I received support from so many users that it is clearly impossible to be
-fair when shortlisting a few of them, but Org's history would not be
-complete if the ones above were not mentioned in this manual.
+I received support from so many users that it is clearly impossible to
+be fair when shortlisting a few of them, but Org's history would not
+be complete if the ones above were not mentioned in this manual.
 
-@section List of contributions
+@anchor{List of Contributions}
+@appendixsec List of Contributions
 
-@itemize @bullet
-
-@item
-@i{Russel Adams} came up with the idea for drawers.
-@item
-@i{Suvayu Ali} has steadily helped on the mailing list, providing useful
-feedback on many features and several patches.
-@item
-@i{Luis Anaya} wrote @file{ox-man.el}.
+@itemize
 @item
-@i{Thomas Baumann} wrote @file{org-bbdb.el} and @file{org-mhe.el}.
+Russel Adams came up with the idea for drawers.
+
 @item
-@i{Michael Brand} helped by reporting many bugs and testing many features.
-He also implemented the distinction between empty fields and 0-value fields
-in Org's spreadsheets.
+Thomas Baumann wrote @samp{ol-bbdb.el} and @samp{ol-mhe.el}.
+
 @item
-@i{Christophe Bataillon} created the great unicorn logo that we use on the
-Org mode website.
+Christophe Bataillon created the great unicorn logo that we use on
+the Org mode website.
+
 @item
-@i{Alex Bochannek} provided a patch for rounding timestamps.
+Alex Bochannek provided a patch for rounding timestamps.
+
 @item
-@i{Jan Böcker} wrote @file{org-docview.el}.
+Jan Böcker wrote @samp{ol-docview.el}.
+
 @item
-@i{Brad Bozarth} showed how to pull RSS feed data into Org mode files.
+Brad Bozarth showed how to pull RSS feed data into Org files.
+
 @item
-@i{Tom Breton} wrote @file{org-choose.el}.
+Tom Breton wrote @samp{org-choose.el}.
+
 @item
-@i{Charles Cave}'s suggestion sparked the implementation of templates
+Charles Cave's suggestion sparked the implementation of templates
 for Remember, which are now templates for capture.
+
 @item
-@i{Pavel Chalmoviansky} influenced the agenda treatment of items with
+Pavel Chalmoviansky influenced the agenda treatment of items with
 specified time.
+
 @item
-@i{Gregory Chernov} patched support for Lisp forms into table
-calculations and improved XEmacs compatibility, in particular by porting
-@file{nouline.el} to XEmacs.
-@item
-@i{Sacha Chua} suggested copying some linking code from Planner, and helped
-make Org popular through her blog.
-@item
-@i{Toby S. Cubitt} contributed to the code for clock formats.
-@item
-@i{Baoqiu Cui} contributed the first DocBook exporter.  In Org 8.0, we go a
-different route: you can now export to Texinfo and export the @file{.texi}
-file to DocBook using @code{makeinfo}.
+Gregory Chernov patched support for Lisp forms into table
+calculations and improved XEmacs compatibility, in particular by
+porting @samp{nouline.el} to XEmacs.
+
 @item
-@i{Eddward DeVilla} proposed and tested checkbox statistics.  He also
-came up with the idea of properties, and that there should be an API for
-them.
+Sacha Chua suggested copying some linking code from Planner.
+
 @item
-@i{Nick Dokos} tracked down several nasty bugs.
+Baoqiu Cui contributed the DocBook exporter.
+
 @item
-@i{Kees Dullemond} used to edit projects lists directly in HTML and so
-inspired some of the early development, including HTML export.  He also
-asked for a way to narrow wide table columns.
+Eddward DeVilla proposed and tested checkbox statistics.  He also
+came up with the idea of properties, and that there should be an API
+for them.
+
 @item
-@i{Jason Dunsmore} has been maintaining the Org-Mode server at Rackspace for
-several years now.  He also sponsored the hosting costs until Rackspace
-started to host us for free.
+Nick Dokos tracked down several nasty bugs.
+
 @item
-@i{Thomas S. Dye} contributed documentation on Worg and helped integrating
-the Org-Babel documentation into the manual.
+Kees Dullemond used to edit projects lists directly in HTML and so
+inspired some of the early development, including HTML export.  He
+also asked for a way to narrow wide table columns.
+
 @item
-@i{Christian Egli} converted the documentation into Texinfo format, inspired
-the agenda, patched CSS formatting into the HTML exporter, and wrote
-@file{org-taskjuggler.el}, which has been rewritten by Nicolas Goaziou as
-@file{ox-taskjuggler.el} for Org 8.0.
+Thomas@tie{}S@.@tie{}Dye contributed documentation on Worg and helped
+integrating the Org Babel documentation into the manual.
+
 @item
-@i{David Emery} provided a patch for custom CSS support in exported
-HTML agendas.
+Christian Egli converted the documentation into Texinfo format,
+inspired the agenda, patched CSS formatting into the HTML exporter,
+and wrote @samp{org-taskjuggler.el}.
+
 @item
-@i{Sean Escriva} took over MobileOrg development on the iPhone platform.
+David Emery provided a patch for custom CSS support in exported HTML
+agendas.
+
 @item
-@i{Nic Ferrier} contributed mailcap and XOXO support.
+Nic Ferrier contributed mailcap and XOXO support.
+
 @item
-@i{Miguel A. Figueroa-Villanueva} implemented hierarchical checkboxes.
+Miguel@tie{}A@.@tie{}Figueroa-Villanueva implemented hierarchical checkboxes.
+
 @item
-@i{John Foerch} figured out how to make incremental search show context
+John Foerch figured out how to make incremental search show context
 around a match in a hidden outline tree.
+
 @item
-@i{Raimar Finken} wrote @file{org-git-line.el}.
+Raimar Finken wrote @samp{org-git-line.el}.
+
 @item
-@i{Mikael Fornius} works as a mailing list moderator.
+Mikael Fornius works as a mailing list moderator.
+
 @item
-@i{Austin Frank} works as a mailing list moderator.
+Austin Frank works as a mailing list moderator.
+
 @item
-@i{Eric Fraga} drove the development of BEAMER export with ideas and
+Eric Fraga drove the development of Beamer export with ideas and
 testing.
+
 @item
-@i{Barry Gidden} did proofreading the manual in preparation for the book
+Barry Gidden did proofreading the manual in preparation for the book
 publication through Network Theory Ltd.
+
 @item
-@i{Niels Giesen} had the idea to automatically archive DONE trees.
+Niels Giesen had the idea to automatically archive DONE trees.
+
 @item
-@i{Nicolas Goaziou} rewrote much of the plain list code.  He also wrote
-@file{org-element.el} and @file{org-export.el}, which was a huge step forward
-in implementing a clean framework for Org exporters.
+Nicolas Goaziou rewrote much of the plain list code.
+
 @item
-@i{Kai Grossjohann} pointed out key-binding conflicts with other packages.
+Kai Grossjohann pointed out key-binding conflicts with other
+packages.
+
 @item
-@i{Brian Gough} of Network Theory Ltd publishes the Org mode manual as a
-book.
+Brian Gough of Network Theory Ltd publishes the Org mode manual as
+a book.
+
 @item
-@i{Bernt Hansen} has driven much of the support for auto-repeating tasks,
-task state change logging, and the clocktable.  His clear explanations have
-been critical when we started to adopt the Git version control system.
+Bernt Hansen has driven much of the support for auto-repeating
+tasks, task state change logging, and the clocktable.  His clear
+explanations have been critical when we started to adopt the Git
+version control system.
+
 @item
-@i{Manuel Hermenegildo} has contributed various ideas, small fixes and
+Manuel Hermenegildo has contributed various ideas, small fixes and
 patches.
+
 @item
-@i{Phil Jackson} wrote @file{org-irc.el}.
+Phil Jackson wrote @samp{ol-irc.el}.
+
 @item
-@i{Scott Jaderholm} proposed footnotes, control over whitespace between
+Scott Jaderholm proposed footnotes, control over whitespace between
 folded entries, and column view for properties.
+
 @item
-@i{Matt Jones} wrote @i{MobileOrg Android}.
-@item
-@i{Tokuya Kameshima} wrote @file{org-wl.el} and @file{org-mew.el}.
+Matt Jones wrote MobileOrg Android.
+
 @item
-@i{Jonathan Leech-Pepin} wrote @file{ox-texinfo.el}.
+Tokuya Kameshima wrote @samp{org-wl.el} and @samp{org-mew.el}.
+
 @item
-@i{Shidai Liu} ("Leo") asked for embedded @LaTeX{} and tested it.  He also
+Shidai Liu (``Leo'') asked for embedded @LaTeX{} and tested it.  He also
 provided frequent feedback and some patches.
+
 @item
-@i{Matt Lundin} has proposed last-row references for table formulas and named
-invisible anchors.  He has also worked a lot on the FAQ.
+Matt Lundin has proposed last-row references for table formulas and
+named invisible anchors.  He has also worked a lot on the FAQ@.
+
 @item
-@i{David Maus} wrote @file{org-atom.el}, maintains the issues file for Org,
-and is a prolific contributor on the mailing list with competent replies,
-small fixes and patches.
+David Maus wrote @samp{org-atom.el}, maintains the issues file for Org,
+and is a prolific contributor on the mailing list with competent
+replies, small fixes and patches.
+
 @item
-@i{Jason F. McBrayer} suggested agenda export to CSV format.
+Jason@tie{}F@.@tie{}McBrayer suggested agenda export to CSV format.
+
 @item
-@i{Max Mikhanosha} came up with the idea of refiling and sticky agendas.
+Max Mikhanosha came up with the idea of refiling.
+
 @item
-@i{Dmitri Minaev} sent a patch to set priority limits on a per-file
+Dmitri Minaev sent a patch to set priority limits on a per-file
 basis.
+
 @item
-@i{Stefan Monnier} provided a patch to keep the Emacs-Lisp compiler
+Stefan Monnier provided a patch to keep the Emacs Lisp compiler
 happy.
+
 @item
-@i{Richard Moreland} wrote MobileOrg for the iPhone.
+Richard Moreland wrote MobileOrg for the iPhone.
+
 @item
-@i{Rick Moynihan} proposed allowing multiple TODO sequences in a file
+Rick Moynihan proposed allowing multiple TODO sequences in a file
 and being able to quickly restrict the agenda to a subtree.
+
 @item
-@i{Todd Neal} provided patches for links to Info files and Elisp forms.
+Todd Neal provided patches for links to Info files and Elisp forms.
+
 @item
-@i{Greg Newman} refreshed the unicorn logo into its current form.
+Greg Newman refreshed the unicorn logo into its current form.
+
 @item
-@i{Tim O'Callaghan} suggested in-file links, search options for general
-file links, and TAGS.
+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
+Osamu Okano wrote @samp{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
+Takeshi Okano translated the manual and David O'Toole's tutorial
 into Japanese.
+
 @item
-@i{Oliver Oppitz} suggested multi-state TODO items.
+Oliver Oppitz suggested multi-state TODO items.
+
 @item
-@i{Scott Otterson} sparked the introduction of descriptive text for
+Scott Otterson sparked the introduction of descriptive text for
 links, among other things.
+
 @item
-@i{Pete Phillips} helped during the development of the TAGS feature, and
-provided frequent feedback.
-@item
-@i{Francesco Pizzolante} provided patches that helped speeding up the agenda
-generation.
-@item
-@i{Martin Pohlack} provided the code snippet to bundle character insertion
-into bundles of 20 for undo.
+Pete Phillips helped during the development of the TAGS feature,
+and provided frequent feedback.
+
 @item
-@i{Rackspace.com} is hosting our website for free.  Thank you Rackspace!
+Martin Pohlack provided the code snippet to bundle character
+insertion into bundles of 20 for undo.
+
 @item
-@i{T.V. Raman} reported bugs and suggested improvements.
+T@.@tie{}V@.@tie{}Raman reported bugs and suggested improvements.
+
 @item
-@i{Matthias Rempe} (Oelde) provided ideas, Windows support, and quality
+Matthias Rempe (Oelde) provided ideas, Windows support, and quality
 control.
+
 @item
-@i{Paul Rivier} provided the basic implementation of named footnotes.  He
-also acted as mailing list moderator for some time.
+Paul Rivier provided the basic implementation of named footnotes.
+He also acted as mailing list moderator for some time.
+
 @item
-@i{Kevin Rogers} contributed code to access VM files on remote hosts.
+Kevin Rogers contributed code to access VM files on remote hosts.
+
 @item
-@i{Frank Ruell} solved the mystery of the @code{keymapp nil} bug, a
-conflict with @file{allout.el}.
+Frank Ruell solved the mystery of the @samp{keymapp nil} bug, a conflict
+with @samp{allout.el}.
+
 @item
-@i{Jason Riedy} generalized the send-receive mechanism for Orgtbl tables with
-extensive patches.
+Jason Riedy generalized the send-receive mechanism for Orgtbl
+tables with extensive patches.
+
 @item
-@i{Philip Rooke} created the Org reference card, provided lots
-of feedback, developed and applied standards to the Org documentation.
+Philip Rooke created the Org reference card, provided lots of
+feedback, developed and applied standards to the Org documentation.
+
 @item
-@i{Christian Schlauer} proposed angular brackets around links, among
+Christian Schlauer proposed angular brackets around links, among
 other things.
+
 @item
-@i{Christopher Schmidt} reworked @code{orgstruct-mode} so that users can
-enjoy folding in non-org buffers by using Org headlines in comments.
-@item
-@i{Paul Sexton} wrote @file{org-ctags.el}.
+Paul Sexton wrote @samp{org-ctags.el}.
+
 @item
-Linking to VM/BBDB/Gnus was first inspired by @i{Tom Shannon}'s
-@file{organizer-mode.el}.
+Tom Shannon's @samp{organizer-mode.el} inspired linking to VM/BBDB/Gnus.
+
 @item
-@i{Ilya Shlyakhter} proposed the Archive Sibling, line numbering in literal
-examples, and remote highlighting for referenced code lines.
+Ilya Shlyakhter proposed the Archive Sibling, line numbering in
+literal examples, and remote highlighting for referenced code lines.
+
 @item
-@i{Stathis Sideris} wrote the @file{ditaa.jar} ASCII to PNG converter that is
-now packaged into Org's @file{contrib} directory.
+Stathis Sideris wrote the @samp{ditaa.jar} ASCII to PNG converter that is
+now packaged into Org's @samp{contrib/} directory.
+
 @item
-@i{Daniel Sinder} came up with the idea of internal archiving by locking
+Daniel Sinder came up with the idea of internal archiving by locking
 subtrees.
+
 @item
-@i{Dale Smith} proposed link abbreviations.
+Dale Smith proposed link abbreviations.
+
 @item
-@i{James TD Smith} has contributed a large number of patches for useful
-tweaks and features.
+James TD Smith has contributed a large number of patches for
+useful tweaks and features.
+
 @item
-@i{Adam Spiers} asked for global linking commands, inspired the link
-extension system, added support for mairix, and proposed the mapping API.
+Adam Spiers asked for global linking commands, inspired the link
+extension system, added support for Mairix, and proposed the mapping
+API@.
+
 @item
-@i{Ulf Stegemann} created the table to translate special symbols to HTML,
-@LaTeX{}, UTF-8, Latin-1 and ASCII.
+Ulf Stegemann created the table to translate special symbols to
+HTML, @LaTeX{}, UTF-8, Latin-1 and ASCII@.
+
 @item
-@i{Andy Stewart} contributed code to @file{org-w3m.el}, to copy HTML content
-with links transformation to Org syntax.
+Andy Stewart contributed code to @samp{ol-w3m.el}, to copy
+HTML content with links transformation to Org syntax.
+
 @item
-@i{David O'Toole} wrote @file{org-publish.el} and drafted the manual
-chapter about publishing.
+David O'Toole wrote @samp{org-publish.el} and drafted the
+manual chapter about publishing.
+
 @item
-@i{Jambunathan K} contributed the ODT exporter and rewrote the HTML exporter.
+Jambunathan@tie{}K@.@tie{}contributed the ODT exporter.
+
 @item
-@i{Sebastien Vauban} reported many issues with @LaTeX{} and BEAMER export and
-enabled source code highlighting in Gnus.
+Sebastien Vauban reported many issues with @LaTeX{} and Beamer export
+and enabled source code highlighting in Gnus.
+
 @item
-@i{Stefan Vollmar} organized a video-recorded talk at the
-Max-Planck-Institute for Neurology.  He also inspired the creation of a
-concept index for HTML export.
+Stefan Vollmar organized a video-recorded talk at the
+Max-Planck-Institute for Neurology.  He also inspired the creation
+of a concept index for HTML export.
+
 @item
-@i{Jürgen Vollmer} contributed code generating the table of contents
-in HTML output.
+Jürgen Vollmer contributed code generating the table of contents in
+HTML output.
+
 @item
-@i{Samuel Wales} has provided important feedback and bug reports.
+Samuel Wales has provided important feedback and bug reports.
+
 @item
-@i{Chris Wallace} provided a patch implementing the @samp{QUOTE}
-keyword.
+Chris Wallace provided a patch implementing the @samp{QUOTE} block.
+
 @item
-@i{David Wainberg} suggested archiving, and improvements to the linking
-system.
+David Wainberg suggested archiving, and improvements to the
+linking system.
+
 @item
-@i{Carsten Wimmer} suggested some changes and helped fix a bug in
+Carsten Wimmer suggested some changes and helped fix a bug in
 linking to Gnus.
+
 @item
-@i{Roland Winkler} requested additional key bindings to make Org
-work on a tty.
+Roland Winkler requested additional key bindings to make Org work on
+a TTY@.
+
 @item
-@i{Piotr Zielinski} wrote @file{org-mouse.el}, proposed agenda blocks
-and contributed various ideas and code snippets.
+Piotr Zielinski wrote @samp{org-mouse.el}, proposed agenda
+blocks and contributed various ideas and code snippets.
+
 @item
-@i{Marco Wahl} wrote @file{org-eww.el}.
+Marco Wahl wrote @samp{ol-eww.el}.
 @end itemize
 
-
 @node GNU Free Documentation License
 @appendix GNU Free Documentation License
-@include doclicense.texi
 
+@center Version 1.3, 3 November 2008
+
+@display
+Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, 
Inc.
+@uref{http://fsf.org/}
+
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+@end display
+
+@enumerate 0
+@item
+PREAMBLE
+
+The purpose of this License is to make a manual, textbook, or other
+functional and useful document @dfn{free}
+in the sense of freedom: to assure everyone the effective freedom
+to copy and redistribute it, with or without modifying it, either
+commercially or noncommercially. Secondarily, this License
+preserves for the author and publisher a way to get credit for
+their work, while not being considered responsible for
+modifications made by others.
+
+This License is a kind of ``copyleft'', which means that derivative
+works of the document must themselves be free in the same sense.
+It complements the GNU General Public License, which is a copyleft
+license designed for free software.
+
+We have designed this License in order to use it for manuals for
+free software, because free software needs free documentation:
+a free program should come with manuals providing the same freedoms
+that the software does.  But this License is not limited to
+software manuals; it can be used for any textual work, regardless
+of subject matter or whether it is published as a printed book.  We
+recommend this License principally for works whose purpose is
+instruction or reference.
+
+@item
+APPLICABILITY AND DEFINITIONS
+
+This License applies to any manual or other work, in any medium,
+that contains a notice placed by the copyright holder saying it can
+be distributed under the terms of this License.  Such a notice
+grants a world-wide, royalty-free license, unlimited in duration,
+to use that work under the conditions stated herein.  The
+``Document'', below, refers to any such manual or work.  Any member
+of the public is a licensee, and is addressed as ``you''.  You accept
+the license if you copy, modify or distribute the work in a way
+requiring permission under copyright law.
+
+A ``Modified Version'' of the Document means any work containing the
+Document or a portion of it, either copied verbatim, or with
+modifications and/or translated into another language.
+
+A ``Secondary Section'' is a named appendix or a front-matter section
+of the Document that deals exclusively with the relationship of the
+publishers or authors of the Document to the Document's overall
+subject (or to related matters) and contains nothing that could
+fall directly within that overall subject.  (Thus, if the Document
+is in part a textbook of mathematics, a Secondary Section may not
+explain any mathematics.)  The relationship could be a matter of
+historical connection with the subject or with related matters, or
+of legal, commercial, philosophical, ethical or political position
+regarding them.
+
+The ``Invariant Sections'' are certain Secondary Sections whose
+titles are designated, as being those of Invariant Sections, in the
+notice that says that the Document is released under this License.
+If a section does not fit the above definition of Secondary then it
+is not allowed to be designated as Invariant.  The Document may
+contain zero Invariant Sections.  If the Document does not identify
+any Invariant Sections then there are none.
+
+The ``Cover Texts'' are certain short passages of text that are
+listed, as Front-Cover Texts or Back-Cover Texts, in the notice
+that says that the Document is released under this License.
+A Front-Cover Text may be at most 5 words, and a Back-Cover Text
+may be at most 25 words.
+
+A ``Transparent'' copy of the Document means a machine-readable copy,
+represented in a format whose specification is available to the
+general public, that is suitable for revising the document
+straightforwardly with generic text editors or (for images composed
+of pixels) generic paint programs or (for drawings) some widely
+available drawing editor, and that is suitable for input to text
+formatters or for automatic translation to a variety of formats
+suitable for input to text formatters.  A copy made in an otherwise
+Transparent file format whose markup, or absence of markup, has
+been arranged to thwart or discourage subsequent modification by
+readers is not Transparent.  An image format is not Transparent if
+used for any substantial amount of text.  A copy that is not
+``Transparent'' is called ``Opaque''.
+
+Examples of suitable formats for Transparent copies include plain
+ASCII without markup, Texinfo input format, @LaTeX{} input format,
+SGML or XML using a publicly available DTD, and standard-conforming
+simple HTML, PostScript or PDF designed for human modification.
+Examples of transparent image formats include PNG, XCF and JPG@.
+Opaque formats include proprietary formats that can be read and
+edited only by proprietary word processors, SGML or XML for which
+the DTD and/or processing tools are not generally available, and
+the machine-generated HTML, PostScript or PDF produced by some word
+processors for output purposes only.
+
+The ``Title Page'' means, for a printed book, the title page itself,
+plus such following pages as are needed to hold, legibly, the
+material this License requires to appear in the title page.  For
+works in formats which do not have any title page as such, ``Title
+Page'' means the text near the most prominent appearance of the
+work's title, preceding the beginning of the body of the text.
+
+The ``publisher'' means any person or entity that distributes copies
+of the Document to the public.
+
+A section ``Entitled XYZ'' means a named subunit of the Document
+whose title either is precisely XYZ or contains XYZ in parentheses
+following text that translates XYZ in another language.  (Here XYZ
+stands for a specific section name mentioned below, such as
+``Acknowledgements'', ``Dedications'', ``Endorsements'', or ``History''.)
+To ``Preserve the Title'' of such a section when you modify the
+Document means that it remains a section ``Entitled XYZ'' according
+to this definition.
+
+The Document may include Warranty Disclaimers next to the notice
+which states that this License applies to the Document.  These
+Warranty Disclaimers are considered to be included by reference in
+this License, but only as regards disclaiming warranties: any other
+implication that these Warranty Disclaimers may have is void and
+has no effect on the meaning of this License.
+
+@item
+VERBATIM COPYING
+
+You may copy and distribute the Document in any medium, either
+commercially or noncommercially, provided that this License, the
+copyright notices, and the license notice saying this License
+applies to the Document are reproduced in all copies, and that you
+add no other conditions whatsoever to those of this License.  You
+may not use technical measures to obstruct or control the reading
+or further copying of the copies you make or distribute.  However,
+you may accept compensation in exchange for copies.  If you
+distribute a large enough number of copies you must also follow the
+conditions in section 3.
+
+You may also lend copies, under the same conditions stated above,
+and you may publicly display copies.
+
+@item
+COPYING IN QUANTITY
+
+If you publish printed copies (or copies in media that commonly
+have printed covers) of the Document, numbering more than 100, and
+the Document's license notice requires Cover Texts, you must
+enclose the copies in covers that carry, clearly and legibly, all
+these Cover Texts: Front-Cover Texts on the front cover, and
+Back-Cover Texts on the back cover.  Both covers must also clearly
+and legibly identify you as the publisher of these copies.  The
+front cover must present the full title with all words of the title
+equally prominent and visible.  You may add other material on the
+covers in addition.  Copying with changes limited to the covers, as
+long as they preserve the title of the Document and satisfy these
+conditions, can be treated as verbatim copying in other respects.
+
+If the required texts for either cover are too voluminous to fit
+legibly, you should put the first ones listed (as many as fit
+reasonably) on the actual cover, and continue the rest onto
+adjacent pages.
+
+If you publish or distribute Opaque copies of the Document
+numbering more than 100, you must either include a machine-readable
+Transparent copy along with each Opaque copy, or state in or with
+each Opaque copy a computer-network location from which the general
+network-using public has access to download using public-standard
+network protocols a complete Transparent copy of the Document, free
+of added material.  If you use the latter option, you must take
+reasonably prudent steps, when you begin distribution of Opaque
+copies in quantity, to ensure that this Transparent copy will
+remain thus accessible at the stated location until at least one
+year after the last time you distribute an Opaque copy (directly or
+through your agents or retailers) of that edition to the public.
+
+It is requested, but not required, that you contact the authors of
+the Document well before redistributing any large number of copies,
+to give them a chance to provide you with an updated version of the
+Document.
+
+@item
+MODIFICATIONS
+
+You may copy and distribute a Modified Version of the Document
+under the conditions of sections 2 and 3 above, provided that you
+release the Modified Version under precisely this License, with the
+Modified Version filling the role of the Document, thus licensing
+distribution and modification of the Modified Version to whoever
+possesses a copy of it.  In addition, you must do these things in
+the Modified Version:
+
+@enumerate A
+@item
+Use in the Title Page (and on the covers, if any) a title
+distinct from that of the Document, and from those of previous
+versions (which should, if there were any, be listed in the
+History section of the Document). You may use the same title as
+a previous version if the original publisher of that version
+gives permission.
+
+@item
+List on the Title Page, as authors, one or more persons or
+entities responsible for authorship of the modifications in the
+Modified Version, together with at least five of the principal
+authors of the Document (all of its principal authors, if it has
+fewer than five), unless they release you from this requirement.
+
+@item
+State on the Title page the name of the publisher of the
+Modified Version, as the publisher.
+
+@item
+Preserve all the copyright notices of the Document.
+
+@item
+Add an appropriate copyright notice for your modifications
+adjacent to the other copyright notices.
+
+@item
+Include, immediately after the copyright notices, a license
+notice giving the public permission to use the Modified Version
+under the terms of this License, in the form shown in the
+Addendum below.
+
+@item
+Preserve in that license notice the full lists of Invariant
+Sections and required Cover Texts given in the Document's
+license notice.
+
+@item
+Include an unaltered copy of this License.
+
+@item
+Preserve the section Entitled ``History'', Preserve its Title, and
+add to it an item stating at least the title, year, new authors,
+and publisher of the Modified Version as given on the Title
+Page. If there is no section Entitled ``History'' in the Document,
+create one stating the title, year, authors, and publisher of
+the Document as given on its Title Page, then add an item
+describing the Modified Version as stated in the previous
+sentence.
+
+@item
+Preserve the network location, if any, given in the Document
+for public access to a Transparent copy of the Document, and
+likewise the network locations given in the Document for
+previous versions it was based on. These may be placed in the
+``History'' section. You may omit a network location for a work
+that was published at least four years before the Document
+itself, or if the original publisher of the version it refers
+to gives permission.
+
+@item
+For any section Entitled ``Acknowledgements'' or ``Dedications'',
+Preserve the Title of the section, and preserve in the section
+all the substance and tone of each of the contributor
+acknowledgements and/or dedications given therein.
+
+@item
+Preserve all the Invariant Sections of the Document, unaltered
+in their text and in their titles. Section numbers or the
+equivalent are not considered part of the section titles.
+
+@item
+Delete any section Entitled ``Endorsements''. Such a section may
+not be included in the Modified Version.
+
+@item
+Do not retitle any existing section to be Entitled
+``Endorsements'' or to conflict in title with any Invariant
+Section.
+
+@item
+Preserve any Warranty Disclaimers.
+@end enumerate
+
+If the Modified Version includes new front-matter sections or
+appendices that qualify as Secondary Sections and contain no material
+copied from the Document, you may at your option designate some or all
+of these sections as invariant.  To do this, add their titles to the
+list of Invariant Sections in the Modified Version's license notice.
+These titles must be distinct from any other section titles.
+
+You may add a section Entitled ``Endorsements'', provided it contains
+nothing but endorsements of your Modified Version by various
+parties---for example, statements of peer review or that the text has
+been approved by an organization as the authoritative definition of a
+standard.
+
+You may add a passage of up to five words as a Front-Cover Text, and a
+passage of up to 25 words as a Back-Cover Text, to the end of the list
+of Cover Texts in the Modified Version.  Only one passage of
+Front-Cover Text and one of Back-Cover Text may be added by (or
+through arrangements made by) any one entity.  If the Document already
+includes a cover text for the same cover, previously added by you or
+by arrangement made by the same entity you are acting on behalf of,
+you may not add another; but you may replace the old one, on explicit
+permission from the previous publisher that added the old one.
+
+The author(s) and publisher(s) of the Document do not by this License
+give permission to use their names for publicity for or to assert or
+imply endorsement of any Modified Version.
+
+@item
+COMBINING DOCUMENTS
+
+You may combine the Document with other documents released under
+this License, under the terms defined in section 4 above for
+modified versions, provided that you include in the combination all
+of the Invariant Sections of all of the original documents,
+unmodified, and list them all as Invariant Sections of your
+combined work in its license notice, and that you preserve all
+their Warranty Disclaimers.
+
+The combined work need only contain one copy of this License, and
+multiple identical Invariant Sections may be replaced with a single
+copy.  If there are multiple Invariant Sections with the same name
+but different contents, make the title of each such section unique
+by adding at the end of it, in parentheses, the name of the
+original author or publisher of that section if known, or else
+a unique number.  Make the same adjustment to the section titles in
+the list of Invariant Sections in the license notice of the
+combined work.
+
+In the combination, you must combine any sections Entitled
+``History'' in the various original documents, forming one section
+Entitled ``History''; likewise combine any sections Entitled
+``Acknowledgements'', and any sections Entitled ``Dedications''.  You
+must delete all sections Entitled ``Endorsements.''
+
+@item
+COLLECTIONS OF DOCUMENTS
+
+You may make a collection consisting of the Document and other
+documents released under this License, and replace the individual
+copies of this License in the various documents with a single copy
+that is included in the collection, provided that you follow the
+rules of this License for verbatim copying of each of the documents
+in all other respects.
+
+You may extract a single document from such a collection, and
+distribute it individually under this License, provided you insert
+a copy of this License into the extracted document, and follow this
+License in all other respects regarding verbatim copying of that
+document.
+
+@item
+AGGREGATION WITH INDEPENDENT WORKS
+
+A compilation of the Document or its derivatives with other
+separate and independent documents or works, in or on a volume of
+a storage or distribution medium, is called an ``aggregate'' if the
+copyright resulting from the compilation is not used to limit the
+legal rights of the compilation's users beyond what the individual
+works permit.  When the Document is included in an aggregate, this
+License does not apply to the other works in the aggregate which
+are not themselves derivative works of the Document.
+
+If the Cover Text requirement of section 3 is applicable to these
+copies of the Document, then if the Document is less than one half
+of the entire aggregate, the Document's Cover Texts may be placed
+on covers that bracket the Document within the aggregate, or the
+electronic equivalent of covers if the Document is in electronic
+form.  Otherwise they must appear on printed covers that bracket
+the whole aggregate.
+
+@item
+TRANSLATION
+
+Translation is considered a kind of modification, so you may
+distribute translations of the Document under the terms of
+section 4.  Replacing Invariant Sections with translations requires
+special permission from their copyright holders, but you may
+include translations of some or all Invariant Sections in addition
+to the original versions of these Invariant Sections.  You may
+include a translation of this License, and all the license notices
+in the Document, and any Warranty Disclaimers, provided that you
+also include the original English version of this License and the
+original versions of those notices and disclaimers.  In case of
+a disagreement between the translation and the original version of
+this License or a notice or disclaimer, the original version will
+prevail.
+
+If a section in the Document is Entitled ``Acknowledgements'',
+``Dedications'', or ``History'', the requirement (section 4) to
+Preserve its Title (section 1) will typically require changing the
+actual title.
+
+@item
+TERMINATION
+
+You may not copy, modify, sublicense, or distribute the Document
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense, or distribute it is void,
+and will automatically terminate your rights under this License.
+
+However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the
+copyright holder fails to notify you of the violation by some
+reasonable means prior to 60 days after the cessation.
+
+Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from
+that copyright holder, and you cure the violation prior to 30 days
+after your receipt of the notice.
+
+Termination of your rights under this section does not terminate
+the licenses of parties who have received copies or rights from you
+under this License.  If your rights have been terminated and not
+permanently reinstated, receipt of a copy of some or all of the
+same material does not give you any rights to use it.
+
+@item
+FUTURE REVISIONS OF THIS LICENSE
+
+The Free Software Foundation may publish new, revised versions of
+the GNU Free Documentation License from time to time.  Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.  See
+@uref{http://www.gnu.org/copyleft/}.
+
+Each version of the License is given a distinguishing version
+number.  If the Document specifies that a particular numbered
+version of this License ``or any later version'' applies to it, you
+have the option of following the terms and conditions either of
+that specified version or of any later version that has been
+published (not as a draft) by the Free Software Foundation.  If
+the Document does not specify a version number of this License,
+you may choose any version ever published (not as a draft) by the
+Free Software Foundation.  If the Document specifies that a proxy
+can decide which future versions of this License can be used, that
+proxy's public statement of acceptance of a version permanently
+authorizes you to choose that version for the Document.
+
+@item
+RELICENSING
+
+``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any
+World Wide Web server that publishes copyrightable works and also
+provides prominent facilities for anybody to edit those works.
+A public wiki that anybody can edit is an example of such
+a server.  A ``Massive Multiauthor Collaboration'' (or ``MMC'')
+contained in the site means any set of copyrightable works thus
+published on the MMC site.
+
+``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0
+license published by Creative Commons Corporation,
+a not-for-profit corporation with a principal place of business in
+San Francisco, California, as well as future copyleft versions of
+that license published by that same organization.
+
+``Incorporate'' means to publish or republish a Document, in whole
+or in part, as part of another Document.
+
+An MMC is ``eligible for relicensing'' if it is licensed under this
+License, and if all works that were first published under this
+License somewhere other than this MMC, and subsequently
+incorporated in whole or in part into the MMC, (1) had no cover
+texts or invariant sections, and (2) were thus incorporated prior
+to November 1, 2008.
+
+The operator of an MMC Site may republish an MMC contained in the
+site under CC-BY-SA on the same site at any time before August 1,
+2009, provided the MMC is eligible for relicensing.
+@end enumerate
+
+@page
+
+@anchor{ADDENDUM How to use this License for your documents}
+@appendixsec ADDENDUM: How to use this License for your documents
+
+To use this License in a document you have written, include a copy of
+the License in the document and put the following copyright and
+license notices just after the title page:
+
+@example
+Copyright (C)  YEAR  YOUR NAME.
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.3
+or any later version published by the Free Software Foundation;
+with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
+Texts.  A copy of the license is included in the section entitled ``GNU
+Free Documentation License''.
+@end example
+
+If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
+replace the ``with@dots{}Texts.''@tie{}line with this:
+
+@example
+with the Invariant Sections being LIST THEIR TITLES, with
+the Front-Cover Texts being LIST, and with the Back-Cover Texts
+being LIST.
+@end example
+
+If you have Invariant Sections without Cover Texts, or some other
+combination of the three, merge those two alternatives to suit the
+situation.
+
+If your document contains nontrivial examples of program code, we
+recommend releasing these examples in parallel under your choice of
+free software license, such as the GNU General Public License, to
+permit their use in free software.
 
 @node Main Index
-@unnumbered Concept index
+@chapter Main Index
 
 @printindex cp
 
 @node Key Index
-@unnumbered Key index
+@chapter Key Index
 
 @printindex ky
 
 @node Command and Function Index
-@unnumbered Command and function index
+@chapter Command and Function Index
 
 @printindex fn
 
 @node Variable Index
-@unnumbered Variable index
+@chapter Variable Index
 
-This is not a complete index of variables and faces, only the ones that are
-mentioned in the manual.  For a complete list, use @kbd{M-x org-customize
-@key{RET}}.
+This is not a complete index of variables and faces, only the ones
+that are mentioned in the manual.  For a more complete list, use
+@kbd{M-x org-customize} and then click yourself through the tree.
 
 @printindex vr
 
 @bye
-
-@c Local variables:
-@c fill-column: 77
-@c indent-tabs-mode: nil
-@c paragraph-start:    "^@[a-zA-Z]*[ \n]\\|^@x?org\\(key\\|cmd\\)\\|\f\\|[     
]*$"
-@c paragraph-separate: "^@[a-zA-Z]*[ \n]\\|^@x?org\\(key\\|cmd\\)\\|[  \f]*$"
-@c End:
-
-
-@c  LocalWords:  webdavhost pre
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7acd96b..275a33b 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -1,5 +1,7 @@
 ORG NEWS -- history of user-visible changes.   -*- mode: org; coding: utf-8 -*-
 
+#+STARTUP: overview
+
 #+LINK: doc https://orgmode.org/worg/doc.html#%s
 #+LINK: git https://code.orgmode.org/bzg/org-mode/commit/%s
 
@@ -8,6 +10,907 @@ See the end of the file for license conditions.
 
 Please send Org bug reports to mailto:address@hidden.
 
+* Version Next
+** New features
+*** Property drawers before first headline, outline level 0
+Property drawers will now work before first headline and Org mode is
+moving more towards making things before the first headline behave
+just as if it was at outline level 0.  Inheritance for properties will
+work also for this level.  In other words; defining things in a
+property drawer before the first headline will make them "inheritable"
+for all headlines.
+
+* Version 9.3
+
+** Incompatible changes
+*** Change bracket link escaping syntax
+
+Org used to percent-encode sensitive characters in the URI part of the
+bracket links.
+
+Now, escaping mechanism uses the usual backslash character, according
+to the following rules, applied in order:
+
+1. All consecutive =\= characters at the end of the link must be
+   escaped;
+2. Any =]= character at the very end of the link must be escaped;
+3. All consecutive =\= characters preceding =][= or =]]= patterns must
+   be escaped;
+4. Any =]= character followed by either =[= or =]= must be escaped;
+5. Others =]= and =\= characters need not be escaped.
+
+When in doubt, use the function ~org-link-escape~ in order to turn
+a link string into its properly escaped form.
+
+The following function will help switching your links to the new
+syntax:
+
+#+begin_src emacs-lisp
+(defun org-update-link-syntax (&optional no-query)
+  "Update syntax for links in current buffer.
+Query before replacing a link, unless optional argument NO-QUERY
+is non-nil."
+  (interactive "P")
+  (org-with-point-at 1
+    (let ((case-fold-search t))
+      (while (re-search-forward "\\[\\[[^]]*?%\\(?:2[05]\\|5[BD]\\)" nil t)
+        (let ((object (save-match-data (org-element-context))))
+          (when (and (eq 'link (org-element-type object))
+                     (= (match-beginning 0)
+                        (org-element-property :begin object)))
+            (goto-char (org-element-property :end object))
+            (let* ((uri-start (+ 2 (match-beginning 0)))
+                   (uri-end (save-excursion
+                              (goto-char uri-start)
+                              (re-search-forward "\\][][]" nil t)
+                              (match-beginning 0)))
+                   (uri (buffer-substring-no-properties uri-start uri-end)))
+              (when (or no-query
+                        (y-or-n-p
+                         (format "Possibly obsolete URI syntax: %S.  Fix? "
+                                 uri)))
+                (setf (buffer-substring uri-start uri-end)
+                      (org-link-escape (org-link-decode uri)))))))))))
+#+end_src
+
+The old ~org-link-escape~ and ~org-link-unescape~ functions have been
+renamed into ~org-link-encode~ and ~org-link-decode~.
+
+*** Change match group number in ~org-link-bracket-re~
+
+Link description, if any, is located in match group 2 instead of match
+group 3.
+
+*** ob-clojure does not auto prepend ~(ns ..)~ statement anymore
+
+When tangling, user usually just wants to tangle literally code instead
+of prepend inserting a ~(ns ..)~ statement before source block
+code.  Now, when you have no ~:ns~ header argument specified, this
+behavior will not happen automatically.
+
+*** Change in behavior on exit from an Org edit buffer
+
+Org will no longer attempt to restore the window configuration in the
+frame to which the user returns after editing a source block with
+~org-edit-src-code~.  Instead, the window configuration will remain as
+it is.
+
+*** Change default value for ~org-email-link-description-format~
+
+When linking from a mail buffer, Org used to truncate the subject of
+the message to 30 characters in order to build the description of the
+link.  This behavior was considered as too surprising.  As
+a consequence, Org no longer truncates subjects.
+
+You can get the old behaviour back with the following:
+
+: (setq org-email-link-description-format "Email %c: %.30s")
+
+*** ~:file~ header argument no longer assume "file" ~:results~
+
+The "file" ~:results~ value is now mandatory for a code block
+returning a link to a file.  The ~:file~ or ~:file-ext~ header
+arguments no longer imply a "file" result is expected.
+
+*** Plain numbers are hours in Column View mode
+
+See [[git:3367ac9457]] for details.
+
+*** All LaTeX preview backends use now xcolor
+
+The dvipng backend was previously relying on fg and bg parameters to
+be passed to the CLI. This didn't work when xcolor was directly or
+indirectly used in the document (e.g. tkiz is a user of xcolor). Since
+every other backend was already using xcolor to set fg and bg, the CLI
+alternative was removed and there is no more a :use-xcolor options
+since now it's implicitly always true.
+
+*** Org-Attach Git commit
+
+[[*Org-Attach has been refactored and extended][Refactoring of Org-Attach]] 
affected the Git commit functionality.  Not
+much, but the following changes are required if you still need to
+auto-commit attachments to git:
+
+- Customization of ~org-attach-annex-auto-get~ needs to be renamed to
+  ~org-attach-git-annex-auto-get~.
+
+- Customization of ~org-attach-commit~ is no longer needed.  Instead
+  one need to require the =org-attach-git= module in the startup.
+
+** New features
+*** New option to wrap source code lines in HTML export
+
+When new option ~html-wrap-src-lines~ (with variable
+~org-html-wrap-src-lines~) is non-nil, HTML export wraps source code
+lines in HTML ~code~ elements.
+
+*** New option to handle schedules and deadlines in iCalendar export
+
+Export ignore done tasks with a deadline when
+~org-icalendar-use-deadline~ contains ~event-if-todo-not-done~.
+Likewise, scheduled done tasks are also ignored when
+~org-icalendar-use-scheduled~ contains the same symbol.
+
+*** Add split-window-right option for src block edit window placement
+
+Given the increasing popularity of wide screen monitors, splitting
+horizontally may make more sense than splitting vertically.  An
+option, ~split-window-right~, to request horizontal splitting has been
+added to ~org-src-window-setup~.
+
+*** Org-Attach has been refactored and extended
+
+Org attach has been refactored and the functionality extended.  It
+should now be easier to understand how it works.  A few improvements
+and extra options have been added as well.
+
+From the initial comment in org-attach source-code:
+
+- Attachments are managed either by using a custom property DIR or by
+  using property ID from org-id.  When DIR is defined, a location in
+  the filesystem is directly attached to the outline node.  When
+  org-id is used, attachments are stored in a folder named after the
+  ID, in a location defined by ~org-attach-id-dir~.  DIR has
+  precedence over ID when both parameters are defined for the current
+  outline node (also when inherited parameters are taken into
+  account).
+
+From now on inheritance requires no extra property and will adhere to
+~org-attach-use-inheritance~ by default.  Inheritance can be
+customized to always be activated or never be activated in
+~org-attach-use-inheritance~.
+
+The ATTACH_DIR property is deprecated in favour of the shorter
+property DIR.  Links to folders inside the DIR property can now be
+declared as relative links.  This is not enabled by default, but can
+be set in ~org-attach-dir-relative~.
+
+When adding new attachment to the outline node the preferred way of
+doing so can be customized.  Take a look at
+~org-attach-preferred-new-method~.  It defaults to using ID since that
+was the behaviour before this change.
+
+If both DIR and ID properties are set on the same node, DIR has
+precedence and will be used.
+
+One can now also choose to build attachment-directory-paths in a
+customized way.  This is an advanced topic, but in some case it makes
+sense to parse an ID in a different way than the default one.  Create
+your own function and add it to the beginning of
+~org-attach-id-to-path-function~list~ if you want to customize the ID
+based folder structure.
+
+If you've used ATTACH_DIR properties to manage attachments, use the
+following code to rename that property to DIR which supports the same
+functionality.  ATTACH_DIR_INHERIT is no longer supported and is
+removed.
+
+#+begin_src emacs-lisp
+  (defun org-update-attach-properties ()
+      "Change properties for Org-Attach."
+      (interactive)
+      (org-with-point-at 1
+       (while (outline-next-heading)
+         (let ((DIR (org--property-local-values "ATTACH_DIR" nil)))
+           (when DIR
+             (org-set-property "DIR" (car DIR))
+             (org-delete-property "ATTACH_DIR"))))
+       (org-delete-property-globally "ATTACH_DIR_INHERIT")))
+#+end_src
+
+For those who hate breaking changes, even though the changes are made
+to clean things up; fear not.  ATTACH_DIR will still continue to work.
+It's just not documented any longer.  When you get the chance, run the
+code above to clean things up anyways!
+
+**** New hooks
+Two hooks are added to org-attach:
+- org-attach-after-change-hook
+- org-attach-open-hook
+
+They are added mostly for internal restructuring purposes, but can
+ofc. be used for other things as well.
+
+*** New link-type: Attachment
+
+Attachment-links are now first-class citizens.  They mimic file-links
+in everything they do but use the existing attachment-folder as a base
+when expanding the links. Both =DIR= and =ID= properties are used to
+try to resolve the links, in exactly the same way as Org-Attach uses
+those properties.
+
+*** Handle overlay specification for notes in Beamer export
+
+This aligns Beamer notes with slide overlays.
+
+*** Add support for lettered lists in Texinfo
+
+Using =:enum A= or =:enum a= Texinfo attribute switches an otherwise
+numbered list to a lettered list.
+
+*** Add a dispatcher command to insert dynamic blocks
+
+You can add new dynamic blocks with function
+~org-dynamic-block-define~.  All such dynamic blocks can be used by
+~org-dynamic-block-insert-dblock~ command.
+
+*** Babel
+
+**** ob-emacs-lisp sets ~lexical-binding~ in Org edit buffers
+
+When editing an Elisp src block, the editing buffer's
+~lexical-binding~ is set according to the src block's =:lexical=
+parameter.
+
+**** Add LaTeX output support in PlantUML
+
+*** New minor mode to display headline numbering
+
+Use =<M-x org-num-mode>= to get a visual indication of the numbering
+in the outline.  The numbering is also automatically updated upon
+changes in the buffer.
+
+*** New property =HTML_HEADLINE_CLASS= in HTML export
+
+The new property =HTML_HEADLINE_CLASS= assigns a class attribute to
+a headline.
+
+*** Allow LaTeX attributes and captions for "table.el" tables
+
+Supported LaTeX attributes are ~:float~, ~:center~, ~:font~ and
+~:caption~.
+
+*** Attach buffer contents to headline
+
+With =<b>= key from attachment dispatcher (=<C-c C-a>=), it is now
+possible to write the contents of a buffer to a file in the headline
+attachment directory.
+
+*** iCalendar export respects a =CLASS= property
+
+Set the =CLASS= property on an entry to specify a visibility class for
+that entry only during iCalendar export. The property can be set to
+anything the calendar server supports. The iCalendar standard defines
+the values =PUBLIC=, =CONFIDENTIAL=, =PRIVATE=, which can be
+interpreted as publicly visible, accessible to a specific group, and
+private respectively.
+
+This property can be inherited during iCalendar export, depending on
+the value of ~org-use-property-inheritance~.
+
+*** New parameter for =INCLUDE= keyword
+
+Add =:coding CODING-SYSTEM= to include files using a different coding
+system than the main Org document.  For example:
+
+#+begin_example
+,#+INCLUDE: "myfile.cmd" src cmd :coding cp850-dos
+#+end_example
+
+*** New values in clock tables' step: =month= and =year=
+*** ODT export handles numbers cookies in lists
+*** New cell movement functions in tables
+
+~S-<UP>~, ~S-<DOWN>~, ~S-<RIGHT>~, and ~S-<LEFT>~ now move cells in
+the corresponding direction by swapping with the adjacent cell.
+
+*** New option to natively fontify LaTeX snippets and environments
+
+A 'native option was added to org-highlight-latex-and-related. It
+matches the same structures than 'latex but it calls
+org-src-font-lock-fontify-block instead, thus bringing about full
+LaTeX font locking.
+
+*** ~org-clone-subtree-with-time-shift~ learnt to shift backward in time
+
+=<C-c C-x c>= (~org-clone-subtree-with-time-shift~) now takes a
+negative value as a valid repeater to shift time stamps in backward
+in cloned subtrees.  You can give, for example, ‘-3d’ to shift three
+days in the past.
+
+*** Toggle display of all vs. undone scheduled habits conveniently
+
+=<C-u K>= (~org-habit-toggle-display-in-agenda~) in an agenda toggles
+the display of all habits to those which are undone and scheduled.
+This is a function for convenience.
+
+*** New parameter for SQL Babel blocks: ~:dbconnection~
+
+The new parameter ~:dbconnection~ allows to specify a connection name
+in a SQL block header: this name is used to look up connection
+parameters in ~sql-connection-alist~.
+
+*** New =:scale= attribute supported by LaTeX exporters
+
+The builtin "latex" exporters now accept and use a =:scale= attribute,
+which scales an image by a given factor.
+
+This attribute is wrapped adound the =scale= parameter of LaTeX's
+=\includegraphics= (bitmap images) or a TiKZ's =\scalebox=.
+Therefore, its value should be some string palatable to LaTeX as
+a positive float Its default value is an empty string (i.e. disabled).
+
+This attribute overrides the =:width= and =:height= attributes.
+
+#+begin_example
+,#+name: Beastie
+,#+caption: I think I saw this curious horse already, but where ?
+,#+LATEX_ATTR: :scale 2
+[[https://orgmode.org/img/org-mode-unicorn-logo.png]]
+#+end_example
+
+*** Allow specifying the target for a table of contents
+
+The =+TOC= keyword now accepts a =:target:= attribute that specifies
+the headline to use for making the table of contents.
+
+#+begin_example
+,* Target
+  :PROPERTIES:
+  :CUSTOM_ID: TargetSection
+  :END:
+,** Heading A
+,** Heading B
+,* Another section
+,#+TOC: headlines 1 :target "#TargetSection"
+#+end_example
+
+** New functions
+*** ~org-dynamic-block-insert-dblock~
+
+Use default keybinding =<C-c C-x x>= to run command
+~org-dynamic-block-insert-dblock~.  It will prompt user to select
+dynamic block in ~org-dynamic-block-alist~.
+
+*** ~org-table-cell-up~
+*** ~org-table-cell-down~
+*** ~org-table-cell-left~
+*** ~org-table-cell-right~
+*** ~org-habit-toggle-display-in-agenda~
+** Removed functions and variables
+*** Removed Org Drill
+
+You can install it back from MELPA.
+
+*** ~org-babel-set-current-result-hash~
+*** ~org-capture-insert-template-here~
+*** ~org-attach-directory~
+
+It has been deprecated in favour of ~org-attach-id-dir~ which is less
+ambiguous given the restructured org-attach.
+
+*** ~org-enable-fixed-width-editor~
+
+This variable was not used through the code base.
+
+** Miscellaneous
+*** Change signature for ~org-list-to-subtree~
+
+The function now accepts the level of the subtree as an optional
+argument.  It no longer deduces it from the current level.
+
+*** LaTeX preview is simplified
+
+Function ~org-latex-preview~, formerly known as
+~org-toggle-latex-fragment~, has a hopefully simpler and more
+predictable behavior.  See its docstring for details.
+
+*** ~org-table-copy-down~ supports patterns
+
+When ~org-table-copy-increment~ is non-nil, it is now possible to
+increment fields like =A1=, or =0A=, i.e., any string prefixed or
+suffixed with a whole number.
+
+*** No more special indentation for description items
+
+Descriptions items are indented like regular ones, i.e., text starts
+after the bullet.  Special indentation used to introduce bugs when
+inserting sub-items in a description list.
+
+*** New hook: ~org-todo-repeat-hook~
+
+This hook was actually introduced in Org 9.2.1, but wasn't advertised.
+
+*** Org Table reads numbers starting with 0 as strings
+*** Disable fast tag selection interface via prefix arg
+
+A call of ~org-set-tags-command~ with prefix argument C-u C-u avoids
+the fast tag selection interface and instead offers the plain
+interface.
+
+*** ~:mkdirp~ now supports create directory for ~:dir~ path
+
+The ~:mkdirp~ header argument used to only work for ~:tangle~ tangle
+files. Now ~:mkdirp~ works for ~:dir~ too. This is more convenient for
+specify default directory and with ~:file~ header argument.
+
+*** New variable: ~org-agenda-breadcrumbs-separator~
+
+If breadcrumbs are showed in org-agenda with the help of "%b" format
+in ~org-agenda-prefix-format~, user can customize breadcrumbs's
+separator using ~org-agenda-breadcrumbs-separator~.
+
+*** New variable ~org-attach-commands~
+
+This variable makes it possible to customize the list of commands for
+the attachment dispatcher.
+
+*** New ID method based on timestamp
+
+If one chooses, it is now possible to create ID's based on timestamp
+(ISO8601) instead of UUID by changing org-id-method to ts.
+
+For an improved folder structure when using timestamp as ID, make sure
+to promote ~org-attach-id-ts-folder-format~ to the first element of
+~org-attach-id-to-path-function-list~ in your configuration at the
+same time.
+
+*** New customization: ~org-id-locations-relative~
+
+New customization to make the persisting of org-id-locations between
+sessions to store links to files as relative instead of absolute.  The
+links will be stored as relative to the path of org-id-locations-file.
+
+*** ~org-ctrl-c-tab~ is functional before the first headline
+
+I.e. treat the whole file as if it was a subtree.
+
+Also fold everything below the chosen level.  Former behavior was to
+leave unfolded subtrees unfolded.
+
+*** ~org-kill-note-or-show-branches~ is functional before the first headline
+
+I.e. treat the whole file as if it was a subtree.
+
+*** Respect narrowing when agenda command is restricted to buffer
+
+* Version 9.2
+** Incompatible changes
+*** Removal of OrgStruct mode mode and radio lists
+
+OrgStruct minor mode and radio lists mechanism (~org-list-send-list~
+and ~org-list-radio-lists-templates~) are removed from the code base.
+
+Note that only radio /lists/ have been removed, not radio tables.
+
+If you want to manipulate lists like in Org in other modes, we suggest
+to use orgalist.el, which you can install from GNU ELPA.
+
+If you want to use Org folding outside of Org buffers, you can have a
+look at the outshine package in the MELPA repository.
+
+*** Change in the structure template expansion
+
+Org 9.2 comes with a new template expansion mechanism, combining
+~org-insert-structure-template~ bound to ~C-c C-,~.
+
+If you customized the ~org-structure-template-alist~ option manually,
+you probably need to update it, see the docstring for accepted values.
+
+If you prefer using previous patterns, e.g. =<s=, you can activate
+them again by requiring Org Tempo library:
+
+: (require 'org-tempo)
+
+or add it to ~org-modules~.
+
+If you need complex templates, look at the ~tempo-define-template~
+function or at solutions like Yasnippet.
+
+*** Change to Noweb expansion
+
+Expansion check =:noweb-ref= only if no matching named block is found
+in the buffer.  As a consequence, any =:noweb-ref= value matching the
+name of a source block in the buffer is ignored. A simple fix is to
+give every concerned source-block, including the named one, a new,
+unique, Noweb reference.
+
+#+BEGIN_SRC org
+  ,#+NAME: foo
+  ,#+BEGIN_SRC emacs-lisp
+    1
+  ,#+END_SRC
+
+  ,#+BEGIN_SRC emacs-lisp :noweb-ref foo
+    2
+  ,#+END_SRC
+
+  ,#+BEGIN_SRC emacs-lisp :noweb yes
+    <<foo>>
+  ,#+END_SRC
+#+END_SRC
+
+should become
+
+#+BEGIN_SRC org
+  ,#+NAME: foo
+  ,#+BEGIN_SRC emacs-lisp :noweb-ref bar
+    1
+  ,#+END_SRC
+
+  ,#+BEGIN_SRC emacs-lisp :noweb-ref bar
+    2
+  ,#+END_SRC
+
+  ,#+BEGIN_SRC emacs-lisp :noweb yes
+    <<bar>>
+  ,#+END_SRC
+#+END_SRC
+
+*** Default/accepted values of ~org-calendar-to-agenda-key~
+
+The default value and accepted value of  ~org-calendar-to-agenda-key~
+changed.  This is an excerpt of the new docstring:
+
+: When set to ‘default’, bind the function to ‘c’, but only if it is
+: available in the Calendar keymap.  This is the default choice because
+: ‘c’ can then be used to switch back and forth between agenda and calendar.
+:
+: When nil, ‘org-calendar-goto-agenda’ is not bound to any key.
+
+Check the full docstring for more.
+
+*** Change the signature of the ~org-set-effort~ function
+
+Here is the new docstring:
+
+: (org-set-effort &optional INCREMENT VALUE)
+:
+: Set the effort property of the current entry.
+: If INCREMENT is non-nil, set the property to the next allowed
+: value.  Otherwise, if optional argument VALUE is provided, use
+: it.  Eventually, prompt for the new value if none of the previous
+: variables is set.
+
+*** Placeholders in =(eval ...)= macros are always strings
+
+Within =(eval ...)= macros, =$1=-like placeholders are always replaced
+with a string.  As a consequence, they must not be enclosed within
+quotes. As an illustration, consider the following, now valid,
+examples:
+
+#+begin_example
+  ,#+macro: join (eval (concat $1 $2))
+  ,#+macro: sum (eval (+ (string-to-number $1) (string-to-number $2)))
+
+  {{{join(a,b)}}} => ab
+  {{{sum(1,2)}}}  => 3
+#+end_example
+
+However, there is no change in non-eval macros:
+
+#+begin_example
+  ,#+macro: disp argument: $1
+
+  {{{disp(text)}}} => argument: text
+#+end_example
+
+*** =align= STARTUP value no longer narrow table columns
+
+Columns narrowing (or shrinking) is now dynamic. See [[*Dynamically
+narrow table columns]] for details. In particular, it is decoupled from
+aligning.
+
+If you need to automatically shrink columns upon opening an Org
+document, use =shrink= value instead, or in addition to align:
+
+#+BEGIN_EXAMPLE
+,#+STARTUP: align shrink
+#+END_EXAMPLE
+
+*** ~org-get-tags~ meaning change
+
+Function ~org-get-tags~ used to return local tags to the current
+headline.  It now returns all the inherited tags in addition to the
+local tags.  In order to get the old behaviour back, you can use:
+
+: (org-get-tags nil t)
+
+*** Alphabetic sorting in tables and lists
+
+When sorting alphabetically, ~org-table-sort-lines~ and ~org-sort-list~
+now sort according to the locale’s collation rules instead of by
+code-point.
+
+*** Change the name of the :tags clocktable option to :match
+
+The =:match= (renamed from =:tags=) option allows to limit clock entries
+to those matching a todo-tags matcher.
+
+The old =:tags= option can be set to =t= to display a headline's tags in a
+dedicated column.
+
+This is consistent with the naming of =org-dblock-write:columnview=
+options, where =:match= is also used as a headlines filter.
+
+** New features
+*** Add ~:session~ support of ob-clojure for CIDER
+You can initialize source block session with Babel default keybinding
+=[C-c C-v C-z]= to use =sesman= session manager to link current
+project, directory or buffer with specific Clojure session, or
+=cider-jack-in= a new CIDER REPL if no CIDER REPLs available. In older
+CIDER version which has not =sesman= integrated, only has
+=cider-jack-in= without Clojure project is supported.
+#+begin_src clojure :session
+(dissoc Clojure 'JVM)
+(conj clojurists "stardiviner")
+#+end_src
+*** Add ~:results link~ support for Babel
+
+With this output format, create a link to the file specified in
+~:file~ header argument, without actually writing any result to it:
+
+#+begin_example
+,#+begin_src shell :dir "data/tmp" :results link :file "crackzor_1.0.c.gz"
+wget -c "http://ben.akrin.com/crackzor/crackzor_1.0.c.gz";
+,#+end_src
+
+,#+results:
+[[file:data/tmp/crackzor_1.0.c.gz]]
+#+end_example
+
+*** Add ~:session~ support of ob-js for js-comint
+#+begin_src js :session "*Javascript REPL*"
+console.log("stardiviner")
+#+end_src
+*** Add ~:session~ support of ob-js for Indium
+#+begin_src js :session "*JS REPL*"
+console.log("stardiviner")
+#+end_src
+*** Add ~:session~ support of ob-js for skewer-mode
+#+begin_src js :session "*skewer-repl*"
+console.log("stardiviner")
+#+end_src
+*** Add support for links to LaTeX equations in HTML export
+Use MathJax links when enabled (by ~org-html-with-latex~), otherwise
+add a label to the rendered equation.
+*** Org Tempo may used for snippet expansion of structure template.
+See manual and the commentary section in ~org-tempo.el~ for details.
+*** Exclude unnumbered headlines from table of contents
+Set their =UNNUMBERED= property to the special =notoc= value.  See
+manual for details.
+*** ~org-archive~ functions update status cookies
+
+Archiving headers through ~org-archive-subtree~ and
+~org-archive-to-archive-sibling~ such as the ones listed below:
+
+#+BEGIN_SRC org
+  ,* Top [1/2]
+  ,** DONE Completed
+  ,** TODO Working
+#+END_SRC
+
+Will update the status cookie in the top level header.
+
+*** Disable =org-agenda-overriding-header= by setting to empty string
+
+The ~org-agenda-overriding-header~ inserted into agenda views can now
+be disabled by setting it to an empty string.
+
+*** Dynamically narrow table columns
+
+With ~C-c TAB~, it is now possible to narrow a column to the width
+specified by a width cookie in the column, or to 1 character if there
+is no such cookie.  The same keybinding expands a narrowed column to
+its previous state.
+
+Editing the column automatically expands the whole column to its full
+size.
+
+*** =org-columns-summary-types= entries can take an optional COLLECT function
+
+You can use this to make collection of a property from an entry
+conditional on another entry. E.g. given this configuration:
+
+#+BEGIN_SRC emacs-lisp
+  (defun custom/org-collect-confirmed (property)
+    "Return `PROPERTY' for `CONFIRMED' entries"
+    (let ((prop (org-entry-get nil property))
+         (confirmed (org-entry-get nil "CONFIRMED")))
+      (if (and prop (string= "[X]" confirmed))
+         prop
+       "0")))
+
+  (setq org-columns-summary-types
+       '(("X+" org-columns--summary-sum
+          custom/org-collect-confirmed)))
+#+END_SRC
+
+You can have a file =bananas.org= containing:
+
+#+BEGIN_SRC org
+  ,#+columns: %ITEM %CONFIRMED %Bananas{+} %Bananas(Confirmed Bananas){X+}
+
+  ,* All shipments
+  ,** Shipment 1
+     :PROPERTIES:
+     :CONFIRMED: [X]
+     :Bananas:  4
+     :END:
+
+  ,** Shipment 2
+     :PROPERTIES:
+     :CONFIRMED: [ ]
+     :BANANAS:  7
+     :END:
+#+END_SRC
+
+... and when going to the top of that file and entering column view
+you should expect to see something like:
+
+| ITEM          | CONFIRMED | Bananas | Confirmed Bananas |
+|---------------+-----------+---------+-------------------|
+| All shipments |           |      11 |                 4 |
+| Shipment 1    | [X]       |       4 |                 4 |
+| Shipment 2    | [ ]       |       7 |                 7 |
+
+#+BEGIN_EXAMPLE
+  ,#+STARTUP: shrink
+#+END_EXAMPLE
+*** Allow to filter by tags/property when capturing colview
+
+You can now use =:match= to filter entries using a todo/tags/properties
+matcher.
+
+*** Add support for Oracle's database alias in Babel blocks
+=ob-sql= library already support running SQL blocks against an Oracle
+database using ~sqlplus~.  Now it's possible to use alias names
+defined in =TNSNAMES= file instead of specifying full connection
+parameters.  See example below.
+
+#+BEGIN_SRC org
+  you can use the previous full connection parameters
+  ,#+BEGIN_SRC sql :engine oracle :dbuser me :dbpassword my_insecure_password 
:database my_db_name :dbhost my_db_host :dbport 1521
+  select sysdate from dual;
+  ,#+END_SRC
+
+  or the alias defined in your TNSNAMES file
+  ,#+BEGIN_SRC sql :engine oracle :dbuser me :dbpassword my_insecure_password 
:database my_tns_alias
+  select sysdate from dual;
+  ,#+END_SRC
+#+END_SRC
+
+*** ~org-agenda-set-restriction-lock~ toggle agenda restriction at point
+
+You can set an agenda restriction lock with =C-x C-x <= or with =<= at the
+beginning of a headline when using Org speed commands.  Now, if there
+is already a restriction at point, hitting =<= again (or =C-x C-x <=) will
+remove it.
+
+*** Headlines can now link to themselves in HTML export
+
+When enabling ~org-html-self-link-headlines~ the headlines exported to
+HTML contain a hyperlink to themselves.
+
+** New commands and functions
+
+*** ~org-insert-structure-template~
+
+This function can be used to wrap existing text of Org elements in
+a #+BEGIN_FOO/#+END_FOO block.  Bound to C-c C-x w by default.
+
+*** ~org-export-excluded-from-toc-p~
+
+See docstring for details.
+
+*** ~org-timestamp-to-time~
+*** ~org-timestamp-from-string~
+*** ~org-timestamp-from-time~
+*** ~org-attach-dired-to-subtree~
+
+See docstring for details.
+
+*** ~org-toggle-narrow-to-subtree~
+
+Toggle the narrowing state of the buffer: when in a narrowed state,
+widen, otherwise call ~org-narrow-to-subtree~ to narrow.
+
+This is attached to the "s" speed command, so that hitting "s" twice
+will go back to the widen state.
+
+*** ~org-browse-news~
+
+Browse https://orgmode.org/Changes.html to let users read information
+about the last major release.
+
+There is a new menu entry for this in the "Documentation" menu item.
+
+*** ~org-info-find-node~
+
+From an Org file or an agenda switch to a suitable info page depending
+on the context.
+
+The function is bound to =C-c C-x I=.
+
+** Removed commands and functions
+*** ~org-outline-overlay-data~
+Use ~org-save-outline-visibility~ instead.
+*** ~org-set-outline-overlay-data~
+Use ~org-save-outline-visibility~ instead.
+*** ~org-get-string-indentation~
+It was not used throughout the code base.
+*** ~org-fix-indentation~
+It was not used throughout code base.
+*** ~org-context-p~
+Use ~org-element-at-point~ instead.
+*** ~org-preserve-lc~
+It is no longer used in the code base.
+*** ~org-try-structure-completion~
+Org Tempo may be used as a replacement.  See details above.
+** Removed options
+
+*** org-babel-use-quick-and-dirty-noweb-expansion
+
+See [[*Change to Noweb expansion][Change to Noweb expansion]] for explanations.
+
+** Miscellaneous
+
+*** New default value for ~org-texinfo-table-scientific-notation~
+
+It is now nil, which means numbers in scientific notation are not
+handled specially by default.
+
+*** New default value for ~org-latex-table-scientific-notation~
+
+It is now nil, which means numbers in scientific notation are not
+handled specially by default.
+
+*** New face: ~org-upcoming-distant-deadline~
+
+It is meant to be used as the face for distant deadlines, see
+~org-agenda-deadline-faces~
+
+*** ~org-paste-subtree~ no longer breaks sections
+
+Unless point is at the beginning of a headline, ~org-paste-subtree~
+now pastes the tree before the next visible headline.  If you need to
+break the section, use ~org-yank~ instead.
+
+*** ~org-table-insert-column~ inserts a column to the right
+
+It used to insert it on the left.  With this change,
+~org-table-insert-column~ and ~org-table-delete-column~ are
+reciprocal.
+
+*** ~org-publish-resolve-external-link~ accepts a new optional argument.
+*** ~org-irc.el~ now supports exporting =irc:= links properly
+
+Previously, irc links were exported by ~ox-md~ and ~ox-html~ as normal
+file links, which lead to them being broken in web browsers. Now both
+of these exporters will properly export to =irc:= links, which will
+open properly in irc clients from web browsers.
+
+*** ~org-comment-dwim~ (bound to =M-;=) now comments headings, if point is on 
a heading
+*** Add support for open source block in window below
+
+Set option ~org-src-window-setup~ to ~split-window-below~.
+
+*** Alphabetic sorting in headings and tags now uses the locale’s sorting rules
+
+When sorting alphabetically, ~org-sort-entries~ and
+~org-tags-sort-function~ now sort according to the locale’s collation
+rules instead of by code-point.
+*** New speed command "k" to kill (cut) the subtree at point
 * Version 9.1
 
 ** Incompatible changes
@@ -137,7 +1040,6 @@ See docstring for details.
 =org-agenda-tags-column= can now be set to =auto=, which will
 automatically align tags to the right edge of the window.  This is now
 the default setting.
-
 *** New value for ~org-publish-sitemap-sort-folders~
 
 The new ~ignore~ value effectively allows toggling inclusion of
@@ -204,7 +1106,7 @@ value of the code will be displayed in the results section.
 
 **** Maxima: new headers ~:prologue~ and ~:epilogue~
 Babel options ~:prologue~ and ~:epilogue~ have been implemented for
-Maxima src blocks which prepend and append, respectively, the given
+Maxima source blocks which prepend and append, respectively, the given
 code strings.  This can be useful for specifying formatting settings
 which would add clutter to exported code.  For instance, you can use
 this ~:prologue "fpprintprec: 2; linel: 50;"~ for presenting Maxima
@@ -486,7 +1388,7 @@ is now obsolete.
 Now ~=...=~ markup uses ~@samp{}~ instead of ~@verb{}~.  You can use
 ~@verb{}~ again by customizing the variable.
 *** Texinfo exports example blocks as ~@example~
-*** Texinfo exports inline src blocks as ~@code{}~
+*** Texinfo exports inline source blocks as ~@code{}~
 *** Texinfo default table markup is ~@asis~
 It used to be ~@samp~ but ~@asis~ is neutral and, therefore, more
 suitable as a default value.
@@ -1303,9 +2205,9 @@ docstring for more information.
 
 ** New features
 
-*** Default lexical evaluation of emacs-lisp src blocks
+*** Default lexical evaluation of emacs-lisp source blocks
 
-Emacs-lisp src blocks in babel are now evaluated using lexical
+Emacs-lisp source blocks in Babel are now evaluated using lexical
 scoping.  There is a new header to control this behavior.
 
 The default results in an eval with lexical scoping.
@@ -1324,7 +2226,7 @@ without changing the headline.
 
 *** Hierarchies of tags
 
-The functionality of nesting tags in hierarchies is added to org-mode.
+The functionality of nesting tags in hierarchies is added to Org mode.
 This is the generalization of what was previously called "Tag groups"
 in the manual.  That term is now changed to "Tag hierarchy".
 
@@ -1746,7 +2648,7 @@ everywhere in the buffer, possibly corrupting URLs.
 
 This undocumented option defaulted to the value of =shell-file-name= at
 the time of loading =ob-shell=.  The new behavior is to use the value
-of =shell-file-name= directly when the shell langage is =shell=.  To chose
+of =shell-file-name= directly when the shell language is =shell=.  To chose
 a different shell, either customize =shell-file-name= or bind this
 variable locally.
 
@@ -2918,7 +3820,7 @@ See https://orgmode.org/elpa/
    | =C-c C-x E=     | =E=    | [[doc::org-inc-effort][org-inc-effort]]        
      |
    |                 | =#=    | 
[[doc::org-toggle-comment][org-toggle-comment]]          |
    |                 | =:=    | [[doc::org-columns][org-columns]]              
   |
-   |                 | =W=    | Set =APPT_WARNTIME=          |
+   |                 | =W=    | Set =APPT_WARNTIME=         |
    | =k=             |        | 
[[doc::org-agenda-capture][org-agenda-capture]]          |
    | C-c ,           | ,      | [[doc::org-priority][org-priority]]            
    |
 
@@ -3754,7 +4656,7 @@ that Calc formulas can operate on them.
 **** org-ctags.el (Paul Sexton)
 
      Targets like =<<my target>>= can now be found by Emacs' etag
-     functionality, and Org-mode links can be used to link to
+     functionality, and Org-mode links can be used to to link to
      etags, also in non-Org-mode files.  For details, see the file
      /org-ctags.el/.
 
@@ -3824,7 +4726,7 @@ that Calc formulas can operate on them.
 
      : Percent escaping is used in Org mode to escape certain characters
      : in links that would either break the parser (e.g. square brackets
-     : in link target oder description) or are not allowed to appear in
+     : in link target or description) or are not allowed to appear in
      : a particular link type (e.g. non-ascii characters in a http:
      : link).
      :
diff --git a/etc/refcards/orgcard.tex b/etc/refcards/orgcard.tex
index 4a51fe0..38f6dce 100644
--- a/etc/refcards/orgcard.tex
+++ b/etc/refcards/orgcard.tex
@@ -1,7 +1,5 @@
 % Reference Card for Org Mode
-\def\orgversionnumber{9.1.9}
-\def\versionyear{2018}          % latest update
-\input emacsver.tex
+\input org-version.tex
 
 %**start of header
 \newcount\columnsperpage
@@ -79,9 +77,6 @@
 \centerline{Released under the terms of the GNU General Public License}
 \centerline{version 3 or later.}
 
-\centerline{For more Emacs documentation, and the \TeX{} source for this card, 
see}
-\centerline{the Emacs distribution, or {\tt 
https://www.gnu.org/software/emacs}}
-
 \endgroup}
 
 % make \bye not \outer so that the \def\bye in the \else clause below
@@ -271,8 +266,10 @@
 \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\noteone{{\small \hfill [1]}}
+%\def\notetwo{{\small \hfill [2]}}
+\def\noteone{{\small [1]}}
+\def\notetwo{{\small [2]}}
 
 
 %**end of header
@@ -292,6 +289,7 @@
 \key{restore property-dependent startup visibility}{C-u C-u TAB}
 \metax{show the whole file, including drawers}{C-u C-u C-u TAB}
 \key{reveal context around point}{C-c C-r}
+\metax{toggle indented view}{M-x org-indent-mode}
 
 \section{Motion}
 
@@ -458,7 +456,7 @@ formula, \kbd{:=} a field formula.
 \key{go to the next code block}{C-c C-v n}
 \key{go to the previous code block}{C-c C-v p}
 \key{demarcate a code block}{C-c C-v d}
-\key{execute the next key sequence in the code edit buffer}{C-c C-v x}
+\key{execute next key sequence in code edit buffer}{C-c C-v x}
 \key{execute all code blocks in current buffer}{C-c C-v b}
 \key{execute all code blocks in current subtree}{C-c C-v s}
 \key{tangle code blocks in current file}{C-c C-v t}
@@ -468,13 +466,14 @@ formula, \kbd{:=} a field formula.
 \key{load the current code block into a session}{C-c C-v l}
 \key{view sha1 hash of the current code block}{C-c C-v a}
 
-\section{Completion}
+\section{Completion and Template Insertion}
 
 In-buffer completion completes TODO keywords at headline start, TeX
 macros after ``{\tt \\}'', option keywords after ``{\tt \#-}'', TAGS
 after  ``{\tt :}'', and dictionary words elsewhere.
 
 \key{complete word at point}{M-TAB}
+\key{structure template (insert or wrap region)}{C-c C-,}
 
 
 \newcolumn
@@ -485,8 +484,8 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 \section{TODO Items and Checkboxes}
 
 \key{rotate the state of the current item}{C-c C-t}
-\metax{select next/previous state}{S-LEFT/RIGHT}
-\metax{select next/previous set}{C-S-LEFT/RIGHT}
+\metax{select next/previous state}{\quad\quad S-LEFT/RIGHT}
+\metax{select next/previous set}{\quad\quad\quad C-S-LEFT/RIGHT}
 \key{toggle ORDERED property}{C-c C-x o}
 
 \key{view TODO items in a sparse tree}{C-c / t}
@@ -512,19 +511,19 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 
 \key{set property/effort}{C-c C-x p/e}
 \key{special commands in property lines}{C-c C-c}
-\key{next/previous allowed value}{S-left/right}
+\key{next/previous allowed value}{S-LEFT/RIGHT}
 \key{turn on column view}{C-c C-x C-c}
 \key{capture columns view in dynamic block}{C-c C-x i}
 
 \key{quit column view}{q}
 \key{show full value}{v}
 \key{edit value}{e}
-\metax{next/previous allowed value}{n/p or S-left/right}
+\metax{next/previous allowed value}{n/p or S-LEFT/RIGHT}
 \key{edit allowed values list}{a}
 \key{make column wider/narrower}{> / <}
-\key{move column left/right}{M-left/right}
-\key{add new column}{M-S-right}
-\key{Delete current column}{M-S-left}
+\key{move column left/right}{M-LEFT/RIGHT}
+\key{add new column}{M-S-RIGHT}
+\key{Delete current column}{M-S-LEFT}
 
 
 \section{Timestamps}
@@ -536,8 +535,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}
-\metax{change timestamp at cursor $\pm 1$ day}{S-RIGHT/LEFT\notetwo}
-\key{change year/month/day at cursor by $\pm 1$}{S-UP/DOWN\notetwo}
+\metax{change timestamp at cursor $\pm 1$ day}{\quad\quad\quad\quad 
S-RIGHT/LEFT \notetwo}
+\key{change year/month/day at cursor by $\pm 1$}{S-UP/DOWN \notetwo}
 \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}
@@ -666,8 +665,6 @@ some other place.
 \key{toggle fixed width for entry or region}{C-c :}
 \key{toggle pretty display of scripts, entities}{C-c C-x {\tt\char`\\}}
 
-{\bf Comments: Text not being exported}
-
 Lines starting with \kbd{\#} and subtrees starting with COMMENT are
 never exported.
 
diff --git a/etc/schema/schemas.xml b/etc/schema/schemas.xml
index a9c14dd..f1e0ed7 100644
--- a/etc/schema/schemas.xml
+++ b/etc/schema/schemas.xml
@@ -1,64 +1,7 @@
-<!-- Copyright (C) 2003-2004, 2007-2019 Free Software Foundation, Inc.
-
-This file is part of GNU Emacs.
-
-GNU Emacs is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>. -->
-
+<?xml version="1.0"?>
 <locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0";>
-  <transformURI fromPattern="*.xml" toPattern="*.rnc"/>
-
-  <uri pattern="*.xsl" typeId="XSLT"/>
-  <uri pattern="*.html" typeId="XHTML"/>
-  <uri pattern="*.rng" typeId="RELAX NG"/>
-  <uri pattern="*.rdf" typeId="RDF"/>
-  <uri pattern="*.dbk" typeId="DocBook"/>
-
-  <namespace ns="http://www.w3.org/1999/XSL/Transform"; typeId="XSLT"/>
-  <namespace ns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; typeId="RDF"/>
-  <namespace ns="http://www.w3.org/1999/xhtml"; typeId="XHTML"/>
-  <namespace ns="http://relaxng.org/ns/structure/1.0"; typeId="RELAX NG"/>
-  <namespace ns="http://thaiopensource.com/ns/locating-rules/1.0";
-            uri="locate.rnc"/>
-
-  <documentElement localName="stylesheet" typeId="XSLT"/>
-  <documentElement prefix="xsl" localName="transform" typeId="XSLT"/>
-
-  <documentElement localName="html" typeId="XHTML"/>
-
-  <documentElement localName="grammar" typeId="RELAX NG"/>
-
-  <documentElement prefix="" localName="article" typeId="DocBook"/>
-  <documentElement prefix="" localName="book" typeId="DocBook"/>
-  <documentElement prefix="" localName="chapter" typeId="DocBook"/>
-  <documentElement prefix="" localName="part" typeId="DocBook"/>
-  <documentElement prefix="" localName="refentry" typeId="DocBook"/>
-  <documentElement prefix="" localName="section" typeId="DocBook"/>
-
-  <documentElement localName="RDF" typeId="RDF"/>
-  <documentElement prefix="rdf" typeId="RDF"/>
-
-  <documentElement localName="locatingRules" uri="locate.rnc"/>
-
-  <typeId id="XSLT" uri="xslt.rnc"/>
-  <typeId id="RELAX NG" uri="relaxng.rnc"/>
-  <typeId id="XHTML" uri="xhtml.rnc"/>
-  <typeId id="DocBook" uri="docbook.rnc"/>
-  <typeId id="RDF" uri="rdfxml.rnc"/>
-
   <documentElement prefix="office" typeId="OpenDocument"/>
   <documentElement prefix="manifest" localName="manifest" typeId="OpenDocument 
Manifest"/>
   <typeId id="OpenDocument" uri="od-schema-v1.2-os.rnc"/>
   <typeId id="OpenDocument Manifest" uri="od-manifest-schema-v1.2-os.rnc"/>
-
 </locatingRules>
diff --git a/lisp/org/ob-C.el b/lisp/org/ob-C.el
index e08773b..ca587cc 100644
--- a/lisp/org/ob-C.el
+++ b/lisp/org/ob-C.el
@@ -34,11 +34,9 @@
 
 (require 'cc-mode)
 (require 'ob)
-
+(require 'org-macs)
 
 (declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
-(declare-function org-remove-indentation "org" (code &optional n))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("C++" . "cpp"))
@@ -375,8 +373,8 @@ FORMAT can be either a format string or a function which is 
called with VAL."
              (pcase (org-babel-C-val-to-base-type v)
                (`stringp (setq type 'stringp))
                (`floatp
-                (if (or (not type) (eq type 'integerp))
-                    (setq type 'floatp)))
+                (when (or (not type) (eq type 'integerp))
+                  (setq type 'floatp)))
                (`integerp
                 (unless type (setq type 'integerp)))))
            val)
@@ -395,9 +393,9 @@ of the same value."
        (setq val (string-to-char val))))
     (let* ((type-data (org-babel-C-val-to-C-type val))
           (type (car type-data))
-          (formated (org-babel-C-format-val type-data val))
-          (suffix (car formated))
-          (data (cdr formated)))
+          (formatted (org-babel-C-format-val type-data val))
+          (suffix (car formatted))
+          (data (cdr formatted)))
       (format "%s %s%s = %s;"
              type
              var
diff --git a/lisp/org/ob-J.el b/lisp/org/ob-J.el
index 2d1715a..b48562d 100644
--- a/lisp/org/ob-J.el
+++ b/lisp/org/ob-J.el
@@ -31,8 +31,8 @@
 ;;; Code:
 
 (require 'ob)
+(require 'org-macs)
 
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function j-console-ensure-session "ext:j-console" ())
 
 (defcustom org-babel-J-command "jconsole"
diff --git a/lisp/org/ob-calc.el b/lisp/org/ob-calc.el
index 6ee93cd..d888f98 100644
--- a/lisp/org/ob-calc.el
+++ b/lisp/org/ob-calc.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 (require 'calc)
 (require 'calc-trail)
 (require 'calc-store)
@@ -34,7 +35,6 @@
 (declare-function calc-store-into    "calc-store" (&optional var))
 (declare-function calc-recall        "calc-store" (&optional var))
 (declare-function math-evaluate-expr "calc-ext"   (x))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-default-header-args:calc nil
   "Default arguments for evaluating a calc source block.")
diff --git a/lisp/org/ob-clojure.el b/lisp/org/ob-clojure.el
index 14c014a..0e5642a 100644
--- a/lisp/org/ob-clojure.el
+++ b/lisp/org/ob-clojure.el
@@ -41,26 +41,30 @@
 ;;; Code:
 (require 'cl-lib)
 (require 'ob)
+(require 'org-macs)
 
+(declare-function cider-jack-in "ext:cider" (&optional prompt-project 
cljs-too))
 (declare-function cider-current-connection "ext:cider-client" (&optional type))
 (declare-function cider-current-ns "ext:cider-client" ())
+(declare-function cider-repls "ext:cider-connection" (&optional type ensure))
 (declare-function nrepl--merge "ext:nrepl-client" (dict1 dict2))
 (declare-function nrepl-dict-get "ext:nrepl-client" (dict key))
 (declare-function nrepl-dict-put "ext:nrepl-client" (dict key value))
-(declare-function nrepl-request:eval "ext:nrepl-client"
-                 (input callback connection &optional session ns line column 
additional-params))
-(declare-function nrepl-sync-request:eval "ext:nrepl-client"
-                 (input connection session &optional ns))
-(declare-function org-trim "org" (s &optional keep-lead))
+(declare-function nrepl-request:eval "ext:nrepl-client" (input callback 
connection &optional ns line column additional-params tooling))
+(declare-function nrepl-sync-request:eval "ext:nrepl-client" (input connection 
&optional ns tooling))
 (declare-function slime-eval "ext:slime" (sexp &optional package))
 
 (defvar nrepl-sync-request-timeout)
+(defvar cider-buffer-ns)
+(defvar sesman-system)
+(defvar cider-version)
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
 
 (defvar org-babel-default-header-args:clojure '())
-(defvar org-babel-header-args:clojure '((package . :any)))
+(defvar org-babel-header-args:clojure '((ns . :any)
+                                       (package . :any)))
 
 (defcustom org-babel-clojure-sync-nrepl-timeout 10
   "Timeout value, in seconds, of a Clojure sync call.
@@ -80,19 +84,39 @@ If the value is nil, timeout is disabled."
          (const :tag "cider" cider)
          (const :tag "SLIME" slime)))
 
+(defcustom org-babel-clojure-default-ns "user"
+  "Default Clojure namespace for source block when finding ns failed."
+  :type 'string
+  :group 'org-babel)
+
+(defun org-babel-clojure-cider-current-ns ()
+  "Like `cider-current-ns' except `cider-find-ns'."
+  (or cider-buffer-ns
+      (let ((repl-buf (cider-current-connection)))
+       (and repl-buf (buffer-local-value 'cider-buffer-ns repl-buf)))
+      org-babel-clojure-default-ns))
+
 (defun org-babel-expand-body:clojure (body params)
   "Expand BODY according to PARAMS, return the expanded body."
   (let* ((vars (org-babel--get-vars params))
+        (ns (or (cdr (assq :ns params))
+                (org-babel-clojure-cider-current-ns)))
         (result-params (cdr (assq :result-params params)))
-        (print-level nil) (print-length nil)
+        (print-level nil)
+        (print-length nil)
         (body (org-trim
-               (if (null vars) (org-trim body)
-                 (concat "(let ["
-                         (mapconcat
-                          (lambda (var)
-                            (format "%S (quote %S)" (car var) (cdr var)))
-                          vars "\n      ")
-                         "]\n" body ")")))))
+               (concat
+                ;; Source block specified namespace :ns.
+                (and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
+                ;; Variables binding.
+                (if (null vars) (org-trim body)
+                  (format "(let [%s]\n%s)"
+                          (mapconcat
+                           (lambda (var)
+                             (format "%S (quote %S)" (car var) (cdr var)))
+                           vars
+                           "\n      ")
+                          body))))))
     (if (or (member "code" result-params)
            (member "pp" result-params))
        (format "(clojure.pprint/pprint (do %s))" body)
@@ -102,9 +126,9 @@ If the value is nil, timeout is disabled."
   "Execute a block of Clojure code with Babel.
 The underlying process performed by the code block can be output
 using the :show-process parameter."
-  (let ((expanded (org-babel-expand-body:clojure body params))
-       (response (list 'dict))
-        result)
+  (let* ((expanded (org-babel-expand-body:clojure body params))
+        (response (list 'dict))
+         result)
     (cl-case org-babel-clojure-backend
       (cider
        (require 'cider)
@@ -117,8 +141,7 @@ using the :show-process parameter."
                     (let ((nrepl-sync-request-timeout
                            org-babel-clojure-sync-nrepl-timeout))
                       (nrepl-sync-request:eval expanded
-                                               (cider-current-connection)
-                                               (cider-current-ns))))
+                                               (cider-current-connection))))
               (setq result
                     (concat
                      (nrepl-dict-get response
@@ -152,8 +175,7 @@ using the :show-process parameter."
                (nrepl--merge response resp)
                ;; Update the status of the nREPL output session.
                (setq status (nrepl-dict-get response "status")))
-             (cider-current-connection)
-             (cider-current-ns))
+             (cider-current-connection))
 
             ;; Wait until the nREPL code finished to be processed.
             (while (not (member "done" status))
@@ -193,6 +215,69 @@ using the :show-process parameter."
       (condition-case nil (org-babel-script-escape result)
        (error result)))))
 
+(defun org-babel-clojure-initiate-session (&optional session _params)
+  "Initiate a session named SESSION according to PARAMS."
+  (when (and session (not (string= session "none")))
+    (save-window-excursion
+      (cond
+       ((org-babel-comint-buffer-livep session) nil)
+       ;; CIDER jack-in to the Clojure project directory.
+       ((eq org-babel-clojure-backend 'cider)
+        (require 'cider)
+        (let ((session-buffer
+              (save-window-excursion
+                (if (version< cider-version "0.18.0")
+                    ;; Older CIDER (without sesman) still need to use
+                    ;; old way.
+                    (cider-jack-in nil) ;jack-in without project
+                  ;; New CIDER (with sesman to manage sessions).
+                  (unless (cider-repls)
+                    (let ((sesman-system 'CIDER))
+                      (call-interactively 'sesman-link-with-directory))))
+                 (current-buffer))))
+          (when (org-babel-comint-buffer-livep session-buffer)
+            (sit-for .25)
+           session-buffer)))
+       ((eq org-babel-clojure-backend 'slime)
+        (error "Session evaluation with SLIME is not supported"))
+       (t
+        (error "Session initiate failed")))
+      (get-buffer session))))
+
+(defun org-babel-prep-session:clojure (session params)
+  "Prepare SESSION according to the header arguments specified in PARAMS."
+  (let ((session (org-babel-clojure-initiate-session session))
+        (var-lines (org-babel-variable-assignments:clojure params)))
+    (when session
+      (org-babel-comint-in-buffer session
+       (dolist (var var-lines)
+         (insert var)
+         (comint-send-input nil t)
+         (org-babel-comint-wait-for-output session)
+         (sit-for .1)
+         (goto-char (point-max)))))
+    session))
+
+(defun org-babel-clojure-var-to-clojure (var)
+  "Convert src block's VAR to Clojure variable."
+  (cond
+   ((listp var)
+    (replace-regexp-in-string "(" "'(" var))
+   ((stringp var)
+    ;; Wrap Babel passed-in header argument value with quotes in Clojure.
+    (format "\"%s\"" var))
+   (t
+    (format "%S" var))))
+
+(defun org-babel-variable-assignments:clojure (params)
+  "Return a list of Clojure statements assigning the block's variables in 
PARAMS."
+  (mapcar
+   (lambda (pair)
+     (format "(def %s %s)"
+             (car pair)
+             (org-babel-clojure-var-to-clojure (cdr pair))))
+   (org-babel--get-vars params)))
+
 (provide 'ob-clojure)
 
 ;;; ob-clojure.el ends here
diff --git a/lisp/org/ob-comint.el b/lisp/org/ob-comint.el
index e27c1f8..aa0d341 100644
--- a/lisp/org/ob-comint.el
+++ b/lisp/org/ob-comint.el
@@ -36,7 +36,7 @@
 
 (defun org-babel-comint-buffer-livep (buffer)
   "Check if BUFFER is a comint buffer with a live process."
-  (let ((buffer (if buffer (get-buffer buffer))))
+  (let ((buffer (when buffer (get-buffer buffer))))
     (and buffer (buffer-live-p buffer) (get-buffer-process buffer) buffer)))
 
 (defmacro org-babel-comint-in-buffer (buffer &rest body)
diff --git a/lisp/org/ob-core.el b/lisp/org/ob-core.el
index 9e78876..f877ff5 100644
--- a/lisp/org/ob-core.el
+++ b/lisp/org/ob-core.el
@@ -35,6 +35,7 @@
 
 (defvar org-babel-library-of-babel)
 (defvar org-edit-src-content-indentation)
+(defvar org-link-file-path-type)
 (defvar org-src-lang-modes)
 (defvar org-src-preserve-indentation)
 
@@ -47,10 +48,8 @@
 (declare-function org-babel-ref-resolve "ob-ref" (ref))
 (declare-function org-babel-ref-split-args "ob-ref" (arg-string))
 (declare-function org-babel-tangle-comment-links "ob-tangle" (&optional info))
-(declare-function org-completing-read "org" (&rest args))
 (declare-function org-current-level "org" ())
 (declare-function org-cycle "org" (&optional arg))
-(declare-function org-do-remove-indentation "org" (&optional n))
 (declare-function org-edit-src-code "org-src" (&optional code 
edit-buffer-name))
 (declare-function org-edit-src-exit "org-src"  ())
 (declare-function org-element-at-point "org-element" ())
@@ -60,9 +59,7 @@
 (declare-function org-element-type "org-element" (element))
 (declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
 (declare-function org-escape-code-in-region "org-src" (beg end))
-(declare-function org-get-indentation "org" (&optional line))
-(declare-function org-get-indentation "org" (&optional line))
-(declare-function org-in-regexp "org" (regexp &optional nlines visually))
+(declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
 (declare-function org-indent-line "org" ())
 (declare-function org-list-get-list-end "org-list" (item struct prevs))
 (declare-function org-list-prevs-alist "org-list" (struct))
@@ -75,24 +72,18 @@
 (declare-function org-narrow-to-subtree "org" ())
 (declare-function org-next-block "org" (arg &optional backward block-regexp))
 (declare-function org-open-at-point "org" (&optional in-emacs 
reference-buffer))
-(declare-function org-outline-overlay-data "org" (&optional use-markers))
 (declare-function org-previous-block "org" (arg &optional block-regexp))
-(declare-function org-remove-indentation "org" (code &optional n))
-(declare-function org-reverse-string "org" (string))
-(declare-function org-set-outline-overlay-data "org" (data))
 (declare-function org-show-context "org" (&optional key))
 (declare-function org-src-coderef-format "org-src" (&optional element))
 (declare-function org-src-coderef-regexp "org-src" (fmt &optional label))
+(declare-function org-src-get-lang-mode "org-src" (lang))
 (declare-function org-table-align "org-table" ())
 (declare-function org-table-end "org-table" (&optional table-type))
 (declare-function org-table-import "org-table" (file arg))
 (declare-function org-table-to-lisp "org-table" (&optional txt))
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function org-unescape-code-in-string "org-src" (s))
-(declare-function org-uniquify "org" (list))
 (declare-function orgtbl-to-generic "org-table" (table params))
 (declare-function orgtbl-to-orgtbl "org-table" (table params))
-(declare-function outline-show-all "outline" ())
 (declare-function tramp-compat-make-temp-file "tramp-compat" (filename 
&optional dir-flag))
 
 (defgroup org-babel nil
@@ -186,9 +177,14 @@ This string must include a \"%s\" which will be replaced 
by the results."
   :safe #'booleanp)
 
 (defun org-babel-noweb-wrap (&optional regexp)
-  (concat org-babel-noweb-wrap-start
-         (or regexp "\\([^ \t\n].+?[^ \t]\\|[^ \t\n]\\)")
-         org-babel-noweb-wrap-end))
+  "Return regexp matching a Noweb reference.
+
+Match any reference, or only those matching REGEXP, if non-nil.
+
+When matching, reference is stored in match group 1."
+  (concat (regexp-quote org-babel-noweb-wrap-start)
+         (or regexp "\\([^ \t\n]\\(?:.*?[^ \t\n]\\)?\\)")
+         (regexp-quote org-babel-noweb-wrap-end)))
 
 (defvar org-babel-src-name-regexp
   "^[ \t]*#\\+name:[ \t]*"
@@ -416,7 +412,7 @@ then run `org-babel-switch-to-session'."
     (post       . :any)
     (prologue   . :any)
     (results   . ((file list vector table scalar verbatim)
-                  (raw html latex org code pp drawer)
+                  (raw html latex org code pp drawer link graphics)
                   (replace silent none append prepend)
                   (output value)))
     (rownames  . ((no yes)))
@@ -532,7 +528,7 @@ to raise errors for all languages.")
   "Hook for functions to be called after `org-babel-execute-src-block'")
 
 (defun org-babel-named-src-block-regexp-for-name (&optional name)
-  "Generate a regexp used to match a src block named NAME.
+  "Generate a regexp used to match a source block named NAME.
 If NAME is nil, match any name.  Matched name is then put in
 match group 9.  Other match groups are defined in
 `org-babel-src-block-regexp'."
@@ -566,7 +562,7 @@ Remove final newline character and spurious indentation."
 
 ;;; functions
 (defvar org-babel-current-src-block-location nil
-  "Marker pointing to the src block currently being executed.
+  "Marker pointing to the source block currently being executed.
 This may also point to a call line or an inline code block.  If
 multiple blocks are being executed (e.g., in chained execution
 through use of the :var header argument) this marker points to
@@ -577,9 +573,10 @@ the outer-most code block.")
 (defun org-babel-get-src-block-info (&optional light datum)
   "Extract information from a source block or inline source block.
 
-Optional argument LIGHT does not resolve remote variable
-references; a process which could likely result in the execution
-of other code blocks.
+When optional argument LIGHT is non-nil, Babel does not resolve
+remote variable references; a process which could likely result
+in the execution of other code blocks, and do not evaluate Lisp
+values in parameters.
 
 By default, consider the block at point.  However, when optional
 argument DATUM is provided, extract information from that parsed
@@ -610,8 +607,9 @@ a list with the following pattern:
                       ;; properties applicable to its location within
                       ;; the document.
                       (org-with-point-at (org-element-property :begin datum)
-                        (org-babel-params-from-properties lang))
-                      (mapcar #'org-babel-parse-header-arguments
+                        (org-babel-params-from-properties lang light))
+                      (mapcar (lambda (h)
+                                (org-babel-parse-header-arguments h light))
                               (cons (org-element-property :parameters datum)
                                     (org-element-property :header datum)))))
               (or (org-element-property :switches datum) "")
@@ -654,7 +652,7 @@ block."
       (let* ((params (nth 2 info))
             (cache (let ((c (cdr (assq :cache params))))
                      (and (not arg) c (string= "yes" c))))
-            (new-hash (and cache (org-babel-sha1-hash info)))
+            (new-hash (and cache (org-babel-sha1-hash info :eval)))
             (old-hash (and cache (org-babel-current-result-hash)))
             (current-cache (and new-hash (equal new-hash old-hash))))
        (cond
@@ -681,9 +679,16 @@ block."
                      (replace-regexp-in-string
                       (org-src-coderef-regexp coderef) "" expand nil nil 1))))
                 (dir (cdr (assq :dir params)))
+                (mkdirp (cdr (assq :mkdirp params)))
                 (default-directory
-                  (or (and dir (file-name-as-directory (expand-file-name dir)))
-                      default-directory))
+                  (cond
+                   ((not dir) default-directory)
+                   ((member mkdirp '("no" "nil" nil))
+                    (file-name-as-directory (expand-file-name dir)))
+                   (t
+                    (let ((d (file-name-as-directory (expand-file-name dir))))
+                      (make-directory d 'parents)
+                      d))))
                 (cmd (intern (concat "org-babel-execute:" lang)))
                 result)
            (unless (fboundp cmd)
@@ -703,13 +708,20 @@ block."
                               (not (listp r)))
                          (list (list r))
                        r)))
-             (let ((file (cdr (assq :file params))))
+             (let ((file (and (member "file" result-params)
+                              (cdr (assq :file params)))))
                ;; If non-empty result and :file then write to :file.
                (when file
-                 (when result
+                 ;; If `:results' are special types like `link' or
+                 ;; `graphics', don't write result to `:file'.  Only
+                 ;; insert a link to `:file'.
+                 (when (and result
+                            (not (or (member "link" result-params)
+                                     (member "graphics" result-params))))
                    (with-temp-file file
                      (insert (org-babel-format-result
-                              result (cdr (assq :sep params))))))
+                              result
+                              (cdr (assq :sep params))))))
                  (setq result file))
                ;; Possibly perform post process provided its
                ;; appropriate.  Dynamically bind "*this*" to the
@@ -1013,7 +1025,7 @@ evaluation mechanisms."
    (call-interactively
     (key-binding (or key (read-key-sequence nil))))))
 
-(defvar org-bracket-link-regexp)
+(defvar org-link-bracket-re)
 
 (defun org-babel-active-location-p ()
   (memq (org-element-type (save-match-data (org-element-context)))
@@ -1021,30 +1033,32 @@ evaluation mechanisms."
 
 ;;;###autoload
 (defun org-babel-open-src-block-result (&optional re-run)
-  "If `point' is on a src block then open the results of the
-source code block, otherwise return nil.  With optional prefix
-argument RE-RUN the source-code block is evaluated even if
-results already exist."
+  "Open results of source block at point.
+
+If `point' is on a source block then open the results of the source
+code block, otherwise return nil.  With optional prefix argument
+RE-RUN the source-code block is evaluated even if results already
+exist."
   (interactive "P")
-  (let ((info (org-babel-get-src-block-info 'light)))
-    (when info
-      (save-excursion
-       ;; go to the results, if there aren't any then run the block
-       (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result))
-                      (progn (org-babel-execute-src-block)
-                             (org-babel-where-is-src-block-result))))
-       (end-of-line 1)
-       (while (looking-at "[\n\r\t\f ]") (forward-char 1))
-       ;; open the results
-       (if (looking-at org-bracket-link-regexp)
-           ;; file results
-           (org-open-at-point)
-         (let ((r (org-babel-format-result
-                   (org-babel-read-result) (cdr (assq :sep (nth 2 info))))))
-           (pop-to-buffer (get-buffer-create "*Org-Babel Results*"))
-           (delete-region (point-min) (point-max))
-           (insert r)))
-       t))))
+  (pcase (org-babel-get-src-block-info 'light)
+    (`(,_ ,_ ,arguments ,_ ,_ ,start ,_)
+     (save-excursion
+       ;; Go to the results, if there aren't any then run the block.
+       (goto-char start)
+       (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result))
+                     (progn (org-babel-execute-src-block)
+                            (org-babel-where-is-src-block-result))))
+       (end-of-line)
+       (skip-chars-forward " \r\t\n")
+       ;; Open the results.
+       (if (looking-at org-link-bracket-re) (org-open-at-point)
+        (let ((r (org-babel-format-result (org-babel-read-result)
+                                          (cdr (assq :sep arguments)))))
+          (pop-to-buffer (get-buffer-create "*Org Babel Results*"))
+          (erase-buffer)
+          (insert r)))
+       t))
+    (_ nil)))
 
 ;;;###autoload
 (defmacro org-babel-map-src-blocks (file &rest body)
@@ -1224,11 +1238,14 @@ the current subtree."
       (widen))))
 
 ;;;###autoload
-(defun org-babel-sha1-hash (&optional info)
-  "Generate an sha1 hash based on the value of info."
+(defun org-babel-sha1-hash (&optional info context)
+  "Generate a sha1 hash based on the value of INFO.
+CONTEXT specifies the context of evaluation.  It can be `:eval',
+`:export', `:tangle'.  A nil value means `:eval'."
   (interactive)
   (let ((print-level nil)
-       (info (or info (org-babel-get-src-block-info))))
+       (info (or info (org-babel-get-src-block-info)))
+       (context (or context :eval)))
     (setf (nth 2 info)
          (sort (copy-sequence (nth 2 info))
                (lambda (a b) (string< (car a) (car b)))))
@@ -1256,8 +1273,9 @@ the current subtree."
           ;; expanded body
           (lang (nth 0 info))
           (params (nth 2 info))
-          (body (if (org-babel-noweb-p params :eval)
-                          (org-babel-expand-noweb-references info) (nth 1 
info)))
+          (body (if (org-babel-noweb-p params context)
+                    (org-babel-expand-noweb-references info)
+                  (nth 1 info)))
           (expand-cmd (intern (concat "org-babel-expand-body:" lang)))
           (assignments-cmd (intern (concat "org-babel-variable-assignments:"
                                            lang)))
@@ -1288,19 +1306,6 @@ the current subtree."
        (looking-at org-babel-result-regexp)
        (match-string-no-properties 1)))))
 
-(defun org-babel-set-current-result-hash (hash info)
-  "Set the current in-buffer hash to HASH."
-  (org-with-wide-buffer
-   (goto-char (org-babel-where-is-src-block-result nil info))
-   (looking-at org-babel-result-regexp)
-   (goto-char (match-beginning 1))
-   (mapc #'delete-overlay (overlays-at (point)))
-   (forward-char org-babel-hash-show)
-   (mapc #'delete-overlay (overlays-at (point)))
-   (replace-match hash nil nil nil 1)
-   (beginning-of-line)
-   (org-babel-hide-hash)))
-
 (defun org-babel-hide-hash ()
   "Hide the hash in the current results line.
 Only the initial `org-babel-hash-show' characters of the hash
@@ -1426,24 +1431,27 @@ portions of results lines."
          (lambda () (add-hook 'change-major-mode-hook
                          'org-babel-show-result-all 'append 'local)))
 
-(defvar org-file-properties)
-(defun org-babel-params-from-properties (&optional lang)
-  "Retrieve parameters specified as properties.
-Return a list of association lists of source block params
+(defun org-babel-params-from-properties (&optional lang no-eval)
+  "Retrieve source block parameters specified as properties.
+
+LANG is the language of the source block, as a string.  When
+optional argument NO-EVAL is non-nil, do not evaluate Lisp values
+in parameters.
+
+Return a list of association lists of source block parameters
 specified in the properties of the current outline entry."
   (save-match-data
     (list
-     ;; header arguments specified with the header-args property at
+     ;; Header arguments specified with the header-args property at
      ;; point of call.
      (org-babel-parse-header-arguments
-      (org-entry-get org-babel-current-src-block-location
-                    "header-args"
-                    'inherit))
-     (and lang  ; language-specific header arguments at point of call
+      (org-entry-get (point) "header-args" 'inherit)
+      no-eval)
+     ;; Language-specific header arguments at point of call.
+     (and lang
          (org-babel-parse-header-arguments
-          (org-entry-get org-babel-current-src-block-location
-                         (concat "header-args:" lang)
-                         'inherit))))))
+          (org-entry-get (point) (concat "header-args:" lang) 'inherit)
+          no-eval)))))
 
 (defun org-babel-balanced-split (string alts)
   "Split STRING on instances of ALTS.
@@ -1531,9 +1539,11 @@ balanced instances of \"[ \t]:\", set ALTS to ((32 9) . 
58)."
                       (cons el acc))))
                 list :initial-value nil))))
 
-(defun org-babel-parse-header-arguments (arg-string)
-  "Parse a string of header arguments returning an alist."
-  (when (> (length arg-string) 0)
+(defun org-babel-parse-header-arguments (string &optional no-eval)
+  "Parse header arguments in STRING.
+When optional argument NO-EVAL is non-nil, do not evaluate Lisp
+in parameters.  Return an alist."
+  (when (org-string-nw-p string)
     (org-babel-parse-multiple-vars
      (delq nil
           (mapcar
@@ -1542,10 +1552,12 @@ balanced instances of \"[ \t]:\", set ALTS to ((32 9) . 
58)."
                   "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
                   arg)
                  (cons (intern (match-string 1 arg))
-                       (org-babel-read (org-babel-chomp (match-string 2 arg))))
+                       (org-babel-read (org-babel-chomp (match-string 2 arg))
+                                       no-eval))
                (cons (intern (org-babel-chomp arg)) nil)))
-           (let ((raw (org-babel-balanced-split arg-string '((32 9) . 58))))
-              (cons (car raw) (mapcar (lambda (r) (concat ":" r)) (cdr 
raw)))))))))
+           (let ((raw (org-babel-balanced-split string '((32 9) . 58))))
+              (cons (car raw)
+                   (mapcar (lambda (r) (concat ":" r)) (cdr raw)))))))))
 
 (defun org-babel-parse-multiple-vars (header-arguments)
   "Expand multiple variable assignments behind a single :var keyword.
@@ -1845,7 +1857,7 @@ With optional prefix argument ARG, jump backward ARG many 
source blocks."
 
 ;;;###autoload
 (defun org-babel-mark-block ()
-  "Mark current src block."
+  "Mark current source block."
   (interactive)
   (let ((head (org-babel-where-is-src-block-head)))
     (when head
@@ -1876,7 +1888,7 @@ region is not active then the point is demarcated."
            (save-excursion
              (goto-char place)
              (let ((lang (nth 0 info))
-                   (indent (make-string (org-get-indentation) ?\s)))
+                   (indent (make-string (current-indentation) ?\s)))
               (when (string-match "^[[:space:]]*$"
                                   (buffer-substring (point-at-bol)
                                                     (point-at-eol)))
@@ -2083,7 +2095,7 @@ Return nil if ELEMENT cannot be read."
      (`paragraph
       ;; Treat paragraphs containing a single link specially.
       (skip-chars-forward " \t")
-      (if (and (looking-at org-bracket-link-regexp)
+      (if (and (looking-at org-link-bracket-re)
               (save-excursion
                 (goto-char (match-end 0))
                 (skip-chars-forward " \r\t\n")
@@ -2125,7 +2137,7 @@ Return nil if ELEMENT cannot be read."
 If the path of the link is a file path it is expanded using
 `expand-file-name'."
   (let* ((case-fold-search t)
-         (raw (and (looking-at org-bracket-link-regexp)
+         (raw (and (looking-at org-link-bracket-re)
                    (org-no-properties (match-string 1))))
          (type (and (string-match org-link-types-re raw)
                     (match-string 1 raw))))
@@ -2206,10 +2218,10 @@ code ---- the results are extracted in the syntax of 
the source
           optional LANG argument.
 
 list ---- the results are rendered as a list.  This option not
-          allowed for inline src blocks.
+          allowed for inline source blocks.
 
 table --- the results are rendered as a table.  This option not
-          allowed for inline src blocks.
+          allowed for inline source blocks.
 
 INFO may provide the values of these header arguments (in the
 `header-arguments-alist' see the docstring for
@@ -2273,7 +2285,7 @@ INFO may provide the values of these header arguments (in 
the
                  (goto-char (org-element-property :end inline))
                  (skip-chars-backward " \t"))
                (unless inline
-                 (setq indent (org-get-indentation))
+                 (setq indent (current-indentation))
                  (forward-line 1))
                (setq beg (point))
                (cond
@@ -2297,7 +2309,7 @@ INFO may provide the values of these header arguments (in 
the
                           (setq start inline-start)
                           (setq finish inline-finish)
                           (setq no-newlines t))
-                        (let ((before-finish (marker-position end)))
+                        (let ((before-finish (copy-marker end)))
                           (goto-char end)
                           (insert (concat finish (unless no-newlines "\n")))
                           (goto-char beg)
@@ -2362,24 +2374,24 @@ INFO may provide the values of these header arguments 
(in the
                  ;; possibly wrap result
                  (cond
                   ((assq :wrap (nth 2 info))
-                   (let ((name (or (cdr (assq :wrap (nth 2 info))) "RESULTS")))
-                     (funcall wrap (concat "#+BEGIN_" name)
-                              (concat "#+END_" (car (split-string name)))
+                   (let ((name (or (cdr (assq :wrap (nth 2 info))) "results")))
+                     (funcall wrap (concat "#+begin_" name)
+                              (concat "#+end_" (car (split-string name)))
                               nil nil (concat "{{{results(@@" name ":") 
"@@)}}}")))
                   ((member "html" result-params)
-                   (funcall wrap "#+BEGIN_EXPORT html" "#+END_EXPORT" nil nil
+                   (funcall wrap "#+begin_export html" "#+end_export" nil nil
                             "{{{results(@@html:" "@@)}}}"))
                   ((member "latex" result-params)
-                   (funcall wrap "#+BEGIN_EXPORT latex" "#+END_EXPORT" nil nil
+                   (funcall wrap "#+begin_export latex" "#+end_export" nil nil
                             "{{{results(@@latex:" "@@)}}}"))
                   ((member "org" result-params)
                    (goto-char beg) (when (org-at-table-p) (org-cycle))
-                   (funcall wrap "#+BEGIN_SRC org" "#+END_SRC" nil nil
+                   (funcall wrap "#+begin_src org" "#+end_src" nil nil
                             "{{{results(src_org{" "})}}}"))
                   ((member "code" result-params)
                    (let ((lang (or lang "none")))
-                     (funcall wrap (format "#+BEGIN_SRC %s%s" lang 
results-switches)
-                              "#+END_SRC" nil nil
+                     (funcall wrap (format "#+begin_src %s%s" lang 
results-switches)
+                              "#+end_src" nil nil
                               (format "{{{results(src_%s[%s]{" lang 
results-switches)
                               "})}}}")))
                   ((member "raw" result-params)
@@ -2388,7 +2400,7 @@ INFO may provide the values of these header arguments (in 
the
                        ;; Stay backward compatible with <7.9.2
                        (member "wrap" result-params))
                    (goto-char beg) (when (org-at-table-p) (org-cycle))
-                   (funcall wrap ":RESULTS:" ":END:" 'no-escape nil
+                   (funcall wrap ":results:" ":end:" 'no-escape nil
                             "{{{results(" ")}}}"))
                   ((and inline (member "file" result-params))
                    (funcall wrap nil nil nil nil "{{{results(" ")}}}"))
@@ -2469,7 +2481,7 @@ in the buffer."
 (defun org-babel-result-end ()
   "Return the point at the end of the current set of results."
   (cond ((looking-at-p "^[ \t]*$") (point)) ;no result
-       ((looking-at-p (format "^[ \t]*%s[ \t]*$" org-bracket-link-regexp))
+       ((looking-at-p (format "^[ \t]*%s[ \t]*$" org-link-bracket-re))
         (line-beginning-position 2))
        (t
         (let ((element (org-element-at-point)))
@@ -2489,15 +2501,20 @@ in the buffer."
 If the `default-directory' is different from the containing
 file's directory then expand relative links."
   (when (stringp result)
-    (format "[[file:%s]%s]"
-           (if (and default-directory
-                    buffer-file-name
-                    (not (string= (expand-file-name default-directory)
-                                  (expand-file-name
-                                   (file-name-directory buffer-file-name)))))
-               (expand-file-name result default-directory)
-             result)
-           (if description (concat "[" description "]") ""))))
+    (let ((same-directory?
+          (and buffer-file-name
+               (not (string= (expand-file-name default-directory)
+                             (expand-file-name
+                              (file-name-directory buffer-file-name)))))))
+      (format "[[file:%s]%s]"
+             (if (and default-directory buffer-file-name same-directory?)
+                 (if (eq org-link-file-path-type 'adaptive)
+                     (file-relative-name
+                      (expand-file-name result default-directory)
+                      (file-name-directory (buffer-file-name)))
+                   (expand-file-name result default-directory))
+               result)
+             (if description (concat "[" description "]") "")))))
 
 (defun org-babel-examplify-region (beg end &optional results-switches inline)
   "Comment out region using the inline `==' or `: ' org example quote."
@@ -2535,7 +2552,7 @@ file's directory then expand relative links."
     (unless (eq (org-element-type element) 'src-block)
       (error "Not in a source block"))
     (goto-char (org-babel-where-is-src-block-head element))
-    (let* ((ind (org-get-indentation))
+    (let* ((ind (current-indentation))
           (body-start (line-beginning-position 2))
           (body (org-element-normalize-string
                  (if (or org-src-preserve-indentation
@@ -2621,19 +2638,6 @@ parameters when merging lists."
                                  results
                                  (split-string
                                   (if (stringp value) value (eval value t))))))
-         (`(,(or :file :file-ext) . ,value)
-          ;; `:file' and `:file-ext' are regular keywords but they
-          ;; imply a "file" `:results' and a "results" `:exports'.
-          (when value
-            (setq results
-                  (funcall merge results-exclusive-groups results '("file")))
-            (unless (or (member "both" exports)
-                        (member "none" exports)
-                        (member "code" exports))
-              (setq exports
-                    (funcall merge
-                             exports-exclusive-groups exports '("results"))))
-            (push pair params)))
          (`(:exports . ,value)
           (setq exports (funcall merge
                                  exports-exclusive-groups
@@ -2662,12 +2666,6 @@ parameters when merging lists."
     ;; Return merged params.
     params))
 
-(defvar org-babel-use-quick-and-dirty-noweb-expansion nil
-  "Set to true to use regular expressions to expand noweb references.
-This results in much faster noweb reference expansion but does
-not properly allow code blocks to inherit the \":noweb-ref\"
-header argument from buffer or subtree wide properties.")
-
 (defun org-babel-noweb-p (params context)
   "Check if PARAMS require expansion in CONTEXT.
 CONTEXT may be one of :tangle, :export or :eval."
@@ -2714,16 +2712,8 @@ block but are passed literally to the \"example-block\"."
          (body (nth 1 info))
         (ob-nww-start org-babel-noweb-wrap-start)
         (ob-nww-end org-babel-noweb-wrap-end)
-        (comment (string= "noweb" (cdr (assq :comments (nth 2 info)))))
-        (rx-prefix (concat "\\(" org-babel-src-name-regexp "\\|"
-                           ":noweb-ref[ \t]+" "\\)"))
          (new-body "")
         (nb-add (lambda (text) (setq new-body (concat new-body text))))
-        (c-wrap (lambda (text)
-                  (with-temp-buffer
-                    (funcall (intern (concat lang "-mode")))
-                    (comment-region (point) (progn (insert text) (point)))
-                    (org-trim (buffer-string)))))
         index source-name evaluate prefix)
     (with-temp-buffer
       (setq-local org-babel-noweb-wrap-start ob-nww-start)
@@ -2755,63 +2745,77 @@ block but are passed literally to the 
\"example-block\"."
                    (let ((raw (org-babel-ref-resolve source-name)))
                      (if (stringp raw) raw (format "%S" raw)))
                  (or
-                  ;; Retrieve from the library of babel.
-                  (nth 2 (assoc (intern source-name)
-                                org-babel-library-of-babel))
+                  ;; Retrieve from the Library of Babel.
+                  (nth 2 (assoc-string source-name org-babel-library-of-babel))
                   ;; Return the contents of headlines literally.
                   (save-excursion
                     (when (org-babel-ref-goto-headline-id source-name)
-                             (org-babel-ref-headline-body)))
+                     (org-babel-ref-headline-body)))
                   ;; Find the expansion of reference in this buffer.
-                  (let ((rx (concat rx-prefix source-name "[ \t\n]"))
-                        expansion)
-                    (save-excursion
-                      (goto-char (point-min))
-                      (if org-babel-use-quick-and-dirty-noweb-expansion
-                          (while (re-search-forward rx nil t)
-                            (let* ((i (org-babel-get-src-block-info 'light))
-                                   (body (if (org-babel-noweb-p (nth 2 i) 
:eval)
-                                            (org-babel-expand-noweb-references 
i)
-                                          (nth 1 i)))
-                                   (sep (or (cdr (assq :noweb-sep (nth 2 i)))
-                                            "\n"))
-                                   (full (if comment
-                                             (let ((cs 
(org-babel-tangle-comment-links i)))
-                                              (concat (funcall c-wrap (car 
cs)) "\n"
-                                                      body "\n"
-                                                      (funcall c-wrap (cadr 
cs))))
-                                           body)))
-                              (setq expansion (cons sep (cons full 
expansion)))))
-                        (org-babel-map-src-blocks nil
-                         (let ((i (let ((org-babel-current-src-block-location 
(point)))
-                                    (org-babel-get-src-block-info 'light))))
-                            (when (equal (or (cdr (assq :noweb-ref (nth 2 i)))
-                                             (nth 4 i))
-                                         source-name)
-                              (let* ((body (if (org-babel-noweb-p (nth 2 i) 
:eval)
-                                              
(org-babel-expand-noweb-references i)
-                                            (nth 1 i)))
-                                     (sep (or (cdr (assq :noweb-sep (nth 2 i)))
-                                              "\n"))
-                                     (full (if comment
-                                               (let ((cs 
(org-babel-tangle-comment-links i)))
-                                                  (concat (funcall c-wrap (car 
cs)) "\n"
-                                                          body "\n"
-                                                          (funcall c-wrap 
(cadr cs))))
-                                             body)))
-                                (setq expansion
-                                      (cons sep (cons full expansion)))))))))
-                    (and expansion
-                         (mapconcat #'identity (nreverse (cdr expansion)) "")))
+                  (save-excursion
+                   (goto-char (point-min))
+                   (let* ((name-regexp
+                           (org-babel-named-src-block-regexp-for-name
+                            source-name))
+                          (comment
+                           (string= "noweb"
+                                    (cdr (assq :comments (nth 2 info)))))
+                          (c-wrap
+                           (lambda (s)
+                             ;; Comment, according to LANG mode,
+                             ;; string S.  Return new string.
+                             (with-temp-buffer
+                               (funcall (org-src-get-lang-mode lang))
+                               (comment-region (point)
+                                               (progn (insert s) (point)))
+                               (org-trim (buffer-string)))))
+                          (expand-body
+                           (lambda (i)
+                             ;; Expand body of code blocked
+                             ;; represented by block info I.
+                             (let ((b (if (org-babel-noweb-p (nth 2 i) :eval)
+                                          (org-babel-expand-noweb-references i)
+                                        (nth 1 i))))
+                               (if (not comment) b
+                                 (let ((cs (org-babel-tangle-comment-links i)))
+                                   (concat (funcall c-wrap (car cs)) "\n"
+                                           b "\n"
+                                           (funcall c-wrap (cadr cs)))))))))
+                     (if (and (re-search-forward name-regexp nil t)
+                              (not (org-in-commented-heading-p)))
+                         ;; Found a source block named SOURCE-NAME.
+                         ;; Assume it is unique; do not look after
+                         ;; `:noweb-ref' header argument.
+                         (funcall expand-body
+                                  (org-babel-get-src-block-info 'light))
+                       ;; Though luck.  We go into the long process
+                       ;; of checking each source block and expand
+                       ;; those with a matching Noweb reference.
+                       (let ((expansion nil))
+                         (org-babel-map-src-blocks nil
+                           (unless (org-in-commented-heading-p)
+                             (let* ((info
+                                     (org-babel-get-src-block-info 'light))
+                                    (parameters (nth 2 info)))
+                               (when (equal source-name
+                                            (cdr (assq :noweb-ref parameters)))
+                                 (push (funcall expand-body info) expansion)
+                                 (push (or (cdr (assq :noweb-sep parameters))
+                                           "\n")
+                                       expansion)))))
+                         (when expansion
+                           (mapconcat #'identity
+                                      (nreverse (cdr expansion))
+                                      ""))))))
                   ;; Possibly raise an error if named block doesn't exist.
                   (if (or org-babel-noweb-error-all-langs
                          (member lang org-babel-noweb-error-langs))
-                      (error "%s" (concat
-                                   (org-babel-noweb-wrap source-name)
-                                   "could not be resolved (see "
-                                   "`org-babel-noweb-error-langs')"))
+                     (error "%s could not be resolved (see \
+`org-babel-noweb-error-langs')"
+                            (org-babel-noweb-wrap source-name))
                     "")))
-               "[\n\r]") (concat "\n" prefix))))))
+               "[\n\r]")
+             (concat "\n" prefix))))))
       (funcall nb-add (buffer-substring index (point-max))))
     new-body))
 
@@ -2927,30 +2931,30 @@ situations in which is it not appropriate."
 (defun org-babel--string-to-number (string)
   "If STRING represents a number return its value.
 Otherwise return nil."
-  (and (string-match-p "\\`-?[0-9]*\\.?[0-9]*\\'" string)
+  (and (string-match-p "\\`-?\\([0-9]\\|\\([1-9]\\|[0-9]*\\.\\)[0-9]*\\)\\'" 
string)
        (string-to-number string)))
 
 (defun org-babel-import-elisp-from-file (file-name &optional separator)
   "Read the results located at FILE-NAME into an elisp table.
 If the table is trivial, then return it as a scalar."
-  (let (result)
-    (save-window-excursion
-      (with-temp-buffer
-       (condition-case err
-           (progn
-             (org-table-import file-name separator)
-             (delete-file file-name)
-             (setq result (mapcar (lambda (row)
-                                    (mapcar #'org-babel-string-read row))
-                                  (org-table-to-lisp))))
-         (error (message "Error reading results: %s" err) nil)))
-      (if (null (cdr result)) ;; if result is trivial vector, then scalarize it
-         (if (consp (car result))
-             (if (null (cdr (car result)))
-                 (caar result)
-               result)
-           (car result))
-       result))))
+  (save-window-excursion
+    (let ((result
+          (with-temp-buffer
+            (condition-case err
+                (progn
+                  (org-table-import file-name separator)
+                  (delete-file file-name)
+                  (delq nil
+                        (mapcar (lambda (row)
+                                  (and (not (eq row 'hline))
+                                       (mapcar #'org-babel-string-read row)))
+                                (org-table-to-lisp))))
+              (error (message "Error reading results: %s" err) nil)))))
+      (pcase result
+       (`((,scalar)) scalar)
+       (`((,_ ,_ . ,_)) result)
+       (`(,scalar) scalar)
+       (_ result)))))
 
 (defun org-babel-string-read (cell)
   "Strip nested \"s from around strings."
@@ -3136,7 +3140,8 @@ after the babel API for OLD-type source blocks is fully 
defined.
 Callers of this function will probably want to add an entry to
 `org-src-lang-modes' as well."
   (dolist (fn '("execute" "expand-body" "prep-session"
-               "variable-assignments" "load-session"))
+               "variable-assignments" "load-session"
+               "edit-prep"))
     (let ((sym (intern-soft (concat "org-babel-" fn ":" old))))
       (when (and sym (fboundp sym))
        (defalias (intern (concat "org-babel-" fn ":" new)) sym))))
@@ -3147,10 +3152,6 @@ Callers of this function will probably want to add an 
entry to
       (when (and sym (boundp sym))
        (defvaralias (intern (concat "org-babel-" var ":" new)) sym)))))
 
-(defun org-babel-strip-quotes (string)
-  "Strip \\\"s from around a string, if applicable."
-  (org-unbracket-string "\"" "\"" string))
-
 (provide 'ob-core)
 
 ;; Local variables:
diff --git a/lisp/org/ob-dot.el b/lisp/org/ob-dot.el
index 35bc893..73a1673 100644
--- a/lisp/org/ob-dot.el
+++ b/lisp/org/ob-dot.el
@@ -69,6 +69,8 @@ This function is called by `org-babel-execute-src-block'."
         (cmdline (or (cdr (assq :cmdline params))
                      (format "-T%s" (file-name-extension out-file))))
         (cmd (or (cdr (assq :cmd params)) "dot"))
+        (coding-system-for-read 'utf-8) ;use utf-8 with sub-processes
+        (coding-system-for-write 'utf-8)
         (in-file (org-babel-temp-file "dot-")))
     (with-temp-file in-file
       (insert (org-babel-expand-body:dot body params)))
diff --git a/lisp/org/ob-emacs-lisp.el b/lisp/org/ob-emacs-lisp.el
index c9f6c49..18b0d48 100644
--- a/lisp/org/ob-emacs-lisp.el
+++ b/lisp/org/ob-emacs-lisp.el
@@ -26,7 +26,13 @@
 ;; Org-Babel support for evaluating emacs-lisp code
 
 ;;; Code:
-(require 'ob)
+
+(require 'ob-core)
+
+(declare-function org-babel--get-vars "ob" (params))
+(declare-function org-babel-result-cond "ob" (result-params scalar-form &rest 
table-forms))
+(declare-function org-babel-reassemble-table "ob" (table colnames rownames))
+(declare-function org-babel-pick-name "ob" (names selector))
 
 (defconst org-babel-header-args:emacs-lisp '((lexical . :any))
   "Emacs-lisp specific header arguments.")
@@ -34,10 +40,11 @@
 (defvar org-babel-default-header-args:emacs-lisp '((:lexical . "no"))
   "Default arguments for evaluating an emacs-lisp source block.
 
-A value of \"yes\" or t causes src blocks to be eval'd using
+A value of \"yes\" or t causes source blocks to be eval'd using
 lexical scoping.  It can also be an alist mapping symbols to
-their value.  It is used as the optional LEXICAL argument to
-`eval', which see.")
+their value.  It is used both as the optional LEXICAL argument to
+`eval', and as the value for `lexical-binding' in buffers created
+by `org-edit-src-code'.")
 
 (defun org-babel-expand-body:emacs-lisp (body params)
   "Expand BODY according to PARAMS, return the expanded body."
@@ -65,9 +72,7 @@ their value.  It is used as the optional LEXICAL argument to
                                       (member "pp" result-params))
                                   (concat "(pp " body ")")
                                 body))
-                        (if (listp lexical)
-                            lexical
-                          (member lexical '("yes" "t"))))))
+                        (org-babel-emacs-lisp-lexical lexical))))
       (org-babel-result-cond result-params
        (let ((print-level nil)
               (print-length nil))
@@ -82,6 +87,23 @@ their value.  It is used as the optional LEXICAL argument to
          (org-babel-pick-name (cdr (assq :rowname-names params))
                               (cdr (assq :rownames params))))))))
 
+(defun org-babel-emacs-lisp-lexical (lexical)
+  "Interpret :lexical source block argument.
+Convert LEXICAL into the form appropriate for `lexical-binding'
+and the LEXICAL argument to `eval'."
+  (if (listp lexical)
+      lexical
+    (not (null (member lexical '("yes" "t"))))))
+
+(defun org-babel-edit-prep:emacs-lisp (info)
+  "Set `lexical-binding' in Org edit buffer.
+Set `lexical-binding' in Org edit buffer according to the
+corresponding :lexical source block argument."
+  (setq lexical-binding
+        (org-babel-emacs-lisp-lexical
+         (org-babel-read
+          (cdr (assq :lexical (nth 2 info)))))))
+
 (org-babel-make-language-alias "elisp" "emacs-lisp")
 
 (provide 'ob-emacs-lisp)
diff --git a/lisp/org/ob-eshell.el b/lisp/org/ob-eshell.el
new file mode 100644
index 0000000..800abce
--- /dev/null
+++ b/lisp/org/ob-eshell.el
@@ -0,0 +1,102 @@
+;;; ob-eshell.el --- Babel Functions for Eshell      -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+
+;; Author: stardiviner <address@hidden>
+;; Keywords: literate programming, reproducible research
+;; Homepage: https://orgmode.org
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Org Babel support for evaluating Eshell source code.
+
+;;; Code:
+(require 'ob)
+(require 'eshell)
+
+(defvar org-babel-default-header-args:eshell '())
+
+(defun org-babel-execute:eshell (body params)
+  "Execute a block of Eshell code BODY with PARAMS.
+This function is called by `org-babel-execute-src-block'.
+
+The BODY can be any code which allowed executed in Eshell.
+Eshell allow to execute normal shell command and Elisp code.
+More details please reference Eshell Info.
+
+The PARAMS are variables assignments."
+  (let* ((session (org-babel-eshell-initiate-session
+                  (cdr (assq :session params))))
+        (full-body (org-babel-expand-body:generic
+                    body params (org-babel-variable-assignments:eshell 
params))))
+    (if session
+       (progn
+         (with-current-buffer session
+           (dolist (line (split-string full-body "\n"))
+             (goto-char eshell-last-output-end)
+             (insert line)
+             (eshell-send-input))
+           ;; get output of last input
+           ;; TODO: collect all output instead of last command's output.
+           (goto-char eshell-last-input-end)
+           (buffer-substring-no-properties (point) eshell-last-output-start)))
+      (with-temp-buffer
+       (eshell-command full-body t)
+       (buffer-string)))))
+
+(defun org-babel-prep-session:eshell (session params)
+  "Prepare SESSION according to the header arguments specified in PARAMS."
+  (let* ((session (org-babel-eshell-initiate-session session))
+        ;; Eshell session buffer is read from variable `eshell-buffer-name'.
+        (eshell-buffer-name session)
+        (var-lines (org-babel-variable-assignments:eshell params)))
+    (call-interactively #'eshell)
+    (mapc #'eshell-command var-lines)
+    session))
+
+(defun ob-eshell-session-live-p (session)
+  "Non-nil if Eshell SESSION exists."
+  (get-buffer session))
+
+(defun org-babel-eshell-initiate-session (&optional session _params)
+  "Initiate a session named SESSION."
+  (when (and session (not (string= session "none")))
+    (save-window-excursion
+      (unless (ob-eshell-session-live-p session)
+       (let ((eshell-buffer-name session)) (eshell))))
+    session))
+
+(defun org-babel-variable-assignments:eshell (params)
+  "Convert ob-eshell :var specified variables into Eshell variables 
assignments."
+  (mapcar
+   (lambda (pair)
+     (format "(setq %s %S)" (car pair) (cdr pair)))
+   (org-babel--get-vars params)))
+
+(defun org-babel-load-session:eshell (session body params)
+  "Load BODY into SESSION with PARAMS."
+  (save-window-excursion
+    (let ((buffer (org-babel-prep-session:eshell session params)))
+      (with-current-buffer buffer
+       (goto-char (point-max))
+       (insert (org-babel-chomp body)))
+      buffer)))
+
+(provide 'ob-eshell)
+
+;;; ob-eshell.el ends here
diff --git a/lisp/org/ob-exp.el b/lisp/org/ob-exp.el
index 4a5bff8..c06e262 100644
--- a/lisp/org/ob-exp.el
+++ b/lisp/org/ob-exp.el
@@ -32,8 +32,6 @@
 (declare-function org-element-type "org-element" (element))
 (declare-function org-escape-code-in-string "org-src" (s))
 (declare-function org-export-copy-buffer "ox" ())
-(declare-function org-fill-template "org" (template alist))
-(declare-function org-get-indentation "org" (&optional line))
 (declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
 
 (defvar org-src-preserve-indentation)
@@ -85,7 +83,7 @@ none ---- do not display either code or results upon export
 Assume point is at block opening line."
   (interactive)
   (save-excursion
-    (let* ((info (org-babel-get-src-block-info 'light))
+    (let* ((info (org-babel-get-src-block-info))
           (lang (nth 0 info))
           (raw-params (nth 2 info))
           hash)
@@ -108,7 +106,7 @@ Assume point is at block opening line."
                                   (symbol-value lang-headers))
                              (append (org-babel-params-from-properties lang)
                                      (list raw-params)))))))
-         (setf hash (org-babel-sha1-hash info)))
+         (setf hash (org-babel-sha1-hash info :export)))
        (org-babel-exp-do-export info 'block hash)))))
 
 (defcustom org-babel-exp-call-line-template
@@ -210,9 +208,9 @@ this template."
                                              (progn (goto-char end)
                                                     (skip-chars-forward " \t")
                                                     (point)))
-                            ;; Otherwise: remove inline src block but
-                            ;; preserve following white spaces.  Then
-                            ;; insert value.
+                            ;; Otherwise: remove inline source block
+                            ;; but preserve following white spaces.
+                            ;; Then insert value.
                             (delete-region begin end)
                             (insert replacement)))))
                      ((or `babel-call `inline-babel-call)
@@ -244,7 +242,7 @@ this template."
                           (insert rep))))
                      (`src-block
                       (let ((match-start (copy-marker (match-beginning 0)))
-                            (ind (org-get-indentation)))
+                            (ind (current-indentation)))
                         ;; Take care of matched block: compute
                         ;; replacement string.  In particular, a nil
                         ;; REPLACEMENT means the block is left as-is
diff --git a/lisp/org/ob-forth.el b/lisp/org/ob-forth.el
index de42042..5d4fe30 100644
--- a/lisp/org/ob-forth.el
+++ b/lisp/org/ob-forth.el
@@ -33,9 +33,9 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
 (declare-function forth-proc "ext:gforth" ())
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-default-header-args:forth '((:session . "yes"))
   "Default header arguments for forth code blocks.")
diff --git a/lisp/org/ob-fortran.el b/lisp/org/ob-fortran.el
index 976c611..1431eb4 100644
--- a/lisp/org/ob-fortran.el
+++ b/lisp/org/ob-fortran.el
@@ -28,13 +28,12 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 (require 'cc-mode)
 (require 'cl-lib)
 
 (declare-function org-entry-get "org"
                  (pom property &optional inherit literal-nil))
-(declare-function org-remove-indentation "org" (code &optional n))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("fortran" . "F90"))
@@ -109,7 +108,7 @@ its header arguments."
   "Wrap body in a \"program ... end program\" block if none exists."
   (if (string-match "^[ \t]*program[ \t]*.*" (capitalize body))
       (let ((vars (org-babel--get-vars params)))
-       (if vars (error "Cannot use :vars if `program' statement is present"))
+       (when vars (error "Cannot use :vars if `program' statement is present"))
        body)
     (format "program main\n%s\nend program main\n" body)))
 
diff --git a/lisp/org/ob-gnuplot.el b/lisp/org/ob-gnuplot.el
index 5ff6756..cc4c3cb 100644
--- a/lisp/org/ob-gnuplot.el
+++ b/lisp/org/ob-gnuplot.el
@@ -39,9 +39,9 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
 (declare-function org-time-string-to-time "org" (s))
-(declare-function org-combine-plists "org" (&rest plists))
 (declare-function orgtbl-to-generic "org-table" (table params))
 (declare-function gnuplot-mode "ext:gnuplot-mode" ())
 (declare-function gnuplot-send-string-to-gnuplot "ext:gnuplot-mode" (str txt))
diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el
index 50d1b57..a683b11 100644
--- a/lisp/org/ob-haskell.el
+++ b/lisp/org/ob-haskell.el
@@ -40,10 +40,9 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 (require 'comint)
 
-(declare-function org-remove-indentation "org" (code &optional n))
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function haskell-mode "ext:haskell-mode" ())
 (declare-function run-haskell "ext:inf-haskell" (&optional arg))
 (declare-function inferior-haskell-load-file
@@ -75,17 +74,16 @@
                     (org-babel-variable-assignments:haskell params)))
          (session (org-babel-haskell-initiate-session session params))
         (comint-preoutput-filter-functions
-              (cons 'ansi-color-filter-apply 
comint-preoutput-filter-functions))
+         (cons 'ansi-color-filter-apply comint-preoutput-filter-functions))
          (raw (org-babel-comint-with-output
                  (session org-babel-haskell-eoe t full-body)
                 (insert (org-trim full-body))
                 (comint-send-input nil t)
                 (insert org-babel-haskell-eoe)
                 (comint-send-input nil t)))
-         (results (mapcar
-                   #'org-babel-strip-quotes
-                   (cdr (member org-babel-haskell-eoe
-                                (reverse (mapcar #'org-trim raw)))))))
+         (results (mapcar #'org-strip-quotes
+                         (cdr (member org-babel-haskell-eoe
+                                       (reverse (mapcar #'org-trim raw)))))))
     (org-babel-reassemble-table
      (let ((result
             (pcase result-type
diff --git a/lisp/org/ob-js.el b/lisp/org/ob-js.el
index dab3aa2..dd53ef6 100644
--- a/lisp/org/ob-js.el
+++ b/lisp/org/ob-js.el
@@ -41,6 +41,11 @@
 (require 'ob)
 
 (declare-function run-mozilla "ext:moz" (arg))
+(declare-function httpd-start "ext:simple-httpd" ())
+(declare-function run-skewer "ext:skewer-mode" ())
+(declare-function skewer-repl "ext:skewer-repl" ())
+(declare-function indium-run-node "ext:indium-nodejs" (command))
+(declare-function indium-eval "ext:indium-interaction" (string &optional 
callback))
 
 (defvar org-babel-default-header-args:js '()
   "Default header arguments for js code blocks.")
@@ -52,7 +57,12 @@
   "Name of command used to evaluate js blocks."
   :group 'org-babel
   :version "24.1"
-  :type 'string)
+  :type '(choice (const "node")
+                (const "mozrepl")
+                (const "skewer-mode")
+                (const "indium")
+                (const "js-comint"))
+  :safe #'stringp)
 
 (defvar org-babel-js-function-wrapper
   "require('sys').print(require('sys').inspect(function(){\n%s\n}()));"
@@ -62,22 +72,13 @@
   "Execute a block of Javascript code with org-babel.
 This function is called by `org-babel-execute-src-block'."
   (let* ((org-babel-js-cmd (or (cdr (assq :cmd params)) org-babel-js-cmd))
+        (session (cdr (assq :session params)))
          (result-type (cdr (assq :result-type params)))
          (full-body (org-babel-expand-body:generic
                     body params (org-babel-variable-assignments:js params)))
-        (result (if (not (string= (cdr (assq :session params)) "none"))
-                    ;; session evaluation
-                    (let ((session (org-babel-prep-session:js
-                                    (cdr (assq :session params)) params)))
-                      (nth 1
-                           (org-babel-comint-with-output
-                               (session (format "%S" org-babel-js-eoe) t body)
-                             (mapc
-                              (lambda (line)
-                                (insert (org-babel-chomp line))
-                                (comint-send-input nil t))
-                              (list body (format "%S" org-babel-js-eoe))))))
-                  ;; external evaluation
+        (result (cond
+                 ;; no session specified, external evaluation
+                 ((string= session "none")
                   (let ((script-file (org-babel-temp-file "js-script-")))
                     (with-temp-file script-file
                       (insert
@@ -87,7 +88,24 @@ This function is called by `org-babel-execute-src-block'."
                          full-body)))
                     (org-babel-eval
                      (format "%s %s" org-babel-js-cmd
-                             (org-babel-process-file-name script-file)) "")))))
+                             (org-babel-process-file-name script-file)) "")))
+                 ;; Indium Node REPL.  Separate case because Indium
+                 ;; REPL is not inherited from Comint mode.
+                 ((string= session "*JS REPL*")
+                  (require 'indium-repl)
+                  (unless (get-buffer session)
+                    (indium-run-node org-babel-js-cmd))
+                  (indium-eval full-body))
+                 ;; session evaluation
+                 (t
+                  (let ((session (org-babel-prep-session:js
+                                  (cdr (assq :session params)) params)))
+                    (nth 1
+                         (org-babel-comint-with-output
+                             (session (format "%S" org-babel-js-eoe) t body)
+                           (dolist (code (list body (format "%S" 
org-babel-js-eoe)))
+                             (insert (org-babel-chomp code))
+                             (comint-send-input nil t)))))))))
     (org-babel-result-cond (cdr (assq :result-params params))
       result (org-babel-js-read result))))
 
@@ -123,11 +141,13 @@ specifying a variable of the same value."
         (var-lines (org-babel-variable-assignments:js params)))
     (when session
       (org-babel-comint-in-buffer session
-       (sit-for .5) (goto-char (point-max))
-       (mapc (lambda (var)
-               (insert var) (comint-send-input nil t)
-               (org-babel-comint-wait-for-output session)
-               (sit-for .1) (goto-char (point-max))) var-lines)))
+       (goto-char (point-max))
+       (dolist (var var-lines)
+         (insert var)
+         (comint-send-input nil t)
+         (org-babel-comint-wait-for-output session)
+         (sit-for .1)
+         (goto-char (point-max)))))
     session))
 
 (defun org-babel-variable-assignments:js (params)
@@ -137,25 +157,47 @@ specifying a variable of the same value."
                          (car pair) (org-babel-js-var-to-js (cdr pair))))
    (org-babel--get-vars params)))
 
-(defun org-babel-js-initiate-session (&optional session)
-  "If there is not a current inferior-process-buffer in SESSION
+(defun org-babel-js-initiate-session (&optional session _params)
+  "If there is not a current inferior-process-buffer in `SESSION'
 then create.  Return the initialized session."
-  (unless (string= session "none")
-    (cond
-     ((string= "mozrepl" org-babel-js-cmd)
-      (require 'moz)
-      (let ((session-buffer (save-window-excursion
-                             (run-mozilla nil)
-                             (rename-buffer session)
-                             (current-buffer))))
-       (if (org-babel-comint-buffer-livep session-buffer)
-           (progn (sit-for .25) session-buffer)
-         (sit-for .5)
-         (org-babel-js-initiate-session session))))
-     ((string= "node" org-babel-js-cmd )
-      (error "Session evaluation with node.js is not supported"))
-     (t
-      (error "Sessions are only supported with mozrepl add \":cmd 
mozrepl\"")))))
+  (cond
+   ((string= session "none")
+    (warn "Session evaluation of ob-js is not supported"))
+   ((string= "*skewer-repl*" session)
+    (require 'skewer-repl)
+    (let ((session-buffer (get-buffer "*skewer-repl*")))
+      (if (and session-buffer
+              (org-babel-comint-buffer-livep (get-buffer session-buffer))
+              (comint-check-proc session-buffer))
+         session-buffer
+       ;; start skewer REPL.
+       (httpd-start)
+       (run-skewer)
+       (skewer-repl)
+       session-buffer)))
+   ((string= "*Javascript REPL*" session)
+    (require 'js-comint)
+    (let ((session-buffer "*Javascript REPL*"))
+      (if (and (org-babel-comint-buffer-livep (get-buffer session-buffer))
+              (comint-check-proc session-buffer))
+         session-buffer
+       (call-interactively 'run-js)
+       (sit-for .5)
+       session-buffer)))
+   ((string= "mozrepl" org-babel-js-cmd)
+    (require 'moz)
+    (let ((session-buffer (save-window-excursion
+                           (run-mozilla nil)
+                           (rename-buffer session)
+                           (current-buffer))))
+      (if (org-babel-comint-buffer-livep session-buffer)
+         (progn (sit-for .25) session-buffer)
+       (sit-for .5)
+       (org-babel-js-initiate-session session))))
+   ((string= "node" org-babel-js-cmd )
+    (error "Session evaluation with node.js is not supported"))
+   (t
+    (error "Sessions are only supported with mozrepl add \":cmd mozrepl\""))))
 
 (provide 'ob-js)
 
diff --git a/lisp/org/ob-keys.el b/lisp/org/ob-keys.el
deleted file mode 100644
index 627648d..0000000
--- a/lisp/org/ob-keys.el
+++ /dev/null
@@ -1,106 +0,0 @@
-;;; ob-keys.el --- Key Bindings for Babel            -*- lexical-binding: t; 
-*-
-
-;; Copyright (C) 2009-2019 Free Software Foundation, Inc.
-
-;; Author: Eric Schulte
-;; Keywords: literate programming, reproducible research
-;; Homepage: https://orgmode.org
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Add Org Babel keybindings to the Org mode keymap for exposing
-;; Org Babel functions.  These will all share a common prefix.  See
-;; the value of `org-babel-key-bindings' for a list of interactive
-;; functions and their associated keys.
-
-;;; Code:
-(require 'ob-core)
-
-(defvar org-babel-key-prefix "\C-c\C-v"
-  "The key prefix for Babel interactive key-bindings.
-See `org-babel-key-bindings' for the list of interactive babel
-functions which are assigned key bindings, and see
-`org-babel-map' for the actual babel keymap.")
-
-(defvar org-babel-map (make-sparse-keymap)
-  "The keymap for interactive Babel functions.")
-
-;;;###autoload
-(defun org-babel-describe-bindings ()
-  "Describe all keybindings behind `org-babel-key-prefix'."
-  (interactive)
-  (describe-bindings org-babel-key-prefix))
-
-(defvar org-babel-key-bindings
-  '(("p" . org-babel-previous-src-block)
-    ("\C-p" . org-babel-previous-src-block)
-    ("n" . org-babel-next-src-block)
-    ("\C-n" . org-babel-next-src-block)
-    ("e" . org-babel-execute-maybe)
-    ("\C-e" . org-babel-execute-maybe)
-    ("o" . org-babel-open-src-block-result)
-    ("\C-o" . org-babel-open-src-block-result)
-    ("\C-v" . org-babel-expand-src-block)
-    ("v" . org-babel-expand-src-block)
-    ("u" . org-babel-goto-src-block-head)
-    ("\C-u" . org-babel-goto-src-block-head)
-    ("g" . org-babel-goto-named-src-block)
-    ("r" . org-babel-goto-named-result)
-    ("\C-r" . org-babel-goto-named-result)
-    ("\C-b" . org-babel-execute-buffer)
-    ("b" . org-babel-execute-buffer)
-    ("\C-s" . org-babel-execute-subtree)
-    ("s" . org-babel-execute-subtree)
-    ("\C-d" . org-babel-demarcate-block)
-    ("d" . org-babel-demarcate-block)
-    ("\C-t" . org-babel-tangle)
-    ("t" . org-babel-tangle)
-    ("\C-f" . org-babel-tangle-file)
-    ("f" . org-babel-tangle-file)
-    ("\C-c" . org-babel-check-src-block)
-    ("c" . org-babel-check-src-block)
-    ("\C-j" . org-babel-insert-header-arg)
-    ("j" . org-babel-insert-header-arg)
-    ("\C-l" . org-babel-load-in-session)
-    ("l" . org-babel-load-in-session)
-    ("\C-i" . org-babel-lob-ingest)
-    ("i" . org-babel-lob-ingest)
-    ("\C-I" . org-babel-view-src-block-info)
-    ("I" . org-babel-view-src-block-info)
-    ("\C-z" . org-babel-switch-to-session)
-    ("z" . org-babel-switch-to-session-with-code)
-    ("\C-a" . org-babel-sha1-hash)
-    ("a" . org-babel-sha1-hash)
-    ("h" . org-babel-describe-bindings)
-    ("\C-x" . org-babel-do-key-sequence-in-edit-buffer)
-    ("x" . org-babel-do-key-sequence-in-edit-buffer)
-    ("k" . org-babel-remove-result-one-or-many)
-    ("\C-\M-h" . org-babel-mark-block))
-  "Alist of key bindings and interactive Babel functions.
-This list associates interactive Babel functions
-with keys.  Each element of this list will add an entry to the
-`org-babel-map' using the letter key which is the `car' of the
-a-list placed behind the generic `org-babel-key-prefix'.")
-
-(provide 'ob-keys)
-
-;; Local variables:
-;; generated-autoload-file: "org-loaddefs.el"
-;; End:
-
-;;; ob-keys.el ends here
diff --git a/lisp/org/ob-latex.el b/lisp/org/ob-latex.el
index 219b11c..adf83d4 100644
--- a/lisp/org/ob-latex.el
+++ b/lisp/org/ob-latex.el
@@ -31,12 +31,12 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
 (declare-function org-create-formula-image "org" (string tofile options buffer 
&optional type))
 (declare-function org-latex-compile "ox-latex" (texfile &optional snippet))
 (declare-function org-latex-guess-inputenc "ox-latex" (header))
 (declare-function org-splice-latex-header "org" (tpl def-pkg pkg snippets-p 
&optional extra))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))
diff --git a/lisp/org/ob-lilypond.el b/lisp/org/ob-lilypond.el
index c07ae78..4538ed5 100644
--- a/lisp/org/ob-lilypond.el
+++ b/lisp/org/ob-lilypond.el
@@ -33,7 +33,9 @@
 
 ;;; Code:
 (require 'ob)
-(require 'outline)
+
+(declare-function org-show-all "org" (&optional types))
+
 (defalias 'lilypond-mode 'LilyPond-mode)
 
 (add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
@@ -264,7 +266,7 @@ LINE is the erroneous line."
     (setq case-fold-search nil)
     (if (search-forward line nil t)
         (progn
-          (outline-show-all)
+          (org-show-all)
           (set-mark (point))
           (goto-char (- (point) (length line))))
       (goto-char temp))))
diff --git a/lisp/org/ob-lisp.el b/lisp/org/ob-lisp.el
index 6fef0da..398ed21 100644
--- a/lisp/org/ob-lisp.el
+++ b/lisp/org/ob-lisp.el
@@ -37,10 +37,10 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
 (declare-function sly-eval "ext:sly" (sexp &optional package))
 (declare-function slime-eval "ext:slime" (sexp &optional package))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("lisp" . "lisp"))
@@ -107,7 +107,7 @@ a property list containing the parameters of the block."
                                      (point-min) (point-max)))))
                               (cdr (assq :package params)))))))
      (org-babel-result-cond (cdr (assq :result-params params))
-       result
+       (org-strip-quotes result)
        (condition-case nil
            (read (org-babel-lisp-vector-to-list result))
          (error result))))
diff --git a/lisp/org/ob-lob.el b/lisp/org/ob-lob.el
index 4197f2d..a6194c4 100644
--- a/lisp/org/ob-lob.el
+++ b/lisp/org/ob-lob.el
@@ -62,7 +62,7 @@ should not be inherited from a source block.")
                  (cons (cons source info)
                        (assq-delete-all source org-babel-library-of-babel))))
          (cl-incf lob-ingest-count))))
-    (message "%d src block%s added to Library of Babel"
+    (message "%d source block%s added to Library of Babel"
             lob-ingest-count (if (> lob-ingest-count 1) "s" ""))
     lob-ingest-count))
 
@@ -138,9 +138,8 @@ see."
                        header
                        org-babel-default-lob-header-args
                        (append
-                        (org-with-wide-buffer
-                         (goto-char begin)
-                         (org-babel-params-from-properties language))
+                        (org-with-point-at begin
+                          (org-babel-params-from-properties language))
                         (list
                          (org-babel-parse-header-arguments
                           (org-element-property :inside-header context))
diff --git a/lisp/org/ob-lua.el b/lisp/org/ob-lua.el
index 8712619..530376a 100644
--- a/lisp/org/ob-lua.el
+++ b/lisp/org/ob-lua.el
@@ -34,10 +34,9 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 (require 'cl-lib)
 
-(declare-function org-remove-indentation "org" (code &optional n))
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function lua-shell "ext:lua-mode" (&optional argprompt))
 (declare-function lua-toggle-shells "ext:lua-mode" (arg))
 (declare-function run-lua "ext:lua" (cmd &optional dedicated show))
@@ -149,7 +148,7 @@ specifying a variable of the same value."
     (if (eq var 'hline)
         org-babel-lua-hline-to
       (format
-       (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" "%S")
+       (if (and (stringp var) (string-match "[\n\r]" var)) "[=[%s]=]" "%S")
        (if (stringp var) (substring-no-properties var) var)))))
 
 (defun org-babel-lua-table-or-string (results)
@@ -291,13 +290,13 @@ last statement in BODY, as elisp."
   (let ((raw
          (pcase result-type
            (`output (org-babel-eval org-babel-lua-command
-                                   (concat (if preamble (concat preamble "\n"))
+                                   (concat preamble (and preamble "\n")
                                            body)))
            (`value (let ((tmp-file (org-babel-temp-file "lua-")))
                     (org-babel-eval
                      org-babel-lua-command
                      (concat
-                      (if preamble (concat preamble "\n") "")
+                      preamble (and preamble "\n")
                       (format
                        (if (member "pp" result-params)
                            org-babel-lua-pp-wrapper-method
diff --git a/lisp/org/ob-ocaml.el b/lisp/org/ob-ocaml.el
index e8f801b..54bc49a 100644
--- a/lisp/org/ob-ocaml.el
+++ b/lisp/org/ob-ocaml.el
@@ -37,11 +37,11 @@
 ;;; Code:
 (require 'ob)
 (require 'comint)
+(require 'org-macs)
 
 (declare-function tuareg-run-caml "ext:tuareg" ())
 (declare-function tuareg-run-ocaml "ext:tuareg" ())
 (declare-function tuareg-interactive-send-input "ext:tuareg" ())
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("ocaml" . "ml"))
@@ -83,11 +83,11 @@
         (raw (org-trim clean))
         (result-params (cdr (assq :result-params params))))
     (string-match
-     "\\(\\(.*\n\\)*\\)[^:\n]+ : \\([^=\n]+\\) =\\(\n\\| \\)\\(.+\\)$"
+     "\\(\\(.*\n\\)*\\)[^:\n]+ : \\([^=\n]+\\) 
=[[:space:]]+\\(\\(.\\|\n\\)+\\)$"
      raw)
     (let ((output (match-string 1 raw))
          (type (match-string 3 raw))
-         (value (match-string 5 raw)))
+         (value (match-string 4 raw)))
       (org-babel-reassemble-table
        (org-babel-result-cond result-params
         (cond
diff --git a/lisp/org/ob-octave.el b/lisp/org/ob-octave.el
index 28c7ad2..d334fa5 100644
--- a/lisp/org/ob-octave.el
+++ b/lisp/org/ob-octave.el
@@ -30,10 +30,10 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
 (declare-function matlab-shell "ext:matlab-mode")
 (declare-function matlab-shell-run-region "ext:matlab-mode")
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-default-header-args:matlab '())
 (defvar org-babel-default-header-args:octave '())
@@ -237,13 +237,11 @@ value of the last statement in BODY, as elisp."
       (`output
        (setq results
             (if matlabp
-                (cdr (reverse (delq "" (mapcar
-                                        #'org-babel-strip-quotes
-                                        (mapcar #'org-trim raw)))))
+                (cdr (reverse (delq "" (mapcar #'org-strip-quotes
+                                               (mapcar #'org-trim raw)))))
               (cdr (member org-babel-octave-eoe-output
-                           (reverse (mapcar
-                                     #'org-babel-strip-quotes
-                                     (mapcar #'org-trim raw)))))))
+                           (reverse (mapcar #'org-strip-quotes
+                                            (mapcar #'org-trim raw)))))))
        (mapconcat #'identity (reverse results) "\n")))))
 
 (defun org-babel-octave-import-elisp-from-file (file-name)
@@ -254,9 +252,9 @@ This removes initial blank and comment lines and then calls
     (with-temp-file temp-file
       (insert-file-contents file-name)
       (re-search-forward "^[ \t]*[^# \t]" nil t)
-      (if (< (setq beg (point-min))
-            (setq end (point-at-bol)))
-         (delete-region beg end)))
+      (when (< (setq beg (point-min))
+              (setq end (point-at-bol)))
+       (delete-region beg end)))
     (org-babel-import-elisp-from-file temp-file '(16))))
 
 (provide 'ob-octave)
diff --git a/lisp/org/ob-plantuml.el b/lisp/org/ob-plantuml.el
index 91229a2..09c9a33 100644
--- a/lisp/org/ob-plantuml.el
+++ b/lisp/org/ob-plantuml.el
@@ -60,16 +60,19 @@ are expected to be scalar variables."
 
 (defun org-babel-plantuml-make-body (body params)
   "Return PlantUML input string.
+
 BODY is the content of the source block and PARAMS is a property list
 of source block parameters.  This function relies on the
 `org-babel-expand-body:generic' function to extract `:var' entries
 from PARAMS and on the `org-babel-variable-assignments:plantuml'
-function to convert variables to PlantUML assignments."
-  (concat
-   "@startuml\n"
-   (org-babel-expand-body:generic
-    body params (org-babel-variable-assignments:plantuml params))
-   "\n@enduml"))
+function to convert variables to PlantUML assignments.
+
+If BODY does not contain @startXXX ... @endXXX clauses, @startuml
+... @enduml will be added."
+  (let ((assignments (org-babel-variable-assignments:plantuml params)))
+    (if (string-prefix-p "@start" body t) assignments
+      (format "@startuml\n%s\n@enduml"
+             (org-babel-expand-body:generic body params assignments)))))
 
 (defun org-babel-execute:plantuml (body params)
   "Execute a block of plantuml code with org-babel.
@@ -93,6 +96,8 @@ This function is called by `org-babel-execute-src-block'."
                            " -teps" "")
                        (if (string= (file-name-extension out-file) "pdf")
                            " -tpdf" "")
+                       (if (string= (file-name-extension out-file) "tex")
+                           " -tlatex" "")
                        (if (string= (file-name-extension out-file) "vdx")
                            " -tvdx" "")
                        (if (string= (file-name-extension out-file) "xmi")
diff --git a/lisp/org/ob-python.el b/lisp/org/ob-python.el
index b10320e..c36bf2d 100644
--- a/lisp/org/ob-python.el
+++ b/lisp/org/ob-python.el
@@ -28,9 +28,8 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
-(declare-function org-remove-indentation "org" )
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function py-shell "ext:python-mode" (&optional argprompt))
 (declare-function py-toggle-shells "ext:python-mode" (arg))
 (declare-function run-python "ext:python" (&optional cmd dedicated show))
@@ -266,13 +265,13 @@ last statement in BODY, as elisp."
   (let ((raw
          (pcase result-type
            (`output (org-babel-eval org-babel-python-command
-                                   (concat (if preamble (concat preamble "\n"))
+                                   (concat preamble (and preamble "\n")
                                            body)))
            (`value (let ((tmp-file (org-babel-temp-file "python-")))
                     (org-babel-eval
                      org-babel-python-command
                      (concat
-                      (if preamble (concat preamble "\n") "")
+                      preamble (and preamble "\n")
                       (format
                        (if (member "pp" result-params)
                            org-babel-python-pp-wrapper-method
@@ -308,9 +307,21 @@ last statement in BODY, as elisp."
               (list (format "open('%s', 'w').write(str(_))"
                             (org-babel-process-file-name tmp-file
                                                           'noquote)))))))
+        (last-indent 0)
         (input-body (lambda (body)
-                      (mapc (lambda (line) (insert line) (funcall send-wait))
-                            (split-string body "[\r\n]"))
+                      (dolist (line (split-string body "[\r\n]"))
+                        ;; Insert a blank line to end an indent
+                        ;; block.
+                        (let ((curr-indent (string-match "\\S-" line)))
+                          (if curr-indent
+                              (progn
+                                (when (< curr-indent last-indent)
+                                  (insert "")
+                                  (funcall send-wait))
+                                (setq last-indent curr-indent))
+                            (setq last-indent 0)))
+                        (insert line)
+                        (funcall send-wait))
                       (funcall send-wait)))
          (results
           (pcase result-type
diff --git a/lisp/org/ob-ref.el b/lisp/org/ob-ref.el
index 2198a84..8c066f7 100644
--- a/lisp/org/ob-ref.el
+++ b/lisp/org/ob-ref.el
@@ -37,8 +37,8 @@
 
 ;; - resource-id :: the id or name of the resource
 
-;; So an example of a simple src block referencing table data in the
-;; same file would be
+;; So an example of a simple source block referencing table data in
+;; the same file would be
 
 ;;  #+NAME: sandbox
 ;;  | 1 |         2 | 3 |
@@ -50,6 +50,7 @@
 
 ;;; Code:
 (require 'ob-core)
+(require 'org-macs)
 (require 'cl-lib)
 
 (declare-function org-babel-lob-get-info "ob-lob" (&optional datum))
@@ -63,7 +64,6 @@
 (declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
 (declare-function org-narrow-to-subtree "org" ())
 (declare-function org-show-context "org" (&optional key))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-babel-update-intermediate nil
   "Update the in-buffer results of code blocks executed to resolve 
references.")
diff --git a/lisp/org/ob-ruby.el b/lisp/org/ob-ruby.el
index 309bd15..be76727 100644
--- a/lisp/org/ob-ruby.el
+++ b/lisp/org/ob-ruby.el
@@ -37,8 +37,8 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function run-ruby "ext:inf-ruby" (&optional command name))
 (declare-function xmp "ext:rcodetools" (&optional option))
 
diff --git a/lisp/org/ob-scheme.el b/lisp/org/ob-scheme.el
index 635b3aa..21d9fad 100644
--- a/lisp/org/ob-scheme.el
+++ b/lisp/org/ob-scheme.el
@@ -112,10 +112,9 @@
     (or buffer
        (progn
          (run-geiser impl)
-         (if name
-             (progn
-               (rename-buffer name t)
-               (org-babel-scheme-set-session-buffer name (current-buffer))))
+         (when name
+           (rename-buffer name t)
+           (org-babel-scheme-set-session-buffer name (current-buffer)))
          (current-buffer)))))
 
 (defun org-babel-scheme-make-session-name (buffer name impl)
@@ -214,6 +213,7 @@ This function is called by `org-babel-execute-src-block'."
             (session (org-babel-scheme-make-session-name
                       source-buffer-name (cdr (assq :session params)) impl))
             (full-body (org-babel-expand-body:scheme body params))
+            (result-params (cdr (assq :result-params params)))
             (result
              (org-babel-scheme-execute-with-geiser
               full-body                       ; code
@@ -227,7 +227,9 @@ This function is called by `org-babel-execute-src-block'."
                                     (cdr (assq :colnames params)))
                (org-babel-pick-name (cdr (assq :rowname-names params))
                                     (cdr (assq :rownames params))))))
-         (org-babel-scheme--table-or-string table))))))
+         (org-babel-result-cond result-params
+           result
+           (org-babel-scheme--table-or-string table)))))))
 
 (provide 'ob-scheme)
 
diff --git a/lisp/org/ob-sed.el b/lisp/org/ob-sed.el
index 33751b8..be4cff4 100644
--- a/lisp/org/ob-sed.el
+++ b/lisp/org/ob-sed.el
@@ -4,7 +4,7 @@
 
 ;; Author: Bjarte Johansen
 ;; Keywords: literate programming, reproducible research
-;; Version: 0.1.0
+;; Version: 0.1.1
 
 ;; This file is part of GNU Emacs.
 
@@ -79,7 +79,7 @@ function is called by `org-babel-execute-src-block'."
          (cmd (mapconcat #'identity
                         (remq nil
                               (list org-babel-sed-command
-                                    (format "--file=\"%s\"" code-file)
+                                    (format "-f \"%s\"" code-file)
                                     cmd-line
                                     in-file))
                         " ")))
diff --git a/lisp/org/ob-shell.el b/lisp/org/ob-shell.el
index 548edce..88342ba 100644
--- a/lisp/org/ob-shell.el
+++ b/lisp/org/ob-shell.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-macs)
 (require 'shell)
 (require 'cl-lib)
 
@@ -36,7 +37,6 @@
 (declare-function org-babel-comint-buffer-livep "ob-comint" (buffer))
 (declare-function org-babel-comint-with-output "ob-comint" (meta &rest body)
                  t)
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function orgtbl-to-generic "org-table" (table params))
 
 (defvar org-babel-default-header-args:shell '())
@@ -57,10 +57,11 @@ is modified outside the Customize interface."
             'org-babel-variable-assignments:shell
             ,(format "Return list of %s statements assigning to the block's \
 variables."
-                     name)))))
+                     name)))
+    (eval `(defvar ,(intern (concat "org-babel-default-header-args:" name)) 
'()))))
 
 (defcustom org-babel-shell-names
-  '("sh" "bash" "csh" "ash" "dash" "ksh" "mksh" "posh")
+  '("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh")
   "List of names of shell supported by babel shell code blocks.
 Call `org-babel-shell-initialize' when modifying this variable
 outside the Customize interface."
@@ -206,62 +207,60 @@ var of the same value."
 If RESULT-TYPE equals `output' then return a list of the outputs
 of the statements in BODY, if RESULT-TYPE equals `value' then
 return the value of the last statement in BODY."
-  (let ((results
-         (cond
-          ((or stdin cmdline)         ; external shell script w/STDIN
-           (let ((script-file (org-babel-temp-file "sh-script-"))
-                 (stdin-file (org-babel-temp-file "sh-stdin-"))
-                 (shebang (cdr (assq :shebang params)))
-                 (padline (not (string= "no" (cdr (assq :padline params))))))
-             (with-temp-file script-file
-               (when shebang (insert (concat shebang "\n")))
-               (when padline (insert "\n"))
-               (insert body))
-             (set-file-modes script-file #o755)
-             (with-temp-file stdin-file (insert (or stdin "")))
-             (with-temp-buffer
-               (call-process-shell-command
-                (concat (if shebang script-file
-                         (format "%s %s" shell-file-name script-file))
-                       (and cmdline (concat " " cmdline)))
-                stdin-file
-               (current-buffer))
-               (buffer-string))))
-          (session                      ; session evaluation
-           (mapconcat
-            #'org-babel-sh-strip-weird-long-prompt
-            (mapcar
-             #'org-trim
-             (butlast
-              (org-babel-comint-with-output
-                  (session org-babel-sh-eoe-output t body)
-                (mapc
-                 (lambda (line)
-                   (insert line)
-                   (comint-send-input nil t)
-                   (while (save-excursion
-                            (goto-char comint-last-input-end)
-                            (not (re-search-forward
-                                  comint-prompt-regexp nil t)))
-                     (accept-process-output
-                      (get-buffer-process (current-buffer)))))
-                 (append
-                  (split-string (org-trim body) "\n")
-                  (list org-babel-sh-eoe-indicator))))
-              2)) "\n"))
-          ('otherwise                   ; external shell script
-           (if (and (cdr (assq :shebang params))
-                    (> (length (cdr (assq :shebang params))) 0))
-               (let ((script-file (org-babel-temp-file "sh-script-"))
-                     (shebang (cdr (assq :shebang params)))
-                     (padline (not (equal "no" (cdr (assq :padline params))))))
-                 (with-temp-file script-file
-                   (when shebang (insert (concat shebang "\n")))
-                   (when padline (insert "\n"))
-                   (insert body))
-                 (set-file-modes script-file #o755)
-                 (org-babel-eval script-file ""))
-             (org-babel-eval shell-file-name (org-trim body)))))))
+  (let* ((shebang (cdr (assq :shebang params)))
+        (results
+         (cond
+          ((or stdin cmdline)         ; external shell script w/STDIN
+           (let ((script-file (org-babel-temp-file "sh-script-"))
+                 (stdin-file (org-babel-temp-file "sh-stdin-"))
+                 (padline (not (string= "no" (cdr (assq :padline params))))))
+             (with-temp-file script-file
+               (when shebang (insert shebang "\n"))
+               (when padline (insert "\n"))
+               (insert body))
+             (set-file-modes script-file #o755)
+             (with-temp-file stdin-file (insert (or stdin "")))
+             (with-temp-buffer
+               (call-process-shell-command
+                (concat (if shebang script-file
+                          (format "%s %s" shell-file-name script-file))
+                        (and cmdline (concat " " cmdline)))
+                stdin-file
+                (current-buffer))
+               (buffer-string))))
+          (session                     ; session evaluation
+           (mapconcat
+            #'org-babel-sh-strip-weird-long-prompt
+            (mapcar
+             #'org-trim
+             (butlast
+              (org-babel-comint-with-output
+                  (session org-babel-sh-eoe-output t body)
+                (dolist (line (append (split-string (org-trim body) "\n")
+                                      (list org-babel-sh-eoe-indicator)))
+                  (insert line)
+                  (comint-send-input nil t)
+                  (while (save-excursion
+                           (goto-char comint-last-input-end)
+                           (not (re-search-forward
+                                 comint-prompt-regexp nil t)))
+                    (accept-process-output
+                     (get-buffer-process (current-buffer))))))
+              2))
+            "\n"))
+          ;; External shell script, with or without a predefined
+          ;; shebang.
+          ((org-string-nw-p shebang)
+           (let ((script-file (org-babel-temp-file "sh-script-"))
+                 (padline (not (equal "no" (cdr (assq :padline params))))))
+             (with-temp-file script-file
+               (insert shebang "\n")
+               (when padline (insert "\n"))
+               (insert body))
+             (set-file-modes script-file #o755)
+             (org-babel-eval script-file "")))
+          (t
+           (org-babel-eval shell-file-name (org-trim body))))))
     (when results
       (let ((result-params (cdr (assq :result-params params))))
         (org-babel-result-cond result-params
diff --git a/lisp/org/ob-sql.el b/lisp/org/ob-sql.el
index 17447b4..1bbfd44 100644
--- a/lisp/org/ob-sql.el
+++ b/lisp/org/ob-sql.el
@@ -39,6 +39,7 @@
 ;; - dbport
 ;; - dbuser
 ;; - dbpassword
+;; - dbconnection (to reference connections in sql-connection-alist)
 ;; - database
 ;; - colnames (default, nil, means "yes")
 ;; - result-params
@@ -73,6 +74,7 @@
 (declare-function org-table-to-lisp "org-table" (&optional txt))
 (declare-function cygwin-convert-file-name-to-windows "cygw32.c" (file 
&optional absolute-p))
 
+(defvar sql-connection-alist)
 (defvar org-babel-default-header-args:sql '())
 
 (defconst org-babel-header-args:sql
@@ -111,8 +113,24 @@ Pass nil to omit that arg."
               (when database (concat "-d" database))))))
 
 (defun org-babel-sql-dbstring-oracle (host port user password database)
-  "Make Oracle command line args for database connection."
-  (format "%s/%s@%s:%s/%s" user password host port database))
+  "Make Oracle command line arguments for database connection.
+
+If HOST and PORT are nil then don't pass them.  This allows you
+to use names defined in your \"TNSNAMES\" file.  So you can
+connect with
+
+  <user>/<password>@<host>:<port>/<database>
+
+or
+
+  <user>/<password>@<database>
+
+using its alias."
+  (cond ((and user password database host port)
+        (format "%s/%s@%s:%s/%s" user password host port database))
+       ((and user password database)
+        (format "%s/%s@%s" user password database))
+       (t (user-error "Missing information to connect to database"))))
 
 (defun org-babel-sql-dbstring-mssql (host user password database)
   "Make sqlcmd command line args for database connection.
@@ -158,16 +176,35 @@ Otherwise, use Emacs' standard conversion function."
        ((string= "windows-nt" system-type) file)
        (t (format "%S" (convert-standard-filename file)))))
 
+(defun org-babel-find-db-connection-param (params name)
+  "Return database connection parameter NAME.
+Given a parameter NAME, if :dbconnection is defined in PARAMS
+then look for the parameter into the corresponding connection
+defined in `sql-connection-alist`, otherwise look into PARAMS.
+Look `sql-connection-alist` (part of SQL mode) for how to define
+database connections."
+  (if (assq :dbconnection params)
+      (let* ((dbconnection (cdr (assq :dbconnection params)))
+             (name-mapping '((:dbhost . sql-server)
+                             (:dbport . sql-port)
+                             (:dbuser . sql-user)
+                             (:dbpassword . sql-password)
+                             (:database . sql-database)))
+             (mapped-name (cdr (assq name name-mapping))))
+        (cadr (assq mapped-name
+                    (cdr (assoc dbconnection sql-connection-alist)))))
+    (cdr (assq name params))))
+
 (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'."
   (let* ((result-params (cdr (assq :result-params params)))
          (cmdline (cdr (assq :cmdline params)))
-         (dbhost (cdr (assq :dbhost params)))
-         (dbport (cdr (assq :dbport params)))
-         (dbuser (cdr (assq :dbuser params)))
-         (dbpassword (cdr (assq :dbpassword params)))
-         (database (cdr (assq :database params)))
+         (dbhost (org-babel-find-db-connection-param params :dbhost))
+         (dbport (org-babel-find-db-connection-param params :dbport))
+         (dbuser (org-babel-find-db-connection-param params :dbuser))
+         (dbpassword (org-babel-find-db-connection-param params :dbpassword))
+         (database (org-babel-find-db-connection-param params :database))
          (engine (cdr (assq :engine params)))
          (colnames-p (not (equal "no" (cdr (assq :colnames params)))))
          (in-file (org-babel-temp-file "sql-in-"))
@@ -241,6 +278,7 @@ SET NEWPAGE 0
 SET TAB OFF
 SET SPACE 0
 SET LINESIZE 9999
+SET TRIMOUT ON TRIMSPOOL ON
 SET ECHO OFF
 SET FEEDBACK OFF
 SET VERIFY OFF
diff --git a/lisp/org/ob-sqlite.el b/lisp/org/ob-sqlite.el
index 04bf4fe..7522c83 100644
--- a/lisp/org/ob-sqlite.el
+++ b/lisp/org/ob-sqlite.el
@@ -28,7 +28,6 @@
 ;;; Code:
 (require 'ob)
 
-(declare-function org-fill-template "org" (template alist))
 (declare-function org-table-convert-region "org-table"
                  (beg0 end0 &optional separator))
 (declare-function orgtbl-to-csv "org-table" (table params))
diff --git a/lisp/org/ob-table.el b/lisp/org/ob-table.el
index 93a8165..42eecea 100644
--- a/lisp/org/ob-table.el
+++ b/lisp/org/ob-table.el
@@ -54,8 +54,7 @@
 
 ;;; Code:
 (require 'ob-core)
-
-(declare-function org-trim "org" (s &optional keep-lead))
+(require 'org-macs)
 
 (defun org-babel-table-truncate-at-newline (string)
   "Replace newline character with ellipses.
diff --git a/lisp/org/ob-tangle.el b/lisp/org/ob-tangle.el
index 3c16200..2ea3341 100644
--- a/lisp/org/ob-tangle.el
+++ b/lisp/org/ob-tangle.el
@@ -30,6 +30,7 @@
 (require 'cl-lib)
 (require 'org-src)
 (require 'org-macs)
+(require 'ol)
 
 (declare-function make-directory "files" (dir &optional parents))
 (declare-function org-at-heading-p "org" (&optional ignored))
@@ -38,18 +39,9 @@
 (declare-function org-before-first-heading-p "org" ())
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-type "org-element" (element))
-(declare-function org-fill-template "org" (template alist))
 (declare-function org-heading-components "org" ())
 (declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
-(declare-function org-link-escape "org" (text &optional table merge))
-(declare-function org-open-link-from-string "org" (s &optional arg 
reference-buffer))
-(declare-function org-remove-indentation "org" (code &optional n))
-(declare-function org-store-link "org" (arg))
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function outline-previous-heading "outline" ())
-(declare-function org-id-find "org-id" (id &optional markerp))
-
-(defvar org-link-types-re)
 
 (defcustom org-babel-tangle-lang-exts
   '(("emacs-lisp" . "el")
@@ -182,7 +174,7 @@ export file for all source blocks.  Optional argument LANG 
can be
 used to limit the exported source code blocks by language.
 Return a list whose CAR is the tangled file name."
   (interactive "fFile to tangle: \nP")
-  (let ((visited-p (get-file-buffer (expand-file-name file)))
+  (let ((visited-p (find-buffer-visiting (expand-file-name file)))
        to-be-removed)
     (prog1
        (save-window-excursion
@@ -236,13 +228,7 @@ used to limit the exported source code blocks by language."
           (let* ((lang (car by-lang))
                  (specs (cdr by-lang))
                  (ext (or (cdr (assoc lang org-babel-tangle-lang-exts)) lang))
-                 (lang-f (intern
-                          (concat
-                           (or (and (cdr (assoc lang org-src-lang-modes))
-                                    (symbol-name
-                                     (cdr (assoc lang org-src-lang-modes))))
-                               lang)
-                           "-mode")))
+                 (lang-f (org-src-get-lang-mode lang))
                  she-banged)
             (mapc
              (lambda (spec)
@@ -333,8 +319,6 @@ references."
     (delete-region (save-excursion (beginning-of-line 1) (point))
                    (save-excursion (end-of-line 1) (forward-char 1) (point)))))
 
-(defvar org-stored-links)
-(defvar org-bracket-link-regexp)
 (defun org-babel-spec-to-string (spec)
   "Insert SPEC into the current file.
 
@@ -409,7 +393,8 @@ can be used to limit the collected code blocks by target 
file."
              (if by-lang (setcdr by-lang (cons block (cdr by-lang)))
                (push (cons src-lang (list block)) blocks)))))))
     ;; Ensure blocks are in the correct order.
-    (mapcar (lambda (b) (cons (car b) (nreverse (cdr b)))) blocks)))
+    (mapcar (lambda (b) (cons (car b) (nreverse (cdr b))))
+           (nreverse blocks))))
 
 (defun org-babel-tangle-single-block (block-counter &optional only-this-block)
   "Collect the tangled source for current block.
@@ -429,7 +414,7 @@ non-nil, return the full association list to be used by
                            (match-string 1 extra))
                       org-coderef-label-format))
         (link (let ((l (org-no-properties (org-store-link nil))))
-                 (and (string-match org-bracket-link-regexp l)
+                 (and (string-match org-link-bracket-re l)
                       (match-string 1 l))))
         (source-name
          (or (nth 4 info)
@@ -503,22 +488,21 @@ non-nil, return the full association list to be used by
       result)))
 
 (defun org-babel-tangle-comment-links (&optional info)
-  "Return a list of begin and end link comments for the code block at point."
-  (let ((link-data
-        `(("start-line" . ,(number-to-string
-                            (org-babel-where-is-src-block-head)))
-          ("file" . ,(buffer-file-name))
-          ("link" . ,(org-link-escape
-                      (progn
-                        (call-interactively #'org-store-link)
-                        (org-no-properties (car (pop org-stored-links))))))
-          ("source-name" .
-           ,(nth 4 (or info (org-babel-get-src-block-info 'light)))))))
+  "Return a list of begin and end link comments for the code block at point.
+INFO, when non nil, is the source block information, as returned
+by `org-babel-get-src-block-info'."
+  (let ((link-data (pcase (or info (org-babel-get-src-block-info 'light))
+                    (`(,_ ,_ ,_ ,_ ,name ,start ,_)
+                     `(("start-line" . ,(org-with-point-at start
+                                          (number-to-string
+                                           (line-number-at-pos))))
+                       ("file" . ,(buffer-file-name))
+                       ("link" . ,(org-no-properties (org-store-link nil)))
+                       ("source-name" . ,name))))))
     (list (org-fill-template org-babel-tangle-comment-format-beg link-data)
          (org-fill-template org-babel-tangle-comment-format-end link-data))))
 
 ;; de-tangling functions
-(defvar org-bracket-link-analytic-regexp)
 (defun org-babel-detangle (&optional source-code-file)
   "Propagate changes in source file back original to Org file.
 This requires that code blocks were tangled with link comments
@@ -528,9 +512,9 @@ which enable the original code blocks to be found."
     (when source-code-file (find-file source-code-file))
     (goto-char (point-min))
     (let ((counter 0) new-body end)
-      (while (re-search-forward org-bracket-link-analytic-regexp nil t)
+      (while (re-search-forward org-link-bracket-re nil t)
         (when (re-search-forward
-              (concat " " (regexp-quote (match-string 5)) " ends here"))
+              (concat " " (regexp-quote (match-string 2)) " ends here"))
           (setq end (match-end 0))
           (forward-line -1)
           (save-excursion
@@ -544,17 +528,15 @@ which enable the original code blocks to be found."
   "Jump from a tangled code file to the related Org mode file."
   (interactive)
   (let ((mid (point))
-       start body-start end
-        target-buffer target-char link path block-name body)
+       start body-start end target-buffer target-char link block-name body)
     (save-window-excursion
       (save-excursion
-       (while (and (re-search-backward org-bracket-link-analytic-regexp nil t)
+       (while (and (re-search-backward org-link-bracket-re nil t)
                    (not ; ever wider searches until matching block comments
                     (and (setq start (line-beginning-position))
                          (setq body-start (line-beginning-position 2))
                          (setq link (match-string 0))
-                         (setq path (match-string 3))
-                         (setq block-name (match-string 5))
+                         (setq block-name (match-string 2))
                          (save-excursion
                            (save-match-data
                              (re-search-forward
@@ -564,12 +546,9 @@ which enable the original code blocks to be found."
        (unless (and start (< start mid) (< mid end))
          (error "Not in tangled code"))
         (setq body (buffer-substring body-start end)))
-      (when (string-match "::" path)
-        (setq path (substring path 0 (match-beginning 0))))
-      (find-file (or (car (org-id-find path)) path))
-      (setq target-buffer (current-buffer))
       ;; Go to the beginning of the relative block in Org file.
-      (org-open-link-from-string link)
+      (org-link-open-from-string link)
+      (setq target-buffer (current-buffer))
       (if (string-match "[^ \t\n\r]:\\([[:digit:]]+\\)" block-name)
           (let ((n (string-to-number (match-string 1 block-name))))
            (if (org-before-first-heading-p) (goto-char (point-min))
@@ -583,10 +562,12 @@ which enable the original code blocks to be found."
                  (t (org-babel-next-src-block (1- n)))))
         (org-babel-goto-named-src-block block-name))
       (goto-char (org-babel-where-is-src-block-head))
-      ;; Preserve location of point within the source code in tangled
-      ;; code file.
       (forward-line 1)
-      (forward-char (- mid body-start))
+      ;; Try to preserve location of point within the source code in
+      ;; tangled code file.
+      (let ((offset (- mid body-start)))
+       (when (> end (+ offset (point)))
+         (forward-char offset)))
       (setq target-char (point)))
     (org-src-switch-to-buffer target-buffer t)
     (goto-char target-char)
diff --git a/lisp/org/ob-vala.el b/lisp/org/ob-vala.el
index 5d14002..85868d8 100644
--- a/lisp/org/ob-vala.el
+++ b/lisp/org/ob-vala.el
@@ -39,8 +39,7 @@
 ;;; Code:
 
 (require 'ob)
-
-(declare-function org-trim "org" (s &optional keep-lead))
+(require 'org-macs)
 
 ;; File extension.
 (add-to-list 'org-babel-tangle-lang-exts '("vala" . "vala"))
diff --git a/lisp/org/ob.el b/lisp/org/ob.el
index 86d6928..6dffa23 100644
--- a/lisp/org/ob.el
+++ b/lisp/org/ob.el
@@ -24,11 +24,11 @@
 ;;; Code:
 (require 'org-macs)
 (require 'org-compat)
+(require 'org-keys)
 (require 'ob-eval)
 (require 'ob-core)
 (require 'ob-comint)
 (require 'ob-exp)
-(require 'ob-keys)
 (require 'ob-table)
 (require 'ob-lob)
 (require 'ob-ref)
diff --git a/lisp/org/org-bbdb.el b/lisp/org/ol-bbdb.el
similarity index 95%
rename from lisp/org/org-bbdb.el
rename to lisp/org/ol-bbdb.el
index 2c4f126..b4940ac 100644
--- a/lisp/org/org-bbdb.el
+++ b/lisp/org/ol-bbdb.el
@@ -1,4 +1,4 @@
-;;; org-bbdb.el --- Support for links to BBDB entries -*- lexical-binding: t; 
-*-
+;;; ol-bbdb.el --- Links to BBDB entries             -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
 
@@ -93,23 +93,22 @@
 ;;
 ;;; Code:
 
-(require 'org)
 (require 'cl-lib)
+(require 'org-compat)
+(require 'org-macs)
+(require 'ol)
 
-;; Declare external functions and variables
+;; Declare functions and variables
 
 (declare-function bbdb "ext:bbdb-com" (string elidep))
 (declare-function bbdb-company "ext:bbdb-com" (string elidep))
-(declare-function bbdb-current-record "ext:bbdb-com"
-                 (&optional planning-on-modifying))
+(declare-function bbdb-current-record "ext:bbdb-com" (&optional 
planning-on-modifying))
 (declare-function bbdb-name "ext:bbdb-com" (string elidep))
-(declare-function bbdb-completing-read-record "ext:bbdb-com"
-                 (prompt &optional omit-records))
+(declare-function bbdb-completing-read-record "ext:bbdb-com" (prompt &optional 
omit-records))
 (declare-function bbdb-record-field "ext:bbdb" (record field))
 (declare-function bbdb-record-getprop "ext:bbdb" (record property))
 (declare-function bbdb-record-name "ext:bbdb" (record))
-(declare-function bbdb-records "ext:bbdb"
-                 (&optional dont-check-disk already-in-db-buffer))
+(declare-function bbdb-records "ext:bbdb" (&optional dont-check-disk 
already-in-db-buffer))
 (declare-function bbdb-split "ext:bbdb" (string separators))
 (declare-function bbdb-string-trim "ext:bbdb" (string))
 (declare-function bbdb-record-get-field "ext:bbdb" (record field))
@@ -121,10 +120,13 @@
 ;; `bbdb-record-xfield' replaces it in recent BBDB v3.x+
 (declare-function bbdb-record-xfield "ext:bbdb" (record label))
 
+(declare-function calendar-absolute-from-gregorian "calendar" (date))
+(declare-function calendar-gregorian-from-absolute "calendar" (date))
 (declare-function calendar-leap-year-p "calendar" (year))
+
 (declare-function diary-ordinal-suffix "diary-lib" (n))
 
-(with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
+(with-no-warnings (defvar date))       ;unprefixed, from calendar.el
 
 ;; Customization
 
@@ -160,13 +162,13 @@ used."
   '(("birthday" .
      (lambda (name years suffix)
        (concat "Birthday: [[bbdb:" name "][" name " ("
-              (format "%s" years)        ; handles numbers as well as strings
-              suffix ")]]")))
+               (format "%s" years) ; handles numbers as well as strings
+               suffix ")]]")))
     ("wedding" .
      (lambda (name years suffix)
        (concat "[[bbdb:" name "][" name "'s "
-              (format "%s" years)
-              suffix " wedding anniversary]]"))))
+               (format "%s" years)
+               suffix " wedding anniversary]]"))))
   "How different types of anniversaries should be formatted.
 An alist of elements (STRING . FORMAT) where STRING is the name of an
 anniversary class and format is either:
@@ -230,7 +232,7 @@ date year)."
                         (bbdb-record-getprop rec 'company)
                       (car (bbdb-record-field rec 'organization))))
           (link (concat "bbdb:" name)))
-      (org-store-link-props :type "bbdb" :name name :company company
+      (org-link-store-props :type "bbdb" :name name :company company
                            :link link :description name)
       link)))
 
@@ -300,7 +302,7 @@ italicized, in all other cases it is left unchanged."
 Argument TIME-STR is the value retrieved from BBDB.  If YYYY- is omitted
 it will be considered unknown."
   (pcase (org-split-string time-str "-")
-    (`(,a ,b nil) (list (string-to-number a) (string-to-number b) nil))
+    (`(,a ,b) (list (string-to-number a) (string-to-number b) nil))
     (`(,a ,b ,c) (list (string-to-number b)
                       (string-to-number c)
                       (string-to-number a)))))
@@ -532,10 +534,10 @@ END:VEVENT\n"
                     (concat (capitalize categ) " " (nth 1 rec))
                     categ)))))
 
-(provide 'org-bbdb)
+(provide 'ol-bbdb)
 
 ;; Local variables:
 ;; generated-autoload-file: "org-loaddefs.el"
 ;; End:
 
-;;; org-bbdb.el ends here
+;;; ol-bbdb.el ends here
diff --git a/lisp/org/org-bibtex.el b/lisp/org/ol-bibtex.el
similarity index 96%
rename from lisp/org/org-bibtex.el
rename to lisp/org/ol-bibtex.el
index 218112c..78cdd04 100644
--- a/lisp/org/org-bibtex.el
+++ b/lisp/org/ol-bibtex.el
@@ -1,4 +1,4 @@
-;;; org-bibtex.el --- Org links to BibTeX entries    -*- lexical-binding: t; 
-*-
+;;; ol-bibtex.el --- Links to BibTeX entries        -*- lexical-binding: t; -*-
 ;;
 ;; Copyright (C) 2007-2019 Free Software Foundation, Inc.
 ;;
@@ -107,21 +107,37 @@
 
 ;;; Code:
 
-(require 'org)
 (require 'bibtex)
 (require 'cl-lib)
 (require 'org-compat)
+(require 'org-macs)
+(require 'ol)
 
 (defvar org-agenda-overriding-header)
 (defvar org-agenda-search-view-always-boolean)
 (defvar org-bibtex-description nil) ; dynamically scoped from org.el
 (defvar org-id-locations)
+(defvar org-property-end-re)
+(defvar org-special-properties)
+(defvar org-window-config-before-follow-link)
 
 (declare-function bibtex-beginning-of-entry "bibtex" ())
 (declare-function bibtex-generate-autokey "bibtex" ())
 (declare-function bibtex-parse-entry "bibtex" (&optional content))
 (declare-function bibtex-url "bibtex" (&optional pos no-browse))
 
+(declare-function org-back-to-heading "org" (&optional invisible-ok))
+(declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
+(declare-function org-entry-properties "org" (&optional pom which))
+(declare-function org-get-tags "org" (&optional pos local))
+(declare-function org-heading-components "org" ())
+(declare-function org-insert-heading "org" (&optional arg invisible-ok top))
+(declare-function org-map-entries "org" (func &optional match scope &rest 
skip))
+(declare-function org-narrow-to-subtree "org" ())
+(declare-function org-open-file "org" (path &optional in-emacs line search))
+(declare-function org-set-property "org" (property value))
+(declare-function org-toggle-tag "org" (tag &optional onoff))
+
 
 ;;; Bibtex data
 (defvar org-bibtex-types
@@ -354,9 +370,8 @@ and `org-exclude-tags-from-inheritance'."
                                            (append org-bibtex-tags
                                                    org-bibtex-no-export-tags))
                              tag))
-                         (if org-bibtex-inherit-tags
-                             (org-get-tags-at)
-                           (org-get-local-tags-at)))))))
+                         (if org-bibtex-inherit-tags (org-get-tags)
+                           (org-get-tags nil t)))))))
     (when type
       (let ((entry (format
                    "@%s{%s,\n%s\n}\n" type id
@@ -489,7 +504,7 @@ With optional argument OPTIONAL, also prompt for optional 
fields."
                   (save-excursion
                     (bibtex-beginning-of-entry)
                     (bibtex-parse-entry)))))
-      (org-store-link-props
+      (org-link-store-props
        :key (cdr (assoc "=key=" entry))
        :author (or (cdr (assoc "author" entry)) "[no author]")
        :editor (or (cdr (assoc "editor" entry)) "[no editor]")
@@ -743,6 +758,6 @@ This function relies `org-search-view' to locate results."
                             string (or org-bibtex-prefix "")
                             org-bibtex-type-property-name))))
 
-(provide 'org-bibtex)
+(provide 'ol-bibtex)
 
-;;; org-bibtex.el ends here
+;;; ol-bibtex.el ends here
diff --git a/lisp/org/org-docview.el b/lisp/org/ol-docview.el
similarity index 86%
rename from lisp/org/org-docview.el
rename to lisp/org/ol-docview.el
index 7e1287f..0aadb9a 100644
--- a/lisp/org/org-docview.el
+++ b/lisp/org/ol-docview.el
@@ -1,4 +1,4 @@
-;;; org-docview.el --- Support for links to doc-view-mode buffers -*- 
lexical-binding: t; -*-
+;;; ol-docview.el --- Links to Docview mode buffers  -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2009-2019 Free Software Foundation, Inc.
 
@@ -43,11 +43,12 @@
 ;;; Code:
 
 
-(require 'org)
 (require 'doc-view)
+(require 'ol)
 
 (declare-function doc-view-goto-page "doc-view" (page))
 (declare-function image-mode-window-get "image-mode" (prop &optional winprops))
+(declare-function org-open-file "org" (path &optional in-emacs line search))
 
 (org-link-set-parameters "docview"
                         :follow #'org-docview-open
@@ -56,11 +57,11 @@
 
 (defun org-docview-export (link description format)
   "Export a docview link from Org files."
-  (let* ((path (if (string-match "\\(.+\\)::.+" link) (match-string 1 link)
-                link))
-         (desc (or description link)))
+  (let ((path (if (string-match "\\(.+\\)::.+" link) (match-string 1 link)
+               link))
+        (desc (or description link)))
     (when (stringp path)
-      (setq path (org-link-escape (expand-file-name path)))
+      (setq path (expand-file-name path))
       (cond
        ((eq format 'html) (format "<a href=\"%s\">%s</a>" path desc))
        ((eq format 'latex) (format "\\href{%s}{%s}" path desc))
@@ -84,7 +85,7 @@
     (let* ((path buffer-file-name)
           (page (image-mode-window-get 'page))
           (link (concat "docview:" path "::" (number-to-string page))))
-      (org-store-link-props
+      (org-link-store-props
        :type "docview"
        :link link
        :description path))))
@@ -93,11 +94,11 @@
   "Use the existing file name completion for file.
 Links to get the file name, then ask the user for the page number
 and append it."
-  (concat (replace-regexp-in-string "^file:" "docview:" 
(org-file-complete-link))
+  (concat (replace-regexp-in-string "^file:" "docview:" 
(org-link-complete-file))
          "::"
          (read-from-minibuffer "Page:" "1")))
 
 
-(provide 'org-docview)
+(provide 'ol-docview)
 
-;;; org-docview.el ends here
+;;; ol-docview.el ends here
diff --git a/lisp/org/org-eshell.el b/lisp/org/ol-eshell.el
similarity index 85%
rename from lisp/org/org-eshell.el
rename to lisp/org/ol-eshell.el
index 2251a1b..137e30f 100644
--- a/lisp/org/org-eshell.el
+++ b/lisp/org/ol-eshell.el
@@ -1,4 +1,4 @@
-;;; org-eshell.el - Support for Links to Working Directories in Eshell -*- 
lexical-binding: t; -*-
+;;; ol-eshell.el - Links to Working Directories in Eshell -*- lexical-binding: 
t; -*-
 
 ;; Copyright (C) 2011-2019 Free Software Foundation, Inc.
 
@@ -23,16 +23,18 @@
 
 ;;; Code:
 
-(require 'org)
 (require 'eshell)
 (require 'esh-mode)
+(require 'ol)
+
+(declare-function eshell/pwd "em-dirs.el" (&rest args))
 
 (org-link-set-parameters "eshell"
                         :follow #'org-eshell-open
                         :store #'org-eshell-store-link)
 
 (defun org-eshell-open (link)
-  "Switch to am eshell buffer and execute a command line.
+  "Switch to an eshell buffer and execute a command line.
    The link can be just a command line (executed in the default
    eshell buffer) or a command line prefixed by a buffer name
    followed by a colon."
@@ -55,12 +57,12 @@
   "Store a link that, when opened, switches back to the current eshell buffer
    and the current working directory."
   (when (eq major-mode 'eshell-mode)
-    (let* ((command (concat "cd " dired-directory))
+    (let* ((command (concat "cd " (eshell/pwd)))
            (link  (concat (buffer-name) ":" command)))
-      (org-store-link-props
+      (org-link-store-props
        :link (concat "eshell:" link)
        :description command))))
 
-(provide 'org-eshell)
+(provide 'ol-eshell)
 
-;;; org-eshell.el ends here
+;;; ol-eshell.el ends here
diff --git a/lisp/org/org-eww.el b/lisp/org/ol-eww.el
similarity index 88%
rename from lisp/org/org-eww.el
rename to lisp/org/ol-eww.el
index 4988237..96357c4 100644
--- a/lisp/org/org-eww.el
+++ b/lisp/org/ol-eww.el
@@ -1,4 +1,4 @@
-;;; org-eww.el --- Store url and kill from Eww mode for Org  -*- 
lexical-binding: t -*-
+;;; ol-eww.el --- Store URL and kill from Eww mode    -*- lexical-binding: t 
-*-
 
 ;; Copyright (C) 2014-2019 Free Software Foundation, Inc.
 
@@ -44,7 +44,7 @@
 
 
 ;;; Code:
-(require 'org)
+(require 'ol)
 (require 'cl-lib)
 
 (defvar eww-current-title)
@@ -55,12 +55,12 @@
 (declare-function eww-current-url "eww")
 
 
-;; Store Org-link in eww-mode buffer
+;; Store Org link in Eww mode buffer
 (org-link-set-parameters "eww" :follow #'eww :store #'org-eww-store-link)
 (defun org-eww-store-link ()
   "Store a link to the url of an EWW buffer."
   (when (eq major-mode 'eww-mode)
-    (org-store-link-props
+    (org-link-store-props
      :type "eww"
      :link (if (< emacs-major-version 25)
               eww-current-url
@@ -72,7 +72,7 @@
                        (eww-current-url))))))
 
 
-;; Some auxiliary functions concerning links in eww buffers
+;; Some auxiliary functions concerning links in Eww buffers
 (defun org-eww-goto-next-url-property-change ()
   "Move to the start of next link if exists.
 Otherwise point is not moved.  Return point."
@@ -93,11 +93,12 @@ Otherwise point is not moved.  Return point."
 (defun org-eww-copy-for-org-mode ()
   "Copy current buffer content or active region with `org-mode' style links.
 This will encode `link-title' and `link-location' with
-`org-make-link-string', and insert the transformed test into the kill ring,
-so that it can be yanked into an Org mode buffer with links working correctly.
+`org-link-make-string' and insert the transformed text into the
+kill ring, so that it can be yanked into an Org mode buffer with
+links working correctly.
 
-Further lines starting with a star get quoted with a comma to keep
-the structure of the Org file."
+Further lines starting with a star get quoted with a comma to
+keep the structure of the Org file."
   (interactive)
   (let* ((regionp (org-region-active-p))
          (transform-start (point-min))
@@ -140,13 +141,13 @@ the structure of the Org file."
               ;; concat `org-mode' style url to `return-content'.
              (setq return-content
                    (concat return-content
-                           (if (stringp link-location)
-                               ;; hint: link-location is different for 
form-elements.
-                               (org-make-link-string link-location link-title)
+                           (if (org-string-nw-p link-location)
+                               ;; Hint: link-location is different
+                               ;; for form-elements.
+                               (org-link-make-string link-location link-title)
                              link-title))))
          (goto-char temp-position) ; reset point before jump next anchor
-         (setq out-bound t)        ; for break out `while' loop
-         ))
+         (setq out-bound t)))      ; for break out `while' loop
       ;; Add the rest until end of the region to be copied.
       (when (< (point) transform-end)
        (setq return-content
@@ -170,6 +171,6 @@ the structure of the Org file."
 (add-hook 'eww-mode-hook #'org-eww-extend-eww-keymap)
 
 
-(provide 'org-eww)
+(provide 'ol-eww)
 
-;;; org-eww.el ends here
+;;; ol-eww.el ends here
diff --git a/lisp/org/org-gnus.el b/lisp/org/ol-gnus.el
similarity index 90%
rename from lisp/org/org-gnus.el
rename to lisp/org/ol-gnus.el
index 15e9564..8ac36f0 100644
--- a/lisp/org/org-gnus.el
+++ b/lisp/org/ol-gnus.el
@@ -1,4 +1,4 @@
-;;; org-gnus.el --- Support for Links to Gnus Groups and Messages -*- 
lexical-binding: t; -*-
+;;; ol-gnus.el --- Links to Gnus Groups and Messages -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
 
@@ -35,7 +35,7 @@
 (require 'gnus-util)
 (require 'nnheader)
 (require 'nnir)
-(require 'org)
+(require 'ol)
 
 
 ;;; Declare external functions and variables
@@ -104,6 +104,7 @@ If `org-store-link' was called with a prefix arg the 
meaning of
 
 (defun org-gnus-article-link (group newsgroups message-id x-no-archive)
   "Create a link to a Gnus article.
+
 The article is specified by its MESSAGE-ID.  Additional
 parameters are the Gnus GROUP, the NEWSGROUPS the article was
 posted to and the X-NO-ARCHIVE header value of that article.
@@ -115,12 +116,12 @@ Otherwise create a link to the article inside Gnus.
 If `org-store-link' was called with a prefix arg the meaning of
 `org-gnus-prefer-web-links' is reversed."
   (if (and (org-xor current-prefix-arg org-gnus-prefer-web-links)
-          newsgroups     ;; Make web links only for nntp groups
-          (not x-no-archive)) ;; and if X-No-Archive isn't set.
-      (format (if (string-match "gmane\\." newsgroups)
+          newsgroups             ;make web links only for nntp groups
+          (not x-no-archive))    ;and if X-No-Archive isn't set
+      (format (if (string-match-p "gmane\\." newsgroups)
                  "http://mid.gmane.org/%s";
                "http://groups.google.com/groups/search?as_umsgid=%s";)
-             (org-fixup-message-id-for-http message-id))
+             (url-encode-url message-id))
     (concat "gnus:" group "#" message-id)))
 
 (defun org-gnus-store-link ()
@@ -129,9 +130,9 @@ If `org-store-link' was called with a prefix arg the 
meaning of
     (`gnus-group-mode
      (let ((group (gnus-group-group-name)))
        (when group
-        (org-store-link-props :type "gnus" :group group)
+        (org-link-store-props :type "gnus" :group group)
         (let ((description (org-gnus-group-link group)))
-          (org-add-link-props :link description :description description)
+          (org-link-add-props :link description :description description)
           description))))
     ((or `gnus-summary-mode `gnus-article-mode)
      (let* ((group
@@ -169,12 +170,12 @@ If `org-store-link' was called with a prefix arg the 
meaning of
         (setq to (or to (gnus-fetch-original-field "To")))
         (setq newsgroups (gnus-fetch-original-field "Newsgroups"))
         (setq x-no-archive (gnus-fetch-original-field "x-no-archive")))
-       (org-store-link-props :type "gnus" :from from :date date :subject 
subject
+       (org-link-store-props :type "gnus" :from from :date date :subject 
subject
                             :message-id message-id :group group :to to)
        (let ((link (org-gnus-article-link
                    group newsgroups message-id x-no-archive))
-            (description (org-email-link-description)))
-        (org-add-link-props :link link :description description)
+            (description (org-link-email-description)))
+        (org-link-add-props :link link :description description)
         link)))
     (`message-mode
      (setq org-store-link-plist nil)   ;reset
@@ -197,11 +198,11 @@ If `org-store-link' was called with a prefix arg the 
meaning of
               (subject (mail-fetch-field "Subject"))
               newsgroup xarchive)      ;those are always nil for gcc
           (unless gcc (error "Can not create link: No Gcc header found"))
-          (org-store-link-props :type "gnus" :from from :subject subject
+          (org-link-store-props :type "gnus" :from from :subject subject
                                 :message-id id :group gcc :to to)
           (let ((link (org-gnus-article-link gcc newsgroup id xarchive))
-                (description (org-email-link-description)))
-            (org-add-link-props :link link :description description)
+                (description (org-link-email-description)))
+            (org-link-add-props :link link :description description)
             link)))))))
 
 (defun org-gnus-open-nntp (path)
@@ -242,7 +243,11 @@ If `org-store-link' was called with a prefix arg the 
meaning of
              (_
               (let ((articles 1)
                     group-opened)
-                (while (not group-opened)
+                (while (and (not group-opened)
+                            ;; Stop on integer overflows.  Note: We
+                            ;; can drop this once we require at least
+                            ;; Emacs 27, which supports bignums.
+                            (> articles 0))
                   (setq group-opened (gnus-group-read-group articles t group))
                   (setq articles (if (< articles 16)
                                      (1+ articles)
@@ -260,7 +265,6 @@ If `org-store-link' was called with a prefix arg the 
meaning of
        (org-gnus-no-server (gnus-no-server))
        (t (gnus))))
 
-(provide 'org-gnus)
-
+(provide 'ol-gnus)
 
-;;; org-gnus.el ends here
+;;; ol-gnus.el ends here
diff --git a/lisp/org/org-info.el b/lisp/org/ol-info.el
similarity index 94%
rename from lisp/org/org-info.el
rename to lisp/org/ol-info.el
index bfbe42c..d145eae 100644
--- a/lisp/org/org-info.el
+++ b/lisp/org/ol-info.el
@@ -1,4 +1,4 @@
-;;; org-info.el --- Support for Links to Info Nodes -*- lexical-binding: t; -*-
+;;; ol-info.el --- Links to Info Nodes               -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
 
@@ -30,7 +30,7 @@
 
 ;;; Code:
 
-(require 'org)
+(require 'ol)
 
 ;; Declare external functions and variables
 
@@ -54,7 +54,7 @@
                        "#" Info-current-node))
          (desc (concat (file-name-nondirectory Info-current-file)
                        "#" Info-current-node)))
-      (org-store-link-props :type "info" :file Info-current-file
+      (org-link-store-props :type "info" :file Info-current-file
                            :node Info-current-node
                            :link link :desc desc)
       link)))
@@ -66,7 +66,7 @@
 
 (defun org-info-follow-link (name)
   "Follow an Info file and node link specified by NAME."
-  (if (or (string-match "\\(.*\\)[#:]:?\\(.*\\)" name)
+  (if (or (string-match "\\(.*\\)\\(?:#\\|::\\)\\(.*\\)" name)
           (string-match "\\(.*\\)" name))
       (let ((filename (match-string 1 name))
            (nodename-or-index (or (match-string 2 name) "Top")))
@@ -129,7 +129,7 @@ See `org-info-emacs-documents' and 
`org-info-other-documents' for details."
 (defun org-info-export (path desc format)
   "Export an info link.
 See `org-link-parameters' for details about PATH, DESC and FORMAT."
-  (let* ((parts (split-string path "[#:]:?"))
+  (let* ((parts (split-string path "#\\|::"))
         (manual (car parts))
         (node (or (nth 1 parts) "Top")))
     (pcase format
@@ -143,6 +143,6 @@ See `org-link-parameters' for details about PATH, DESC and 
FORMAT."
         (format "@ref{%s,%s,,%s,}" node title manual)))
       (_ nil))))
 
-(provide 'org-info)
+(provide 'ol-info)
 
-;;; org-info.el ends here
+;;; ol-info.el ends here
diff --git a/lisp/org/org-irc.el b/lisp/org/ol-irc.el
similarity index 93%
rename from lisp/org/org-irc.el
rename to lisp/org/ol-irc.el
index 97f093e..d39760b 100644
--- a/lisp/org/org-irc.el
+++ b/lisp/org/ol-irc.el
@@ -1,4 +1,4 @@
-;;; org-irc.el --- Store Links to IRC Sessions -*- lexical-binding: t; -*-
+;;; ol-irc.el --- Links to IRC Sessions              -*- lexical-binding: t; 
-*-
 ;;
 ;; Copyright (C) 2008-2019 Free Software Foundation, Inc.
 ;;
@@ -48,7 +48,7 @@
 
 ;;; Code:
 
-(require 'org)
+(require 'ol)
 
 (declare-function erc-buffer-filter "erc" (predicate &optional proc))
 (declare-function erc-channel-p "erc" (channel))
@@ -73,7 +73,10 @@
 
 ;; Generic functions/config (extend these for other clients)
 
-(org-link-set-parameters "irc" :follow #'org-irc-visit :store 
#'org-irc-store-link)
+(org-link-set-parameters "irc"
+                        :follow #'org-irc-visit
+                        :store #'org-irc-store-link
+                        :export #'org-irc-export)
 
 (defun org-irc-visit (link)
   "Parse LINK and dispatch to the correct function based on the client found."
@@ -152,7 +155,7 @@ the session itself."
             (parsed-line (org-irc-erc-get-line-from-log erc-line)))
        (if (erc-logging-enabled nil)
            (progn
-             (org-store-link-props
+             (org-link-store-props
               :type "file"
               :description (concat "'" (org-irc-ellipsify-description
                                         (cadr parsed-line) 20)
@@ -165,7 +168,7 @@ the session itself."
           (link (org-irc-parse-link link-text)))
       (if link-text
          (progn
-           (org-store-link-props
+           (org-link-store-props
             :type "irc"
             :link (concat "irc:/" link-text)
             :description (concat "irc session `" link-text "'")
@@ -247,10 +250,20 @@ default."
       ;; no server match, make new connection
       (erc-select :server server :port port))))
 
-(provide 'org-irc)
+(defun org-irc-export (link description format)
+  "Export an IRC link.
+See `org-link-parameters' for details about LINK, DESCRIPTION and
+FORMAT."
+  (let ((desc (or description link)))
+    (pcase format
+      (`html (format "<a href=\"irc:%s\">%s</a>" link desc))
+      (`md (format "[%s](irc:%s)" desc link))
+      (_ nil))))
+
+(provide 'ol-irc)
 
 ;; Local variables:
 ;; generated-autoload-file: "org-loaddefs.el"
 ;; End:
 
-;;; org-irc.el ends here
+;;; ol-irc.el ends here
diff --git a/lisp/org/org-mhe.el b/lisp/org/ol-mhe.el
similarity index 95%
rename from lisp/org/org-mhe.el
rename to lisp/org/ol-mhe.el
index a37c41a..b2c163c 100644
--- a/lisp/org/org-mhe.el
+++ b/lisp/org/ol-mhe.el
@@ -1,4 +1,4 @@
-;;; org-mhe.el --- Support for Links to MH-E Messages -*- lexical-binding: t; 
-*-
+;;; ol-mhe.el --- Links to MH-E Messages             -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
 
@@ -31,7 +31,7 @@
 ;;; Code:
 
 (require 'org-macs)
-(require 'org)
+(require 'ol)
 
 ;; Customization variables
 
@@ -88,12 +88,12 @@ supported by MH-E."
             (subject (org-mhe-get-header "Subject:"))
             (date (org-mhe-get-header "Date:"))
             link desc)
-       (org-store-link-props :type "mh" :from from :to to :date date
+       (org-link-store-props :type "mh" :from from :to to :date date
                              :subject subject :message-id message-id)
-       (setq desc (org-email-link-description))
+       (setq desc (org-link-email-description))
        (setq link (concat "mhe:" (org-mhe-get-message-real-folder) "#"
                           (org-unbracket-string "<" ">" message-id)))
-       (org-add-link-props :link link :description desc)
+       (org-link-add-props :link link :description desc)
        link))))
 
 (defun org-mhe-open (path)
@@ -199,7 +199,7 @@ folders."
     (mh-search-choose)
     (if (eq mh-searcher 'pick)
        (progn
-         (setq article (org-add-angle-brackets article))
+         (setq article (org-link-add-angle-brackets article))
          (mh-search folder (list "--message-id" article))
          (when (and org-mhe-search-all-folders
                     (not (org-mhe-get-message-real-folder)))
@@ -214,6 +214,6 @@ folders."
       (kill-buffer)
       (error "Message not found"))))
 
-(provide 'org-mhe)
+(provide 'ol-mhe)
 
-;;; org-mhe.el ends here
+;;; ol-mhe.el ends here
diff --git a/lisp/org/org-rmail.el b/lisp/org/ol-rmail.el
similarity index 92%
rename from lisp/org/org-rmail.el
rename to lisp/org/ol-rmail.el
index c3d941e..a62b917 100644
--- a/lisp/org/org-rmail.el
+++ b/lisp/org/ol-rmail.el
@@ -1,4 +1,4 @@
-;;; org-rmail.el --- Support for Links to Rmail Messages -*- lexical-binding: 
t; -*-
+;;; ol-rmail.el --- Links to Rmail Messages          -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2004-2019 Free Software Foundation, Inc.
 
@@ -30,7 +30,7 @@
 
 ;;; Code:
 
-(require 'org)
+(require 'ol)
 
 ;; Declare external functions and variables
 (declare-function rmail-show-message  "rmail" (&optional n no-summary))
@@ -65,13 +65,13 @@
               (subject (mail-fetch-field "subject"))
               (date (mail-fetch-field "date"))
               desc link)
-         (org-store-link-props
+         (org-link-store-props
           :type "rmail" :from from :to to :date date
           :subject subject :message-id message-id)
          (setq message-id (org-unbracket-string "<" ">" message-id))
-         (setq desc (org-email-link-description))
+         (setq desc (org-link-email-description))
          (setq link (concat "rmail:" folder "#" message-id))
-         (org-add-link-props :link link :description desc)
+         (org-link-add-props :link link :description desc)
          (rmail-show-message rmail-current-message)
          link)))))
 
@@ -89,7 +89,7 @@
   (require 'rmail)
   (cond ((null article) (setq article ""))
        ((stringp article)
-        (setq article (org-add-angle-brackets article)))
+        (setq article (org-link-add-angle-brackets article)))
        (t (user-error "Wrong RMAIL link format")))
   (let (message-number)
     (save-excursion
@@ -110,6 +110,6 @@
          message-number)
       (error "Message not found"))))
 
-(provide 'org-rmail)
+(provide 'ol-rmail)
 
-;;; org-rmail.el ends here
+;;; ol-rmail.el ends here
diff --git a/lisp/org/org-w3m.el b/lisp/org/ol-w3m.el
similarity index 83%
rename from lisp/org/org-w3m.el
rename to lisp/org/ol-w3m.el
index 23fd0f8..046d3b6 100644
--- a/lisp/org/org-w3m.el
+++ b/lisp/org/ol-w3m.el
@@ -1,4 +1,4 @@
-;;; org-w3m.el --- Support from Copy and Paste From w3m -*- lexical-binding: 
t; -*-
+;;; ol-w3m.el --- Copy and Paste From W3M            -*- lexical-binding: t; 
-*-
 
 ;; Copyright (C) 2008-2019 Free Software Foundation, Inc.
 
@@ -41,7 +41,7 @@
 
 ;;; Code:
 
-(require 'org)
+(require 'ol)
 
 (defvar w3m-current-url)
 (defvar w3m-current-title)
@@ -50,7 +50,7 @@
 (defun org-w3m-store-link ()
   "Store a link to a w3m buffer."
   (when (eq major-mode 'w3m-mode)
-    (org-store-link-props
+    (org-link-store-props
      :type "w3m"
      :link w3m-current-url
      :url (url-view-url t)
@@ -59,7 +59,7 @@
 (defun org-w3m-copy-for-org-mode ()
   "Copy current buffer content or active region with Org style links.
 This will encode `link-title' and `link-location' with
-`org-make-link-string', and insert the transformed test into the kill ring,
+`org-link-make-string', and insert the transformed test into the kill ring,
 so that it can be yanked into an Org  buffer with links working correctly."
   (interactive)
   (let* ((regionp (org-region-active-p))
@@ -72,40 +72,41 @@ so that it can be yanked into an Org  buffer with links 
working correctly."
       (setq transform-start (region-beginning))
       (setq transform-end (region-end))
       ;; Deactivate mark if current mark is activate.
-      (if (fboundp 'deactivate-mark) (deactivate-mark)))
+      (when (fboundp 'deactivate-mark) (deactivate-mark)))
     (message "Transforming links...")
     (save-excursion
       (goto-char transform-start)
-      (while (and (not out-bound)                 ; still inside region to copy
+      (while (and (not out-bound)      ; still inside region to copy
                   (not (org-w3m-no-next-link-p))) ; no next link current buffer
         ;; store current point before jump next anchor
         (setq temp-position (point))
         ;; move to next anchor when current point is not at anchor
         (or (get-text-property (point) 'w3m-href-anchor) 
(org-w3m-get-next-link-start))
-        (if (<= (point) transform-end)  ; if point is inside transform bound
+        (if (<= (point) transform-end) ; if point is inside transform bound
             (progn
               ;; get content between two links.
-              (if (> (point) temp-position)
-                  (setq return-content (concat return-content
-                                               (buffer-substring
-                                                temp-position (point)))))
+              (when (> (point) temp-position)
+                (setq return-content (concat return-content
+                                             (buffer-substring
+                                              temp-position (point)))))
               ;; get link location at current point.
               (setq link-location (get-text-property (point) 'w3m-href-anchor))
               ;; get link title at current point.
               (setq link-title (buffer-substring (point)
                                                  (org-w3m-get-anchor-end)))
               ;; concat Org style url to `return-content'.
-              (setq return-content (concat return-content
-                                           (org-make-link-string
-                                            link-location link-title))))
-          (goto-char temp-position)     ; reset point before jump next anchor
-          (setq out-bound t)            ; for break out `while' loop
-          ))
+              (setq return-content
+                   (concat return-content
+                           (if (org-string-nw-p link-location)
+                               (org-link-make-string link-location link-title)
+                             link-title))))
+          (goto-char temp-position) ; reset point before jump next anchor
+          (setq out-bound t)))     ; for break out `while' loop
       ;; add the rest until end of the region to be copied
-      (if (< (point) transform-end)
-          (setq return-content
-                (concat return-content
-                        (buffer-substring (point) transform-end))))
+      (when (< (point) transform-end)
+        (setq return-content
+              (concat return-content
+                      (buffer-substring (point) transform-end))))
       (org-kill-new return-content)
       (message "Transforming links...done, use C-y to insert text into Org 
file")
       (message "Copy with link transformation complete."))))
@@ -178,6 +179,6 @@ Return t if there is no previous link; otherwise, return 
nil."
    (define-key w3m-minor-mode-map "\C-c\C-x\M-w" 'org-w3m-copy-for-org-mode)
    (define-key w3m-minor-mode-map "\C-c\C-x\C-w" 'org-w3m-copy-for-org-mode)))
 
-(provide 'org-w3m)
+(provide 'ol-w3m)
 
-;;; org-w3m.el ends here
+;;; ol-w3m.el ends here
diff --git a/lisp/org/ol.el b/lisp/org/ol.el
new file mode 100644
index 0000000..95a7e91
--- /dev/null
+++ b/lisp/org/ol.el
@@ -0,0 +1,1907 @@
+;;; ol.el --- Org links library                      -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2018  Free Software Foundation, Inc.
+
+;; Author: Carsten Dominik <carsten at orgmode dot org>
+;; Keywords: outlines, hypermedia, calendar, wp
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides tooling to handle both external and internal
+;; links.
+
+;;; Code:
+
+(require 'org-compat)
+(require 'org-macs)
+
+(defvar clean-buffer-list-kill-buffer-names)
+(defvar org-agenda-buffer-name)
+(defvar org-comment-string)
+(defvar org-highlight-links)
+(defvar org-id-link-to-org-use-id)
+(defvar org-inhibit-startup)
+(defvar org-outline-regexp-bol)
+(defvar org-src-source-file-name)
+(defvar org-time-stamp-formats)
+(defvar org-ts-regexp)
+
+(declare-function calendar-cursor-to-date "calendar" (&optional error event))
+(declare-function dired-get-filename "dired" (&optional localp 
no-error-if-not-filep))
+(declare-function org-at-heading-p "org" (&optional _))
+(declare-function org-back-to-heading "org" (&optional invisible-ok))
+(declare-function org-do-occur "org" (regexp &optional cleanup))
+(declare-function org-element-at-point "org-element" ())
+(declare-function org-element-cache-refresh "org-element" (pos))
+(declare-function org-element-context "org-element" (&optional element))
+(declare-function org-element-lineage "org-element" (datum &optional types 
with-self))
+(declare-function org-element-link-parser "org-element" ())
+(declare-function org-element-property "org-element" (property element))
+(declare-function org-element-type "org-element" (element))
+(declare-function org-element-update-syntax "org-element" ())
+(declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
+(declare-function org-find-property "org" (property &optional value))
+(declare-function org-get-heading "org" (&optional no-tags no-todo no-priority 
no-comment))
+(declare-function org-heading-components "org" ())
+(declare-function org-id-find-id-file "org-id" (id))
+(declare-function org-id-store-link "org-id" ())
+(declare-function org-insert-heading "org" (&optional arg invisible-ok top))
+(declare-function org-load-modules-maybe "org" (&optional force))
+(declare-function org-mark-ring-push "org" (&optional pos buffer))
+(declare-function org-occur "org" (regexp &optional keep-previous callback))
+(declare-function org-open-file "org" (path &optional in-emacs line search))
+(declare-function org-overview "org" ())
+(declare-function org-restart-font-lock "org" ())
+(declare-function org-show-context "org" (&optional key))
+(declare-function org-src-coderef-format "org-src" (&optional element))
+(declare-function org-src-coderef-regexp "org-src" (fmt &optional label))
+(declare-function org-src-edit-buffer-p "org-src" (&optional buffer))
+(declare-function org-src-source-buffer "org-src" ())
+(declare-function org-src-source-type "org-src" ())
+(declare-function org-time-stamp-format "org" (&optional long inactive))
+(declare-function outline-next-heading "outline" ())
+
+
+;;; Customization
+
+(defgroup org-link nil
+  "Options concerning links in Org mode."
+  :tag "Org Link"
+  :group 'org)
+
+(defcustom org-link-parameters nil
+  "An alist of properties that defines all the links in Org mode.
+The key in each association is a string of the link type.
+Subsequent optional elements make up a plist of link properties.
+
+:follow - A function that takes the link path as an argument.
+
+:export - A function that takes the link path, description and
+export-backend as arguments.
+
+:store - A function responsible for storing the link.  See the
+function `org-store-link-functions'.
+
+:complete - A function that inserts a link with completion.  The
+function takes one optional prefix argument.
+
+:face - A face for the link, or a function that returns a face.
+The function takes one argument which is the link path.  The
+default face is `org-link'.
+
+:mouse-face - The mouse-face. The default is `highlight'.
+
+:display - `full' will not fold the link in descriptive
+display.  Default is `org-link'.
+
+:help-echo - A string or function that takes (window object position)
+as arguments and returns a string.
+
+:keymap - A keymap that is active on the link.  The default is
+`org-mouse-map'.
+
+:htmlize-link - A function for the htmlize-link.  Defaults
+to (list :uri \"type:path\")
+
+:activate-func - A function to run at the end of font-lock
+activation.  The function must accept (link-start link-end path bracketp)
+as arguments."
+  :group 'org-link
+  :package-version '(Org . "9.1")
+  :type '(alist :tag "Link display parameters"
+               :value-type plist)
+  :safe nil)
+
+(defcustom org-link-descriptive t
+  "Non-nil means Org displays descriptive links.
+
+E.g. [[https://orgmode.org][Org website]] is be displayed as
+\"Org Website\", hiding the link itself and just displaying its
+description.  When set to nil, Org displays the full links
+literally.
+
+You can interactively set the value of this variable by calling
+`org-toggle-link-display' or from the \"Org > Hyperlinks\" menu."
+  :group 'org-link
+  :type 'boolean
+  :safe #'booleanp)
+
+(defcustom org-link-make-description-function nil
+  "Function to use for generating link descriptions from links.
+This function must take two parameters: the first one is the
+link, the second one is the description generated by
+`org-insert-link'.  The function should return the description to
+use."
+  :group 'org-link
+  :type '(choice (const nil) (function))
+  :safe #'null)
+
+(defcustom org-link-file-path-type 'adaptive
+  "How the path name in file links should be stored.
+Valid values are:
+
+relative  Relative to the current directory, i.e. the directory of the file
+          into which the link is being inserted.
+absolute  Absolute path, if possible with ~ for home directory.
+noabbrev  Absolute path, no abbreviation of home directory.
+adaptive  Use relative path for files in the current directory and sub-
+          directories of it.  For other files, use an absolute path."
+  :group 'org-link
+  :type '(choice
+         (const relative)
+         (const absolute)
+         (const noabbrev)
+         (const adaptive))
+  :safe #'symbolp)
+
+(defcustom org-link-abbrev-alist nil
+  "Alist of link abbreviations.
+The car of each element is a string, to be replaced at the start of a link.
+The cdrs are replacement values, like (\"linkkey\" . REPLACE).  Abbreviated
+links in Org buffers can have an optional tag after a double colon, e.g.,
+
+     [[linkkey:tag][description]]
+
+The `linkkey' must be a single word, starting with a letter, followed
+by letters, numbers, `-' or `_'.
+
+If REPLACE is a string, the tag will simply be appended to create the link.
+If the string contains \"%s\", the tag will be inserted there.  If the string
+contains \"%h\", it will cause a url-encoded version of the tag to be inserted
+at that point (see the function `url-hexify-string').  If the string contains
+the specifier \"%(my-function)\", then the custom function `my-function' will
+be invoked: this function takes the tag as its only argument and must return
+a string.
+
+REPLACE may also be a function that will be called with the tag as the
+only argument to create the link, which should be returned as a string.
+
+See the manual for examples."
+  :group 'org-link
+  :type '(repeat
+         (cons (string :tag "Protocol")
+               (choice
+                (string :tag "Format")
+                (function))))
+  :safe (lambda (val)
+         (pcase val
+           (`(,(pred stringp) . ,(pred stringp)) t)
+           (_ nil))))
+
+(defgroup org-link-follow nil
+  "Options concerning following links in Org mode."
+  :tag "Org Follow Link"
+  :group 'org-link)
+
+(defcustom org-link-translation-function nil
+  "Function to translate links with different syntax to Org syntax.
+This can be used to translate links created for example by the Planner
+or emacs-wiki packages to Org syntax.
+The function must accept two parameters, a TYPE containing the link
+protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
+which is everything after the link protocol.  It should return a cons
+with possibly modified values of type and path.
+Org contains a function for this, so if you set this variable to
+`org-translate-link-from-planner', you should be able follow many
+links created by planner."
+  :group 'org-link-follow
+  :type '(choice (const nil) (function))
+  :safe #'null)
+
+(defcustom org-link-doi-server-url "https://doi.org/";
+  "The URL of the DOI server."
+  :group 'org-link-follow
+  :version "24.3"
+  :type 'string
+  :safe #'stringp)
+
+(defcustom org-link-frame-setup
+  '((vm . vm-visit-folder-other-frame)
+    (vm-imap . vm-visit-imap-folder-other-frame)
+    (gnus . org-gnus-no-new-news)
+    (file . find-file-other-window)
+    (wl . wl-other-frame))
+  "Setup the frame configuration for following links.
+When following a link with Emacs, it may often be useful to display
+this link in another window or frame.  This variable can be used to
+set this up for the different types of links.
+For VM, use any of
+    `vm-visit-folder'
+    `vm-visit-folder-other-window'
+    `vm-visit-folder-other-frame'
+For Gnus, use any of
+    `gnus'
+    `gnus-other-frame'
+    `org-gnus-no-new-news'
+For FILE, use any of
+    `find-file'
+    `find-file-other-window'
+    `find-file-other-frame'
+For Wanderlust use any of
+    `wl'
+    `wl-other-frame'
+For the calendar, use the variable `calendar-setup'.
+For BBDB, it is currently only possible to display the matches in
+another window."
+  :group 'org-link-follow
+  :type '(list
+         (cons (const vm)
+               (choice
+                (const vm-visit-folder)
+                (const vm-visit-folder-other-window)
+                (const vm-visit-folder-other-frame)))
+         (cons (const vm-imap)
+               (choice
+                (const vm-visit-imap-folder)
+                (const vm-visit-imap-folder-other-window)
+                (const vm-visit-imap-folder-other-frame)))
+         (cons (const gnus)
+               (choice
+                (const gnus)
+                (const gnus-other-frame)
+                (const org-gnus-no-new-news)))
+         (cons (const file)
+               (choice
+                (const find-file)
+                (const find-file-other-window)
+                (const find-file-other-frame)))
+         (cons (const wl)
+               (choice
+                (const wl)
+                (const wl-other-frame))))
+  :safe nil)
+
+(defcustom org-link-search-must-match-exact-headline 'query-to-create
+  "Non-nil means internal fuzzy links can only match headlines.
+
+When nil, the a fuzzy link may point to a target or a named
+construct in the document.  When set to the special value
+`query-to-create', offer to create a new headline when none
+matched.
+
+Spaces and statistics cookies are ignored during heading searches."
+  :group 'org-link-follow
+  :version "24.1"
+  :type '(choice
+         (const :tag "Use fuzzy text search" nil)
+         (const :tag "Match only exact headline" t)
+         (const :tag "Match exact headline or query to create it"
+                query-to-create))
+  :safe #'symbolp)
+
+(defcustom org-link-use-indirect-buffer-for-internals nil
+  "Non-nil means use indirect buffer to display infile links.
+Activating internal links (from one location in a file to another location
+in the same file) normally just jumps to the location.  When the link is
+activated with a `\\[universal-argument]' prefix (or with mouse-3), the link \
+is displayed in
+another window.  When this option is set, the other window actually displays
+an indirect buffer clone of the current buffer, to avoid any visibility
+changes to the current buffer."
+  :group 'org-link-follow
+  :type 'boolean
+  :safe #'booleanp)
+
+(defcustom org-link-shell-confirm-function 'yes-or-no-p
+  "Non-nil means ask for confirmation before executing shell links.
+
+Shell links can be dangerous: just think about a link
+
+     [[shell:rm -rf ~/*][Google Search]]
+
+This link would show up in your Org document as \"Google Search\",
+but really it would remove your entire home directory.
+Therefore we advise against setting this variable to nil.
+Just change it to `y-or-n-p' if you want to confirm with a
+single keystroke rather than having to type \"yes\"."
+  :group 'org-link-follow
+  :type '(choice
+         (const :tag "with yes-or-no (safer)" yes-or-no-p)
+         (const :tag "with y-or-n (faster)" y-or-n-p)
+         (const :tag "no confirmation (dangerous)" nil))
+  :safe nil)
+
+(defcustom org-link-shell-skip-confirm-regexp ""
+  "Regexp to skip confirmation for shell links."
+  :group 'org-link-follow
+  :version "24.1"
+  :type 'regexp
+  :safe nil)
+
+(defcustom org-link-elisp-confirm-function 'yes-or-no-p
+  "Non-nil means ask for confirmation before executing Emacs Lisp links.
+Elisp links can be dangerous: just think about a link
+
+     [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
+
+This link would show up in your Org document as \"Google Search\",
+but really it would remove your entire home directory.
+Therefore we advise against setting this variable to nil.
+Just change it to `y-or-n-p' if you want to confirm with a
+single keystroke rather than having to type \"yes\"."
+  :group 'org-link-follow
+  :type '(choice
+         (const :tag "with yes-or-no (safer)" yes-or-no-p)
+         (const :tag "with y-or-n (faster)" y-or-n-p)
+         (const :tag "no confirmation (dangerous)" nil))
+  :safe nil)
+
+(defcustom org-link-elisp-skip-confirm-regexp ""
+  "A regexp to skip confirmation for Elisp links."
+  :group 'org-link-follow
+  :version "24.1"
+  :type 'regexp
+  :safe nil)
+
+(defgroup org-link-store nil
+  "Options concerning storing links in Org mode."
+  :tag "Org Store Link"
+  :group 'org-link)
+
+(defcustom org-link-context-for-files t
+  "Non-nil means file links from `org-store-link' contain context.
+\\<org-mode-map>
+A search string is 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'.  When this option is t, the entire active region
+is be placed in the search string of the file link.  If set to a
+positive integer N, only the first N lines of context are stored.
+
+Using a prefix argument to the command `org-store-link' \
+\(`\\[universal-argument] \\[org-store-link]')
+negates this setting for the duration of the command."
+  :group 'org-link-store
+  :type '(choice boolean integer)
+  :safe (lambda (val) (or (booleanp val) (integerp val))))
+
+(defcustom org-link-email-description-format "Email %c: %s"
+  "Format of the description part of a link to an email or usenet message.
+The following %-escapes will be replaced by corresponding information:
+
+%F   full \"From\" field
+%f   name, taken from \"From\" field, address if no name
+%T   full \"To\" field
+%t   first name in \"To\" field, address if no name
+%c   correspondent.  Usually \"from NAME\", but if you sent it yourself, it
+     will be \"to NAME\".  See also the variable `org-from-is-user-regexp'.
+%s   subject
+%d   date
+%m   message-id.
+
+You may use normal field width specification between the % and the letter.
+This is for example useful to limit the length of the subject.
+
+Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
+  :group 'org-link-store
+  :package-version '(Org . 9.3)
+  :type 'string
+  :safe #'stringp)
+
+(defcustom org-link-from-user-regexp
+  (let ((mail (and (org-string-nw-p user-mail-address)
+                  (format "\\<%s\\>" (regexp-quote user-mail-address))))
+       (name (and (org-string-nw-p user-full-name)
+                  (format "\\<%s\\>" (regexp-quote user-full-name)))))
+    (if (and mail name) (concat mail "\\|" name) (or mail name)))
+  "Regexp matched against the \"From:\" header of an email or Usenet message.
+It should match if the message is from the user him/herself."
+  :group 'org-link-store
+  :type 'regexp
+  :safe #'stringp)
+
+(defcustom org-link-keep-stored-after-insertion nil
+  "Non-nil means keep link in list for entire session.
+\\<org-mode-map>
+The command `org-store-link' adds a link pointing to the current
+location to an internal list.  These links accumulate during a session.
+The command `org-insert-link' can be used to insert links into any
+Org file (offering completion for all stored links).
+
+When this option is nil, every link which has been inserted once using
+`\\[org-insert-link]' will be removed from the list, to make completing the \
+unused
+links more efficient."
+  :group 'org-link-store
+  :type 'boolean
+  :safe #'booleanp)
+
+;;; Public variables
+
+(defconst org-target-regexp (let ((border "[^<>\n\r \t]"))
+                             (format "<<\\(%s\\|%s[^<>\n\r]*%s\\)>>"
+                                     border border border))
+  "Regular expression matching a link target.")
+
+(defconst org-radio-target-regexp (format "<%s>" org-target-regexp)
+  "Regular expression matching a radio target.")
+
+(defvar-local org-target-link-regexp nil
+  "Regular expression matching radio targets in plain text.")
+
+(defvar org-link-types-re nil
+  "Matches a link that has a url-like prefix like \"http:\"")
+
+(defvar org-link-angle-re nil
+  "Matches link with angular brackets, spaces are allowed.")
+
+(defvar org-link-plain-re nil
+  "Matches plain link, without spaces.")
+
+(defvar org-link-bracket-re nil
+  "Matches a link in double brackets.")
+
+(defvar org-link-any-re nil
+  "Regular expression matching any link.")
+
+(defvar-local org-link-abbrev-alist-local nil
+  "Buffer-local version of `org-link-abbrev-alist', which see.
+The value of this is taken from the LINK keywords.")
+
+(defvar org-stored-links nil
+  "Contains the links stored with `org-store-link'.")
+
+(defvar org-store-link-plist nil
+  "Plist with info about the most recently link created with 
`org-store-link'.")
+
+(defvar org-create-file-search-functions nil
+  "List of functions to construct the right search string for a file link.
+
+These functions are called in turn with point at the location to
+which the link should point.
+
+A function in the hook should first test if it would like to
+handle this file type, for example by checking the `major-mode'
+or the file extension.  If it decides not to handle this file, it
+should just return nil to give other functions a chance.  If it
+does handle the file, it must return the search string to be used
+when following the link.  The search string will be part of the
+file link, given after a double colon, and `org-open-at-point'
+will automatically search for it.  If special measures must be
+taken to make the search successful, another function should be
+added to the companion hook `org-execute-file-search-functions',
+which see.
+
+A function in this hook may also use `setq' to set the variable
+`description' to provide a suggestion for the descriptive text to
+be used for this link when it gets inserted into an Org buffer
+with \\[org-insert-link].")
+
+(defvar org-execute-file-search-functions nil
+  "List of functions to execute a file search triggered by a link.
+
+Functions added to this hook must accept a single argument, the
+search string that was part of the file link, the part after the
+double colon.  The function must first check if it would like to
+handle this search, for example by checking the `major-mode' or
+the file extension.  If it decides not to handle this search, it
+should just return nil to give other functions a chance.  If it
+does handle the search, it must return a non-nil value to keep
+other functions from trying.
+
+Each function can access the current prefix argument through the
+variable `current-prefix-arg'.  Note that a single prefix is used
+to force opening a link in Emacs, so it may be good to only use a
+numeric or double prefix to guide the search function.
+
+In case this is needed, a function in this hook can also restore
+the window configuration before `org-open-at-point' was called using:
+
+    (set-window-configuration org-window-config-before-follow-link)")
+
+(defvar org-open-link-functions nil
+  "Hook for functions finding a plain text link.
+These functions must take a single argument, the link content.
+They will be called for links that look like [[link text][description]]
+when LINK TEXT does not have a protocol like \"http:\" and does not look
+like a filename (e.g. \"./blue.png\").
+
+These functions will be called *before* Org attempts to resolve the
+link by doing text searches in the current buffer - so if you want a
+link \"[[target]]\" to still find \"<<target>>\", your function should
+handle this as a special case.
+
+When the function does handle the link, it must return a non-nil value.
+If it decides that it is not responsible for this link, it must return
+nil to indicate that that Org can continue with other options like
+exact and fuzzy text search.")
+
+
+;;; Internal Variables
+
+(defconst org-link--forbidden-chars "]\t\n\r<>"
+  "Characters forbidden within a link, as a string.")
+
+(defvar org-link--history nil
+  "History for inserted links.")
+
+(defvar org-link--insert-history nil
+  "Minibuffer history for links inserted with `org-insert-link'.")
+
+(defvar org-link--search-failed nil
+  "Non-nil when last link search failed.")
+
+
+;;; Internal Functions
+
+(defun org-link--try-special-completion (type)
+  "If there is completion support for link type TYPE, offer it."
+  (let ((fun (org-link-get-parameter type :complete)))
+    (if (functionp fun)
+       (funcall fun)
+      (read-string "Link (no completion support): " (concat type ":")))))
+
+(defun org-link--prettify (link)
+  "Return a human-readable representation of LINK.
+The car of LINK must be a raw link.  The cdr of LINK must be
+either a link description or nil."
+  (let ((desc (or (cadr link) "<no description>")))
+    (concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
+           "<" (car link) ">")))
+
+(defun org-link--decode-compound (hex)
+  "Unhexify Unicode hex-chars HEX.
+E.g. \"%C3%B6\" is the German o-Umlaut.  Note: this function also
+decodes single byte encodings like \"%E1\" (a-acute) if not
+followed by another \"%[A-F0-9]{2}\" group."
+  (save-match-data
+    (let* ((bytes (cdr (split-string hex "%")))
+          (ret "")
+          (eat 0)
+          (sum 0))
+      (while bytes
+       (let* ((val (string-to-number (pop bytes) 16))
+              (shift-xor
+               (if (= 0 eat)
+                   (cond
+                    ((>= val 252) (cons 6 252))
+                    ((>= val 248) (cons 5 248))
+                    ((>= val 240) (cons 4 240))
+                    ((>= val 224) (cons 3 224))
+                    ((>= val 192) (cons 2 192))
+                    (t (cons 0 0)))
+                 (cons 6 128))))
+         (when (>= val 192) (setq eat (car shift-xor)))
+         (setq val (logxor val (cdr shift-xor)))
+         (setq sum (+ (lsh sum (car shift-xor)) val))
+         (when (> eat 0) (setq eat (- eat 1)))
+         (cond
+          ((= 0 eat)                   ;multi byte
+           (setq ret (concat ret (char-to-string sum)))
+           (setq sum 0))
+          ((not bytes)                 ; single byte(s)
+           (setq ret (org-link--decode-single-byte-sequence hex))))))
+      ret)))
+
+(defun org-link--decode-single-byte-sequence (hex)
+  "Unhexify hex-encoded single byte character sequence HEX."
+  (mapconcat (lambda (byte)
+              (char-to-string (string-to-number byte 16)))
+            (cdr (split-string hex "%"))
+            ""))
+
+(defun org-link--fontify-links-to-this-file ()
+  "Fontify links to the current file in `org-stored-links'."
+  (let ((f (buffer-file-name)) a b)
+    (setq a (mapcar (lambda(l)
+                     (let ((ll (car l)))
+                       (when (and (string-match "^file:\\(.+\\)::" ll)
+                                  (equal f (expand-file-name (match-string 1 
ll))))
+                         ll)))
+                   org-stored-links))
+    (when (featurep 'org-id)
+      (setq b (mapcar (lambda(l)
+                       (let ((ll (car l)))
+                         (when (and (string-match "^id:\\(.+\\)$" ll)
+                                    (equal f (expand-file-name
+                                              (or (org-id-find-id-file
+                                                   (match-string 1 ll)) ""))))
+                           ll)))
+                     org-stored-links)))
+    (mapcar (lambda(l)
+             (put-text-property 0 (length l) 'face 'font-lock-comment-face l))
+           (delq nil (append a b)))))
+
+(defun org-link--buffer-for-internals ()
+  "Return buffer used for displaying the target of internal links."
+  (cond
+   ((not org-link-use-indirect-buffer-for-internals) (current-buffer))
+   ((string-suffix-p "(Clone)" (buffer-name))
+    (message "Buffer is already a clone, not making another one")
+    ;; We also do not modify visibility in this case.
+    (current-buffer))
+   (t             ;make a new indirect buffer for displaying the link
+    (let* ((indirect-buffer-name (concat (buffer-name) "(Clone)"))
+          (indirect-buffer
+           (or (get-buffer indirect-buffer-name)
+               (make-indirect-buffer (current-buffer)
+                                     indirect-buffer-name
+                                     'clone))))
+      (with-current-buffer indirect-buffer (org-overview))
+      indirect-buffer))))
+
+(defun org-link--search-radio-target (target)
+  "Search a radio target matching TARGET in current buffer.
+White spaces are not significant."
+  (let ((re (format "<<<%s>>>"
+                   (mapconcat #'regexp-quote
+                              (split-string target)
+                              "[ \t]+\\(?:\n[ \t]*\\)?")))
+       (origin (point)))
+    (goto-char (point-min))
+    (catch :radio-match
+      (while (re-search-forward re nil t)
+       (forward-char -1)
+       (let ((object (org-element-context)))
+         (when (eq (org-element-type object) 'radio-target)
+           (goto-char (org-element-property :begin object))
+           (org-show-context 'link-search)
+           (throw :radio-match nil))))
+      (goto-char origin)
+      (user-error "No match for radio target: %s" target))))
+
+
+;;; Public API
+
+(defun org-link-types ()
+  "Return a list of known link types."
+  (mapcar #'car org-link-parameters))
+
+(defun org-link-get-parameter (type key)
+  "Get TYPE link property for KEY.
+TYPE is a string and KEY is a plist keyword.  See
+`org-link-parameters' for supported keywords."
+  (plist-get (cdr (assoc type org-link-parameters))
+            key))
+
+(defun org-link-set-parameters (type &rest parameters)
+  "Set link TYPE properties to PARAMETERS.
+PARAMETERS should be keyword value pairs.  See
+`org-link-parameters' for supported keys."
+  (let ((data (assoc type org-link-parameters)))
+    (if data (setcdr data (org-combine-plists (cdr data) parameters))
+      (push (cons type parameters) org-link-parameters)
+      (org-link-make-regexps)
+      (when (featurep 'org-element) (org-element-update-syntax)))))
+
+(defun org-link-make-regexps ()
+  "Update the link regular expressions.
+This should be called after the variable `org-link-parameters' has changed."
+  (let ((types-re (regexp-opt (org-link-types) t)))
+    (setq org-link-types-re
+         (concat "\\`" types-re ":")
+         org-link-angle-re
+         (format "<%s:\\([^>\n]*\\(?:\n[ \t]*[^> \t\n][^>\n]*\\)*\\)>"
+                 types-re)
+         org-link-plain-re
+         (concat
+          "\\<" types-re ":"
+          "\\([^][ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] 
\t\n]\\|/\\)\\)\\)")
+         ;;     "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
+         org-link-bracket-re
+         (rx (seq "[["
+                  ;; URI part: match group 1.
+                  (group
+                   ;; Allow an even number of backslashes right
+                   ;; before the closing bracket.
+                   (or (one-or-more "\\\\")
+                       (and (*? anything)
+                            (not (any "\\"))
+                            (zero-or-more "\\\\"))))
+                  "]"
+                  ;; Description (optional): match group 2.
+                  (opt "[" (group (+? anything)) "]")
+                  "]"))
+         org-link-any-re
+         (concat "\\(" org-link-bracket-re "\\)\\|\\("
+                 org-link-angle-re "\\)\\|\\("
+                 org-link-plain-re "\\)"))))
+
+(defun org-link-complete-file (&optional arg)
+  "Create a file link using completion."
+  (let ((file (read-file-name "File: "))
+       (pwd (file-name-as-directory (expand-file-name ".")))
+       (pwd1 (file-name-as-directory (abbreviate-file-name
+                                      (expand-file-name ".")))))
+    (cond ((equal arg '(16))
+          (concat "file:"
+                  (abbreviate-file-name (expand-file-name file))))
+         ((string-match
+           (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
+          (concat "file:" (match-string 1 file)))
+         ((string-match
+           (concat "^" (regexp-quote pwd) "\\(.+\\)")
+           (expand-file-name file))
+          (concat "file:"
+                  (match-string 1 (expand-file-name file))))
+         (t (concat "file:" file)))))
+
+(defun org-link-email-description (&optional fmt)
+  "Return the description part of an email link.
+This takes information from `org-store-link-plist' and formats it
+according to FMT (default from `org-link-email-description-format')."
+  (setq fmt (or fmt org-link-email-description-format))
+  (let* ((p org-store-link-plist)
+        (to (plist-get p :toaddress))
+        (from (plist-get p :fromaddress))
+        (table
+         (list
+          (cons "%c" (plist-get p :fromto))
+          (cons "%F" (plist-get p :from))
+          (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) 
"?"))
+          (cons "%T" (plist-get p :to))
+          (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
+          (cons "%s" (plist-get p :subject))
+          (cons "%d" (plist-get p :date))
+          (cons "%m" (plist-get p :message-id)))))
+    (when (string-match "%c" fmt)
+      ;; Check if the user wrote this message
+      (if (and org-link-from-user-regexp from to
+              (save-match-data (string-match org-link-from-user-regexp from)))
+         (setq fmt (replace-match "to %t" t t fmt))
+       (setq fmt (replace-match "from %f" t t fmt))))
+    (org-replace-escapes fmt table)))
+
+(defun org-link-store-props (&rest plist)
+  "Store link properties.
+The properties are pre-processed by extracting names, addresses
+and dates."
+  (let ((x (plist-get plist :from)))
+    (when x
+      (let ((adr (mail-extract-address-components x)))
+       (setq plist (plist-put plist :fromname (car adr)))
+       (setq plist (plist-put plist :fromaddress (nth 1 adr))))))
+  (let ((x (plist-get plist :to)))
+    (when x
+      (let ((adr (mail-extract-address-components x)))
+       (setq plist (plist-put plist :toname (car adr)))
+       (setq plist (plist-put plist :toaddress (nth 1 adr))))))
+  (let ((x (ignore-errors (date-to-time (plist-get plist :date)))))
+    (when x
+      (setq plist (plist-put plist :date-timestamp
+                            (format-time-string
+                             (org-time-stamp-format t) x)))
+      (setq plist (plist-put plist :date-timestamp-inactive
+                            (format-time-string
+                             (org-time-stamp-format t t) x)))))
+  (let ((from (plist-get plist :from))
+       (to (plist-get plist :to)))
+    (when (and from to org-link-from-user-regexp)
+      (setq plist
+           (plist-put plist :fromto
+                      (if (string-match org-link-from-user-regexp from)
+                          (concat "to %t")
+                        (concat "from %f"))))))
+  (setq org-store-link-plist plist))
+
+(defun org-link-add-props (&rest plist)
+  "Add these properties to the link property list."
+  (let (key value)
+    (while plist
+      (setq key (pop plist) value (pop plist))
+      (setq org-store-link-plist
+           (plist-put org-store-link-plist key value)))))
+
+(defun org-link-encode (text table)
+  "Return percent escaped representation of string TEXT.
+TEXT is a string with the text to escape. TABLE is a list of
+characters that should be escaped."
+  (mapconcat
+   (lambda (c)
+     (if (memq c table)
+        (mapconcat (lambda (e) (format "%%%.2X" e))
+                   (or (encode-coding-char c 'utf-8)
+                       (error "Unable to percent escape character: %c" c))
+                   "")
+       (char-to-string c)))
+   text ""))
+
+(defun org-link-decode (s)
+  "Decode percent-encoded parts in string S.
+E.g. \"%C3%B6\" becomes the german o-Umlaut."
+  (replace-regexp-in-string "\\(%[0-9A-Za-z]\\{2\\}\\)+"
+                           #'org-link--decode-compound s t t))
+
+(defun org-link-escape (link)
+  "Backslash-escape sensitive characters in string LINK."
+  ;; Escape closing square brackets followed by another square bracket
+  ;; or at the end of the link.  Also escape final backslashes so that
+  ;; we do not escape inadvertently URI's closing bracket.
+  (with-temp-buffer
+    (insert link)
+    (insert (make-string (- (skip-chars-backward "\\\\"))
+                        ?\\))
+    (while (search-backward "\]" nil t)
+      (when (looking-at-p "\\]\\(?:[][]\\|\\'\\)")
+       (insert (make-string (1+ (- (skip-chars-backward "\\\\")))
+                            ?\\))))
+    (buffer-string)))
+
+(defun org-link-unescape (link)
+  "Remove escaping backslash characters from string LINK."
+  (with-temp-buffer
+    (save-excursion (insert link))
+    (while (re-search-forward "\\(\\\\+\\)\\]\\(?:[][]\\|\\'\\)" nil t)
+      (replace-match (make-string (/ (- (match-end 1) (match-beginning 1)) 2)
+                                 ?\\)
+                    nil t nil 1))
+    (goto-char (point-max))
+    (delete-char (/ (- (skip-chars-backward "\\\\")) 2))
+    (buffer-string)))
+
+(defun org-link-make-string (link &optional description)
+  "Make a bracket link, consisting of LINK and DESCRIPTION.
+LINK is escaped with backslashes for inclusion in buffer."
+  (unless (org-string-nw-p link) (error "Empty link"))
+  (let* ((uri (org-link-escape link))
+        (zero-width-space (string ?\x200B))
+        (description
+         (and (org-string-nw-p description)
+              ;; Description cannot contain two consecutive square
+              ;; brackets, or end with a square bracket.  To prevent
+              ;; this, insert a zero width space character between
+              ;; the brackets, or at the end of the description.
+              (replace-regexp-in-string
+               "\\(]\\)\\(]\\)"
+               (concat "\\1" zero-width-space "\\2")
+               (replace-regexp-in-string "]\\'"
+                                         (concat "\\&" zero-width-space)
+                                         (org-trim description))))))
+    (format "[[%s]%s]"
+           uri
+           (if description (format "[%s]" description) ""))))
+
+(defun org-store-link-functions ()
+  "List of functions that are called to create and store a link.
+
+The functions are defined in the `:store' property of
+`org-link-parameters'.
+
+Each function will be called in turn until one returns a non-nil
+value.  Each function should check if it is responsible for
+creating this link (for example by looking at the major mode).
+If not, it must exit and return nil.  If yes, it should return
+a non-nil value after calling `org-link-store-props' with a list
+of properties and values.  Special properties are:
+
+:type         The link prefix, like \"http\".  This must be given.
+:link         The link, like \"http://www.astro.uva.nl/~dominik\";.
+              This is obligatory as well.
+:description  Optional default description for the second pair
+              of brackets in an Org mode link.  The user can still change
+              this when inserting this link into an Org mode buffer.
+
+In addition to these, any additional properties can be specified
+and then used in capture templates."
+  (cl-loop for link in org-link-parameters
+          with store-func
+          do (setq store-func (org-link-get-parameter (car link) :store))
+          if store-func
+          collect store-func))
+
+(defun org-link-expand-abbrev (link)
+  "Replace link abbreviations in LINK string.
+Abbreviations are defined in `org-link-abbrev-alist'."
+  (if (not (string-match "^\\([^:]*\\)\\(::?\\(.*\\)\\)?$" link)) link
+    (let* ((key (match-string 1 link))
+          (as (or (assoc key org-link-abbrev-alist-local)
+                  (assoc key org-link-abbrev-alist)))
+          (tag (and (match-end 2) (match-string 3 link)))
+          rpl)
+      (if (not as)
+         link
+       (setq rpl (cdr as))
+       (cond
+        ((symbolp rpl) (funcall rpl tag))
+        ((string-match "%(\\([^)]+\\))" rpl)
+         (replace-match
+          (save-match-data
+            (funcall (intern-soft (match-string 1 rpl)) tag)) t t rpl))
+        ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
+        ((string-match "%h" rpl)
+         (replace-match (url-hexify-string (or tag "")) t t rpl))
+        (t (concat rpl tag)))))))
+
+(defun org-link-open (link &optional arg)
+  "Open a link object LINK.
+Optional argument is passed to `org-open-file' when S is
+a \"file\" link."
+  (let ((type (org-element-property :type link))
+       (path (org-element-property :path link)))
+    (cond
+     ((equal type "file")
+      (if (string-match "[*?{]" (file-name-nondirectory path))
+         (dired path)
+       ;; Look into `org-link-parameters' in order to find
+       ;; a DEDICATED-FUNCTION to open file.  The function will be
+       ;; applied on raw link instead of parsed link due to the
+       ;; limitation in `org-add-link-type' ("open" function called
+       ;; with a single argument).  If no such function is found,
+       ;; fallback to `org-open-file'.
+       (let* ((option (org-element-property :search-option link))
+              (app (org-element-property :application link))
+              (dedicated-function
+               (org-link-get-parameter (if app (concat type "+" app) type)
+                                       :follow)))
+         (if dedicated-function
+             (funcall dedicated-function
+                      (concat path
+                              (and option (concat "::" option))))
+           (apply #'org-open-file
+                  path
+                  (cond (arg)
+                        ((equal app "emacs") 'emacs)
+                        ((equal app "sys") 'system))
+                  (cond ((not option) nil)
+                        ((string-match-p "\\`[0-9]+\\'" option)
+                         (list (string-to-number option)))
+                        (t (list nil option))))))))
+     ((functionp (org-link-get-parameter type :follow))
+      (funcall (org-link-get-parameter type :follow) path))
+     ((member type '("coderef" "custom-id" "fuzzy" "radio"))
+      (unless (run-hook-with-args-until-success 'org-open-link-functions path)
+       (if (not arg) (org-mark-ring-push)
+         (switch-to-buffer-other-window (org-link--buffer-for-internals)))
+       (let ((destination
+              (org-with-wide-buffer
+               (if (equal type "radio")
+                   (org-link--search-radio-target
+                    (org-element-property :path link))
+                 (org-link-search
+                  (pcase type
+                    ("custom-id" (concat "#" path))
+                    ("coderef" (format "(%s)" path))
+                    (_ path))
+                  ;; Prevent fuzzy links from matching themselves.
+                  (and (equal type "fuzzy")
+                       (+ 2 (org-element-property :begin link)))))
+               (point))))
+         (unless (and (<= (point-min) destination)
+                      (>= (point-max) destination))
+           (widen))
+         (goto-char destination))))
+     (t (browse-url-at-point)))))
+
+(defun org-link-open-from-string (s &optional arg)
+  "Open a link in the string S, as if it was in Org mode.
+Optional argument is passed to `org-open-file' when S is
+a \"file\" link."
+  (interactive "sLink: \nP")
+  (pcase (with-temp-buffer
+          (let ((org-inhibit-startup nil))
+            (insert s)
+            (org-mode)
+            (goto-char (point-min))
+            (org-element-link-parser)))
+    (`nil (user-error "No valid link in %S" s))
+    (link (org-link-open link arg))))
+
+(defun org-link-search (s &optional avoid-pos stealth)
+  "Search for a search string S.
+
+If S starts with \"#\", it triggers a custom ID search.
+
+If S is enclosed within parenthesis, it initiates a coderef
+search.
+
+If S is surrounded by forward slashes, it is interpreted as
+a regular expression.  In Org mode files, this will create an
+`org-occur' sparse tree.  In ordinary files, `occur' will be used
+to list matches.  If the current buffer is in `dired-mode', grep
+will be used to search in all files.
+
+When AVOID-POS is given, ignore matches near that position.
+
+When optional argument STEALTH is non-nil, do not modify
+visibility around point, thus ignoring `org-show-context-detail'
+variable.
+
+Search is case-insensitive and ignores white spaces.  Return type
+of matched result, which is either `dedicated' or `fuzzy'."
+  (unless (org-string-nw-p s) (error "Invalid search string \"%s\"" s))
+  (let* ((case-fold-search t)
+        (origin (point))
+        (normalized (replace-regexp-in-string "\n[ \t]*" " " s))
+        (starred (eq (string-to-char normalized) ?*))
+        (words (split-string (if starred (substring s 1) s)))
+        (s-multi-re (mapconcat #'regexp-quote words "\\(?:[ \t\n]+\\)"))
+        (s-single-re (mapconcat #'regexp-quote words "[ \t]+"))
+        type)
+    (cond
+     ;; Check if there are any special search functions.
+     ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
+     ((eq (string-to-char s) ?#)
+      ;; Look for a custom ID S if S starts with "#".
+      (let* ((id (substring normalized 1))
+            (match (org-find-property "CUSTOM_ID" id)))
+       (if match (progn (goto-char match) (setf type 'dedicated))
+         (error "No match for custom ID: %s" id))))
+     ((string-match "\\`(\\(.*\\))\\'" normalized)
+      ;; Look for coderef targets if S is enclosed within parenthesis.
+      (let ((coderef (match-string-no-properties 1 normalized))
+           (re (substring s-single-re 1 -1)))
+       (goto-char (point-min))
+       (catch :coderef-match
+         (while (re-search-forward re nil t)
+           (let ((element (org-element-at-point)))
+             (when (and (memq (org-element-type element)
+                              '(example-block src-block))
+                        (org-match-line
+                         (concat ".*?" (org-src-coderef-regexp
+                                        (org-src-coderef-format element)
+                                        coderef))))
+               (setq type 'dedicated)
+               (goto-char (match-beginning 2))
+               (throw :coderef-match nil))))
+         (goto-char origin)
+         (error "No match for coderef: %s" coderef))))
+     ((string-match "\\`/\\(.*\\)/\\'" normalized)
+      ;; Look for a regular expression.
+      (funcall (if (derived-mode-p 'org-mode) #'org-occur #'org-do-occur)
+              (match-string 1 s)))
+     ;; From here, we handle fuzzy links.
+     ;;
+     ;; Look for targets, only if not in a headline search.
+     ((and (not starred)
+          (let ((target (format "<<%s>>" s-multi-re)))
+            (catch :target-match
+              (goto-char (point-min))
+              (while (re-search-forward target nil t)
+                (backward-char)
+                (let ((context (org-element-context)))
+                  (when (eq (org-element-type context) 'target)
+                    (setq type 'dedicated)
+                    (goto-char (org-element-property :begin context))
+                    (throw :target-match t))))
+              nil))))
+     ;; Look for elements named after S, only if not in a headline
+     ;; search.
+     ((and (not starred)
+          (let ((name (format "^[ \t]*#\\+NAME: +%s[ \t]*$" s-single-re)))
+            (catch :name-match
+              (goto-char (point-min))
+              (while (re-search-forward name nil t)
+                (let ((element (org-element-at-point)))
+                  (when (equal words
+                               (split-string
+                                (org-element-property :name element)))
+                    (setq type 'dedicated)
+                    (beginning-of-line)
+                    (throw :name-match t))))
+              nil))))
+     ;; Regular text search.  Prefer headlines in Org mode buffers.
+     ;; Ignore COMMENT keyword, TODO keywords, priority cookies,
+     ;; statistics cookies and tags.
+     ((and (derived-mode-p 'org-mode)
+          (let ((title-re
+                 (format "%s.*\\(?:%s[ \t]\\)?.*%s"
+                         org-outline-regexp-bol
+                         org-comment-string
+                         (mapconcat #'regexp-quote words ".+")))
+                (cookie-re "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]")
+                (comment-re (format "\\`%s[ \t]+" org-comment-string)))
+            (goto-char (point-min))
+            (catch :found
+              (while (re-search-forward title-re nil t)
+                (when (equal words
+                             (split-string
+                              (replace-regexp-in-string
+                               cookie-re ""
+                               (replace-regexp-in-string
+                                comment-re "" (org-get-heading t t t)))))
+                  (throw :found t)))
+              nil)))
+      (beginning-of-line)
+      (setq type 'dedicated))
+     ;; Offer to create non-existent headline depending on
+     ;; `org-link-search-must-match-exact-headline'.
+     ((and (derived-mode-p 'org-mode)
+          (eq org-link-search-must-match-exact-headline 'query-to-create)
+          (yes-or-no-p "No match - create this as a new heading? "))
+      (goto-char (point-max))
+      (unless (bolp) (newline))
+      (org-insert-heading nil t t)
+      (insert s "\n")
+      (beginning-of-line 0))
+     ;; Only headlines are looked after.  No need to process
+     ;; further: throw an error.
+     ((and (derived-mode-p 'org-mode)
+          (or starred org-link-search-must-match-exact-headline))
+      (goto-char origin)
+      (error "No match for fuzzy expression: %s" normalized))
+     ;; Regular text search.
+     ((catch :fuzzy-match
+       (goto-char (point-min))
+       (while (re-search-forward s-multi-re nil t)
+         ;; Skip match if it contains AVOID-POS or it is included in
+         ;; a link with a description but outside the description.
+         (unless (or (and avoid-pos
+                          (<= (match-beginning 0) avoid-pos)
+                          (> (match-end 0) avoid-pos))
+                     (and (save-match-data
+                            (org-in-regexp org-link-bracket-re))
+                          (match-beginning 3)
+                          (or (> (match-beginning 3) (point))
+                              (<= (match-end 3) (point)))
+                          (org-element-lineage
+                           (save-match-data (org-element-context))
+                           '(link) t)))
+           (goto-char (match-beginning 0))
+           (setq type 'fuzzy)
+           (throw :fuzzy-match t)))
+       nil))
+     ;; All failed.  Throw an error.
+     (t (goto-char origin)
+       (error "No match for fuzzy expression: %s" normalized)))
+    ;; Disclose surroundings of match, if appropriate.
+    (when (and (derived-mode-p 'org-mode) (not stealth))
+      (org-show-context 'link-search))
+    type))
+
+(defun org-link-heading-search-string (&optional string)
+  "Make search string for the current headline or STRING."
+  (let ((s (or string
+              (and (derived-mode-p 'org-mode)
+                   (save-excursion
+                     (org-back-to-heading t)
+                     (org-element-property :raw-value
+                                           (org-element-at-point))))))
+       (lines org-link-context-for-files))
+    (unless string (setq s (concat "*" s))) ;Add * for headlines
+    (setq s (replace-regexp-in-string "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" "" 
s))
+    (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 (split-string s) " ")))
+
+(defun org-link-display-format (s)
+  "Replace links in string S with their description.
+If there is no description, use the link target."
+  (save-match-data
+    (replace-regexp-in-string
+     org-link-bracket-re
+     (lambda (m) (or (match-string 2 m) (match-string 1 m)))
+     s nil t)))
+
+(defun org-link-add-angle-brackets (s)
+  "Wrap string S within angle brackets."
+  (unless (equal (substring s 0 1) "<") (setq s (concat "<" s)))
+  (unless (equal (substring s -1) ">") (setq s (concat s ">")))
+  s)
+
+
+;;; Built-in link types
+
+;;;; "doi" link type
+(defun org-link--open-doi (path)
+  "Open a \"doi\" type link.
+PATH is a the path to search for, as a string."
+  (browse-url (url-encode-url (concat org-link-doi-server-url path))))
+
+(org-link-set-parameters "doi" :follow #'org-link--open-doi)
+
+;;;; "elisp" link type
+(defun org-link--open-elisp (path)
+  "Open a \"elisp\" type link.
+PATH is the sexp to evaluate, as a string."
+  (if (or (and (org-string-nw-p org-link-elisp-skip-confirm-regexp)
+              (string-match-p org-link-elisp-skip-confirm-regexp path))
+         (not org-link-elisp-confirm-function)
+         (funcall org-link-elisp-confirm-function
+                  (format "Execute %S as Elisp? "
+                          (org-add-props path nil 'face 'org-warning))))
+      (message "%s => %s" path
+              (if (eq ?\( (string-to-char path))
+                  (eval (read path))
+                (call-interactively (read path))))
+    (user-error "Abort")))
+
+(org-link-set-parameters "elisp" :follow #'org-link--open-elisp)
+
+;;;; "file" link type
+(org-link-set-parameters "file" :complete #'org-link-complete-file)
+
+;;;; "help" link type
+(defun org-link--open-help (path)
+  "Open a \"help\" type link.
+PATH is a symbol name, as a string."
+  (pcase (intern path)
+    ((and (pred fboundp) variable) (describe-function variable))
+    ((and (pred boundp) function) (describe-variable function))
+    (name (user-error "Unknown function or variable: %s" name))))
+
+(org-link-set-parameters "help" :follow #'org-link--open-help)
+
+;;;; "http", "https", "mailto", "ftp", and "news" link types
+(dolist (scheme '("ftp" "http" "https" "mailto" "news"))
+  (org-link-set-parameters scheme
+                          :follow
+                          (lambda (url) (browse-url (concat scheme ":" url)))))
+
+;;;; "shell" link type
+(defun org-link--open-shell (path)
+  "Open a \"shell\" type link.
+PATH is the command to execute, as a string."
+  (if (or (and (org-string-nw-p org-link-shell-skip-confirm-regexp)
+              (string-match-p org-link-shell-skip-confirm-regexp path))
+         (not org-link-shell-confirm-function)
+         (funcall org-link-shell-confirm-function
+                  (format "Execute %S in shell? "
+                          (org-add-props path nil 'face 'org-warning))))
+      (let ((buf (generate-new-buffer "*Org Shell Output*")))
+       (message "Executing %s" path)
+       (shell-command path buf)
+       (when (featurep 'midnight)
+         (setq clean-buffer-list-kill-buffer-names
+               (cons (buffer-name buf)
+                     clean-buffer-list-kill-buffer-names))))
+    (user-error "Abort")))
+
+(org-link-set-parameters "shell" :follow #'org-link--open-shell)
+
+
+;;; Interactive Functions
+
+;;;###autoload
+(defun org-next-link (&optional search-backward)
+  "Move forward to the next link.
+If the link is in hidden text, expose it.  When SEARCH-BACKWARD
+is non-nil, move backward."
+  (interactive)
+  (let ((pos (point))
+       (search-fun (if search-backward #'re-search-backward
+                     #'re-search-forward)))
+    ;; Tweak initial position.  If last search failed, wrap around.
+    ;; Otherwise, make sure we do not match current link.
+    (cond
+     ((not (and org-link--search-failed (eq this-command last-command)))
+      (cond
+       ((and (not search-backward) (looking-at org-link-any-re))
+       (goto-char (match-end 0)))
+       (search-backward
+       (pcase (org-in-regexp org-link-any-re nil t)
+         (`(,beg . ,_) (goto-char beg))
+         (_ nil)))
+       (t nil)))
+     (search-backward
+      (goto-char (point-max))
+      (message "Link search wrapped back to end of buffer"))
+     (t
+      (goto-char (point-min))
+      (message "Link search wrapped back to beginning of buffer")))
+    (setq org-link--search-failed nil)
+    (catch :found
+      (while (funcall search-fun org-link-any-re nil t)
+       (let ((context (save-excursion
+                        (unless search-backward (forward-char -1))
+                        (org-element-context))))
+         (pcase (org-element-lineage context '(link) t)
+           (`nil nil)
+           (link
+            (goto-char (org-element-property :begin link))
+            (when (org-invisible-p) (org-show-context))
+            (throw :found t)))))
+      (goto-char pos)
+      (setq org-link--search-failed t)
+      (message "No further link found"))))
+
+;;;###autoload
+(defun org-previous-link ()
+  "Move backward to the previous link.
+If the link is in hidden text, expose it."
+  (interactive)
+  (org-next-link t))
+
+;;;###autoload
+(defun org-toggle-link-display ()
+  "Toggle the literal or descriptive display of links."
+  (interactive)
+  (if org-link-descriptive (remove-from-invisibility-spec '(org-link))
+    (add-to-invisibility-spec '(org-link)))
+  (org-restart-font-lock)
+  (setq org-link-descriptive (not org-link-descriptive)))
+
+;;;###autoload
+(defun org-store-link (arg &optional interactive?)
+  "Store a link to the current location.
+\\<org-mode-map>
+This link is added to `org-stored-links' and can later be inserted
+into an Org buffer with `org-insert-link' (`\\[org-insert-link]').
+
+For some link types, a `\\[universal-argument]' prefix ARG is interpreted.  \
+A single
+`\\[universal-argument]' negates `org-context-in-file-links' for file links or
+`org-gnus-prefer-web-links' for links to Usenet articles.
+
+A `\\[universal-argument] \\[universal-argument]' prefix ARG forces \
+skipping storing functions that are not
+part of Org core.
+
+A `\\[universal-argument] \\[universal-argument] \\[universal-argument]' \
+prefix ARG forces storing a link for each line in the
+active region.
+
+Assume the function is called interactively if INTERACTIVE? is
+non-nil."
+  (interactive "P\np")
+  (org-load-modules-maybe)
+  (if (and (equal arg '(64)) (org-region-active-p))
+      (save-excursion
+       (let ((end (region-end)))
+         (goto-char (region-beginning))
+         (set-mark (point))
+         (while (< (point-at-eol) end)
+           (move-end-of-line 1) (activate-mark)
+           (let (current-prefix-arg)
+             (call-interactively 'org-store-link))
+           (move-beginning-of-line 2)
+           (set-mark (point)))))
+    (setq org-store-link-plist nil)
+    (let (link cpltxt desc description search txt custom-id agenda-link)
+      (cond
+       ;; Store a link using an external link type, if any function is
+       ;; available. If more than one can generate a link from current
+       ;; location, ask which one to use.
+       ((and (not (equal arg '(16)))
+            (let ((results-alist nil))
+              (dolist (f (org-store-link-functions))
+                (when (funcall f)
+                  ;; XXX: return value is not link's plist, so we
+                  ;; store the new value before it is modified.  It
+                  ;; would be cleaner to ask store link functions to
+                  ;; return the plist instead.
+                  (push (cons f (copy-sequence org-store-link-plist))
+                        results-alist)))
+              (pcase results-alist
+                (`nil nil)
+                (`((,_ . ,_)) t)       ;single choice: nothing to do
+                (`((,name . ,_) . ,_)
+                 ;; Reinstate link plist associated to the chosen
+                 ;; function.
+                 (apply #'org-link-store-props
+                        (cdr (assoc-string
+                              (completing-read
+                               "Which function for creating the link? "
+                               (mapcar #'car results-alist)
+                               nil t (symbol-name name))
+                              results-alist)))
+                 t))))
+       (setq link (plist-get org-store-link-plist :link))
+       (setq desc (or (plist-get org-store-link-plist :description)
+                      link)))
+
+       ;; Store a link from a remote editing buffer.
+       ((org-src-edit-buffer-p)
+       (let ((coderef-format (org-src-coderef-format))
+             (format-link
+              (lambda (label)
+                (if org-src-source-file-name
+                    (format "file:%s::(%s)" org-src-source-file-name label)
+                  (format "(%s)" label)))))
+         (cond
+          ;; Code references do not exist in this type of buffer.
+          ;; Pretend we're linking from the source buffer directly.
+          ((not (memq (org-src-source-type) '(example-block src-block)))
+           (with-current-buffer (org-src-source-buffer)
+             (org-store-link arg interactive?))
+           (setq link nil))
+          ;; A code reference exists.  Use it.
+          ((save-excursion
+             (beginning-of-line)
+             (re-search-forward (org-src-coderef-regexp coderef-format)
+                                (line-end-position)
+                                t))
+           (setq link (funcall format-link (match-string-no-properties 3))))
+          ;; No code reference.  Create a new one then store the link
+          ;; to it, but only in the function is called interactively.
+          (interactive?
+           (end-of-line)
+           (let* ((label (read-string "Code line label: "))
+                  (reference (format coderef-format label))
+                  (gc (- 79 (length reference))))
+             (if (< (current-column) gc)
+                 (org-move-to-column gc t)
+               (insert " "))
+             (insert reference)
+             (setq link (funcall format-link label))))
+          ;; No code reference, and non-interactive call.  Don't know
+          ;; what to do.  Give up.
+          (t (setq link nil)))))
+
+       ;; We are in the agenda, link to referenced location
+       ((equal (bound-and-true-p org-agenda-buffer-name) (buffer-name))
+       (let ((m (or (get-text-property (point) 'org-hd-marker)
+                    (get-text-property (point) 'org-marker))))
+         (when m
+           (org-with-point-at m
+             (setq agenda-link (org-store-link nil interactive?))))))
+
+       ((eq major-mode 'calendar-mode)
+       (let ((cd (calendar-cursor-to-date)))
+         (setq link
+               (format-time-string
+                (car org-time-stamp-formats)
+                (apply 'encode-time
+                       (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
+                             nil nil nil))))
+         (org-link-store-props :type "calendar" :date cd)))
+
+       ((eq major-mode 'help-mode)
+       (setq link (concat "help:" (save-excursion
+                                    (goto-char (point-min))
+                                    (looking-at "^[^ ]+")
+                                    (match-string 0))))
+       (org-link-store-props :type "help"))
+
+       ((eq major-mode 'w3-mode)
+       (setq cpltxt (if (and (buffer-name)
+                             (not (string-match "Untitled" (buffer-name))))
+                        (buffer-name)
+                      (url-view-url t))
+             link (url-view-url t))
+       (org-link-store-props :type "w3" :url (url-view-url t)))
+
+       ((eq major-mode 'image-mode)
+       (setq cpltxt (concat "file:"
+                            (abbreviate-file-name buffer-file-name))
+             link cpltxt)
+       (org-link-store-props :type "image" :file buffer-file-name))
+
+       ;; In dired, store a link to the file of the current line
+       ((derived-mode-p 'dired-mode)
+       (let ((file (dired-get-filename nil t)))
+         (setq file (if file
+                        (abbreviate-file-name
+                         (expand-file-name (dired-get-filename nil t)))
+                      ;; otherwise, no file so use current directory.
+                      default-directory))
+         (setq cpltxt (concat "file:" file)
+               link cpltxt)))
+
+       ((setq search (run-hook-with-args-until-success
+                     'org-create-file-search-functions))
+       (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
+                          "::" search))
+       (setq cpltxt (or description link)))
+
+       ((and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 
'org-mode))
+       (org-with-limited-levels
+        (setq custom-id (org-entry-get nil "CUSTOM_ID"))
+        (cond
+         ;; Store a link using the target at point
+         ((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
+          (setq cpltxt
+                (concat "file:"
+                        (abbreviate-file-name
+                         (buffer-file-name (buffer-base-buffer)))
+                        "::" (match-string 1))
+                link cpltxt))
+         ((and (featurep 'org-id)
+               (or (eq org-id-link-to-org-use-id t)
+                   (and interactive?
+                        (or (eq org-id-link-to-org-use-id 
'create-if-interactive)
+                            (and (eq org-id-link-to-org-use-id
+                                     'create-if-interactive-and-no-custom-id)
+                                 (not custom-id))))
+                   (and org-id-link-to-org-use-id (org-entry-get nil "ID"))))
+          ;; Store a link using the ID at point
+          (setq link (condition-case nil
+                         (prog1 (org-id-store-link)
+                           (setq desc (or (plist-get org-store-link-plist
+                                                     :description)
+                                          "")))
+                       (error
+                        ;; Probably before first headline, link only to file
+                        (concat "file:"
+                                (abbreviate-file-name
+                                 (buffer-file-name (buffer-base-buffer))))))))
+         (t
+          ;; Just link to current headline
+          (setq cpltxt (concat "file:"
+                               (abbreviate-file-name
+                                (buffer-file-name (buffer-base-buffer)))))
+          ;; Add a context search string
+          (when (org-xor org-link-context-for-files (equal arg '(4)))
+            (let* ((element (org-element-at-point))
+                   (name (org-element-property :name element)))
+              (setq txt (cond
+                         ((org-at-heading-p) nil)
+                         (name)
+                         ((org-region-active-p)
+                          (buffer-substring (region-beginning) (region-end)))))
+              (when (or (null txt) (string-match "\\S-" txt))
+                (setq cpltxt
+                      (concat cpltxt "::"
+                              (condition-case nil
+                                  (org-link-heading-search-string txt)
+                                (error "")))
+                      desc (or name
+                               (nth 4 (ignore-errors (org-heading-components)))
+                               "NONE")))))
+          (when (string-match "::\\'" cpltxt)
+            (setq cpltxt (substring cpltxt 0 -2)))
+          (setq link cpltxt)))))
+
+       ((buffer-file-name (buffer-base-buffer))
+       ;; Just link to this file here.
+       (setq cpltxt (concat "file:"
+                            (abbreviate-file-name
+                             (buffer-file-name (buffer-base-buffer)))))
+       ;; Add a context string.
+       (when (org-xor org-link-context-for-files (equal arg '(4)))
+         (setq txt (if (org-region-active-p)
+                       (buffer-substring (region-beginning) (region-end))
+                     (buffer-substring (point-at-bol) (point-at-eol))))
+         ;; Only use search option if there is some text.
+         (when (string-match "\\S-" txt)
+           (setq cpltxt
+                 (concat cpltxt "::" (org-link-heading-search-string txt))
+                 desc "NONE")))
+       (setq link cpltxt))
+
+       (interactive?
+       (user-error "No method for storing a link from this buffer"))
+
+       (t (setq link nil)))
+
+      ;; We're done setting link and desc, clean up
+      (when (consp link) (setq cpltxt (car link) link (cdr link)))
+      (setq link (or link cpltxt)
+           desc (or desc cpltxt))
+      (cond ((not desc))
+           ((equal desc "NONE") (setq desc nil))
+           (t (setq desc (org-link-display-format desc))))
+      ;; Return the link
+      (if (not (and interactive? link))
+         (or agenda-link (and link (org-link-make-string link desc)))
+       (push (list link desc) org-stored-links)
+       (message "Stored: %s" (or desc link))
+       (when custom-id
+         (setq link (concat "file:" (abbreviate-file-name
+                                     (buffer-file-name)) "::#" custom-id))
+         (push (list link desc) org-stored-links))
+       (car org-stored-links)))))
+
+;;;###autoload
+(defun org-insert-link (&optional complete-file link-location description)
+  "Insert a link.  At the prompt, enter the link.
+
+Completion can be used to insert any of the link protocol prefixes in use.
+
+The history can be used to select a link previously stored with
+`org-store-link'.  When the empty string is entered (i.e. if you just
+press `RET' at the prompt), the link defaults to the most recently
+stored link.  As `SPC' triggers completion in the minibuffer, you need to
+use `M-SPC' or `C-q SPC' to force the insertion of a space character.
+
+You will also be prompted for a description, and if one is given, it will
+be displayed in the buffer instead of the link.
+
+If there is already a link at point, this command will allow you to edit
+link and description parts.
+
+With a `\\[universal-argument]' prefix, prompts for a file to link to.  The \
+file name can be
+selected using completion.  The path to the file will be relative to the
+current directory if the file is in the current directory or a subdirectory.
+Otherwise, the link will be the absolute path as completed in the minibuffer
+\(i.e. normally ~/path/to/file).  You can configure this behavior using the
+option `org-link-file-path-type'.
+
+With a `\\[universal-argument] \\[universal-argument]' prefix, enforce an \
+absolute path even if the file is in
+the current directory or below.
+
+A `\\[universal-argument] \\[universal-argument] \\[universal-argument]' \
+prefix negates `org-link-keep-stored-after-insertion'.
+
+If the LINK-LOCATION parameter is non-nil, this value will be used as
+the link location instead of reading one interactively.
+
+If the DESCRIPTION parameter is non-nil, this value will be used as the
+default description.  Otherwise, if `org-link-make-description-function'
+is non-nil, this function will be called with the link target, and the
+result will be the default link description.  When called non-interactively,
+don't allow to edit the default description."
+  (interactive "P")
+  (let* ((wcf (current-window-configuration))
+        (origbuf (current-buffer))
+        (region (when (org-region-active-p)
+                  (buffer-substring (region-beginning) (region-end))))
+        (remove (and region (list (region-beginning) (region-end))))
+        (desc region)
+        (link link-location)
+        (abbrevs org-link-abbrev-alist-local)
+        entry all-prefixes auto-desc)
+    (cond
+     (link-location)                 ; specified by arg, just use it.
+     ((org-in-regexp org-link-bracket-re 1)
+      ;; We do have a link at point, and we are going to edit it.
+      (setq remove (list (match-beginning 0) (match-end 0)))
+      (setq desc (when (match-end 2) (match-string-no-properties 2)))
+      (setq link (read-string "Link: "
+                             (org-link-unescape
+                              (match-string-no-properties 1)))))
+     ((or (org-in-regexp org-link-angle-re)
+         (org-in-regexp org-link-plain-re))
+      ;; Convert to bracket link
+      (setq remove (list (match-beginning 0) (match-end 0))
+           link (read-string "Link: "
+                             (org-unbracket-string "<" ">" (match-string 0)))))
+     ((member complete-file '((4) (16)))
+      ;; Completing read for file names.
+      (setq link (org-link-complete-file complete-file)))
+     (t
+      ;; Read link, with completion for stored links.
+      (org-link--fontify-links-to-this-file)
+      (org-switch-to-buffer-other-window "*Org Links*")
+      (with-current-buffer "*Org Links*"
+       (erase-buffer)
+       (insert "Insert a link.
+Use TAB to complete link prefixes, then RET for type-specific completion 
support\n")
+       (when org-stored-links
+         (insert "\nStored links are available with <up>/<down> or M-p/n \
+\(most recent with RET):\n\n")
+         (insert (mapconcat #'org-link--prettify
+                            (reverse org-stored-links)
+                            "\n")))
+       (goto-char (point-min)))
+      (let ((cw (selected-window)))
+       (select-window (get-buffer-window "*Org Links*" 'visible))
+       (with-current-buffer "*Org Links*" (setq truncate-lines t))
+       (unless (pos-visible-in-window-p (point-max))
+         (org-fit-window-to-buffer))
+       (and (window-live-p cw) (select-window cw)))
+      (setq all-prefixes (append (mapcar #'car abbrevs)
+                                (mapcar #'car org-link-abbrev-alist)
+                                (org-link-types)))
+      (unwind-protect
+         ;; Fake a link history, containing the stored links.
+         (let ((org-link--history
+                (append (mapcar #'car org-stored-links)
+                        org-link--insert-history)))
+           (setq link
+                 (org-completing-read
+                  "Link: "
+                  (append
+                   (mapcar (lambda (x) (concat x ":")) all-prefixes)
+                   (mapcar #'car org-stored-links))
+                  nil nil nil
+                  'org-link--history
+                  (caar org-stored-links)))
+           (unless (org-string-nw-p link) (user-error "No link selected"))
+           (dolist (l org-stored-links)
+             (when (equal link (cadr l))
+               (setq link (car l))
+               (setq auto-desc t)))
+           (when (or (member link all-prefixes)
+                     (and (equal ":" (substring link -1))
+                          (member (substring link 0 -1) all-prefixes)
+                          (setq link (substring link 0 -1))))
+             (setq link (with-current-buffer origbuf
+                          (org-link--try-special-completion link)))))
+       (set-window-configuration wcf)
+       (kill-buffer "*Org Links*"))
+      (setq entry (assoc link org-stored-links))
+      (or entry (push link org-link--insert-history))
+      (setq desc (or desc (nth 1 entry)))))
+
+    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
+                  (not org-link-keep-stored-after-insertion))
+      (setq org-stored-links (delq (assoc link org-stored-links)
+                                  org-stored-links)))
+
+    (when (and (string-match org-link-plain-re link)
+              (not (string-match org-ts-regexp link)))
+      ;; URL-like link, normalize the use of angular brackets.
+      (setq link (org-unbracket-string "<" ">" link)))
+
+    ;; Check if we are linking to the current file with a search
+    ;; option If yes, simplify the link by using only the search
+    ;; option.
+    (when (and buffer-file-name
+              (let ((case-fold-search nil))
+                (string-match "\\`file:\\(.+?\\)::" link)))
+      (let ((path (match-string-no-properties 1 link))
+           (search (substring-no-properties link (match-end 0))))
+       (save-match-data
+         (when (equal (file-truename buffer-file-name) (file-truename path))
+           ;; We are linking to this same file, with a search option
+           (setq link search)))))
+
+    ;; Check if we can/should use a relative path.  If yes, simplify
+    ;; the link.
+    (let ((case-fold-search nil))
+      (when (string-match "\\`\\(file\\|docview\\):" link)
+       (let* ((type (match-string-no-properties 0 link))
+              (path-start (match-end 0))
+              (search (and (string-match "::\\(.*\\)\\'" link)
+                           (match-string 1 link)))
+              (path
+               (if search
+                   (substring-no-properties
+                    link path-start (match-beginning 0))
+                 (substring-no-properties link (match-end 0))))
+              (origpath path))
+         (cond
+          ((or (eq org-link-file-path-type 'absolute)
+               (equal complete-file '(16)))
+           (setq path (abbreviate-file-name (expand-file-name path))))
+          ((eq org-link-file-path-type 'noabbrev)
+           (setq path (expand-file-name path)))
+          ((eq org-link-file-path-type 'relative)
+           (setq path (file-relative-name path)))
+          (t
+           (save-match-data
+             (if (string-match (concat "^" (regexp-quote
+                                            (expand-file-name
+                                             (file-name-as-directory
+                                              default-directory))))
+                               (expand-file-name path))
+                 ;; We are linking a file with relative path name.
+                 (setq path (substring (expand-file-name path)
+                                       (match-end 0)))
+               (setq path (abbreviate-file-name (expand-file-name path)))))))
+         (setq link (concat type path (and search (concat "::" search))))
+         (when (equal desc origpath)
+           (setq desc path)))))
+
+    (unless auto-desc
+      (let ((initial-input
+            (cond
+             (description)
+             ((not org-link-make-description-function) desc)
+             (t (condition-case nil
+                    (funcall org-link-make-description-function link desc)
+                  (error
+                   (message "Can't get link description from %S"
+                            (symbol-name org-link-make-description-function))
+                   (sit-for 2)
+                   nil))))))
+       (setq desc (if (called-interactively-p 'any)
+                      (read-string "Description: " initial-input)
+                    initial-input))))
+
+    (unless (org-string-nw-p desc) (setq desc nil))
+    (when remove (apply #'delete-region remove))
+    (insert (org-link-make-string link desc))
+    ;; Redisplay so as the new link has proper invisible characters.
+    (sit-for 0)))
+
+;;;###autoload
+(defun org-insert-all-links (arg &optional pre post)
+  "Insert all links in `org-stored-links'.
+When a universal prefix, do not delete the links from `org-stored-links'.
+When `ARG' is a number, insert the last N link(s).
+`PRE' and `POST' are optional arguments to define a string to
+prepend or to append."
+  (interactive "P")
+  (let ((org-link-keep-stored-after-insertion (equal arg '(4)))
+       (links (copy-sequence org-stored-links))
+       (pr (or pre "- "))
+       (po (or post "\n"))
+       (cnt 1) l)
+    (if (null org-stored-links)
+       (message "No link to insert")
+      (while (and (or (listp arg) (>= arg cnt))
+                 (setq l (if (listp arg)
+                             (pop links)
+                           (pop org-stored-links))))
+       (setq cnt (1+ cnt))
+       (insert pr)
+       (org-insert-link nil (car l) (or (cadr l) "<no description>"))
+       (insert po)))))
+
+;;;###autoload
+(defun org-insert-last-stored-link (arg)
+  "Insert the last link stored in `org-stored-links'."
+  (interactive "p")
+  (org-insert-all-links arg "" "\n"))
+
+;;;###autoload
+(defun org-insert-link-global ()
+  "Insert a link like Org mode does.
+This command can be called in any mode to insert a link in Org syntax."
+  (interactive)
+  (org-load-modules-maybe)
+  (org-run-like-in-org-mode 'org-insert-link))
+
+;;;###autoload
+(defun org-update-radio-target-regexp ()
+  "Find all radio targets in this file and update the regular expression.
+Also refresh fontification if needed."
+  (interactive)
+  (let ((old-regexp org-target-link-regexp)
+       ;; Some languages, e.g., Chinese, do not use spaces to
+       ;; separate words.  Also allow to surround radio targets with
+       ;; line-breakable characters.
+       (before-re "\\(?:^\\|[^[:alnum:]]\\|\\c|\\)\\(")
+       (after-re "\\)\\(?:$\\|[^[:alnum:]]\\|\\c|\\)")
+       (targets
+        (org-with-wide-buffer
+         (goto-char (point-min))
+         (let (rtn)
+           (while (re-search-forward org-radio-target-regexp nil t)
+             ;; Make sure point is really within the object.
+             (backward-char)
+             (let ((obj (org-element-context)))
+               (when (eq (org-element-type obj) 'radio-target)
+                 (cl-pushnew (org-element-property :value obj) rtn
+                             :test #'equal))))
+           rtn))))
+    (setq org-target-link-regexp
+         (and targets
+              (concat before-re
+                      (mapconcat
+                       (lambda (x)
+                         (replace-regexp-in-string
+                          " +" "\\s-+" (regexp-quote x) t t))
+                       targets
+                       "\\|")
+                      after-re)))
+    (unless (equal old-regexp org-target-link-regexp)
+      ;; Clean-up cache.
+      (let ((regexp (cond ((not old-regexp) org-target-link-regexp)
+                         ((not org-target-link-regexp) old-regexp)
+                         (t
+                          (concat before-re
+                                  (mapconcat
+                                   (lambda (re)
+                                     (substring re (length before-re)
+                                                (- (length after-re))))
+                                   (list old-regexp org-target-link-regexp)
+                                   "\\|")
+                                  after-re)))))
+       (when (featurep 'org-element)
+         (org-with-point-at 1
+           (while (re-search-forward regexp nil t)
+             (org-element-cache-refresh (match-beginning 1))))))
+      ;; Re fontify buffer.
+      (when (memq 'radio org-highlight-links)
+       (org-restart-font-lock)))))
+
+
+;;; Initialize Regexps
+
+(org-link-make-regexps)
+
+
+(provide 'ol)
+
+;;; ol.el ends here
diff --git a/lisp/org/org-agenda.el b/lisp/org/org-agenda.el
index 6870b78..7cb5cca 100644
--- a/lisp/org/org-agenda.el
+++ b/lisp/org/org-agenda.el
@@ -46,6 +46,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'ol)
 (require 'org)
 (require 'org-macs)
 
@@ -90,6 +91,7 @@
 (defvar org-habit-show-habits)
 (defvar org-habit-show-habits-only-for-today)
 (defvar org-habit-show-all-today)
+(defvar org-habit-scheduled-past-days)
 
 ;; Defined somewhere in this file, but used before definition.
 (defvar org-agenda-buffer-name "*Org Agenda*")
@@ -381,6 +383,9 @@ the daily/weekly agenda, see `org-agenda-skip-function'.")
                               (const :scheduled*)
                               (const :timestamp)
                               (const :sexp))))
+                  (list :tag "Columns format"
+                        (const org-overriding-columns-format)
+                        (string :tag "Format"))
                   (list :tag "Standard skipping condition"
                         :value (org-agenda-skip-function 
'(org-agenda-skip-entry-if))
                         (const org-agenda-skip-function)
@@ -461,7 +466,7 @@ type     The command type, any of the following symbols:
           ...         A user-defined function.
 match    What to search for:
           - a single keyword for TODO keyword searches
-          - a tags match expression for tags searches
+          - a tags/property/todo match expression for searches
           - a word search expression for text searches.
           - a regular expression for occur searches
           For all other commands, this should be the empty string.
@@ -548,11 +553,11 @@ should provide a description for the prefix, like
                                       (const :format "" stuck)
                                       (const :tag "" :format "" "")
                                       
,org-agenda-custom-commands-local-options)
-                                (list :tag "Tags search"
+                                (list :tag "Tags/Property match (all agenda 
files)"
                                       (const :format "" tags)
                                       (string :tag "Match")
                                       
,org-agenda-custom-commands-local-options)
-                                (list :tag "Tags search, TODO entries only"
+                                (list :tag "Tags/Property match of TODO 
entries (all agenda files)"
                                       (const :format "" tags-todo)
                                       (string :tag "Match")
                                       
,org-agenda-custom-commands-local-options)
@@ -1706,6 +1711,13 @@ Custom commands can set this variable in the options 
section."
   :version "26.1"
   :package-version '(Org . "9.1"))
 
+(defcustom org-agenda-breadcrumbs-separator "->"
+  "The separator of breadcrumbs in agenda lines."
+  :group 'org-agenda-line-format
+  :package-version '(Org . "9.3")
+  :type 'string
+  :safe #'stringp)
+
 (defvar org-prefix-format-compiled nil
   "The compiled prefix format and associated variables.
 This is a list where first element is a list of variable bindings, and second
@@ -2021,7 +2033,8 @@ estimate."
 The sole argument to the function, which is called once for each
 possible tag, is a string giving the name of the tag.  The
 function should return either nil if the tag should be included
-as normal, or \"-<TAG>\" to exclude the tag.
+as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
+lines not carrying this tag.
 Note that for the purpose of tag filtering, only the lower-case version of
 all tags will be considered, so that this function will only ever see
 the lower-case version of all tags."
@@ -2065,6 +2078,23 @@ works you probably want to add it to 
`org-agenda-custom-commands' for good."
        (setcdr ass (cdr entry))
       (push entry org-agenda-custom-commands))))
 
+(defmacro org-agenda--insert-overriding-header (default)
+  "Insert header into agenda view.
+The inserted header depends on `org-agenda-overriding-header'.
+If the empty string, don't insert a header.  If any other string,
+insert it as a header.  If nil, insert DEFAULT, which should
+evaluate to a string."
+  (declare (debug (form)) (indent defun))
+  `(cond
+    ((not org-agenda-overriding-header) (insert ,default))
+    ((equal org-agenda-overriding-header "") nil)
+    ((stringp org-agenda-overriding-header)
+     (insert (propertize org-agenda-overriding-header
+                        'face 'org-agenda-structure)
+            "\n"))
+    (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
+                  org-agenda-overriding-header))))
+
 ;;; Define the org-agenda-mode
 
 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
@@ -2167,29 +2197,36 @@ The following commands are available:
 
 \\{org-agenda-mode-map}"
   (interactive)
-  (cond (org-agenda-doing-sticky-redo
-        ;; Refreshing sticky agenda-buffer
-        ;;
-        ;; Preserve the value of `org-agenda-local-vars' variables,
-        ;; while letting `kill-all-local-variables' kill the rest
-        (let ((save (buffer-local-variables)))
-          (kill-all-local-variables)
-          (mapc #'make-local-variable org-agenda-local-vars)
-          (dolist (elem save)
-            (pcase elem
-              (`(,var . ,val)          ;ignore unbound variables
-               (when (and val (memq var org-agenda-local-vars))
-                 (set var val))))))
-        (setq-local org-agenda-this-buffer-is-sticky t))
-       (org-agenda-sticky
-        ;; Creating a sticky Agenda buffer for the first time
-        (kill-all-local-variables)
-        (mapc 'make-local-variable org-agenda-local-vars)
-        (setq-local org-agenda-this-buffer-is-sticky t))
-       (t
-        ;; Creating a non-sticky agenda buffer
-        (kill-all-local-variables)
-        (setq-local org-agenda-this-buffer-is-sticky nil)))
+  (let ((agenda-local-vars-to-keep
+        '(text-scale-mode-amount
+          text-scale-mode
+          text-scale-mode-lighter
+          face-remapping-alist))
+       (save (buffer-local-variables)))
+    (kill-all-local-variables)
+    (cl-flet ((reset-saved (var-set)
+                          "Reset variables in VAR-SET to possibly stored value 
in SAVE."
+                          (dolist (elem save)
+                            (pcase elem
+                              (`(,var . ,val)          ;ignore unbound 
variables
+                               (when (and val (memq var var-set))
+                                 (set var val)))))))
+      (cond (org-agenda-doing-sticky-redo
+            ;; Refreshing sticky agenda-buffer
+            ;;
+            ;; Preserve the value of `org-agenda-local-vars' variables.
+            (mapc #'make-local-variable org-agenda-local-vars)
+            (reset-saved org-agenda-local-vars)
+            (setq-local org-agenda-this-buffer-is-sticky t))
+           (org-agenda-sticky
+            ;; Creating a sticky Agenda buffer for the first time
+            (mapc 'make-local-variable org-agenda-local-vars)
+            (setq-local org-agenda-this-buffer-is-sticky t))
+           (t
+            ;; Creating a non-sticky agenda buffer
+            (setq-local org-agenda-this-buffer-is-sticky nil)))
+      (mapc #'make-local-variable agenda-local-vars-to-keep)
+      (reset-saved agenda-local-vars-to-keep)))
   (setq org-agenda-undo-list nil
        org-agenda-pending-undo-list nil
        org-agenda-bulk-marked-entries nil)
@@ -2200,16 +2237,16 @@ The following commands are available:
   (setq indent-tabs-mode nil)
   (use-local-map org-agenda-mode-map)
   (easy-menu-add org-agenda-menu)
-  (if org-startup-truncated (setq truncate-lines t))
+  (when org-startup-truncated (setq truncate-lines t))
   (setq-local line-move-visual nil)
   (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
   (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
   ;; Make sure properties are removed when copying text
   (if (boundp 'filter-buffer-substring-functions)
       (add-hook 'filter-buffer-substring-functions
-                (lambda (fun start end delete)
+               (lambda (fun start end delete)
                   (substring-no-properties (funcall fun start end delete)))
-                nil t)
+               nil t)
     ;; Emacs >= 24.4.
     (add-function :filter-return (local 'filter-buffer-substring-function)
                   #'substring-no-properties))
@@ -2363,9 +2400,10 @@ The following commands are available:
 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
-(org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
+(org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag)
 (org-defkey org-agenda-mode-map "_" 'org-agenda-filter-by-effort)
 (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
+(org-defkey org-agenda-mode-map "/" 'org-agenda-filter)
 (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
 (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
@@ -2375,6 +2413,7 @@ The following commands are available:
 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg"    'org-mobile-pull)
 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp"    'org-mobile-push)
+(org-defkey org-agenda-mode-map "\C-c\C-xI" 'org-info-find-node)
 
 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
@@ -2445,8 +2484,20 @@ The following commands are available:
       :keys "v A"]
      "--"
      ["Remove Restriction" org-agenda-remove-restriction-lock 
org-agenda-restrict])
-    ["Write view to file" org-agenda-write t]
+    ("Filter current view"
+     ["with generic interface" org-agenda-filter t]
+     "--"
+     ["by category at cursor" org-agenda-filter-by-category t]
+     ["by tag" org-agenda-filter-by-tag t]
+     ["by effort" org-agenda-filter-by-effort t]
+     ["by regexp" org-agenda-filter-by-regexp t]
+     ["by top-level headline" org-agenda-filter-by-top-headline t]
+     "--"
+     ["Remove all filtering" org-agenda-filter-remove-all t]
+     "--"
+     ["limit" org-agenda-limit-interactively t])
     ["Rebuild buffer" org-agenda-redo t]
+    ["Write view to file" org-agenda-write t]
     ["Save all Org buffers" org-save-all-org-buffers t]
     "--"
     ["Show original entry" org-agenda-show t]
@@ -2551,30 +2602,30 @@ that have been changed along."
   (interactive)
   (or org-agenda-allow-remote-undo
       (user-error "Check the variable `org-agenda-allow-remote-undo' to 
activate remote undo"))
-  (if (not (eq this-command last-command))
-      (setq org-agenda-undo-has-started-in nil
-           org-agenda-pending-undo-list org-agenda-undo-list))
-  (if (not org-agenda-pending-undo-list)
-      (user-error "No further undo information"))
+  (when (not (eq this-command last-command))
+    (setq org-agenda-undo-has-started-in nil
+         org-agenda-pending-undo-list org-agenda-undo-list))
+  (when (not org-agenda-pending-undo-list)
+    (user-error "No further undo information"))
   (let* ((entry (pop org-agenda-pending-undo-list))
         buf line cmd rembuf)
     (setq cmd (pop entry) line (pop entry))
     (setq rembuf (nth 2 entry))
     (org-with-remote-undo rembuf
       (while (bufferp (setq buf (pop entry)))
-       (if (pop entry)
-           (with-current-buffer buf
-             (let ((last-undo-buffer buf)
-                    (inhibit-read-only t))
-               (unless (memq buf org-agenda-undo-has-started-in)
-                 (push buf org-agenda-undo-has-started-in)
-                 (make-local-variable 'pending-undo-list)
-                 (undo-start))
-               (while (and pending-undo-list
-                           (listp pending-undo-list)
-                           (not (car pending-undo-list)))
-                 (pop pending-undo-list))
-               (undo-more 1))))))
+       (when (pop entry)
+         (with-current-buffer buf
+           (let ((last-undo-buffer buf)
+                  (inhibit-read-only t))
+             (unless (memq buf org-agenda-undo-has-started-in)
+               (push buf org-agenda-undo-has-started-in)
+               (make-local-variable 'pending-undo-list)
+               (undo-start))
+             (while (and pending-undo-list
+                         (listp pending-undo-list)
+                         (not (car pending-undo-list)))
+               (pop pending-undo-list))
+             (undo-more 1))))))
     (org-goto-line line)
     (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
 
@@ -2797,9 +2848,9 @@ Pressing `<' twice means to restrict to the current 
subtree or region
       ;; If we have sticky agenda buffers, set a name for the buffer,
       ;; depending on the invoking keys.  The user may still set this
       ;; as a command option, which will overwrite what we do here.
-      (if org-agenda-sticky
-         (setq org-agenda-buffer-name
-               (format "*Org Agenda(%s)*" org-keys)))
+      (when org-agenda-sticky
+       (setq org-agenda-buffer-name
+             (format "*Org Agenda(%s)*" org-keys)))
       ;; Establish the restriction, if any
       (when (and (not org-agenda-overriding-restriction) restriction)
        (put 'org-agenda-files 'org-restrict (list bfn))
@@ -2814,7 +2865,13 @@ Pressing `<' twice means to restrict to the current 
subtree or region
            (org-back-to-heading t)
            (move-marker org-agenda-restrict-begin (point))
            (move-marker org-agenda-restrict-end
-                        (progn (org-end-of-subtree t)))))))
+                        (progn (org-end-of-subtree t)))))
+        ((and (eq restriction 'buffer)
+              (or (< 1 (point-min))
+                  (< (point-max) (1+ (buffer-size)))))
+         (setq org-agenda-restrict (current-buffer))
+         (move-marker org-agenda-restrict-begin (point-min))
+         (move-marker org-agenda-restrict-end (point-max)))))
 
       ;; For example the todo list should not need it (but does...)
       (cond
@@ -2823,10 +2880,10 @@ Pressing `<' twice means to restrict to the current 
subtree or region
            (progn
              (setq type (nth 2 entry) org-match (eval (nth 3 entry))
                    lprops (nth 4 entry))
-             (if org-agenda-sticky
-                 (setq org-agenda-buffer-name
-                       (or (and (stringp org-match) (format "*Org 
Agenda(%s:%s)*" org-keys org-match))
-                           (format "*Org Agenda(%s)*" org-keys))))
+             (when org-agenda-sticky
+               (setq org-agenda-buffer-name
+                     (or (and (stringp org-match) (format "*Org 
Agenda(%s:%s)*" org-keys org-match))
+                         (format "*Org Agenda(%s)*" org-keys))))
              (put 'org-agenda-redo-command 'org-lprops lprops)
              (cond
               ((eq type 'agenda)
@@ -2884,10 +2941,10 @@ Pressing `<' twice means to restrict to the current 
subtree or region
               (when note
                 (message "FLAGGING-NOTE ([?] for more info): %s"
                          (org-add-props
-                          (replace-regexp-in-string
-                           "\\\\n" "//"
-                           (copy-sequence note))
-                          nil 'face 'org-warning))))))
+                             (replace-regexp-in-string
+                              "\\\\n" "//"
+                              (copy-sequence note))
+                             nil 'face 'org-warning))))))
         t t))
        ((equal org-keys "#") (call-interactively 
'org-agenda-list-stuck-projects))
        ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
@@ -3000,19 +3057,18 @@ s   Search for keywords                 M   Like m, but 
only TODO entries
                                            (symbol-name type)
                                          "Lambda expression"))
                      (t "???"))))
-             (if org-agenda-menu-show-matcher
-                 (setq line
-                       (concat line ": "
-                               (cond
-                                ((stringp match)
-                                 (setq match (copy-sequence match))
-                                 (org-add-props match nil 'face 'org-warning))
-                                ((listp type)
-                                 (format "set of %d commands" (length 
type))))))
-               (if (org-string-nw-p match)
-                   (add-text-properties
-                    0 (length line) (list 'help-echo
-                                          (concat "Matcher: " match)) line)))
+             (cond
+              ((not (org-string-nw-p match)) nil)
+              (org-agenda-menu-show-matcher
+               (setq line
+                     (concat line ": "
+                             (cond
+                              ((stringp match)
+                               (propertize match 'face 'org-warning))
+                              ((listp type)
+                               (format "set of %d commands" (length type)))))))
+              (t
+               (org-add-props line nil 'help-echo (concat "Matcher: " match))))
              (push line lines)))
          (setq lines (nreverse lines))
          (when prefixes
@@ -3048,21 +3104,47 @@ s   Search for keywords                 M   Like m, but 
only TODO entries
          ;; Make the window the right size
          (goto-char (point-min))
          (if second-time
-             (if (not (pos-visible-in-window-p (point-max)))
-                 (org-fit-window-to-buffer))
+             (when (not (pos-visible-in-window-p (point-max)))
+               (org-fit-window-to-buffer))
            (setq second-time t)
            (org-fit-window-to-buffer))
 
+         ;; Hint to navigation if window too small for all information
+         (setq header-line-format
+               (when (not (pos-visible-in-window-p (point-max)))
+                 "Use SPC, DEL, C-n or C-p to navigate."))
+
          ;; Ask for selection
-         (message "Press key for agenda command%s:"
-                  (if (or restrict-ok org-agenda-overriding-restriction)
-                      (if org-agenda-overriding-restriction
-                          " (restriction lock active)"
-                        (if restriction
-                            (format " (restricted to %s)" restriction)
-                          " (unrestricted)"))
-                    ""))
-         (setq c (read-char-exclusive))
+         (cl-loop
+          do (progn
+               (message "Press key for agenda command%s:"
+                        (if (or restrict-ok org-agenda-overriding-restriction)
+                            (if org-agenda-overriding-restriction
+                                " (restriction lock active)"
+                              (if restriction
+                                  (format " (restricted to %s)" restriction)
+                                " (unrestricted)"))
+                          ""))
+               (setq c (read-char-exclusive)))
+          until (not (memq c '(14 16 ?\s ?\d)))
+          do (cl-case c
+               (14 (if (not (pos-visible-in-window-p (point-max)))
+                       (ignore-errors (scroll-up 1))
+                     (message "End of buffer")
+                     (sit-for 1)))
+               (16 (if (not (pos-visible-in-window-p (point-min)))
+                       (ignore-errors (scroll-down 1))
+                     (message "Beginning of buffer")
+                     (sit-for 1)))
+               (?\s (if (not (pos-visible-in-window-p (point-max)))
+                        (scroll-up nil)
+                      (message "End of buffer")
+                      (sit-for 1)))
+               (?\d (if (not (pos-visible-in-window-p (point-min)))
+                        (scroll-down nil)
+                      (message "Beginning of buffer")
+                      (sit-for 1)))))
+
          (message "")
          (cond
           ((assoc (char-to-string c) custom)
@@ -3235,7 +3317,7 @@ todo         The todo keyword, if any
 tags         All tags including inherited ones, separated by colons
 date         The relevant date, like 2007-2-14
 time         The time, like 15:00-16:50
-extra        Sting with extra planning info
+extra        String with extra planning info
 priority-l   The priority letter if any was given
 priority-n   The computed numerical priority
 agenda-day   The day in the agenda where this is listed"
@@ -3245,11 +3327,9 @@ agenda-day   The day in the agenda where this is listed"
        (org-tags-view nil cmd-key)
       (org-agenda nil cmd-key)))
   (set-buffer org-agenda-buffer-name)
-  (let* ((lines (org-split-string (buffer-string) "\n"))
-        line)
-    (while (setq line (pop lines))
-      (catch 'next
-       (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
+  (let ((lines (org-split-string (buffer-string) "\n")))
+    (dolist (line lines)
+      (when (get-text-property 0 'org-category line)
        (setq org-agenda-info
              (org-fix-agenda-info (text-properties-at 0 line)))
        (princ
@@ -3266,14 +3346,14 @@ This ensures the export commands can easily use it."
     (when (setq tmp (plist-get props 'tags))
       (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
     (when (setq tmp (plist-get props 'date))
-      (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
+      (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
       (let ((calendar-date-display-form '(year "-" month "-" day)))
        '((format "%4d, %9s %2s, %4s" dayname monthname day year))
 
        (setq tmp (calendar-date-string tmp)))
       (setq props (plist-put props 'date tmp)))
     (when (setq tmp (plist-get props 'day))
-      (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
+      (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
       (let ((calendar-date-display-form '(year "-" month "-" day)))
        (setq tmp (calendar-date-string tmp)))
       (setq props (plist-put props 'day tmp))
@@ -3513,7 +3593,7 @@ removed from the entry content.  Currently only 
`planning' is allowed here."
                 (add-text-properties (match-beginning 0) (match-end 0)
                                      '(face org-link))))
             (goto-char (point-min))
-            (while (re-search-forward org-bracket-link-regexp (point-max) t)
+            (while (re-search-forward org-link-bracket-re (point-max) t)
               (set-text-properties (match-beginning 0) (match-end 0)
                                    nil))
             (goto-char (point-min))
@@ -3536,15 +3616,15 @@ removed from the entry content.  Currently only 
`planning' is allowed here."
                     (replace-match "")))))
             (goto-char (point-max))
             (skip-chars-backward " \t\n")
-            (if (looking-at "[ \t\n]+\\'") (replace-match ""))
+            (when (looking-at "[ \t\n]+\\'") (replace-match ""))
 
             ;; find and remove min common indentation
             (goto-char (point-min))
             (untabify (point-min) (point-max))
-            (setq ind (org-get-indentation))
+            (setq ind (current-indentation))
             (while (not (eobp))
               (unless (looking-at "[ \t]*$")
-                (setq ind (min ind (org-get-indentation))))
+                (setq ind (min ind (current-indentation))))
               (beginning-of-line 2))
             (goto-char (point-min))
             (while (not (eobp))
@@ -3586,6 +3666,11 @@ removed from the entry content.  Currently only 
`planning' is allowed here."
 (defvar org-agenda-regexp-filter nil)
 (defvar org-agenda-effort-filter nil)
 (defvar org-agenda-top-headline-filter nil)
+
+(defvar org-agenda-represented-categories nil
+  "Cache for the list of all categories in the agenda.")
+(defvar org-agenda-represented-tags nil
+  "Cache for the list of all categories in the agenda.")
 (defvar org-agenda-tag-filter-preset nil
   "A preset of the tags filter used for secondary agenda filtering.
 This must be a list of strings, each string must be a single tag preceded
@@ -3596,6 +3681,20 @@ the entire agenda view.  In a block agenda, it will not 
work reliably to
 define a filter for one of the individual blocks.  You need to set it in
 the global options and expect it to be applied to the entire view.")
 
+(defconst org-agenda-filter-variables
+  '((category . org-agenda-category-filter)
+    (tag . org-agenda-tag-filter)
+    (effort . org-agenda-effort-filter)
+    (regexp . org-agenda-regexp-filter))
+  "Alist of filter types and associated variables")
+(defun org-agenda-filter-any ()
+  "Is any filter active?"
+  (let ((form (cons 'or (mapcar (lambda (x)
+                                 (if (or (symbol-value (cdr x))
+                                         (get :preset-filter x))
+                                     t nil))
+                               org-agenda-filter-variables))))
+    (eval form)))
 (defvar org-agenda-category-filter-preset nil
   "A preset of the category filter used for secondary agenda filtering.
 This must be a list of strings, each string must be a single category
@@ -3681,18 +3780,19 @@ FILTER-ALIST is an alist of filters we need to apply 
when
          (or wconf org-agenda-pre-window-conf))))
 
 (defun org-agenda-prepare (&optional name)
-  (let ((filter-alist (if org-agenda-persistent-filter
-                         (with-current-buffer
-                             (get-buffer-create org-agenda-buffer-name)
-                           (list `(tag . ,org-agenda-tag-filter)
-                                 `(re . ,org-agenda-regexp-filter)
-                                 `(effort . ,org-agenda-effort-filter)
-                                 `(cat . ,org-agenda-category-filter))))))
+  (let ((filter-alist (when org-agenda-persistent-filter
+                       (with-current-buffer
+                           (get-buffer-create org-agenda-buffer-name)
+                         `((tag . ,org-agenda-tag-filter)
+                           (re . ,org-agenda-regexp-filter)
+                           (effort . ,org-agenda-effort-filter)
+                           (cat . ,org-agenda-category-filter))))))
     (if (org-agenda-use-sticky-p)
        (progn
          (put 'org-agenda-tag-filter :preset-filter nil)
          (put 'org-agenda-category-filter :preset-filter nil)
          (put 'org-agenda-regexp-filter :preset-filter nil)
+         (put 'org-agenda-effort-filter :preset-filter nil)
          ;; Popup existing buffer
          (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
                                     filter-alist)
@@ -3743,7 +3843,8 @@ FILTER-ALIST is an alist of filters we need to apply when
             (setq-local org-agenda-name name)))
       (setq buffer-read-only nil))))
 
-(defvar org-agenda-overriding-columns-format)  ; From org-colview.el
+(defvar org-overriding-columns-format)
+(defvar org-local-columns-format)
 (defun org-agenda-finalize ()
   "Finishing touch for the agenda buffer, called just before displaying it."
   (unless org-agenda-multi
@@ -3758,13 +3859,11 @@ FILTER-ALIST is an alist of filters we need to apply 
when
          (org-agenda-align-tags))
        (unless org-agenda-with-colors
          (remove-text-properties (point-min) (point-max) '(face nil)))
-       (if (and (boundp 'org-agenda-overriding-columns-format)
-                org-agenda-overriding-columns-format)
-           (setq-local org-agenda-overriding-columns-format
-                       org-agenda-overriding-columns-format))
-       (if (and (boundp 'org-agenda-view-columns-initially)
-                org-agenda-view-columns-initially)
-           (org-agenda-columns))
+       (when (bound-and-true-p org-overriding-columns-format)
+         (setq-local org-local-columns-format
+                     org-overriding-columns-format))
+       (when org-agenda-view-columns-initially
+         (org-agenda-columns))
        (when org-agenda-fontify-priorities
          (org-agenda-fontify-priorities))
        (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
@@ -3773,9 +3872,9 @@ FILTER-ALIST is an alist of filters we need to apply when
        (when org-agenda-entry-text-mode
          (org-agenda-entry-text-hide)
          (org-agenda-entry-text-show))
-       (if (and (functionp 'org-habit-insert-consistency-graphs)
-                (save-excursion (next-single-property-change (point-min) 
'org-habit-p)))
-           (org-habit-insert-consistency-graphs))
+       (when (and (featurep 'org-habit)
+                  (save-excursion (next-single-property-change (point-min) 
'org-habit-p)))
+         (org-habit-insert-consistency-graphs))
        (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
        (unless (or (eq org-agenda-show-inherited-tags 'always)
                    (and (listp org-agenda-show-inherited-tags)
@@ -3791,10 +3890,12 @@ FILTER-ALIST is an alist of filters we need to apply 
when
              (while (equal (forward-line) 0)
                (when (setq mrk (get-text-property (point) 'org-hd-marker))
                  (put-text-property (point-at-bol) (point-at-eol)
-                                    'tags (org-with-point-at mrk
-                                            (delete-dups
-                                             (mapcar 'downcase 
(org-get-tags-at))))))))))
+                                    'tags
+                                    (org-with-point-at mrk
+                                      (mapcar #'downcase (org-get-tags)))))))))
        (run-hooks 'org-agenda-finalize-hook)
+       (setq org-agenda-represented-tags nil
+             org-agenda-represented-categories nil)
        (when org-agenda-top-headline-filter
          (org-agenda-filter-top-headline-apply
           org-agenda-top-headline-filter))
@@ -3845,15 +3946,15 @@ FILTER-ALIST is an alist of filters we need to apply 
when
 (defun org-agenda-unmark-clocking-task ()
   "Unmark the current clocking task."
   (mapc (lambda (o)
-         (if (eq (overlay-get o 'type) 'org-agenda-clocking)
-             (delete-overlay o)))
+         (when (eq (overlay-get o 'type) 'org-agenda-clocking)
+           (delete-overlay o)))
        (overlays-in (point-min) (point-max))))
 
 (defun org-agenda-fontify-priorities ()
   "Make highest priority lines bold, and lowest italic."
   (interactive)
-  (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
-                  (delete-overlay o)))
+  (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
+                     (delete-overlay o)))
        (overlays-in (point-min) (point-max)))
   (save-excursion
     (let (b e p ov h l)
@@ -4053,12 +4154,11 @@ This check for agenda markers in all agenda buffers 
currently active."
 
 (defun org-agenda-entry-text-hide ()
   "Remove any shown entry context."
-  (delq nil
-       (mapcar (lambda (o)
-                 (if (eq (overlay-get o 'org-overlay-type)
-                         'agenda-entry-content)
-                     (progn (delete-overlay o) t)))
-               (overlays-in (point-min) (point-max)))))
+  (mapc (lambda (o)
+         (when (eq (overlay-get o 'org-overlay-type)
+                   'agenda-entry-content)
+           (delete-overlay o)))
+       (overlays-in (point-min) (point-max))))
 
 (defun org-agenda-get-day-face (date)
   "Return the face DATE should be displayed with."
@@ -4099,28 +4199,31 @@ given in `org-agenda-start-on-weekday'.
 When WITH-HOUR is non-nil, only include scheduled and deadline
 items if they have an hour specification like [h]h:mm."
   (interactive "P")
-  (if org-agenda-overriding-arguments
-      (setq arg (car org-agenda-overriding-arguments)
-           start-day (nth 1 org-agenda-overriding-arguments)
-           span (nth 2 org-agenda-overriding-arguments)))
-  (if (and (integerp arg) (> arg 0))
-      (setq span arg arg nil))
+  (when org-agenda-overriding-arguments
+    (setq arg (car org-agenda-overriding-arguments)
+         start-day (nth 1 org-agenda-overriding-arguments)
+         span (nth 2 org-agenda-overriding-arguments)))
+  (when (and (integerp arg) (> arg 0))
+    (setq span arg arg nil))
+  (when (numberp span)
+    (unless (< 0 span)
+      (user-error "Agenda creation impossible for this span(=%d days)." span)))
   (catch 'exit
     (setq org-agenda-buffer-name
          (or org-agenda-buffer-tmp-name
              (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
-             (if org-agenda-sticky
-                 (cond ((and org-keys (stringp org-match))
-                        (format "*Org Agenda(%s:%s)*" org-keys org-match))
-                       (org-keys
-                        (format "*Org Agenda(%s)*" org-keys))
-                       (t "*Org Agenda(a)*")))
+             (when org-agenda-sticky
+               (cond ((and org-keys (stringp org-match))
+                      (format "*Org Agenda(%s:%s)*" org-keys org-match))
+                     (org-keys
+                      (format "*Org Agenda(%s)*" org-keys))
+                     (t "*Org Agenda(a)*")))
              "*Org Agenda*"))
     (org-agenda-prepare "Day/Week")
     (setq start-day (or start-day org-agenda-start-day))
-    (if (stringp start-day)
-       ;; Convert to an absolute day number
-       (setq start-day (time-to-days (org-read-date nil t start-day))))
+    (when (stringp start-day)
+      ;; Convert to an absolute day number
+      (setq start-day (time-to-days (org-read-date nil t start-day))))
     (org-compile-prefix-format 'agenda)
     (org-set-sorting-strategy 'agenda)
     (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
@@ -4128,8 +4231,8 @@ items if they have an hour specification like [h]h:mm."
           (sd (or start-day today))
           (ndays (org-agenda-span-to-ndays span sd))
           (org-agenda-start-on-weekday
-           (if (or (eq ndays 7) (eq ndays 14))
-               org-agenda-start-on-weekday))
+           (and (or (eq ndays 7) (eq ndays 14))
+                org-agenda-start-on-weekday))
           (thefiles (org-agenda-files nil 'ifmode))
           (files thefiles)
           (start (if (or (null org-agenda-start-on-weekday)
@@ -4162,28 +4265,27 @@ items if they have an hour specification like [h]h:mm."
               (w1 (org-days-to-iso-week d1))
               (w2 (org-days-to-iso-week d2)))
          (setq s (point))
-         (if org-agenda-overriding-header
-             (insert (org-add-props (copy-sequence 
org-agenda-overriding-header)
-                         nil 'face 'org-agenda-structure) "\n")
-           (insert (org-agenda-span-name span)
+         (org-agenda--insert-overriding-header
+           (concat (org-agenda-span-name span)
                    "-agenda"
-                   (if (< (- d2 d1) 350)
-                       (if (= w1 w2)
-                           (format " (W%02d)" w1)
-                         (format " (W%02d-W%02d)" w1 w2))
-                     "")
+                   (cond ((<= 350 (- d2 d1)) "")
+                          ((= w1 w2) (format " (W%02d)" w1))
+                          (t (format " (W%02d-W%02d)" w1 w2)))
                    ":\n")))
-       (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
-                                                 'org-date-line t))
-       (org-agenda-mark-header-line s))
+       ;; Add properties if we actually inserted a header.
+       (when (> (point) s)
+         (add-text-properties s (1- (point))
+                              (list 'face 'org-agenda-structure
+                                    'org-date-line t))
+         (org-agenda-mark-header-line s)))
       (while (setq d (pop day-numbers))
        (setq date (calendar-gregorian-from-absolute d)
              s (point))
        (if (or (setq todayp (= d today))
                (and (not start-pos) (= d sd)))
            (setq start-pos (point))
-         (if (and start-pos (not end-pos))
-             (setq end-pos (point))))
+         (when (and start-pos (not end-pos))
+           (setq end-pos (point))))
        (setq files thefiles
              rtnall nil)
        (while (setq file (pop files))
@@ -4223,34 +4325,33 @@ items if they have an hour specification like [h]h:mm."
                                 file date
                                 org-agenda-entry-types)))))
            (setq rtnall (append rtnall rtn)))) ;; all entries
-       (if org-agenda-include-diary
-           (let ((org-agenda-search-headline-for-time t))
-             (require 'diary-lib)
-             (setq rtn (org-get-entries-from-diary date))
-             (setq rtnall (append rtnall rtn))))
-       (if (or rtnall org-agenda-show-all-dates)
-           (progn
-             (setq day-cnt (1+ day-cnt))
-             (insert
-              (if (stringp org-agenda-format-date)
-                  (format-time-string org-agenda-format-date
-                                      (org-time-from-absolute date))
-                (funcall org-agenda-format-date date))
-              "\n")
-             (put-text-property s (1- (point)) 'face
-                                (org-agenda-get-day-face date))
-             (put-text-property s (1- (point)) 'org-date-line t)
-             (put-text-property s (1- (point)) 'org-agenda-date-header t)
-             (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
-             (when todayp
-               (put-text-property s (1- (point)) 'org-today t))
-             (setq rtnall
-                   (org-agenda-add-time-grid-maybe rtnall ndays todayp))
-             (if rtnall (insert ;; all entries
-                         (org-agenda-finalize-entries rtnall 'agenda)
-                         "\n"))
-             (put-text-property s (1- (point)) 'day d)
-             (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
+       (when org-agenda-include-diary
+         (let ((org-agenda-search-headline-for-time t))
+           (require 'diary-lib)
+           (setq rtn (org-get-entries-from-diary date))
+           (setq rtnall (append rtnall rtn))))
+       (when (or rtnall org-agenda-show-all-dates)
+         (setq day-cnt (1+ day-cnt))
+         (insert
+          (if (stringp org-agenda-format-date)
+              (format-time-string org-agenda-format-date
+                                  (org-time-from-absolute date))
+            (funcall org-agenda-format-date date))
+          "\n")
+         (put-text-property s (1- (point)) 'face
+                            (org-agenda-get-day-face date))
+         (put-text-property s (1- (point)) 'org-date-line t)
+         (put-text-property s (1- (point)) 'org-agenda-date-header t)
+         (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
+         (when todayp
+           (put-text-property s (1- (point)) 'org-today t))
+         (setq rtnall
+               (org-agenda-add-time-grid-maybe rtnall ndays todayp))
+         (when rtnall (insert ;; all entries
+                       (org-agenda-finalize-entries rtnall 'agenda)
+                       "\n"))
+         (put-text-property s (1- (point)) 'day d)
+         (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
       (when (and org-agenda-clockreport-mode clocktable-start)
        (let ((org-agenda-files (org-agenda-files nil 'ifmode))
              ;; the above line is to ensure the restricted range!
@@ -4264,22 +4365,22 @@ items if they have an hour specification like [h]h:mm."
          (insert tbl)))
       (goto-char (point-min))
       (or org-agenda-multi (org-agenda-fit-window-to-buffer))
-      (unless (and (pos-visible-in-window-p (point-min))
-                  (pos-visible-in-window-p (point-max)))
+      (unless (or (not (get-buffer-window))
+                 (and (pos-visible-in-window-p (point-min))
+                      (pos-visible-in-window-p (point-max))))
        (goto-char (1- (point-max)))
        (recenter -1)
-       (if (not (pos-visible-in-window-p (or start-pos 1)))
-           (progn
-             (goto-char (or start-pos 1))
-             (recenter 1))))
+       (when (not (pos-visible-in-window-p (or start-pos 1)))
+         (goto-char (or start-pos 1))
+         (recenter 1)))
       (goto-char (or start-pos 1))
       (add-text-properties (point-min) (point-max)
                           `(org-agenda-type agenda
                                             org-last-args (,arg ,start-day 
,span)
                                             org-redo-cmd 
,org-agenda-redo-command
                                             org-series-cmd ,org-cmd))
-      (if (eq org-agenda-show-log-scoped 'clockcheck)
-         (org-agenda-show-clocking-issues))
+      (when (eq org-agenda-show-log-scoped 'clockcheck)
+       (org-agenda-show-clocking-issues))
       (org-agenda-finalize)
       (setq buffer-read-only t)
       (message ""))))
@@ -4379,10 +4480,10 @@ This command searches the agenda files, and in addition 
the files
 listed in `org-agenda-text-search-extra-files' unless a restriction lock
 is active."
   (interactive "P")
-  (if org-agenda-overriding-arguments
-      (setq todo-only (car org-agenda-overriding-arguments)
-           string (nth 1 org-agenda-overriding-arguments)
-           edit-at (nth 2 org-agenda-overriding-arguments)))
+  (when org-agenda-overriding-arguments
+    (setq todo-only (car org-agenda-overriding-arguments)
+         string (nth 1 org-agenda-overriding-arguments)
+         edit-at (nth 2 org-agenda-overriding-arguments)))
   (let* ((props (list 'face nil
                      'done-face 'org-agenda-done
                      'org-not-done-regexp org-not-done-regexp
@@ -4407,12 +4508,12 @@ is active."
                     (edit-at string))
                    'org-agenda-search-history)))
     (catch 'exit
-      (if org-agenda-sticky
-         (setq org-agenda-buffer-name
-               (if (stringp string)
-                   (format "*Org Agenda(%s:%s)*"
-                           (or org-keys (or (and todo-only "S") "s")) string)
-                 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
+      (when org-agenda-sticky
+       (setq org-agenda-buffer-name
+             (if (stringp string)
+                 (format "*Org Agenda(%s:%s)*"
+                         (or org-keys (or (and todo-only "S") "s")) string)
+               (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
       (org-agenda-prepare "SEARCH")
       (org-compile-prefix-format 'search)
       (org-set-sorting-strategy 'search)
@@ -4430,9 +4531,9 @@ is active."
       (when (equal (string-to-char words) ?:)
        (setq full-words t
              words (substring words 1)))
-      (if (or org-agenda-search-view-always-boolean
-             (member (string-to-char words) '(?- ?+ ?\{)))
-         (setq boolean t))
+      (when (or org-agenda-search-view-always-boolean
+               (member (string-to-char words) '(?- ?+ ?\{)))
+       (setq boolean t))
       (setq words (split-string words))
       (let (www w)
        (while (setq w (pop words))
@@ -4452,12 +4553,12 @@ is active."
       (when boolean
        (let (wds w)
          (while (setq w (pop words))
-           (if (or (equal (substring w 0 1) "\"")
-                   (and (> (length w) 1)
-                        (member (substring w 0 1) '("+" "-"))
-                        (equal (substring w 1 2) "\"")))
-               (while (and words (not (equal (substring w -1) "\"")))
-                 (setq w (concat w " " (pop words)))))
+           (when (or (equal (substring w 0 1) "\"")
+                     (and (> (length w) 1)
+                          (member (substring w 0 1) '("+" "-"))
+                          (equal (substring w 1 2) "\"")))
+             (while (and words (not (equal (substring w -1) "\"")))
+               (setq w (concat w " " (pop words)))))
            (and (string-match "\\`\\([-+]?\\)\"" w)
                 (setq w (replace-match "\\1" nil nil w)))
            (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
@@ -4484,14 +4585,14 @@ is active."
       (if (not regexps+)
          (setq regexp org-outline-regexp-bol)
        (setq regexp (pop regexps+))
-       (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
-                                         regexp))))
+       (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
+                                           regexp))))
       (setq files (org-agenda-files nil 'ifmode))
       ;; Add `org-agenda-text-search-extra-files' unless there is some
       ;; restriction.
-      (unless (get 'org-agenda-files 'org-restrict)
-       (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
-         (pop org-agenda-text-search-extra-files)
+      (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
+       (pop org-agenda-text-search-extra-files)
+       (unless (get 'org-agenda-files 'org-restrict)
          (setq files (org-add-archive-files files))))
       ;; Uniquify files.  However, let `org-check-agenda-file' handle
       ;; non-existent ones.
@@ -4509,10 +4610,10 @@ is active."
          (setq buffer (if (file-exists-p file)
                           (org-get-agenda-file-buffer file)
                         (error "No such file %s" file)))
-         (if (not buffer)
-             ;; If file does not exist, make sure an error message is sent
-             (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
-                                     file))))
+         (unless buffer
+           ;; If file does not exist, make sure an error message is sent
+           (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
+                                   file))))
          (with-current-buffer buffer
            (with-syntax-table (org-search-syntax-table)
              (unless (derived-mode-p 'org-mode)
@@ -4555,12 +4656,12 @@ is active."
                                   (point-at-bol)
                                   (if hdl-only (point-at-eol) end)))
                        (mapc (lambda (wr) (when (string-match wr str)
-                                       (goto-char (1- end))
-                                       (throw :skip t)))
+                                            (goto-char (1- end))
+                                            (throw :skip t)))
                              regexps-)
                        (mapc (lambda (wr) (unless (string-match wr str)
-                                       (goto-char (1- end))
-                                       (throw :skip t)))
+                                            (goto-char (1- end))
+                                            (throw :skip t)))
                              (if todo-only
                                  (cons (concat "^\\*+[ \t]+"
                                                 org-not-done-regexp)
@@ -4577,7 +4678,7 @@ is active."
                                  (and (eq org-agenda-show-inherited-tags t)
                                       (or (eq org-agenda-use-tag-inheritance t)
                                           (memq 'todo 
org-agenda-use-tag-inheritance))))
-                             tags (org-get-tags-at nil (not inherited-tags))
+                             tags (org-get-tags nil (not inherited-tags))
                              txt (org-agenda-format-item
                                   ""
                                   (buffer-substring-no-properties
@@ -4594,25 +4695,25 @@ is active."
                        (goto-char (1- end))))))))))
        (setq rtn (nreverse ee))
        (setq rtnall (append rtnall rtn)))
-      (if org-agenda-overriding-header
-         (insert (org-add-props (copy-sequence org-agenda-overriding-header)
-                     nil 'face 'org-agenda-structure) "\n")
-       (insert "Search words: ")
-       (add-text-properties (point-min) (1- (point))
-                            (list 'face 'org-agenda-structure))
-       (setq pos (point))
-       (insert string "\n")
-       (add-text-properties pos (1- (point)) (list 'face 'org-warning))
-       (setq pos (point))
-       (unless org-agenda-multi
-         (insert (substitute-command-keys "\
+      (org-agenda--insert-overriding-header
+       (with-temp-buffer
+         (insert "Search words: ")
+         (add-text-properties (point-min) (1- (point))
+                              (list 'face 'org-agenda-structure))
+         (setq pos (point))
+         (insert string "\n")
+         (add-text-properties pos (1- (point)) (list 'face 'org-warning))
+         (setq pos (point))
+         (unless org-agenda-multi
+           (insert (substitute-command-keys "\\<org-agenda-mode-map>\
 Press `\\[org-agenda-manipulate-query-add]', \
 `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
 `\\[org-agenda-manipulate-query-add-re]', \
 `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
-`\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
-         (add-text-properties pos (1- (point))
-                              (list 'face 'org-agenda-structure))))
+`\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
+           (add-text-properties pos (1- (point))
+                                (list 'face 'org-agenda-structure)))
+         (buffer-string)))
       (org-agenda-mark-header-line (point-min))
       (when rtnall
        (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
@@ -4651,31 +4752,31 @@ the list to these.  When using 
`\\[universal-argument]', you will be prompted
 for a keyword.  A numeric prefix directly selects the Nth keyword in
 `org-todo-keywords-1'."
   (interactive "P")
-  (if org-agenda-overriding-arguments
-      (setq arg org-agenda-overriding-arguments))
-  (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
+  (when org-agenda-overriding-arguments
+    (setq arg org-agenda-overriding-arguments))
+  (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
   (let* ((today (org-today))
         (date (calendar-gregorian-from-absolute today))
-        (kwds org-todo-keywords-for-agenda)
         (completion-ignore-case t)
-        (org-select-this-todo-keyword
-         (if (stringp arg) arg
-           (and arg (integerp arg) (> arg 0)
-                 (nth (1- arg) kwds))))
-        rtn rtnall files file pos)
-    (when (equal arg '(4))
-      (setq org-select-this-todo-keyword
-           (completing-read "Keyword (or KWD1|K2D2|...): "
-                            (mapcar #'list kwds) nil nil)))
-    (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
+         kwds org-select-this-todo-keyword rtn rtnall files file pos)
     (catch 'exit
-      (if org-agenda-sticky
-         (setq org-agenda-buffer-name
-               (if (stringp org-select-this-todo-keyword)
-                   (format "*Org Agenda(%s:%s)*" (or org-keys "t")
-                           org-select-this-todo-keyword)
-                 (format "*Org Agenda(%s)*" (or org-keys "t")))))
+      (when org-agenda-sticky
+       (setq org-agenda-buffer-name
+             (if (stringp org-select-this-todo-keyword)
+                 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
+                         org-select-this-todo-keyword)
+               (format "*Org Agenda(%s)*" (or org-keys "t")))))
       (org-agenda-prepare "TODO")
+      (setq kwds org-todo-keywords-for-agenda
+            org-select-this-todo-keyword (if (stringp arg) arg
+                                           (and (integerp arg)
+                                               (> arg 0)
+                                                (nth (1- arg) kwds))))
+      (when (equal arg '(4))
+        (setq org-select-this-todo-keyword
+              (completing-read "Keyword (or KWD1|K2D2|...): "
+                               (mapcar #'list kwds) nil nil)))
+      (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
       (org-compile-prefix-format 'todo)
       (org-set-sorting-strategy 'todo)
       (setq org-agenda-redo-command
@@ -4690,31 +4791,31 @@ for a keyword.  A numeric prefix directly selects the 
Nth keyword in
          (org-check-agenda-file file)
          (setq rtn (org-agenda-get-day-entries file date :todo))
          (setq rtnall (append rtnall rtn))))
-      (if org-agenda-overriding-header
-         (insert (org-add-props (copy-sequence org-agenda-overriding-header)
-                     nil 'face 'org-agenda-structure) "\n")
-       (insert "Global list of TODO items of type: ")
-       (add-text-properties (point-min) (1- (point))
-                            (list 'face 'org-agenda-structure
-                                  'short-heading
-                                  (concat "ToDo: "
-                                          (or org-select-this-todo-keyword 
"ALL"))))
-       (org-agenda-mark-header-line (point-min))
-       (insert (org-agenda-propertize-selected-todo-keywords
-                org-select-this-todo-keyword))
-       (setq pos (point))
-       (unless org-agenda-multi
-         (insert (substitute-command-keys "Available with \
-`N \\[org-agenda-redo]': (0)[ALL]"))
-         (let ((n 0) s)
-           (mapc (lambda (x)
-                   (setq s (format "(%d)%s" (setq n (1+ n)) x))
-                   (if (> (+ (current-column) (string-width s) 1) 
(frame-width))
-                       (insert "\n                     "))
-                   (insert " " s))
-                 kwds))
-         (insert "\n"))
-       (add-text-properties pos (1- (point)) (list 'face 
'org-agenda-structure)))
+      (org-agenda--insert-overriding-header
+        (with-temp-buffer
+         (insert "Global list of TODO items of type: ")
+         (add-text-properties (point-min) (1- (point))
+                              (list 'face 'org-agenda-structure
+                                    'short-heading
+                                    (concat "ToDo: "
+                                            (or org-select-this-todo-keyword 
"ALL"))))
+         (org-agenda-mark-header-line (point-min))
+         (insert (org-agenda-propertize-selected-todo-keywords
+                  org-select-this-todo-keyword))
+         (setq pos (point))
+         (unless org-agenda-multi
+           (insert (substitute-command-keys "Press \
+\\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
+to search again: (0)[ALL]"))
+           (let ((n 0))
+              (dolist (k kwds)
+                (let ((s (format "(%d)%s" (cl-incf n) k)))
+                  (when (> (+ (current-column) (string-width s) 1) 
(window-width))
+                    (insert "\n                     "))
+                  (insert " " s))))
+           (insert "\n"))
+         (add-text-properties pos (1- (point)) (list 'face 
'org-agenda-structure))
+         (buffer-string)))
       (org-agenda-mark-header-line (point-min))
       (when rtnall
        (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
@@ -4735,9 +4836,9 @@ for a keyword.  A numeric prefix directly selects the Nth 
keyword in
   "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
 The prefix arg TODO-ONLY limits the search to TODO entries."
   (interactive "P")
-  (if org-agenda-overriding-arguments
-      (setq todo-only (car org-agenda-overriding-arguments)
-           match (nth 1 org-agenda-overriding-arguments)))
+  (when org-agenda-overriding-arguments
+    (setq todo-only (car org-agenda-overriding-arguments)
+         match (nth 1 org-agenda-overriding-arguments)))
   (let* ((org-tags-match-list-sublevels
          org-tags-match-list-sublevels)
         (completion-ignore-case t)
@@ -4747,17 +4848,18 @@ The prefix arg TODO-ONLY limits the search to TODO 
entries."
     (when (and (stringp match) (not (string-match "\\S-" match)))
       (setq match nil))
     (catch 'exit
-      (if org-agenda-sticky
-         (setq org-agenda-buffer-name
-               (if (stringp match)
-                   (format "*Org Agenda(%s:%s)*"
-                           (or org-keys (or (and todo-only "M") "m")) match)
-                 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
+      ;; TODO: this code is repeated a lot...
+      (when org-agenda-sticky
+       (setq org-agenda-buffer-name
+             (if (stringp match)
+                 (format "*Org Agenda(%s:%s)*"
+                         (or org-keys (or (and todo-only "M") "m")) match)
+               (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
+      (setq matcher (org-make-tags-matcher match))
       ;; Prepare agendas (and `org-tag-alist-for-agenda') before
       ;; expanding tags within `org-make-tags-matcher'
       (org-agenda-prepare (concat "TAGS " match))
-      (setq matcher (org-make-tags-matcher match)
-           match (car matcher)
+      (setq match (car matcher)
            matcher (cdr matcher))
       (org-compile-prefix-format 'tags)
       (org-set-sorting-strategy 'tags)
@@ -4792,24 +4894,25 @@ The prefix arg TODO-ONLY limits the search to TODO 
entries."
                                           matcher
                                           org--matcher-tags-todo-only))
                  (setq rtnall (append rtnall rtn))))))))
-      (if org-agenda-overriding-header
-         (insert (org-add-props (copy-sequence org-agenda-overriding-header)
-                     nil 'face 'org-agenda-structure) "\n")
-       (insert "Headlines with TAGS match: ")
-       (add-text-properties (point-min) (1- (point))
-                            (list 'face 'org-agenda-structure
-                                  'short-heading
-                                  (concat "Match: " match)))
-       (setq pos (point))
-       (insert match "\n")
-       (add-text-properties pos (1- (point)) (list 'face 'org-warning))
-       (setq pos (point))
-       (unless org-agenda-multi
-         (insert (substitute-command-keys
-                  "Press `\\[universal-argument] \\[org-agenda-redo]' \
-to search again with new search string\n")))
-       (add-text-properties pos (1- (point))
-                            (list 'face 'org-agenda-structure)))
+      (org-agenda--insert-overriding-header
+        (with-temp-buffer
+         (insert "Headlines with TAGS match: ")
+         (add-text-properties (point-min) (1- (point))
+                              (list 'face 'org-agenda-structure
+                                    'short-heading
+                                    (concat "Match: " match)))
+         (setq pos (point))
+         (insert match "\n")
+         (add-text-properties pos (1- (point)) (list 'face 'org-warning))
+         (setq pos (point))
+         (unless org-agenda-multi
+           (insert (substitute-command-keys
+                    "Press \
+\\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
+to search again\n")))
+         (add-text-properties pos (1- (point))
+                              (list 'face 'org-agenda-structure))
+         (buffer-string)))
       (org-agenda-mark-header-line (point-min))
       (when rtnall
        (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
@@ -4833,8 +4936,11 @@ used by user-defined selections using 
`org-agenda-skip-function'.")
 
 (defvar org-agenda-overriding-header nil
   "When set during agenda, todo and tags searches it replaces the header.
-This variable should not be set directly, but custom commands can bind it
-in the options section.")
+If an empty string, no header will be inserted.  If any other
+string, it will be inserted as a header.  If nil, a header will
+be generated automatically according to the command.  This
+variable should not be set directly, but custom commands can bind
+it in the options section.")
 
 (defun org-agenda-skip-entry-if (&rest conditions)
   "Skip entry if any of CONDITIONS is true.
@@ -4981,14 +5087,14 @@ of what a project is and how to check if it stuck, 
customize the variable
                       (format "^\\*+[ \t]+\\(%s\\)\\>"
                               (mapconcat #'identity todo-wds "\\|"))))
         (tags-re (cond ((null tags) nil)
-                       ((member "*" tags)
-                        (eval-when-compile
+                       ((member "*" tags) org-tag-line-re)
+                       (tags
+                        (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
                           (concat org-outline-regexp-bol
-                                  ".*:[[:alnum:]_@#%]+:[ \t]*$")))
-                       (tags (concat org-outline-regexp-bol
-                                     ".*:\\("
-                                     (mapconcat #'identity tags "\\|")
-                                     "\\):[[:alnum:]_@#%:]*[ \t]*$"))
+                                  ".*?[ \t]:"
+                                  other-tags
+                                  (regexp-opt tags t)
+                                  ":" other-tags "[ \t]*$")))
                        (t nil)))
         (re-list (delq nil (list todo-re tags-re gen-re)))
         (skip-re
@@ -5090,23 +5196,10 @@ each date.  It also removes lines that contain only 
whitespace."
   (while (re-search-forward "^ +\n" nil t)
     (replace-match ""))
   (goto-char (point-min))
-  (if (re-search-forward "^Org mode dummy\n?" nil t)
-      (replace-match ""))
+  (when (re-search-forward "^Org mode dummy\n?" nil t)
+    (replace-match ""))
   (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
 
-;; Make sure entries from the diary have the right text properties.
-(eval-after-load "diary-lib"
-  '(if (boundp 'diary-modify-entry-list-string-function)
-       ;; We can rely on the hook, nothing to do
-       nil
-     ;; Hook not available, must use advice to make this work
-     (defadvice add-to-diary-list (before org-mark-diary-entry activate)
-       "Make the position visible."
-       (if (and org-disable-agenda-to-diary  ;; called from org-agenda
-               (stringp string)
-               buffer-file-name)
-          (setq string (org-modify-diary-entry-string string))))))
-
 (defun org-modify-diary-entry-string (string)
   "Add text properties to string, allowing Org to act on it."
   (org-add-props string nil
@@ -5184,14 +5277,14 @@ function from a program - use 
`org-agenda-get-day-entries' instead."
     (setq org-diary-last-run-time time)
     ;; If this is called during org-agenda, don't return any entries to
     ;; the calendar.  Org Agenda will list these entries itself.
-    (if org-disable-agenda-to-diary (setq files nil))
+    (when org-disable-agenda-to-diary (setq files nil))
     (while (setq file (pop files))
       (setq rtn (apply 'org-agenda-get-day-entries file date args))
       (setq results (append results rtn)))
     (when results
       (setq results
            (mapcar (lambda (i) (replace-regexp-in-string
-                                org-bracket-link-regexp "\\3" i)) results))
+                                org-link-bracket-re "\\2" i)) results))
       (concat (org-agenda-finalize-entries results) "\n"))))
 
 ;;; Agenda entry finders
@@ -5366,7 +5459,7 @@ and the timestamp type relevant for the sorting strategy 
in
                  (and (eq org-agenda-show-inherited-tags t)
                       (or (eq org-agenda-use-tag-inheritance t)
                           (memq 'todo org-agenda-use-tag-inheritance))))
-             tags (org-get-tags-at nil (not inherited-tags))
+             tags (org-get-tags nil (not inherited-tags))
              level (make-string (org-reduced-level (org-outline-level)) ? )
              txt (org-agenda-format-item "" txt level category tags t)
              priority (1+ (org-get-priority txt)))
@@ -5421,7 +5514,7 @@ This function is invoked if 
`org-agenda-todo-ignore-deadlines',
          (and org-agenda-todo-ignore-deadlines
               (re-search-forward org-deadline-time-regexp end t)
               (cond
-               ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
+               ((eq org-agenda-todo-ignore-deadlines 'all) t)
                ((eq org-agenda-todo-ignore-deadlines 'far)
                 (not (org-deadline-close-p (match-string 1))))
                ((eq org-agenda-todo-ignore-deadlines 'future)
@@ -5576,7 +5669,7 @@ displayed in agenda view."
                             (or (eq org-agenda-use-tag-inheritance t)
                                 (memq 'agenda
                                       org-agenda-use-tag-inheritance)))))
-                  (tags (org-get-tags-at nil (not inherited-tags)))
+                  (tags (org-get-tags nil (not inherited-tags)))
                   (level (make-string (org-reduced-level (org-outline-level))
                                       ?\s))
                   (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
@@ -5640,7 +5733,7 @@ displayed in agenda view."
                    (and (eq org-agenda-show-inherited-tags t)
                         (or (eq org-agenda-use-tag-inheritance t)
                             (memq 'agenda org-agenda-use-tag-inheritance))))
-               tags (org-get-tags-at nil (not inherited-tags))
+               tags (org-get-tags nil (not inherited-tags))
                todo-state (org-get-todo-state)
                warntime (get-text-property (point) 'org-appt-warntime)
                extra nil)
@@ -5728,10 +5821,10 @@ then those holidays will be skipped."
         (parts
          (delq nil
                (list
-                (if (memq 'closed items) (concat "\\<" org-closed-string))
-                (if (memq 'clock items) (concat "\\<" org-clock-string))
-                (if (memq 'state items)
-                    (format "- State \"%s\".*?" org-todo-regexp)))))
+                (when (memq 'closed items) (concat "\\<" org-closed-string))
+                (when (memq 'clock items) (concat "\\<" org-clock-string))
+                (when (memq 'state items)
+                  (format "- +State \"%s\".*?" org-todo-regexp)))))
         (parts-re (if parts (mapconcat 'identity parts "\\|")
                     (error "`org-agenda-log-mode-items' is empty")))
         (regexp (concat
@@ -5745,7 +5838,7 @@ then those holidays will be skipped."
                      0 0 0 (nth 1 date) (car date) (nth 2 date)))
                    1 11))))
         (org-agenda-search-headline-for-time nil)
-        marker hdmarker priority category level tags closedp
+        marker hdmarker priority category level tags closedp type
         statep clockp state ee txt extra timestr rest clocked inherited-tags)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
@@ -5790,7 +5883,7 @@ then those holidays will be skipped."
                      (and (eq org-agenda-show-inherited-tags t)
                           (or (eq org-agenda-use-tag-inheritance t)
                               (memq 'todo org-agenda-use-tag-inheritance))))
-                 tags (org-get-tags-at nil (not inherited-tags))
+                 tags (org-get-tags nil (not inherited-tags))
                  level (make-string (org-reduced-level (org-outline-level)) ? 
))
            (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
            (setq txt (match-string 1))
@@ -5805,11 +5898,14 @@ then those holidays will be skipped."
                        (statep (concat "State:     (" state ")"))
                        (t (concat "Clocked:   (" clocked  ")")))
                       txt level category tags timestr)))
+         (setq type (cond (closedp "closed")
+                          (statep "state")
+                          (t "clock")))
          (setq priority 100000)
          (org-add-props txt props
            'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
            'priority priority 'level level
-           'type "closed" 'date date
+           'type type 'date date
            'undone-face 'org-warning 'done-face 'org-agenda-done)
          (push txt ee))
        (goto-char (point-at-eol))))
@@ -5854,7 +5950,14 @@ See also the user option 
`org-agenda-clock-consistency-checks'."
              (error "No valid Clock line")
              (throw 'next t))
            (unless (match-end 3)
-             (setq issue "No end time"
+             (setq issue
+                   (format
+                    "No end time: (%s)"
+                    (org-duration-from-minutes
+                     (floor
+                      (- (float-time (org-current-time))
+                         (float-time (org-time-string-to-time (match-string 
1))))
+                      60)))
                    face (or (plist-get pl :no-end-time-face) face))
              (throw 'next t))
            (setq ts (match-string 1)
@@ -5904,15 +6007,15 @@ See also the user option 
`org-agenda-clock-consistency-checks'."
     (unless ok-list
       ;; there are no OK times for gaps...
       (throw 'exit nil))
-    (if (> (- (/ t2 36000) (/ t1 36000)) 24)
-       ;; This is more than 24 hours, so it is OK.
-       ;; because we have at least one OK time, that must be in the
-       ;; 24 hour interval.
-       (throw 'exit t))
+    (when (> (- (/ t2 36000) (/ t1 36000)) 24)
+      ;; This is more than 24 hours, so it is OK.
+      ;; because we have at least one OK time, that must be in the
+      ;; 24 hour interval.
+      (throw 'exit t))
     ;; We have a shorter gap.
     ;; Now we have to get the minute of the day when these times are
-    (let* ((t1dec (decode-time t1))
-          (t2dec (decode-time t2))
+    (let* ((t1dec (org-decode-time t1))
+          (t2dec (org-decode-time t2))
           ;; compute the minute on the day
           (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
           (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
@@ -5923,7 +6026,7 @@ See also the user option 
`org-agenda-clock-consistency-checks'."
       ;; Now check if any of the OK times is in the gap
       (mapc (lambda (x)
              ;; Wrap the time to after midnight if necessary
-             (if (< x min1) (setq x (+ x 1440)))
+             (when (< x min1) (setq x (+ x 1440)))
              ;; Check if in interval
              (and (<= min1 x) (>= min2 x) (throw 'exit t)))
            ok-list)
@@ -6004,10 +6107,7 @@ specification like [h]h:mm."
                         org-deadline-warning-days))
                   ;; Set pre-warning to deadline.
                   (t 0))))
-              (wdays (if suppress-prewarning
-                         (let ((org-deadline-warning-days suppress-prewarning))
-                           (org-get-wdays s))
-                       (org-get-wdays s))))
+              (wdays (or suppress-prewarning (org-get-wdays s))))
          (cond
           ;; Only display deadlines at their base date, at future
           ;; repeat occurrences or in today agenda.
@@ -6039,7 +6139,7 @@ specification like [h]h:mm."
                             (or (eq org-agenda-use-tag-inheritance t)
                                 (memq 'agenda
                                       org-agenda-use-tag-inheritance)))))
-                  (tags (org-get-tags-at nil (not inherited-tags)))
+                  (tags (org-get-tags nil (not inherited-tags)))
                   (time
                    (cond
                     ;; No time of day designation if it is only
@@ -6154,6 +6254,7 @@ scheduled items with an hour specification like [h]h:mm."
               (diff (- current schedule))
               (warntime (get-text-property (point) 'org-appt-warntime))
               (pastschedp (< schedule today))
+              (futureschedp (> schedule today))
               (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
               (suppress-delay
                (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
@@ -6191,7 +6292,8 @@ scheduled items with an hour specification like [h]h:mm."
                       habitp
                       (bound-and-true-p org-habit-show-all-today))
            (when (or (and (> ddays 0) (< diff ddays))
-                     (> diff org-scheduled-past-days)
+                     (> diff (or (and habitp org-habit-scheduled-past-days)
+                                 org-scheduled-past-days))
                      (> schedule current)
                      (and (/= current schedule)
                           (/= current today)
@@ -6239,15 +6341,23 @@ scheduled items with an hour specification like 
[h]h:mm."
                             (or (eq org-agenda-use-tag-inheritance t)
                                 (memq 'agenda
                                       org-agenda-use-tag-inheritance)))))
-                  (tags (org-get-tags-at nil (not inherited-tags)))
+                  (tags (org-get-tags nil (not inherited-tags)))
                   (level (make-string (org-reduced-level (org-outline-level))
                                       ?\s))
                   (head (buffer-substring (point) (line-end-position)))
                   (time
                    (cond
-                    ;; No time of day designation if it is only
-                    ;; a reminder.
-                    ((and (/= current schedule) (/= current repeat)) nil)
+                    ;; No time of day designation if it is only a
+                    ;; reminder, except for habits, which always show
+                    ;; the time of day.  Habits are an exception
+                    ;; because if there is a time of day, that is
+                    ;; interpreted to mean they should usually happen
+                    ;; then, even if doing the habit was missed.
+                    ((and
+                      (not habitp)
+                      (/= current schedule)
+                      (/= current repeat))
+                     nil)
                     ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
                      (concat (substring s (match-beginning 1)) " "))
                     (t 'time)))
@@ -6261,6 +6371,8 @@ scheduled items with an hour specification like [h]h:mm."
                     head level category tags time nil habitp))
                   (face (cond ((and (not habitp) pastschedp)
                                'org-scheduled-previously)
+                              ((and habitp futureschedp)
+                               'org-agenda-done)
                               (todayp 'org-scheduled-today)
                               (t 'org-scheduled)))
                   (habitp (and habitp (org-habit-parse-todo))))
@@ -6324,59 +6436,59 @@ scheduled items with an hour specification like 
[h]h:mm."
                        pos
                        (current-buffer)
                        (error-message-string err))))))
-         (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
-             ;; Only allow days between the limits, because the normal
-             ;; date stamps will catch the limits.
-             (save-excursion
-               (setq todo-state (org-get-todo-state))
-               (setq donep (member todo-state org-done-keywords))
-               (if (and donep org-agenda-skip-timestamp-if-done)
-                   (throw :skip t))
-               (setq marker (org-agenda-new-marker (point))
-                     category (org-get-category))
-               (if (not (re-search-backward org-outline-regexp-bol nil t))
-                   (throw :skip nil)
-                 (goto-char (match-beginning 0))
-                 (setq hdmarker (org-agenda-new-marker (point))
-                       inherited-tags
-                       (or (eq org-agenda-show-inherited-tags 'always)
-                           (and (listp org-agenda-show-inherited-tags)
-                                (memq 'agenda org-agenda-show-inherited-tags))
-                           (and (eq org-agenda-show-inherited-tags t)
-                                (or (eq org-agenda-use-tag-inheritance t)
-                                    (memq 'agenda 
org-agenda-use-tag-inheritance))))
-
-                       tags (org-get-tags-at nil (not inherited-tags)))
-                 (setq level (make-string (org-reduced-level 
(org-outline-level)) ? ))
-                 (looking-at "\\*+[ \t]+\\(.*\\)")
-                 (setq head (match-string 1))
-                 (let ((remove-re
-                        (if org-agenda-remove-timeranges-from-blocks
-                            (concat
-                             "<" (regexp-quote s1) ".*?>"
-                             "--"
-                             "<" (regexp-quote s2) ".*?>")
-                          nil)))
-                   (setq txt (org-agenda-format-item
-                              (format
-                               (nth (if (= d1 d2) 0 1)
-                                    org-agenda-timerange-leaders)
-                               (1+ (- d0 d1)) (1+ (- d2 d1)))
-                              head level category tags
-                              (cond ((and (= d1 d0) (= d2 d0))
-                                     (concat "<" start-time ">--<" end-time 
">"))
-                                     ((= d1 d0)
-                                     (concat "<" start-time ">"))
-                                    ((= d2 d0)
-                                     (concat "<" end-time ">")))
-                              remove-re))))
-               (org-add-props txt props
-                 'org-marker marker 'org-hd-marker hdmarker
-                 'type "block" 'date date
-                 'level level
-                 'todo-state todo-state
-                 'priority (org-get-priority txt))
-               (push txt ee))))
+         (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
+           ;; Only allow days between the limits, because the normal
+           ;; date stamps will catch the limits.
+           (save-excursion
+             (setq todo-state (org-get-todo-state))
+             (setq donep (member todo-state org-done-keywords))
+             (when (and donep org-agenda-skip-timestamp-if-done)
+               (throw :skip t))
+             (setq marker (org-agenda-new-marker (point))
+                   category (org-get-category))
+             (if (not (re-search-backward org-outline-regexp-bol nil t))
+                 (throw :skip nil)
+               (goto-char (match-beginning 0))
+               (setq hdmarker (org-agenda-new-marker (point))
+                     inherited-tags
+                     (or (eq org-agenda-show-inherited-tags 'always)
+                         (and (listp org-agenda-show-inherited-tags)
+                              (memq 'agenda org-agenda-show-inherited-tags))
+                         (and (eq org-agenda-show-inherited-tags t)
+                              (or (eq org-agenda-use-tag-inheritance t)
+                                  (memq 'agenda 
org-agenda-use-tag-inheritance))))
+
+                     tags (org-get-tags nil (not inherited-tags)))
+               (setq level (make-string (org-reduced-level 
(org-outline-level)) ? ))
+               (looking-at "\\*+[ \t]+\\(.*\\)")
+               (setq head (match-string 1))
+               (let ((remove-re
+                      (if org-agenda-remove-timeranges-from-blocks
+                          (concat
+                           "<" (regexp-quote s1) ".*?>"
+                           "--"
+                           "<" (regexp-quote s2) ".*?>")
+                        nil)))
+                 (setq txt (org-agenda-format-item
+                            (format
+                             (nth (if (= d1 d2) 0 1)
+                                  org-agenda-timerange-leaders)
+                             (1+ (- d0 d1)) (1+ (- d2 d1)))
+                            head level category tags
+                            (cond ((and (= d1 d0) (= d2 d0))
+                                   (concat "<" start-time ">--<" end-time ">"))
+                                   ((= d1 d0)
+                                   (concat "<" start-time ">"))
+                                  ((= d2 d0)
+                                   (concat "<" end-time ">")))
+                            remove-re))))
+             (org-add-props txt props
+               'org-marker marker 'org-hd-marker hdmarker
+               'type "block" 'date date
+               'level level
+               'todo-state todo-state
+               'priority (org-get-priority txt))
+             (push txt ee))))
        (goto-char pos)))
     ;; Sort the entries by expiration date.
     (nreverse ee)))
@@ -6460,9 +6572,9 @@ Any match of REMOVE-RE will be removed from TXT."
             (tag (if tags (nth (1- (length tags)) tags) ""))
             (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
             time
-            (ts (if dotime (concat
-                            (if (stringp dotime) dotime "")
-                            (and org-agenda-search-headline-for-time txt))))
+            (ts (when dotime (concat
+                              (if (stringp dotime) dotime "")
+                              (and org-agenda-search-headline-for-time txt))))
             (time-of-day (and dotime (org-get-time-of-day ts)))
             stamp plain s0 s1 s2 rtn srp l
             duration breadcrumbs)
@@ -6480,17 +6592,17 @@ Any match of REMOVE-RE will be removed from TXT."
            ;; If the times are in TXT (not in DOTIMES), and the prefix will 
list
            ;; them, we might want to remove them there to avoid duplication.
            ;; The user can turn this off with a variable.
-           (if (and org-prefix-has-time
-                    org-agenda-remove-times-when-in-prefix (or stamp plain)
-                    (string-match (concat (regexp-quote s0) " *") txt)
-                    (not (equal ?\] (string-to-char (substring txt (match-end 
0)))))
-                    (if (eq org-agenda-remove-times-when-in-prefix 'beg)
-                        (= (match-beginning 0) 0)
-                      t))
-               (setq txt (replace-match "" nil nil txt))))
+           (when (and org-prefix-has-time
+                      org-agenda-remove-times-when-in-prefix (or stamp plain)
+                      (string-match (concat (regexp-quote s0) " *") txt)
+                      (not (equal ?\] (string-to-char (substring txt 
(match-end 0)))))
+                      (if (eq org-agenda-remove-times-when-in-prefix 'beg)
+                          (= (match-beginning 0) 0)
+                        t))
+             (setq txt (replace-match "" nil nil txt))))
          ;; Normalize the time(s) to 24 hour
-         (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
-         (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
+         (when s1 (setq s1 (org-get-time-of-day s1 'string t)))
+         (when s2 (setq s2 (org-get-time-of-day s2 'string t)))
 
          ;; Try to set s2 if s1 and
          ;; `org-agenda-default-appointment-duration' are set
@@ -6506,7 +6618,7 @@ Any match of REMOVE-RE will be removed from TXT."
            (setq duration (- (org-duration-to-minutes s2)
                              (org-duration-to-minutes s1)))))
 
-       (when (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
+       (when (string-match org-tag-group-re txt)
          ;; Tags are in the string
          (if (or (eq org-agenda-remove-tags t)
                  (and org-agenda-remove-tags
@@ -6514,7 +6626,7 @@ Any match of REMOVE-RE will be removed from TXT."
              (setq txt (replace-match "" t t txt))
            (setq txt (replace-match
                       (concat (make-string (max (- 50 (length txt)) 1) ?\ )
-                              (match-string 2 txt))
+                              (match-string 1 txt))
                       t t txt))))
 
        (when remove-re
@@ -6526,14 +6638,16 @@ Any match of REMOVE-RE will be removed from TXT."
        (add-text-properties 0 (length txt) '(org-heading t) txt)
 
        ;; Prepare the variables needed in the eval of the compiled format
-       (if org-prefix-has-breadcrumbs
-           (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
-                               (let ((s (org-display-outline-path nil nil "->" 
t)))
-                                 (if (eq "" s) "" (concat s "->"))))))
+       (when org-prefix-has-breadcrumbs
+         (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
+                             (let ((s (org-format-outline-path 
(org-get-outline-path)
+                                                               (1- 
(frame-width))
+                                                               nil 
org-agenda-breadcrumbs-separator)))
+                               (if (eq "" s) "" (concat s 
org-agenda-breadcrumbs-separator))))))
        (setq time (cond (s2 (concat
                              (org-agenda-time-of-day-to-ampm-maybe s1)
                              "-" (org-agenda-time-of-day-to-ampm-maybe s2)
-                             (if org-agenda-timegrid-use-ampm " ")))
+                             (when org-agenda-timegrid-use-ampm " ")))
                         (s1 (concat
                              (org-agenda-time-of-day-to-ampm-maybe s1)
                              (if org-agenda-timegrid-use-ampm
@@ -6543,19 +6657,17 @@ Any match of REMOVE-RE will be removed from TXT."
              extra (or (and (not habitp) extra) "")
              category (if (symbolp category) (symbol-name category) category)
              level (or level ""))
-       (if (string-match org-bracket-link-regexp category)
+       (if (string-match org-link-bracket-re category)
            (progn
-             (setq l (if (match-end 3)
-                         (- (match-end 3) (match-beginning 3))
-                       (- (match-end 1) (match-beginning 1))))
+             (setq l (string-width (or (match-string 2) (match-string 1))))
              (when (< l (or org-prefix-category-length 0))
                (setq category (copy-sequence category))
                (org-add-props category nil
                  'extra-space (make-string
                                (- org-prefix-category-length l 1) ?\ ))))
-         (if (and org-prefix-category-max-length
-                  (>= (length category) org-prefix-category-max-length))
-             (setq category (substring category 0 (1- 
org-prefix-category-max-length)))))
+         (when (and org-prefix-category-max-length
+                    (>= (length category) org-prefix-category-max-length))
+           (setq category (substring category 0 (1- 
org-prefix-category-max-length)))))
        ;; Evaluate the compiled format
        (setq rtn (concat (eval formatter) txt))
 
@@ -6581,8 +6693,8 @@ Any match of REMOVE-RE will be removed from TXT."
 The modified list may contain inherited tags, and tags matched by
 `org-agenda-hide-tags-regexp' will be removed."
   (when (or add-inherited hide-re)
-    (if (string-match "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" txt)
-       (setq txt (substring txt 0 (match-beginning 0))))
+    (when (string-match org-tag-group-re txt)
+      (setq txt (substring txt 0 (match-beginning 0))))
     (setq tags
          (delq nil
                (mapcar (lambda (tg)
@@ -6636,9 +6748,9 @@ TODAYP is t when the current agenda view is on today."
           (req (car org-agenda-time-grid))
           (remove (member 'remove-match req))
           new time)
-      (if (and (member 'require-timed req) (not have))
-         ;; don't show empty grid
-         (throw 'exit list))
+      (when (and (member 'require-timed req) (not have))
+       ;; don't show empty grid
+       (throw 'exit list))
       (while (setq time (pop gridtimes))
        (unless (and remove (member time have))
          (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
@@ -6686,10 +6798,11 @@ and stored in the variable 
`org-prefix-format-compiled'."
            c (or (match-string 3 s) "")
            opt (match-beginning 1)
            start (1+ (match-beginning 0)))
-      (if (eq var 'time) (setq org-prefix-has-time t))
-      (if (eq var 'tag)  (setq org-prefix-has-tag  t))
-      (if (eq var 'effort) (setq org-prefix-has-effort t))
-      (if (eq var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
+      (cl-case var
+       (time        (setq org-prefix-has-time        t))
+       (tag         (setq org-prefix-has-tag         t))
+       (effort      (setq org-prefix-has-effort      t))
+       (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
       (setq f (concat "%" (match-string 2 s) "s"))
       (when (eq var 'category)
        (setq org-prefix-category-length
@@ -6697,8 +6810,8 @@ and stored in the variable `org-prefix-format-compiled'."
        (setq org-prefix-category-max-length
              (let ((x (match-string 2 s)))
                (save-match-data
-                 (if (string-match "\\.[0-9]+" x)
-                     (string-to-number (substring (match-string 0 x) 1)))))))
+                 (and (string-match "\\.[0-9]+" x)
+                      (string-to-number (substring (match-string 0 x) 1)))))))
       (if (eq var 'eval)
          (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
        (if opt
@@ -6746,7 +6859,7 @@ HH:MM."
         (not (eq (get-text-property 1 'face s) 'org-link)))
       (let* ((h (string-to-number (match-string 1 s)))
             (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
-            (ampm (if (match-end 4) (downcase (match-string 4 s))))
+            (ampm (when (match-end 4) (downcase (match-string 4 s))))
             (am-p (equal ampm "am"))
             (h1   (cond ((not ampm) h)
                         ((= h 12) (if am-p 0 12))
@@ -6823,7 +6936,7 @@ The optional argument TYPE tells the agenda type."
   "Limit the number of agenda entries."
   (let ((include (and limit (< limit 0))))
     (if limit
-       (let ((fun (or fn (lambda (p) (if p 1))))
+       (let ((fun (or fn (lambda (p) (when p 1))))
              (lim 0))
          (delq nil
                (mapcar
@@ -6831,7 +6944,7 @@ The optional argument TYPE tells the agenda type."
                   (let ((pval (funcall
                                fun (get-text-property (1- (length e))
                                                       prop e))))
-                    (if pval (setq lim (+ lim pval)))
+                    (when pval (setq lim (+ lim pval)))
                     (cond ((and pval (<= lim (abs limit))) e)
                           ((and include (not pval)) e))))
                 list)))
@@ -6969,16 +7082,17 @@ The optional argument TYPE tells the agenda type."
         (tb (and plb (substring b plb)))
         (case-fold-search nil))
     (when pla
-      (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 
'org-todo-regexp a) "")
-                               "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
-         (setq ta (substring ta (match-end 0))))
+      (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 
'org-todo-regexp a) "")
+                                 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
+       (setq ta (substring ta (match-end 0))))
       (setq ta (downcase ta)))
     (when plb
-      (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 
'org-todo-regexp b) "")
-                               "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
-         (setq tb (substring tb (match-end 0))))
+      (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 
'org-todo-regexp b) "")
+                                 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
+       (setq tb (substring tb (match-end 0))))
       (setq tb (downcase tb)))
-    (cond ((not ta) +1)
+    (cond ((not (or ta tb)) nil)
+         ((not ta) +1)
          ((not tb) -1)
          ((string-lessp ta tb) -1)
          ((string-lessp tb ta) +1))))
@@ -6987,7 +7101,8 @@ The optional argument TYPE tells the agenda type."
   "Compare the string values of the first tags of A and B."
   (let ((ta (car (last (get-text-property 1 'tags a))))
        (tb (car (last (get-text-property 1 'tags b)))))
-    (cond ((not ta) +1)
+    (cond ((not (or ta tb)) nil)
+         ((not ta) +1)
          ((not tb) -1)
          ((string-lessp ta tb) -1)
          ((string-lessp tb ta) +1))))
@@ -7074,11 +7189,11 @@ their type."
         (alpha-down      (if alpha-up (- alpha-up) nil))
         (need-user-cmp   (org-em 'user-defined-up 'user-defined-down ss))
         user-defined-up user-defined-down)
-    (if (and need-user-cmp org-agenda-cmp-user-defined
-            (functionp org-agenda-cmp-user-defined))
-       (setq user-defined-up
-             (funcall org-agenda-cmp-user-defined a b)
-             user-defined-down (if user-defined-up (- user-defined-up) nil)))
+    (when (and need-user-cmp org-agenda-cmp-user-defined
+              (functionp org-agenda-cmp-user-defined))
+      (setq user-defined-up
+           (funcall org-agenda-cmp-user-defined a b)
+           user-defined-down (if user-defined-up (- user-defined-up) nil)))
     (cdr (assoc
          (eval (cons 'or org-agenda-sorting-strategy-selected))
          '((-1 . t) (1 . nil) (nil . nil))))))
@@ -7111,58 +7226,69 @@ Argument ARG is the prefix argument."
 
 ;;;###autoload
 (defun org-agenda-set-restriction-lock (&optional type)
-  "Set restriction lock for agenda, to current subtree or file.
-Restriction will be the file if TYPE is `file', or if type is the
-universal prefix \\='(4), or if the cursor is before the first headline
-in the file.  Otherwise, restriction will be to the current subtree."
+  "Set restriction lock for agenda to current subtree or file.
+When in a restricted subtree, remove it.
+
+The restriction will span over the entire file if TYPE is `file',
+or if type is '(4), or if the cursor is before the first headline
+in the file. Otherwise, only apply the restriction to the current
+subtree."
   (interactive "P")
-  (org-agenda-remove-restriction-lock 'noupdate)
-  (and (equal type '(4)) (setq type 'file))
-  (setq type (cond
-             (type type)
-             ((org-at-heading-p) 'subtree)
-             ((condition-case nil (org-back-to-heading t) (error nil))
-              'subtree)
-             (t 'file)))
-  (if (eq type 'subtree)
-      (progn
-       (setq org-agenda-restrict (current-buffer))
-       (setq org-agenda-overriding-restriction 'subtree)
-       (put 'org-agenda-files 'org-restrict
-            (list (buffer-file-name (buffer-base-buffer))))
-       (org-back-to-heading t)
-       (move-overlay org-agenda-restriction-lock-overlay
-                     (point)
-                     (if org-agenda-restriction-lock-highlight-subtree
-                         (save-excursion (org-end-of-subtree t t) (point))
-                       (point-at-eol)))
-       (move-marker org-agenda-restrict-begin (point))
-       (move-marker org-agenda-restrict-end
-                    (save-excursion (org-end-of-subtree t t)))
-       (message "Locking agenda restriction to subtree"))
-    (put 'org-agenda-files 'org-restrict
-        (list (buffer-file-name (buffer-base-buffer))))
-    (setq org-agenda-restrict nil)
-    (setq org-agenda-overriding-restriction 'file)
-    (move-marker org-agenda-restrict-begin nil)
-    (move-marker org-agenda-restrict-end nil)
-    (message "Locking agenda restriction to file"))
-  (setq current-prefix-arg nil)
+  (if (and org-agenda-overriding-restriction
+          (member org-agenda-restriction-lock-overlay
+                  (overlays-at (point)))
+          (equal (overlay-start org-agenda-restriction-lock-overlay)
+                 (point)))
+      (org-agenda-remove-restriction-lock 'noupdate)
+    (org-agenda-remove-restriction-lock 'noupdate)
+    (and (equal type '(4)) (setq type 'file))
+    (setq type (cond
+               (type type)
+               ((org-at-heading-p) 'subtree)
+               ((condition-case nil (org-back-to-heading t) (error nil))
+                'subtree)
+               (t 'file)))
+    (if (eq type 'subtree)
+       (progn
+         (setq org-agenda-restrict (current-buffer))
+         (setq org-agenda-overriding-restriction 'subtree)
+         (put 'org-agenda-files 'org-restrict
+              (list (buffer-file-name (buffer-base-buffer))))
+         (org-back-to-heading t)
+         (move-overlay org-agenda-restriction-lock-overlay
+                       (point)
+                       (if org-agenda-restriction-lock-highlight-subtree
+                           (save-excursion (org-end-of-subtree t t) (point))
+                         (point-at-eol)))
+         (move-marker org-agenda-restrict-begin (point))
+         (move-marker org-agenda-restrict-end
+                      (save-excursion (org-end-of-subtree t t)))
+         (message "Locking agenda restriction to subtree"))
+      (put 'org-agenda-files 'org-restrict
+          (list (buffer-file-name (buffer-base-buffer))))
+      (setq org-agenda-restrict nil)
+      (setq org-agenda-overriding-restriction 'file)
+      (move-marker org-agenda-restrict-begin nil)
+      (move-marker org-agenda-restrict-end nil)
+      (message "Locking agenda restriction to file"))
+    (setq current-prefix-arg nil))
   (org-agenda-maybe-redo))
 
 (defun org-agenda-remove-restriction-lock (&optional noupdate)
-  "Remove the agenda restriction lock."
+  "Remove agenda restriction lock."
   (interactive "P")
-  (delete-overlay org-agenda-restriction-lock-overlay)
-  (delete-overlay org-speedbar-restriction-lock-overlay)
-  (setq org-agenda-overriding-restriction nil)
-  (setq org-agenda-restrict nil)
-  (put 'org-agenda-files 'org-restrict nil)
-  (move-marker org-agenda-restrict-begin nil)
-  (move-marker org-agenda-restrict-end nil)
-  (setq current-prefix-arg nil)
-  (message "Agenda restriction lock removed")
-  (or noupdate (org-agenda-maybe-redo)))
+  (if (not org-agenda-restrict)
+      (message "No agenda restriction to remove.")
+    (delete-overlay org-agenda-restriction-lock-overlay)
+    (delete-overlay org-speedbar-restriction-lock-overlay)
+    (setq org-agenda-overriding-restriction nil)
+    (setq org-agenda-restrict nil)
+    (put 'org-agenda-files 'org-restrict nil)
+    (move-marker org-agenda-restrict-begin nil)
+    (move-marker org-agenda-restrict-end nil)
+    (setq current-prefix-arg nil)
+    (message "Agenda restriction lock removed")
+    (or noupdate (org-agenda-maybe-redo))))
 
 (defun org-agenda-maybe-redo ()
   "If there is any window showing the agenda view, update it."
@@ -7182,14 +7308,14 @@ in the file.  Otherwise, restriction will be to the 
current subtree."
 ;;; Agenda commands
 
 (defun org-agenda-check-type (error &rest types)
-  "Check if agenda buffer is of allowed type.
+  "Check if agenda buffer or component is of allowed type.
 If ERROR is non-nil, throw an error, otherwise just return nil.
 Allowed types are `agenda' `todo' `tags' `search'."
   (cond ((not org-agenda-type)
         (error "No Org agenda currently displayed"))
        ((memq org-agenda-type types) t)
        (error
-        (error "Not allowed in %s-type agenda buffers" org-agenda-type))
+        (error "Not allowed in '%s'-type agenda buffer or component" 
org-agenda-type))
        (t nil)))
 
 (defun org-agenda-Quit ()
@@ -7361,11 +7487,15 @@ With a prefix argument, do so in all agenda buffers."
 (defvar org-agenda-filter-form nil)
 (defvar org-agenda-filtered-by-category nil)
 
+(defsubst org-agenda-get-category ()
+  "Return the category of the agenda line."
+  (org-get-at-bol 'org-category))
+
 (defun org-agenda-filter-by-category (strip)
   "Filter lines in the agenda buffer that have a specific category.
 The category is that of the current line.
-Without prefix argument, keep only the lines of that category.
-With a prefix argument, exclude the lines of that category."
+With a `\\[universal-argument]' prefix argument, exclude the lines of that 
category.
+When there is already a category filter in place, this command removes the 
filter."
   (interactive "P")
   (if (and org-agenda-filtered-by-category
           org-agenda-category-filter)
@@ -7395,7 +7525,8 @@ search from."
 (defvar org-agenda-filtered-by-top-headline nil)
 (defun org-agenda-filter-by-top-headline (strip)
   "Keep only those lines that are descendants from the same top headline.
-The top headline is that of the current line."
+The top headline is that of the current line.  With prefix arg STRIP, hide
+all lines of the category at point."
   (interactive "P")
   (if org-agenda-filtered-by-top-headline
       (progn
@@ -7407,46 +7538,60 @@ The top headline is that of the current line."
         (error "No top-level headline at point")))))
 
 (defvar org-agenda-regexp-filter nil)
-(defun org-agenda-filter-by-regexp (strip)
-  "Filter agenda entries by a regular expression.
-Regexp filters are cumulative.
-With no prefix argument, keep entries matching the regexp.
-With one prefix argument, filter out entries matching the regexp.
-With two prefix arguments, remove the regexp filters."
+(defun org-agenda-filter-by-regexp (strip-or-accumulate)
+  "Filter agenda entries by a regular expressions.
+You will be prompted for the regular expression, and the agenda
+view will only show entries that are matched by that expression.
+
+With one `\\[universal-argument]' prefix argument, hide entries matching the 
regexp.
+When there is already a regexp filter active, this command removed the
+filter.  However, with two `\\[universal-argument]' prefix arguments, add a 
new condition to
+an already existing regexp filter."
   (interactive "P")
-  (if (not (equal strip '(16)))
-      (let ((flt (concat (if (equal strip '(4)) "-" "+")
-                        (read-from-minibuffer
-                         (if (equal strip '(4))
-                             "Filter out entries matching regexp: "
-                           "Narrow to entries matching regexp: ")))))
-       (push flt org-agenda-regexp-filter)
-       (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
-    (org-agenda-filter-show-all-re)
-    (message "Regexp filter removed")))
+  (let* ((strip (equal strip-or-accumulate '(4)))
+        (accumulate (equal strip-or-accumulate '(16))))
+    (cond
+     ((and org-agenda-regexp-filter (not accumulate))
+      (org-agenda-filter-show-all-re)
+      (message "Regexp filter removed"))
+     (t (let ((flt (concat (if strip "-" "+")
+                          (read-from-minibuffer
+                           (if strip
+                               "Hide entries matching regexp: "
+                             "Narrow to entries matching regexp: ")))))
+         (push flt org-agenda-regexp-filter)
+         (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
 
 (defvar org-agenda-effort-filter nil)
-(defun org-agenda-filter-by-effort (strip)
+(defun org-agenda-filter-by-effort (strip-or-accumulate)
   "Filter agenda entries by effort.
-With no prefix argument, keep entries matching the effort condition.
-With one prefix argument, filter out entries matching the condition.
-With two prefix arguments, remove the effort filters."
+With no `\\[universal-argument]' prefix argument, keep entries matching the 
effort condition.
+With one `\\[universal-argument]' prefix argument, filter out entries matching 
the condition.
+With two `\\[universal-argument]' prefix arguments, add a second condition to 
the existing filter.
+This last option is in practice not very useful, but it is available for
+consistency with the other filter commands."
   (interactive "P")
-  (cond
-   ((member strip '(nil 4))
-    (let* ((efforts (split-string
-                    (or (cdr (assoc (concat org-effort-property "_ALL")
-                                    org-global-properties))
-                        "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
-          ;; XXX: the following handles only up to 10 different
-          ;; effort values.
-          (allowed-keys (if (null efforts) nil
-                          (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
-                                  (number-sequence 1 (length efforts)))))
-          (op nil))
-      (while (not (memq op '(?< ?> ?=)))
-       (setq op (read-char-exclusive "Effort operator? (> = or <)")))
-      ;; Select appropriate duration.  Ignore non-digit characters.
+  (let* ((efforts (split-string
+                  (or (cdr (assoc (concat org-effort-property "_ALL")
+                                  org-global-properties))
+                      "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
+        ;; XXX: the following handles only up to 10 different
+        ;; effort values.
+        (allowed-keys (if (null efforts) nil
+                        (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
+                                (number-sequence 1 (length efforts)))))
+        (keep (equal strip-or-accumulate '(16)))
+        (negative (equal strip-or-accumulate '(4)))
+        (current org-agenda-effort-filter)
+        (op nil))
+    (while (not (memq op '(?< ?> ?= ?_)))
+      (setq op (read-char-exclusive
+               "Effort operator? (> = or <)     or press `_' again to remove 
filter")))
+    ;; Select appropriate duration.  Ignore non-digit characters.
+    (if (eq op ?_)
+       (progn
+         (org-agenda-filter-show-all-effort)
+         (message "Effort filter removed"))
       (let ((prompt
             (apply #'format
                    (concat "Effort %c "
@@ -7458,15 +7603,149 @@ With two prefix arguments, remove the effort filters."
        (while (not (memq eff allowed-keys))
          (message prompt)
          (setq eff (- (read-char-exclusive) 48)))
+       (org-agenda-filter-show-all-effort)
        (setq org-agenda-effort-filter
-             (list (concat (if strip "-" "+")
-                           (char-to-string op)
-                           ;; Numbering is 1 2 3 ... 9 0, but we want
-                           ;; 0 1 2 ... 8 9.
-                           (nth (mod (1- eff) 10) efforts)))))
-      (org-agenda-filter-apply org-agenda-effort-filter 'effort)))
-   (t (org-agenda-filter-show-all-effort)
-      (message "Effort filter removed"))))
+             (append
+              (list (concat (if negative "-" "+")
+                            (char-to-string op)
+                            ;; Numbering is 1 2 3 ... 9 0, but we want
+                            ;; 0 1 2 ... 8 9.
+                            (nth (mod (1- eff) 10) efforts)))
+              (if keep current nil)))
+       (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
+
+
+(defun org-agenda-filter (&optional strip-or-accumulate)
+  "Prompt for a general filter string and apply it to the agenda.
+
+The string may contain filter elements like
+
++category
++tag
++<effort        > and = are also allowed as effort operators
++/regexp/
+
+Instead of `+', `-' is allowed to strip the agenda of matching entries.
+`+' is optional if it is not required to separate two string parts.
+Multiple filter elements can be concatenated without spaces, for example
+
+     +work-John<0:10-/plot/
+
+selects entries with category `work' and effort estimates below 10 minutes,
+and deselects entries with tag `John' or matching the regexp `plot'.
+
+During entry of the filter, completion for tags, categories and effort
+values is offered.  Since the syntax for categories and tags is identical
+there should be no overlap between categoroes and tags.  If there is, tags
+get priority.
+
+A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate 
the
+entire filter, which can be useful in connection with the prompt history.
+
+A double `\\[universal-argument] \\[universal-argument]' prefix arg will add 
the new filter elements to the
+existing ones. A shortcut for this is to add an additional `+' at the
+beginning of the string, like `+-John'.
+
+With a triple prefix argument, execute the computed filtering defined in
+the variable `org-agenda-auto-exclude-function'."
+  (interactive "P")
+  (if (equal strip-or-accumulate '(64))
+      ;; Execute the auto-exclude action
+      (if (not org-agenda-auto-exclude-function)
+         (user-error "`org-agenda-auto-exclude-function' is undefined")
+       (org-agenda-filter-show-all-tag)
+       (setq org-agenda-tag-filter nil)
+       (dolist (tag (org-agenda-get-represented-tags))
+         (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
+           (when modifier
+             (push modifier org-agenda-tag-filter))))
+       (unless (null org-agenda-tag-filter)
+         (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
+    ;; Prompt for a filter and act
+    (let* ((tag-list (org-agenda-get-represented-tags))
+          (category-list (org-agenda-get-represented-categories))
+          (negate (equal strip-or-accumulate '(4)))
+          (f-string (completing-read
+                     (concat
+                      (if negate "Negative filter" "Filter")
+                      " [+cat-tag<0:10-/regexp/]: ")
+                     'org-agenda-filter-completion-function))
+          (keep (or (if (string-match "^+[-+]" f-string)
+                        (progn (setq f-string (substring f-string 1)) t))
+                    (equal strip-or-accumulate '(16))))
+          (fc (if keep org-agenda-category-filter))
+          (ft (if keep org-agenda-tag-filter))
+          (fe (if keep org-agenda-effort-filter))
+          (fr (if keep org-agenda-regexp-filter))
+          pm s)
+      (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ 
\t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
+       (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
+       (when negate
+         (setq pm (if (equal pm "+") "-" "+")))
+       (cond
+        ((match-beginning 3)
+         ;; category or tag
+         (setq s (match-string 3 f-string))
+         (cond
+          ((member s tag-list)
+           (add-to-list 'ft (concat pm s) 'append 'equal))
+          ((member s category-list)
+           (add-to-list 'fc (concat pm s) 'append 'equal))
+          (t (message
+              "`%s%s' filter ignored because tag/category is not represented"
+              pm s))))
+        ((match-beginning 4)
+         ;; effort
+         (add-to-list 'fe (concat pm (match-string 4 f-string)) t 'equal))
+        ((match-beginning 5)
+         ;; regexp
+         (add-to-list 'fr (concat pm (match-string 6 f-string)) t 'equal)))
+       (setq f-string (substring f-string (match-end 0))))
+      (org-agenda-filter-remove-all)
+      (and fc (org-agenda-filter-apply
+              (setq org-agenda-category-filter fc) 'category))
+      (and ft (org-agenda-filter-apply
+              (setq org-agenda-tag-filter ft) 'tag))
+      (and fe (org-agenda-filter-apply
+              (setq org-agenda-effort-filter fe) 'effort))
+      (and fr (org-agenda-filter-apply
+              (setq org-agenda-regexp-filter fr) 'regexp))
+      )))
+
+(defun org-agenda-filter-completion-function (string _predicate &optional flag)
+  "Complete a complex filter string
+FLAG specifies the type of completion operation to perform.  This
+function is passed as a collection function to `completing-read',
+which see."
+  (let ((completion-ignore-case t)     ;tags are case-sensitive
+       (confirm (lambda (x) (stringp x)))
+       (prefix "")
+       (operator "")
+       table)
+    (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
+      (setq prefix (match-string 1 string)
+           operator (match-string 2 string)
+           string (match-string 3 string)))
+    (cond
+     ((member operator '("+" "-" "" nil))
+      (setq table (append (org-agenda-get-represented-categories)
+                         (org-agenda-get-represented-tags))))
+     ((member operator '("<" ">" "="))
+      (setq table (split-string
+                  (or (cdr (assoc (concat org-effort-property "_ALL")
+                                  org-global-properties))
+                      "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
+                  " +")))
+     (t (setq table nil)))
+    (pcase flag
+      (`t (all-completions string table confirm))
+      (`lambda (assoc string table)) ;exact match?
+      (`nil
+       (pcase (try-completion string table confirm)
+        ((and completion (pred stringp))
+         (concat prefix completion))
+        (completion completion)))
+      (_ nil))))
 
 (defun org-agenda-filter-remove-all ()
   "Remove all filters from the current agenda buffer."
@@ -7483,14 +7762,17 @@ With two prefix arguments, remove the effort filters."
     (org-agenda-filter-show-all-effort))
   (org-agenda-finalize))
 
-(defun org-agenda-filter-by-tag (arg &optional char exclude)
+(defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
   "Keep only those lines in the agenda buffer that have a specific tag.
 
 The tag is selected with its fast selection letter, as configured.
 
-With a `\\[universal-argument]' prefix, exclude the agenda search.
+With a `\\[universal-argument]' prefix, apply the filter negatively, stripping 
all matches.
+
+With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag 
to the existing filter
+instead of replacing it.
 
-With a `\\[universal-argument] \\[universal-argument]' prefix, filter the 
literal tag, \
+With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' 
prefix, filter the literal tag, \
 i.e. don't
 filter on all its group members.
 
@@ -7499,33 +7781,38 @@ should be used to exclude the search - the interactive 
user can
 also press `-' or `+' to switch between filtering and excluding."
   (interactive "P")
   (let* ((alist org-tag-alist-for-agenda)
+        (seen-chars nil)
         (tag-chars (mapconcat
                     (lambda (x) (if (and (not (symbolp (car x)))
-                                         (cdr x))
-                                    (char-to-string (cdr x))
+                                         (cdr x)
+                                         (not (member (cdr x) seen-chars)))
+                                    (progn
+                                      (push (cdr x) seen-chars)
+                                      (char-to-string (cdr x)))
                                   ""))
                     org-tag-alist-for-agenda ""))
-        (valid-char-list (append '(?\t ?\r ?/ ?. ?\s ?q)
+        (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
                                  (string-to-list tag-chars)))
-        (exclude (or exclude (equal arg '(4))))
-        (expand (not (equal arg '(16))))
+        (exclude (or exclude (equal strip-or-accumulate '(4))))
+        (accumulate (equal strip-or-accumulate '(16)))
+        (expand (not (equal strip-or-accumulate '(64))))
         (inhibit-read-only t)
         (current org-agenda-tag-filter)
         a n tag)
     (unless char
       (while (not (memq char valid-char-list))
-       (message
-        "%s by tag [%s ]:tag-char, [TAB]:tag, %s[/]:off, 
[+/-]:filter/exclude%s, [q]:quit"
-        (if exclude "Exclude" "Filter")
+       (org-unlogged-message
+        "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
+        (if exclude "Exclude[+]" "Filter[-]")
+        (if expand "" " (no grouptag expand)")
         tag-chars
-        (if org-agenda-auto-exclude-function "[RET], " "")
-        (if expand "" ", no grouptag expand"))
+        (if org-agenda-auto-exclude-function "[RET] " ""))
        (setq char (read-char-exclusive))
        ;; Excluding or filtering down
        (cond ((eq char ?-) (setq exclude t))
              ((eq char ?+) (setq exclude nil)))))
     (when (eq char ?\t)
-      (unless (local-variable-p 'org-global-tags-completion-table 
(current-buffer))
+      (unless (local-variable-p 'org-global-tags-completion-table)
        (setq-local org-global-tags-completion-table
                    (org-global-tags-completion-table)))
       (let ((completion-ignore-case t))
@@ -7538,11 +7825,11 @@ also press `-' or `+' to switch between filtering and 
excluding."
        (setq org-agenda-tag-filter nil)
        (dolist (tag (org-agenda-get-represented-tags))
          (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
-           (if modifier
-               (push modifier org-agenda-tag-filter))))
-       (if (not (null org-agenda-tag-filter))
-           (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
-     ((eq char ?/)
+           (when modifier
+             (push modifier org-agenda-tag-filter))))
+       (unless (null org-agenda-tag-filter)
+         (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
+     ((eq char ?\\)
       (org-agenda-filter-show-all-tag)
       (when (get 'org-agenda-tag-filter :preset-filter)
        (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
@@ -7559,21 +7846,36 @@ also press `-' or `+' to switch between filtering and 
excluding."
       (setq tag (car a))
       (setq org-agenda-tag-filter
            (cons (concat (if exclude "-" "+") tag)
-                 current))
+                 (if accumulate current nil)))
       (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
      (t (error "Invalid tag selection character %c" char)))))
 
-(defun org-agenda-get-represented-tags ()
-  "Get a list of all tags currently represented in the agenda."
-  (let (p tags)
-    (save-excursion
-      (goto-char (point-min))
-      (while (setq p (next-single-property-change (point) 'tags))
-       (goto-char p)
-       (mapc (lambda (x) (add-to-list 'tags x))
-             (get-text-property (point) 'tags))))
-    tags))
+(defun org-agenda-get-represented-categories ()
+  "Return a list of all categories used in this agenda buffer."
+  (or org-agenda-represented-categories
+      (when (derived-mode-p 'org-agenda-mode)
+       (let ((pos (point-min)) categories)
+         (while (and (< pos (point-max))
+                     (setq pos (next-single-property-change
+                                pos 'org-category nil (point-max))))
+           (push (get-text-property pos 'org-category) categories))
+         (setq org-agenda-represented-categories
+               (nreverse (org-uniquify (delq nil categories))))))))
 
+(defun org-agenda-get-represented-tags ()
+  "Return a list of all tags used in this agenda buffer.
+These will be lower-case, for filtering."
+  (or org-agenda-represented-tags
+      (when (derived-mode-p 'org-agenda-mode)
+       (let ((pos (point-min)) tags-lists tt)
+         (while (and (< pos (point-max))
+                     (setq pos (next-single-property-change
+                                pos 'tags nil (point-max))))
+           (setq tt (get-text-property pos 'tags))
+           (if tt (push tt tags-lists)))
+         (setq org-agenda-represented-tags
+               (nreverse (org-uniquify
+                          (delq nil (apply 'append tags-lists)))))))))
 
 (defun org-agenda-filter-make-matcher (filter type &optional expand)
   "Create the form that tests a line for agenda filter.  Optional
@@ -7636,7 +7938,7 @@ function to set the right switches in the returned form."
     (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
       (let* ((tag (substring x 1))
             (f (cond
-                ((string= "" tag) '(not tags))
+                ((string= "" tag) 'tags)
                 ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
                  ;; TAG is a regexp.
                  (list 'org-match-any-p (substring tag 1 -1) 'tags))
@@ -7689,9 +7991,10 @@ When NO-OPERATOR is non-nil, do not add the + operator 
to returned tags."
 argument EXPAND can be used for the TYPE tag and will expand the
 tags in the FILTER if any of the tags in FILTER are grouptags."
   ;; Deactivate `org-agenda-entry-text-mode' when filtering
-  (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
+  (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
   (let (tags cat txt)
-    (setq org-agenda-filter-form (org-agenda-filter-make-matcher filter type 
expand))
+    (setq org-agenda-filter-form (org-agenda-filter-make-matcher
+                                 filter type expand))
     ;; Only set `org-agenda-filtered-by-category' to t when a unique
     ;; category is used as the filter:
     (setq org-agenda-filtered-by-category
@@ -7701,17 +8004,17 @@ tags in the FILTER if any of the tags in FILTER are 
grouptags."
     (save-excursion
       (goto-char (point-min))
       (while (not (eobp))
-       (if (org-get-at-bol 'org-marker)
+       (if (org-get-at-bol 'org-hd-marker)
            (progn
              (setq tags (org-get-at-bol 'tags)
-                   cat (org-get-at-eol 'org-category 1)
+                   cat (org-agenda-get-category)
                    txt (org-get-at-bol 'txt))
-             (if (not (eval org-agenda-filter-form))
-                 (org-agenda-filter-hide-line type))
+             (unless (eval org-agenda-filter-form)
+               (org-agenda-filter-hide-line type))
              (beginning-of-line 2))
          (beginning-of-line 2))))
-    (if (get-char-property (point) 'invisible)
-       (ignore-errors (org-agenda-previous-line)))))
+    (when (get-char-property (point) 'invisible)
+      (ignore-errors (org-agenda-previous-line)))))
 
 (defun org-agenda-filter-top-headline-apply (hl &optional negative)
   "Filter by top headline HL."
@@ -7721,12 +8024,12 @@ tags in the FILTER if any of the tags in FILTER are 
grouptags."
     (while (not (eobp))
       (let* ((pos (org-get-at-bol 'org-hd-marker))
              (tophl (and pos (org-find-top-headline pos))))
-        (if (and tophl (funcall (if negative 'identity 'not)
-                               (string= hl tophl)))
-            (org-agenda-filter-hide-line 'top-headline)))
+        (when (and tophl (funcall (if negative 'identity 'not)
+                                 (string= hl tophl)))
+          (org-agenda-filter-hide-line 'top-headline)))
       (beginning-of-line 2)))
-  (if (get-char-property (point) 'invisible)
-      (org-agenda-previous-line))
+  (when (get-char-property (point) 'invisible)
+    (org-agenda-previous-line))
   (setq org-agenda-top-headline-filter hl
        org-agenda-filtered-by-top-headline t))
 
@@ -7744,7 +8047,8 @@ tags in the FILTER if any of the tags in FILTER are 
grouptags."
   (save-excursion
     (goto-char (point-min))
     (let ((inhibit-read-only t) pos)
-      (while (setq pos (text-property-any (point) (point-max) 'org-filter-type 
type))
+      (while (setq pos (text-property-any (point) (point-max)
+                                         'org-filter-type type))
        (goto-char pos)
        (remove-text-properties
         (point) (next-single-property-change (point) 'org-filter-type)
@@ -7955,9 +8259,10 @@ With prefix ARG, go backward that many times the current 
span."
 (defun org-agenda-view-mode-dispatch ()
   "Call one of the view mode commands."
   (interactive)
-  (message "View: [d]ay  [w]eek  for[t]night  [m]onth  [y]ear  [SPC]reset  
[q]uit/abort
-      time[G]rid   [[]inactive  [f]ollow      [l]og    [L]og-all   [c]lockcheck
-      [a]rch-trees [A]rch-files clock[R]eport include[D]iary       
[E]ntryText")
+  (org-unlogged-message
+   "View: [d]ay  [w]eek  for[t]night  [m]onth  [y]ear  [SPC]reset  [q]uit/abort
+       time[G]rid   [[]inactive  [f]ollow      [l]og    [L]og-all   
[c]lockcheck
+       [a]rch-trees [A]rch-files clock[R]eport include[D]iary       
[E]ntryText")
   (pcase (read-char-exclusive)
     (?\ (call-interactively 'org-agenda-reset-view))
     (?d (call-interactively 'org-agenda-day-view))
@@ -8042,8 +8347,8 @@ SPAN may be `day', `week', `fortnight', `month', `year'."
   (org-agenda-check-type t 'agenda)
   (let* ((args (get-text-property (min (1- (point-max)) (point)) 
'org-last-args))
         (curspan (nth 2 args)))
-    (if (and (not n) (equal curspan span))
-       (error "Viewing span is already \"%s\"" span))
+    (when (and (not n) (equal curspan span))
+      (error "Viewing span is already \"%s\"" span))
     (let* ((sd (or (org-get-at-bol 'day)
                   (nth 1 args)
                   org-starting-day))
@@ -8107,11 +8412,10 @@ so that the date SD will be in that range."
   (org-agenda-check-type t 'agenda)
   (beginning-of-line 1)
   ;; This does not work if user makes date format that starts with a blank
-  (if (looking-at "^\\S-") (forward-char 1))
-  (if (not (re-search-forward "^\\S-" nil t arg))
-      (progn
-       (backward-char 1)
-       (error "No next date after this line in this buffer")))
+  (when (looking-at-p "^\\S-") (forward-char 1))
+  (unless (re-search-forward "^\\S-" nil t arg)
+    (backward-char 1)
+    (error "No next date after this line in this buffer"))
   (goto-char (match-beginning 0)))
 
 (defun org-agenda-previous-date-line (&optional arg)
@@ -8119,8 +8423,8 @@ so that the date SD will be in that range."
   (interactive "p")
   (org-agenda-check-type t 'agenda)
   (beginning-of-line 1)
-  (if (not (re-search-backward "^\\S-" nil t arg))
-      (error "No previous date before this line in this buffer")))
+  (unless (re-search-backward "^\\S-" nil t arg)
+    (error "No previous date before this line in this buffer")))
 
 ;; Initialize the highlight
 (defvar org-hl (make-overlay 1 1))
@@ -8276,56 +8580,51 @@ When called with a prefix argument, include all archive 
files as well."
               ((eq org-agenda-show-log 'clockcheck) " ClkCk")
               (org-agenda-show-log " Log")
               (t ""))
+             (if (org-agenda-filter-any) " " "")
              (if (or org-agenda-category-filter
                      (get 'org-agenda-category-filter :preset-filter))
                  '(:eval (propertize
-                          (concat " <"
+                           (concat "["
                                   (mapconcat
                                    'identity
                                    (append
                                     (get 'org-agenda-category-filter 
:preset-filter)
                                     org-agenda-category-filter)
                                    "")
-                                  ">")
+                                   "]")
                           'face 'org-agenda-filter-category
                           'help-echo "Category used in filtering")) "")
              (if (or org-agenda-tag-filter
                      (get 'org-agenda-tag-filter :preset-filter))
                  '(:eval (propertize
-                          (concat " {"
-                                  (mapconcat
+                          (concat (mapconcat
                                    'identity
                                    (append
                                     (get 'org-agenda-tag-filter :preset-filter)
                                     org-agenda-tag-filter)
-                                   "")
-                                  "}")
+                                   ""))
                           'face 'org-agenda-filter-tags
                           'help-echo "Tags used in filtering")) "")
              (if (or org-agenda-effort-filter
                      (get 'org-agenda-effort-filter :preset-filter))
                  '(:eval (propertize
-                          (concat " {"
-                                  (mapconcat
+                          (concat (mapconcat
                                    'identity
                                    (append
                                     (get 'org-agenda-effort-filter 
:preset-filter)
                                     org-agenda-effort-filter)
-                                   "")
-                                  "}")
+                                   ""))
                           'face 'org-agenda-filter-effort
                           'help-echo "Effort conditions used in filtering")) 
"")
              (if (or org-agenda-regexp-filter
                      (get 'org-agenda-regexp-filter :preset-filter))
                  '(:eval (propertize
-                          (concat " ["
-                                  (mapconcat
-                                   'identity
+                          (concat (mapconcat
+                                   (lambda (x) (concat (substring x 0 1) "/" 
(substring x 1) "/"))
                                    (append
                                     (get 'org-agenda-regexp-filter 
:preset-filter)
                                     org-agenda-regexp-filter)
-                                   "")
-                                  "]")
+                                   ""))
                           'face 'org-agenda-filter-regexp
                           'help-echo "Regexp used in filtering")) "")
              (if org-agenda-archives-mode
@@ -8373,7 +8672,7 @@ When called with a prefix argument, include all archive 
files as well."
          (goto (save-excursion
                  (move-end-of-line 0)
                  (previous-single-property-change (point) 'org-marker))))
-      (if goto (goto-char goto))
+      (when goto (goto-char goto))
       (org-move-to-column col)))
   (org-agenda-do-context-action))
 
@@ -8432,7 +8731,7 @@ Point is in the buffer where the item originated.")
         (buffer (marker-buffer marker))
         (pos (marker-position marker))
         (type (org-get-at-bol 'type))
-        dbeg dend (n 0) conf)
+        dbeg dend (n 0))
     (org-with-remote-undo buffer
       (with-current-buffer buffer
        (save-excursion
@@ -8444,14 +8743,20 @@ Point is in the buffer where the item originated.")
                  dend (min (point-max) (1+ (point-at-eol)))))
          (goto-char dbeg)
          (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
-      (setq conf (or (eq t org-agenda-confirm-kill)
-                    (and (numberp org-agenda-confirm-kill)
-                         (> n org-agenda-confirm-kill))))
-      (and conf
-          (not (y-or-n-p
-                (format "Delete entry with %d lines in buffer \"%s\"? "
-                        n (buffer-name buffer))))
-          (error "Abort"))
+      (when (or (eq t org-agenda-confirm-kill)
+               (and (numberp org-agenda-confirm-kill)
+                    (> n org-agenda-confirm-kill)))
+       (let ((win-conf (current-window-configuration)))
+         (unwind-protect
+             (and
+              (prog2
+                  (org-agenda-tree-to-indirect-buffer nil)
+                  (not (y-or-n-p
+                        (format "Delete entry with %d lines in buffer \"%s\"? "
+                                n (buffer-name buffer))))
+                (kill-buffer org-last-indirect-buffer))
+              (error "Abort"))
+           (set-window-configuration win-conf))))
       (let ((org-agenda-buffer-name bufname-orig))
        (org-remove-subtree-entries-from-agenda buffer dbeg dend))
       (with-current-buffer buffer (delete-region dbeg dend))
@@ -8585,9 +8890,9 @@ It also looks at the text of the entry itself."
      ((and buffer lk)
       (mapcar (lambda(l)
                (with-current-buffer buffer
-                 (setq trg (and (string-match org-bracket-link-regexp l)
+                 (setq trg (and (string-match org-link-bracket-re l)
                                 (match-string 1 l)))
-                 (if (or (not trg) (string-match org-any-link-re trg))
+                 (if (or (not trg) (string-match org-link-any-re trg))
                      (org-with-wide-buffer
                       (goto-char marker)
                       (when (search-forward l nil lkend)
@@ -8601,11 +8906,11 @@ It also looks at the text of the entry itself."
                      (goto-char (match-beginning 0))
                      (org-open-at-point)))))
              lk))
-     ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
+     ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
          (save-excursion
            (beginning-of-line 1)
-           (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
-      (org-open-link-from-string (match-string 1)))
+           (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
+      (org-link-open-from-string (match-string 1)))
      (t (message "No link to open here")))))
 
 (defun org-agenda-copy-local-variable (var)
@@ -8623,8 +8928,8 @@ displayed Org file fills the frame."
   (interactive)
   (if (and org-return-follows-link
           (not (org-get-at-bol 'org-marker))
-          (org-in-regexp org-bracket-link-regexp))
-      (org-open-link-from-string (match-string 0))
+          (org-in-regexp org-link-bracket-re))
+      (org-link-open-from-string (match-string 0))
     (let* ((marker (or (org-get-at-bol 'org-marker)
                       (org-agenda-error)))
           (buffer (marker-buffer marker))
@@ -8660,9 +8965,8 @@ if it was hidden in the outline."
 
 When called repeatedly, scroll the window that is displaying the buffer.
 
-With a `\\[universal-argument]' prefix, use `org-show-entry' instead of \
-`outline-show-subtree'
-to display the item, so that drawers and logbooks stay folded."
+With a `\\[universal-argument]' prefix argument, display the item, but \
+fold drawers."
   (interactive "P")
   (let ((win (selected-window)))
     (if (and (window-live-p org-agenda-show-window)
@@ -8671,7 +8975,13 @@ to display the item, so that drawers and logbooks stay 
folded."
          (select-window org-agenda-show-window)
          (ignore-errors (scroll-up)))
       (org-agenda-goto t)
-      (if arg (org-show-entry) (outline-show-subtree))
+      (org-show-entry)
+      (if arg (org-cycle-hide-drawers 'children)
+       (org-with-wide-buffer
+        (narrow-to-region (org-entry-beginning-position)
+                          (org-entry-end-position))
+        (org-show-all '(drawers))))
+      (when arg )
       (setq org-agenda-show-window (selected-window)))
     (select-window win)))
 
@@ -8703,7 +9013,7 @@ if it was hidden in the outline."
     (set-window-start (selected-window) (point-at-bol))
     (cond
      ((= more 0)
-      (outline-hide-subtree)
+      (org-flag-subtree t)
       (save-excursion
        (org-back-to-heading)
        (run-hook-with-args 'org-cycle-hook 'folded))
@@ -8755,8 +9065,8 @@ docstring of `org-agenda-show-1'."
       (if (equal org-agenda-cycle-counter 0)
          (setq org-agenda-cycle-counter 2)
        (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
-       (if (> org-agenda-cycle-counter 3)
-           (setq org-agenda-cycle-counter 0)))))
+       (when (> org-agenda-cycle-counter 3)
+         (setq org-agenda-cycle-counter 0)))))
   (org-agenda-show-1 org-agenda-cycle-counter))
 
 (defun org-agenda-recenter (arg)
@@ -8775,8 +9085,8 @@ docstring of `org-agenda-show-1'."
 
 (defun org-agenda-check-no-diary ()
   "Check if the entry is a diary link and abort if yes."
-  (if (org-get-at-bol 'org-agenda-diary-link)
-      (org-agenda-error)))
+  (when (org-get-at-bol 'org-agenda-diary-link)
+    (org-agenda-error)))
 
 (defun org-agenda-error ()
   "Throw an error when a command is not allowed in the agenda."
@@ -8822,7 +9132,7 @@ the dedicated frame."
     (with-current-buffer buffer
       (save-excursion
        (goto-char pos)
-       (funcall 'org-tree-to-indirect-buffer arg)))))
+       (org-tree-to-indirect-buffer arg)))))
 
 (defvar org-last-heading-marker (make-marker)
   "Marker pointing to the headline that last changed its TODO state
@@ -8852,6 +9162,7 @@ the same tree node, and the headline of the tree node in 
the Org file."
         (hdmarker (org-get-at-bol 'org-hd-marker))
         (todayp (org-agenda-today-p (org-get-at-bol 'day)))
         (inhibit-read-only t)
+        org-loop-over-headlines-in-active-region
         org-agenda-headline-snapshot-before-repeat newhead just-one)
     (org-with-remote-undo buffer
       (with-current-buffer buffer
@@ -8912,9 +9223,7 @@ If FORCE-TAGS is non-nil, the car of it returns the new 
tags."
         (line (org-current-line))
         (org-agenda-buffer (current-buffer))
         (thetags (with-current-buffer (marker-buffer hdmarker)
-                   (org-with-wide-buffer
-                    (goto-char hdmarker)
-                    (org-get-tags-at))))
+                   (org-get-tags hdmarker)))
         props m pl undone-face done-face finish new dotime level cat tags)
     (save-excursion
       (goto-char (point-max))
@@ -8926,7 +9235,7 @@ If FORCE-TAGS is non-nil, the car of it returns the new 
tags."
                   (equal m hdmarker))
          (setq props (text-properties-at (point))
                dotime (org-get-at-bol 'dotime)
-               cat (org-get-at-eol 'org-category 1)
+               cat (org-agenda-get-category)
                level (org-get-at-bol 'level)
                tags thetags
                new
@@ -8970,32 +9279,35 @@ If FORCE-TAGS is non-nil, the car of it returns the new 
tags."
        (beginning-of-line 0)))))
 
 (defun org-agenda-align-tags (&optional line)
-  "Align all tags in agenda items to `org-agenda-tags-column'."
+  "Align all tags in agenda items to `org-agenda-tags-column'.
+When optional argument LINE is non-nil, align tags only on the
+current line."
   (let ((inhibit-read-only t)
        (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
                                    (- (window-text-width))
                                  org-agenda-tags-column))
+       (end (and line (line-end-position)))
        l c)
     (save-excursion
-      (goto-char (if line (point-at-bol) (point-min)))
-      (while (re-search-forward "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"
-                               (if line (point-at-eol) nil) t)
+      (goto-char (if line (line-beginning-position) (point-min)))
+      (while (re-search-forward org-tag-group-re end t)
        (add-text-properties
-        (match-beginning 2) (match-end 2)
+        (match-beginning 1) (match-end 1)
         (list 'face (delq nil (let ((prop (get-text-property
-                                           (match-beginning 2) 'face)))
+                                           (match-beginning 1) 'face)))
                                 (or (listp prop) (setq prop (list prop)))
                                 (if (memq 'org-tag prop)
                                     prop
                                   (cons 'org-tag prop))))))
-       (setq l (- (match-end 2) (match-beginning 2))
+       (setq l (string-width (match-string 1))
              c (if (< org-agenda-tags-column 0)
                    (- (abs org-agenda-tags-column) l)
                  org-agenda-tags-column))
-       (delete-region (match-beginning 1) (match-end 1))
        (goto-char (match-beginning 1))
+       (delete-region (save-excursion (skip-chars-backward " \t") (point))
+                      (point))
        (insert (org-add-props
-                   (make-string (max 1 (- c (current-column))) ?\ )
+                   (make-string (max 1 (- c (current-column))) ?\s)
                    (plist-put (copy-sequence (text-properties-at (point)))
                               'face nil))))
       (goto-char (point-min))
@@ -9035,7 +9347,7 @@ Called with a universal prefix arg, show the priority 
instead of setting it."
          (widen)
          (goto-char pos)
          (org-show-context 'agenda)
-         (funcall 'org-priority force-direction)
+         (org-priority force-direction)
          (end-of-line 1)
          (setq newhead (org-get-heading)))
        (org-agenda-change-all-lines newhead hdmarker)
@@ -9061,7 +9373,7 @@ Called with a universal prefix arg, show the priority 
instead of setting it."
          (org-show-context 'agenda)
          (if tag
              (org-toggle-tag tag onoff)
-           (call-interactively 'org-set-tags))
+           (call-interactively #'org-set-tags-command))
          (end-of-line 1)
          (setq newhead (org-get-heading)))
        (org-agenda-change-all-lines newhead hdmarker)
@@ -9180,9 +9492,9 @@ Called with a universal prefix arg, show the priority 
instead of setting it."
                cdate (calendar-absolute-from-gregorian
                       (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
                today (org-today))
-         (if (> today cdate)
-             ;; immediately shift to today
-             (setq arg (- today cdate))))
+         (when (> today cdate)
+           ;; immediately shift to today
+           (setq arg (- today cdate))))
        (org-timestamp-change arg (or what 'day))
        (when (and (org-at-date-range-p)
                   (re-search-backward org-tr-regexp-both (point-at-bol)))
@@ -9315,7 +9627,6 @@ ARG is passed through to `org-deadline'."
          (widen)
          (goto-char pos)
          (org-show-context 'agenda)
-         (org-cycle-hide-drawers 'children)
          (org-clock-in arg)
          (setq newhead (org-get-heading)))
        (org-agenda-change-all-lines newhead hdmarker))
@@ -9355,8 +9666,8 @@ buffer, display it in another window."
   (interactive)
   (let (pos)
     (mapc (lambda (o)
-           (if (eq (overlay-get o 'type) 'org-agenda-clocking)
-               (setq pos (overlay-start o))))
+           (when (eq (overlay-get o 'type) 'org-agenda-clocking)
+             (setq pos (overlay-start o))))
          (overlays-in (point-min) (point-max)))
     (cond (pos (goto-char pos))
          ;; If the currently clocked entry is not in the agenda
@@ -9442,62 +9753,64 @@ the resulting entry will not be shown.  When TEXT is 
empty, switch to
      (find-file-noselect org-agenda-diary-file))
     (widen)
     (goto-char (point-min))
-    (cond
-     ((eq type 'anniversary)
-      (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
-         (progn
-           (or (org-at-heading-p t)
-               (progn
-                 (outline-next-heading)
-                 (insert "* Anniversaries\n\n")
-                 (beginning-of-line -1)))))
-      (outline-next-heading)
-      (org-back-over-empty-lines)
-      (backward-char 1)
-      (insert "\n")
-      (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
-                     (nth 2 d1) (car d1) (nth 1 d1) text)))
-     ((eq type 'day)
-      (let ((org-prefix-has-time t)
-           (org-agenda-time-leading-zero t)
-           fmt time time2)
-       (if org-agenda-insert-diary-extract-time
-           ;; Use org-agenda-format-item to parse text for a time-range and
-           ;; remove it.  FIXME: This is a hack, we should refactor
-           ;; that function to make time extraction available separately
-           (setq fmt (org-agenda-format-item nil text nil nil nil t)
-                 time (get-text-property 0 'time fmt)
-                 time2 (if (> (length time) 0)
-                           ;; split-string removes trailing ...... if
-                           ;; no end time given.  First space
-                           ;; separates time from date.
-                           (concat " " (car (split-string time "\\.")))
-                         nil)
-                 text (get-text-property 0 'txt fmt)))
-       (if (eq org-agenda-insert-diary-strategy 'top-level)
-           (org-agenda-insert-diary-as-top-level text)
-         (require 'org-datetree)
-         (org-datetree-find-date-create d1)
-         (org-agenda-insert-diary-make-new-entry text))
-       (org-insert-time-stamp (org-time-from-absolute
-                               (calendar-absolute-from-gregorian d1))
-                              nil nil nil nil time2))
-      (end-of-line 0))
-     ((eq type 'block)
-      (if (> (calendar-absolute-from-gregorian d1)
-            (calendar-absolute-from-gregorian d2))
-         (setq d1 (prog1 d2 (setq d2 d1))))
-      (if (eq org-agenda-insert-diary-strategy 'top-level)
-         (org-agenda-insert-diary-as-top-level text)
-       (require 'org-datetree)
-       (org-datetree-find-date-create d1)
-       (org-agenda-insert-diary-make-new-entry text))
-      (org-insert-time-stamp (org-time-from-absolute
-                             (calendar-absolute-from-gregorian d1)))
-      (insert "--")
-      (org-insert-time-stamp (org-time-from-absolute
-                             (calendar-absolute-from-gregorian d2)))
-      (end-of-line 0)))
+    (cl-case type
+      (anniversary
+       (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
+          (progn
+            (or (org-at-heading-p t)
+                (progn
+                  (outline-next-heading)
+                  (insert "* Anniversaries\n\n")
+                  (beginning-of-line -1)))))
+       (outline-next-heading)
+       (org-back-over-empty-lines)
+       (backward-char 1)
+       (insert "\n")
+       (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
+                      (nth 2 d1) (car d1) (nth 1 d1) text)))
+      (day
+       (let ((org-prefix-has-time t)
+            (org-agenda-time-leading-zero t)
+            fmt time time2)
+        (when org-agenda-insert-diary-extract-time
+          ;; Use org-agenda-format-item to parse text for a time-range and
+          ;; remove it.  FIXME: This is a hack, we should refactor
+          ;; that function to make time extraction available separately
+          (setq fmt (org-agenda-format-item nil text nil nil nil t)
+                time (get-text-property 0 'time fmt)
+                time2 (if (> (length time) 0)
+                          ;; split-string removes trailing ...... if
+                          ;; no end time given.  First space
+                          ;; separates time from date.
+                          (concat " " (car (split-string time "\\.")))
+                        nil)
+                text (get-text-property 0 'txt fmt)))
+        (if (eq org-agenda-insert-diary-strategy 'top-level)
+            (org-agenda-insert-diary-as-top-level text)
+          (require 'org-datetree)
+          (org-datetree-find-date-create d1)
+          (org-agenda-insert-diary-make-new-entry text))
+        (org-insert-time-stamp (org-time-from-absolute
+                                (calendar-absolute-from-gregorian d1))
+                               nil nil nil nil time2))
+       (end-of-line 0))
+      ((block) ;; Wrap this in (strictly unnecessary) parens because
+       ;; otherwise the indentation gets confused by the
+       ;; special meaning of 'block
+       (when (> (calendar-absolute-from-gregorian d1)
+               (calendar-absolute-from-gregorian d2))
+        (setq d1 (prog1 d2 (setq d2 d1))))
+       (if (eq org-agenda-insert-diary-strategy 'top-level)
+          (org-agenda-insert-diary-as-top-level text)
+        (require 'org-datetree)
+        (org-datetree-find-date-create d1)
+        (org-agenda-insert-diary-make-new-entry text))
+       (org-insert-time-stamp (org-time-from-absolute
+                              (calendar-absolute-from-gregorian d1)))
+       (insert "--")
+       (org-insert-time-stamp (org-time-from-absolute
+                              (calendar-absolute-from-gregorian d2)))
+       (end-of-line 0)))
     (if (string-match "\\S-" text)
        (progn
          (set-window-configuration cw)
@@ -9554,9 +9867,9 @@ entries in that Org file."
   (if (not (eq org-agenda-diary-file 'diary-file))
       (org-agenda-diary-entry-in-org-file)
     (require 'diary-lib)
-    (let* ((char (progn
-                  (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early 
[a]nniversary [b]lock [c]yclic")
-                  (read-char-exclusive)))
+    (let* ((char (read-char-exclusive
+                 "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
+ [a]nniversary [b]lock [c]yclic"))
           (cmd (cdr (assoc char
                            '((?d . diary-insert-entry)
                              (?w . diary-insert-weekly-entry)
@@ -9701,8 +10014,20 @@ This is a command that has to be installed in 
`calendar-mode-map'."
       'org-marked-entry-overlay))
 
 (defun org-agenda-bulk-mark (&optional arg)
-  "Mark the entry at point for future bulk action."
+  "Mark entries for future bulk action.
+
+When ARG is nil or one and region is not active then mark the
+entry at point.
+
+When ARG is nil or one and region is active then mark the entries
+in the region.
+
+When ARG is greater than one mark ARG lines."
   (interactive "p")
+  (when (and (or (not arg) (= arg 1)) (use-region-p))
+    (setq arg (count-lines (region-beginning) (region-end)))
+    (goto-char (region-beginning))
+    (deactivate-mark))
   (dotimes (i (or arg 1))
     (unless (org-get-at-bol 'org-agenda-diary-link)
       (let* ((m (org-get-at-bol 'org-hd-marker))
@@ -9720,9 +10045,9 @@ This is a command that has to be installed in 
`calendar-mode-map'."
              (goto-char (next-single-property-change (point) 'org-hd-marker)))
            (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))))))
+         (beginning-of-line 2)))))
+  (message "%d entries marked for bulk action"
+          (length org-agenda-bulk-marked-entries)))
 
 (defun org-agenda-bulk-mark-all ()
   "Mark all entries for future agenda bulk action."
@@ -9744,8 +10069,8 @@ This is a command that has to be installed in 
`calendar-mode-map'."
            (setq entries-marked (1+ entries-marked))
            (call-interactively 'org-agenda-bulk-mark)))))
 
-    (if (not entries-marked)
-       (message "No entry matching this regexp."))))
+    (unless entries-marked
+      (message "No entry matching this regexp."))))
 
 (defun org-agenda-bulk-unmark (&optional arg)
   "Unmark the entry at point for future bulk action."
@@ -9817,8 +10142,9 @@ bulk action."
   "Execute an remote-editing action on all marked entries.
 The prefix arg is passed through to the command if possible."
   (interactive "P")
-  ;; Make sure we have markers, and only valid ones.
-  (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
+  ;; When there is no mark, act on the agenda entry at point.
+  (if (not org-agenda-bulk-marked-entries)
+      (save-excursion (org-agenda-bulk-mark)))
   (dolist (m org-agenda-bulk-marked-entries)
     (unless (and (markerp m)
                 (marker-buffer m)
@@ -9827,8 +10153,8 @@ The prefix arg is passed through to the command if 
possible."
       (user-error "Marker %s for bulk command is invalid" m)))
 
   ;; Prompt for the bulk command.
-  (message
-   (concat (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")
+  (org-unlogged-message
+   (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist 
marks): "
           "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
           "[S]catter [f]unction    "
           (and org-agenda-bulk-custom-functions
@@ -10145,9 +10471,9 @@ details and examples.
 If an entry has a APPT_WARNTIME property, its value will be used
 to override `appt-message-warning-time'."
   (interactive "P")
-  (if refresh (setq appt-time-msg-list nil))
-  (if (eq filter t)
-      (setq filter (read-from-minibuffer "Regexp filter: ")))
+  (when refresh (setq appt-time-msg-list nil))
+  (when (eq filter t)
+    (setq filter (read-from-minibuffer "Regexp filter: ")))
   (let* ((cnt 0)                        ; count added events
          (scope (or args '(:deadline* :scheduled* :timestamp)))
          (org-agenda-new-buffers nil)
@@ -10155,7 +10481,8 @@ to override `appt-message-warning-time'."
          ;; 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 (time-to-days nil)))
+         (today (org-date-to-gregorian
+                 (time-to-days nil)))
          (org-agenda-restrict nil)
          (files (org-agenda-files 'unrestricted)) entries file
          (org-agenda-buffer nil))
@@ -10167,12 +10494,12 @@ to override `appt-message-warning-time'."
                   (append entries
                           (apply 'org-agenda-get-day-entries
                                  file today scope)))))
-    ;; Map thru entries and find if we should filter them out
+    ;; Map through entries and find if we should filter them out
     (mapc
      (lambda (x)
        (let* ((evt (org-trim
                     (replace-regexp-in-string
-                     org-bracket-link-regexp "\\3"
+                     org-link-bracket-re "\\2"
                      (or (get-text-property 1 'txt x) ""))))
               (cat (get-text-property (1- (length x)) 'org-category x))
               (tod (get-text-property 1 'time-of-day x))
diff --git a/lisp/org/org-archive.el b/lisp/org/org-archive.el
index dc0dfa4..4721ef7 100644
--- a/lisp/org/org-archive.el
+++ b/lisp/org/org-archive.el
@@ -29,6 +29,7 @@
 ;;; Code:
 
 (require 'org)
+(require 'cl-lib)
 
 (declare-function org-element-type "org-element" (element))
 (declare-function org-datetree-find-date-create "org-datetree" (date &optional 
keep-restriction))
@@ -126,22 +127,6 @@ Hook functions are called with point on the subtree in the
 original file.  At this stage, the subtree has been added to the
 archive location, but not yet deleted from the original file.")
 
-(defun org-get-local-archive-location ()
-  "Get the archive location applicable at point."
-  (let ((re "^[ \t]*#\\+ARCHIVE:[ \t]+\\(\\S-.*\\S-\\)[ \t]*$")
-       prop)
-    (save-excursion
-      (save-restriction
-       (widen)
-       (setq prop (org-entry-get nil "ARCHIVE" 'inherit))
-       (cond
-        ((and prop (string-match "\\S-" prop))
-         prop)
-        ((or (re-search-backward re nil t)
-             (re-search-forward re nil t))
-         (match-string 1))
-        (t org-archive-location))))))
-
 ;;;###autoload
 (defun org-add-archive-files (files)
   "Splice the archive files into the list of files.
@@ -159,47 +144,36 @@ archive file is."
      files))))
 
 (defun org-all-archive-files ()
-  "Get a list of all archive files used in the current buffer."
-  (let ((case-fold-search t)
-       files)
-    (org-with-wide-buffer
-     (goto-char (point-min))
-     (while (re-search-forward
-            "^[ \t]*\\(#\\+\\|:\\)ARCHIVE:[ \t]+\\(.*\\)"
-            nil t)
-       (when (save-match-data
-              (if (eq (match-string 1) ":") (org-at-property-p)
-                (eq (org-element-type (org-element-at-point)) 'keyword)))
-        (let ((file (org-extract-archive-file
-                     (match-string-no-properties 2))))
-          (when (and (org-string-nw-p file) (file-exists-p file))
-            (push file files))))))
-    (setq files (nreverse files))
-    (let ((file (org-extract-archive-file)))
-      (when (and (org-string-nw-p file) (file-exists-p file))
-       (push file files)))
-    files))
-
-(defun org-extract-archive-file (&optional location)
-  "Extract and expand the file name from archive LOCATION.
-if LOCATION is not given, the value of `org-archive-location' is used."
-  (setq location (or location org-archive-location))
-  (if (string-match "\\(.*\\)::\\(.*\\)" location)
-      (if (= (match-beginning 1) (match-end 1))
-         (buffer-file-name (buffer-base-buffer))
-       (expand-file-name
-        (format (match-string 1 location)
-                (file-name-nondirectory
-                 (buffer-file-name (buffer-base-buffer))))))))
-
-(defun org-extract-archive-heading (&optional location)
-  "Extract the heading from archive LOCATION.
-if LOCATION is not given, the value of `org-archive-location' is used."
-  (setq location (or location org-archive-location))
-  (if (string-match "\\(.*\\)::\\(.*\\)" location)
-      (format (match-string 2 location)
-             (file-name-nondirectory
-              (buffer-file-name (buffer-base-buffer))))))
+  "List of all archive files used in the current buffer."
+  (let* ((case-fold-search t)
+        (files `(,(car (org-archive--compute-location org-archive-location)))))
+    (org-with-point-at 1
+      (while (re-search-forward "^[ \t]*:ARCHIVE:" nil t)
+       (when (org-at-property-p)
+         (pcase (org-archive--compute-location (match-string 3))
+           (`(,file . ,_)
+            (when (org-string-nw-p file)
+              (cl-pushnew file files :test #'file-equal-p))))))
+      (cl-remove-if-not #'file-exists-p (nreverse files)))))
+
+(defun org-archive--compute-location (location)
+  "Extract and expand the location from archive LOCATION.
+Return a pair (FILE . HEADING) where FILE is the file name and
+HEADING the heading of the archive location, as strings.  Raise
+an error if LOCATION is not a valid archive location."
+  (unless (string-match "::" location)
+    (error "Invalid archive location: %S" location))
+  (let ((current-file (buffer-file-name (buffer-base-buffer)))
+       (file-fmt (substring location 0 (match-beginning 0)))
+       (heading-fmt (substring location (match-end 0))))
+    (cons
+     ;; File part.
+     (if (org-string-nw-p file-fmt)
+        (expand-file-name
+         (format file-fmt (file-name-nondirectory current-file)))
+       current-file)
+     ;; Heading part.
+     (format heading-fmt (file-name-nondirectory current-file)))))
 
 ;;;###autoload
 (defun org-archive-subtree (&optional find-done)
@@ -231,7 +205,7 @@ direct children of this heading."
      ((equal find-done '(4))  (org-archive-all-done))
      ((equal find-done '(16)) (org-archive-all-old))
      (t
-      ;; Save all relevant TODO keyword-relatex variables
+      ;; Save all relevant TODO keyword-related variables.
       (let* ((tr-org-todo-keywords-1 org-todo-keywords-1)
             (tr-org-todo-kwd-alist org-todo-kwd-alist)
             (tr-org-done-keywords org-done-keywords)
@@ -244,10 +218,11 @@ direct children of this heading."
             (file (abbreviate-file-name
                    (or (buffer-file-name (buffer-base-buffer))
                        (error "No file associated to buffer"))))
-            (location (org-get-local-archive-location))
-            (afile (or (org-extract-archive-file location)
-                       (error "Invalid `org-archive-location'")))
-            (heading (org-extract-archive-heading location))
+            (location (org-archive--compute-location
+                       (or (org-entry-get nil "ARCHIVE" 'inherit)
+                           org-archive-location)))
+            (afile (car location))
+            (heading (cdr location))
             (infile-p (equal file (abbreviate-file-name (or afile ""))))
             (newfile-p (and (org-string-nw-p afile)
                             (not (file-exists-p afile))))
@@ -271,9 +246,15 @@ direct children of this heading."
          (org-back-to-heading t)
          ;; Get context information that will be lost by moving the
          ;; tree.  See `org-archive-save-context-info'.
-         (let* ((all-tags (org-get-tags-at))
-                (local-tags (org-get-tags))
-                (inherited-tags (org-delete-all local-tags all-tags))
+         (let* ((all-tags (org-get-tags))
+                (local-tags
+                 (cl-remove-if (lambda (tag)
+                                 (get-text-property 0 'inherited tag))
+                               all-tags))
+                (inherited-tags
+                 (cl-remove-if-not (lambda (tag)
+                                     (get-text-property 0 'inherited tag))
+                                   all-tags))
                 (context
                  `((category . ,(org-get-category nil 'force-refresh))
                    (file . ,file)
@@ -315,12 +296,12 @@ direct children of this heading."
                       org-odd-levels-only
                     tr-org-odd-levels-only)))
              (goto-char (point-min))
-             (outline-show-all)
+             (org-show-all '(headings blocks))
              (if (and heading (not (and datetree-date (not 
datetree-subheading-p))))
                  (progn
                    (if (re-search-forward
                         (concat "^" (regexp-quote heading)
-                                "[ \t]*\\(:[[:alnum:]_@#%:]+:\\)?[ 
\t]*\\($\\|\r\\)")
+                                "\\([ \t]+:\\(" org-tag-re ":\\)+\\)?[ \t]*$")
                         nil t)
                        (goto-char (match-end 0))
                      ;; Heading not found, just insert it at the end
@@ -345,8 +326,7 @@ direct children of this heading."
                (if org-archive-reversed-order
                    (progn
                      (goto-char (point-min))
-                     (unless (org-at-heading-p) (outline-next-heading))
-                     (insert "\n") (backward-char 1))
+                     (unless (org-at-heading-p) (outline-next-heading)))
                  (goto-char (point-max))
                  ;; Subtree narrowing can let the buffer end on
                  ;; a headline.  `org-paste-subtree' then deletes it.
@@ -361,7 +341,7 @@ direct children of this heading."
                   (or (and (eq org-archive-subtree-add-inherited-tags 'infile)
                            infile-p)
                       (eq org-archive-subtree-add-inherited-tags t))
-                  (org-set-tags-to all-tags))
+                  (org-set-tags all-tags))
              ;; Mark the entry as done
              (when (and org-archive-mark-done
                         (let ((case-fold-search nil))
@@ -390,6 +370,12 @@ direct children of this heading."
        (when (featurep 'org-inlinetask)
          (org-inlinetask-remove-END-maybe))
        (setq org-markers-to-move nil)
+       (when org-provide-todo-statistics
+         (save-excursion
+           ;; Go to parent, even if no children exist.
+           (org-up-heading-safe)
+           ;; Update cookie of parent.
+           (org-update-statistics-cookies nil)))
        (message "Subtree archived %s"
                 (if (eq this-buffer buffer)
                     (concat "under heading: " heading)
@@ -416,7 +402,7 @@ Archiving time is retained in the ARCHIVE_TIME node 
property."
         '(progn (setq org-map-continue-from
                       (progn (org-back-to-heading)
                              (if (looking-at (concat "^.*:" org-archive-tag 
":.*$"))
-                                 (org-end-of-subtree t)
+                                 (org-end-of-subtree t)
                                (point))))
                 (when (org-at-heading-p)
                   (org-archive-to-archive-sibling)))
@@ -464,8 +450,11 @@ Archiving time is retained in the ARCHIVE_TIME node 
property."
         (format-time-string
          (substring (cdr org-time-stamp-formats) 1 -1)))
        (outline-up-heading 1 t)
-       (outline-hide-subtree)
+       (org-flag-subtree t)
        (org-cycle-show-empty-lines 'folded)
+       (when org-provide-todo-statistics
+         ;; Update TODO statistics of parent.
+         (org-update-parent-todo-statistics))
        (goto-char pos)))
     (org-reveal)
     (if (looking-at "^[ \t]*$")
diff --git a/lisp/org/org-attach-git.el b/lisp/org/org-attach-git.el
new file mode 100644
index 0000000..525495f
--- /dev/null
+++ b/lisp/org/org-attach-git.el
@@ -0,0 +1,119 @@
+;;; org-attach-git.el --- Automatic git commit extension to org-attach -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Original Author: John Wiegley <address@hidden>
+;; Restructurer: Gustav Wikström <address@hidden>
+;; Keywords: org data git
+
+;; This file is part of GNU Emacs.
+;;
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; An extension to org-attach.  If `org-attach-id-dir' is initialized
+;; as a Git repository, then org-attach-git will automatically commit
+;; changes when it sees them.  Requires git-annex.
+
+;;; Code:
+
+(require 'org-attach)
+(require 'vc-git)
+
+(defcustom org-attach-git-annex-cutoff (* 32 1024)
+  "If non-nil, files larger than this will be annexed instead of stored."
+  :group 'org-attach
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type '(choice
+         (const :tag "None" nil)
+         (integer :tag "Bytes")))
+
+(defcustom org-attach-git-annex-auto-get 'ask
+  "Confirmation preference for automatically getting annex files.
+If \\='ask, prompt using `y-or-n-p'.  If t, always get.  If nil, never get."
+  :group 'org-attach
+  :package-version '(Org . "9.0")
+  :version "26.1"
+  :type '(choice
+         (const :tag "confirm with `y-or-n-p'" ask)
+         (const :tag "always get from annex if necessary" t)
+         (const :tag "never get from annex" nil)))
+
+(defun org-attach-git-use-annex ()
+  "Return non-nil if git annex can be used."
+  (let ((git-dir (vc-git-root (expand-file-name org-attach-id-dir))))
+    (and org-attach-git-annex-cutoff
+         (or (file-exists-p (expand-file-name "annex" git-dir))
+             (file-exists-p (expand-file-name ".git/annex" git-dir))))))
+
+(defun org-attach-git-annex-get-maybe (path)
+  "Call git annex get PATH (via shell) if using git annex.
+Signals an error if the file content is not available and it was not 
retrieved."
+  (let* ((default-directory (expand-file-name org-attach-id-dir))
+        (path-relative (file-relative-name path)))
+    (when (and (org-attach-git-use-annex)
+              (not
+               (string-equal
+                "found"
+                (shell-command-to-string
+                 (format "git annex find --format=found --in=here %s"
+                         (shell-quote-argument path-relative))))))
+      (let ((should-get
+            (if (eq org-attach-git-annex-auto-get 'ask)
+                (y-or-n-p (format "Run git annex get %s? " path-relative))
+              org-attach-git-annex-auto-get)))
+       (unless should-get
+         (error "File %s stored in git annex but unavailable" path))
+       (message "Running git annex get \"%s\"." path-relative)
+       (call-process "git" nil nil nil "annex" "get" path-relative)))))
+
+(defun org-attach-git-commit (&optional _)
+  "Commit changes to git if `org-attach-id-dir' is properly initialized.
+This checks for the existence of a \".git\" directory in that directory.
+
+Takes an unused optional argument for the sake of being compatible
+with hook `org-attach-after-change-hook'."
+  (let* ((dir (expand-file-name org-attach-id-dir))
+        (git-dir (vc-git-root dir))
+        (use-annex (org-attach-git-use-annex))
+        (changes 0))
+    (when (and git-dir (executable-find "git"))
+      (with-temp-buffer
+       (cd dir)
+        (dolist (new-or-modified
+                 (split-string
+                  (shell-command-to-string
+                   "git ls-files -zmo --exclude-standard") "\0" t))
+          (if (and use-annex
+                   (>= (file-attribute-size (file-attributes new-or-modified))
+                       org-attach-git-annex-cutoff))
+              (call-process "git" nil nil nil "annex" "add" new-or-modified)
+            (call-process "git" nil nil nil "add" new-or-modified))
+           (cl-incf changes))
+       (dolist (deleted
+                (split-string
+                 (shell-command-to-string "git ls-files -z --deleted") "\0" t))
+         (call-process "git" nil nil nil "rm" deleted)
+         (cl-incf changes))
+       (when (> changes 0)
+         (shell-command "git commit -m 'Synchronized attachments'"))))))
+
+(add-hook 'org-attach-after-change-hook 'org-attach-git-commit)
+(add-hook 'org-attach-open-hook 'org-attach-git-annex-get-maybe)
+
+(provide 'org-attach-git)
+
+;;; org-attach-git.el ends here
diff --git a/lisp/org/org-attach.el b/lisp/org/org-attach.el
index f430cd5..bc49be7 100644
--- a/lisp/org/org-attach.el
+++ b/lisp/org/org-attach.el
@@ -1,9 +1,9 @@
-;;; org-attach.el --- Manage file attachments to Org tasks -*- 
lexical-binding: t; -*-
+;;; org-attach.el --- Manage file attachments to Org outlines -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2008-2019 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <address@hidden>
-;; Keywords: org data task
+;; Keywords: org data attachment
 
 ;; This file is part of GNU Emacs.
 ;;
@@ -24,54 +24,44 @@
 
 ;; See the Org manual for information on how to use it.
 ;;
-;; Attachments are managed in a special directory called "data", which
-;; lives in the same directory as the org file itself.  If this data
-;; directory is initialized as a Git repository, then org-attach will
-;; automatically commit changes when it sees them.
-;;
-;; Attachment directories are identified using a UUID generated for the
-;; task which has the attachments.  These are added as property to the
-;; task when necessary, and should not be deleted or changed by the
-;; user, ever.  UUIDs are generated by a mechanism defined in the variable
-;; `org-id-method'.
+;; Attachments are managed either by using a custom property DIR or by
+;; using property ID from org-id.  When DIR is defined, a location in
+;; the filesystem is directly attached to the outline node.  When
+;; org-id is used, attachments are stored in a folder named after the
+;; ID, in a location defined by `org-attach-id-dir'.  DIR has
+;; precedence over ID when both parameters are defined for the current
+;; outline node (also when inherited parameters are taken into
+;; account).
 
 ;;; Code:
 
 (require 'cl-lib)
 (require 'org)
+(require 'ol)
 (require 'org-id)
-(require 'vc-git)
 
 (declare-function dired-dwim-target-directory "dired-aux")
 
 (defgroup org-attach nil
-  "Options concerning entry attachments in Org mode."
+  "Options concerning attachments in Org mode."
   :tag "Org Attach"
   :group 'org)
 
-(defcustom org-attach-directory "data/"
+(defcustom org-attach-id-dir "data/"
   "The directory where attachments are stored.
 If this is a relative path, it will be interpreted relative to the directory
 where the Org file lives."
   :group 'org-attach
-  :type 'directory)
+  :type 'directory
+  :safe #'stringp)
 
-(defcustom org-attach-commit t
-  "If non-nil commit attachments with git.
-This is only done if the Org file is in a git repository."
+(defcustom org-attach-dir-relative nil
+  "Non-nil means directories in DIR property are added as relative links.
+Defaults to absolute location."
   :group 'org-attach
   :type 'boolean
-  :version "26.1"
-  :package-version '(Org . "9.0"))
-
-(defcustom org-attach-git-annex-cutoff (* 32 1024)
-  "If non-nil, files larger than this will be annexed instead of stored."
-  :group 'org-attach
-  :version "24.4"
-  :package-version '(Org . "8.0")
-  :type '(choice
-         (const :tag "None" nil)
-         (integer :tag "Bytes")))
+  :package-version '(Org . "9.3")
+  :safe #'booleanp)
 
 (defcustom org-attach-auto-tag "ATTACH"
   "Tag that will be triggered automatically when an entry has an attachment."
@@ -80,15 +70,27 @@ This is only done if the Org file is in a git repository."
          (const :tag "None" nil)
          (string :tag "Tag")))
 
-(defcustom org-attach-file-list-property "Attachments"
-  "The property used to keep a list of attachment belonging to this entry.
-This is not really needed, so you may set this to nil if you don't want it.
-Also, for entries where children inherit the directory, the list of
-attachments is not kept in this property."
+(defcustom org-attach-preferred-new-method 'id
+  "Preferred way to attach to nodes without existing ID and DIR property.
+This choice is used when adding attachments to nodes without ID
+and DIR properties.
+
+Allowed values are:
+
+id         Create and use an ID parameter
+dir        Create and use a DIR parameter
+ask        Ask the user for input of which method to choose
+nil        Prefer to not create a new parameter
+
+           nil means that ID or DIR has to be created explicitly
+           before attaching files."
   :group 'org-attach
+  :package-version '(org . "9.3")
   :type '(choice
-         (const :tag "None" nil)
-         (string :tag "Tag")))
+         (const :tag "ID parameter" id)
+         (const :tag "DIR parameter" dir)
+         (const :tag "Ask user" ask)
+         (const :tag "Don't create" nil)))
 
 (defcustom org-attach-method 'cp
   "The preferred method to attach a file.
@@ -112,14 +114,24 @@ lns   create a symbol link.  Note that this is not 
supported
   :group 'org-attach
   :type 'boolean)
 
-(defcustom org-attach-allow-inheritance t
-  "Non-nil means allow attachment directories be inherited."
+(defcustom org-attach-use-inheritance 'selective
+  "Attachment inheritance for the outline.
+
+Enabling inheritance for org-attach implies two things.  First,
+that attachment links will look through all parent headings until
+it finds the linked attachment.  Second, that running org-attach
+inside a node without attachments will make org-attach operate on
+the first parent heading it finds with an attachment.
+
+Selective means to respect the inheritance setting in
+`org-use-property-inheritance'."
   :group 'org-attach
+  :type '(choice
+         (const :tag "Don't use inheritance" nil)
+         (const :tag "Inherit parent node attachments" t)
+         (const :tag "Respect org-use-property-inheritance" selective))
   :type 'boolean)
 
-(defvar org-attach-inherited nil
-  "Indicates if the last access to the attachment directory was inherited.")
-
 (defcustom org-attach-store-link-p nil
   "Non-nil means store a link to a file when attaching it."
   :group 'org-attach
@@ -140,28 +152,108 @@ When set to `query', ask the user instead."
          (const :tag "Always delete attachments" t)
          (const :tag "Query the user" query)))
 
-(defcustom org-attach-annex-auto-get 'ask
-  "Confirmation preference for automatically getting annex files.
-If \\='ask, prompt using `y-or-n-p'.  If t, always get.  If nil, never get."
+(defun org-attach-id-uuid-folder-format (id)
+  "Translate an UUID ID into a folder-path.
+Default format for how Org translates ID properties to a path for
+attachments.  Useful if ID is generated with UUID."
+  (format "%s/%s"
+         (substring id 0 2)
+         (substring id 2)))
+
+(defun org-attach-id-ts-folder-format (id)
+  "Translate an ID based on a timestamp to a folder-path.
+Useful way of translation if ID is generated based on ISO8601
+timestamp.  Splits the attachment folder hierarchy into
+year-month, the rest."
+  (format "%s/%s"
+         (substring id 0 6)
+         (substring id 6)))
+
+(defcustom org-attach-id-to-path-function-list 
'(org-attach-id-uuid-folder-format
+                                                org-attach-id-ts-folder-format)
+  "List of functions parsing an ID string into a folder-path.
+The first function in this list defines the preferred function
+which will be used when creating new attachment folders.  All
+functions of this list will be tried when looking for existing
+attachment folders based on ID."
   :group 'org-attach
-  :package-version '(Org . "9.0")
-  :version "26.1"
-  :type '(choice
-         (const :tag "confirm with `y-or-n-p'" ask)
-         (const :tag "always get from annex if necessary" t)
-         (const :tag "never get from annex" nil)))
+  :package-version '(Org . "9.3")
+  :type '(repeat (function :tag "Function with ID as input")))
+
+(defvar org-attach-after-change-hook nil
+  "Hook to be called when files have been added or removed to the attachment 
folder.")
+
+(defvar org-attach-open-hook nil
+  "Hook that is invoked by `org-attach-open'.
+
+Created mostly to be compatible with org-attach-git after removing
+git-funtionality from this file.")
+
+(defcustom org-attach-commands
+  '(((?a ?\C-a) org-attach-attach
+     "Select a file and attach it to the task, using `org-attach-method'.")
+    ((?c ?\C-c) org-attach-attach-cp
+     "Attach a file using copy method.")
+    ((?m ?\C-m) org-attach-attach-mv
+     "Attach a file using move method.")
+    ((?l ?\C-l) org-attach-attach-ln
+     "Attach a file using link method.")
+    ((?y ?\C-y) org-attach-attach-lns
+     "Attach a file using symbolic-link method.")
+    ((?u ?\C-u) org-attach-url
+     "Attach a file from URL (downloading it).")
+    ((?b) org-attach-buffer
+     "Select a buffer and attach its contents to the task.")
+    ((?n ?\C-n) org-attach-new
+     "Create a new attachment, as an Emacs buffer.")
+    ((?z ?\C-z) org-attach-sync
+     "Synchronize the current node with its attachment\n directory, in case \
+you added attachments yourself.\n")
+    ((?o ?\C-o) org-attach-open
+     "Open current node's attachments.")
+    ((?O) org-attach-open-in-emacs
+     "Like \"o\", but force opening in Emacs.")
+    ((?f ?\C-f) org-attach-reveal
+     "Open current node's attachment directory.  Create if missing.")
+    ((?F) org-attach-reveal-in-emacs
+     "Like \"f\", but force using Dired in Emacs.\n")
+    ((?d ?\C-d) org-attach-delete-one
+     "Delete one attachment, you will be prompted for a file name.")
+    ((?D) org-attach-delete-all
+     "Delete all of a node's attachments.  A safer way is\n to open the \
+directory in dired and delete from there.\n")
+    ((?s ?\C-s) org-attach-set-directory
+     "Set a specific attachment directory for this entry. Sets DIR property.")
+    ((?S ?\C-S) org-attach-unset-directory
+     "Unset the attachment directory for this entry.  Removes DIR property.")
+    ((?q) (lambda () (interactive) (message "Abort")) "Abort."))
+  "The list of commands for the attachment dispatcher.
+Each entry in this list is a list of three elements:
+- A list of keys (characters) to select the command (the fist
+  character in the list is shown in the attachment dispatcher's
+  splash buffer and minubuffer prompt).
+- A command that is called interactively when one of these keys
+  is pressed.
+- A docstring for this command in the attachment dispatcher's
+  splash buffer."
+  :group 'org-attach
+  :package-version '(Org . "9.3")
+  :type '(repeat (list (repeat :tag "Keys" character)
+                      (function :tag "Command")
+                      (string :tag "Docstring"))))
 
 ;;;###autoload
 (defun org-attach ()
   "The dispatcher for attachment commands.
 Shows a list of commands and prompts for another key to execute a command."
   (interactive)
-  (let (c marker)
+  (let ((dir (org-attach-dir nil 'no-fs-check))
+       c marker)
     (when (eq major-mode 'org-agenda-mode)
       (setq marker (or (get-text-property (point) 'org-hd-marker)
                       (get-text-property (point) 'org-marker)))
       (unless marker
-       (error "No task in current line")))
+       (error "No item in current line")))
     (save-excursion
       (when marker
        (set-buffer (marker-buffer marker))
@@ -171,200 +263,189 @@ Shows a list of commands and prompts for another key to 
execute a command."
        (save-window-excursion
          (unless org-attach-expert
            (with-output-to-temp-buffer "*Org Attach*"
-             (princ "Select an Attachment Command:
-
-a       Select a file and attach it to the task, using `org-attach-method'.
-c/m/l/y Attach a file using copy/move/link/symbolic-link method.
-u       Attach a file from URL (downloading it).
-n       Create a new attachment, as an Emacs buffer.
-z       Synchronize the current task with its attachment
-        directory, in case you added attachments yourself.
-
-o       Open current task's attachments.
-O       Like \"o\", but force opening in Emacs.
-f       Open current task's attachment directory.
-F       Like \"f\", but force using dired in Emacs.
-
-d       Delete one attachment, you will be prompted for a file name.
-D       Delete all of a task's attachments.  A safer way is
-        to open the directory in dired and delete from there.
-
-s       Set a specific attachment directory for this entry or reset to default.
-i       Make children of the current entry inherit its attachment 
directory.")))
+              (princ
+               (concat "Attachment folder:\n"
+                      (or dir
+                          "Can't find an existing attachment-folder")
+                      (unless (and dir (file-directory-p dir))
+                        "\n(Not yet created)")
+                      "\n\n"
+                      (format "Select an Attachment Command:\n\n%s"
+                              (mapconcat
+                               (lambda (entry)
+                                 (pcase entry
+                                   (`((,key . ,_) ,_ ,docstring)
+                                    (format "%c       %s"
+                                            key
+                                            (replace-regexp-in-string 
"\n\\([\t ]*\\)"
+                                                                      "        
"
+                                                                      docstring
+                                                                      nil nil 
1)))
+                                   (_
+                                    (user-error
+                                     "Invalid `org-attach-commands' item: %S"
+                                     entry))))
+                               org-attach-commands
+                               "\n"))))))
          (org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
-         (message "Select command: [acmlzoOfFdD]")
+         (message "Select command: [%s]"
+                  (concat (mapcar #'caar org-attach-commands)))
          (setq c (read-char-exclusive))
          (and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
-      (cond
-       ((memq c '(?a ?\C-a)) (call-interactively 'org-attach-attach))
-       ((memq c '(?c ?\C-c))
-       (let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach)))
-       ((memq c '(?m ?\C-m))
-       (let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach)))
-       ((memq c '(?l ?\C-l))
-       (let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach)))
-       ((memq c '(?y ?\C-y))
-       (let ((org-attach-method 'lns)) (call-interactively 
'org-attach-attach)))
-       ((memq c '(?u ?\C-u))
-        (let ((org-attach-method 'url)) (call-interactively 'org-attach-url)))
-       ((memq c '(?n ?\C-n)) (call-interactively 'org-attach-new))
-       ((memq c '(?z ?\C-z)) (call-interactively 'org-attach-sync))
-       ((memq c '(?o ?\C-o)) (call-interactively 'org-attach-open))
-       ((eq c ?O)            (call-interactively 'org-attach-open-in-emacs))
-       ((memq c '(?f ?\C-f)) (call-interactively 'org-attach-reveal))
-       ((memq c '(?F))       (call-interactively 'org-attach-reveal-in-emacs))
-       ((memq c '(?d ?\C-d)) (call-interactively
-                             'org-attach-delete-one))
-       ((eq c ?D)            (call-interactively 'org-attach-delete-all))
-       ((eq c ?q)            (message "Abort"))
-       ((memq c '(?s ?\C-s)) (call-interactively
-                             'org-attach-set-directory))
-       ((memq c '(?i ?\C-i)) (call-interactively
-                             'org-attach-set-inherit))
-       (t (error "No such attachment command %c" c))))))
-
-(defun org-attach-dir (&optional create-if-not-exists-p)
-  "Return the directory associated with the current entry.
-This first checks for a local property ATTACH_DIR, and then for an inherited
-property ATTACH_DIR_INHERIT.  If neither exists, the default mechanism
-using the entry ID will be invoked to access the unique directory for the
-current entry.
-If the directory does not exist and CREATE-IF-NOT-EXISTS-P is non-nil,
-the directory and (if necessary) the corresponding ID will be created."
-  (let (attach-dir uuid)
-    (setq org-attach-inherited (org-entry-get nil "ATTACH_DIR_INHERIT"))
+      (let ((command (cl-some (lambda (entry)
+                               (and (memq c (nth 0 entry)) (nth 1 entry)))
+                             org-attach-commands)))
+       (if (commandp command t)
+           (call-interactively command)
+         (error "No such attachment command: %c" c))))))
+
+(defun org-attach-dir (&optional create-if-not-exists-p no-fs-check)
+  "Return the directory associated with the current outline node.
+First check for DIR property, then ID property.
+`org-attach-use-inheritance' determines whether inherited
+properties also will be considered.
+
+If an ID property is found the default mechanism using that ID
+will be invoked to access the directory for the current entry.
+Note that this method returns the directory as declared by ID or
+DIR even if the directory doesn't exist in the filesystem.
+
+If CREATE-IF-NOT-EXIST-P is non-nil, `org-attach-dir-get-create'
+is run.  If NO-FS-CHECK is non-nil, the function returns the path
+to the attachment even if it has not yet been initialized in the
+filesystem.
+
+If no attachment directory can be derived, return nil."
+  (let (attach-dir id)
     (cond
-     ((setq attach-dir (org-entry-get nil "ATTACH_DIR"))
+     (create-if-not-exists-p
+      (setq attach-dir (org-attach-dir-get-create)))
+     ((setq attach-dir (org-entry-get nil "DIR" org-attach-use-inheritance))
+      (org-attach-check-absolute-path attach-dir))
+     ;; Deprecated and removed from documentation, but still
+     ;; works. FIXME: Remove after major nr change.
+     ((setq attach-dir (org-entry-get nil "ATTACH_DIR" 
org-attach-use-inheritance))
       (org-attach-check-absolute-path attach-dir))
-     ((and org-attach-allow-inheritance
-          (org-entry-get nil "ATTACH_DIR_INHERIT" t))
-      (setq attach-dir
-           (org-with-wide-buffer
-            (if (marker-position org-entry-property-inherited-from)
-                (goto-char org-entry-property-inherited-from)
-              (org-back-to-heading t))
-            (let (org-attach-allow-inheritance)
-              (org-attach-dir create-if-not-exists-p))))
-      (org-attach-check-absolute-path attach-dir)
-      (setq org-attach-inherited t))
-     (t                                        ; use the ID
+     ((setq id (org-entry-get nil "ID" org-attach-use-inheritance))
       (org-attach-check-absolute-path nil)
-      (setq uuid (org-id-get (point) create-if-not-exists-p))
-      (when (or uuid create-if-not-exists-p)
-       (unless uuid (error "ID retrieval/creation failed"))
-       (setq attach-dir (expand-file-name
-                         (format "%s/%s"
-                                 (substring uuid 0 2)
-                                 (substring uuid 2))
-                         (expand-file-name org-attach-directory))))))
-    (when attach-dir
-      (if (and create-if-not-exists-p
-              (not (file-directory-p attach-dir)))
-         (make-directory attach-dir t))
-      (and (file-exists-p attach-dir)
-          attach-dir))))
+      (setq attach-dir (org-attach-dir-from-id id 'try-all))))
+    (if no-fs-check
+       attach-dir
+      (when (and attach-dir (file-directory-p attach-dir))
+       attach-dir))))
+
+(defun org-attach-dir-get-create ()
+  "Return existing or new directory associated with the current outline node.
+`org-attach-preferred-new-method' decides how to attach new
+directory if neither ID nor DIR property exist.
+
+If the attachment by some reason cannot be created an error will be raised."
+  (interactive)
+  (let ((attach-dir (org-attach-dir nil 'no-fs-check)))
+    (unless attach-dir
+      (let (answer)
+       (when (eq org-attach-preferred-new-method 'ask)
+         (message "Create new ID [1] property or DIR [2] property for 
attachments?")
+         (setq answer (read-char-exclusive)))
+       (cond
+        ((or (eq org-attach-preferred-new-method 'id) (eq answer ?1))
+         (setq attach-dir (org-attach-dir-from-id (org-id-get nil t))))
+        ((or (eq org-attach-preferred-new-method 'dir) (eq answer ?2))
+         (setq attach-dir (org-attach-set-directory)))
+        ((eq org-attach-preferred-new-method 'nil)
+         (error "No existing directory. DIR or ID property has to be 
explicitly created")))))
+    (unless attach-dir
+      (error "No attachment directory is associated with the current node"))
+    (unless (file-directory-p attach-dir)
+      (make-directory attach-dir t))
+    attach-dir))
+
+(defun org-attach-dir-from-id (id  &optional try-all)
+  "Returns a folder path based on `org-attach-id-dir' and ID.
+If TRY-ALL is non-nil, try all id-to-path functions in
+`org-attach-id-to-path-function-list' and return the first path
+that exist in the filesystem, or the first one if none exist.
+Otherwise only use the first function in that list."
+  (let ((attach-dir-preferred (expand-file-name
+                              (funcall (car 
org-attach-id-to-path-function-list) id)
+                              (expand-file-name org-attach-id-dir))))
+    (if try-all
+       (let ((attach-dir attach-dir-preferred)
+             (fun-list (cdr org-attach-id-to-path-function-list)))
+         (while (and fun-list (not (file-directory-p attach-dir)))
+           (setq attach-dir (expand-file-name
+                             (funcall (car fun-list) id)
+                             (expand-file-name org-attach-id-dir)))
+           (setq fun-list (cdr fun-list)))
+         (if (file-directory-p attach-dir)
+             attach-dir
+           attach-dir-preferred))
+      attach-dir-preferred)))
 
 (defun org-attach-check-absolute-path (dir)
   "Check if we have enough information to root the attachment directory.
 When DIR is given, check also if it is already absolute.  Otherwise,
-assume that it will be relative, and check if `org-attach-directory' is
+assume that it will be relative, and check if `org-attach-id-dir' is
 absolute, or if at least the current buffer has a file name.
 Throw an error if we cannot root the directory."
   (or (and dir (file-name-absolute-p dir))
-      (file-name-absolute-p org-attach-directory)
+      (file-name-absolute-p org-attach-id-dir)
       (buffer-file-name (buffer-base-buffer))
-      (error "Need absolute `org-attach-directory' to attach in buffers 
without filename")))
+      (error "Need absolute `org-attach-id-dir' to attach in buffers without 
filename")))
 
-(defun org-attach-set-directory (&optional arg)
-  "Set the ATTACH_DIR node property and ask to move files there.
+(defun org-attach-set-directory ()
+  "Set the DIR node property and ask to move files there.
 The property defines the directory that is used for attachments
-of the entry.  When called with `\\[universal-argument]', reset \
-the directory to
-the default ID based one."
-  (interactive "P")
+of the entry.  Creates relative links if `org-attach-dir-relative'
+is non-nil.
+
+Return the directory."
+  (interactive)
   (let ((old (org-attach-dir))
-        (new
-         (progn
-           (if arg (org-entry-delete nil "ATTACH_DIR")
-             (let ((dir (read-directory-name
-                         "Attachment directory: "
-                         (org-entry-get nil
-                                        "ATTACH_DIR"
-                                        (and org-attach-allow-inheritance 
t)))))
-               (org-entry-put nil "ATTACH_DIR" dir)))
-           (org-attach-dir t))))
+       (new
+        (let* ((attach-dir (read-directory-name
+                            "Attachment directory: "
+                            (org-entry-get nil "DIR")))
+               (current-dir (file-name-directory (or default-directory
+                                                     buffer-file-name)))
+               (attach-dir-relative (file-relative-name attach-dir 
current-dir)))
+          (org-entry-put nil "DIR" (if org-attach-dir-relative
+                                       attach-dir-relative
+                                     attach-dir))
+           attach-dir)))
     (unless (or (string= old new)
                 (not old))
       (when (yes-or-no-p "Copy over attachments from old directory? ")
+        (copy-directory old new t t t))
+      (when (yes-or-no-p (concat "Delete " old))
+        (delete-directory old t)))
+    new))
+
+(defun org-attach-unset-directory ()
+  "Removes DIR node property.
+If attachment folder is changed due to removal of DIR-property
+ask to move attachments to new location and ask to delete old
+attachment-folder.
+
+Change of attachment-folder due to unset might be if an ID
+property is set on the node, or if a separate inherited
+DIR-property exists (that is different than the unset one)."
+  (interactive)
+  (let ((old (org-attach-dir))
+       (new
+         (progn
+          (org-entry-delete nil "DIR")
+          ;; ATTACH-DIR is deprecated and removed from documentation,
+          ;; but still works. Remove code for it after major nr change.
+          (org-entry-delete nil "ATTACH_DIR")
+          (org-attach-dir))))
+    (unless (or (string= old new)
+                (not old))
+      (when (and new (yes-or-no-p "Copy over attachments from old directory? 
"))
         (copy-directory old new t nil t))
       (when (yes-or-no-p (concat "Delete " old))
         (delete-directory old t)))))
 
-(defun org-attach-set-inherit ()
-  "Set the ATTACH_DIR_INHERIT property of the current entry.
-The property defines the directory that is used for attachments
-of the entry and any children that do not explicitly define (by setting
-the ATTACH_DIR property) their own attachment directory."
-  (interactive)
-  (org-entry-put nil "ATTACH_DIR_INHERIT" "t")
-  (message "Children will inherit attachment directory"))
-
-(defun org-attach-use-annex ()
-  "Return non-nil if git annex can be used."
-  (let ((git-dir (vc-git-root (expand-file-name org-attach-directory))))
-    (and org-attach-git-annex-cutoff
-         (or (file-exists-p (expand-file-name "annex" git-dir))
-             (file-exists-p (expand-file-name ".git/annex" git-dir))))))
-
-(defun org-attach-annex-get-maybe (path)
-  "Call git annex get PATH (via shell) if using git annex.
-Signals an error if the file content is not available and it was not 
retrieved."
-  (let ((path-relative (file-relative-name path)))
-    (when (and (org-attach-use-annex)
-              (not
-               (string-equal
-                "found"
-                (shell-command-to-string
-                 (format "git annex find --format=found --in=here %s"
-                         (shell-quote-argument path-relative))))))
-      (let ((should-get
-            (if (eq org-attach-annex-auto-get 'ask)
-                (y-or-n-p (format "Run git annex get %s? " path-relative))
-              org-attach-annex-auto-get)))
-       (if should-get
-           (progn (message "Running git annex get \"%s\"." path-relative)
-                  (call-process "git" nil nil nil "annex" "get" path-relative))
-         (error "File %s stored in git annex but it is not available, and was 
not retrieved"
-                path))))))
-
-(defun org-attach-commit ()
-  "Commit changes to git if `org-attach-directory' is properly initialized.
-This checks for the existence of a \".git\" directory in that directory."
-  (let* ((dir (expand-file-name org-attach-directory))
-        (git-dir (vc-git-root dir))
-        (use-annex (org-attach-use-annex))
-        (changes 0))
-    (when (and git-dir (executable-find "git"))
-      (with-temp-buffer
-       (cd dir)
-        (dolist (new-or-modified
-                 (split-string
-                  (shell-command-to-string
-                   "git ls-files -zmo --exclude-standard") "\0" t))
-          (if (and use-annex
-                   (>= (file-attribute-size (file-attributes new-or-modified))
-                       org-attach-git-annex-cutoff))
-              (call-process "git" nil nil nil "annex" "add" new-or-modified)
-            (call-process "git" nil nil nil "add" new-or-modified))
-           (cl-incf changes))
-       (dolist (deleted
-                (split-string
-                 (shell-command-to-string "git ls-files -z --deleted") "\0" t))
-         (call-process "git" nil nil nil "rm" deleted)
-         (cl-incf changes))
-       (when (> changes 0)
-         (shell-command "git commit -m 'Synchronized attachments'"))))))
-
 (defun org-attach-tag (&optional off)
   "Turn the autotag on or (if OFF is set) off."
   (when org-attach-auto-tag
@@ -386,10 +467,25 @@ Only do this when `org-attach-store-link-p' is non-nil."
 
 (defun org-attach-url (url)
   (interactive "MURL of the file to attach: \n")
-  (org-attach-attach url))
+  (let ((org-attach-method 'url))
+    (org-attach-attach url)))
+
+(defun org-attach-buffer (buffer-name)
+  "Attach BUFFER-NAME's contents to current outline node.
+BUFFER-NAME is a string.  Signals a `file-already-exists' error
+if it would overwrite an existing filename."
+  (interactive "bBuffer whose contents should be attached: ")
+  (let* ((attach-dir (org-attach-dir 'get-create))
+        (output (expand-file-name buffer-name attach-dir)))
+    (when (file-exists-p output)
+      (signal 'file-already-exists (list "File exists" output)))
+    (run-hook-with-args 'org-attach-after-change-hook attach-dir)
+    (org-attach-tag)
+    (with-temp-file output
+      (insert-buffer-substring buffer-name))))
 
 (defun org-attach-attach (file &optional visit-dir method)
-  "Move/copy/link FILE into the attachment directory of the current task.
+  "Move/copy/link FILE into the attachment directory of the current outline 
node.
 If VISIT-DIR is non-nil, visit the directory with dired.
 METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
 `org-attach-method'."
@@ -404,10 +500,7 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default 
taken from
     nil))
   (setq method (or method org-attach-method))
   (let ((basename (file-name-nondirectory file)))
-    (when (and org-attach-file-list-property (not org-attach-inherited))
-      (org-entry-add-to-multivalued-property
-       (point) org-attach-file-list-property basename))
-    (let* ((attach-dir (org-attach-dir t))
+    (let* ((attach-dir (org-attach-dir 'get-create))
            (fname (expand-file-name basename attach-dir)))
       (cond
        ((eq method 'mv) (rename-file file fname))
@@ -415,8 +508,7 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default 
taken from
        ((eq method 'ln) (add-name-to-file file fname))
        ((eq method 'lns) (make-symbolic-link file fname))
        ((eq method 'url) (url-copy-file file fname)))
-      (when org-attach-commit
-        (org-attach-commit))
+      (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-tag)
       (cond ((eq org-attach-store-link-p 'attached)
              (org-attach-store-link fname))
@@ -424,7 +516,7 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default 
taken from
              (org-attach-store-link file)))
       (if visit-dir
           (dired attach-dir)
-        (message "File %S is now a task attachment." basename)))))
+        (message "File %S is now an attachment." basename)))))
 
 (defun org-attach-attach-cp ()
   "Attach a file by copying it."
@@ -449,13 +541,10 @@ On some systems, this apparently does copy the file 
instead."
   (let ((org-attach-method 'lns)) (call-interactively 'org-attach-attach)))
 
 (defun org-attach-new (file)
-  "Create a new attachment FILE for the current task.
+  "Create a new attachment FILE for the current outline node.
 The attachment is created as an Emacs buffer."
   (interactive "sCreate attachment named: ")
-  (when (and org-attach-file-list-property (not org-attach-inherited))
-    (org-entry-add-to-multivalued-property
-     (point) org-attach-file-list-property file))
-  (let ((attach-dir (org-attach-dir t)))
+  (let ((attach-dir (org-attach-dir 'get-create)))
     (org-attach-tag)
     (find-file (expand-file-name file attach-dir))
     (message "New attachment %s" file)))
@@ -463,7 +552,7 @@ The attachment is created as an Emacs buffer."
 (defun org-attach-delete-one (&optional file)
   "Delete a single attachment."
   (interactive)
-  (let* ((attach-dir (org-attach-dir t))
+  (let* ((attach-dir (org-attach-dir))
         (files (org-attach-file-list attach-dir))
         (file (or file
                   (completing-read
@@ -475,44 +564,32 @@ The attachment is created as an Emacs buffer."
     (unless (file-exists-p file)
       (error "No such attachment: %s" file))
     (delete-file file)
-    (when org-attach-commit
-      (org-attach-commit))))
+    (run-hook-with-args 'org-attach-after-change-hook attach-dir)))
 
 (defun org-attach-delete-all (&optional force)
-  "Delete all attachments from the current task.
+  "Delete all attachments from the current outline node.
 This actually deletes the entire attachment directory.
 A safer way is to open the directory in dired and delete from there."
   (interactive "P")
-  (when (and org-attach-file-list-property (not org-attach-inherited))
-    (org-entry-delete (point) org-attach-file-list-property))
   (let ((attach-dir (org-attach-dir)))
-    (when
-       (and attach-dir
-            (or force
-                (y-or-n-p "Are you sure you want to remove all attachments of 
this entry? ")))
-      (shell-command (format "rm -fr %s" attach-dir))
+    (when (and attach-dir
+              (or force
+                  (yes-or-no-p "Really remove all attachments of this entry? 
")))
+      (delete-directory attach-dir (yes-or-no-p "Recursive?") t)
       (message "Attachment directory removed")
-      (when org-attach-commit
-        (org-attach-commit))
+      (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-untag))))
 
 (defun org-attach-sync ()
-  "Synchronize the current tasks with its attachments.
+  "Synchronize the current outline node with its attachments.
 This can be used after files have been added externally."
   (interactive)
-  (when org-attach-commit
-    (org-attach-commit))
-  (when (and org-attach-file-list-property (not org-attach-inherited))
-    (org-entry-delete (point) org-attach-file-list-property))
   (let ((attach-dir (org-attach-dir)))
     (when attach-dir
+      (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (let ((files (org-attach-file-list attach-dir)))
-       (org-attach-tag (not files))
-       (when org-attach-file-list-property
-         (dolist (file files)
-           (unless (string-match "^\\.\\.?\\'" file)
-             (org-entry-add-to-multivalued-property
-              (point) org-attach-file-list-property file))))))))
+       (org-attach-tag (not files))))
+    (unless attach-dir (org-attach-tag t))))
 
 (defun org-attach-file-list (dir)
   "Return a list of files in the attachment directory.
@@ -521,35 +598,38 @@ This ignores files ending in \"~\"."
        (mapcar (lambda (x) (if (string-match "^\\.\\.?\\'" x) nil x))
                (directory-files dir nil "[^~]\\'"))))
 
-(defun org-attach-reveal (&optional if-exists)
-  "Show the attachment directory of the current task.
-This will attempt to use an external program to show the directory."
-  (interactive "P")
-  (let ((attach-dir (org-attach-dir (not if-exists))))
-    (and attach-dir (org-open-file attach-dir))))
+(defun org-attach-reveal ()
+  "Show the attachment directory of the current outline node.
+This will attempt to use an external program to show the
+directory.  Will create an attachment and folder if it doesn't
+exist yet.  Respects `org-attach-preferred-new-method'."
+  (interactive)
+  (org-open-file (org-attach-dir-get-create)))
 
 (defun org-attach-reveal-in-emacs ()
-  "Show the attachment directory of the current task in dired."
+  "Show the attachment directory of the current outline node in dired.
+Will create an attachment and folder if it doesn't exist yet.
+Respects `org-attach-preferred-new-method'."
   (interactive)
-  (let ((attach-dir (org-attach-dir t)))
-    (dired attach-dir)))
+  (dired (org-attach-dir-get-create)))
 
 (defun org-attach-open (&optional in-emacs)
-  "Open an attachment of the current task.
+  "Open an attachment of the current outline node.
 If there are more than one attachment, you will be prompted for the file name.
 This command will open the file using the settings in `org-file-apps'
 and in the system-specific variants of this variable.
 If IN-EMACS is non-nil, force opening in Emacs."
   (interactive "P")
-  (let* ((attach-dir (org-attach-dir t))
-        (files (org-attach-file-list attach-dir))
-        (file (if (= (length files) 1)
-                  (car files)
-                (completing-read "Open attachment: "
-                                 (mapcar #'list files) nil t)))
-         (path (expand-file-name file attach-dir)))
-    (org-attach-annex-get-maybe path)
-    (org-open-file path in-emacs)))
+  (let ((attach-dir (org-attach-dir)))
+    (if attach-dir
+       (let* ((file (pcase (org-attach-file-list attach-dir)
+                      (`(,file) file)
+                      (files (completing-read "Open attachment: "
+                                              (mapcar #'list files) nil t))))
+              (path (expand-file-name file attach-dir)))
+         (run-hook-with-args 'org-attach-open-hook path)
+         (org-open-file path in-emacs))
+      (error "No attachment directory exist"))))
 
 (defun org-attach-open-in-emacs ()
   "Open attachment, force opening in Emacs.
@@ -568,14 +648,114 @@ Basically, this adds the path to the attachment 
directory, and a \"file:\"
 prefix."
   (concat "file:" (org-attach-expand file)))
 
+(org-link-set-parameters "attachment"
+                         :follow #'org-attach-open-link
+                         :export #'org-attach-export-link
+                         :complete #'org-attach-complete-link)
+
+(defun org-attach-open-link (link &optional in-emacs)
+  "Attachment link type LINK is expanded with the attached directory and 
opened.
+
+With optional prefix argument IN-EMACS, Emacs will visit the file.
+With a double \\[universal-argument] \\[universal-argument] \
+prefix arg, Org tries to avoid opening in Emacs
+and to use an external application to visit the file."
+  (interactive "P")
+  (let (line search)
+    (cond
+     ((string-match "::\\([0-9]+\\)\\'" link)
+      (setq line (string-to-number (match-string 1 link))
+           link (substring link 0 (match-beginning 0))))
+     ((string-match "::\\(.+\\)\\'" link)
+      (setq search (match-string 1 link)
+            link (substring link 0 (match-beginning 0)))))
+    (if (string-match "[*?{]" (file-name-nondirectory link))
+        (dired (org-attach-expand link))
+      (org-open-file (org-attach-expand link) in-emacs line search))))
+
+(defun org-attach-complete-link ()
+  "Advise the user with the available files in the attachment directory."
+  (let ((attach-dir (org-attach-dir)))
+    (if attach-dir
+       (let* ((attached-dir (expand-file-name attach-dir))
+              (file (read-file-name "File: " attached-dir))
+              (pwd (file-name-as-directory attached-dir))
+               (pwd-relative (file-name-as-directory
+                             (abbreviate-file-name attached-dir))))
+         (cond
+          ((string-match (concat "^" (regexp-quote pwd-relative) "\\(.+\\)") 
file)
+           (concat "attachment:" (match-string 1 file)))
+          ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
+                         (expand-file-name file))
+           (concat "attachment:" (match-string 1 (expand-file-name file))))
+          (t (concat "attachment:" file))))
+      (error "No attachment directory exist"))))
+
+(defun org-attach-export-link (link description format)
+  "Translate attachment LINK from Org mode format to exported FORMAT.
+Also includes the DESCRIPTION of the link in the export."
+  (save-excursion
+    (let (path desc)
+      (cond
+       ((string-match "::\\([0-9]+\\)\\'" link)
+        (setq link (substring link 0 (match-beginning 0))))
+       ((string-match "::\\(.+\\)\\'" link)
+        (setq link (substring link 0 (match-beginning 0)))))
+      (setq path (file-relative-name (org-attach-expand link))
+            desc (or description link))
+      (pcase format
+        (`html (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
+        (`latex (format "\\href{%s}{%s}" path desc))
+        (`texinfo (format "@uref{%s,%s}" path desc))
+        (`ascii (format "%s (%s)" desc path))
+        (`md (format "[%s](%s)" desc path))
+        (_ path)))))
+
 (defun org-attach-archive-delete-maybe ()
   "Maybe delete subtree attachments when archiving.
 This function is called by `org-archive-hook'.  The option
 `org-attach-archive-delete' controls its behavior."
-  (when (if (eq org-attach-archive-delete 'query)
-           (yes-or-no-p "Delete all attachments? ")
-         org-attach-archive-delete)
-    (org-attach-delete-all t)))
+  (when org-attach-archive-delete
+    (org-attach-delete-all (not (eq org-attach-archive-delete 'query)))))
+
+
+;; Attach from dired.
+
+;; Add the following lines to the config file to get a binding for
+;; dired-mode.
+
+;; (add-hook
+;;  'dired-mode-hook
+;;  (lambda ()
+;;    (define-key dired-mode-map (kbd "C-c C-x a") 
#'org-attach-dired-to-subtree))))
+
+;;;###autoload
+(defun org-attach-dired-to-subtree (files)
+  "Attach FILES marked or current file in dired to subtree in other window.
+Takes the method given in `org-attach-method' for the attach action.
+Precondition: Point must be in a dired buffer.
+Idea taken from `gnus-dired-attach'."
+  (interactive
+   (list (dired-get-marked-files)))
+  (unless (eq major-mode 'dired-mode)
+    (user-error "This command must be triggered in a dired buffer"))
+  (let ((start-win (selected-window))
+        (other-win
+         (get-window-with-predicate
+          (lambda (window)
+            (with-current-buffer (window-buffer window)
+              (eq major-mode 'org-mode))))))
+    (unless other-win
+      (user-error
+       "Can't attach to subtree.  No window displaying an Org buffer"))
+    (select-window other-win)
+    (dolist (file files)
+      (org-attach-attach file))
+    (select-window start-win)
+    (when (eq 'mv org-attach-method)
+      (revert-buffer))))
+
+
 
 (add-hook 'org-archive-hook 'org-attach-archive-delete-maybe)
 
diff --git a/lisp/org/org-capture.el b/lisp/org/org-capture.el
index 829872c..4f97e17 100644
--- a/lisp/org/org-capture.el
+++ b/lisp/org/org-capture.el
@@ -51,20 +51,32 @@
 (require 'org)
 
 (declare-function org-at-encrypted-entry-p "org-crypt" ())
+(declare-function org-at-table-p "org-table" (&optional table-type))
 (declare-function org-clock-update-mode-line "org-clock" (&optional refresh))
 (declare-function org-datetree-find-date-create "org-datetree" (date &optional 
keep-restriction))
 (declare-function org-decrypt-entry "org-crypt" ())
+(declare-function org-element-at-point "org-element" ())
+(declare-function org-element-lineage "org-element" (datum &optional types 
with-self))
+(declare-function org-element-property "org-element" (property element))
 (declare-function org-encrypt-entry "org-crypt" ())
+(declare-function org-insert-link "ol" (&optional complete-file link-location 
default-description))
+(declare-function org-link-make-string "ol" (link &optional description))
 (declare-function org-table-analyze "org-table" ())
 (declare-function org-table-current-dline "org-table" ())
+(declare-function org-table-fix-formulas "org-table" (key replace &optional 
limit delta remove))
 (declare-function org-table-goto-line "org-table" (N))
 
+(defvar dired-buffers)
 (defvar org-end-time-was-given)
 (defvar org-remember-default-headline)
 (defvar org-remember-templates)
-(defvar org-table-hlines)
+(defvar org-store-link-plist)
+(defvar org-table-border-regexp)
 (defvar org-table-current-begin-pos)
-(defvar dired-buffers)
+(defvar org-table-dataline-regexp)
+(defvar org-table-fix-formulas-confirm)
+(defvar org-table-hline-regexp)
+(defvar org-table-hlines)
 
 (defvar org-capture-clock-was-started nil
   "Internal flag, noting if the clock was started.")
@@ -263,6 +275,8 @@ properties are:
                      capture was invoked, kill the buffer again after capture
                      is finalized.
 
+ :no-save            Do not save the target file after finishing the capture.
+
 The template defines the text to be inserted.  Often this is an
 Org mode entry (so the first line should start with a star) that
 will be filed as a child of the target headline.  It can also be
@@ -284,8 +298,10 @@ be replaced with content and expanded:
               with `org-capture-use-agenda-date' set.
   %T          Time stamp as above, with date and time.
   %u, %U      Like the above, but inactive time stamps.
-  %i          Initial content, copied from the active region.  If %i is
-              indented, the entire inserted text will be indented as well.
+  %i          Initial content, copied from the active region.  If
+              there is text before %i on the same line, such as
+              indentation, and %i is not inside a %(sexp), that prefix
+              will be added before every line in the inserted text.
   %a          Annotation, normally the link created with `org-store-link'.
   %A          Like %a, but prompt for the description part.
   %l          Like %a, but only insert the literal link.
@@ -474,37 +490,32 @@ this is necessary after initialization of the capture 
process,
 to avoid conflicts with other active capture processes."
   (plist-get (if local org-capture-current-plist org-capture-plist) prop))
 
-(defun org-capture-member (prop &optional local)
-  "Is PROP a property in `org-capture-plist'.
-When LOCAL is set, use the local variable `org-capture-current-plist',
-this is necessary after initialization of the capture process,
-to avoid conflicts with other active capture processes."
-  (plist-get (if local org-capture-current-plist org-capture-plist) prop))
-
 ;;; The minor mode
 
-(defvar org-capture-mode-map (make-sparse-keymap)
+(defvar org-capture-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c\C-c" #'org-capture-finalize)
+    (define-key map "\C-c\C-k" #'org-capture-kill)
+    (define-key map "\C-c\C-w" #'org-capture-refile)
+    map)
   "Keymap for `org-capture-mode', a minor mode.
 Use this map to set additional keybindings for when Org mode is used
 for a capture buffer.")
 
 (defvar org-capture-mode-hook nil
-  "Hook for the minor `org-capture-mode'.")
+  "Hook for the `org-capture-mode' minor mode.")
 
 (define-minor-mode org-capture-mode
   "Minor mode for special key bindings in a capture buffer.
 
 Turning on this mode runs the normal hook `org-capture-mode-hook'."
-  nil " Rem" org-capture-mode-map
+  nil " Cap" org-capture-mode-map
   (setq-local
    header-line-format
    (substitute-command-keys
     "\\<org-capture-mode-map>Capture buffer.  Finish \
 `\\[org-capture-finalize]', refile `\\[org-capture-refile]', \
 abort `\\[org-capture-kill]'.")))
-(define-key org-capture-mode-map "\C-c\C-c" 'org-capture-finalize)
-(define-key org-capture-mode-map "\C-c\C-k" 'org-capture-kill)
-(define-key org-capture-mode-map "\C-c\C-w" 'org-capture-refile)
 
 ;;; The main commands
 
@@ -652,44 +663,38 @@ of the day at point (if any) or the current HH:MM time."
                         :annotation annotation
                         :initial initial
                         :return-to-wconf (current-window-configuration)
-                        :default-time
-                        (or org-overriding-default-time
-                            (org-current-time)))
-       (org-capture-set-target-location)
+                        :default-time (or org-overriding-default-time
+                                          (org-current-time)))
+       (org-capture-set-target-location (and (equal goto 0) 'here))
        (condition-case error
            (org-capture-put :template (org-capture-fill-template))
          ((error quit)
           (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
-          (error "Capture abort: %s" error)))
+          (error "Capture abort: %s" (error-message-string error))))
 
        (setq org-capture-clock-keep (org-capture-get :clock-keep))
-       (if (equal goto 0)
-           ;;insert at point
-           (org-capture-insert-template-here)
-         (condition-case error
-             (org-capture-place-template
-              (eq (car (org-capture-get :target)) 'function))
-           ((error quit)
-            (if (and (buffer-base-buffer (current-buffer))
+       (condition-case error
+           (org-capture-place-template
+            (eq (car (org-capture-get :target)) 'function))
+         ((error quit)
+          (when (and (buffer-base-buffer (current-buffer))
                      (string-prefix-p "CAPTURE-" (buffer-name)))
-                (kill-buffer (current-buffer)))
-            (set-window-configuration (org-capture-get :return-to-wconf))
-            (error "Capture template `%s': %s"
-                   (org-capture-get :key)
-                   (nth 1 error))))
-         (if (and (derived-mode-p 'org-mode)
-                  (org-capture-get :clock-in))
-             (condition-case nil
-                 (progn
-                   (if (org-clock-is-active)
-                       (org-capture-put :interrupted-clock
-                                        (copy-marker org-clock-marker)))
-                   (org-clock-in)
-                   (setq-local org-capture-clock-was-started t))
-               (error
-                "Could not start the clock in this capture buffer")))
-         (if (org-capture-get :immediate-finish)
-             (org-capture-finalize)))))))))
+            (kill-buffer (current-buffer)))
+          (set-window-configuration (org-capture-get :return-to-wconf))
+          (error "Capture template `%s': %s"
+                 (org-capture-get :key)
+                 (error-message-string error))))
+       (when (and (derived-mode-p 'org-mode) (org-capture-get :clock-in))
+         (condition-case nil
+             (progn
+               (when (org-clock-is-active)
+                 (org-capture-put :interrupted-clock
+                                  (copy-marker org-clock-marker)))
+               (org-clock-in)
+               (setq-local org-capture-clock-was-started t))
+           (error "Could not start the clock in this capture buffer")))
+       (when (org-capture-get :immediate-finish)
+         (org-capture-finalize))))))))
 
 (defun org-capture-get-template ()
   "Get the template from a file or a function if necessary."
@@ -743,9 +748,7 @@ captured item after finalizing."
          (org-with-point-at clock-in-task (org-clock-in)))
        (message "Interrupted clock has been resumed"))))
 
-  (let ((beg (point-min))
-       (end (point-max))
-       (abort-note nil))
+  (let ((abort-note nil))
     ;; Store the size of the capture buffer
     (org-capture-put :captured-entry-size (- (point-max) (point-min)))
     (widen)
@@ -753,16 +756,11 @@ captured item after finalizing."
     (org-capture-put :insertion-point (point))
 
     (if org-note-abort
-       (let ((m1 (org-capture-get :begin-marker 'local))
-             (m2 (org-capture-get :end-marker 'local)))
-         (if (and m1 m2 (= m1 beg) (= m2 end))
-             (progn
-               (setq m2 (if (cdr (assq 'heading org-blank-before-new-entry))
-                            m2 (1+ m2))
-                     m2 (if (< (point-max) m2) (point-max) m2))
-               (setq abort-note 'clean)
-               (kill-region m1 m2))
-           (setq abort-note 'dirty)))
+       (let ((beg (org-capture-get :begin-marker 'local))
+             (end (org-capture-get :end-marker 'local)))
+         (if (not (and beg end)) (setq abort-note 'dirty)
+           (setq abort-note t)
+           (org-with-wide-buffer (kill-region beg end))))
 
       ;; Postprocessing:  Update Statistics cookies, do the sorting
       (when (derived-mode-p 'org-mode)
@@ -774,9 +772,21 @@ captured item after finalizing."
        ;; If we have added a table line, maybe recompute?
        (when (and (eq (org-capture-get :type 'local) 'table-line)
                   (org-at-table-p))
-         (if (org-table-get-stored-formulas)
-             (org-table-recalculate 'all) ;; FIXME: Should we iterate???
-           (org-table-align))))
+         (if (not (org-table-get-stored-formulas)) (org-table-align)
+           ;; Adjust formulas, if necessary.  We assume a non-nil
+           ;; `:immediate-finish' means that no confirmation is
+           ;; required.  Else, obey `org-table-fix-formulas-confirm'.
+           ;;
+           ;; The delta required to fix formulas depends on the
+           ;; number of rows inserted by the template.
+           (when (or (org-capture-get :immediate-finish)
+                     (not org-table-fix-formulas-confirm)
+                     (funcall org-table-fix-formulas-confirm "Fix formulas? "))
+             (org-table-fix-formulas
+              "@" nil (1- (org-table-current-dline))
+              (count-lines (org-capture-get :begin-marker 'local)
+                           (org-capture-get :end-marker 'local))))
+           (org-table-recalculate 'all)))) ;FIXME: should we iterate?
       ;; Store this place as the last one where we stored something
       ;; Do the marking in the base buffer, so that it makes sense after
       ;; the indirect buffer has been killed.
@@ -790,8 +800,8 @@ captured item after finalizing."
        (goto-char (org-capture-get :decrypted))
        (org-encrypt-entry)))
 
-    ;; Kill the indirect buffer
-    (save-buffer)
+    (unless (org-capture-get :no-save) (save-buffer))
+
     (let ((return-wconf (org-capture-get :return-to-wconf 'local))
          (new-buffer (org-capture-get :new-buffer 'local))
          (kill-buffer (org-capture-get :kill-buffer 'local))
@@ -867,17 +877,15 @@ for `entry'-type templates"))
     ;; early.  We want to wait for the refiling to be over, so we
     ;; control when the latter function is called.
     (org-capture-put :kill-buffer nil :jump-to-captured nil)
-    (unwind-protect
-       (progn
-         (org-capture-finalize)
-         (save-window-excursion
-           (with-current-buffer base
-             (org-with-wide-buffer
-              (goto-char pos)
-              (call-interactively 'org-refile))))
-         (when kill-buffer (kill-buffer base))
-         (when jump-to-captured (org-capture-goto-last-stored)))
-      (set-marker pos nil))))
+    (org-capture-finalize)
+    (save-window-excursion
+      (with-current-buffer base
+       (org-with-point-at pos
+         (call-interactively 'org-refile))))
+    (when kill-buffer
+      (with-current-buffer base (save-buffer))
+      (kill-buffer base))
+    (when jump-to-captured (org-capture-goto-last-stored))))
 
 (defun org-capture-kill ()
   "Abort the current capture process."
@@ -915,6 +923,8 @@ Store them in the capture property list."
   (let ((target-entry-p t))
     (save-excursion
       (pcase (or target (org-capture-get :target))
+       (`here
+        (org-capture-put :exact-position (point) :insert-here t))
        (`(file ,path)
         (set-buffer (org-capture-target-buffer path))
         (org-capture-put-target-region-and-position)
@@ -1000,7 +1010,7 @@ Store them in the capture property list."
                   (equal current-prefix-arg 1))
               ;; Prompt for date.
               (let ((prompt-time (org-read-date
-                                  nil t nil "Date for tree entry:" nil)))
+                                  nil t nil "Date for tree entry:")))
                 (org-capture-put
                  :default-time
                  (cond ((and (or (not (boundp 'org-time-was-given))
@@ -1008,7 +1018,8 @@ Store them in the capture property list."
                              (not (= (time-to-days prompt-time) (org-today))))
                         ;; Use 00:00 when no time is given for another
                         ;; date than today?
-                        (apply #'encode-time 0 0 0
+                        (apply #'encode-time 0 0
+                               org-extend-today-until
                                (cl-cdddr (decode-time prompt-time))))
                        ((string-match "\\([^ ]+\\)--?[^ ]+[ ]+\\(.*\\)"
                                       org-read-date-final-answer)
@@ -1026,7 +1037,7 @@ Store them in the capture property list."
               (org-today))))
            ;; the following is the keep-restriction argument for
            ;; org-datetree-find-date-create
-           (if outline-path 'subtree-at-point))))
+           (when outline-path 'subtree-at-point))))
        (`(file+function ,path ,function)
         (set-buffer (org-capture-target-buffer path))
         (org-capture-put-target-region-and-position)
@@ -1095,7 +1106,7 @@ may have been stored before."
   (org-switch-to-buffer-other-window
    (org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
   (widen)
-  (outline-show-all)
+  (org-show-all)
   (goto-char (org-capture-get :pos))
   (setq-local outline-level 'org-outline-level)
   (pcase (org-capture-get :type)
@@ -1109,11 +1120,16 @@ may have been stored before."
 
 (defun org-capture-place-entry ()
   "Place the template as a new Org entry."
-  (let ((reversed? (org-capture-get :prepend))
+  (let ((template (org-capture-get :template))
+       (reversed? (org-capture-get :prepend))
+       (exact-position (org-capture-get :exact-position))
+       (insert-here? (org-capture-get :insert-here))
        (level 1))
-    (when (org-capture-get :exact-position)
-      (goto-char (org-capture-get :exact-position)))
+    (org-capture-verify-tree template)
+    (when exact-position (goto-char exact-position))
     (cond
+     ;; Force insertion at point.
+     ((org-capture-get :insert-here) nil)
      ;; Insert as a child of the current entry.
      ((org-capture-get :target-entry-p)
       (setq level (org-get-valid-level
@@ -1126,165 +1142,220 @@ may have been stored before."
       (unless (org-at-heading-p) (outline-next-heading)))
      ;; Otherwise, insert as a top-level entry at the end of the file.
      (t (goto-char (point-max))))
-    (unless (bolp) (insert "\n"))
-    (org-capture-empty-lines-before)
-    (let ((beg (point))
-         (template (org-capture-get :template)))
-      (org-capture-verify-tree template)
-      (org-paste-subtree level template 'for-yank)
-      (org-capture-empty-lines-after)
-      (org-capture-position-for-last-stored beg)
-      (unless (org-at-heading-p) (outline-next-heading))
-      (let ((end (point)))
-       (org-capture-mark-kill-region beg end)
-       (org-capture-narrow beg end)
-       (when (or (re-search-backward "%\\?" beg t)
-                 (re-search-forward "%\\?" end t))
-         (replace-match ""))))))
+    (let ((origin (point)))
+      (unless (bolp) (insert "\n"))
+      (org-capture-empty-lines-before)
+      (let ((beg (point)))
+       (save-restriction
+         (when insert-here? (narrow-to-region beg beg))
+         (org-paste-subtree level template 'for-yank))
+       (org-capture-position-for-last-stored beg)
+       (let ((end (if (org-at-heading-p) (line-end-position 0) (point))))
+         (org-capture-empty-lines-after)
+         (unless (org-at-heading-p) (outline-next-heading))
+         (org-capture-mark-kill-region origin (point))
+         (org-capture-narrow beg end)
+         (when (or (search-backward "%?" beg t)
+                   (search-forward "%?" end t))
+           (replace-match "")))))))
 
 (defun org-capture-place-item ()
   "Place the template as a new plain list item."
-  (let* ((txt (org-capture-get :template))
-        (target-entry-p (org-capture-get :target-entry-p))
-        (ind 0)
-        beg end)
-    (if (org-capture-get :exact-position)
-       (goto-char (org-capture-get :exact-position))
-      (cond
-       ((not target-entry-p)
-       ;; Insert as top-level entry, either at beginning or at end of file
-       (setq beg (point-min) end (point-max)))
-       (t
-       (setq beg (1+ (point-at-eol))
-             end (save-excursion (outline-next-heading) (point)))))
-      (setq ind nil)
-      (if (org-capture-get :prepend)
-         (progn
-           (goto-char beg)
-           (when (org-list-search-forward (org-item-beginning-re) end t)
-             (goto-char (match-beginning 0))
-             (setq ind (org-get-indentation))))
-       (goto-char end)
-       (when (org-list-search-backward (org-item-beginning-re) beg t)
-         (setq ind (org-get-indentation))
-         (org-end-of-item)))
-      (unless ind (goto-char end)))
-    ;; Remove common indentation
-    (setq txt (org-remove-indentation txt))
-    ;; Make sure this is indeed an item
-    (unless (string-match (concat "\\`" (org-item-re)) txt)
-      (setq txt (concat "- "
-                       (mapconcat 'identity (split-string txt "\n")
-                                  "\n  "))))
-    ;; Prepare surrounding empty lines.
-    (unless (bolp) (insert "\n"))
-    (org-capture-empty-lines-before)
-    (setq beg (point))
-    (unless (eolp) (save-excursion (insert "\n")))
-    (unless ind
-      (org-indent-line)
-      (setq ind (org-get-indentation))
-      (delete-region beg (point)))
-    ;; Set the correct indentation, depending on context
-    (setq ind (make-string ind ?\ ))
-    (setq txt (concat ind
-                     (mapconcat 'identity (split-string txt "\n")
-                                (concat "\n" ind))
-                     "\n"))
-    ;; Insert item.
-    (insert txt)
-    (org-capture-empty-lines-after)
-    (org-capture-position-for-last-stored beg)
-    (setq end (point))
-    (org-capture-mark-kill-region beg end)
-    (org-capture-narrow beg end)
-    (if (or (re-search-backward "%\\?" beg t)
-           (re-search-forward "%\\?" end t))
-       (replace-match ""))))
+  (let ((prepend? (org-capture-get :prepend))
+       (template (org-remove-indentation (org-capture-get :template)))
+       item)
+    ;; Make template suitable for insertion.  In particular, add
+    ;; a main bullet if it is missing.
+    (unless (string-match-p (concat "\\`" (org-item-re)) template)
+      (setq template (concat "- " (mapconcat #'identity
+                                            (split-string template "\n")
+                                            "\n  "))))
+    ;; Delimit the area where we should look for a plain list.
+    (pcase-let ((`(,beg . ,end)
+                (cond ((org-capture-get :exact-position)
+                       ;; User gave a specific position.  Start
+                       ;; looking for lists from here.
+                       (org-with-point-at (org-capture-get :exact-position)
+                         (cons (line-beginning-position)
+                               (if (org-capture-get :insert-here)
+                                   (line-beginning-position)
+                                 (org-entry-end-position)))))
+                      ((org-capture-get :target-entry-p)
+                       ;; At a heading, limit search to its body.
+                       (cons (line-beginning-position 2)
+                             (org-entry-end-position)))
+                      (t
+                       ;; Table is not necessarily under a heading.
+                       ;; Search whole buffer.
+                       (cons (point-min) (point-max))))))
+      ;; Find the first plain list in the delimited area.
+      (goto-char beg)
+      (let ((item-regexp (org-item-beginning-re)))
+       (catch :found
+         (while (re-search-forward item-regexp end t)
+           (when (setq item (org-element-lineage
+                             (org-element-at-point) '(plain-list) t))
+             (goto-char (org-element-property (if prepend? :post-affiliated
+                                                :contents-end)
+                                              item))
+             (throw :found t)))
+         ;; No list found.  Move to the location when to insert
+         ;; template.  Skip planning info and properties drawers, if
+         ;; any.
+         (goto-char (cond ((org-capture-get :insert-here) beg)
+                          ((not prepend?) end)
+                          ((org-before-first-heading-p) beg)
+                          (t (max (save-excursion
+                                    (org-end-of-meta-data)
+                                    (point))
+                                  beg)))))))
+    ;; Insert template.
+    (let ((origin (point)))
+      (unless (bolp) (insert "\n"))
+      ;; When a new list is created, always obey to `:empty-lines' and
+      ;; friends.
+      ;;
+      ;; When capturing in an existing list, do not change blank lines
+      ;; above or below the list; consider it to be a stable
+      ;; structure.  However, we can control how many blank lines
+      ;; separate items.  So obey to `:empty-lines' between items as
+      ;; long as it does not insert more than one empty line.  In the
+      ;; specific case of empty lines above, it means we only obey the
+      ;; parameter when appending an item.
+      (unless (and item prepend?)
+       (org-capture-empty-lines-before
+        (and item
+             (not prepend?)
+             (min 1 (or (org-capture-get :empty-lines-before)
+                        (org-capture-get :empty-lines)
+                        0)))))
+      (org-capture-position-for-last-stored (point))
+      (let ((beg (line-beginning-position))
+           (end (progn
+                  (insert (org-trim template) "\n")
+                  (point-marker))))
+       (when item
+         (let ((i (save-excursion
+                    (goto-char (org-element-property :post-affiliated item))
+                    (current-indentation))))
+           (save-excursion
+             (goto-char beg)
+             (save-excursion
+               (while (< (point) end)
+                 (indent-to i)
+                 (forward-line)))
+             ;; Pre-pending an item could change the type of the list
+             ;; if there is a mismatch.  In this situation,
+             ;; prioritize the existing list.
+             (when prepend?
+               (let ((ordered? (eq 'ordered (org-element-property :type 
item))))
+                 (when (org-xor ordered?
+                                (string-match-p "\\`[A-Za-z0-9]\\([.)]\\)"
+                                                template))
+                   (org-cycle-list-bullet (if ordered? "1." "-")))))
+             ;; Eventually repair the list for proper indentation and
+             ;; bullets.
+             (org-list-repair))))
+       ;; Limit number of empty lines.  See above for details.
+       (unless (and item (not prepend?))
+         (org-capture-empty-lines-after
+          (and item
+               prepend?
+               (min 1 (or (org-capture-get :empty-lines-after)
+                          (org-capture-get :empty-lines)
+                          0)))))
+       (org-capture-mark-kill-region origin (point))
+       ;; ITEM always end with a newline character.  Make sure we do
+       ;; not narrow at the beginning of the next line, possibly
+       ;; altering its structure (e.g., when it is a headline).
+       (org-capture-narrow beg (1- end))
+       (when (or (search-backward "%?" beg t)
+                 (search-forward "%?" end t))
+         (replace-match ""))))))
 
 (defun org-capture-place-table-line ()
   "Place the template as a table line."
   (require 'org-table)
-  (let* ((txt (org-capture-get :template))
-        (target-entry-p (org-capture-get :target-entry-p))
-        (table-line-pos (org-capture-get :table-line-pos))
-        beg end)
+  (let ((text
+        (pcase (org-trim (org-capture-get :template))
+          ((pred (string-match-p org-table-border-regexp))
+           "| %?Bad template |")
+          (text (concat text "\n"))))
+       (table-line-pos (org-capture-get :table-line-pos))
+       beg end)
     (cond
      ((org-capture-get :exact-position)
-      (goto-char (org-capture-get :exact-position)))
-     ((not target-entry-p)
-      ;; Table is not necessarily under a heading
+      (org-with-point-at (org-capture-get :exact-position)
+       (setq beg (line-beginning-position))
+       (setq end (if (org-capture-get :insert-here) beg
+                   (org-entry-end-position)))))
+     ((not (org-capture-get :target-entry-p))
+      ;; Table is not necessarily under a heading.  Find first table
+      ;; in the buffer.
       (setq beg (point-min) end (point-max)))
      (t
-      ;; WE are at a heading, limit search to the body
-      (setq beg (1+ (point-at-eol))
-           end (save-excursion (outline-next-heading) (point)))))
-    (if (re-search-forward org-table-dataline-regexp end t)
-       (let ((b (org-table-begin)) (e (org-table-end)) (case-fold-search t))
-         (goto-char e)
-         (if (looking-at "[ \t]*#\\+tblfm:")
-             (forward-line 1))
-         (narrow-to-region b (point)))
+      ;; We are at a heading, limit search to the body.
+      (setq beg (line-beginning-position 2))
+      (setq end (save-excursion (outline-next-heading) (point)))))
+    (goto-char beg)
+    ;; Narrow to the table, possibly creating one if necessary.
+    (catch :found
+      (while (re-search-forward org-table-dataline-regexp end t)
+       (pcase (org-element-lineage (org-element-at-point) '(table) t)
+         (`nil nil)
+         ((pred (lambda (e) (eq 'table.el (org-element-property :type e))))
+          nil)
+         (table
+          (goto-char (org-element-property :contents-end table))
+          (narrow-to-region (org-element-property :post-affiliated table)
+                            (point))
+          (throw :found t))))
+      ;; No table found.  Create it with an empty header.
       (goto-char end)
-      (insert "\n|   |\n|----|\n|    |\n")
-      (narrow-to-region (1+ end) (point)))
-    ;; We are narrowed to the table, or to an empty line if there was no table
-
-    ;; Check if the template is good
-    (if (not (string-match org-table-dataline-regexp txt))
-       (setq txt "| %?Bad template |\n"))
-    (if (functionp table-line-pos)
-       (setq table-line-pos (funcall table-line-pos))
-      (setq table-line-pos (eval table-line-pos)))
+      (unless (bolp) (insert "\n"))
+      (let ((origin (point)))
+       (insert "|   |\n|---|\n")
+       (narrow-to-region origin (point))))
+    ;; In the current table, find the appropriate location for TEXT.
     (cond
+     ((org-capture-get :insert-here) nil)
      ((and table-line-pos
-          (string-match "\\(I+\\)\\([-+][0-9]\\)" table-line-pos))
+          (string-match "\\(I+\\)\\([-+][0-9]+\\)" table-line-pos))
       (goto-char (point-min))
-      ;; we have a complex line specification
-      (let ((ll (ignore-errors
-                 (save-match-data (org-table-analyze))
-                 (aref org-table-hlines
-                       (- (match-end 1) (match-beginning 1)))))
+      (let ((line
+            (condition-case _
+                (progn
+                  (save-match-data (org-table-analyze))
+                  (aref org-table-hlines
+                        (- (match-end 1) (match-beginning 1))))
+              (error
+               (error "Invalid table line specification %S" table-line-pos))))
            (delta (string-to-number (match-string 2 table-line-pos))))
-       ;; The user wants a special position in the table
-       (unless ll
-         (error "Invalid table line specification \"%s\"" table-line-pos))
-       (goto-char org-table-current-begin-pos)
-       (forward-line (+ ll delta (if (< delta 0) 0 -1)))
-       (org-table-insert-row 'below)
-       (beginning-of-line 1)
-       (delete-region (point) (1+ (point-at-eol)))
-       (setq beg (point))
-       (insert txt)
-       (setq end (point))))
+       (forward-line (+ line delta (if (< delta 0) 0 -1)))
+       (forward-line)))                ;insert below
      ((org-capture-get :prepend)
       (goto-char (point-min))
-      (re-search-forward org-table-hline-regexp nil t)
-      (beginning-of-line 1)
-      (re-search-forward org-table-dataline-regexp nil t)
-      (beginning-of-line 1)
-      (setq beg (point))
-      (org-table-insert-row)
-      (beginning-of-line 1)
-      (delete-region (point) (1+ (point-at-eol)))
-      (insert txt)
-      (setq end (point)))
+      (cond
+       ((not (re-search-forward org-table-hline-regexp nil t)))
+       ((re-search-forward org-table-dataline-regexp nil t) 
(beginning-of-line))
+       (t (goto-char (org-table-end)))))
      (t
-      (goto-char (point-max))
-      (re-search-backward org-table-dataline-regexp nil t)
-      (beginning-of-line 1)
-      (org-table-insert-row 'below)
-      (beginning-of-line 1)
-      (delete-region (point) (1+ (point-at-eol)))
-      (setq beg (point))
-      (insert txt)
-      (setq end (point))))
-    (goto-char beg)
-    (org-capture-position-for-last-stored 'table-line)
-    (if (or (re-search-backward "%\\?" beg t)
-           (re-search-forward "%\\?" end t))
-       (replace-match ""))
-    (org-table-align)))
+      (goto-char (org-table-end))))
+    ;; Insert text and position point according to template.
+    (let ((origin (point)))
+      (unless (bolp) (insert "\n"))
+      (let ((beg (point))
+           (end (save-excursion
+                  (insert text)
+                  (point))))
+       (org-capture-position-for-last-stored 'table-line)
+       (org-capture-mark-kill-region origin end)
+       ;; TEXT is guaranteed to end with a newline character.  Ignore
+       ;; it when narrowing so as to not alter data on the next line.
+       (org-capture-narrow beg (1- end))
+       (when (or (search-backward "%?" beg t)
+                 (search-forward "%?" end t))
+         (replace-match ""))))))
 
 (defun org-capture-place-plain-text ()
   "Place the template plainly.
@@ -1292,35 +1363,36 @@ If the target locator points at an Org node, place the 
template into
 the text of the entry, before the first child.  If not, place the
 template at the beginning or end of the file.
 Of course, if exact position has been required, just put it there."
-  (let* ((txt (org-capture-get :template))
-        beg end)
-    (cond
-     ((org-capture-get :exact-position)
-      (goto-char (org-capture-get :exact-position)))
-     ((and (org-capture-get :target-entry-p)
-          (bolp)
-          (looking-at org-outline-regexp))
-      ;; we should place the text into this entry
-      (if (org-capture-get :prepend)
-         ;; Skip meta data and drawers
-         (org-end-of-meta-data t)
-       ;; go to ent of the entry text, before the next headline
-       (outline-next-heading)))
-     (t
-      ;; beginning or end of file
-      (goto-char (if (org-capture-get :prepend) (point-min) (point-max)))))
-    (or (bolp) (newline))
+  (cond
+   ((org-capture-get :exact-position)
+    (goto-char (org-capture-get :exact-position)))
+   ((org-capture-get :target-entry-p)
+    ;; Place the text into this entry.
+    (if (org-capture-get :prepend)
+       ;; Skip meta data and drawers.
+       (org-end-of-meta-data t)
+      ;; Go to end of the entry text, before the next headline.
+      (outline-next-heading)))
+   (t
+    ;; Beginning or end of file.
+    (goto-char (if (org-capture-get :prepend) (point-min) (point-max)))))
+  (let ((origin (point)))
+    (unless (bolp) (insert "\n"))
     (org-capture-empty-lines-before)
-    (setq beg (point))
-    (insert txt)
-    (org-capture-empty-lines-after)
-    (org-capture-position-for-last-stored beg)
-    (setq end (point))
-    (org-capture-mark-kill-region beg (1- end))
-    (org-capture-narrow beg (1- end))
-    (if (or (re-search-backward "%\\?" beg t)
-           (re-search-forward "%\\?" end t))
-       (replace-match ""))))
+    (org-capture-position-for-last-stored (point))
+    (let ((beg (point)))
+      (insert (org-capture-get :template))
+      (unless (bolp) (insert "\n"))
+      ;; Ignore the final newline character so as to not alter data
+      ;; after inserted text.  Yet, if the template is empty, make
+      ;; sure END matches BEG instead of pointing before it.
+      (let ((end (max beg (1- (point)))))
+       (org-capture-empty-lines-after)
+       (org-capture-mark-kill-region origin (point))
+       (org-capture-narrow beg end)
+       (when (or (search-backward "%?" beg t)
+                 (search-forward "%?" end t))
+         (replace-match ""))))))
 
 (defun org-capture-mark-kill-region (beg end)
   "Mark the region that will have to be killed when aborting capture."
@@ -1377,7 +1449,7 @@ Point will be after the empty lines, so insertion can 
directly be done."
   (let ((pos (point)))
     (org-back-over-empty-lines)
     (delete-region (point) pos)
-    (if (> n 0) (newline n))))
+    (when (> n 0) (newline n))))
 
 (defun org-capture-empty-lines-after (&optional n)
   "Set the correct number of empty lines after the inserted string.
@@ -1387,49 +1459,11 @@ Point will remain at the first line after the inserted 
text."
   (org-back-over-empty-lines)
   (while (looking-at "[ \t]*\n") (replace-match ""))
   (let ((pos (point)))
-    (if (> n 0) (newline n))
+    (when (> n 0) (newline n))
     (goto-char pos)))
 
 (defvar org-clock-marker) ; Defined in org.el
 
-(defun org-capture-insert-template-here ()
-  "Insert the capture template at point."
-  (let* ((template (org-capture-get :template))
-        (type  (org-capture-get :type))
-        beg end pp)
-    (unless (bolp) (insert "\n"))
-    (setq beg (point))
-    (cond
-     ((and (eq type 'entry) (derived-mode-p 'org-mode))
-      (org-capture-verify-tree (org-capture-get :template))
-      (org-paste-subtree nil template t))
-     ((and (memq type '(item checkitem))
-          (derived-mode-p 'org-mode)
-          (save-excursion (skip-chars-backward " \t\n")
-                          (setq pp (point))
-                          (org-in-item-p)))
-      (goto-char pp)
-      (org-insert-item)
-      (skip-chars-backward " ")
-      (skip-chars-backward "-+*0123456789).")
-      (delete-region (point) (point-at-eol))
-      (setq beg (point))
-      (org-remove-indentation template)
-      (insert template)
-      (org-capture-empty-lines-after)
-      (goto-char beg)
-      (org-list-repair)
-      (org-end-of-item))
-     (t
-      (insert template)
-      (org-capture-empty-lines-after)
-      (skip-chars-forward " \t\n")
-      (unless (eobp) (beginning-of-line))))
-    (setq end (point))
-    (goto-char beg)
-    (when (re-search-forward "%\\?" end t)
-      (replace-match ""))))
-
 (defun org-capture-set-plist (entry)
   "Initialize the property list from the template definition."
   (setq org-capture-plist (copy-sequence (nthcdr 5 entry)))
@@ -1477,94 +1511,6 @@ Use PREFIX as a prefix for the name of the indirect 
buffer."
   (unless (org-kill-is-subtree-p tree)
     (error "Template is not a valid Org entry or tree")))
 
-(defun org-mks (table title &optional prompt specials)
-  "Select a member of an alist with multiple keys.
-
-TABLE is the alist which should contain entries where the car is a string.
-There should be two types of entries.
-
-1. prefix descriptions like (\"a\" \"Description\")
-   This indicates that `a' is a prefix key for multi-letter selection, and
-   that there are entries following with keys like \"ab\", \"ax\"...
-
-2. Select-able members must have more than two elements, with the first
-   being the string of keys that lead to selecting it, and the second a
-   short description string of the item.
-
-The command will then make a temporary buffer listing all entries
-that can be selected with a single key, and all the single key
-prefixes.  When you press the key for a single-letter entry, it is selected.
-When you press a prefix key, the commands (and maybe further prefixes)
-under this key will be shown and offered for selection.
-
-TITLE will be placed over the selection in the temporary buffer,
-PROMPT will be used when prompting for a key.  SPECIAL is an
-alist with (\"key\" \"description\") entries.  When one of these
-is selected, only the bare key is returned."
-  (save-window-excursion
-    (let ((inhibit-quit t)
-         (buffer (org-switch-to-buffer-other-window "*Org Select*"))
-         (prompt (or prompt "Select: "))
-         current)
-      (unwind-protect
-         (catch 'exit
-           (while t
-             (erase-buffer)
-             (insert title "\n\n")
-             (let ((des-keys nil)
-                   (allowed-keys '("\C-g"))
-                   (cursor-type nil))
-               ;; Populate allowed keys and descriptions keys
-               ;; available with CURRENT selector.
-               (let ((re (format "\\`%s\\(.\\)\\'"
-                                 (if current (regexp-quote current) "")))
-                     (prefix (if current (concat current " ") "")))
-                 (dolist (entry table)
-                   (pcase entry
-                     ;; Description.
-                     (`(,(and key (pred (string-match re))) ,desc)
-                      (let ((k (match-string 1 key)))
-                        (push k des-keys)
-                        (push k allowed-keys)
-                        (insert prefix "[" k "]" "..." "  " desc "..." "\n")))
-                     ;; Usable entry.
-                     (`(,(and key (pred (string-match re))) ,desc . ,_)
-                      (let ((k (match-string 1 key)))
-                        (insert prefix "[" k "]" "     " desc "\n")
-                        (push k allowed-keys)))
-                     (_ nil))))
-               ;; Insert special entries, if any.
-               (when specials
-                 (insert "----------------------------------------------------\
----------------------------\n")
-                 (pcase-dolist (`(,key ,description) specials)
-                   (insert (format "[%s]     %s\n" key description))
-                   (push key allowed-keys)))
-               ;; Display UI and let user select an entry or
-               ;; a sub-level prefix.
-               (goto-char (point-min))
-               (unless (pos-visible-in-window-p (point-max))
-                 (org-fit-window-to-buffer))
-               (message prompt)
-               (let ((pressed (char-to-string (read-char-exclusive))))
-                 (while (not (member pressed allowed-keys))
-                   (message "Invalid key `%s'" pressed) (sit-for 1)
-                   (message prompt)
-                   (setq pressed (char-to-string (read-char-exclusive))))
-                 (setq current (concat current pressed))
-                 (cond
-                  ((equal pressed "\C-g") (user-error "Abort"))
-                  ;; Selection is a prefix: open a new menu.
-                  ((member pressed des-keys))
-                  ;; Selection matches an association: return it.
-                  ((let ((entry (assoc current table)))
-                     (and entry (throw 'exit entry))))
-                  ;; Selection matches a special entry: return the
-                  ;; selection prefix.
-                  ((assoc current specials) (throw 'exit current))
-                  (t (error "No entry available")))))))
-       (when buffer (kill-buffer buffer))))))
-
 ;;; The template code
 (defun org-capture-select-template (&optional keys)
   "Select a capture template.
@@ -1605,7 +1551,8 @@ The template may still contain \"%?\" for cursor 
positioning."
         (v-c (and kill-ring (current-kill 0)))
         (v-x (or (org-get-x-clipboard 'PRIMARY)
                  (org-get-x-clipboard 'CLIPBOARD)
-                 (org-get-x-clipboard 'SECONDARY)))
+                 (org-get-x-clipboard 'SECONDARY)
+                 ""))                  ;ensure it is a string
         ;; `initial' and `annotation' might have been passed.  But if
         ;; the property list has them, we prefer those values.
         (v-i (or (plist-get org-store-link-plist :initial)
@@ -1624,14 +1571,14 @@ The template may still contain \"%?\" for cursor 
positioning."
                  (replace-match "[[\\1][%^{Link description}]]" nil nil v-a)
                v-a))
         (v-l (if (and v-a (string-match l-re v-a))
-                 (replace-match "\\1" nil nil v-a)
+                 (replace-match "[[\\1]]" nil nil v-a)
                v-a))
         (v-n user-full-name)
         (v-k (if (marker-buffer org-clock-marker)
                  (org-no-properties org-clock-heading)
                ""))
         (v-K (if (marker-buffer org-clock-marker)
-                 (org-make-link-string
+                 (org-link-make-string
                   (format "%s::*%s"
                           (buffer-file-name (marker-buffer org-clock-marker))
                           v-k)
@@ -1646,10 +1593,8 @@ The template may still contain \"%?\" for cursor 
positioning."
                      (org-get-x-clipboard 'CLIPBOARD)
                      (org-get-x-clipboard 'SECONDARY)
                      v-c))))
-
     (setq org-store-link-plist (plist-put org-store-link-plist :annotation 
v-a))
     (setq org-store-link-plist (plist-put org-store-link-plist :initial v-i))
-
     (unless template
       (setq template "")
       (message "no template") (ding)
@@ -1661,7 +1606,6 @@ The template may still contain \"%?\" for cursor 
positioning."
       (setq mark-active nil)
       (insert template)
       (goto-char (point-min))
-
       ;; %[] insert contents of a file.
       (save-excursion
        (while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
@@ -1678,10 +1622,8 @@ The template may still contain \"%?\" for cursor 
positioning."
                 (insert (format "%%![couldn not insert %s: %s]"
                                 filename
                                 error))))))))
-
       ;; Mark %() embedded elisp for later evaluation.
       (org-capture-expand-embedded-elisp 'mark)
-
       ;; Expand non-interactive templates.
       (let ((regexp 
"%\\(:[-A-Za-z]+\\|<\\([^>\n]+\\)>\\|[aAcfFikKlntTuUx]\\)"))
        (save-excursion
@@ -1709,11 +1651,9 @@ The template may still contain \"%?\" for cursor 
positioning."
                             ;; Outside embedded Lisp, repeat leading
                             ;; characters before initial place holder
                             ;; every line.
-                            (let ((lead (buffer-substring-no-properties
-                                         (line-beginning-position) (point))))
-                              (replace-regexp-in-string "\n\\(.\\)"
-                                                        (concat lead "\\1")
-                                                        v-i nil nil 1))))
+                            (let ((lead (concat "\n"
+                                                (org-current-line-string t))))
+                              (replace-regexp-in-string "\n" lead v-i nil t))))
                          (?a v-a)
                          (?A v-A)
                          (?c v-c)
@@ -1733,10 +1673,8 @@ The template may still contain \"%?\" for cursor 
positioning."
                       ;; Escape sensitive characters.
                       (replace-regexp-in-string "[\\\"]" "\\\\\\&" replacement)
                     replacement))))))))
-
       ;; Expand %() embedded Elisp.  Limit to Sexp originally marked.
       (org-capture-expand-embedded-elisp)
-
       ;; Expand interactive templates.  This is the last step so that
       ;; template is mostly expanded when prompting happens.  Turn on
       ;; Org mode and set local variables.  This is to support
@@ -1782,9 +1720,7 @@ The template may still contain \"%?\" for cursor 
positioning."
                         (unless (eq (char-before) ?:) (insert ":"))
                         (insert ins)
                         (unless (eq (char-after) ?:) (insert ":"))
-                        (and (org-at-heading-p)
-                             (let ((org-ignore-region t))
-                               (org-set-tags nil 'align))))))
+                        (when (org-at-heading-p) (org-align-tags)))))
                    ((or "C" "L")
                     (let ((insert-fun (if (equal key "C") #'insert
                                         (lambda (s) (org-insert-link 0 s)))))
@@ -1799,7 +1735,36 @@ The template may still contain \"%?\" for cursor 
positioning."
                                                first-value)))
                         (_ (error "Invalid `org-capture--clipboards' value: %S"
                                   org-capture--clipboards)))))
-                   ("p" (org-set-property prompt nil))
+                   ("p"
+                    ;; We remove file properties inherited from
+                    ;; target buffer so `org-read-property-value' has
+                    ;; a chance to find allowed values in sub-trees
+                    ;; from the target buffer.
+                    (setq-local org-file-properties nil)
+                    (let* ((origin (set-marker (make-marker)
+                                               (org-capture-get :pos)
+                                               (org-capture-get :buffer)))
+                           ;; Find location from where to get allowed
+                           ;; values.  If `:target-entry-p' is
+                           ;; non-nil, the current headline in the
+                           ;; target buffer is going to be a parent
+                           ;; headline, so location is fine.
+                           ;; Otherwise, find the parent headline in
+                           ;; the target buffer.
+                           (pom (if (org-capture-get :target-entry-p) origin
+                                  (let ((level (progn
+                                                 (while (org-up-heading-safe))
+                                                 (org-current-level))))
+                                    (org-with-point-at origin
+                                      (let ((l (if (org-at-heading-p)
+                                                   (org-current-level)
+                                                 most-positive-fixnum)))
+                                        (while (and l (>= l level))
+                                          (setq l (org-up-heading-safe)))
+                                        (if l (point-marker)
+                                          (point-min-marker)))))))
+                           (value (org-read-property-value prompt pom)))
+                      (org-set-property prompt value)))
                    ((or "t" "T" "u" "U")
                     ;; These are the date/time related ones.
                     (let* ((upcase? (equal (upcase key) key))
@@ -1827,7 +1792,6 @@ The template may still contain \"%?\" for cursor 
positioning."
                    (_
                     (error "Unknown template placeholder: \"%%^%s\""
                            key))))))))
-
        ;; Replace %n escapes with nth %^{...} string.
        (setq strings (nreverse strings))
        (save-excursion
@@ -1836,16 +1800,16 @@ The template may still contain \"%?\" for cursor 
positioning."
              (replace-match
               (nth (1- (string-to-number (match-string 1))) strings)
               nil t)))))
-
       ;; Make sure there are no empty lines before the text, and that
-      ;; it ends with a newline character.
+      ;; it ends with a newline character or it is empty.
       (skip-chars-forward " \t\n")
       (delete-region (point-min) (line-beginning-position))
       (goto-char (point-max))
       (skip-chars-backward " \t\n")
-      (delete-region (point) (point-max))
-      (insert "\n")
-
+      (if (bobp) (delete-region (point) (line-end-position))
+       (end-of-line)
+       (delete-region (point) (point-max))
+       (insert "\n"))
       ;; Return the expanded template and kill the capture buffer.
       (untabify (point-min) (point-max))
       (set-buffer-modified-p nil)
@@ -1952,9 +1916,9 @@ Assume sexps have been marked with
                 (setq jump-to-captured t))
 
               (append (list key desc type target template)
-                      (if prepend '(:prepend t))
-                      (if immediate '(:immediate-finish t))
-                      (if jump-to-captured '(:jump-to-captured t)))))
+                      (and prepend '(:prepend t))
+                      (and immediate '(:immediate-finish t))
+                      (and jump-to-captured '(:jump-to-captured t)))))
 
           org-remember-templates))))
 
diff --git a/lisp/org/org-clock.el b/lisp/org/org-clock.el
index 9046661..df4ba62 100644
--- a/lisp/org/org-clock.el
+++ b/lisp/org/org-clock.el
@@ -35,12 +35,17 @@
 (declare-function notifications-notify "notifications" (&rest params))
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-link-display-format "ol" (s))
+(declare-function org-link-heading-search-string "ol" (&optional string))
+(declare-function org-link-make-string "ol" (link &optional description))
 (declare-function org-table-goto-line "org-table" (n))
+(declare-function org-dynamic-block-define "org" (type func))
 
-(defvar org-frame-title-format-backup frame-title-format)
+(defvar org-frame-title-format-backup nil)
+(defvar org-state)
+(defvar org-link-bracket-re)
 (defvar org-time-stamp-formats)
 
-
 (defgroup org-clock nil
   "Options concerning clocking working time in Org mode."
   :tag "Org Clock"
@@ -156,7 +161,10 @@ state to switch it to."
          (symbol :tag "Function")))
 
 (defcustom org-clock-history-length 5
-  "Number of clock tasks to remember in history."
+  "Number of clock tasks to remember in history.
+Clocking in using history works best if this is at most 35, in
+which case all digits and capital letters are used up by the
+*Clock Task Select* buffer."
   :group 'org-clock
   :type 'integer)
 
@@ -294,10 +302,12 @@ string as argument."
    :stepskip0 nil
    :fileskip0 nil
    :tags nil
+   :match nil
    :emphasize nil
    :link nil
    :narrow '40!
    :indent t
+   :hidefiles nil
    :formula nil
    :timestamp nil
    :level nil
@@ -328,11 +338,12 @@ For more information, see `org-clocktable-write-default'."
   :version "24.1"
   :type 'alist)
 
-(defcustom org-clock-clocktable-default-properties '(:maxlevel 2 :scope file)
+(defcustom org-clock-clocktable-default-properties '(:maxlevel 2)
   "Default properties for new clocktables.
 These will be inserted into the BEGIN line, to make it easy for users to
 play with them."
   :group 'org-clocktable
+  :package-version '(Org . "9.2")
   :type 'plist)
 
 (defcustom org-clock-idle-time nil
@@ -518,8 +529,7 @@ cannot be translated."
   (cond ((functionp org-clock-heading-function)
         (funcall org-clock-heading-function))
        ((org-before-first-heading-p) "???")
-       (t (replace-regexp-in-string
-           org-bracket-link-analytic-regexp "\\5"
+       (t (org-link-display-format
            (org-no-properties (org-get-heading t t t t))))))
 
 (defun org-clock-menu ()
@@ -533,7 +543,7 @@ cannot be translated."
 
 (defun org-clock-history-push (&optional pos buffer)
   "Push a marker to the clock history."
-  (setq org-clock-history-length (max 1 (min 35 org-clock-history-length)))
+  (setq org-clock-history-length (max 1 org-clock-history-length))
   (let ((m (move-marker (make-marker)
                        (or pos (point)) (org-base-buffer
                                          (or buffer (current-buffer)))))
@@ -723,7 +733,8 @@ menu\nmouse-2 will jump to task"))
 The time returned includes the time spent on this task in
 previous clocking intervals."
   (let ((currently-clocked-time
-        (floor (time-convert (time-since org-clock-start-time) 'integer)
+        (floor (org-time-convert-to-integer
+                (org-time-since org-clock-start-time))
                60)))
     (+ currently-clocked-time (or org-clock-total-time 0))))
 
@@ -732,8 +743,8 @@ previous clocking intervals."
 VALUE can be a number of minutes, or a string with format hh:mm or mm.
 When the string starts with a + or a - sign, the current value of the effort
 property will be changed by that amount.  If the effort value is expressed
-as an `org-effort-durations' (e.g. \"3h\"), the modified value will be
-converted to a hh:mm duration.
+as an unit defined in `org-duration-units' (e.g. \"3h\"), the modified
+value will be converted to a hh:mm duration.
 
 This command will update the \"Effort\" property of the currently
 clocked item, and the value displayed in the mode line."
@@ -913,47 +924,52 @@ If necessary, clock-out of the currently active clock."
 (defvar org-clock-resolving-clocks nil)
 (defvar org-clock-resolving-clocks-due-to-idleness nil)
 
-(defun org-clock-resolve-clock (clock resolve-to clock-out-time
-                                     &optional close-p restart-p fail-quietly)
-  "Resolve `CLOCK' given the time `RESOLVE-TO', and the present.
-`CLOCK' is a cons cell of the form (MARKER START-TIME)."
-  (let ((org-clock-resolving-clocks t))
-    (cond
-     ((null resolve-to)
-      (org-clock-clock-cancel clock)
-      (if (and restart-p (not org-clock-clocking-in))
-         (org-clock-clock-in clock)))
-
-     ((eq resolve-to 'now)
-      (if restart-p
-         (error "RESTART-P is not valid here"))
-      (if (or close-p org-clock-clocking-in)
-         (org-clock-clock-out clock fail-quietly)
-       (unless (org-is-active-clock clock)
-         (org-clock-clock-in clock t))))
-
-     ((not (time-less-p resolve-to nil))
-      (error "RESOLVE-TO must refer to a time in the past"))
-
-     (t
-      (if restart-p
-         (error "RESTART-P is not valid here"))
-      (org-clock-clock-out clock fail-quietly (or clock-out-time
-                                                 resolve-to))
-      (unless org-clock-clocking-in
-       (if close-p
-           (setq org-clock-leftover-time (and (null clock-out-time)
-                                              resolve-to))
-         (org-clock-clock-in clock nil (and clock-out-time
-                                            resolve-to))))))))
+(defun org-clock-resolve-clock
+    (clock resolve-to clock-out-time close restart fail-quietly)
+  "Resolve CLOCK given the time RESOLVE-TO, and the present.
+CLOCK is a cons cell of the form (MARKER START-TIME)."
+  (let ((org-clock-resolving-clocks t)
+       ;; If the clocked entry contained only a clock and possibly
+       ;; the associated drawer, and we either cancel it or clock it
+       ;; out, `org-clock-out-remove-zero-time-clocks' may clear all
+       ;; contents, and leave point on the /next/ headline.  We store
+       ;; the current entry location to be able to get back here when
+       ;; we need to clock in again the previously clocked task.
+       (heading (org-with-point-at (car clock)
+                  (org-back-to-heading t)
+                  (point-marker))))
+    (pcase resolve-to
+      (`nil
+       (org-clock-clock-cancel clock)
+       (when (and restart (not org-clock-clocking-in))
+        (org-with-point-at heading (org-clock-in))))
+      (`now
+       (cond
+       (restart (error "RESTART is not valid here"))
+       ((or close org-clock-clocking-in)
+        (org-clock-clock-out clock fail-quietly))
+       ((org-is-active-clock clock) nil)
+       (t (org-clock-clock-in clock t))))
+      ((pred (org-time-less-p nil))
+       (error "RESOLVE-TO must refer to a time in the past"))
+      (_
+       (when restart (error "RESTART is not valid here"))
+       (org-clock-clock-out clock fail-quietly (or clock-out-time resolve-to))
+       (cond
+       (org-clock-clocking-in nil)
+       (close
+        (setq org-clock-leftover-time (and (null clock-out-time) resolve-to)))
+       (t
+        (org-with-point-at heading
+          (org-clock-in nil (and clock-out-time resolve-to)))))))))
 
 (defun org-clock-jump-to-current-clock (&optional effective-clock)
-  (interactive)
+  "When an Org clock is running, jump to it."
   (let ((drawer (org-clock-into-drawer))
        (clock (or effective-clock (cons org-clock-marker
                                         org-clock-start-time))))
     (unless (marker-buffer (car clock))
-      (error "No clock is currently running"))
+      (user-error "No Org clock is currently running"))
     (org-with-clock clock (org-clock-goto))
     (with-current-buffer (marker-buffer (car clock))
       (goto-char (car clock))
@@ -1033,7 +1049,7 @@ to be CLOCKED OUT."))))
                                   nil 45)))
                (and (not (memq char-pressed '(?i ?q))) char-pressed)))))
         (default
-          (floor (time-convert (time-since last-valid) 'integer)
+          (floor (org-time-convert-to-integer (org-time-since last-valid))
                  60))
         (keep
          (and (memq ch '(?k ?K))
@@ -1042,8 +1058,8 @@ to be CLOCKED OUT."))))
          (and (memq ch '(?g ?G))
               (read-number "Got back how many minutes ago? " default)))
         (subtractp (memq ch '(?s ?S)))
-        (barely-started-p (time-less-p
-                           (time-subtract last-valid (cdr clock))
+        (barely-started-p (org-time-less-p
+                           (org-time-subtract last-valid (cdr clock))
                            45))
         (start-over (and subtractp barely-started-p)))
     (cond
@@ -1070,9 +1086,9 @@ to be CLOCKED OUT."))))
                   (and gotback (= gotback default)))
               'now)
              (keep
-              (time-add last-valid (* 60 keep)))
+              (org-time-add last-valid (* 60 keep)))
              (gotback
-              (time-since (* 60 gotback)))
+              (org-time-since (* 60 gotback)))
              (t
               (error "Unexpected, please report this as a bug")))
        (and gotback last-valid)
@@ -1102,9 +1118,9 @@ If `only-dangling-p' is non-nil, only ask to resolve 
dangling
                        (lambda (clock)
                          (format
                           "Dangling clock started %d mins ago"
-                          (floor (time-convert (time-since (cdr clock))
-                                               'integer)
-                                 60)))))
+                          (floor (org-time-convert-to-integer
+                                   (org-time-since (cdr clock)))
+                                  60)))))
                   (or last-valid
                       (cdr clock)))))))))))
 
@@ -1154,7 +1170,7 @@ so long."
             org-clock-marker (marker-buffer org-clock-marker))
     (let* ((org-clock-user-idle-seconds (org-user-idle-seconds))
           (org-clock-user-idle-start
-           (time-since org-clock-user-idle-seconds))
+           (org-time-since org-clock-user-idle-seconds))
           (org-clock-resolving-clocks-due-to-idleness t))
       (if (> org-clock-user-idle-seconds (* 60 org-clock-idle-time))
          (org-clock-resolve
@@ -1216,33 +1232,27 @@ the default behavior."
          (throw 'abort nil)))
 
       (when (equal select '(4))
-       (setq selected-task (org-clock-select-task "Clock-in on task: "))
-       (if selected-task
-           (setq selected-task (copy-marker selected-task))
-         (error "Abort")))
+       (pcase (org-clock-select-task "Clock-in on task: ")
+         (`nil (error "Abort"))
+         (task (setq selected-task (copy-marker task)))))
 
       (when (equal select '(16))
        ;; Mark as default clocking task
        (org-clock-mark-default-task))
 
       (when interrupting
-       ;; We are interrupting the clocking of a different task.
-       ;; Save a marker to this task, so that we can go back.
-       ;; First check if we are trying to clock into the same task!
-       (when (save-excursion
-               (unless selected-task
-                 (org-back-to-heading t))
-               (and (equal (marker-buffer org-clock-hd-marker)
-                           (if selected-task
-                               (marker-buffer selected-task)
-                             (current-buffer)))
-                    (= (marker-position org-clock-hd-marker)
-                       (if selected-task
-                           (marker-position selected-task)
-                         (point)))
-                    (equal org-clock-current-task (nth 4 
(org-heading-components)))))
-         (message "Clock continues in \"%s\"" org-clock-heading)
-         (throw 'abort nil))
+       ;; We are interrupting the clocking of a different task.  Save
+       ;; a marker to this task, so that we can go back.  First check
+       ;; if we are trying to clock into the same task!
+       (when (or selected-task (derived-mode-p 'org-mode))
+         (org-with-point-at selected-task
+           (unless selected-task (org-back-to-heading t))
+           (when (and (eq (marker-buffer org-clock-hd-marker)
+                          (org-base-buffer (current-buffer)))
+                      (= (point) (marker-position org-clock-hd-marker))
+                      (equal org-clock-current-task (org-get-heading t t t t)))
+             (message "Clock continues in %S" org-clock-heading)
+             (throw 'abort nil))))
        (move-marker org-clock-interrupted-task
                     (marker-position org-clock-marker)
                     (marker-buffer org-clock-marker))
@@ -1267,7 +1277,7 @@ the default behavior."
         (or interrupting (move-marker org-clock-interrupted-task nil))
         (run-hooks 'org-clock-in-prepare-hook)
         (org-clock-history-push)
-        (setq org-clock-current-task (nth 4 (org-heading-components)))
+        (setq org-clock-current-task (org-get-heading t t t t))
         (cond ((functionp org-clock-in-switch-to-state)
                (let ((case-fold-search nil))
                  (looking-at org-complex-heading-regexp))
@@ -1310,7 +1320,7 @@ the default behavior."
                        (end-of-line 0)
                        (org-in-item-p)))
             (beginning-of-line 1)
-            (indent-line-to (- (org-get-indentation) 2)))
+            (indent-line-to (- (current-indentation) 2)))
           (insert org-clock-string " ")
           (setq org-clock-effort (org-entry-get (point) org-effort-property))
           (setq org-clock-total-time (org-clock-sum-current-item
@@ -1321,11 +1331,10 @@ the default behavior."
                          (y-or-n-p
                           (format
                            "You stopped another clock %d mins ago; start this 
one from then? "
-                           (/ (time-convert
-                               (time-subtract
+                           (/ (org-time-convert-to-integer
+                               (org-time-subtract
                                 (org-current-time org-clock-rounding-minutes t)
-                                leftover)
-                               'integer)
+                                leftover))
                               60)))
                          leftover)
                     start-time
@@ -1347,6 +1356,7 @@ the default behavior."
         ;; add to frame title
         (when (or (eq org-clock-clocked-in-display 'frame-title)
                   (eq org-clock-clocked-in-display 'both))
+          (setq org-frame-title-format-backup frame-title-format)
           (setq frame-title-format org-clock-frame-title-format))
         (org-clock-update-mode-line)
         (when org-clock-mode-line-timer
@@ -1501,9 +1511,9 @@ line and position cursor in that line."
            (let ((beg (point)))
              (insert ":" drawer ":\n:END:\n")
              (org-indent-region beg (point))
-             (goto-char beg)
-             (org-flag-drawer t)
-             (forward-line))))
+             (org-flag-region
+              (line-end-position -1) (1- (point)) t 'org-hide-drawer)
+             (forward-line -1))))
         ;; When a clock drawer needs to be created because of the
         ;; number of clock items or simply if it is missing, collect
         ;; all clocks in the section and wrap them within the drawer.
@@ -1527,7 +1537,7 @@ line and position cursor in that line."
            (let ((end (point-marker)))
              (goto-char beg)
              (save-excursion (insert ":" drawer ":\n"))
-             (org-flag-drawer t)
+             (org-flag-region (line-end-position) (1- end) t 'org-hide-drawer)
              (org-indent-region (point) end)
              (forward-line)
              (unless org-log-states-order-reversed
@@ -1537,6 +1547,14 @@ line and position cursor in that line."
         (org-log-states-order-reversed (goto-char (car (last positions))))
         (t (goto-char (car positions))))))))
 
+(defun org-clock-restore-frame-title-format ()
+  "Restore `frame-title-format' from `org-frame-title-format-backup'.
+`frame-title-format' is restored if `org-frame-title-format-backup' is not nil
+and current `frame-title-format' is equal to `org-clock-frame-title-format'."
+  (when (and org-frame-title-format-backup
+            (equal frame-title-format org-clock-frame-title-format))
+    (setq frame-title-format org-frame-title-format-backup)))
+
 ;;;###autoload
 (defun org-clock-out (&optional switch-to-state fail-quietly at-time)
   "Stop the currently running clock.
@@ -1548,7 +1566,7 @@ to, overriding the existing value of 
`org-clock-out-switch-to-state'."
     (when (not (org-clocking-p))
       (setq global-mode-string
            (delq 'org-mode-line-string global-mode-string))
-      (setq frame-title-format org-frame-title-format-backup)
+      (org-clock-restore-frame-title-format)
       (force-mode-line-update)
       (if fail-quietly (throw 'exit t) (user-error "No active clock")))
     (let ((org-clock-out-switch-to-state
@@ -1576,10 +1594,10 @@ to, overriding the existing value of 
`org-clock-out-switch-to-state'."
          (delete-region (point) (point-at-eol))
          (insert "--")
          (setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
-         (setq s (time-convert (time-subtract
-                                (org-time-string-to-time te)
-                                (org-time-string-to-time ts))
-                               'integer)
+         (setq s (org-time-convert-to-integer
+                  (time-subtract
+                   (org-time-string-to-time te)
+                   (org-time-string-to-time ts)))
                h (floor s 3600)
                m (floor (mod s 3600) 60))
          (insert " => " (format "%2d:%02d" h m))
@@ -1604,7 +1622,7 @@ to, overriding the existing value of 
`org-clock-out-switch-to-state'."
            (setq org-clock-idle-timer nil))
          (setq global-mode-string
                (delq 'org-mode-line-string global-mode-string))
-         (setq frame-title-format org-frame-title-format-backup)
+         (org-clock-restore-frame-title-format)
          (when org-clock-out-switch-to-state
            (save-excursion
              (org-back-to-heading t)
@@ -1704,7 +1722,7 @@ Optional argument N tells to change by that many units."
   (when (not (org-clocking-p))
     (setq global-mode-string
          (delq 'org-mode-line-string global-mode-string))
-    (setq frame-title-format org-frame-title-format-backup)
+    (org-clock-restore-frame-title-format)
     (force-mode-line-update)
     (error "No active clock"))
   (save-excursion    ; Do not replace this with `with-current-buffer'.
@@ -1718,9 +1736,10 @@ Optional argument N tells to change by that many units."
       (sit-for 2)))
   (move-marker org-clock-marker nil)
   (move-marker org-clock-hd-marker nil)
+  (setq org-clock-current-task nil)
   (setq global-mode-string
        (delq 'org-mode-line-string global-mode-string))
-  (setq frame-title-format org-frame-title-format-backup)
+  (org-clock-restore-frame-title-format)
   (force-mode-line-update)
   (message "Clock canceled")
   (run-hooks 'org-clock-cancel-hook))
@@ -1747,7 +1766,6 @@ With prefix arg SELECT, offer recently clocked tasks for 
selection."
     (goto-char m)
     (org-show-entry)
     (org-back-to-heading t)
-    (org-cycle-hide-drawers 'children)
     (recenter org-clock-goto-before-context)
     (org-reveal)
     (if recent
@@ -1786,88 +1804,87 @@ HEADLINE-FILTER is a zero-arg function that, if 
specified, is called for
 each headline in the time range with point at the headline.  Headlines for
 which HEADLINE-FILTER returns nil are excluded from the clock summation.
 PROPNAME lets you set a custom text property instead of :org-clock-minutes."
-  (org-with-silent-modifications
-   (let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
-                     org-clock-string
-                     "[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ 
\t]+\\([0-9]+\\):\\([0-9]+\\)\\)"))
-         (lmax 30)
-         (ltimes (make-vector lmax 0))
-         (level 0)
-         (tstart (cond ((stringp tstart) (org-time-string-to-seconds tstart))
-                       ((consp tstart) (float-time tstart))
-                       (t tstart)))
-         (tend (cond ((stringp tend) (org-time-string-to-seconds tend))
-                     ((consp tend) (float-time tend))
-                     (t tend)))
-         (t1 0)
-         time)
-     (remove-text-properties (point-min) (point-max)
-                            `(,(or propname :org-clock-minutes) t
-                              :org-clock-force-headline-inclusion t))
-     (save-excursion
-       (goto-char (point-max))
-       (while (re-search-backward re nil t)
-        (cond
-         ((match-end 2)
-          ;; Two time stamps.
-          (let* ((ts (float-time
-                      (encode-time
-                       (save-match-data
-                         (org-parse-time-string (match-string 2))))))
-                 (te (float-time
-                      (encode-time
-                       (org-parse-time-string (match-string 3)))))
-                 (dt (- (if tend (min te tend) te)
-                        (if tstart (max ts tstart) ts))))
-            (when (> dt 0) (cl-incf t1 (floor dt 60)))))
-         ((match-end 4)
-          ;; A naked time.
-          (setq t1 (+ t1 (string-to-number (match-string 5))
-                      (* 60 (string-to-number (match-string 4))))))
-         (t     ;A headline
-          ;; Add the currently clocking item time to the total.
-          (when (and org-clock-report-include-clocking-task
-                     (eq (org-clocking-buffer) (current-buffer))
-                     (eq (marker-position org-clock-hd-marker) (point))
-                     tstart
-                     tend
-                     (>= (float-time org-clock-start-time) tstart)
-                     (<= (float-time org-clock-start-time) tend))
-            (let ((time (floor (time-convert
-                                (time-since org-clock-start-time)
-                                'integer)
-                               60)))
-              (setq t1 (+ t1 time))))
-          (let* ((headline-forced
-                  (get-text-property (point)
-                                     :org-clock-force-headline-inclusion))
-                 (headline-included
-                  (or (null headline-filter)
-                      (save-excursion
-                        (save-match-data (funcall headline-filter))))))
-            (setq level (- (match-end 1) (match-beginning 1)))
-            (when (>= level lmax)
-              (setq ltimes (vconcat ltimes (make-vector lmax 0)) lmax (* 2 
lmax)))
-            (when (or (> t1 0) (> (aref ltimes level) 0))
-              (when (or headline-included headline-forced)
-                (if headline-included
-                    (cl-loop for l from 0 to level do
-                             (aset ltimes l (+ (aref ltimes l) t1))))
-                (setq time (aref ltimes level))
-                (goto-char (match-beginning 0))
-                (put-text-property (point) (point-at-eol)
-                                   (or propname :org-clock-minutes) time)
-                (when headline-filter
-                  (save-excursion
-                    (save-match-data
-                      (while (org-up-heading-safe)
-                        (put-text-property
-                         (point) (line-end-position)
-                         :org-clock-force-headline-inclusion t))))))
-              (setq t1 0)
-              (cl-loop for l from level to (1- lmax) do
-                       (aset ltimes l 0)))))))
-       (setq org-clock-file-total-minutes (aref ltimes 0))))))
+  (with-silent-modifications
+    (let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
+                      org-clock-string
+                      "[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ 
\t]+\\([0-9]+\\):\\([0-9]+\\)\\)"))
+          (lmax 30)
+          (ltimes (make-vector lmax 0))
+          (level 0)
+          (tstart (cond ((stringp tstart) (org-time-string-to-seconds tstart))
+                        ((consp tstart) (float-time tstart))
+                        (t tstart)))
+          (tend (cond ((stringp tend) (org-time-string-to-seconds tend))
+                      ((consp tend) (float-time tend))
+                      (t tend)))
+          (t1 0)
+          time)
+      (remove-text-properties (point-min) (point-max)
+                             `(,(or propname :org-clock-minutes) t
+                               :org-clock-force-headline-inclusion t))
+      (save-excursion
+       (goto-char (point-max))
+       (while (re-search-backward re nil t)
+         (cond
+          ((match-end 2)
+           ;; Two time stamps.
+           (let* ((ts (float-time
+                       (apply #'encode-time
+                              (save-match-data
+                                (org-parse-time-string (match-string 2))))))
+                  (te (float-time
+                       (apply #'encode-time
+                              (org-parse-time-string (match-string 3)))))
+                  (dt (- (if tend (min te tend) te)
+                         (if tstart (max ts tstart) ts))))
+             (when (> dt 0) (cl-incf t1 (floor dt 60)))))
+          ((match-end 4)
+           ;; A naked time.
+           (setq t1 (+ t1 (string-to-number (match-string 5))
+                       (* 60 (string-to-number (match-string 4))))))
+          (t    ;A headline
+           ;; Add the currently clocking item time to the total.
+           (when (and org-clock-report-include-clocking-task
+                      (eq (org-clocking-buffer) (current-buffer))
+                      (eq (marker-position org-clock-hd-marker) (point))
+                      tstart
+                      tend
+                      (>= (float-time org-clock-start-time) tstart)
+                      (<= (float-time org-clock-start-time) tend))
+             (let ((time (floor (org-time-convert-to-integer
+                                 (org-time-since org-clock-start-time))
+                                60)))
+               (setq t1 (+ t1 time))))
+           (let* ((headline-forced
+                   (get-text-property (point)
+                                      :org-clock-force-headline-inclusion))
+                  (headline-included
+                   (or (null headline-filter)
+                       (save-excursion
+                         (save-match-data (funcall headline-filter))))))
+             (setq level (- (match-end 1) (match-beginning 1)))
+             (when (>= level lmax)
+               (setq ltimes (vconcat ltimes (make-vector lmax 0)) lmax (* 2 
lmax)))
+             (when (or (> t1 0) (> (aref ltimes level) 0))
+               (when (or headline-included headline-forced)
+                 (if headline-included
+                     (cl-loop for l from 0 to level do
+                              (aset ltimes l (+ (aref ltimes l) t1))))
+                 (setq time (aref ltimes level))
+                 (goto-char (match-beginning 0))
+                 (put-text-property (point) (point-at-eol)
+                                    (or propname :org-clock-minutes) time)
+                 (when headline-filter
+                   (save-excursion
+                     (save-match-data
+                       (while (org-up-heading-safe)
+                         (put-text-property
+                          (point) (line-end-position)
+                          :org-clock-force-headline-inclusion t))))))
+               (setq t1 0)
+               (cl-loop for l from level to (1- lmax) do
+                        (aset ltimes l 0)))))))
+       (setq org-clock-file-total-minutes (aref ltimes 0))))))
 
 (defun org-clock-sum-current-item (&optional tstart)
   "Return time, clocked on current item in total."
@@ -1939,29 +1956,28 @@ Use `\\[org-clock-remove-overlays]' to remove the 
subtree times."
 (defvar-local org-clock-overlays nil)
 
 (defun org-clock-put-overlay (time)
-  "Put an overlays on the current line, displaying TIME.
-This creates a new overlay and stores it in `org-clock-overlays', so that it
-will be easy to remove."
-  (let (ov tx)
-    (beginning-of-line)
-    (let ((case-fold-search nil))
-      (when (looking-at org-complex-heading-regexp)
-       (goto-char (match-beginning 4))))
-    (setq ov (make-overlay (point) (point-at-eol))
-         tx (concat (buffer-substring-no-properties (point) (match-end 4))
-                    (org-add-props
-                        (make-string
-                         (max 0 (- (- 60 (current-column))
-                                   (- (match-end 4) (match-beginning 4))
-                                   (length (org-get-at-bol 'line-prefix))))
-                         ?\·)
-                        '(face shadow))
-                    (org-add-props
-                        (format " %9s " (org-duration-from-minutes time))
-                        '(face org-clock-overlay))
-                    ""))
-    (overlay-put ov 'display tx)
-    (push ov org-clock-overlays)))
+  "Put an overlay on the headline at point, displaying TIME.
+Create a new overlay and store it in `org-clock-overlays', so
+that it will be easy to remove.  This function assumes point is
+on a headline."
+  (org-match-line org-complex-heading-regexp)
+  (goto-char (match-beginning 4))
+  (let* ((headline (match-string 4))
+        (text (concat headline
+                      (org-add-props
+                          (make-string
+                           (max (- (- 60 (current-column))
+                                   (org-string-width headline)
+                                   (length (org-get-at-bol 'line-prefix)))
+                                0)
+                           ?\·)
+                          '(face shadow))
+                      (org-add-props
+                          (format " %9s " (org-duration-from-minutes time))
+                          '(face org-clock-overlay))))
+        (o (make-overlay (point) (line-end-position))))
+    (org-overlay-display o text)
+    (push o org-clock-overlays)))
 
 ;;;###autoload
 (defun org-clock-remove-overlays (&optional _beg _end noremove)
@@ -1976,7 +1992,7 @@ If NOREMOVE is nil, remove this function from the
       (remove-hook 'before-change-functions
                   'org-clock-remove-overlays 'local))))
 
-(defvar org-state) ;; dynamically scoped into this function
+;;;###autoload
 (defun org-clock-out-if-current ()
   "Clock out if the current entry contains the running clock.
 This is used to stop the clock after a TODO entry is marked DONE,
@@ -1993,16 +2009,13 @@ and is only done if the variable 
`org-clock-out-when-done' is not nil."
                    (or (buffer-base-buffer (current-buffer))
                        (current-buffer)))
             (< (point) org-clock-marker)
-            (> (save-excursion (outline-next-heading) (point))
+            (> (org-with-wide-buffer (org-entry-end-position))
                org-clock-marker))
     ;; Clock out, but don't accept a logging message for this.
     (let ((org-log-note-clock-out nil)
          (org-clock-out-switch-to-state nil))
       (org-clock-out))))
 
-(add-hook 'org-after-todo-state-change-hook
-         'org-clock-out-if-current)
-
 ;;;###autoload
 (defun org-clock-get-clocktable (&rest props)
   "Get a formatted clocktable with parameters according to PROPS.
@@ -2054,6 +2067,8 @@ in the buffer and update it."
     (start (goto-char start)))
   (org-update-dblock))
 
+(org-dynamic-block-define "clocktable" #'org-clock-report)
+
 (defun org-day-of-week (day month year)
   "Return the day of the week as an integer."
   (nth 6
@@ -2125,9 +2140,10 @@ time.
 
 The return value is a list containing two internal times, one for
 the beginning of the range and one for its end, like the ones
-returned by `current time' or `encode-time' and a string used to
+returned by `current-time' or `encode-time' and a string used to
 display information.  If AS-STRINGS is non-nil, the returned
-times will be formatted strings.
+times will be formatted strings.  Note that the first element is
+always nil when KEY is `untilnow'.
 
 If WSTART is non-nil, use this number to specify the starting day
 of a week (monday is 1).  If MSTART is non-nil, use this number
@@ -2201,13 +2217,17 @@ have priority."
        (`lastq     (setq key 'quarter shift -1))))
     ;; Prepare start and end times depending on KEY's type.
     (pcase key
-      ((or `day `today) (setq m 0 h 0 h1 24 d (+ d shift)))
+      ((or `day `today) (setq m 0
+                              h org-extend-today-until
+                              h1 (+ 24 org-extend-today-until)
+                              d (+ d shift)))
       ((or `week `thisweek)
        (let* ((ws (or wstart 1))
              (diff (+ (* -7 shift) (if (= dow 0) (- 7 ws) (- dow ws)))))
-        (setq m 0 h 0 d (- d diff) d1 (+ 7 d))))
+        (setq m 0 h org-extend-today-until d (- d diff) d1 (+ 7 d))))
       ((or `month `thismonth)
-       (setq h 0 m 0 d (or mstart 1) month (+ month shift) month1 (1+ month)))
+       (setq h org-extend-today-until m 0 d (or mstart 1)
+             month (+ month shift) month1 (1+ month)))
       ((or `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
@@ -2225,32 +2245,22 @@ have priority."
             (setq shiftedy (- y (+ 1 (nth 0 tmp)))
                   shiftedm (- 13 (* 3 (nth 1 tmp)))
                   shiftedq (- 5 (nth 1 tmp)))))
-        (setq m 0 h 0 d 1 month shiftedm month1 (+ 3 shiftedm) y shiftedy))
+        (setq m 0 h org-extend-today-until d 1
+               month shiftedm month1 (+ 3 shiftedm) y shiftedy))
        ((> (+ q shift) 0)              ; Shift is within this year.
         (setq shiftedq (+ q shift))
         (setq shiftedy y)
         (let ((qshift (* 3 (1- (+ q shift)))))
-          (setq m 0 h 0 d 1 month (+ 1 qshift) month1 (+ 4 qshift))))))
+          (setq m 0 h org-extend-today-until d 1
+                 month (+ 1 qshift) month1 (+ 4 qshift))))))
       ((or `year `thisyear)
-       (setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y)))
+       (setq m 0 h org-extend-today-until d 1 month 1 y (+ y shift) y1 (1+ y)))
       ((or `interactive `untilnow))    ; Special cases, ignore them.
       (_ (user-error "No such time block %s" key)))
     ;; Format start and end times according to AS-STRINGS.
     (let* ((start (pcase key
                    (`interactive (org-read-date nil t nil "Range start? "))
-                    ;; In theory, all clocks started after the dawn of
-                    ;; humanity.  However, the platform's clock
-                    ;; support might not go back that far.  Choose the
-                    ;; POSIX timestamp -2**41 (approximately 68,000
-                    ;; BCE) if that works, otherwise -2**31 (1901) if
-                    ;; that works, otherwise 0 (1970).  Going back
-                    ;; billions of years would loop forever on Mac OS
-                    ;; X 10.6 with Emacs 26 and earlier (Bug#27736).
-                   (`untilnow
-                     (let ((old 0))
-                       (dolist (older '((-32768 0) (-33554432 0)) old)
-                         (when (ignore-errors (decode-time older))
-                          (setq old older)))))
+                   (`untilnow nil)
                    (_ (encode-time 0 m h d month y))))
           (end (pcase key
                  (`interactive (org-read-date nil t nil "Range end? "))
@@ -2274,7 +2284,7 @@ have priority."
              (`untilnow "now"))))
       (if (not as-strings) (list start end text)
        (let ((f (cdr org-time-stamp-formats)))
-         (list (format-time-string f start)
+         (list (and start (format-time-string f start))
                (format-time-string f end)
                text))))))
 
@@ -2382,15 +2392,22 @@ the currently selected interval size."
                    (`file-with-archives
                     (and buffer-file-name
                          (org-add-archive-files (list buffer-file-name))))
+                   ((or `nil `file `subtree `tree
+                        (and (pred symbolp)
+                             (guard (string-match "\\`tree\\([0-9]+\\)\\'"
+                                                  (symbol-name scope)))))
+                    (or (buffer-file-name (buffer-base-buffer))
+                        (current-buffer)))
                    ((pred functionp) (funcall scope))
                    ((pred consp) scope)
-                   (_ (or (buffer-file-name) (current-buffer)))))
+                   (_ (user-error "Unknown scope: %S" scope))))
           (block (plist-get params :block))
           (ts (plist-get params :tstart))
           (te (plist-get params :tend))
           (ws (plist-get params :wstart))
           (ms (plist-get params :mstart))
           (step (plist-get params :step))
+          (hide-files (plist-get params :hidefiles))
           (formatter (or (plist-get params :formatter)
                          org-clock-clocktable-formatter
                          'org-clocktable-write-default))
@@ -2445,7 +2462,9 @@ the currently selected interval size."
             ;; Even though `file-with-archives' can consist of
             ;; multiple files, we consider this is one extended file
             ;; instead.
-            (and (consp files) (not (eq scope 'file-with-archives)))))
+            (and (not hide-files)
+                 (consp files)
+                 (not (eq scope 'file-with-archives)))))
 
        (funcall formatter
                 origin
@@ -2475,6 +2494,7 @@ from the dynamic block definition."
         (narrow (or (plist-get params :narrow) (and compact? '40!)))
         (level? (and (not compact?) (plist-get params :level)))
         (timestamp (plist-get params :timestamp))
+        (tags (plist-get params :tags))
         (properties (plist-get params :properties))
         (time-columns
          (if (or compact? (< maxlevel 2)) 1
@@ -2535,6 +2555,7 @@ from the dynamic block definition."
        (if multifile "|" "")           ;file column, maybe
        (if level? "|" "")              ;level column, maybe
        (if timestamp "|" "")           ;timestamp column, maybe
+       (if tags "|" "")                 ;tags columns, maybe
        (if properties                  ;properties columns, maybe
           (make-string (length properties) ?|)
         "")
@@ -2552,6 +2573,8 @@ from the dynamic block definition."
      (if timestamp                     ;timestamp column, maybe
         (concat (org-clock--translate "Timestamp" lang) "|")
        "")
+     (if tags "Tags |" "")              ;tags columns, maybe
+
      (if properties                    ;properties columns, maybe
         (concat (mapconcat #'identity properties "|") "|")
        "")
@@ -2566,8 +2589,9 @@ from the dynamic block definition."
      "|"                               ;table line starter
      (if multifile (format "| %s " (org-clock--translate "ALL" lang)) "")
                                        ;file column, maybe
-     (if level? "|" "")                        ;level column, maybe
+     (if level?    "|" "")             ;level column, maybe
      (if timestamp "|" "")             ;timestamp column, maybe
+     (if tags      "|" "")             ;timestamp column, maybe
      (make-string (length properties) ?|) ;properties columns, maybe
      (concat (format org-clock-total-time-cell-format
                     (org-clock--translate "Total time" lang))
@@ -2592,13 +2616,14 @@ from the dynamic block definition."
          (when multifile
            ;; Summarize the time collected from this file.
            (insert-before-markers
-            (format (concat "| %s %s | %s%s"
+            (format (concat "| %s %s | %s%s%s"
                             (format org-clock-file-time-cell-format
                                     (org-clock--translate "File time" lang))
                             " | *%s*|\n")
                     (file-name-nondirectory file-name)
-                    (if level?   "| " "")  ;level column, maybe
+                    (if level?    "| " "") ;level column, maybe
                     (if timestamp "| " "") ;timestamp column, maybe
+                    (if tags      "| " "") ;tags column, maybe
                     (if properties         ;properties columns, maybe
                         (make-string (length properties) ?|)
                       "")
@@ -2606,16 +2631,16 @@ from the dynamic block definition."
 
          ;; Get the list of node entries and iterate over it
          (when (> maxlevel 0)
-           (pcase-dolist (`(,level ,headline ,ts ,time ,props) entries)
+           (pcase-dolist (`(,level ,headline ,tgs ,ts ,time ,props) entries)
              (when narrow-cut-p
                (setq headline
                      (if (and (string-match
-                               (format "\\`%s\\'" org-bracket-link-regexp)
+                               (format "\\`%s\\'" org-link-bracket-re)
                                headline)
-                              (match-end 3))
+                              (match-end 2))
                          (format "[[%s][%s]]"
                                  (match-string 1 headline)
-                                 (org-shorten-string (match-string 3 headline)
+                                 (org-shorten-string (match-string 2 headline)
                                                      narrow))
                        (org-shorten-string headline narrow))))
              (cl-flet ((format-field (f) (format (cond ((not emph) "%s |")
@@ -2628,6 +2653,7 @@ from the dynamic block definition."
                 (if multifile "|" "") ;free space for file name column?
                 (if level? (format "%d|" level) "") ;level, maybe
                 (if timestamp (concat ts "|") "")   ;timestamp, maybe
+                (if tags (concat (mapconcat #'identity tgs ", ") "|") "")   
;tags, maybe
                 (if properties         ;properties columns, maybe
                     (concat (mapconcat (lambda (p) (or (cdr (assoc p props)) 
""))
                                        properties
@@ -2683,69 +2709,87 @@ LEVEL is an integer.  Indent by two spaces per level 
above 1."
     (concat "\\_" (make-string (* 2 (1- level)) ?\s))))
 
 (defun org-clocktable-steps (params)
-  "Step through the range to make a number of clock tables."
-  (let* ((ts (plist-get params :tstart))
-        (te (plist-get params :tend))
-        (ws (plist-get params :wstart))
-        (ms (plist-get params :mstart))
-        (step0 (plist-get params :step))
-        (step (cdr (assq step0 '((day . 86400) (week . 604800)))))
-        (stepskip0 (plist-get params :stepskip0))
-        (block (plist-get params :block))
-        cc tsb)
-    (when block
-      (setq cc (org-clock-special-range block nil t ws ms)
-           ts (car cc)
-           te (nth 1 cc)))
-    (cond
-     ((numberp ts)
-      ;; If ts is a number, it's an absolute day number from
-      ;; org-agenda.
-      (pcase-let ((`(,month ,day ,year) (calendar-gregorian-from-absolute ts)))
-       (setq ts (float-time (encode-time 0 0 0 day month year)))))
-     (ts
-      (setq ts (float-time (org-time-string-to-time ts)))))
-    (cond
-     ((numberp te)
-      ;; Likewise for te.
-      (pcase-let ((`(,month ,day ,year) (calendar-gregorian-from-absolute te)))
-       (setq te (float-time (encode-time 0 0 0 day month year)))))
-     (te
-      (setq te (float-time (org-time-string-to-time te)))))
-    (setq tsb
-         (if (eq step0 'week)
-             (let ((dow (nth 6 (decode-time ts))))
-               (if (<= dow ws) ts
-                 (- ts (* 86400 (- dow ws)))))
-           ts))
-    (while (< tsb te)
+  "Create one or more clock tables, according to PARAMS.
+Step through the range specifications in plist PARAMS to make
+a number of clock tables."
+  (let* ((ignore-empty-tables (plist-get params :stepskip0))
+         (step (plist-get params :step))
+         (step-header
+          (pcase step
+            (`day "Daily report: ")
+            (`week "Weekly report starting on: ")
+            (`month "Monthly report starting on: ")
+            (`year "Annual report starting on: ")
+            (_ (user-error "Unknown `:step' specification: %S" step))))
+         (week-start (or (plist-get params :wstart) 1))
+         (month-start (or (plist-get params :mstart) 1))
+         (range
+          (pcase (plist-get params :block)
+            (`nil nil)
+            (range
+             (org-clock-special-range range nil t week-start month-start))))
+         ;; For both START and END, any number is an absolute day
+         ;; number from Agenda.  Otherwise, consider value to be an Org
+         ;; timestamp string.  The `:block' property has precedence
+         ;; over `:tstart' and `:tend'.
+         (start
+          (pcase (if range (car range) (plist-get params :tstart))
+            ((and (pred numberp) n)
+             (pcase-let ((`(,m ,d ,y) (calendar-gregorian-from-absolute n)))
+               (apply #'encode-time (list 0 0 org-extend-today-until d m y))))
+            (timestamp
+            (seconds-to-time
+             (org-matcher-time (or timestamp
+                                   ;; The year Org was born.
+                                   "<2003-01-01 Thu 00:00>"))))))
+         (end
+          (pcase (if range (nth 1 range) (plist-get params :tend))
+            ((and (pred numberp) n)
+             (pcase-let ((`(,m ,d ,y) (calendar-gregorian-from-absolute n)))
+               (apply #'encode-time (list 0 0 org-extend-today-until d m y))))
+            (timestamp (seconds-to-time (org-matcher-time timestamp))))))
+    (while (time-less-p start end)
       (unless (bolp) (insert "\n"))
-      (let ((start-time (max tsb ts)))
-       (cl-incf tsb (let ((dow (nth 6 (decode-time tsb))))
-                      (if (or (eq step0 'day)
-                              (= dow ws))
-                          step
-                        (* 86400 (- ws dow)))))
-       (insert "\n"
-               (if (eq step0 'day) "Daily report: "
-                 "Weekly report starting on: ")
-               (format-time-string (org-time-stamp-format nil t) start-time)
-               "\n")
-       (let ((table-begin (line-beginning-position 0))
-             (step-time
-              (org-dblock-write:clocktable
-               (org-combine-plists
-                params
-                (list
-                 :header "" :step nil :block nil
-                 :tstart (format-time-string (org-time-stamp-format t t)
-                                             start-time)
-                 :tend (format-time-string (org-time-stamp-format t t)
-                                           (min te tsb)))))))
-         (re-search-forward "^[ \t]*#\\+END:")
-         (when (and stepskip0 (equal step-time 0))
-           ;; Remove the empty table
-           (delete-region (line-beginning-position) table-begin))))
+      ;; Insert header before each clock table.
+      (insert "\n"
+              step-header
+              (format-time-string (org-time-stamp-format nil t) start)
+             "\n")
+      ;; Compute NEXT, which is the end of the current clock table,
+      ;; according to step.
+      (let* ((next
+              (apply #'encode-time
+                     (pcase-let
+                         ((`(,_ ,_ ,_ ,d ,m ,y ,dow . ,_) (decode-time start)))
+                       (pcase step
+                         (`day (list 0 0 org-extend-today-until (1+ d) m y))
+                         (`week
+                          (let ((offset (if (= dow week-start) 7
+                                          (mod (- week-start dow) 7))))
+                            (list 0 0 org-extend-today-until (+ d offset) m 
y)))
+                         (`month (list 0 0 0 month-start (1+ m) y))
+                         (`year (list 0 0 org-extend-today-until 1 1 (1+ 
y)))))))
+             (table-begin (line-beginning-position 0))
+            (step-time
+              ;; Write clock table between START and NEXT.
+             (org-dblock-write:clocktable
+              (org-combine-plists
+               params (list :header ""
+                             :step nil
+                             :block nil
+                            :tstart (format-time-string
+                                      (org-time-stamp-format t t)
+                                      start)
+                            :tend (format-time-string
+                                    (org-time-stamp-format t t)
+                                    ;; Never include clocks past END.
+                                    (if (time-less-p end next) end next)))))))
+       (let ((case-fold-search t)) (re-search-forward "^[ \t]*#\\+END:"))
+       ;; Remove the table if it is empty and `:stepskip0' is
+       ;; non-nil.
+       (when (and ignore-empty-tables (equal step-time 0))
+         (delete-region (line-beginning-position) table-begin))
+        (setq start next))
       (end-of-line 0))))
 
 (defun org-clock-get-table-data (file params)
@@ -2758,13 +2802,14 @@ file time (in minutes) as 1st and 2nd elements.  The 
third element
 of this list will be a list of headline entries.  Each entry has the
 following structure:
 
-  (LEVEL HEADLINE TIMESTAMP TIME PROPERTIES)
+  (LEVEL HEADLINE TAGS TIMESTAMP TIME PROPERTIES)
 
 LEVEL:      The level of the headline, as an integer.  This will be
             the reduced level, so 1,2,3,... even if only odd levels
             are being used.
 HEADLINE:   The text of the headline.  Depending on PARAMS, this may
             already be formatted like a link.
+TAGS:       The list of tags of the headline.
 TIMESTAMP:  If PARAMS require it, this will be a time stamp found in the
             entry, any of SCHEDULED, DEADLINE, NORMAL, or first inactive,
             in this sequence.
@@ -2783,9 +2828,10 @@ PROPERTIES: The list properties specified in the 
`:properties' parameter
         (block (plist-get params :block))
         (link (plist-get params :link))
         (tags (plist-get params :tags))
+        (match (plist-get params :match))
         (properties (plist-get params :properties))
         (inherit-property-p (plist-get params :inherit-props))
-        (matcher (and tags (cdr (org-make-tags-matcher tags))))
+        (matcher (and match (cdr (org-make-tags-matcher match))))
         cc st p tbl)
 
     (setq org-clock-file-total-minutes nil)
@@ -2806,10 +2852,11 @@ PROPERTIES: The list properties specified in the 
`:properties' parameter
       (org-clock-sum ts te
                     (when matcher
                       `(lambda ()
-                         (let* ((tags-list (org-get-tags-at))
+                         (let* ((todo (org-get-todo-state))
+                                (tags-list (org-get-tags))
                                 (org-scanner-tags tags-list)
                                 (org-trust-scanner-tags t))
-                           (funcall ,matcher nil tags-list nil)))))
+                           (funcall ,matcher todo tags-list nil)))))
       (goto-char (point-min))
       (setq st t)
       (while (or (and (bobp) (prog1 st (setq st nil))
@@ -2826,8 +2873,8 @@ PROPERTIES: The list properties specified in the 
`:properties' parameter
                       (hdl
                        (if (not link) headline
                          (let ((search
-                                (org-make-org-heading-search-string headline)))
-                           (org-make-link-string
+                                (org-link-heading-search-string headline)))
+                           (org-link-make-string
                             (if (not (buffer-file-name)) search
                               (format "file:%s::%s" (buffer-file-name) search))
                             ;; Prune statistics cookies.  Replace
@@ -2838,6 +2885,7 @@ PROPERTIES: The list properties specified in the 
`:properties' parameter
                               (replace-regexp-in-string
                                "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
                                headline)))))))
+                      (tgs (and tags (org-get-tags)))
                       (tsp
                        (and timestamp
                             (cl-some (lambda (p) (org-entry-get (point) p))
@@ -2852,7 +2900,7 @@ PROPERTIES: The list properties specified in the 
`:properties' parameter
                                                (point) p inherit-property-p)))
                                        (and v (cons p v))))
                                    properties)))))
-                 (push (list level hdl tsp time props) tbl)))))))
+                 (push (list level hdl tgs tsp time props) tbl)))))))
       (list file org-clock-file-total-minutes (nreverse tbl)))))
 
 ;; Saving and loading the clock
@@ -2889,9 +2937,10 @@ Otherwise, return nil."
          (end-of-line 1)
          (setq ts (match-string 1)
                te (match-string 3))
-         (setq s (float-time
-                  (time-subtract (org-time-string-to-time te)
-                                 (org-time-string-to-time ts)))
+         (setq s (- (float-time
+                     (apply #'encode-time (org-parse-time-string te)))
+                    (float-time
+                     (apply #'encode-time (org-parse-time-string ts))))
                neg (< s 0)
                s (abs s)
                h (floor (/ s 3600))
diff --git a/lisp/org/org-colview.el b/lisp/org/org-colview.el
index 51a8eff..caef425 100644
--- a/lisp/org/org-colview.el
+++ b/lisp/org/org-colview.el
@@ -41,6 +41,9 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-restriction "org-element" (element))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-dynamic-block-define "org" (type func))
+(declare-function org-link-display-format "ol" (s))
+(declare-function org-link-open-from-string "ol" (s &optional arg))
 
 (defvar org-agenda-columns-add-appointments-to-effort-sum)
 (defvar org-agenda-columns-compute-summary-properties)
@@ -67,7 +70,8 @@ or nil if the normal value should be used."
 (defcustom org-columns-summary-types nil
   "Alist between operators and summarize functions.
 
-Each association follows the pattern (LABEL . SUMMARIZE) where
+Each association follows the pattern (LABEL . SUMMARIZE),
+or (LABEL SUMMARIZE COLLECT) where
 
   LABEL is a string used in #+COLUMNS definition describing the
   summary type.  It can contain any character but \"}\".  It is
@@ -78,6 +82,13 @@ Each association follows the pattern (LABEL . SUMMARIZE) 
where
   The second one is a format string or nil.  It has to return
   a string summarizing the list of values.
 
+  COLLECT is a function called with one argument, a property
+  name.  It is called in the context of a headline and must
+  return the collected property, or the empty string.  You can
+  use this to only collect a property if a related conditional
+  properties is set, e.g., to return VACATION_DAYS only if
+  CONFIRMED is true.
+
 Note that the return value can become one value for an higher
 order summary, so the function is expected to handle its own
 output.
@@ -88,7 +99,11 @@ in `org-columns-summary-types-default', which see."
   :version "26.1"
   :package-version '(Org . "9.0")
   :type '(alist :key-type (string :tag "       Label")
-               :value-type (function :tag "Summarize")))
+               :value-type
+               (choice (function :tag "Summarize")
+                       (list :tag "Collect and summarize"
+                             (function :tag "Summarize")
+                             (function :tag "Collect")))))
 
 
 
@@ -221,21 +236,27 @@ See `org-columns-summary-types' for details.")
     "--"
     ["Quit" org-columns-quit t]))
 
-(defun org-columns--displayed-value (spec value)
+(defun org-columns--displayed-value (spec value &optional no-star)
   "Return displayed value for specification SPEC in current entry.
+
 SPEC is a column format specification as stored in
 `org-columns-current-fmt-compiled'.  VALUE is the real value to
-display, as a string."
+display, as a string.
+
+When NO-STAR is non-nil, do not add asterisks before displayed
+value for ITEM property."
   (or (and (functionp org-columns-modify-value-for-display-function)
           (funcall org-columns-modify-value-for-display-function
                    (nth 1 spec)        ;column name
                    value))
       (pcase spec
        (`("ITEM" . ,_)
-        (concat (make-string (1- (org-current-level))
-                             (if org-hide-leading-stars ?\s ?*))
-                "* "
-                (org-columns-compact-links value)))
+        (let ((stars
+               (and (not no-star)
+                    (concat (make-string (1- (org-current-level))
+                                         (if org-hide-leading-stars ?\s ?*))
+                            "* "))))
+          (concat stars (org-link-display-format value))))
        (`(,_ ,_ ,_ ,_ nil) value)
        ;; If PRINTF is set, assume we are displaying a number and
        ;; obey to the format string.
@@ -268,7 +289,11 @@ possible to override it with optional argument 
COMPILED-FMT."
                                          (get-text-property (point) 'duration))
                                         'face 'org-warning))
                        "")))
-           (list spec v (org-columns--displayed-value spec v))))))
+           ;; A non-nil COMPILED-FMT means we're calling from Org
+           ;; Agenda mode, where we do not want leading stars for
+           ;; ITEM.  Hence the optional argument for
+           ;; `org-columns--displayed-value'.
+           (list spec v (org-columns--displayed-value spec v compiled-fmt))))))
      (or compiled-fmt org-columns-current-fmt-compiled))))
 
 (defun org-columns--set-widths (cache)
@@ -301,13 +326,29 @@ integers greater than 0."
 
 (defun org-columns--summarize (operator)
   "Return summary function associated to string OPERATOR."
-  (if (not operator) nil
-    (cdr (or (assoc operator org-columns-summary-types)
-            (assoc operator org-columns-summary-types-default)
-            (error "Unknown %S operator" operator)))))
+  (pcase (or (assoc operator org-columns-summary-types)
+            (assoc operator org-columns-summary-types-default))
+    (`nil (error "Unknown %S operator" operator))
+    (`(,_ . ,(and (pred functionp) summarize)) summarize)
+    (`(,_ ,summarize ,_) summarize)
+    (_ (error "Invalid definition for operator %S" operator))))
+
+(defun org-columns--collect (operator)
+  "Return collect function associated to string OPERATOR.
+Return nil if no collect function is associated to OPERATOR."
+  (pcase (or (assoc operator org-columns-summary-types)
+            (assoc operator org-columns-summary-types-default))
+    (`nil (error "Unknown %S operator" operator))
+    (`(,_ . ,(pred functionp)) nil)    ;default value
+    (`(,_ ,_ ,collect) collect)
+    (_ (error "Invalid definition for operator %S" operator))))
 
 (defun org-columns--overlay-text (value fmt width property original)
-  "Return text."
+  "Return decorated VALUE string for columns overlay display.
+FMT is a format string.  WIDTH is the width of the column, as an
+integer.  PROPERTY is the property being displayed, as a string.
+ORIGINAL is the real string, i.e., before it is modified by
+`org-columns--displayed-value'."
   (format fmt
           (let ((v (org-columns-add-ellipses value width)))
             (pcase property
@@ -387,14 +428,14 @@ DATELINE is non-nil when the face used should be
                              (line-beginning-position 2))))
        (overlay-put ov 'keymap org-columns-map)
        (push ov org-columns-overlays))
-      (org-with-silent-modifications
-       (let ((inhibit-read-only t))
-        (put-text-property
-         (line-end-position 0)
-         (line-beginning-position 2)
-         'read-only
-         (substitute-command-keys
-          "Type \\<org-columns-map>`\\[org-columns-edit-value]' \
+      (with-silent-modifications
+       (let ((inhibit-read-only t))
+         (put-text-property
+          (line-end-position 0)
+          (line-beginning-position 2)
+          'read-only
+          (substitute-command-keys
+           "Type \\<org-columns-map>`\\[org-columns-edit-value]' \
 to edit property")))))))
 
 (defun org-columns-add-ellipses (string width)
@@ -424,6 +465,7 @@ for the duration of the command.")
   "Overlay the newline before the current line with the table title."
   (interactive)
   (let ((title "")
+       (linum-offset (org-line-number-display-width 'columns))
        (i 0))
     (dolist (column org-columns-current-fmt-compiled)
       (pcase column
@@ -435,7 +477,7 @@ for the duration of the command.")
     (setq-local org-previous-header-line-format header-line-format)
     (setq org-columns-full-header-line-format
          (concat
-          (org-add-props " " nil 'display '(space :align-to 0))
+          (org-add-props " " nil 'display `(space :align-to ,linum-offset))
           (org-add-props (substring title 0 -1) nil 'face 'org-column-title)))
     (setq org-columns-previous-hscroll -1)
     (add-hook 'post-command-hook 'org-columns-hscroll-title nil 'local)))
@@ -443,13 +485,15 @@ for the duration of the command.")
 (defun org-columns-hscroll-title ()
   "Set the `header-line-format' so that it scrolls along with the table."
   (sit-for .0001) ; need to force a redisplay to update window-hscroll
-  (when (not (= (window-hscroll) org-columns-previous-hscroll))
-    (setq header-line-format
-         (concat (substring org-columns-full-header-line-format 0 1)
-                 (substring org-columns-full-header-line-format
-                            (1+ (window-hscroll))))
-         org-columns-previous-hscroll (window-hscroll))
-    (force-mode-line-update)))
+  (let ((hscroll (window-hscroll)))
+    (when (/= org-columns-previous-hscroll hscroll)
+      (setq header-line-format
+           (concat (substring org-columns-full-header-line-format 0 1)
+                   (substring org-columns-full-header-line-format
+                              (min (length org-columns-full-header-line-format)
+                                   (1+ hscroll))))
+           org-columns-previous-hscroll hscroll)
+      (force-mode-line-update))))
 
 (defvar org-colview-initial-truncate-line-value nil
   "Remember the value of `truncate-lines' across colview.")
@@ -466,24 +510,16 @@ for the duration of the command.")
     (set-marker org-columns-begin-marker nil)
     (when (markerp org-columns-top-level-marker)
       (set-marker org-columns-top-level-marker nil))
-    (org-with-silent-modifications
-     (mapc #'delete-overlay org-columns-overlays)
-     (setq org-columns-overlays nil)
-     (let ((inhibit-read-only t))
-       (remove-text-properties (point-min) (point-max) '(read-only t))))
+    (with-silent-modifications
+      (mapc #'delete-overlay org-columns-overlays)
+      (setq org-columns-overlays nil)
+      (let ((inhibit-read-only t))
+       (remove-text-properties (point-min) (point-max) '(read-only t))))
     (when org-columns-flyspell-was-active
       (flyspell-mode 1))
     (when (local-variable-p 'org-colview-initial-truncate-line-value)
       (setq truncate-lines org-colview-initial-truncate-line-value))))
 
-(defun org-columns-compact-links (s)
-  "Replace [[link][desc]] with [desc] or [link]."
-  (while (string-match org-bracket-link-regexp s)
-    (setq s (replace-match
-            (concat "[" (match-string (if (match-end 3) 3 1) s) "]")
-            t t s)))
-  s)
-
 (defun org-columns-show-value ()
   "Show the full value of the property."
   (interactive)
@@ -495,10 +531,10 @@ for the duration of the command.")
 (defun org-columns-quit ()
   "Remove the column overlays and in this way exit column editing."
   (interactive)
-  (org-with-silent-modifications
-   (org-columns-remove-overlays)
-   (let ((inhibit-read-only t))
-     (remove-text-properties (point-min) (point-max) '(read-only t))))
+  (with-silent-modifications
+    (org-columns-remove-overlays)
+    (let ((inhibit-read-only t))
+      (remove-text-properties (point-min) (point-max) '(read-only t))))
   (if (not (eq major-mode 'org-agenda-mode))
       (setq org-columns-current-fmt nil)
     (setq org-agenda-columns-active nil)
@@ -526,9 +562,17 @@ for the duration of the command.")
       (org-columns-next-allowed-value)
     (org-columns-edit-value "TAGS")))
 
-(defvar org-agenda-overriding-columns-format nil
+(defvar org-overriding-columns-format nil
+  "When set, overrides any other format definition for the agenda.
+Don't set this, this is meant for dynamic scoping.  Set
+`org-columns-default-format' and `org-columns-default-format-for-agenda'
+instead.  You should use this variable only in the local settings
+section for a custom agenda view.")
+
+(defvar-local org-local-columns-format nil
   "When set, overrides any other format definition for the agenda.
-Don't set this, this is meant for dynamic scoping.")
+This can be set as a buffer local value to avoid interfering with
+dynamic scoping for `org-overriding-columns-format'.")
 
 (defun org-columns-edit-value (&optional key)
   "Edit the value of the property at point in column view.
@@ -544,7 +588,7 @@ Where possible, use the standard interface for changing 
this line."
         (action
          (pcase key
            ("CLOCKSUM"
-            (error "This special column cannot be edited"))
+            (user-error "This special column cannot be edited"))
            ("ITEM"
             (lambda () (org-with-point-at pom (org-edit-headline))))
            ("TODO"
@@ -561,7 +605,7 @@ Where possible, use the standard interface for changing 
this line."
                        (if (eq org-fast-tag-selection-single-key 'expert)
                            t
                          org-fast-tag-selection-single-key)))
-                  (call-interactively #'org-set-tags)))))
+                  (call-interactively #'org-set-tags-command)))))
            ("DEADLINE"
             (lambda ()
               (org-with-point-at pom (call-interactively #'org-deadline))))
@@ -589,7 +633,7 @@ Where possible, use the standard interface for changing 
this line."
       (org-columns--call action)
       ;; The following let preserves the current format, and makes
       ;; sure that in only a single file things need to be updated.
-      (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
+      (let* ((org-overriding-columns-format org-columns-current-fmt)
             (buffer (marker-buffer pom))
             (org-agenda-contributing-files
              (list (with-current-buffer buffer
@@ -597,8 +641,8 @@ Where possible, use the standard interface for changing 
this line."
        (org-agenda-columns)))
      (t
       (let ((inhibit-read-only t))
-       (org-with-silent-modifications
-        (remove-text-properties (max (point-min) (1- bol)) eol '(read-only t)))
+       (with-silent-modifications
+         (remove-text-properties (max (point-min) (1- bol)) eol '(read-only 
t)))
        (org-columns--call action))
       ;; Some properties can modify headline (e.g., "TODO"), and
       ;; possible shuffle overlays.  Make sure they are still all at
@@ -683,7 +727,7 @@ an integer, select that value."
        (org-columns--call action)
        ;; The following let preserves the current format, and makes
        ;; sure that in only a single file things need to be updated.
-       (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
+       (let* ((org-overriding-columns-format org-columns-current-fmt)
               (buffer (marker-buffer pom))
               (org-agenda-contributing-files
                (list (with-current-buffer buffer
@@ -719,13 +763,13 @@ around it."
       (setq time-after (copy-sequence time))
       (setf (nth 3 time-before) (1- (nth 3 time)))
       (setf (nth 3 time-after) (1+ (nth 3 time)))
-      (mapcar (lambda (x) (format-time-string fmt (encode-time x)))
+      (mapcar (lambda (x) (format-time-string fmt (apply 'encode-time x)))
              (list time-before time time-after)))))
 
 (defun org-columns-open-link (&optional arg)
   (interactive "P")
   (let ((value (get-char-property (point) 'org-columns-value)))
-    (org-open-link-from-string value arg)))
+    (org-link-open-from-string value arg)))
 
 ;;;###autoload
 (defun org-columns-get-format-and-top-level ()
@@ -783,17 +827,17 @@ view for the whole buffer unconditionally.
 When COLUMNS-FMT-STRING is non-nil, use it as the column format."
   (interactive "P")
   (org-columns-remove-overlays)
-  (when global (goto-char (point-min)))
-  (if (markerp org-columns-begin-marker)
-      (move-marker org-columns-begin-marker (point))
-    (setq org-columns-begin-marker (point-marker)))
-  (org-columns-goto-top-level)
-  ;; Initialize `org-columns-current-fmt' and
-  ;; `org-columns-current-fmt-compiled'.
-  (let ((org-columns--time (float-time)))
-    (org-columns-get-format columns-fmt-string)
-    (unless org-columns-inhibit-recalculation (org-columns-compute-all))
-    (save-excursion
+  (save-excursion
+    (when global (goto-char (point-min)))
+    (if (markerp org-columns-begin-marker)
+       (move-marker org-columns-begin-marker (point))
+      (setq org-columns-begin-marker (point-marker)))
+    (org-columns-goto-top-level)
+    ;; Initialize `org-columns-current-fmt' and
+    ;; `org-columns-current-fmt-compiled'.
+    (let ((org-columns--time (float-time)))
+      (org-columns-get-format columns-fmt-string)
+      (unless org-columns-inhibit-recalculation (org-columns-compute-all))
       (save-restriction
        (when (and (not global) (org-at-heading-p))
          (narrow-to-region (point) (org-end-of-subtree t t)))
@@ -1011,8 +1055,8 @@ the current buffer."
 
 (defun org-columns-uncompile-format (compiled)
   "Turn the compiled columns format back into a string representation.
-COMPILED is an alist, as returned by
-`org-columns-compile-format', which see."
+
+COMPILED is an alist, as returned by `org-columns-compile-format'."
   (mapconcat
    (lambda (spec)
      (pcase spec
@@ -1085,16 +1129,7 @@ as a canonical duration, i.e., using units defined in
   "Apply FUN to time values TIMES.
 Return the result as a duration."
   (org-duration-from-minutes
-   (apply fun
-         (mapcar (lambda (time)
-                   ;; Unlike to `org-duration-to-minutes' standard
-                   ;; behavior, we want to consider plain numbers as
-                   ;; hours.  As a consequence, we treat them
-                   ;; differently.
-                   (if (string-match-p "\\`[0-9]+\\(?:\\.[0-9]*\\)?\\'" time)
-                       (* 60 (string-to-number time))
-                     (org-duration-to-minutes time)))
-                 times))
+   (apply fun (mapcar #'org-duration-to-minutes times))
    (org-duration-h:mm-only-p times)))
 
 (defun org-columns--compute-spec (spec &optional update)
@@ -1111,7 +1146,9 @@ properties drawers."
         (last-level lmax)
         (property (car spec))
         (printf (nth 4 spec))
-        (summarize (org-columns--summarize (nth 3 spec))))
+        (operator (nth 3 spec))
+        (collect (and operator (org-columns--collect operator)))
+        (summarize (and operator (org-columns--summarize operator))))
     (org-with-wide-buffer
      ;; Find the region to compute.
      (goto-char org-columns-top-level-marker)
@@ -1123,7 +1160,8 @@ properties drawers."
         (setq last-level level))
        (setq level (org-reduced-level (org-outline-level)))
        (let* ((pos (match-beginning 0))
-             (value (org-entry-get nil property))
+              (value (if collect (funcall collect property)
+                      (org-entry-get (point) property)))
              (value-set (org-string-nw-p value)))
         (cond
          ((< level last-level)
@@ -1142,9 +1180,9 @@ properties drawers."
                      (old (assoc spec summaries-alist)))
                 (if old (setcdr old summary)
                   (push (cons spec summary) summaries-alist)
-                  (org-with-silent-modifications
-                   (add-text-properties
-                    pos (1+ pos) (list 'org-summaries summaries-alist)))))
+                  (with-silent-modifications
+                    (add-text-properties
+                     pos (1+ pos) (list 'org-summaries summaries-alist)))))
               ;; When PROPERTY exists in current node, even if empty,
               ;; but its value doesn't match the one computed, use
               ;; the latter instead.
@@ -1180,9 +1218,9 @@ column specification."
 
 (defun org-columns-compute-all ()
   "Compute all columns that have operators defined."
-  (org-with-silent-modifications
-   (remove-text-properties (point-min) (point-max) '(org-summaries t)))
-  (let ((org-columns--time (float-time (current-time)))
+  (with-silent-modifications
+    (remove-text-properties (point-min) (point-max) '(org-summaries t)))
+  (let ((org-columns--time (float-time))
        seen)
     (dolist (spec org-columns-current-fmt-compiled)
       (let ((property (car spec)))
@@ -1212,7 +1250,7 @@ When PRINTF is non-nil, use it to format the result."
   "Summarize CHECK-BOXES with a check-box cookie."
   (format "[%d/%d]"
          (cl-count-if (lambda (b) (or (equal b "[X]")
-                                 (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
+                                  (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
                       check-boxes)
          (length check-boxes)))
 
@@ -1261,17 +1299,17 @@ When PRINTF is non-nil, use it to format the result."
    times))
 
 (defun org-columns--summary-min-age (ages _)
-  "Compute the minimum time among AGES."
+  "Compute the minimum age among AGES."
   (org-columns--format-age
    (apply #'min (mapcar #'org-columns--age-to-minutes ages))))
 
 (defun org-columns--summary-max-age (ages _)
-  "Compute the maximum time among AGES."
+  "Compute the maximum age among AGES."
   (org-columns--format-age
    (apply #'max (mapcar #'org-columns--age-to-minutes ages))))
 
 (defun org-columns--summary-mean-age (ages _)
-  "Compute the minimum time among AGES."
+  "Compute the mean age among AGES."
   (org-columns--format-age
    (/ (apply #'+ (mapcar #'org-columns--age-to-minutes ages))
       (float (length ages)))))
@@ -1298,14 +1336,15 @@ and variances (respectively) of the individual 
estimates."
 
 ;;; Dynamic block for Column view
 
-(defun org-columns--capture-view (maxlevel skip-empty format local)
+(defun org-columns--capture-view (maxlevel match skip-empty exclude-tags 
format local)
   "Get the column view of the current buffer.
 
 MAXLEVEL sets the level limit.  SKIP-EMPTY tells whether to skip
 empty rows, an empty row being one where all the column view
-specifiers but ITEM are empty.  FORMAT is a format string for
-columns, or nil.  When LOCAL is non-nil, only capture headings in
-current subtree.
+specifiers but ITEM are empty.  EXCLUDE-TAGS is a list of tags
+that will be excluded from the resulting view.  FORMAT is a
+format string for columns, or nil.  When LOCAL is non-nil, only
+capture headings in current subtree.
 
 This function returns a list containing the title row and all
 other rows.  Each row is a list of fields, as strings, or
@@ -1328,12 +1367,17 @@ other rows.  Each row is a list of fields, as strings, 
or
                                             'org-columns-value
                                           'org-columns-value-modified)))
                     row)))
-          (unless (and skip-empty
-                       (let ((r (delete-dups (remove "" row))))
-                         (or (null r) (and has-item (= (length r) 1)))))
+          (unless (or
+                   (and skip-empty
+                        (let ((r (delete-dups (remove "" row))))
+                          (or (null r) (and has-item (= (length r) 1)))))
+                   (and exclude-tags
+                        (cl-some (lambda (tag) (member tag exclude-tags))
+                                 (org-get-tags))))
             (push (cons (org-reduced-level (org-current-level)) (nreverse row))
                   table)))))
-     (and maxlevel (format "LEVEL<=%d" maxlevel))
+     (or (and maxlevel (format "LEVEL<=%d" maxlevel))
+        (and match match))
      (and local 'tree)
      'archive 'comment)
     (org-columns-quit)
@@ -1357,24 +1401,54 @@ an inline src-block."
 ;;;###autoload
 (defun org-dblock-write:columnview (params)
   "Write the column view table.
+
 PARAMS is a property list of parameters:
 
-:id       the :ID: property of the entry where the columns view
-         should be built.  When the symbol `local', call locally.
-         When `global' call column view with the cursor at the beginning
-         of the buffer (usually this means that the whole buffer switches
-         to column view).  When \"file:path/to/file.org\", invoke column
-         view at the start of that file.  Otherwise, the ID is located
-         using `org-id-find'.
-:hlines   When t, insert a hline before each item.  When a number, insert
-         a hline before each level <= that number.
-:indent   When non-nil, indent each ITEM field according to its level.
-:vlines   When t, make each column a colgroup to enforce vertical lines.
-:maxlevel When set to a number, don't capture headlines below this level.
-:skip-empty-rows
-         When t, skip rows where all specifiers other than ITEM are empty.
-:width    apply widths specified in columns format using <N> specifiers.
-:format   When non-nil, specify the column view format to use."
+`:id' (mandatory)
+
+    The ID property of the entry where the columns view should be
+    built.  When the symbol `local', call locally.  When `global'
+    call column view with the cursor at the beginning of the
+    buffer (usually this means that the whole buffer switches to
+    column view).  When \"file:path/to/file.org\", invoke column
+    view at the start of that file.  Otherwise, the ID is located
+    using `org-id-find'.
+
+`:exclude-tags'
+
+    List of tags to exclude from column view table.
+
+`:format'
+
+    When non-nil, specify the column view format to use.
+
+`:hlines'
+
+    When non-nil, insert a hline before each item.  When
+    a number, insert a hline before each level inferior or equal
+    to that number.
+
+`:indent'
+
+    When non-nil, indent each ITEM field according to its level.
+
+`:match'
+
+    When set to a string, use this as a tags/property match filter.
+
+`:maxlevel'
+
+    When set to a number, don't capture headlines below this level.
+
+`:skip-empty-rows'
+
+    When non-nil, skip rows where all specifiers other than ITEM
+    are empty.
+
+`:vlines'
+
+    When non-nil, make each column a column group to enforce
+    vertical lines."
   (let ((table
         (let ((id (plist-get params :id))
               view-file view-pos)
@@ -1397,7 +1471,9 @@ PARAMS is a property list of parameters:
             (org-with-wide-buffer
              (when view-pos (goto-char view-pos))
              (org-columns--capture-view (plist-get params :maxlevel)
+                                        (plist-get params :match)
                                         (plist-get params :skip-empty-rows)
+                                        (plist-get params :exclude-tags)
                                         (plist-get params :format)
                                         view-pos))))))
     (when table
@@ -1429,14 +1505,6 @@ PARAMS is a property list of parameters:
                          (concat "\\_" (make-string (* 2 (1- level)) ?\s) item)
                        item))))
            (push (cdr row) new-table))))
-      (when (plist-get params :width)
-       (setq table
-             (append table
-                     (list
-                      (mapcar (lambda (spec)
-                                (let ((w (nth 2 spec)))
-                                  (if w (format "<%d>" (max 3 w)) "")))
-                              org-columns-current-fmt-compiled)))))
       (when (plist-get params :vlines)
        (setq table
              (let ((size (length org-columns-current-fmt-compiled)))
@@ -1482,6 +1550,7 @@ PARAMS is a property list of parameters:
                     (id)))))
   (org-update-dblock))
 
+(org-dynamic-block-define "columnview" #'org-columns-insert-dblock)
 
 
 ;;; Column view in the agenda
@@ -1497,7 +1566,9 @@ PARAMS is a property list of parameters:
   (let* ((org-columns--time (float-time))
         (fmt
          (cond
-          ((bound-and-true-p org-agenda-overriding-columns-format))
+          ((bound-and-true-p org-overriding-columns-format))
+          ((bound-and-true-p org-local-columns-format))
+          ((bound-and-true-p org-columns-default-format-for-agenda))
           ((let ((m (org-get-at-bol 'org-hd-marker)))
              (and m
                   (or (org-entry-get m "COLUMNS" t)
@@ -1616,8 +1687,8 @@ This will add overlays to the date lines, to show the 
summary for each day."
     (let ((b (find-buffer-visiting file)))
       (with-current-buffer (or (buffer-base-buffer b) b)
        (org-with-wide-buffer
-        (org-with-silent-modifications
-         (remove-text-properties (point-min) (point-max) '(org-summaries t)))
+        (with-silent-modifications
+          (remove-text-properties (point-min) (point-max) '(org-summaries t)))
         (goto-char (point-min))
         (org-columns-get-format-and-top-level)
         (dolist (spec fmt)
diff --git a/lisp/org/org-compat.el b/lisp/org/org-compat.el
index bb927fe..4446a16 100644
--- a/lisp/org/org-compat.el
+++ b/lisp/org/org-compat.el
@@ -25,34 +25,114 @@
 ;;; Commentary:
 
 ;; This file contains code needed for compatibility with older
-;; versions of GNU Emacs.
+;; versions of GNU Emacs and integration with other packages.
 
 ;;; Code:
 
 (require 'cl-lib)
 (require 'org-macs)
 
+(declare-function org-agenda-diary-entry "org-agenda")
+(declare-function org-agenda-maybe-redo "org-agenda" ())
+(declare-function org-agenda-remove-restriction-lock "org-agenda" (&optional 
noupdate))
+(declare-function org-align-tags "org" (&optional all))
+(declare-function org-at-heading-p "org" (&optional ignored))
 (declare-function org-at-table.el-p "org" ())
 (declare-function org-element-at-point "org-element" ())
+(declare-function org-element-context "org-element" (&optional element))
+(declare-function org-element-lineage "org-element" (blob &optional types 
with-self))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-element-property "org-element" (property element))
 (declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
-(declare-function org-link-set-parameters "org" (type &rest rest))
+(declare-function org-get-heading "org" (&optional no-tags no-todo no-priority 
no-comment))
+(declare-function org-get-tags "org" (&optional pos local))
+(declare-function org-link-display-format "ol" (s))
+(declare-function org-link-set-parameters "ol" (type &rest rest))
+(declare-function org-log-into-drawer "org" ())
+(declare-function org-make-tag-string "org" (tags))
+(declare-function org-reduced-level "org" (l))
+(declare-function org-show-context "org" (&optional key))
 (declare-function org-table-end "org-table" (&optional table-type))
 (declare-function outline-next-heading "outline" ())
+(declare-function speedbar-line-directory "speedbar" (&optional depth))
 (declare-function table--at-cell-p "table" (position &optional object 
at-column))
 
+(defvar calendar-mode-map)
+(defvar org-complex-heading-regexp)
+(defvar org-agenda-diary-file)
+(defvar org-agenda-overriding-restriction)
+(defvar org-agenda-restriction-lock-overlay)
 (defvar org-table-any-border-regexp)
 (defvar org-table-dataline-regexp)
 (defvar org-table-tab-recognizes-table.el)
 (defvar org-table1-hline-regexp)
 
+
+;;; Emacs < 27.1 compatibility
+
+(unless (fboundp 'proper-list-p)
+  ;; `proper-list-p' was added in Emacs 27.1.  The function below is
+  ;; taken from Emacs subr.el 200195e824b^.
+  (defun proper-list-p (object)
+    "Return OBJECT's length if it is a proper list, nil otherwise.
+A proper list is neither circular nor dotted (i.e., its last cdr
+is nil)."
+    (and (listp object) (ignore-errors (length object)))))
+
+(if (fboundp 'xor)
+    ;; `xor' was added in Emacs 27.1.
+    (defalias 'org-xor #'xor)
+  (defsubst org-xor (a b)
+    "Exclusive `or'."
+    (if a (not b) b)))
+
+(unless (fboundp 'pcomplete-uniquify-list)
+  ;; The misspelled variant was made obsolete in Emacs 27.1
+  (defalias 'pcomplete-uniquify-list 'pcomplete-uniqify-list))
+
+(if (fboundp 'time-convert)
+    (progn
+      (defsubst org-time-convert-to-integer (time)
+       (time-convert time 'integer))
+      (defsubst org-time-convert-to-list (time)
+       (time-convert time 'list)))
+  (defun org-time-convert-to-integer (time)
+    (floor (float-time time)))
+  (defun org-time-convert-to-list (time)
+    (seconds-to-time (float-time time))))
+
+
+;;; Emacs < 26.1 compatibility
+
+(if (fboundp 'line-number-display-width)
+    (defalias 'org-line-number-display-width 'line-number-display-width)
+  (defun org-line-number-display-width (&rest _) 0))
+
+(if (fboundp 'buffer-hash)
+    (defalias 'org-buffer-hash 'buffer-hash)
+  (defun org-buffer-hash () (md5 (current-buffer))))
+
+(unless (fboundp 'file-attribute-modification-time)
+  (defsubst file-attribute-modification-time (attributes)
+    "The modification time in ATTRIBUTES returned by `file-attributes'.
+This is the time of the last change to the file's contents, and
+is a list of integers (HIGH LOW USEC PSEC) in the same style
+as (current-time)."
+    (nth 5 attributes)))
+
+(unless (fboundp 'file-attribute-size)
+  (defsubst file-attribute-size (attributes)
+    "The size (in bytes) in ATTRIBUTES returned by `file-attributes'.
+This is a floating point number if the size is too large for an integer."
+    (nth 7 attributes)))
+
+
 ;;; Emacs < 25.1 compatibility
 
 (when (< emacs-major-version 25)
   (defalias 'outline-hide-entry 'hide-entry)
   (defalias 'outline-hide-sublevels 'hide-sublevels)
   (defalias 'outline-hide-subtree 'hide-subtree)
-  (defalias 'outline-show-all 'show-all)
   (defalias 'outline-show-branches 'show-branches)
   (defalias 'outline-show-children 'show-children)
   (defalias 'outline-show-entry 'show-entry)
@@ -72,11 +152,49 @@
          (and (memq system-type '(windows-nt ms-dos))
               (= lastc ?\\))))))
 
+;; `string-collate-lessp' is new in Emacs 25.
+(if (fboundp 'string-collate-lessp)
+    (defalias 'org-string-collate-lessp
+      'string-collate-lessp)
+  (defun org-string-collate-lessp (s1 s2 &rest _)
+    "Return non-nil if STRING1 is less than STRING2 in lexicographic order.
+Case is significant."
+    (string< s1 s2)))
+
+;; The time- functions below translate nil to `current-time` and
+;; accept an integer as of Emacs 25.  `decode-time` and
+;; `format-time-string` accept nil on Emacs 24 but don't accept an
+;; integer until Emacs 25.
+(if (< emacs-major-version 25)
+    (let ((convert
+           (lambda (time)
+             (cond ((not time) (current-time))
+                   ((numberp time) (seconds-to-time time))
+                   (t time)))))
+      (defun org-decode-time (&optional time)
+        (decode-time (funcall convert time)))
+      (defun org-format-time-string (format-string &optional time universal)
+        (format-time-string format-string (funcall convert time) universal))
+      (defun org-time-add (a b)
+        (time-add (funcall convert a) (funcall convert b)))
+      (defun org-time-subtract (a b)
+        (time-subtract (funcall convert a) (funcall convert b)))
+      (defun org-time-since (time)
+        (time-since (funcall convert time)))
+      (defun org-time-less-p (t1 t2)
+        (time-less-p (funcall convert t1) (funcall convert t2))))
+  (defalias 'org-decode-time 'decode-time)
+  (defalias 'org-format-time-string 'format-time-string)
+  (defalias 'org-time-add 'time-add)
+  (defalias 'org-time-subtract 'time-subtract)
+  (defalias 'org-time-since 'time-since)
+  (defalias 'org-time-less-p 'time-less-p))
+
 
 ;;; Obsolete aliases (remove them after the next major release).
 
 ;;;; XEmacs compatibility, now removed.
-(define-obsolete-function-alias 'org-activate-mark 'activate-mark)
+(define-obsolete-function-alias 'org-activate-mark 'activate-mark "Org 9.0")
 (define-obsolete-function-alias 'org-add-hook 'add-hook "Org 9.0")
 (define-obsolete-function-alias 'org-bound-and-true-p 'bound-and-true-p "Org 
9.0")
 (define-obsolete-function-alias 'org-decompose-region 'decompose-region "Org 
9.0")
@@ -91,6 +209,7 @@
 (define-obsolete-function-alias 'org-match-string-no-properties 
'match-string-no-properties "Org 9.0")
 (define-obsolete-function-alias 'org-propertize 'propertize "Org 9.0")
 (define-obsolete-function-alias 'org-select-frame-set-input-focus 
'select-frame-set-input-focus "Org 9.0")
+(define-obsolete-function-alias 'org-file-remote-p 'file-remote-p "Org 9.2")
 
 (defmacro org-re (s)
   "Replace posix classes in regular expression S."
@@ -177,6 +296,24 @@ Counting starts at 1."
   'org-activate-links "Org 9.0")
 (define-obsolete-function-alias 'org-activate-plain-links 'ignore "Org 9.0")
 (define-obsolete-function-alias 'org-activate-angle-links 'ignore "Org 9.0")
+(define-obsolete-function-alias 'org-remove-double-quotes 'org-strip-quotes 
"Org 9.0")
+(define-obsolete-function-alias 'org-get-indentation
+  'current-indentation "Org 9.2")
+(define-obsolete-function-alias 'org-capture-member 'org-capture-get "Org 9.2")
+(define-obsolete-function-alias 'org-remove-from-invisibility-spec
+  'remove-from-invisibility-spec "Org 9.2")
+
+(define-obsolete-variable-alias 'org-effort-durations 'org-duration-units
+  "Org 9.2")
+
+(define-obsolete-function-alias 'org-toggle-latex-fragment 'org-latex-preview
+  "Org 9.3")
+
+(define-obsolete-function-alias 'org-remove-latex-fragment-image-overlays
+  'org-clear-latex-preview "Org 9.3")
+
+(define-obsolete-variable-alias 'org-attach-directory
+  'org-attach-id-dir "Org 9.3")
 
 (defun org-in-fixed-width-region-p ()
   "Non-nil if point in a fixed-width region."
@@ -228,9 +365,10 @@ See `org-link-parameters' for documentation on the other 
parameters."
 
 (make-obsolete 'org-add-link-type "use `org-link-set-parameters' instead." 
"Org 9.0")
 
+;;;; Functions unused in Org core.
 (defun org-table-recognize-table.el ()
   "If there is a table.el table nearby, recognize it and move into it."
-  (when (and org-table-tab-recognizes-table.el (org-at-table.el-p))
+  (when (org-at-table.el-p)
     (beginning-of-line)
     (unless (or (looking-at org-table-dataline-regexp)
                 (not (looking-at org-table1-hline-regexp)))
@@ -246,19 +384,33 @@ See `org-link-parameters' for documentation on the other 
parameters."
             (message "recognizing table.el table...done")))
       (error "This should not happen"))))
 
-;; Not used by Org core since commit 6d1e3082, Feb 2010.
+;; Not used since commit 6d1e3082, Feb 2010.
 (make-obsolete 'org-table-recognize-table.el
-               "please notify the org mailing list if you use this function."
+               "please notify Org mailing list if you use this function."
                "Org 9.0")
 
+(defmacro org-preserve-lc (&rest body)
+  (declare (debug (body))
+          (obsolete "please notify Org mailing list if you use this function."
+                    "Org 9.2"))
+  (org-with-gensyms (line col)
+    `(let ((,line (org-current-line))
+          (,col (current-column)))
+       (unwind-protect
+          (progn ,@body)
+        (org-goto-line ,line)
+        (org-move-to-column ,col)))))
+
+(defun org-version-check (version &rest _)
+  "Non-nil if VERSION is lower (older) than `emacs-version'."
+  (declare (obsolete "use `version<' or `fboundp' instead."
+                    "Org 9.2"))
+  (version< version emacs-version))
+
 (defun org-remove-angle-brackets (s)
   (org-unbracket-string "<" ">" s))
 (make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "Org 9.0")
 
-(defun org-remove-double-quotes (s)
-  (org-unbracket-string "\"" "\"" s))
-(make-obsolete 'org-remove-double-quotes 'org-unbracket-string "Org 9.0")
-
 (defcustom org-publish-sitemap-file-entry-format "%t"
   "Format string for site-map file entry.
 You could use brackets to delimit on what part the link will be.
@@ -344,16 +496,137 @@ use of this function is for the stuck project list."
 (define-obsolete-variable-alias 'org-texinfo-def-table-markup
   'org-texinfo-table-default-markup "Org 9.1")
 
-;;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
-;;; This make-obsolete call was added 2016-09-01.
+(define-obsolete-variable-alias 'org-agenda-overriding-columns-format
+  'org-overriding-columns-format "Org 9.2.2")
+
+(define-obsolete-variable-alias 'org-doi-server-url
+  'org-link-doi-server-url "Org 9.3")
+
+(define-obsolete-variable-alias 'org-email-link-description-format
+  'org-link-email-description-format "Org 9.3")
+
+(define-obsolete-variable-alias 'org-make-link-description-function
+  'org-link-make-description-function "Org 9.3")
+
+(define-obsolete-variable-alias 'org-from-is-user-regexp
+  'org-link-from-user-regexp "Org 9.3")
+
+(define-obsolete-variable-alias 'org-descriptive-links
+  'org-link-descriptive "Org 9.3")
+
+(define-obsolete-variable-alias 'org-context-in-file-links
+  'org-link-context-for-files "Org 9.3")
+
+(define-obsolete-variable-alias 'org-keep-stored-link-after-insertion
+  'org-link-keep-stored-after-insertion "Org 9.3")
+
+(define-obsolete-variable-alias 'org-display-internal-link-with-indirect-buffer
+  'org-link-use-indirect-buffer-for-internals "Org 9.3")
+
+(define-obsolete-variable-alias 'org-confirm-shell-link-function
+  'org-link-shell-confirm-function "Org 9.3")
+
+(define-obsolete-variable-alias 'org-confirm-shell-link-not-regexp
+  'org-link-shell-skip-confirm-regexp "Org 9.3")
+
+(define-obsolete-variable-alias 'org-confirm-elisp-link-function
+  'org-link-elisp-confirm-function "Org 9.3")
+
+(define-obsolete-variable-alias 'org-confirm-elisp-link-not-regexp
+  'org-link-elisp-skip-confirm-regexp "Org 9.3")
+
+(define-obsolete-function-alias 'org-file-complete-link
+  'org-link-complete-file "Org 9.3")
+
+(define-obsolete-function-alias 'org-email-link-description
+  'org-link-email-description "Org 9.3")
+
+(define-obsolete-function-alias 'org-make-link-string
+  'org-link-make-string "Org 9.3")
+
+(define-obsolete-function-alias 'org-store-link-props
+  'org-link-store-props "Org 9.3")
+
+(define-obsolete-function-alias 'org-add-link-props
+  'org-link-add-props "Org 9.3")
+
+(define-obsolete-function-alias 'org-make-org-heading-search-string
+  'org-link-heading-search-string "Org 9.3")
+
+(define-obsolete-function-alias 'org-make-link-regexps
+  'org-link-make-regexps "Org 9.3")
+
+(define-obsolete-variable-alias 'org-angle-link-re
+  'org-link-angle-re "Org 9.3")
+
+(define-obsolete-variable-alias 'org-plain-link-re
+  'org-link-plain-re "Org 9.3")
+
+(define-obsolete-variable-alias 'org-bracket-link-regexp
+  'org-link-bracket-re "Org 9.3")
+
+(define-obsolete-variable-alias 'org-bracket-link-analytic-regexp
+  'org-link-bracket-re "Org 9.3")
+
+(define-obsolete-variable-alias 'org-any-link-re
+  'org-link-any-re "Org 9.3")
+
+(define-obsolete-function-alias 'org-open-link-from-string
+  'org-link-open-from-string "Org 9.3")
+
+(define-obsolete-function-alias 'org-add-angle-brackets
+  'org-link-add-angle-brackets "Org 9.3")
+
+;; The function was made obsolete by commit 65399674d5 of 2013-02-22.
+;; This make-obsolete call was added 2016-09-01.
 (make-obsolete 'org-capture-import-remember-templates
               "use the `org-capture-templates' variable instead."
               "Org 9.0")
 
+(defun org-show-block-all ()
+  "Unfold all blocks in the current buffer."
+  (interactive)
+  (remove-overlays nil nil 'invisible 'org-hide-block))
+
+(make-obsolete 'org-show-block-all
+              "use `org-show-all' instead."
+              "Org 9.2")
+
+(define-obsolete-function-alias 'org-get-tags-at 'org-get-tags "Org 9.2")
+
+(defun org-get-local-tags ()
+  "Get a list of tags defined in the current headline."
+  (declare (obsolete "use `org-get-tags' instead." "Org 9.2"))
+  (org-get-tags nil 'local))
+
+(defun org-get-local-tags-at (&optional pos)
+  "Get a list of tags defined in the current headline."
+  (declare (obsolete "use `org-get-tags' instead." "Org 9.2"))
+  (org-get-tags pos 'local))
+
+(defun org-get-tags-string ()
+  "Get the TAGS string in the current headline."
+  (declare (obsolete "use `org-make-tag-string' instead." "Org 9.2"))
+  (org-make-tag-string (org-get-tags nil t)))
+
+(define-obsolete-function-alias 'org-set-tags-to 'org-set-tags "Org 9.2")
+
+(defun org-align-all-tags ()
+  "Align the tags in all headings."
+  (declare (obsolete "use `org-align-tags' instead." "Org 9.2"))
+  (org-align-tags t))
+
+(defmacro org-with-silent-modifications (&rest body)
+  (declare (obsolete "use `with-silent-modifications' instead." "Org 9.2")
+          (debug (body)))
+  `(with-silent-modifications ,@body))
+
+(define-obsolete-function-alias 'org-babel-strip-quotes
+  'org-strip-quotes "Org 9.2")
 
 ;;;; Obsolete link types
 
-(eval-after-load 'org
+(eval-after-load 'ol
   '(progn
      (org-link-set-parameters "file+emacs") ;since Org 9.0
      (org-link-set-parameters "file+sys"))) ;since Org 9.0
@@ -362,38 +635,6 @@ use of this function is for the stuck project list."
 
 ;;; Miscellaneous functions
 
-;; `xor' was added in Emacs 27.1.
-(defalias 'org-xor
-  (if (fboundp 'xor)
-      #'xor
-    (lambda (a b)
-      "Exclusive or."
-      (if a (not b) b))))
-
-(defun org-version-check (version feature level)
-  (let* ((v1 (mapcar 'string-to-number (split-string version "[.]")))
-         (v2 (mapcar 'string-to-number (split-string emacs-version "[.]")))
-         (rmaj (or (nth 0 v1) 99))
-         (rmin (or (nth 1 v1) 99))
-         (rbld (or (nth 2 v1) 99))
-         (maj (or (nth 0 v2) 0))
-         (min (or (nth 1 v2) 0))
-         (bld (or (nth 2 v2) 0)))
-    (if (or (< maj rmaj)
-            (and (= maj rmaj)
-                 (< min rmin))
-            (and (= maj rmaj)
-                 (= min rmin)
-                 (< bld rbld)))
-        (if (eq level :predicate)
-            ;; just return if we have the version
-            nil
-          (let ((msg (format "Emacs %s or greater is recommended for %s"
-                             version feature)))
-            (display-warning 'org msg level)
-            t))
-      t)))
-
 (defun org-get-x-clipboard (value)
   "Get the value of the X or Windows clipboard."
   (cond ((and (eq window-system 'x)
@@ -407,38 +648,13 @@ use of this function is for the stuck project list."
         ((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
          (w32-get-clipboard-data))))
 
-(defun org-add-props (string plist &rest props)
-  "Add text properties to entire string, from beginning to end.
-PLIST may be a list of properties, PROPS are individual properties and values
-that will be added to PLIST.  Returns the string that was modified."
-  (add-text-properties
-   0 (length string) (if props (append plist props) plist) string)
-  string)
-(put 'org-add-props 'lisp-indent-function 2)
-
-(defun org-fit-window-to-buffer (&optional window max-height min-height
-                                           shrink-only)
-  "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
-WINDOW defaults to the selected window.  MAX-HEIGHT and MIN-HEIGHT are
-passed through to `fit-window-to-buffer'.  If SHRINK-ONLY is set, call
-`shrink-window-if-larger-than-buffer' instead, the height limit is
-ignored in this case."
-  (cond ((if (fboundp 'window-full-width-p)
-             (not (window-full-width-p window))
-           ;; do nothing if another window would suffer
-           (> (frame-width) (window-width window))))
-        ((and (fboundp 'fit-window-to-buffer) (not shrink-only))
-         (fit-window-to-buffer window max-height min-height))
-        ((fboundp 'shrink-window-if-larger-than-buffer)
-         (shrink-window-if-larger-than-buffer window)))
-  (or window (selected-window)))
-
 ;; `set-transient-map' is only in Emacs >= 24.4
 (defalias 'org-set-transient-map
   (if (fboundp 'set-transient-map)
       'set-transient-map
     'set-temporary-overlay-map))
 
+
 ;;; Region compatibility
 
 (defvar org-ignore-region nil
@@ -455,20 +671,13 @@ Unlike to `use-region-p', this function also checks
              (> (point) (region-beginning)))
     (exchange-point-and-mark)))
 
+
 ;;; Invisibility compatibility
 
-(defun org-remove-from-invisibility-spec (arg)
-  "Remove elements from `buffer-invisibility-spec'."
-  (if (fboundp 'remove-from-invisibility-spec)
-      (remove-from-invisibility-spec arg)
-    (if (consp buffer-invisibility-spec)
-        (setq buffer-invisibility-spec
-              (delete arg buffer-invisibility-spec)))))
-
 (defun org-in-invisibility-spec-p (arg)
   "Is ARG a member of `buffer-invisibility-spec'?"
-  (if (consp buffer-invisibility-spec)
-      (member arg buffer-invisibility-spec)))
+  (when (consp buffer-invisibility-spec)
+    (member arg buffer-invisibility-spec)))
 
 (defun org-move-to-column (column &optional force _buffer)
   "Move to column COLUMN.
@@ -487,8 +696,8 @@ Pass COLUMN and FORCE to `move-to-column'."
   (let ((start 0) (n 1))
     (while (string-match "\n" s start)
       (setq start (match-end 0) n (1+ n)))
-    (if (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
-        (setq n (1- n)))
+    (when (and (> (length s) 0) (= (aref s (1- (length s))) ?\n))
+      (setq n (1- n)))
     n))
 
 (defun org-kill-new (string &rest args)
@@ -511,16 +720,6 @@ Pass COLUMN and FORCE to `move-to-column'."
       "Return the local name component of FILE."
       (or (file-remote-p file 'localname) file))))
 
-(defmacro org-no-popups (&rest body)
-  "Suppress popup windows.
-Let-bind some variables to nil around BODY to achieve the desired
-effect, which variables to use depends on the Emacs version."
-  (if (org-version-check "24.2.50" "" :predicate)
-      `(let (pop-up-frames display-buffer-alist)
-         ,@body)
-    `(let (pop-up-frames special-display-buffer-names special-display-regexps 
special-display-function)
-       ,@body)))
-
 ;;;###autoload
 (defmacro org-check-version ()
   "Try very hard to provide sensible version strings."
@@ -539,13 +738,10 @@ effect, which variables to use depends on the Emacs 
version."
            (defun org-release () "N/A")
            (defun org-git-version () "N/A !!check installation!!"))))))
 
-(defmacro org-with-silent-modifications (&rest body)
-  (if (fboundp 'with-silent-modifications)
-      `(with-silent-modifications ,@body)
-    `(org-unmodified ,@body)))
-(def-edebug-spec org-with-silent-modifications (body))
 
-;; Functions for Emacs < 24.4 compatibility
+
+;;; Functions for Emacs < 24.4 compatibility
+
 (defun org-define-error (name message)
   "Define NAME as a new error signal.
 MESSAGE is a string that will be output to the echo area if such
@@ -566,6 +762,341 @@ attention to case differences."
            (eq t (compare-strings suffix nil nil
                                   string start-pos nil ignore-case))))))
 
+
+;;; Integration with and fixes for other packages
+
+(defgroup org-imenu-and-speedbar nil
+  "Options concerning imenu and speedbar in Org mode."
+  :tag "Org Imenu and Speedbar"
+  :group 'org-structure)
+
+(defcustom org-imenu-depth 2
+  "The maximum level for Imenu access to Org headlines.
+This also applied for speedbar access."
+  :group 'org-imenu-and-speedbar
+  :type 'integer)
+
+;;;; Imenu
+
+(defvar-local org-imenu-markers nil
+  "All markers currently used by Imenu.")
+
+(defun org-imenu-get-tree ()
+  "Produce the index for Imenu."
+  (dolist (x org-imenu-markers) (move-marker x nil))
+  (setq org-imenu-markers nil)
+  (org-with-wide-buffer
+   (goto-char (point-max))
+   (let* ((re (concat "^" (org-get-limited-outline-regexp)))
+         (subs (make-vector (1+ org-imenu-depth) nil))
+         (last-level 0))
+     (while (re-search-backward re nil t)
+       (let ((level (org-reduced-level (funcall outline-level)))
+            (headline (org-no-properties
+                       (org-link-display-format (org-get-heading t t t t)))))
+        (when (and (<= level org-imenu-depth) (org-string-nw-p headline))
+          (let* ((m (point-marker))
+                 (item (propertize headline 'org-imenu-marker m 'org-imenu t)))
+            (push m org-imenu-markers)
+            (if (>= level last-level)
+                (push (cons item m) (aref subs level))
+              (push (cons item
+                          (cl-mapcan #'identity (cl-subseq subs (1+ level))))
+                    (aref subs level))
+              (cl-loop for i from (1+ level) to org-imenu-depth
+                       do (aset subs i nil)))
+            (setq last-level level)))))
+     (aref subs 1))))
+
+(eval-after-load "imenu"
+  '(progn
+     (add-hook 'imenu-after-jump-hook
+              (lambda ()
+                (when (derived-mode-p 'org-mode)
+                  (org-show-context 'org-goto))))
+     (add-hook 'org-mode-hook
+              (lambda ()
+                (setq imenu-create-index-function 'org-imenu-get-tree)))))
+
+;;;; Speedbar
+
+(defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
+  "Overlay marking the agenda restriction line in speedbar.")
+(overlay-put org-speedbar-restriction-lock-overlay
+            'face 'org-agenda-restriction-lock)
+(overlay-put org-speedbar-restriction-lock-overlay
+            'help-echo "Agendas are currently limited to this item.")
+(delete-overlay org-speedbar-restriction-lock-overlay)
+
+(defun org-speedbar-set-agenda-restriction ()
+  "Restrict future agenda commands to the location at point in speedbar.
+If there is already a restriction lock at the location, remove it.
+
+To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
+  (interactive)
+  (require 'org-agenda)
+  (let (p m tp np dir txt)
+    (cond
+     ((setq p (text-property-any (point-at-bol) (point-at-eol)
+                                'org-imenu t))
+      (setq m (get-text-property p 'org-imenu-marker))
+      (with-current-buffer (marker-buffer m)
+       (goto-char m)
+       (if (and org-agenda-overriding-restriction
+                (member org-agenda-restriction-lock-overlay
+                        (overlays-at (point))))
+           (org-agenda-remove-restriction-lock 'noupdate)
+         (org-agenda-set-restriction-lock 'subtree))))
+     ((setq p (text-property-any (point-at-bol) (point-at-eol)
+                                'speedbar-function 'speedbar-find-file))
+      (setq tp (previous-single-property-change
+               (1+ p) 'speedbar-function)
+           np (next-single-property-change
+               tp 'speedbar-function)
+           dir (speedbar-line-directory)
+           txt (buffer-substring-no-properties (or tp (point-min))
+                                               (or np (point-max))))
+      (with-current-buffer (find-file-noselect
+                           (let ((default-directory dir))
+                             (expand-file-name txt)))
+       (unless (derived-mode-p 'org-mode)
+         (user-error "Cannot restrict to non-Org mode file"))
+       (org-agenda-set-restriction-lock 'file)))
+     (t (user-error "Don't know how to restrict Org mode agenda")))
+    (move-overlay org-speedbar-restriction-lock-overlay
+                 (point-at-bol) (point-at-eol))
+    (setq current-prefix-arg nil)
+    (org-agenda-maybe-redo)))
+
+(defvar speedbar-file-key-map)
+(declare-function speedbar-add-supported-extension "speedbar" (extension))
+(eval-after-load "speedbar"
+  '(progn
+     (speedbar-add-supported-extension ".org")
+     (define-key speedbar-file-key-map "<" 
'org-speedbar-set-agenda-restriction)
+     (define-key speedbar-file-key-map "\C-c\C-x<" 
'org-speedbar-set-agenda-restriction)
+     (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
+     (define-key speedbar-file-key-map "\C-c\C-x>" 
'org-agenda-remove-restriction-lock)
+     (add-hook 'speedbar-visiting-tag-hook
+              (lambda () (and (derived-mode-p 'org-mode) (org-show-context 
'org-goto))))))
+
+;;;; Add Log
+
+(defun org-add-log-current-headline ()
+  "Return current headline or nil.
+This function ignores inlinetasks.  It is meant to be used as
+`add-log-current-defun-function' value."
+  (org-with-limited-levels (org-get-heading t t t t)))
+
+;;;; Flyspell
+
+(defun org--flyspell-object-check-p (element)
+  "Non-nil when Flyspell can check object at point.
+ELEMENT is the element at point."
+  (let ((object (save-excursion
+                 (when (looking-at-p "\\>") (backward-char))
+                 (org-element-context element))))
+    (cl-case (org-element-type object)
+      ;; Prevent checks in links due to keybinding conflict with
+      ;; Flyspell.
+      ((code entity export-snippet inline-babel-call
+            inline-src-block line-break latex-fragment link macro
+            statistics-cookie target timestamp verbatim)
+       nil)
+      (footnote-reference
+       ;; Only in inline footnotes, within the definition.
+       (and (eq (org-element-property :type object) 'inline)
+           (< (save-excursion
+                (goto-char (org-element-property :begin object))
+                (search-forward ":" nil t 2))
+              (point))))
+      (otherwise t))))
+
+(defun org-mode-flyspell-verify ()
+  "Function used for `flyspell-generic-check-word-predicate'."
+  (if (org-at-heading-p)
+      ;; At a headline or an inlinetask, check title only.  This is
+      ;; faster than relying on `org-element-at-point'.
+      (and (save-excursion (beginning-of-line)
+                          (and (let ((case-fold-search t))
+                                 (not (looking-at-p "\\*+ END[ \t]*$")))
+                               (let ((case-fold-search nil))
+                                 (looking-at org-complex-heading-regexp))))
+          (match-beginning 4)
+          (>= (point) (match-beginning 4))
+          (or (not (match-beginning 5))
+              (< (point) (match-beginning 5))))
+    (let* ((element (org-element-at-point))
+          (post-affiliated (org-element-property :post-affiliated element)))
+      (cond
+       ;; Ignore checks in all affiliated keywords but captions.
+       ((< (point) post-affiliated)
+       (and (save-excursion
+              (beginning-of-line)
+              (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
+            (> (point) (match-end 0))
+            (org--flyspell-object-check-p element)))
+       ;; Ignore checks in LOGBOOK (or equivalent) drawer.
+       ((let ((log (org-log-into-drawer)))
+         (and log
+              (let ((drawer (org-element-lineage element '(drawer))))
+                (and drawer
+                     (eq (compare-strings
+                          log nil nil
+                          (org-element-property :drawer-name drawer) nil nil t)
+                         t)))))
+       nil)
+       (t
+       (cl-case (org-element-type element)
+         ((comment quote-section) t)
+         (comment-block
+          ;; Allow checks between block markers, not on them.
+          (and (> (line-beginning-position) post-affiliated)
+               (save-excursion
+                 (end-of-line)
+                 (skip-chars-forward " \r\t\n")
+                 (< (point) (org-element-property :end element)))))
+         ;; Arbitrary list of keywords where checks are meaningful.
+         ;; Make sure point is on the value part of the element.
+         (keyword
+          (and (member (org-element-property :key element)
+                       '("DESCRIPTION" "TITLE"))
+               (save-excursion
+                 (search-backward ":" (line-beginning-position) t))))
+         ;; Check is globally allowed in paragraphs verse blocks and
+         ;; table rows (after affiliated keywords) but some objects
+         ;; must not be affected.
+         ((paragraph table-row verse-block)
+          (let ((cbeg (org-element-property :contents-begin element))
+                (cend (org-element-property :contents-end element)))
+            (and cbeg (>= (point) cbeg) (< (point) cend)
+                 (org--flyspell-object-check-p element))))))))))
+(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
+
+(defun org-remove-flyspell-overlays-in (beg end)
+  "Remove flyspell overlays in region."
+  (and (bound-and-true-p flyspell-mode)
+       (fboundp 'flyspell-delete-region-overlays)
+       (flyspell-delete-region-overlays beg end)))
+
+(defvar flyspell-delayed-commands)
+(eval-after-load "flyspell"
+  '(add-to-list 'flyspell-delayed-commands 'org-self-insert-command))
+
+;;;; Bookmark
+
+(defun org-bookmark-jump-unhide ()
+  "Unhide the current position, to show the bookmark location."
+  (and (derived-mode-p 'org-mode)
+       (or (org-invisible-p)
+          (save-excursion (goto-char (max (point-min) (1- (point))))
+                          (org-invisible-p)))
+       (org-show-context 'bookmark-jump)))
+
+;; Make `bookmark-jump' shows the jump location if it was hidden.
+(eval-after-load "bookmark"
+  '(if (boundp 'bookmark-after-jump-hook)
+       ;; We can use the hook
+       (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
+     ;; Hook not available, use advice
+     (defadvice bookmark-jump (after org-make-visible activate)
+       "Make the position visible."
+       (org-bookmark-jump-unhide))))
+
+;;;; Calendar
+
+(defcustom org-calendar-to-agenda-key 'default
+  "Key to be installed in `calendar-mode-map' for switching to the agenda.
+
+The command `org-calendar-goto-agenda' will be bound to this key.
+
+When set to `default', bind the function to `c', but only if it is
+available in the Calendar keymap.  This is the default choice because
+`c' can then be used to switch back and forth between agenda and calendar.
+
+When nil, `org-calendar-goto-agenda' is not bound to any key."
+  :group 'org-agenda
+  :type '(choice
+         (const :tag "Bind to `c' if available" default)
+         (key-sequence :tag "Other binding")
+         (const :tag "No binding" nil))
+  :safe (lambda (v) (or (symbolp v) (stringp v)))
+  :package-version '(Org . "9.2"))
+
+(defcustom org-calendar-insert-diary-entry-key [?i]
+  "The key to be installed in `calendar-mode-map' for adding diary entries.
+This option is irrelevant until `org-agenda-diary-file' has been configured
+to point to an Org file.  When that is the case, the command
+`org-agenda-diary-entry' will be bound to the key given here, by default
+`i'.  In the calendar, `i' normally adds entries to `diary-file'.  So
+if you want to continue doing this, you need to change this to a different
+key."
+  :group 'org-agenda
+  :type 'sexp)
+
+(defun org--setup-calendar-bindings ()
+  "Bind Org functions in Calendar keymap."
+  (pcase org-calendar-to-agenda-key
+    (`nil nil)
+    ((and key (pred stringp))
+     (local-set-key (kbd key) #'org-calendar-goto-agenda))
+    ((guard (not (lookup-key calendar-mode-map "c")))
+     (local-set-key "c" #'org-calendar-goto-agenda))
+    (_ nil))
+  (unless (eq org-agenda-diary-file 'diary-file)
+    (local-set-key org-calendar-insert-diary-entry-key
+                  #'org-agenda-diary-entry)))
+
+(eval-after-load "calendar"
+  '(add-hook 'calendar-mode-hook #'org--setup-calendar-bindings))
+
+;;;; Saveplace
+
+;; Make sure saveplace shows the location if it was hidden
+(eval-after-load "saveplace"
+  '(defadvice save-place-find-file-hook (after org-make-visible activate)
+     "Make the position visible."
+     (org-bookmark-jump-unhide)))
+
+;;;; Ecb
+
+;; Make sure ecb shows the location if it was hidden
+(eval-after-load "ecb"
+  '(defadvice ecb-method-clicked (after esf/org-show-context activate)
+     "Make hierarchy visible when jumping into location from ECB tree buffer."
+     (when (derived-mode-p 'org-mode)
+       (org-show-context))))
+
+;;;; Simple
+
+(defun org-mark-jump-unhide ()
+  "Make the point visible with `org-show-context' after jumping to the mark."
+  (when (and (derived-mode-p 'org-mode)
+            (org-invisible-p))
+    (org-show-context 'mark-goto)))
+
+(eval-after-load "simple"
+  '(defadvice pop-to-mark-command (after org-make-visible activate)
+     "Make the point visible with `org-show-context'."
+     (org-mark-jump-unhide)))
+
+(eval-after-load "simple"
+  '(defadvice exchange-point-and-mark (after org-make-visible activate)
+     "Make the point visible with `org-show-context'."
+     (org-mark-jump-unhide)))
+
+(eval-after-load "simple"
+  '(defadvice pop-global-mark (after org-make-visible activate)
+     "Make the point visible with `org-show-context'."
+     (org-mark-jump-unhide)))
+
+;;;; Session
+
+;; Make "session.el" ignore our circular variable.
+(defvar session-globals-exclude)
+(eval-after-load "session"
+  '(add-to-list 'session-globals-exclude 'org-mark-ring))
+
 (provide 'org-compat)
 
 ;;; org-compat.el ends here
diff --git a/lisp/org/org-crypt.el b/lisp/org/org-crypt.el
index 9cd76c9..1bdf623 100644
--- a/lisp/org/org-crypt.el
+++ b/lisp/org/org-crypt.el
@@ -190,7 +190,7 @@ See `org-crypt-disable-auto-save'."
             (error (insert contents) (error (nth 1 err)))))
         (when folded
           (goto-char start-heading)
-          (outline-hide-subtree))
+          (org-flag-subtree t))
         nil)))))
 
 (defun org-decrypt-entry ()
diff --git a/lisp/org/org-duration.el b/lisp/org/org-duration.el
index 770c72f..e350bc7 100644
--- a/lisp/org/org-duration.el
+++ b/lisp/org/org-duration.el
@@ -51,7 +51,6 @@
 
 (require 'cl-lib)
 (require 'org-macs)
-(declare-function org-trim "org" (s &optional keep-lead))
 
 
 ;;; Public variables
diff --git a/lisp/org/org-element.el b/lisp/org/org-element.el
index 04e2fda..56b3cc4 100644
--- a/lisp/org/org-element.el
+++ b/lisp/org/org-element.el
@@ -58,10 +58,55 @@
 
 ;;; Code:
 
-(require 'org)
 (require 'avl-tree)
 (require 'cl-lib)
-
+(require 'ol)
+(require 'org)
+(require 'org-compat)
+(require 'org-entities)
+(require 'org-footnote)
+(require 'org-list)
+(require 'org-macs)
+(require 'org-table)
+
+(declare-function org-at-heading-p "org" (&optional _))
+(declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
+(declare-function org-escape-code-in-string "org-src" (s))
+(declare-function org-find-visible "org" ())
+(declare-function org-macro-escape-arguments "org-macro" (&rest args))
+(declare-function org-macro-extract-arguments "org-macro" (s))
+(declare-function org-reduced-level "org" (l))
+(declare-function org-unescape-code-in-string "org-src" (s))
+(declare-function outline-next-heading "outline" ())
+(declare-function outline-previous-heading "outline" ())
+
+(defvar org-archive-tag)
+(defvar org-clock-line-re)
+(defvar org-closed-string)
+(defvar org-comment-string)
+(defvar org-complex-heading-regexp)
+(defvar org-dblock-start-re)
+(defvar org-deadline-string)
+(defvar org-done-keywords)
+(defvar org-drawer-regexp)
+(defvar org-edit-src-content-indentation)
+(defvar org-emph-re)
+(defvar org-emphasis-regexp-components)
+(defvar org-keyword-time-not-clock-regexp)
+(defvar org-match-substring-regexp)
+(defvar org-odd-levels-only)
+(defvar org-outline-regexp-bol)
+(defvar org-planning-line-re)
+(defvar org-property-drawer-re)
+(defvar org-property-format)
+(defvar org-property-re)
+(defvar org-scheduled-string)
+(defvar org-src-preserve-indentation)
+(defvar org-tags-column)
+(defvar org-time-stamp-formats)
+(defvar org-todo-regexp)
+(defvar org-ts-regexp-both)
+(defvar org-verbatim-re)
 
 
 ;;; Definitions And Rules
@@ -91,7 +136,7 @@ specially in `org-element--object-lex'.")
   (setq org-element-paragraph-separate
        (concat "^\\(?:"
                ;; Headlines, inlinetasks.
-               org-outline-regexp "\\|"
+               "\\*+ " "\\|"
                ;; Footnote definitions.
                "\\[fn:[-_[:word:]]+\\]" "\\|"
                ;; Diary sexps.
@@ -117,7 +162,7 @@ specially in `org-element--object-lex'.")
                ;; LaTeX environments.
                "\\\\begin{\\([A-Za-z0-9*]+\\)}" "\\|"
                ;; Clock lines.
-               (regexp-quote org-clock-string) "\\|"
+               "CLOCK:" "\\|"
                ;; Lists.
                (let ((term (pcase org-plain-list-ordered-item-terminator
                              (?\) ")") (?. "\\.") (_ "[.)]")))
@@ -307,8 +352,9 @@ Don't modify it, set `org-element-affiliated-keywords' 
instead.")
       (strike-through ,@standard-set)
       (subscript ,@standard-set)
       (superscript ,@standard-set)
-      ;; Ignore inline babel call and inline src block as formulas are
-      ;; possible.  Also ignore line breaks and statistics cookies.
+      ;; Ignore inline babel call and inline source block as formulas
+      ;; are possible.  Also ignore line breaks and statistics
+      ;; cookies.
       (table-cell bold code entity export-snippet footnote-reference italic
                  latex-fragment link macro radio-target strike-through
                  subscript superscript target timestamp underline verbatim)
@@ -491,6 +537,7 @@ objects, or a strings.
 
 The function takes care of setting `:parent' property for CHILD.
 Return parent element."
+  (declare (indent 1))
   (if (not children) parent
     ;; Link every child to PARENT. If PARENT is nil, it is a secondary
     ;; string: parent is the list itself.
@@ -677,7 +724,7 @@ Assume point is at the beginning of the block."
 (defun org-element-center-block-interpreter (_ contents)
   "Interpret a center-block element as Org syntax.
 CONTENTS is the contents of the element."
-  (format "#+BEGIN_CENTER\n%s#+END_CENTER" contents))
+  (format "#+begin_center\n%s#+end_center" contents))
 
 
 ;;;; Drawer
@@ -787,7 +834,7 @@ Assume point is at beginning of dynamic block."
 (defun org-element-dynamic-block-interpreter (dynamic-block contents)
   "Interpret DYNAMIC-BLOCK element as Org syntax.
 CONTENTS is the contents of the element."
-  (format "#+BEGIN: %s%s\n%s#+END:"
+  (format "#+begin: %s%s\n%s#+end:"
          (org-element-property :block-name dynamic-block)
          (let ((args (org-element-property :arguments dynamic-block)))
            (if args (concat " " args) ""))
@@ -812,7 +859,8 @@ their value.
 
 Return a list whose CAR is `footnote-definition' and CDR is
 a plist containing `:label', `:begin' `:end', `:contents-begin',
-`:contents-end', `:post-blank' and `:post-affiliated' keywords.
+`:contents-end', `:pre-blank',`:post-blank' and
+`:post-affiliated' keywords.
 
 Assume point is at the beginning of the footnote definition."
   (save-excursion
@@ -838,12 +886,16 @@ Assume point is at the beginning of the footnote 
definition."
               ((eq ?* (char-after (match-beginning 0))) (match-beginning 0))
               (t (skip-chars-forward " \r\t\n" limit)
                  (if (= limit (point)) limit (line-beginning-position))))))
+          (pre-blank 0)
           (contents-begin
            (progn (search-forward "]")
                   (skip-chars-forward " \r\t\n" end)
                   (cond ((= (point) end) nil)
                         ((= (line-beginning-position) post-affiliated) (point))
-                        (t (line-beginning-position)))))
+                        (t
+                         (setq pre-blank
+                               (count-lines (line-beginning-position) begin))
+                         (line-beginning-position)))))
           (contents-end
            (progn (goto-char end)
                   (skip-chars-backward " \r\t\n")
@@ -855,6 +907,7 @@ Assume point is at the beginning of the footnote 
definition."
                   :end end
                   :contents-begin contents-begin
                   :contents-end (and contents-begin contents-end)
+                  :pre-blank pre-blank
                   :post-blank (count-lines contents-end end)
                   :post-affiliated post-affiliated)
             (cdr affiliated))))))
@@ -862,9 +915,18 @@ Assume point is at the beginning of the footnote 
definition."
 (defun org-element-footnote-definition-interpreter (footnote-definition 
contents)
   "Interpret FOOTNOTE-DEFINITION element as Org syntax.
 CONTENTS is the contents of the footnote-definition."
-  (concat (format "[fn:%s]" (org-element-property :label footnote-definition))
-         " "
-         contents))
+  (let ((pre-blank
+        (min (or (org-element-property :pre-blank footnote-definition)
+                 ;; 0 is specific to paragraphs at the beginning of
+                 ;; the footnote definition, so we use 1 as
+                 ;; a fall-back value, which is more universal.
+                 1)
+             ;; Footnote ends after more than two consecutive empty
+             ;; lines: limit ourselves to 2 newline characters.
+             2)))
+    (concat (format "[fn:%s]" (org-element-property :label 
footnote-definition))
+           (if (= pre-blank 0) (concat " " (org-trim contents))
+             (concat (make-string pre-blank ?\n) contents)))))
 
 
 ;;;; Headline
@@ -911,7 +973,7 @@ Return value is a plist."
 Return a list whose CAR is `headline' and CDR is a plist
 containing `:raw-value', `:title', `:begin', `:end',
 `:pre-blank', `:contents-begin' and `:contents-end', `:level',
-`:priority', `:tags', `:todo-keyword',`:todo-type', `:scheduled',
+`:priority', `:tags', `:todo-keyword', `:todo-type', `:scheduled',
 `:deadline', `:closed', `:archivedp', `:commentedp'
 `:footnote-section-p', `:post-blank' and `:post-affiliated'
 keywords.
@@ -931,10 +993,10 @@ Assume point is at beginning of the headline."
           (level (prog1 (org-reduced-level (skip-chars-forward "*"))
                    (skip-chars-forward " \t")))
           (todo (and org-todo-regexp
-                     (let (case-fold-search) (looking-at org-todo-regexp))
+                     (let (case-fold-search) (looking-at (concat 
org-todo-regexp " ")))
                      (progn (goto-char (match-end 0))
                             (skip-chars-forward " \t")
-                            (match-string 0))))
+                            (match-string 1))))
           (todo-type
            (and todo (if (member todo org-done-keywords) 'done 'todo)))
           (priority (and (looking-at "\\[#.\\][ \t]*")
@@ -1172,18 +1234,18 @@ CONTENTS is the contents of inlinetask."
                (concat
                 (make-string
                  (max (- (+ org-tags-column (length task) (length tags))) 1)
-                 ? )
+                 ?\s)
                 tags))
               (t
                (concat
-                (make-string (max (- org-tags-column (length task)) 1) ? )
+                (make-string (max (- org-tags-column (length task)) 1) ?\s)
                 tags))))
            ;; Prefer degenerate inlinetasks when there are no
            ;; contents.
            (when contents
              (concat "\n"
                      contents
-                     (make-string level ?*) " END")))))
+                     (make-string level ?*) " end")))))
 
 
 ;;;; Item
@@ -1195,8 +1257,8 @@ STRUCT is the structure of the plain list.
 
 Return a list whose CAR is `item' and CDR is a plist containing
 `:bullet', `:begin', `:end', `:contents-begin', `:contents-end',
-`:checkbox', `:counter', `:tag', `:structure', `:post-blank' and
-`:post-affiliated' keywords.
+`:checkbox', `:counter', `:tag', `:structure', `:pre-blank',
+`:post-blank' and `:post-affiliated' keywords.
 
 When optional argument RAW-SECONDARY-P is non-nil, item's tag, if
 any, will not be parsed as a secondary string, but as a plain
@@ -1223,20 +1285,25 @@ Assume point is at the beginning of the item."
                          (string-to-number (match-string 0 c)))))))
           (end (progn (goto-char (nth 6 (assq (point) struct)))
                       (if (bolp) (point) (line-beginning-position 2))))
+          (pre-blank 0)
           (contents-begin
-           (progn (goto-char
-                   ;; Ignore tags in un-ordered lists: they are just
-                   ;; a part of item's body.
-                   (if (and (match-beginning 4)
-                            (save-match-data (string-match "[.)]" bullet)))
-                       (match-beginning 4)
-                     (match-end 0)))
-                  (skip-chars-forward " \r\t\n" end)
-                  (cond ((= (point) end) nil)
-                        ;; If first line isn't empty, contents really
-                        ;; start at the text after item's meta-data.
-                        ((= (line-beginning-position) begin) (point))
-                        (t (line-beginning-position)))))
+           (progn
+             (goto-char
+              ;; Ignore tags in un-ordered lists: they are just
+              ;; a part of item's body.
+              (if (and (match-beginning 4)
+                       (save-match-data (string-match "[.)]" bullet)))
+                  (match-beginning 4)
+                (match-end 0)))
+             (skip-chars-forward " \r\t\n" end)
+             (cond ((= (point) end) nil)
+                   ;; If first line isn't empty, contents really
+                   ;; start at the text after item's meta-data.
+                   ((= (line-beginning-position) begin) (point))
+                   (t
+                    (setq pre-blank
+                          (count-lines (line-beginning-position) begin))
+                    (line-beginning-position)))))
           (contents-end (and contents-begin
                              (progn (goto-char end)
                                     (skip-chars-backward " \r\t\n")
@@ -1251,6 +1318,7 @@ Assume point is at the beginning of the item."
                        :checkbox checkbox
                        :counter counter
                        :structure struct
+                       :pre-blank pre-blank
                        :post-blank (count-lines (or contents-end begin) end)
                        :post-affiliated begin))))
       (org-element-put-property
@@ -1266,35 +1334,43 @@ Assume point is at the beginning of the item."
 (defun org-element-item-interpreter (item contents)
   "Interpret ITEM element as Org syntax.
 CONTENTS is the contents of the element."
-  (let* ((bullet (let ((bullet (org-element-property :bullet item)))
-                  (org-list-bullet-string
-                   (cond ((not (string-match "[0-9a-zA-Z]" bullet)) "- ")
-                         ((eq org-plain-list-ordered-item-terminator ?\)) "1)")
-                         (t "1.")))))
-        (checkbox (org-element-property :checkbox item))
-        (counter (org-element-property :counter item))
-        (tag (let ((tag (org-element-property :tag item)))
-               (and tag (org-element-interpret-data tag))))
-        ;; Compute indentation.
-        (ind (make-string (length bullet) 32))
-        (item-starts-with-par-p
-         (eq (org-element-type (car (org-element-contents item)))
-             'paragraph)))
-    ;; Indent contents.
+  (let ((tag (pcase (org-element-property :tag item)
+              (`nil nil)
+              (tag (format "%s :: " (org-element-interpret-data tag)))))
+       (bullet
+        (org-list-bullet-string
+         (cond
+          ((not (string-match-p "[0-9a-zA-Z]"
+                                (org-element-property :bullet item))) "- ")
+          ((eq org-plain-list-ordered-item-terminator ?\)) "1)")
+          (t "1.")))))
     (concat
      bullet
-     (and counter (format "[@%d] " counter))
-     (pcase checkbox
+     (pcase (org-element-property :counter item)
+       (`nil nil)
+       (counter (format "[@%d] " counter)))
+     (pcase (org-element-property :checkbox item)
        (`on "[X] ")
        (`off "[ ] ")
        (`trans "[-] ")
        (_ nil))
-     (and tag (format "%s :: " tag))
+     tag
      (when contents
-       (let ((contents (replace-regexp-in-string
-                       "\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))
-        (if item-starts-with-par-p (org-trim contents)
-          (concat "\n" contents)))))))
+       (let* ((ind (make-string (if tag 5 (length bullet)) ?\s))
+             (pre-blank
+              (min (or (org-element-property :pre-blank item)
+                       ;; 0 is specific to paragraphs at the
+                       ;; beginning of the item, so we use 1 as
+                       ;; a fall-back value, which is more universal.
+                       1)
+                   ;; Lists ends after more than two consecutive
+                   ;; empty lines: limit ourselves to 2 newline
+                   ;; characters.
+                   2))
+             (contents (replace-regexp-in-string
+                        "\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))
+        (if (= pre-blank 0) (org-trim contents)
+          (concat (make-string pre-blank ?\n) contents)))))))
 
 
 ;;;; Plain List
@@ -1516,7 +1592,7 @@ Assume point is at the beginning of the block."
 (defun org-element-quote-block-interpreter (_ contents)
   "Interpret quote-block element as Org syntax.
 CONTENTS is the contents of the element."
-  (format "#+BEGIN_QUOTE\n%s#+END_QUOTE" contents))
+  (format "#+begin_quote\n%s#+end_quote" contents))
 
 
 ;;;; Section
@@ -1602,7 +1678,7 @@ Assume point is at the beginning of the block."
   "Interpret SPECIAL-BLOCK element as Org syntax.
 CONTENTS is the contents of the element."
   (let ((block-type (org-element-property :type special-block)))
-    (format "#+BEGIN_%s\n%s#+END_%s" block-type contents block-type)))
+    (format "#+begin_%s\n%s#+end_%s" block-type contents block-type)))
 
 
 
@@ -1670,7 +1746,7 @@ containing `:call', `:inside-header', `:arguments',
 
 (defun org-element-babel-call-interpreter (babel-call _)
   "Interpret BABEL-CALL element as Org syntax."
-  (concat "#+CALL: "
+  (concat "#+call: "
          (org-element-property :call babel-call)
          (let ((h (org-element-property :inside-header babel-call)))
            (and h (format "[%s]" h)))
@@ -1692,7 +1768,7 @@ Return a list whose CAR is `clock' and CDR is a plist 
containing
   (save-excursion
     (let* ((case-fold-search nil)
           (begin (point))
-          (value (progn (search-forward org-clock-string (line-end-position) t)
+          (value (progn (search-forward "CLOCK:" (line-end-position) t)
                         (skip-chars-forward " \t")
                         (org-element-timestamp-parser)))
           (duration (and (search-forward " => " (line-end-position) t)
@@ -1717,7 +1793,7 @@ Return a list whose CAR is `clock' and CDR is a plist 
containing
 
 (defun org-element-clock-interpreter (clock _)
   "Interpret CLOCK element as Org syntax."
-  (concat org-clock-string " "
+  (concat "CLOCK: "
          (org-element-timestamp-interpreter
           (org-element-property :value clock) nil)
          (let ((duration (org-element-property :duration clock)))
@@ -1824,7 +1900,7 @@ Assume point is at comment block beginning."
 
 (defun org-element-comment-block-interpreter (comment-block _)
   "Interpret COMMENT-BLOCK element as Org syntax."
-  (format "#+BEGIN_COMMENT\n%s#+END_COMMENT"
+  (format "#+begin_comment\n%s#+end_comment"
          (org-element-normalize-string
           (org-remove-indentation
            (org-element-property :value comment-block)))))
@@ -1951,15 +2027,22 @@ containing `:begin', `:end', `:number-lines', 
`:preserve-indent',
 (defun org-element-example-block-interpreter (example-block _)
   "Interpret EXAMPLE-BLOCK element as Org syntax."
   (let ((switches (org-element-property :switches example-block))
-       (value (org-element-property :value example-block)))
-    (concat "#+BEGIN_EXAMPLE" (and switches (concat " " switches)) "\n"
-           (org-element-normalize-string
-            (org-escape-code-in-string
-             (if (or org-src-preserve-indentation
-                     (org-element-property :preserve-indent example-block))
-                 value
-               (org-remove-indentation value))))
-           "#+END_EXAMPLE")))
+       (value
+        (let ((val (org-element-property :value example-block)))
+          (cond
+           ((or org-src-preserve-indentation
+                (org-element-property :preserve-indent example-block))
+            val)
+           ((= 0 org-edit-src-content-indentation)
+            (org-remove-indentation val))
+           (t
+            (let ((ind (make-string org-edit-src-content-indentation ?\s)))
+              (replace-regexp-in-string "^[ \t]*\\S-"
+                                        (concat ind "\\&")
+                                        (org-remove-indentation val))))))))
+    (concat "#+begin_example" (and switches (concat " " switches)) "\n"
+           (org-element-normalize-string (org-escape-code-in-string value))
+           "#+end_example")))
 
 
 ;;;; Export Block
@@ -2012,7 +2095,7 @@ Assume point is at export-block beginning."
 
 (defun org-element-export-block-interpreter (export-block _)
   "Interpret EXPORT-BLOCK element as Org syntax."
-  (format "#+BEGIN_EXPORT %s\n%s#+END_EXPORT"
+  (format "#+begin_export %s\n%s#+end_export"
          (org-element-property :type export-block)
          (org-element-property :value export-block)))
 
@@ -2035,26 +2118,22 @@ Assume point is at the beginning of the fixed-width 
area."
   (save-excursion
     (let* ((begin (car affiliated))
           (post-affiliated (point))
-          value
           (end-area
            (progn
              (while (and (< (point) limit)
                          (looking-at "[ \t]*:\\( \\|$\\)"))
-               ;; Accumulate text without starting colons.
-               (setq value
-                     (concat value
-                             (buffer-substring-no-properties
-                              (match-end 0) (point-at-eol))
-                             "\n"))
                (forward-line))
-             (point)))
+             (if (bolp) (line-end-position 0) (point))))
           (end (progn (skip-chars-forward " \r\t\n" limit)
                       (if (eobp) (point) (line-beginning-position)))))
       (list 'fixed-width
            (nconc
             (list :begin begin
                   :end end
-                  :value value
+                  :value (replace-regexp-in-string
+                          "^[ \t]*: ?" ""
+                          (buffer-substring-no-properties post-affiliated
+                                                          end-area))
                   :post-blank (count-lines end-area end)
                   :post-affiliated post-affiliated)
             (cdr affiliated))))))
@@ -2062,10 +2141,7 @@ Assume point is at the beginning of the fixed-width 
area."
 (defun org-element-fixed-width-interpreter (fixed-width _)
   "Interpret FIXED-WIDTH element as Org syntax."
   (let ((value (org-element-property :value fixed-width)))
-    (and value
-        (replace-regexp-in-string
-         "^" ": "
-         (if (string-match "\n\\'" value) (substring value 0 -1) value)))))
+    (and value (replace-regexp-in-string "^" ": " value))))
 
 
 ;;;; Horizontal Rule
@@ -2139,7 +2215,7 @@ containing `:key', `:value', `:begin', `:end', 
`:post-blank' and
 (defun org-element-keyword-interpreter (keyword _)
   "Interpret KEYWORD element as Org syntax."
   (format "#+%s: %s"
-         (org-element-property :key keyword)
+         (downcase (org-element-property :key keyword))
          (org-element-property :value keyword)))
 
 
@@ -2369,7 +2445,7 @@ containing `:closed', `:deadline', `:scheduled', `:begin',
 ;;;; Src Block
 
 (defun org-element-src-block-parser (limit affiliated)
-  "Parse a src block.
+  "Parse a source block.
 
 LIMIT bounds the search.  AFFILIATED is a list of which CAR is
 the buffer position at the beginning of the first affiliated
@@ -2425,7 +2501,7 @@ Assume point is at the beginning of the block."
                       (string-match "-l +\"\\([^\"\n]+\\)\"" switches)
                       (match-string 1 switches)))
                 ;; Should labels be retained in (or stripped from)
-                ;; src blocks?
+                ;; source blocks?
                 (retain-labels
                  (or (not switches)
                      (not (string-match "-r\\>" switches))
@@ -2480,14 +2556,14 @@ Assume point is at the beginning of the block."
             (org-remove-indentation val))
            (t
             (let ((ind (make-string org-edit-src-content-indentation ?\s)))
-              (replace-regexp-in-string
-               "^" ind (org-remove-indentation val))))))))
-    (concat (format "#+BEGIN_SRC%s\n"
-                   (concat (and lang (concat " " lang))
-                           (and switches (concat " " switches))
-                           (and params (concat " " params))))
-           (org-element-normalize-string (org-escape-code-in-string value))
-           "#+END_SRC")))
+              (replace-regexp-in-string "^[ \t]*\\S-"
+                                        (concat ind "\\&")
+                                        (org-remove-indentation val))))))))
+    (format "#+begin_src%s\n%s#+end_src"
+           (concat (and lang (concat " " lang))
+                   (and switches (concat " " switches))
+                   (and params (concat " " params)))
+           (org-element-normalize-string (org-escape-code-in-string value)))))
 
 
 ;;;; Table
@@ -2635,7 +2711,7 @@ Assume point is at beginning of the block."
 (defun org-element-verse-block-interpreter (_ contents)
   "Interpret verse-block element as Org syntax.
 CONTENTS is verse block contents."
-  (format "#+BEGIN_VERSE\n%s#+END_VERSE" contents))
+  (format "#+begin_verse\n%s#+end_verse" contents))
 
 
 
@@ -2803,7 +2879,7 @@ Assume point is at the beginning of the snippet."
 
 When at a footnote reference, return a list whose car is
 `footnote-reference' and cdr a plist with `:label', `:type',
-`:begin', `:end', `:content-begin', `:contents-end' and
+`:begin', `:end', `:contents-begin', `:contents-end' and
 `:post-blank' as keywords.  Otherwise, return nil."
   (when (looking-at org-footnote-re)
     (let ((closing (with-syntax-table org-element--pair-square-table
@@ -2899,7 +2975,7 @@ When at an inline source block, return a list whose car is
 `:language', `:value', `:parameters' and `:post-blank' as
 keywords.  Otherwise, return nil.
 
-Assume point is at the beginning of the inline src block."
+Assume point is at the beginning of the inline source block."
   (save-excursion
     (catch :no-object
       (when (let ((case-fold-search nil))
@@ -3066,13 +3142,13 @@ Assume point is at the beginning of the link."
        (setq contents-begin (match-beginning 1))
        (setq contents-end (match-end 1)))
        ;; Type 2: Standard link, i.e. [[https://orgmode.org][homepage]]
-       ((looking-at org-bracket-link-regexp)
+       ((looking-at org-link-bracket-re)
        (setq format 'bracket)
-       (setq contents-begin (match-beginning 3))
-       (setq contents-end (match-end 3))
+       (setq contents-begin (match-beginning 2))
+       (setq contents-end (match-end 2))
        (setq link-end (match-end 0))
-       ;; RAW-LINK is the original link.  Expand any
-       ;; abbreviation in it.
+       ;; RAW-LINK is the original link.  Decode any encoding.
+       ;; Expand any abbreviation in it.
        ;;
        ;; Also treat any newline character and associated
        ;; indentation as a single space character.  This is not
@@ -3083,9 +3159,10 @@ Assume point is at the beginning of the link."
        ;; [[shell:ls *.org]], which defeats Org's focus on
        ;; simplicity.
        (setq raw-link (org-link-expand-abbrev
-                       (replace-regexp-in-string
-                        "[ \t]*\n[ \t]*" " "
-                        (match-string-no-properties 1))))
+                       (org-link-unescape
+                        (replace-regexp-in-string
+                         "[ \t]*\n[ \t]*" " "
+                         (match-string-no-properties 1)))))
        ;; Determine TYPE of link and set PATH accordingly.  According
        ;; to RFC 3986, remove whitespaces from URI in external links.
        ;; In internal ones, treat indentation as a single space.
@@ -3115,7 +3192,7 @@ Assume point is at the beginning of the link."
          (setq type "fuzzy")
          (setq path raw-link))))
        ;; Type 3: Plain link, e.g., https://orgmode.org
-       ((looking-at org-plain-link-re)
+       ((looking-at org-link-plain-re)
        (setq format 'plain)
        (setq raw-link (match-string-no-properties 0))
        (setq type (match-string-no-properties 1))
@@ -3124,7 +3201,7 @@ Assume point is at the beginning of the link."
        ;; Type 4: Angular link, e.g., <https://orgmode.org>.  Unlike to
        ;; bracket links, follow RFC 3986 and remove any extra
        ;; whitespace in URI.
-       ((looking-at org-angle-link-re)
+       ((looking-at org-link-angle-re)
        (setq format 'angle)
        (setq type (match-string-no-properties 1))
        (setq link-end (match-end 0))
@@ -3218,15 +3295,18 @@ a plist with `:key', `:args', `:begin', `:end', 
`:value' and
 
 Assume point is at the macro."
   (save-excursion
-    (when (looking-at "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\(([ 
\t\n]*\\([^\000]*?\\))\\)?}}}")
+    (when (looking-at 
"{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\([^\000]*?\\))\\)?}}}")
       (let ((begin (point))
            (key (downcase (match-string-no-properties 1)))
            (value (match-string-no-properties 0))
            (post-blank (progn (goto-char (match-end 0))
                               (skip-chars-forward " \t")))
            (end (point))
-           (args (let ((args (match-string-no-properties 3)))
-                   (and args (org-macro-extract-arguments args)))))
+           (args (pcase (match-string-no-properties 3)
+                   (`nil nil)
+                   (a (org-macro-extract-arguments
+                       (replace-regexp-in-string
+                        "[ \t\r\n]+" " " (org-trim a)))))))
        (list 'macro
              (list :key key
                    :value value
@@ -3237,7 +3317,11 @@ Assume point is at the macro."
 
 (defun org-element-macro-interpreter (macro _)
   "Interpret MACRO object as Org syntax."
-  (org-element-property :value macro))
+  (format "{{{%s%s}}}"
+         (org-element-property :key macro)
+         (pcase (org-element-property :args macro)
+           (`nil "")
+           (args (format "(%s)" (apply #'org-macro-escape-arguments args))))))
 
 
 ;;;; Radio-target
@@ -3815,7 +3899,8 @@ element it has to parse."
        ((org-at-heading-p)
        (org-element-inlinetask-parser limit raw-secondary-p))
        ;; From there, elements can have affiliated keywords.
-       (t (let ((affiliated (org-element--collect-affiliated-keywords limit)))
+       (t (let ((affiliated (org-element--collect-affiliated-keywords
+                            limit (memq granularity '(nil object)))))
            (cond
             ;; Jumping over affiliated keywords put point off-limits.
             ;; Parse them as regular keywords.
@@ -3874,7 +3959,18 @@ element it has to parse."
             ((looking-at "%%(")
              (org-element-diary-sexp-parser limit affiliated))
             ;; Table.
-            ((looking-at "[ \t]*\\(|\\|\\+\\(-+\\+\\)+[ \t]*$\\)")
+            ((or (looking-at "[ \t]*|")
+                 ;; There is no strict definition of a table.el
+                 ;; table.  Try to prevent false positive while being
+                 ;; quick.
+                 (let ((rule-regexp "[ \t]*\\+\\(-+\\+\\)+[ \t]*$")
+                       (next (line-beginning-position 2)))
+                   (and (looking-at rule-regexp)
+                        (save-excursion
+                          (forward-line)
+                          (re-search-forward "^[ \t]*\\($\\|[^|]\\)" limit t)
+                          (and (> (line-beginning-position) next)
+                               (org-match-line rule-regexp))))))
              (org-element-table-parser limit affiliated))
             ;; List.
             ((looking-at (org-item-re))
@@ -3890,7 +3986,7 @@ element it has to parse."
 ;; that element, and, in the meantime, collect information they give
 ;; into appropriate properties.  Hence the following function.
 
-(defun org-element--collect-affiliated-keywords (limit)
+(defun org-element--collect-affiliated-keywords (limit parse)
   "Collect affiliated keywords from point down to LIMIT.
 
 Return a list whose CAR is the position at the first of them and
@@ -3899,13 +3995,16 @@ beginning of the first line after them.
 
 As a special case, if element doesn't start at the beginning of
 the line (e.g., a paragraph starting an item), CAR is current
-position of point and CDR is nil."
+position of point and CDR is nil.
+
+When PARSE is non-nil, values from keywords belonging to
+`org-element-parsed-keywords' are parsed as secondary strings."
   (if (not (bolp)) (list (point))
     (let ((case-fold-search t)
          (origin (point))
          ;; RESTRICT is the list of objects allowed in parsed
-         ;; keywords value.
-         (restrict (org-element-restriction 'keyword))
+         ;; keywords value.  If PARSE is nil, no object is allowed.
+         (restrict (and parse (org-element-restriction 'keyword)))
          output)
       (while (and (< (point) limit) (looking-at org-element--affiliated-re))
        (let* ((raw-kwd (upcase (match-string 1)))
@@ -3914,35 +4013,35 @@ position of point and CDR is nil."
               (kwd (or (cdr (assoc raw-kwd
                                    org-element-keyword-translation-alist))
                        raw-kwd))
+              ;; PARSED? is non-nil when keyword should have its
+              ;; value parsed.
+              (parsed? (member kwd org-element-parsed-keywords))
               ;; Find main value for any keyword.
               (value
-               (save-match-data
-                 (org-trim
-                  (buffer-substring-no-properties
-                   (match-end 0) (line-end-position)))))
-              ;; PARSEDP is non-nil when keyword should have its
-              ;; value parsed.
-              (parsedp (member kwd org-element-parsed-keywords))
-              ;; If KWD is a dual keyword, find its secondary
-              ;; value.  Maybe parse it.
-              (dualp (member kwd org-element-dual-keywords))
+               (let ((beg (match-end 0))
+                     (end (save-excursion
+                            (end-of-line)
+                            (skip-chars-backward " \t")
+                            (point))))
+                 (if parsed?
+                     (org-element--parse-objects beg end nil restrict)
+                   (org-trim (buffer-substring-no-properties beg end)))))
+              ;; If KWD is a dual keyword, find its secondary value.
+              ;; Maybe parse it.
+              (dual? (member kwd org-element-dual-keywords))
               (dual-value
-               (and dualp
+               (and dual?
                     (let ((sec (match-string-no-properties 2)))
-                      (if (or (not sec) (not parsedp)) sec
+                      (cond
+                       ((and sec parsed?)
                         (save-match-data
                           (org-element--parse-objects
-                           (match-beginning 2) (match-end 2) nil restrict))))))
+                           (match-beginning 2) (match-end 2) nil restrict)))
+                       (sec sec)))))
               ;; Attribute a property name to KWD.
               (kwd-sym (and kwd (intern (concat ":" (downcase kwd))))))
          ;; Now set final shape for VALUE.
-         (when parsedp
-           (setq value
-                 (org-element--parse-objects
-                  (match-end 0)
-                  (progn (end-of-line) (skip-chars-backward " \t") (point))
-                  nil restrict)))
-         (when dualp
+         (when dual?
            (setq value (and (or value dual-value) (cons value dual-value))))
          (when (or (member kwd org-element-multiple-keywords)
                    ;; Attributes can always appear on multiple lines.
@@ -4046,7 +4145,10 @@ If STRING is the empty string or nil, return nil."
            (ignore-errors
              (if (symbolp v) (makunbound v)
                (set (make-local-variable (car v)) (cdr v)))))
-         (insert string)
+         ;; Transferring local variables may put the temporary buffer
+         ;; into a read-only state.  Make sure we can insert STRING.
+         (let ((inhibit-read-only t)) (insert string))
+         ;; Prevent "Buffer *temp* modified; kill anyway?".
          (restore-buffer-modified-p nil)
          (org-element--parse-objects
           (point-min) (point-max) nil restriction parent))))))
@@ -4532,8 +4634,9 @@ to interpret.  Return Org syntax as a string."
                              (and (eq type 'paragraph)
                                   (memq (org-element-type parent)
                                         '(footnote-definition item))
-                                  (eq data
-                                      (car (org-element-contents parent)))))))
+                                  (eq data (car (org-element-contents parent)))
+                                  (eq (org-element-property :pre-blank parent)
+                                      0)))))
                          ""))))))
                (if (memq type '(org-data plain-text nil)) results
                  ;; Build white spaces.  If no `:post-blank' property
@@ -4555,7 +4658,7 @@ If there is no affiliated keyword, return the empty 
string."
            (let (dual)
              (when (member key org-element-dual-keywords)
                (setq dual (cdr value) value (car value)))
-             (concat "#+" key
+             (concat "#+" (downcase key)
                      (and dual
                           (format "[%s]" (org-element-interpret-data dual)))
                      ": "
@@ -4950,7 +5053,6 @@ A and B are either integers or lists of integers, as 
returned by
 (defsubst org-element--cache-root ()
   "Return root value in cache.
 This function assumes `org-element--cache' is a valid AVL tree."
-  ;; FIXME: Why use internal functions of avl-tree?
   (avl-tree--node-left (avl-tree--dummyroot org-element--cache)))
 
 
@@ -4979,7 +5081,6 @@ the cache."
                    (aref (car org-element--cache-sync-requests) 0)))
        (node (org-element--cache-root))
        lower upper)
-    ;; FIXME: Why use internal functions of avl-tree?
     (while node
       (let* ((element (avl-tree--node-data node))
             (begin (org-element-property :begin element)))
@@ -5055,7 +5156,7 @@ Assume ELEMENT belongs to cache and that a cache is 
active."
   (setq org-element--cache-sync-timer
        (run-with-idle-timer
         (let ((idle (current-idle-time)))
-          (if idle (time-add idle org-element-cache-sync-break)
+          (if idle (org-time-add idle org-element-cache-sync-break)
             org-element-cache-sync-idle-time))
         nil
         #'org-element--cache-sync
@@ -5066,7 +5167,7 @@ Assume ELEMENT belongs to cache and that a cache is 
active."
 TIME-LIMIT is a time value or nil."
   (and time-limit
        (or (input-pending-p)
-          (time-less-p time-limit nil))))
+          (org-time-less-p time-limit nil))))
 
 (defsubst org-element--cache-shift-positions (element offset &optional props)
   "Shift ELEMENT properties relative to buffer positions by OFFSET.
@@ -5120,7 +5221,8 @@ updated before current modification are actually 
submitted."
             (and next (aref next 0))
             threshold
             (and (not threshold)
-                 (time-add nil org-element-cache-sync-duration))
+                 (org-time-add nil
+                               org-element-cache-sync-duration))
             future-change)
            ;; Request processed.  Merge current and next offsets and
            ;; transfer ending position.
@@ -5460,7 +5562,7 @@ the process stopped before finding the expected result."
 
 (defconst org-element--cache-sensitive-re
   (concat
-   org-outline-regexp-bol "\\|"
+   "^\\*+ " "\\|"
    "\\\\end{[A-Za-z0-9*]+}[ \t]*$" "\\|"
    "^[ \t]*\\(?:"
    "#\\+\\(?:BEGIN[:_]\\|END\\(?:_\\|:?[ \t]*$\\)\\)" "\\|"
@@ -5869,24 +5971,24 @@ Providing it allows for quicker computation."
                    ;; Otherwise, return NEXT.
                    (t (throw 'exit next)))))))))))))
 
-(defun org-element-lineage (blob &optional types with-self)
+(defun org-element-lineage (datum &optional types with-self)
   "List all ancestors of a given element or object.
 
-BLOB is an object or element.
+DATUM is an object or element.
 
-When optional argument TYPES is a list of symbols, return the
-first element or object in the lineage whose type belongs to that
-list.
+Return ancestors from the closest to the farthest.  When optional
+argument TYPES is a list of symbols, return the first element or
+object in the lineage whose type belongs to that list instead.
 
 When optional argument WITH-SELF is non-nil, lineage includes
-BLOB itself as the first element, and TYPES, if provided, also
+DATUM itself as the first element, and TYPES, if provided, also
 apply to it.
 
-When BLOB is obtained through `org-element-context' or
+When DATUM is obtained through `org-element-context' or
 `org-element-at-point', only ancestors from its section can be
-found.  There is no such limitation when BLOB belongs to a full
+found.  There is no such limitation when DATUM belongs to a full
 parse tree."
-  (let ((up (if with-self blob (org-element-property :parent blob)))
+  (let ((up (if with-self datum (org-element-property :parent datum)))
        ancestors)
     (while (and up (not (memq (org-element-type up) types)))
       (unless types (push up ancestors))
@@ -5914,16 +6016,16 @@ end of ELEM-A."
     ;; ELEM-A position in such a situation.  Note that the case of
     ;; a footnote definition is impossible: it cannot contain two
     ;; paragraphs in a row because it cannot contain a blank line.
-    (if (and specialp
-            (or (not (eq (org-element-type elem-B) 'paragraph))
-                (/= (org-element-property :begin elem-B)
-                    (org-element-property :contents-begin elem-B))))
-       (error "Cannot swap elements"))
+    (when (and specialp
+              (or (not (eq (org-element-type elem-B) 'paragraph))
+                  (/= (org-element-property :begin elem-B)
+                      (org-element-property :contents-begin elem-B))))
+      (error "Cannot swap elements"))
     ;; In a special situation, ELEM-A will have no indentation.  We'll
     ;; give it ELEM-B's (which will in, in turn, have no indentation).
     (let* ((ind-B (when specialp
                    (goto-char (org-element-property :begin elem-B))
-                   (org-get-indentation)))
+                   (current-indentation)))
           (beg-A (org-element-property :begin elem-A))
           (end-A (save-excursion
                    (goto-char (org-element-property :end elem-A))
diff --git a/lisp/org/org-entities.el b/lisp/org/org-entities.el
index 66837f3..a5c05ea 100644
--- a/lisp/org/org-entities.el
+++ b/lisp/org/org-entities.el
@@ -543,11 +543,11 @@ This first checks the user list, then the built-in list."
     (dolist (e org-entities)
       (pcase e
        (`(,name ,latex ,mathp ,html ,ascii ,latin ,utf8)
-        (if (equal ascii "|") (setq ascii "\\vert"))
-        (if (equal latin "|") (setq latin "\\vert"))
-        (if (equal utf8  "|") (setq utf8  "\\vert"))
-        (if (equal ascii "=>") (setq ascii "= >"))
-        (if (equal latin "=>") (setq latin "= >"))
+        (when (equal ascii "|") (setq ascii "\\vert"))
+        (when (equal latin "|") (setq latin "\\vert"))
+        (when (equal utf8  "|") (setq utf8  "\\vert"))
+        (when (equal ascii "=>") (setq ascii "= >"))
+        (when (equal latin "=>") (setq latin "= >"))
         (insert "|" name
                 "|" (format "=%s=" latex)
                 "|" (format (if mathp "$%s$" "$\\mbox{%s}$") latex)
diff --git a/lisp/org/org-faces.el b/lisp/org/org-faces.el
index ffd1c44..a97d4dc 100644
--- a/lisp/org/org-faces.el
+++ b/lisp/org/org-faces.el
@@ -311,7 +311,7 @@ determines if it is a foreground or a background color."
   (if (not value)
       (setq org-tags-special-faces-re nil)
     (setq org-tags-special-faces-re
-         (concat ":\\(" (mapconcat 'car value "\\|") "\\):"))))
+         (concat ":" (regexp-opt (mapcar #'car value) t) ":"))))
 
 (defface org-checkbox '((t :inherit bold))
   "Face for checkboxes."
@@ -395,8 +395,7 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword."
 
 (defface org-block '((t :inherit shadow))
   "Face text in #+begin ... #+end blocks.
-For source-blocks `org-src-block-faces' takes precedence.
-See also `org-fontify-quote-and-verse-blocks'."
+For source-blocks `org-src-block-faces' takes precedence."
   :group 'org-faces
   :version "26.1")
 
@@ -414,11 +413,13 @@ See also `org-fontify-quote-and-verse-blocks'."
   :version "22.1")
 
 (defface org-quote '((t (:inherit org-block)))
-  "Face for #+BEGIN_QUOTE ... #+END_QUOTE blocks."
+  "Face for #+BEGIN_QUOTE ... #+END_QUOTE blocks.
+Active when `org-fontify-quote-and-verse-blocks' is set."
   :group 'org-faces)
 
 (defface org-verse '((t (:inherit org-block)))
-  "Face for #+BEGIN_VERSE ... #+END_VERSE blocks."
+  "Face for #+BEGIN_VERSE ... #+END_VERSE blocks.
+Active when `org-fontify-quote-and-verse-blocks' is set."
   :group 'org-faces)
 
 (defcustom org-fontify-quote-and-verse-blocks nil
@@ -511,13 +512,18 @@ which days belong to the weekend."
     (((class color) (min-colors 8)  (background light)) (:foreground "red"))
     (((class color) (min-colors 8)  (background dark)) (:foreground "red" 
:bold t))
     (t (:bold t)))
-  "Face for items scheduled previously, and not yet done."
+  "Face for items scheduled previously, and not yet done.
+See also `org-agenda-deadline-faces'."
   :group 'org-faces)
 
+(defface org-upcoming-distant-deadline '((t :inherit org-default))
+  "Face for items scheduled previously, not done, and have a distant deadline.
+See also `org-agenda-deadline-faces'.")
+
 (defcustom org-agenda-deadline-faces
   '((1.0 . org-warning)
     (0.5 . org-upcoming-deadline)
-    (0.0 . default))
+    (0.0 . org-upcoming-distant-deadline))
   "Faces for showing deadlines in the agenda.
 This is a list of cons cells.  The cdr of each cell is a face to be used,
 and it can also just be like \\='(:foreground \"yellow\").
@@ -553,10 +559,6 @@ month and 365.24 days for a year)."
   "Face for tag(s) in the mode-line when filtering the agenda."
   :group 'org-faces)
 
-(defface org-agenda-filter-regexp '((t :inherit mode-line))
-  "Face for regexp(s) in the mode-line when filtering the agenda."
-  :group 'org-faces)
-
 (defface org-agenda-filter-category '((t :inherit mode-line))
   "Face for categories in the mode-line when filtering the agenda."
   :group 'org-faces)
@@ -565,6 +567,10 @@ month and 365.24 days for a year)."
   "Face for effort in the mode-line when filtering the agenda."
   :group 'org-faces)
 
+(defface org-agenda-filter-regexp '((t :inherit mode-line))
+  "Face for regexp(s) in the mode-line when filtering the agenda."
+  :group 'org-faces)
+
 (defface org-time-grid    ;Copied from `font-lock-variable-name-face'
   '((((class color) (min-colors 16) (background light)) (:foreground 
"DarkGoldenrod"))
     (((class color) (min-colors 16) (background dark)) (:foreground 
"LightGoldenrod"))
diff --git a/lisp/org/org-feed.el b/lisp/org/org-feed.el
index b2dc4f3..f9f5fb0 100644
--- a/lisp/org/org-feed.el
+++ b/lisp/org/org-feed.el
@@ -407,14 +407,13 @@ it can be a list structured like an entry in 
`org-feed-alist'."
          ;; Write the new status
          ;; We do this only now, in case something goes wrong above, so
          ;; that would would end up with a status that does not reflect
-         ;; which items truely have been handled
+         ;; which items truly have been handled
          (org-feed-write-status inbox-pos drawer status)
 
          ;; Normalize the visibility of the inbox tree
          (goto-char inbox-pos)
-         (outline-hide-subtree)
+         (org-flag-subtree t)
          (org-show-children)
-         (org-cycle-hide-drawers 'children)
 
          ;; Hooks and messages
          (when org-feed-save-after-adding (save-buffer))
@@ -567,7 +566,7 @@ If that property is already present, nothing changes."
                              (if (looking-at
                                   (concat "^\\([ \t]*\\)%" name "[ \t]*$"))
                                  (org-feed-make-indented-block
-                                  v (org-get-indentation))
+                                  v (current-indentation))
                                v))))))))
                (when replacement
                  (insert
diff --git a/lisp/org/org-footnote.el b/lisp/org/org-footnote.el
index f896318..0fe3828 100644
--- a/lisp/org/org-footnote.el
+++ b/lisp/org/org-footnote.el
@@ -47,18 +47,16 @@
 (declare-function org-end-of-subtree "org"  (&optional invisible-ok 
to-heading))
 (declare-function org-fill-paragraph "org" (&optional justify region))
 (declare-function org-in-block-p "org" (names))
-(declare-function org-in-regexp "org" (re &optional nlines visually))
 (declare-function org-in-verbatim-emphasis "org" ())
 (declare-function org-inside-LaTeX-fragment-p "org" ())
 (declare-function org-inside-latex-macro-p "org" ())
 (declare-function org-mark-ring-push "org" (&optional pos buffer))
 (declare-function org-show-context "org" (&optional key))
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function outline-next-heading "outline")
 
 (defvar electric-indent-mode)
 (defvar org-blank-before-new-entry)    ; defined in org.el
-(defvar org-bracket-link-regexp)       ; defined in org.el
+(defvar org-link-bracket-re)   ; defined in org.el
 (defvar org-complex-heading-regexp)    ; defined in org.el
 (defvar org-odd-levels-only)           ; defined in org.el
 (defvar org-outline-regexp)            ; defined in org.el
@@ -116,7 +114,8 @@ you will need to run the following command after the change:
           (org-element-cache-reset 'all)))
   :type '(choice
          (string :tag "Collect footnotes under heading")
-         (const :tag "Define footnotes locally" nil)))
+         (const :tag "Define footnotes locally" nil))
+  :safe #'string-or-null-p)
 
 (defcustom org-footnote-define-inline nil
   "Non-nil means define footnotes inline, at reference location.
@@ -124,7 +123,8 @@ When nil, footnotes will be defined in a special section 
near
 the end of the document.  When t, the [fn:label:definition] notation
 will be used to define the footnote at the reference position."
   :group 'org-footnote
-  :type 'boolean)
+  :type 'boolean
+  :safe #'booleanp)
 
 (defcustom org-footnote-auto-label t
   "Non-nil means define automatically new labels for footnotes.
@@ -141,7 +141,8 @@ random         Automatically generate a unique, random 
label."
          (const :tag "Prompt for label" nil)
          (const :tag "Create automatic [fn:N]" t)
          (const :tag "Offer automatic [fn:N] for editing" confirm)
-         (const :tag "Create a random label" random)))
+         (const :tag "Create a random label" random))
+  :safe #'symbolp)
 
 (defcustom org-footnote-auto-adjust nil
   "Non-nil means automatically adjust footnotes after insert/delete.
@@ -159,7 +160,8 @@ The main values of this variable can be set with in-buffer 
options:
          (const :tag "No adjustment" nil)
          (const :tag "Renumber" renumber)
          (const :tag "Sort" sort)
-         (const :tag "Renumber and Sort" t)))
+         (const :tag "Renumber and Sort" t))
+  :safe #'symbolp)
 
 (defcustom org-footnote-fill-after-inline-note-extraction nil
   "Non-nil means fill paragraphs after extracting footnotes.
@@ -167,7 +169,8 @@ When extracting inline footnotes, the lengths of lines can 
change a lot.
 When this option is set, paragraphs from which an inline footnote has been
 extracted will be filled again."
   :group 'org-footnote
-  :type 'boolean)
+  :type 'boolean
+  :safe #'booleanp)
 
 
 ;;;; Predicates
@@ -186,76 +189,53 @@ extracted will be filled again."
             (org-in-block-p org-footnote-forbidden-blocks)))))
 
 (defun org-footnote-at-reference-p ()
-  "Is the cursor at a footnote reference?
-
+  "Non-nil if point is at a footnote reference.
 If so, return a list containing its label, beginning and ending
-positions, and the definition, when inlined."
-  (when (and (org-footnote-in-valid-context-p)
-            (or (looking-at org-footnote-re)
-                (org-in-regexp org-footnote-re)
-                (save-excursion (re-search-backward org-footnote-re nil t)))
-            (/= (match-beginning 0) (line-beginning-position)))
-    (let* ((beg (match-beginning 0))
-          (label (match-string-no-properties 1))
-          ;; Inline footnotes don't end at (match-end 0) as
-          ;; `org-footnote-re' stops just after the second colon.
-          ;; Find the real ending with `scan-sexps', so Org doesn't
-          ;; get fooled by unrelated closing square brackets.
-          (end (ignore-errors (scan-sexps beg 1))))
-      ;; Point is really at a reference if it's located before true
-      ;; ending of the footnote.
-      (when (and end
-                (< (point) end)
-                ;; Verify match isn't a part of a link.
-                (not (save-excursion
-                       (goto-char beg)
-                       (let ((linkp
-                              (save-match-data
-                                (org-in-regexp org-bracket-link-regexp))))
-                         (and linkp (< (point) (cdr linkp))))))
-                ;; Verify point doesn't belong to a LaTeX macro.
-                (not (org-inside-latex-macro-p)))
-       (list label beg end
-             ;; Definition: ensure this is an inline footnote first.
-             (and (match-end 2)
-                  (org-trim
-                   (buffer-substring-no-properties
-                    (match-end 0) (1- end)))))))))
+positions, and the definition, when inline."
+  (let ((reference (org-element-context)))
+    (when (eq 'footnote-reference (org-element-type reference))
+      (let ((end (save-excursion
+                  (goto-char (org-element-property :end reference))
+                  (skip-chars-backward " \t")
+                  (point))))
+       (when (< (point) end)
+         (list (org-element-property :label reference)
+               (org-element-property :begin reference)
+               end
+               (and (eq 'inline (org-element-property :type reference))
+                    (buffer-substring-no-properties
+                     (org-element-property :contents-begin reference)
+                     (org-element-property :contents-end
+                                           reference)))))))))
 
 (defun org-footnote-at-definition-p ()
-  "Is point within a footnote definition?
+  "Non-nil if point is within a footnote definition.
 
-This matches only pure definitions like [1] or [fn:name] at the
+This matches only pure definitions like [fn:name] at the
 beginning of a line.  It does not match references like
 \[fn:name:definition], where the footnote text is included and
 defined locally.
 
-The return value will be nil if not at a footnote definition, and
+The return value is nil if not at a footnote definition, and
 a list with label, start, end and definition of the footnote
 otherwise."
-  (when (save-excursion (beginning-of-line) (org-footnote-in-valid-context-p))
-    (save-excursion
-      (end-of-line)
-      ;; Footnotes definitions are separated by new headlines, another
-      ;; footnote definition or 2 blank lines.
-      (let ((lim (save-excursion
-                  (re-search-backward
-                   (concat org-outline-regexp-bol
-                           "\\|^\\([ \t]*\n\\)\\{2,\\}") nil t))))
-       (when (re-search-backward org-footnote-definition-re lim t)
-         (let ((label (match-string-no-properties 1))
-               (beg (match-beginning 0))
-               (beg-def (match-end 0))
-               (end (if (progn
-                          (end-of-line)
-                          (re-search-forward
-                           (concat org-outline-regexp-bol "\\|"
-                                   org-footnote-definition-re "\\|"
-                                   "^\\([ \t]*\n\\)\\{2,\\}") nil 'move))
-                        (match-beginning 0)
-                      (point))))
-           (list label beg end
-                 (org-trim (buffer-substring-no-properties beg-def end)))))))))
+  (pcase (org-element-lineage (org-element-at-point) '(footnote-definition) t)
+    (`nil nil)
+    (definition
+      (let* ((label (org-element-property :label definition))
+            (begin (org-element-property :post-affiliated definition))
+            (end (save-excursion
+                   (goto-char (org-element-property :end definition))
+                   (skip-chars-backward " \r\t\n")
+                   (line-beginning-position 2)))
+            (contents-begin (org-element-property :contents-begin definition))
+            (contents-end (org-element-property :contents-end definition))
+            (contents
+             (if (not contents-begin) ""
+               (org-trim
+                (buffer-substring-no-properties contents-begin
+                                                contents-end)))))
+       (list label begin end contents)))))
 
 
 ;;;; Internal functions
@@ -313,23 +293,23 @@ otherwise."
 
 (defun org-footnote--clear-footnote-section ()
   "Remove all footnote sections in buffer and create a new one.
-New section is created at the end of the buffer, before any file
-local variable definition.  Leave point within the new section."
+New section is created at the end of the buffer.  Leave point
+within the new section."
   (when org-footnote-section
     (goto-char (point-min))
-    (let ((regexp
-          (format "^\\*+ +%s[ \t]*$"
-                  (regexp-quote org-footnote-section))))
+    (let ((regexp (format "^\\*+ +%s[ \t]*$"
+                         (regexp-quote org-footnote-section))))
       (while (re-search-forward regexp nil t)
        (delete-region
         (match-beginning 0)
-        (progn (org-end-of-subtree t t)
-               (if (not (eobp)) (point)
-                 (org-footnote--goto-local-insertion-point)
-                 (skip-chars-forward " \t\n")
-                 (if (eobp) (point) (line-beginning-position)))))))
+        (org-end-of-subtree t t))))
     (goto-char (point-max))
-    (org-footnote--goto-local-insertion-point)
+    ;; Clean-up blank lines at the end of the buffer.
+    (skip-chars-backward " \r\t\n")
+    (unless (bobp)
+      (forward-line)
+      (when (eolp) (insert "\n")))
+    (delete-region (point) (point-max))
     (when (and (cdr (assq 'heading org-blank-before-new-entry))
               (zerop (save-excursion (org-back-over-empty-lines))))
       (insert "\n"))
@@ -448,14 +428,8 @@ while collecting them."
   "Find insertion point for footnote, just before next outline heading.
 Assume insertion point is within currently accessible part of the buffer."
   (org-with-limited-levels (outline-next-heading))
-  ;; Skip file local variables.  See `modify-file-local-variable'.
-  (when (eobp)
-    (let ((case-fold-search t))
-      (re-search-backward "^[ \t]*# +Local Variables:"
-                         (max (- (point-max) 3000) (point-min))
-                         t)))
   (skip-chars-backward " \t\n")
-  (forward-line)
+  (unless (bobp) (forward-line))
   (unless (bolp) (insert "\n")))
 
 
@@ -470,16 +444,15 @@ the buffer position bounding the search.
 
 Return value is a list like those provided by `org-footnote-at-reference-p'.
 If no footnote is found, return nil."
-  (save-excursion
-    (let* ((label-fmt (if label (format "\\[fn:%s[]:]" label) 
org-footnote-re)))
-      (catch 'exit
-       (while t
-         (unless (funcall (if backward #'re-search-backward 
#'re-search-forward)
-                          label-fmt limit t)
-           (throw 'exit nil))
+  (let ((label-regexp (if label (format "\\[fn:%s[]:]" label) 
org-footnote-re)))
+    (catch :exit
+      (save-excursion
+       (while (funcall (if backward #'re-search-backward #'re-search-forward)
+                       label-regexp limit t)
          (unless backward (backward-char))
-         (let ((ref (org-footnote-at-reference-p)))
-           (when ref (throw 'exit ref))))))))
+         (pcase (org-footnote-at-reference-p)
+           (`nil nil)
+           (reference (throw :exit reference))))))))
 
 (defun org-footnote-next-reference-or-definition (limit)
   "Move point to next footnote reference or definition.
@@ -488,8 +461,10 @@ LIMIT is the buffer position bounding the search.
 
 Return value is a list like those provided by
 `org-footnote-at-reference-p' or `org-footnote-at-definition-p'.
-If no footnote is found, return nil."
-  (let* (ref (origin (point)))
+If no footnote is found, return nil.
+
+This function is meant to be used for fontification only."
+  (let ((origin (point)))
     (catch 'exit
       (while t
        (unless (re-search-forward org-footnote-re limit t)
@@ -499,15 +474,56 @@ If no footnote is found, return nil."
        ;; the closing square bracket.
        (backward-char)
        (cond
-        ((setq ref (org-footnote-at-reference-p))
-         (throw 'exit ref))
+        ((and (/= (match-beginning 0) (line-beginning-position))
+              (let* ((beg (match-beginning 0))
+                     (label (match-string-no-properties 1))
+                     ;; Inline footnotes don't end at (match-end 0)
+                     ;; as `org-footnote-re' stops just after the
+                     ;; second colon.  Find the real ending with
+                     ;; `scan-sexps', so Org doesn't get fooled by
+                     ;; unrelated closing square brackets.
+                     (end (ignore-errors (scan-sexps beg 1))))
+                (and end
+                     ;; Verify match isn't a part of a link.
+                     (not (save-excursion
+                            (goto-char beg)
+                            (let ((linkp
+                                   (save-match-data
+                                     (org-in-regexp org-link-bracket-re))))
+                              (and linkp (< (point) (cdr linkp))))))
+                     ;; Verify point doesn't belong to a LaTeX macro.
+                     (not (org-inside-latex-macro-p))
+                     (throw 'exit
+                            (list label beg end
+                                  ;; Definition: ensure this is an
+                                  ;; inline footnote first.
+                                  (and (match-end 2)
+                                       (org-trim
+                                        (buffer-substring-no-properties
+                                         (match-end 0) (1- end))))))))))
         ;; Definition: also grab the last square bracket, matched in
         ;; `org-footnote-re' for non-inline footnotes.
-        ((save-match-data (org-footnote-at-definition-p))
-         (let ((end (match-end 0)))
-           (throw 'exit
-                  (list nil (match-beginning 0)
-                        (if (eq (char-before end) ?\]) end (1+ end)))))))))))
+        ((and (save-excursion
+                (beginning-of-line)
+                (save-match-data (org-footnote-in-valid-context-p)))
+              (save-excursion
+                (end-of-line)
+                ;; Footnotes definitions are separated by new
+                ;; headlines, another footnote definition or 2 blank
+                ;; lines.
+                (let ((end (match-end 0))
+                      (lim (save-excursion
+                             (re-search-backward
+                              (concat org-outline-regexp-bol
+                                      "\\|^\\([ \t]*\n\\)\\{2,\\}")
+                              nil t))))
+                  (and (re-search-backward org-footnote-definition-re lim t)
+                       (throw 'exit
+                              (list nil
+                                    (match-beginning 0)
+                                    (if (eq (char-before end) ?\]) end
+                                      (1+ end)))))))))
+        (t nil))))))
 
 (defun org-footnote-goto-definition (label &optional location)
   "Move point to the definition of the footnote LABEL.
@@ -528,7 +544,7 @@ value if point was successfully moved."
       (user-error "Definition is outside narrowed part of buffer")))
     (org-mark-ring-push)
     (goto-char def-start)
-    (looking-at (format "\\[fn:%s[]:] ?" (regexp-quote label)))
+    (looking-at (format "\\[fn:%s[]:]" (regexp-quote label)))
     (goto-char (match-end 0))
     (org-show-context 'link-search)
     (when (derived-mode-p 'org-mode)
@@ -540,21 +556,23 @@ value if point was successfully moved."
 (defun org-footnote-goto-previous-reference (label)
   "Find the first closest (to point) reference of footnote with label LABEL."
   (interactive "sLabel: ")
-  (org-mark-ring-push)
-  (let ((label (org-footnote-normalize-label label))
-       ref)
-    (save-excursion
-      (setq ref (or (org-footnote-get-next-reference label t)
-                   (org-footnote-get-next-reference label)
-                   (save-restriction
-                     (widen)
-                     (or
-                      (org-footnote-get-next-reference label t)
-                      (org-footnote-get-next-reference label))))))
-    (if (not ref)
-       (error "Cannot find reference of footnote %s" label)
-      (goto-char (nth 1 ref))
-      (org-show-context 'link-search))))
+  (let* ((label (org-footnote-normalize-label label))
+        (reference
+         (save-excursion
+           (or (org-footnote-get-next-reference label t)
+               (org-footnote-get-next-reference label)
+               (and (buffer-narrowed-p)
+                    (org-with-wide-buffer
+                     (or (org-footnote-get-next-reference label t)
+                         (org-footnote-get-next-reference label)))))))
+        (start (nth 1 reference)))
+    (cond ((not reference)
+          (user-error "Cannot find reference of footnote %S" label))
+         ((or (> start (point-max)) (< start (point-min)))
+          (user-error "Reference is outside narrowed part of buffer")))
+    (org-mark-ring-push)
+    (goto-char start)
+    (org-show-context 'link-search)))
 
 
 ;;;; Getters
@@ -676,21 +694,22 @@ Return buffer position at the beginning of the 
definition.  This
 function doesn't move point."
   (let ((label (org-footnote-normalize-label label))
        electric-indent-mode)           ; Prevent wrong indentation.
-    (org-with-wide-buffer
-     (cond
-      ((not org-footnote-section) (org-footnote--goto-local-insertion-point))
-      ((save-excursion
-        (goto-char (point-min))
-        (re-search-forward
-         (concat "^\\*+[ \t]+" (regexp-quote org-footnote-section) "[ \t]*$")
-         nil t))
-       (goto-char (match-end 0))
-       (forward-line)
-       (unless (bolp) (insert "\n")))
-      (t (org-footnote--clear-footnote-section)))
-     (when (zerop (org-back-over-empty-lines)) (insert "\n"))
-     (insert "[fn:" label "] \n")
-     (line-beginning-position 0))))
+    (org-preserve-local-variables
+     (org-with-wide-buffer
+      (cond
+       ((not org-footnote-section) (org-footnote--goto-local-insertion-point))
+       ((save-excursion
+         (goto-char (point-min))
+         (re-search-forward
+          (concat "^\\*+[ \t]+" (regexp-quote org-footnote-section) "[ \t]*$")
+          nil t))
+       (goto-char (match-end 0))
+       (forward-line)
+       (unless (bolp) (insert "\n")))
+       (t (org-footnote--clear-footnote-section)))
+      (when (zerop (org-back-over-empty-lines)) (insert "\n"))
+      (insert "[fn:" label "] \n")
+      (line-beginning-position 0)))))
 
 (defun org-footnote-delete-references (label)
   "Delete every reference to footnote LABEL.
@@ -733,31 +752,32 @@ and all references of a footnote label.
 
 If LABEL is non-nil, delete that footnote instead."
   (catch 'done
-    (let* ((nref 0) (ndef 0) x
-          ;; 1. Determine LABEL of footnote at point.
-          (label (cond
-                  ;; LABEL is provided as argument.
-                  (label)
-                  ;; Footnote reference at point.  If the footnote is
-                  ;; anonymous, delete it and exit instead.
-                  ((setq x (org-footnote-at-reference-p))
-                   (or (car x)
-                       (progn
-                         (delete-region (nth 1 x) (nth 2 x))
-                         (message "Anonymous footnote removed")
-                         (throw 'done t))))
-                  ;; Footnote definition at point.
-                  ((setq x (org-footnote-at-definition-p))
-                   (car x))
-                  (t (error "Don't know which footnote to remove")))))
-      ;; 2. Now that LABEL is non-nil, find every reference and every
-      ;; definition, and delete them.
-      (setq nref (org-footnote-delete-references label)
-           ndef (org-footnote-delete-definitions label))
-      ;; 3. Verify consistency of footnotes and notify user.
-      (org-footnote-auto-adjust-maybe)
-      (message "%d definition(s) of and %d reference(s) of footnote %s removed"
-              ndef nref label))))
+    (org-preserve-local-variables
+     (let* ((nref 0) (ndef 0) x
+           ;; 1. Determine LABEL of footnote at point.
+           (label (cond
+                   ;; LABEL is provided as argument.
+                   (label)
+                   ;; Footnote reference at point.  If the footnote is
+                   ;; anonymous, delete it and exit instead.
+                   ((setq x (org-footnote-at-reference-p))
+                    (or (car x)
+                        (progn
+                          (delete-region (nth 1 x) (nth 2 x))
+                          (message "Anonymous footnote removed")
+                          (throw 'done t))))
+                   ;; Footnote definition at point.
+                   ((setq x (org-footnote-at-definition-p))
+                    (car x))
+                   (t (error "Don't know which footnote to remove")))))
+       ;; 2. Now that LABEL is non-nil, find every reference and every
+       ;; definition, and delete them.
+       (setq nref (org-footnote-delete-references label)
+            ndef (org-footnote-delete-definitions label))
+       ;; 3. Verify consistency of footnotes and notify user.
+       (org-footnote-auto-adjust-maybe)
+       (message "%d definition(s) of and %d reference(s) of footnote %s 
removed"
+               ndef nref label)))))
 
 
 ;;;; Sorting, Renumbering, Normalizing
@@ -765,28 +785,25 @@ If LABEL is non-nil, delete that footnote instead."
 (defun org-footnote-renumber-fn:N ()
   "Order numbered footnotes into a sequence in the document."
   (interactive)
-  (let ((references (org-footnote--collect-references)))
-    (unwind-protect
-       (let* ((c 0)
-              (references (cl-remove-if-not
-                           (lambda (r) (string-match-p "\\`[0-9]+\\'" (car r)))
-                           references))
-              (alist (mapcar (lambda (l) (cons l (number-to-string (cl-incf 
c))))
-                             (delete-dups (mapcar #'car references)))))
-         (org-with-wide-buffer
-          ;; Re-number references.
-          (dolist (ref references)
-            (goto-char (nth 1 ref))
-            (org-footnote--set-label (cdr (assoc (nth 0 ref) alist))))
-          ;; Re-number definitions.
-          (goto-char (point-min))
-          (while (re-search-forward "^\\[fn:\\([0-9]+\\)\\]" nil t)
-            (replace-match (or (cdr (assoc (match-string 1) alist))
-                               ;; Un-referenced definitions get
-                               ;; higher numbers.
-                               (number-to-string (cl-incf c)))
-                           nil nil nil 1))))
-      (dolist (r references) (set-marker (nth 1 r) nil)))))
+  (let* ((c 0)
+        (references (cl-remove-if-not
+                     (lambda (r) (string-match-p "\\`[0-9]+\\'" (car r)))
+                     (org-footnote--collect-references)))
+        (alist (mapcar (lambda (l) (cons l (number-to-string (cl-incf c))))
+                       (delete-dups (mapcar #'car references)))))
+    (org-with-wide-buffer
+     ;; Re-number references.
+     (dolist (ref references)
+       (goto-char (nth 1 ref))
+       (org-footnote--set-label (cdr (assoc (nth 0 ref) alist))))
+     ;; Re-number definitions.
+     (goto-char (point-min))
+     (while (re-search-forward "^\\[fn:\\([0-9]+\\)\\]" nil t)
+       (replace-match (or (cdr (assoc (match-string 1) alist))
+                         ;; Un-referenced definitions get higher
+                         ;; numbers.
+                         (number-to-string (cl-incf c)))
+                     nil nil nil 1)))))
 
 (defun org-footnote-sort ()
   "Rearrange footnote definitions in the current buffer.
@@ -795,129 +812,121 @@ references.  Also relocate definitions at the end of 
their
 relative section or within a single footnote section, according
 to `org-footnote-section'.  Inline definitions are ignored."
   (let ((references (org-footnote--collect-references)))
-    (unwind-protect
-       (let ((definitions (org-footnote--collect-definitions 'delete)))
-         (org-with-wide-buffer
-          (org-footnote--clear-footnote-section)
-          ;; Insert footnote definitions at the appropriate location,
-          ;; separated by a blank line.  Each definition is inserted
-          ;; only once throughout the buffer.
-          (let (inserted)
-            (dolist (cell references)
-              (let ((label (car cell))
-                    (nested (not (nth 2 cell)))
-                    (inline (nth 3 cell)))
-                (unless (or (member label inserted) inline)
-                  (push label inserted)
-                  (unless (or org-footnote-section nested)
-                    ;; If `org-footnote-section' is non-nil, or
-                    ;; reference is nested, point is already at the
-                    ;; correct position.  Otherwise, move at the
-                    ;; appropriate location within the section
-                    ;; containing the reference.
-                    (goto-char (nth 1 cell))
-                    (org-footnote--goto-local-insertion-point))
-                  (insert "\n"
-                          (or (cdr (assoc label definitions))
-                              (format "[fn:%s] DEFINITION NOT FOUND." label))
-                          "\n"))))
-            ;; Insert un-referenced footnote definitions at the end.
-            (let ((unreferenced
-                   (cl-remove-if (lambda (d) (member (car d) inserted))
-                                 definitions)))
-              (dolist (d unreferenced) (insert "\n" (cdr d) "\n"))))))
-      ;; Clear dangling markers in the buffer.
-      (dolist (r references) (set-marker (nth 1 r) nil)))))
+    (org-preserve-local-variables
+     (let ((definitions (org-footnote--collect-definitions 'delete)))
+       (org-with-wide-buffer
+       (org-footnote--clear-footnote-section)
+       ;; Insert footnote definitions at the appropriate location,
+       ;; separated by a blank line.  Each definition is inserted
+       ;; only once throughout the buffer.
+       (let (inserted)
+         (dolist (cell references)
+           (let ((label (car cell))
+                 (nested (not (nth 2 cell)))
+                 (inline (nth 3 cell)))
+             (unless (or (member label inserted) inline)
+               (push label inserted)
+               (unless (or org-footnote-section nested)
+                 ;; If `org-footnote-section' is non-nil, or
+                 ;; reference is nested, point is already at the
+                 ;; correct position.  Otherwise, move at the
+                 ;; appropriate location within the section
+                 ;; containing the reference.
+                 (goto-char (nth 1 cell))
+                 (org-footnote--goto-local-insertion-point))
+               (insert "\n"
+                       (or (cdr (assoc label definitions))
+                           (format "[fn:%s] DEFINITION NOT FOUND." label))
+                       "\n"))))
+         ;; Insert un-referenced footnote definitions at the end.
+         (pcase-dolist (`(,label . ,definition) definitions)
+           (unless (member label inserted)
+             (insert "\n" definition "\n")))))))))
 
 (defun org-footnote-normalize ()
   "Turn every footnote in buffer into a numbered one."
   (interactive)
-  (let ((references (org-footnote--collect-references 'anonymous)))
-    (unwind-protect
-       (let ((n 0)
-             (translations nil)
-             (definitions nil))
-         (org-with-wide-buffer
-          ;; Update label for reference.  We need to do this before
-          ;; clearing definitions in order to rename nested footnotes
-          ;; before they are deleted.
-          (dolist (cell references)
-            (let* ((label (car cell))
-                   (anonymous (not label))
-                   (new
-                    (cond
-                     ;; In order to differentiate anonymous
-                     ;; references from regular ones, set their
-                     ;; labels to integers, not strings.
-                     (anonymous (setcar cell (cl-incf n)))
-                     ((cdr (assoc label translations)))
-                     (t (let ((l (number-to-string (cl-incf n))))
-                          (push (cons label l) translations)
-                          l)))))
-              (goto-char (nth 1 cell)) ; Move to reference's start.
-              (org-footnote--set-label
-               (if anonymous (number-to-string new) new))
-              (let ((size (nth 3 cell)))
-                ;; Transform inline footnotes into regular references
-                ;; and retain their definition for later insertion as
-                ;; a regular footnote definition.
-                (when size
-                  (let ((def (concat
-                              (format "[fn:%s] " new)
-                              (org-trim
-                               (substring
-                                (delete-and-extract-region
-                                 (point) (+ (point) size 1))
-                                1)))))
-                    (push (cons (if anonymous new label) def) definitions)
-                    (when org-footnote-fill-after-inline-note-extraction
-                      (org-fill-paragraph)))))))
-          ;; Collect definitions.  Update labels according to ALIST.
-          (let ((definitions
-                  (nconc definitions
-                         (org-footnote--collect-definitions 'delete)))
-                (inserted))
-            (org-footnote--clear-footnote-section)
-            (dolist (cell references)
-              (let* ((label (car cell))
-                     (anonymous (integerp label))
-                     (pos (nth 1 cell)))
-                ;; Move to appropriate location, if required.  When
-                ;; there is a footnote section or reference is
-                ;; nested, point is already at the expected location.
-                (unless (or org-footnote-section (not (nth 2 cell)))
-                  (goto-char pos)
-                  (org-footnote--goto-local-insertion-point))
-                ;; Insert new definition once label is updated.
-                (unless (member label inserted)
-                  (push label inserted)
-                  (let ((stored (cdr (assoc label definitions)))
-                        ;; Anonymous footnotes' label is already
-                        ;; up-to-date.
-                        (new (if anonymous label
-                               (cdr (assoc label translations)))))
-                    (insert "\n"
-                            (cond
-                             ((not stored)
-                              (format "[fn:%s] DEFINITION NOT FOUND." new))
-                             (anonymous stored)
-                             (t
-                              (replace-regexp-in-string
-                               "\\`\\[fn:\\(.*?\\)\\]" new stored nil nil 1)))
-                            "\n")))))
-            ;; Insert un-referenced footnote definitions at the end.
-            (let ((unreferenced
-                   (cl-remove-if (lambda (d) (member (car d) inserted))
-                                 definitions)))
-              (dolist (d unreferenced)
-                (insert "\n"
-                        (replace-regexp-in-string
-                         org-footnote-definition-re
-                         (format "[fn:%d]" (cl-incf n))
-                         (cdr d))
-                        "\n"))))))
-      ;; Clear dangling markers.
-      (dolist (r references) (set-marker (nth 1 r) nil)))))
+  (org-preserve-local-variables
+   (let ((n 0)
+        (translations nil)
+        (definitions nil)
+        (references (org-footnote--collect-references 'anonymous)))
+     (org-with-wide-buffer
+      ;; Update label for reference.  We need to do this before
+      ;; clearing definitions in order to rename nested footnotes
+      ;; before they are deleted.
+      (dolist (cell references)
+       (let* ((label (car cell))
+              (anonymous (not label))
+              (new
+               (cond
+                ;; In order to differentiate anonymous references
+                ;; from regular ones, set their labels to integers,
+                ;; not strings.
+                (anonymous (setcar cell (cl-incf n)))
+                ((cdr (assoc label translations)))
+                (t (let ((l (number-to-string (cl-incf n))))
+                     (push (cons label l) translations)
+                     l)))))
+         (goto-char (nth 1 cell))      ; Move to reference's start.
+         (org-footnote--set-label
+          (if anonymous (number-to-string new) new))
+         (let ((size (nth 3 cell)))
+           ;; Transform inline footnotes into regular references and
+           ;; retain their definition for later insertion as
+           ;; a regular footnote definition.
+           (when size
+             (let ((def (concat
+                         (format "[fn:%s] " new)
+                         (org-trim
+                          (substring
+                           (delete-and-extract-region
+                            (point) (+ (point) size 1))
+                           1)))))
+               (push (cons (if anonymous new label) def) definitions)
+               (when org-footnote-fill-after-inline-note-extraction
+                 (org-fill-paragraph)))))))
+      ;; Collect definitions.  Update labels according to ALIST.
+      (let ((definitions
+             (nconc definitions
+                    (org-footnote--collect-definitions 'delete)))
+           (inserted))
+       (org-footnote--clear-footnote-section)
+       (dolist (cell references)
+         (let* ((label (car cell))
+                (anonymous (integerp label))
+                (pos (nth 1 cell)))
+           ;; Move to appropriate location, if required.  When there
+           ;; is a footnote section or reference is nested, point is
+           ;; already at the expected location.
+           (unless (or org-footnote-section (not (nth 2 cell)))
+             (goto-char pos)
+             (org-footnote--goto-local-insertion-point))
+           ;; Insert new definition once label is updated.
+           (unless (member label inserted)
+             (push label inserted)
+             (let ((stored (cdr (assoc label definitions)))
+                   ;; Anonymous footnotes' label is already
+                   ;; up-to-date.
+                   (new (if anonymous label
+                          (cdr (assoc label translations)))))
+               (insert "\n"
+                       (cond
+                        ((not stored)
+                         (format "[fn:%s] DEFINITION NOT FOUND." new))
+                        (anonymous stored)
+                        (t
+                         (replace-regexp-in-string
+                          "\\`\\[fn:\\(.*?\\)\\]" new stored nil nil 1)))
+                       "\n")))))
+       ;; Insert un-referenced footnote definitions at the end.
+       (pcase-dolist (`(,label . ,definition) definitions)
+         (unless (member label inserted)
+           (insert "\n"
+                   (replace-regexp-in-string org-footnote-definition-re
+                                             (format "[fn:%d]" (cl-incf n))
+                                             definition)
+                   "\n"))))))))
 
 (defun org-footnote-auto-adjust-maybe ()
   "Renumber and/or sort footnotes according to user settings."
diff --git a/lisp/org/org-goto.el b/lisp/org/org-goto.el
new file mode 100644
index 0000000..5ce9b8c
--- /dev/null
+++ b/lisp/org/org-goto.el
@@ -0,0 +1,312 @@
+;;; org-goto.el --- Fast navigation in an Org buffer  -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2012-2019 Free Software Foundation, Inc.
+
+;; Author: Carsten Dominik <carsten at orgmode dot org>
+;; Keywords: outlines, hypermedia, calendar, wp
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'org-macs)
+(require 'org-compat)
+
+(declare-function org-at-heading-p "org" (&optional ignored))
+(declare-function org-beginning-of-line "org" (&optional n))
+(declare-function org-defkey "org" (keymap key def))
+(declare-function org-mark-ring-push "org" (&optional pos buffer))
+(declare-function org-overview "org" ())
+(declare-function org-refile-check-position "org" (refile-pointer))
+(declare-function org-refile-get-location "org" (&optional prompt 
default-buffer new-nodes))
+(declare-function org-show-context "org" (&optional key))
+(declare-function org-show-set-visibility "org" (detail))
+
+(defvar org-complex-heading-regexp)
+(defvar org-startup-align-all-tables)
+(defvar org-startup-folded)
+(defvar org-startup-truncated)
+(defvar org-special-ctrl-a/e)
+(defvar org-refile-target-verify-function)
+(defvar org-refile-use-outline-path)
+(defvar org-refile-targets)
+
+(defvar org-goto-exit-command nil)
+(defvar org-goto-map nil)
+(defvar org-goto-marker nil)
+(defvar org-goto-selected-point nil)
+(defvar org-goto-start-pos nil)
+(defvar org-goto-window-configuration nil)
+
+(defconst org-goto-local-auto-isearch-map (make-sparse-keymap))
+(set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
+
+(defconst org-goto-help
+  "Browse buffer copy, to find location or copy text.%s
+RET=jump to location             C-g=quit and return to previous location
+\[Up]/[Down]=next/prev headline   TAB=cycle visibility   [/] org-occur")
+
+
+
+;;; Customization
+
+(defgroup org-goto nil
+  "Options concerning Org Goto navigation interface."
+  :tag "Org Goto"
+  :group 'org)
+
+(defcustom org-goto-interface 'outline
+  "The default interface to be used for `org-goto'.
+
+Allowed values are:
+
+`outline'
+
+   The interface shows an outline of the relevant file and the
+   correct heading is found by moving through the outline or by
+   searching with incremental search.
+
+`outline-path-completion'
+
+  Headlines in the current buffer are offered via completion.
+  This is the interface also used by the refile command."
+  :group 'org-goto
+  :type '(choice
+         (const :tag "Outline" outline)
+         (const :tag "Outline-path-completion" outline-path-completion)))
+
+(defcustom org-goto-max-level 5
+  "Maximum target level when running `org-goto' with refile interface."
+  :group 'org-goto
+  :type 'integer)
+
+(defcustom org-goto-auto-isearch t
+  "Non-nil means typing characters in `org-goto' starts incremental search.
+When nil, you can use these keybindings to navigate the buffer:
+
+  q    Quit the Org Goto interface
+  n    Go to the next visible heading
+  p    Go to the previous visible heading
+  f    Go one heading forward on same level
+  b    Go one heading backward on same level
+  u    Go one heading up"
+  :group 'org-goto
+  :type 'boolean)
+
+
+
+;;; Internal functions
+
+(defun org-goto--set-map ()
+  "Set the keymap `org-goto'."
+  (setq org-goto-map
+       (let ((map (make-sparse-keymap)))
+         (let ((cmds '(isearch-forward isearch-backward kill-ring-save 
set-mark-command
+                                       mouse-drag-region universal-argument 
org-occur)))
+           (dolist (cmd cmds)
+             (substitute-key-definition cmd cmd map global-map)))
+         (suppress-keymap map)
+         (org-defkey map "\C-m"     'org-goto-ret)
+         (org-defkey map [(return)] 'org-goto-ret)
+         (org-defkey map [(left)]   'org-goto-left)
+         (org-defkey map [(right)]  'org-goto-right)
+         (org-defkey map [(control ?g)] 'org-goto-quit)
+         (org-defkey map "\C-i" 'org-cycle)
+         (org-defkey map [(tab)] 'org-cycle)
+         (org-defkey map [(down)] 'outline-next-visible-heading)
+         (org-defkey map [(up)] 'outline-previous-visible-heading)
+         (if org-goto-auto-isearch
+             (if (fboundp 'define-key-after)
+                 (define-key-after map [t] 'org-goto-local-auto-isearch)
+               nil)
+           (org-defkey map "q" 'org-goto-quit)
+           (org-defkey map "n" 'outline-next-visible-heading)
+           (org-defkey map "p" 'outline-previous-visible-heading)
+           (org-defkey map "f" 'outline-forward-same-level)
+           (org-defkey map "b" 'outline-backward-same-level)
+           (org-defkey map "u" 'outline-up-heading))
+         (org-defkey map "/" 'org-occur)
+         (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
+         (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
+         (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
+         (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
+         (org-defkey map "\C-c\C-u" 'outline-up-heading)
+         map)))
+
+;; `isearch-other-control-char' was removed in Emacs 24.4.
+(if (fboundp 'isearch-other-control-char)
+    (progn
+      (define-key org-goto-local-auto-isearch-map "\C-i" 
'isearch-other-control-char)
+      (define-key org-goto-local-auto-isearch-map "\C-m" 
'isearch-other-control-char))
+  (define-key org-goto-local-auto-isearch-map "\C-i" nil)
+  (define-key org-goto-local-auto-isearch-map "\C-m" nil)
+  (define-key org-goto-local-auto-isearch-map [return] nil))
+
+(defun org-goto--local-search-headings (string bound noerror)
+  "Search and make sure that any matches are in headlines."
+  (catch 'return
+    (while (if isearch-forward
+               (search-forward string bound noerror)
+             (search-backward string bound noerror))
+      (when (save-match-data
+             (and (save-excursion
+                    (beginning-of-line)
+                    (looking-at org-complex-heading-regexp))
+                  (or (not (match-beginning 5))
+                      (< (point) (match-beginning 5)))))
+       (throw 'return (point))))))
+
+(defun org-goto-local-auto-isearch ()
+  "Start isearch."
+  (interactive)
+  (let ((keys (this-command-keys)))
+    (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
+      (isearch-mode t)
+      (isearch-process-search-char (string-to-char keys))
+      (org-font-lock-ensure))))
+
+(defun org-goto-ret (&optional _arg)
+  "Finish `org-goto' by going to the new location."
+  (interactive "P")
+  (setq org-goto-selected-point (point))
+  (setq org-goto-exit-command 'return)
+  (throw 'exit nil))
+
+(defun org-goto-left ()
+  "Finish `org-goto' by going to the new location."
+  (interactive)
+  (if (org-at-heading-p)
+      (progn
+       (beginning-of-line 1)
+       (setq org-goto-selected-point (point)
+             org-goto-exit-command 'left)
+       (throw 'exit nil))
+    (user-error "Not on a heading")))
+
+(defun org-goto-right ()
+  "Finish `org-goto' by going to the new location."
+  (interactive)
+  (if (org-at-heading-p)
+      (progn
+       (setq org-goto-selected-point (point)
+             org-goto-exit-command 'right)
+       (throw 'exit nil))
+    (user-error "Not on a heading")))
+
+(defun org-goto-quit ()
+  "Finish `org-goto' without cursor motion."
+  (interactive)
+  (setq org-goto-selected-point nil)
+  (setq org-goto-exit-command 'quit)
+  (throw 'exit nil))
+
+
+
+;;; Public API
+
+;;;###autoload
+(defun org-goto-location (&optional _buf help)
+  "Let the user select a location in current buffer.
+This function uses a recursive edit.  It returns the selected
+position or nil."
+  (org-no-popups
+   (let ((isearch-mode-map org-goto-local-auto-isearch-map)
+        (isearch-hide-immediately nil)
+        (isearch-search-fun-function
+         (lambda () #'org-goto--local-search-headings))
+        (help (or help org-goto-help)))
+     (save-excursion
+       (save-window-excursion
+        (delete-other-windows)
+        (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
+        (pop-to-buffer-same-window
+         (condition-case nil
+             (make-indirect-buffer (current-buffer) "*org-goto*")
+           (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
+        (let (temp-buffer-show-function temp-buffer-show-hook)
+          (with-output-to-temp-buffer "*Org Help*"
+          (princ (format help (if org-goto-auto-isearch
+                                  "  Just type for auto-isearch."
+                                "  n/p/f/b/u to navigate, q to quit.")))))
+        (org-fit-window-to-buffer (get-buffer-window "*Org Help*"))
+        (setq buffer-read-only nil)
+        (let ((org-startup-truncated t)
+              (org-startup-folded nil)
+              (org-startup-align-all-tables nil))
+          (org-mode)
+          (org-overview))
+        (setq buffer-read-only t)
+        (if (and (boundp 'org-goto-start-pos)
+                 (integer-or-marker-p org-goto-start-pos))
+            (progn (goto-char org-goto-start-pos)
+                   (when (org-invisible-p)
+                     (org-show-set-visibility 'lineage)))
+          (goto-char (point-min)))
+        (let (org-special-ctrl-a/e) (org-beginning-of-line))
+        (message "Select location and press RET")
+        (use-local-map org-goto-map)
+        (recursive-edit)))
+     (kill-buffer "*org-goto*")
+     (cons org-goto-selected-point org-goto-exit-command))))
+
+;;;###autoload
+(defun org-goto (&optional alternative-interface)
+  "Look up a different location in the current file, keeping current 
visibility.
+
+When you want look-up or go to a different location in a
+document, the fastest way is often to fold the entire buffer and
+then dive into the tree.  This method has the disadvantage, that
+the previous location will be folded, which may not be what you
+want.
+
+This command works around this by showing a copy of the current
+buffer in an indirect buffer, in overview mode.  You can dive
+into the tree in that copy, use org-occur and incremental search
+to find a location.  When pressing RET or `Q', the command
+returns to the original buffer in which the visibility is still
+unchanged.  After RET it will also jump to the location selected
+in the indirect buffer and expose the headline hierarchy above.
+
+With a prefix argument, use the alternative interface: e.g., if
+`org-goto-interface' is `outline' use `outline-path-completion'."
+  (interactive "P")
+  (org-goto--set-map)
+  (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
+        (org-refile-use-outline-path t)
+        (org-refile-target-verify-function nil)
+        (interface
+         (if (not alternative-interface)
+             org-goto-interface
+           (if (eq org-goto-interface 'outline)
+               'outline-path-completion
+             'outline)))
+        (org-goto-start-pos (point))
+        (selected-point
+         (if (eq interface 'outline) (car (org-goto-location))
+           (let ((pa (org-refile-get-location "Goto")))
+             (org-refile-check-position pa)
+             (nth 3 pa)))))
+    (if selected-point
+       (progn
+         (org-mark-ring-push org-goto-start-pos)
+         (goto-char selected-point)
+         (when (or (org-invisible-p) (org-invisible-p2))
+           (org-show-context 'org-goto)))
+      (message "Quit"))))
+
+(provide 'org-goto)
+
+;;; org-goto.el ends here
diff --git a/lisp/org/org-habit.el b/lisp/org/org-habit.el
index 6234d02..22f2e47 100644
--- a/lisp/org/org-habit.el
+++ b/lisp/org/org-habit.el
@@ -89,6 +89,21 @@ It will be green even if it was done after the deadline."
   :group 'org-habit
   :type 'boolean)
 
+(defcustom org-habit-scheduled-past-days nil
+  "Value to use instead of `org-scheduled-past-days', for habits only.
+
+If nil, `org-scheduled-past-days' is used.
+
+Setting this to say 10000 is a way to make habits always show up
+as a reminder, even if you set `org-scheduled-past-days' to a
+small value because you regard scheduled items as a way of
+\"turning on\" TODO items on a particular date, rather than as a
+means of creating calendar-based reminders."
+  :group 'org-habit
+  :type '(choice integer (const nil))
+  :package-version '(Org . "9.3")
+  :safe (lambda (v) (or (integerp v) (null v))))
+
 (defface org-habit-clear-face
   '((((background light)) (:background "#8270f9"))
     (((background dark)) (:background "blue")))
@@ -373,31 +388,30 @@ current time."
                                    (throw :exit s))))))))))
                 donep)))
             markedp face)
-       (if donep
-           (let ((done-time (time-add
-                             starting
-                             (days-to-time
-                              (- start (time-to-days starting))))))
-
-             (aset graph index org-habit-completed-glyph)
-             (setq markedp t)
-             (put-text-property
-              index (1+ index) 'help-echo
-              (format-time-string (org-time-stamp-format) done-time) graph)
-             (while (and done-dates
-                         (= start (car done-dates)))
-               (setq last-done-date (car done-dates)
-                     done-dates (cdr done-dates))))
-         (if todayp
-             (aset graph index org-habit-today-glyph)))
+       (cond
+        (donep
+         (aset graph index org-habit-completed-glyph)
+         (setq markedp t)
+         (while (and done-dates (= start (car done-dates)))
+           (setq last-done-date (car done-dates))
+           (setq done-dates (cdr done-dates))))
+        (todayp
+         (aset graph index org-habit-today-glyph)))
        (setq face (if (or in-the-past-p todayp)
                       (car faces)
                     (cdr faces)))
-       (if (and in-the-past-p
-                (not (eq face 'org-habit-overdue-face))
-                (not markedp))
-           (setq face (cdr faces)))
-       (put-text-property index (1+ index) 'face face graph))
+       (when (and in-the-past-p
+                  (not (eq face 'org-habit-overdue-face))
+                  (not markedp))
+         (setq face (cdr faces)))
+       (put-text-property index (1+ index) 'face face graph)
+       (put-text-property index (1+ index)
+                          'help-echo
+                          (concat (format-time-string
+                                   (org-time-stamp-format)
+                                    (time-add starting (days-to-time (- start 
(time-to-days starting)))))
+                                  (if donep " DONE" ""))
+                          graph))
       (setq start (1+ start)
            index (1+ index)))
     graph))
@@ -406,7 +420,8 @@ current time."
   "Insert consistency graph for any habitual tasks."
   (let ((inhibit-read-only t)
        (buffer-invisibility-spec '(org-link))
-       (moment (time-since (* 3600 org-extend-today-until))))
+       (moment (org-time-subtract nil
+                                  (* 3600 org-extend-today-until))))
     (save-excursion
       (goto-char (if line (point-at-bol) (point-min)))
       (while (not (eobp))
@@ -421,7 +436,7 @@ current time."
              habit
              (time-subtract moment (days-to-time org-habit-preceding-days))
              moment
-             (time-add moment (days-to-time org-habit-following-days))))))
+              (time-add moment (days-to-time org-habit-following-days))))))
        (forward-line)))))
 
 (defun org-habit-toggle-habits ()
@@ -434,7 +449,18 @@ current time."
   (message "Habits turned %s"
           (if org-habit-show-habits "on" "off")))
 
-(org-defkey org-agenda-mode-map "K" 'org-habit-toggle-habits)
+(defun org-habit-toggle-display-in-agenda (arg)
+  "Toggle display of habits in agenda.
+With ARG toggle display of all vs. undone scheduled habits.
+See `org-habit-show-all-today'."
+  (interactive "P")
+  (if (not arg)
+      (org-habit-toggle-habits)
+    (org-agenda-check-type t 'agenda)
+    (setq org-habit-show-all-today (not org-habit-show-all-today))
+    (when org-habit-show-habits (org-agenda-redo))))
+
+(org-defkey org-agenda-mode-map "K" 'org-habit-toggle-display-in-agenda)
 
 (provide 'org-habit)
 
diff --git a/lisp/org/org-id.el b/lisp/org/org-id.el
index 7f7faaa..653baf9 100644
--- a/lisp/org/org-id.el
+++ b/lisp/org/org-id.el
@@ -71,8 +71,11 @@
 ;;; Code:
 
 (require 'org)
+(require 'ol)
 
 (declare-function message-make-fqdn "message" ())
+(declare-function org-goto-location "org-goto" (&optional _buf help))
+(declare-function org-link-set-parameters "ol" (type &rest rest))
 
 ;;; Customization
 
@@ -139,11 +142,15 @@ org        Org's own internal method, using an encoding 
of the current time to
 
 uuid       Create random (version 4) UUIDs.  If the program defined in
            `org-id-uuid-program' is available it is used to create the ID.
-           Otherwise an internal functions is used."
+           Otherwise an internal functions is used.
+
+ts         Create ID's based on ISO8601 timestamps (without separators
+           and without timezone, local time).  Precision down to seconds."
   :group 'org-id
   :type '(choice
          (const :tag "Org's internal method" org)
-         (const :tag "external: uuidgen" uuid)))
+         (const :tag "external: uuidgen" uuid)
+         (const :tag "ISO8601 timestamp" ts)))
 
 (defcustom org-id-prefix nil
   "The prefix for IDs.
@@ -160,7 +167,7 @@ to have no space characters in them."
   "Non-nil means add the domain name to new IDs.
 This ensures global uniqueness of IDs, and is also suggested by
 the relevant RFCs.  This is relevant only if `org-id-method' is
-`org'.  When uuidgen is used, the domain will never be added.
+`org' or `ts'.  When uuidgen is used, the domain will never be added.
 
 The default is to not use this because we have no really good way to get
 the true domain, and Org entries will normally not be shared with enough
@@ -188,6 +195,22 @@ This variable is only relevant when 
`org-id-track-globally' is set."
   :group 'org-id
   :type 'file)
 
+(defcustom org-id-locations-file-relative nil
+  "Determines if org-id-locations should be stored as relative links.
+Non-nil means that links to locations are stored as links
+relative to the location of where `org-id-locations-file' is
+stored.
+
+Nil means to store absolute paths to files.
+
+This customization is useful when folders are shared across
+systems but mounted at different roots.  Relative path to
+`org-id-locations-file' still has to be maintained across
+systems."
+  :group 'org-id
+  :type 'boolean
+  :package-version '(Org . "9.3"))
+
 (defvar org-id-locations nil
   "List of files with IDs in those files.")
 
@@ -275,9 +298,9 @@ If necessary, the ID is created."
 ;;;###autoload
 (defun org-id-get-with-outline-drilling ()
   "Use an outline-cycling interface to retrieve the ID of an entry.
-This only finds entries in the current buffer, using `org-get-location'.
+This only finds entries in the current buffer, using `org-goto-location'.
 It returns the ID of the entry.  If necessary, the ID is created."
-  (let* ((spos (org-get-location (current-buffer) org-goto-help))
+  (let* ((spos (org-goto-location))
         (pom (and spos (move-marker (make-marker) (car spos)))))
     (prog1 (org-id-get pom 'create)
       (move-marker pom nil))))
@@ -349,6 +372,13 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
                            (require 'message)
                            (concat "@" (message-make-fqdn))))))
        (setq unique (concat etime postfix))))
+     ((eq org-id-method 'ts)
+      (let ((ts (format-time-string "%Y%m%dT%H%M%S.%6N"))
+           (postfix (if org-id-include-domain
+                        (progn
+                          (require 'message)
+                          (concat "@" (message-make-fqdn))))))
+       (setq unique (concat ts postfix))))
      (t (error "Invalid `org-id-method'")))
     (concat prefix unique)))
 
@@ -356,7 +386,7 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
   "Return string with random (version 4) UUID."
   (let ((rnd (md5 (format "%s%s%s%s%s%s%s"
                          (random)
-                         (time-convert nil 'list)
+                         (org-time-convert-to-list nil)
                          (user-uid)
                          (emacs-pid)
                          (user-full-name)
@@ -418,7 +448,7 @@ using `org-id-decode'."
   ;; FIXME: If TIME represents N seconds after the epoch, then
   ;; this encoding assumes 0 <= N < 110075314176 = (* (expt 36 4) 65536),
   ;; i.e., that TIME is from 1970-01-01 00:00:00 to 5458-02-23 20:09:36 UTC.
-  (setq time (time-convert time 'list))
+  (setq time (org-time-convert-to-list nil))
   (concat (org-id-int-to-b36 (nth 0 time) 4)
          (org-id-int-to-b36 (nth 1 time) 4)
          (org-id-int-to-b36 (nth 2 time) 4)))
@@ -446,81 +476,56 @@ and TIME is a Lisp time value (HI LO USEC)."
 Store the relation between files and corresponding IDs.
 This will scan all agenda files, all associated archives, and all
 files currently mentioned in `org-id-locations'.
-When FILES is given, scan these files instead."
+When FILES is given, scan also these files."
   (interactive)
   (if (not org-id-track-globally)
       (error "Please turn on `org-id-track-globally' if you want to track IDs")
-    (let* ((org-id-search-archives
-           (or org-id-search-archives
-               (and (symbolp org-id-extra-files)
-                    (symbol-value org-id-extra-files)
-                    (member 'agenda-archives org-id-extra-files))))
-          (files
-           (or files
-               (append
-                ;; Agenda files and all associated archives
-                (org-agenda-files t org-id-search-archives)
-                ;; Explicit extra files
-                (if (symbolp org-id-extra-files)
-                    (symbol-value org-id-extra-files)
-                  org-id-extra-files)
-                ;; Files associated with live Org buffers
-                (delq nil
-                      (mapcar (lambda (b)
-                                (with-current-buffer b
-                                  (and (derived-mode-p 'org-mode) 
(buffer-file-name))))
-                              (buffer-list)))
-                ;; All files known to have IDs
-                org-id-files)))
-          org-agenda-new-buffers
-          file nfiles tfile ids reg found id seen (ndup 0))
-      (when (member 'agenda-archives files)
-       (setq files (delq 'agenda-archives (copy-sequence files))))
-      (setq nfiles (length files))
-      (while (setq file (pop files))
-       (unless silent
-         (message "Finding ID locations (%d/%d files): %s"
-                  (- nfiles (length files)) nfiles file))
-       (setq tfile (file-truename file))
-       (when (and (file-exists-p file) (not (member tfile seen)))
-         (push tfile seen)
-         (setq ids nil)
-         (with-current-buffer (org-get-agenda-file-buffer file)
-           (save-excursion
-             (save-restriction
-               (widen)
-               (goto-char (point-min))
-               (while (re-search-forward "^[ \t]*:ID:[ \t]+\\(\\S-+\\)[ \t]*$"
-                                         nil t)
-                 (setq id (match-string-no-properties 1))
-                 (if (member id found)
-                     (progn
-                       (message "Duplicate ID \"%s\", also in file %s"
-                                id (or (car (delq
-                                             nil
-                                             (mapcar
-                                              (lambda (x)
-                                                (if (member id (cdr x))
-                                                    (car x)))
-                                              reg)))
-                                       (buffer-file-name)))
-                       (when (= ndup 0)
-                         (ding)
-                         (sit-for 2))
-                       (setq ndup (1+ ndup)))
-                   (push id found)
-                   (push id ids)))
-               (push (cons (abbreviate-file-name file) ids) reg))))))
-      (org-release-buffers org-agenda-new-buffers)
-      (setq org-agenda-new-buffers nil)
-      (setq org-id-locations reg)
+    (let* ((files (delete-dups
+                  (mapcar #'file-truename
+                          (append
+                           ;; Agenda files and all associated archives
+                           (org-agenda-files t org-id-search-archives)
+                           ;; Explicit extra files
+                           (unless (symbolp org-id-extra-files)
+                             org-id-extra-files)
+                           ;; All files known to have IDs
+                           org-id-files
+                           ;; function input
+                           files))))
+          (nfiles (length files))
+          ids seen-ids (ndup 0) (i 0) file-id-alist)
+      (with-temp-buffer
+       (delay-mode-hooks
+         (org-mode)
+          (dolist (file files)
+           (unless silent
+              (setq i (1+ i))
+              (message "Finding ID locations (%d/%d files): %s"
+                       i nfiles file))
+           (when (file-exists-p file)
+             (insert-file-contents file nil nil nil 'replace)
+             (setq ids (org-map-entries
+                        (lambda ()
+                          (org-entry-get (point) "ID"))
+                        "ID<>\"\""))
+             (dolist (id ids)
+               (if (member id seen-ids)
+                   (progn
+                     (message "Duplicate ID \"%s\"" id)
+                     (setq ndup (1+ ndup)))
+                 (push id seen-ids)))
+              (when ids
+               (setq file-id-alist (cons (cons (abbreviate-file-name file) ids)
+                                         file-id-alist)))))))
+      (setq org-id-locations file-id-alist)
       (setq org-id-files (mapcar 'car org-id-locations))
-      (org-id-locations-save) ;; this function can also handle the alist form
+      (org-id-locations-save)
       ;; now convert to a hash
       (setq org-id-locations (org-id-alist-to-hash org-id-locations))
-      (if (> ndup 0)
-         (message "WARNING: %d duplicate IDs found, check *Messages* buffer" 
ndup)
-       (message "%d unique files scanned for IDs" (length org-id-files)))
+      (when (> ndup 0)
+       (warn "WARNING: %d duplicate IDs found, check *Messages* buffer" ndup))
+      (message "%d files scanned, %d files contains IDs and in total %d IDs 
found."
+              nfiles (length org-id-files) (hash-table-count org-id-locations))
       org-id-locations)))
 
 (defun org-id-locations-save ()
@@ -529,6 +534,16 @@ When FILES is given, scan these files instead."
     (let ((out (if (hash-table-p org-id-locations)
                   (org-id-hash-to-alist org-id-locations)
                 org-id-locations)))
+      (when (and org-id-locations-file-relative out)
+       (setq out (mapcar
+                   (lambda (item)
+                    (if (file-name-absolute-p (car item))
+                        (cons (file-relative-name
+                                (car item) (file-name-directory
+                                           org-id-locations-file))
+                               (cdr item))
+                       item))
+                  out)))
       (with-temp-file org-id-locations-file
        (let ((print-level nil)
              (print-length nil))
@@ -542,7 +557,12 @@ When FILES is given, scan these files instead."
       (condition-case nil
          (progn
            (insert-file-contents org-id-locations-file)
-           (setq org-id-locations (read (current-buffer))))
+           (setq org-id-locations (read (current-buffer)))
+           (let ((loc (file-name-directory org-id-locations-file)))
+             (mapc (lambda (item)
+                     (unless (file-name-absolute-p (car item))
+                       (setf (car item) (expand-file-name (car item) loc))))
+                   org-id-locations)))
        (error
         (message "Could not read org-id-values from %s.  Setting it to nil."
                  org-id-locations-file))))
@@ -552,10 +572,12 @@ When FILES is given, scan these files instead."
 (defun org-id-add-location (id file)
   "Add the ID with location FILE to the database of ID locations."
   ;; Only if global tracking is on, and when the buffer has a file
-  (when (and org-id-track-globally id file)
-    (unless org-id-locations (org-id-locations-load))
-    (puthash id (abbreviate-file-name file) org-id-locations)
-    (add-to-list 'org-id-files (abbreviate-file-name file))))
+  (let ((afile (abbreviate-file-name file)))
+    (when (and org-id-track-globally id file)
+      (unless org-id-locations (org-id-locations-load))
+      (puthash id afile org-id-locations)
+      (unless (member afile org-id-files)
+       (add-to-list 'org-id-files afile)))))
 
 (unless noninteractive
   (add-hook 'kill-emacs-hook 'org-id-locations-save))
@@ -565,7 +587,7 @@ When FILES is given, scan these files instead."
   (let (res x)
     (maphash
      (lambda (k v)
-       (if (setq x (member v res))
+       (if (setq x (assoc v res))
           (setcdr x (cons k (cdr x)))
         (push (list v k) res)))
      hash)
@@ -649,7 +671,7 @@ optional argument MARKERP, return the position as a new 
marker."
                                (match-string 4)
                              (match-string 0)))
                       link))))
-      (org-store-link-props :link link :description desc :type "id")
+      (org-link-store-props :link link :description desc :type "id")
       link)))
 
 (defun org-id-open (id)
diff --git a/lisp/org/org-indent.el b/lisp/org/org-indent.el
index 4904d81..a69293a 100644
--- a/lisp/org/org-indent.el
+++ b/lisp/org/org-indent.el
@@ -150,15 +150,16 @@ useful to make it ever so slightly different."
       ;; Text line prefixes.
       (aset org-indent--text-line-prefixes
            n
-           (concat (org-add-props (make-string (+ n indentation) ?\s)
-                       nil 'face 'org-indent)
-                   (and (> n 0)
-                        (char-to-string org-indent-boundary-char)))))))
+           (org-add-props
+               (concat (make-string (+ n indentation) ?\s)
+                       (and (> n 0)
+                            (char-to-string org-indent-boundary-char)))
+               nil 'face 'org-indent)))))
 
 (defsubst org-indent-remove-properties (beg end)
   "Remove indentations between BEG and END."
-  (org-with-silent-modifications
-   (remove-text-properties beg end '(line-prefix nil wrap-prefix nil))))
+  (with-silent-modifications
+    (remove-text-properties beg end '(line-prefix nil wrap-prefix nil))))
 
 ;;;###autoload
 (define-minor-mode org-indent-mode
@@ -332,39 +333,39 @@ stopped."
      (let* ((case-fold-search t)
            (limited-re (org-get-limited-outline-regexp))
            (level (or (org-current-level) 0))
-           (time-limit (and delay (time-add nil delay))))
+           (time-limit (and delay (org-time-add nil delay))))
        ;; For each line, set `line-prefix' and `wrap-prefix'
        ;; properties depending on the type of line (headline, inline
        ;; task, item or other).
-       (org-with-silent-modifications
-       (while (and (<= (point) end) (not (eobp)))
-         (cond
-          ;; When in asynchronous mode, check if interrupt is
-          ;; required.
-          ((and delay (input-pending-p)) (throw 'interrupt (point)))
-          ;; In asynchronous mode, take a break of
-          ;; `org-indent-agent-resume-delay' every DELAY to avoid
-          ;; blocking any other idle timer or process output.
-          ((and delay (time-less-p time-limit nil))
-           (setq org-indent-agent-resume-timer
-                 (run-with-idle-timer
-                  (time-add (current-idle-time) org-indent-agent-resume-delay)
-                  nil #'org-indent-initialize-agent))
-           (throw 'interrupt (point)))
-          ;; Headline or inline task.
-          ((looking-at org-outline-regexp)
-           (let* ((nstars (- (match-end 0) (match-beginning 0) 1))
-                  (type (or (looking-at-p limited-re) 'inlinetask)))
-             (org-indent-set-line-properties nstars 0 type)
-             ;; At an headline, define new value for LEVEL.
-             (unless (eq type 'inlinetask) (setq level nstars))))
-          ;; List item: `wrap-prefix' is set where body starts.
-          ((org-at-item-p)
-           (org-indent-set-line-properties
-            level (org-list-item-body-column (point))))
-          ;; Regular line.
-          (t
-           (org-indent-set-line-properties level (org-get-indentation))))))))))
+       (with-silent-modifications
+        (while (and (<= (point) end) (not (eobp)))
+          (cond
+           ;; When in asynchronous mode, check if interrupt is
+           ;; required.
+           ((and delay (input-pending-p)) (throw 'interrupt (point)))
+           ;; In asynchronous mode, take a break of
+           ;; `org-indent-agent-resume-delay' every DELAY to avoid
+           ;; blocking any other idle timer or process output.
+           ((and delay (org-time-less-p time-limit nil))
+            (setq org-indent-agent-resume-timer
+                  (run-with-idle-timer
+                   (time-add (current-idle-time) org-indent-agent-resume-delay)
+                   nil #'org-indent-initialize-agent))
+            (throw 'interrupt (point)))
+           ;; Headline or inline task.
+           ((looking-at org-outline-regexp)
+            (let* ((nstars (- (match-end 0) (match-beginning 0) 1))
+                   (type (or (looking-at-p limited-re) 'inlinetask)))
+              (org-indent-set-line-properties nstars 0 type)
+              ;; At an headline, define new value for LEVEL.
+              (unless (eq type 'inlinetask) (setq level nstars))))
+           ;; List item: `wrap-prefix' is set where body starts.
+           ((org-at-item-p)
+            (org-indent-set-line-properties
+             level (org-list-item-body-column (point))))
+           ;; Regular line.
+           (t
+            (org-indent-set-line-properties level 
(current-indentation))))))))))
 
 (defun org-indent-notify-modified-headline (beg end)
   "Set `org-indent-modified-headline-flag' depending on context.
diff --git a/lisp/org/org-inlinetask.el b/lisp/org/org-inlinetask.el
index 82372e5..c76d7d2 100644
--- a/lisp/org/org-inlinetask.el
+++ b/lisp/org/org-inlinetask.el
@@ -40,9 +40,9 @@
 ;; parent into children.
 ;;
 ;; Special fontification of inline tasks, so that they can be
-;; immediately recognized.  From the stars of the headline, only the
-;; first and the last two will be visible, the others will be hidden
-;; using the `org-hide' face.
+;; immediately recognized.  From the stars of the headline, only last
+;; two will be visible, the others will be hidden using the `org-hide'
+;; face.
 ;;
 ;; An inline task is identified solely by a minimum outline level,
 ;; given by the variable `org-inlinetask-min-level', default 15.
@@ -54,14 +54,14 @@
 ;;
 ;; As an example, here are two valid inline tasks:
 ;;
-;;    **************** TODO a small task
+;;    **************** TODO A small task
 ;;
 ;; and
 ;;
-;;    **************** TODO another small task
+;;    **************** TODO Another small task
 ;;                     DEADLINE: <2009-03-30 Mon>
 ;;                     :PROPERTIES:
-;;                       :SOMETHING: or other
+;;                     :SOMETHING: another thing
 ;;                     :END:
 ;;                     And here is some extra text
 ;;    **************** END
@@ -123,7 +123,8 @@ default, or nil if no state should be assigned."
 
 (defun org-inlinetask-insert-task (&optional no-state)
   "Insert an inline task.
-If prefix arg NO-STATE is set, ignore `org-inlinetask-default-state'."
+If prefix arg NO-STATE is set, ignore `org-inlinetask-default-state'.
+If there is a region wrap it inside the inline task."
   (interactive "P")
   ;; Error when inside an inline task, except if point was at its very
   ;; beginning, in which case the new inline task will be inserted
@@ -135,13 +136,19 @@ If prefix arg NO-STATE is set, ignore 
`org-inlinetask-default-state'."
   (let* ((indent (if org-odd-levels-only
                     (1- (* 2 org-inlinetask-min-level))
                   org-inlinetask-min-level))
-        (indent-string (concat (make-string indent ?*) " ")))
+        (indent-string (concat (make-string indent ?*) " "))
+        (rbeg (if (org-region-active-p) (region-beginning) (point)))
+        (rend (if (org-region-active-p) (region-end) (point))))
+    (goto-char rend)
+    (insert "\n" indent-string "END\n")
+    (goto-char rbeg)
+    (unless (bolp) (insert "\n"))
     (insert indent-string
            (if (or no-state (not org-inlinetask-default-state))
-               "\n"
-             (concat org-inlinetask-default-state " \n"))
-           indent-string "END\n"))
-  (end-of-line -1))
+               ""
+             (concat org-inlinetask-default-state " "))
+           (if (= rend rbeg) "" "\n"))
+    (unless (= rend rbeg) (end-of-line 0))))
 (define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
 
 (defun org-inlinetask-outline-regexp ()
@@ -152,24 +159,24 @@ The number of levels is controlled by 
`org-inlinetask-min-level'."
                  org-inlinetask-min-level)))
     (format "^\\(\\*\\{%d,\\}\\)[ \t]+" nstars)))
 
+(defun org-inlinetask-end-p ()
+  "Return a non-nil value if point is on inline task's END part."
+  (let ((case-fold-search t))
+    (org-match-line (concat (org-inlinetask-outline-regexp) "END[ \t]*$"))))
+
 (defun org-inlinetask-at-task-p ()
-  "Return true if point is at beginning of an inline task."
-  (save-excursion
-    (beginning-of-line)
-    (and (looking-at (concat (org-inlinetask-outline-regexp)  "\\(.*\\)"))
-        (not (string-match "^end[ \t]*$" (downcase (match-string 2)))))))
+  "Return non-nil if point is at beginning of an inline task."
+  (and (org-match-line (concat (org-inlinetask-outline-regexp)  "\\(.*\\)"))
+       (not (org-inlinetask-end-p))))
 
 (defun org-inlinetask-in-task-p ()
   "Return true if point is inside an inline task."
   (save-excursion
     (beginning-of-line)
-    (let* ((case-fold-search t)
-          (stars-re (org-inlinetask-outline-regexp))
-          (task-beg-re (concat stars-re "\\(?:.*\\)"))
-          (task-end-re (concat stars-re "END[ \t]*$")))
-      (or (looking-at-p task-beg-re)
+    (let ((case-fold-search t))
+      (or (looking-at-p (concat (org-inlinetask-outline-regexp) "\\(?:.*\\)"))
          (and (re-search-forward "^\\*+[ \t]+" nil t)
-              (progn (beginning-of-line) (looking-at-p task-end-re)))))))
+              (org-inlinetask-end-p))))))
 
 (defun org-inlinetask-goto-beginning ()
   "Go to the beginning of the inline task at point."
@@ -177,7 +184,7 @@ The number of levels is controlled by 
`org-inlinetask-min-level'."
   (let ((case-fold-search t)
        (inlinetask-re (org-inlinetask-outline-regexp)))
     (re-search-backward inlinetask-re nil t)
-    (when (looking-at-p (concat inlinetask-re "END[ \t]*$"))
+    (when (org-inlinetask-end-p)
       (re-search-backward inlinetask-re nil t))))
 
 (defun org-inlinetask-goto-end ()
@@ -185,16 +192,15 @@ The number of levels is controlled by 
`org-inlinetask-min-level'."
     Return point."
   (save-match-data
     (beginning-of-line)
-    (let* ((case-fold-search t)
-           (inlinetask-re (org-inlinetask-outline-regexp))
-           (task-end-re (concat inlinetask-re "END[ \t]*$")))
+    (let ((case-fold-search t)
+         (inlinetask-re (org-inlinetask-outline-regexp)))
       (cond
-       ((looking-at-p task-end-re)
+       ((org-inlinetask-end-p)
         (forward-line))
        ((looking-at-p inlinetask-re)
         (forward-line)
         (cond
-         ((looking-at-p task-end-re) (forward-line))
+         ((org-inlinetask-end-p) (forward-line))
          ((looking-at-p inlinetask-re))
          ((org-inlinetask-in-task-p)
           (re-search-forward inlinetask-re nil t)
@@ -262,17 +268,6 @@ If the task has an end part, also demote it."
            (goto-char beg)
            (org-fixup-indentation diff)))))))
 
-(defun org-inlinetask-get-current-indentation ()
-  "Get the indentation of the last non-while line above this one."
-  (save-excursion
-    (beginning-of-line 1)
-    (skip-chars-backward " \t\n")
-    (beginning-of-line 1)
-    (or (org-at-item-p)
-       (looking-at "[ \t]*"))
-    (goto-char (match-end 0))
-    (current-column)))
-
 (defvar org-indent-indentation-per-level) ; defined in org-indent.el
 
 (defface org-inlinetask '((t :inherit shadow))
@@ -317,9 +312,8 @@ If the task has an end part, also demote it."
      ((= end start))
      ;; Inlinetask was folded: expand it.
      ((eq (get-char-property (1+ start) 'invisible) 'outline)
-      (outline-flag-region start end nil)
-      (org-cycle-hide-drawers 'children))
-     (t (outline-flag-region start end t)))))
+      (org-flag-region start end nil 'outline))
+     (t (org-flag-region start end t 'outline)))))
 
 (defun org-inlinetask-hide-tasks (state)
   "Hide inline tasks in buffer when STATE is `contents' or `children'.
diff --git a/lisp/org/org-keys.el b/lisp/org/org-keys.el
new file mode 100644
index 0000000..ae4f60d
--- /dev/null
+++ b/lisp/org/org-keys.el
@@ -0,0 +1,924 @@
+;;; org-keys.el --- Key bindings for Org mode        -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+
+;; Author: Nicolas Goaziou <address@hidden>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library adds bindings for Org mode buffers.  It also
+;; implements both Speed keys and Babel speed keys.  See manual for
+;; details.
+
+;;; Code:
+
+(defvar org-outline-regexp)
+
+(declare-function org-add-note "org" ())
+(declare-function org-agenda "org" (&optional arg org-keys restriction))
+(declare-function org-agenda-file-to-front "org" (&optional to-end))
+(declare-function org-agenda-remove-restriction-lock "org" (&optional 
noupdate))
+(declare-function org-agenda-set-restriction-lock "org" (&optional type))
+(declare-function org-archive-subtree "org" (&optional find-done))
+(declare-function org-archive-subtree-default "org" ())
+(declare-function org-archive-subtree-default-with-confirmation "org" ())
+(declare-function org-archive-to-archive-sibling "org" ())
+(declare-function org-at-heading-p "org" (&optional ignored))
+(declare-function org-attach "org" ())
+(declare-function org-backward-element "org" ())
+(declare-function org-backward-heading-same-level "org" (arg &optional 
invisible-ok))
+(declare-function org-backward-paragraph "org" ())
+(declare-function org-backward-sentence "org" (&optional arg))
+(declare-function org-beginning-of-line "org" (&optional n))
+(declare-function org-clock-cancel "org" ())
+(declare-function org-clock-display "org" (&optional arg))
+(declare-function org-clock-goto "org" (&optional select))
+(declare-function org-clock-in "org" (&optional select start-time))
+(declare-function org-clock-in-last "org" (&optional arg))
+(declare-function org-clock-out "org" (&optional switch-to-state fail-quietly 
at-time))
+(declare-function org-clone-subtree-with-time-shift "org" (n &optional shift))
+(declare-function org-columns "org" (&optional global columns-fmt-string))
+(declare-function org-comment-dwim "org" (arg))
+(declare-function org-copy "org" ())
+(declare-function org-copy-special "org" ())
+(declare-function org-copy-visible "org" (beg end))
+(declare-function org-ctrl-c-ctrl-c "org" (&optional arg))
+(declare-function org-ctrl-c-minus "org" ())
+(declare-function org-ctrl-c-ret "org" ())
+(declare-function org-ctrl-c-star "org" ())
+(declare-function org-ctrl-c-tab "org" (&optional arg))
+(declare-function org-cut-special "org" ())
+(declare-function org-cut-subtree "org" (&optional n))
+(declare-function org-cycle "org" (&optional arg))
+(declare-function org-cycle-agenda-files "org" ())
+(declare-function org-date-from-calendar "org" ())
+(declare-function org-dynamic-block-insert-dblock "org" (&optional arg))
+(declare-function org-dblock-update "org" (&optional arg))
+(declare-function org-deadline "org" (arg1 &optional time))
+(declare-function org-decrease-number-at-point "org" (&optional inc))
+(declare-function org-delete-backward-char "org" (n))
+(declare-function org-delete-char "org" (n))
+(declare-function org-delete-indentation "org" (&optional arg))
+(declare-function org-demote-subtree "org" ())
+(declare-function org-display-outline-path "org" (&optional file current 
separator just-return-string))
+(declare-function org-down-element "org" ())
+(declare-function org-edit-special "org" (&optional arg))
+(declare-function org-element-at-point "org-element" ())
+(declare-function org-element-type "org-element" (element))
+(declare-function org-emphasize "org" (&optional char))
+(declare-function org-end-of-line "org" (&optional n))
+(declare-function org-entry-put "org" (pom property value))
+(declare-function org-eval-in-calendar "org" (form &optional keepdate))
+(declare-function org-evaluate-time-range "org" (&optional to-buffer))
+(declare-function org-export-dispatch "org" (&optional arg))
+(declare-function org-feed-goto-inbox "org" (feed))
+(declare-function org-feed-update-all "org" ())
+(declare-function org-fill-paragraph "org" (&optional justify region))
+(declare-function org-find-file-at-mouse "org" (ev))
+(declare-function org-footnote-action "org" (&optional special))
+(declare-function org-force-cycle-archived "org" ())
+(declare-function org-force-self-insert "org" (n))
+(declare-function org-forward-element "org" ())
+(declare-function org-forward-heading-same-level "org" (arg &optional 
invisible-ok))
+(declare-function org-forward-paragraph "org" ())
+(declare-function org-forward-sentence "org" (&optional arg))
+(declare-function org-goto "org" (&optional alternative-interface))
+(declare-function org-goto-calendar "org" (&optional arg))
+(declare-function org-inc-effort "org" ())
+(declare-function org-increase-number-at-point "org" (&optional inc))
+(declare-function org-info-find-node "org" (&optional nodename))
+(declare-function org-insert-all-links "org" (arg &optional pre post))
+(declare-function org-insert-drawer "org" (&optional arg drawer))
+(declare-function org-insert-heading-respect-content "org" (&optional 
invisible-ok))
+(declare-function org-insert-last-stored-link "org" (arg))
+(declare-function org-insert-link "org" (&optional complete-file link-location 
default-description))
+(declare-function org-insert-structure-template "org" (type))
+(declare-function org-insert-todo-heading "org" (arg &optional force-heading))
+(declare-function org-insert-todo-heading-respect-content "org" (&optional 
force-state))
+(declare-function org-kill-line "org" (&optional arg))
+(declare-function org-kill-note-or-show-branches "org" ())
+(declare-function org-list-make-subtree "org" ())
+(declare-function org-mark-element "org" ())
+(declare-function org-mark-ring-goto "org" (&optional n))
+(declare-function org-mark-ring-push "org" (&optional pos buffer))
+(declare-function org-mark-subtree "org" (&optional up))
+(declare-function org-match-sparse-tree "org" (&optional todo-only match))
+(declare-function org-meta-return "org" (&optional arg))
+(declare-function org-metadown "org" (&optional _arg))
+(declare-function org-metaleft "org" (&optional _))
+(declare-function org-metaright "org" (&optional _arg))
+(declare-function org-metaup "org" (&optional _arg))
+(declare-function org-narrow-to-block "org" ())
+(declare-function org-narrow-to-element "org" ())
+(declare-function org-narrow-to-subtree "org" ())
+(declare-function org-next-block "org" (arg &optional backward block-regexp))
+(declare-function org-next-link "org" (&optional search-backward))
+(declare-function org-next-visible-heading "org" (arg))
+(declare-function org-open-at-mouse "org" (ev))
+(declare-function org-open-at-point "org" (&optional arg reference-buffer))
+(declare-function org-open-line "org" (n))
+(declare-function org-paste-special "org" (arg))
+(declare-function org-plot/gnuplot "org-plot" (&optional params))
+(declare-function org-previous-block "org" (arg &optional block-regexp))
+(declare-function org-previous-link "org" ())
+(declare-function org-previous-visible-heading "org" (arg))
+(declare-function org-priority "org" (&optional action show))
+(declare-function org-promote-subtree "org" ())
+(declare-function org-redisplay-inline-images "org" ())
+(declare-function org-refile "org" (&optional arg1 default-buffer rfloc msg))
+(declare-function org-reftex-citation "org" ())
+(declare-function org-reload "org" (&optional arg1))
+(declare-function org-remove-file "org" (&optional file))
+(declare-function org-resolve-clocks "org" (&optional only-dangling-p 
prompt-fn last-valid))
+(declare-function org-return "org" (&optional indent))
+(declare-function org-return-indent "org" ())
+(declare-function org-reveal "org" (&optional siblings))
+(declare-function org-schedule "org" (arg &optional time))
+(declare-function org-self-insert-command "org" (N))
+(declare-function org-set-effort "org" (&optional increment value))
+(declare-function org-set-property "org" (property value))
+(declare-function org-set-property-and-value "org" (use-last))
+(declare-function org-set-tags-command "org" (&optional arg))
+(declare-function org-shiftcontroldown "org" (&optional n))
+(declare-function org-shiftcontrolleft "org" ())
+(declare-function org-shiftcontrolright "org" ())
+(declare-function org-shiftcontrolup "org" (&optional n))
+(declare-function org-shiftdown "org" (&optional arg))
+(declare-function org-shiftleft "org" (&optional arg))
+(declare-function org-shiftmetadown "org" (&optional _arg))
+(declare-function org-shiftmetaleft "org" ())
+(declare-function org-shiftmetaright "org" ())
+(declare-function org-shiftmetaup "org" (&optional arg))
+(declare-function org-shiftright "org" (&optional arg))
+(declare-function org-shifttab "org" (&optional arg))
+(declare-function org-shiftup "org" (&optional arg))
+(declare-function org-show-all "org" (&optional types))
+(declare-function org-show-children "org" (&optional level))
+(declare-function org-show-subtree "org" ())
+(declare-function org-sort "org" (&optional with-case))
+(declare-function org-sparse-tree "org" (&optional arg type))
+(declare-function org-table-blank-field "org" ())
+(declare-function org-table-copy-down "org" (n))
+(declare-function org-table-create-or-convert-from-region "org" (arg))
+(declare-function org-table-create-with-table\.el "org-table" ())
+(declare-function org-table-edit-field "org" (arg))
+(declare-function org-table-eval-formula "org" (&optional arg equation 
suppress-align suppress-const suppress-store suppress-analysis))
+(declare-function org-table-field-info "org" (arg))
+(declare-function org-table-rotate-recalc-marks "org" (&optional newchar))
+(declare-function org-table-sum "org" (&optional beg end nlast))
+(declare-function org-table-toggle-coordinate-overlays "org" ())
+(declare-function org-table-toggle-formula-debugger "org" ())
+(declare-function org-time-stamp "org" (arg &optional inactive))
+(declare-function org-time-stamp-inactive "org" (&optional arg))
+(declare-function org-timer "org" (&optional restart no-insert))
+(declare-function org-timer-item "org" (&optional arg))
+(declare-function org-timer-pause-or-continue "org" (&optional stop))
+(declare-function org-timer-set-timer "org" (&optional opt))
+(declare-function org-timer-start "org" (&optional offset))
+(declare-function org-timer-stop "org" ())
+(declare-function org-todo "org" (&optional arg1))
+(declare-function org-toggle-archive-tag "org" (&optional find-done))
+(declare-function org-toggle-checkbox "org" (&optional toggle-presence))
+(declare-function org-toggle-comment "org" ())
+(declare-function org-toggle-fixed-width "org" ())
+(declare-function org-toggle-inline-images "org" (&optional include-linked))
+(declare-function org-latex-preview "org" (&optional arg))
+(declare-function org-toggle-narrow-to-subtree "org" ())
+(declare-function org-toggle-ordered-property "org" ())
+(declare-function org-toggle-pretty-entities "org" ())
+(declare-function org-toggle-tags-groups "org" ())
+(declare-function org-toggle-time-stamp-overlays "org" ())
+(declare-function org-transpose-element "org" ())
+(declare-function org-transpose-words "org" ())
+(declare-function org-tree-to-indirect-buffer "org" (&optional arg))
+(declare-function org-up-element "org" ())
+(declare-function org-update-statistics-cookies "org" (all))
+(declare-function org-yank "org" (&optional arg))
+(declare-function orgtbl-ascii-plot "org-table" (&optional ask))
+
+
+
+;;; Variables
+
+(defvar org-mode-map (make-sparse-keymap)
+  "Keymap fo Org mode.")
+
+(defcustom org-replace-disputed-keys nil
+  "Non-nil means use alternative key bindings for some keys.
+
+Org mode uses S-<cursor> keys for changing timestamps and priorities.
+These keys are also used by other packages like Shift Select mode,
+CUA mode or Windmove.  If you want to use Org mode together with
+one of these other modes, or more generally if you would like to
+move some Org mode commands to other keys, set this variable and
+configure the keys with the variable `org-disputed-keys'.
+
+This option is only relevant at load-time of Org mode, and must be set
+*before* org.el is loaded.  Changing it requires a restart of Emacs to
+become effective."
+  :group 'org-startup
+  :type 'boolean
+  :safe #'booleanp)
+
+(defcustom org-use-extra-keys nil
+  "Non-nil means use extra key sequence definitions for certain commands.
+This happens automatically if `window-system' is nil.  This
+variable lets you do the same manually.  You must set it before
+loading Org."
+  :group 'org-startup
+  :type 'boolean
+  :safe #'booleanp)
+
+(defvaralias 'org-CUA-compatible 'org-replace-disputed-keys)
+
+(defcustom org-disputed-keys
+  '(([(shift up)]              . [(meta p)])
+    ([(shift down)]            . [(meta n)])
+    ([(shift left)]            . [(meta -)])
+    ([(shift right)]           . [(meta +)])
+    ([(control shift right)]    . [(meta shift +)])
+    ([(control shift left)]    . [(meta shift -)]))
+  "Keys for which Org mode and other modes compete.
+This is an alist, cars are the default keys, second element specifies
+the alternative to use when `org-replace-disputed-keys' is t.
+
+Keys can be specified in any syntax supported by `define-key'.
+The value of this option takes effect only at Org mode startup,
+therefore you'll have to restart Emacs to apply it after changing."
+  :group 'org-startup
+  :type 'alist)
+
+(defcustom org-mouse-1-follows-link
+  (if (boundp 'mouse-1-click-follows-link) mouse-1-click-follows-link t)
+  "Non-nil means mouse-1 on a link will follow the link.
+A longer mouse click will still set point.  Needs to be set
+before org.el is loaded."
+  :group 'org-link-follow
+  :version "26.1"
+  :package-version '(Org . "8.3")
+  :type '(choice
+         (const :tag "A double click follows the link" double)
+         (const :tag "Unconditionally follow the link with mouse-1" t)
+         (integer :tag "mouse-1 click does not follow the link if longer than 
N ms" 450))
+  :safe t)
+
+(defcustom org-tab-follows-link nil
+  "Non-nil means on links TAB will follow the link.
+Needs to be set before Org is loaded.
+This really should not be used, it does not make sense, and the
+implementation is bad."
+  :group 'org-link-follow
+  :type 'boolean)
+
+(defcustom org-follow-link-hook nil
+  "Hook that is run after a link has been followed."
+  :group 'org-link-follow
+  :type 'hook)
+
+(defcustom org-return-follows-link nil
+  "Non-nil means on links RET will follow the link.
+In tables, the special behavior of RET has precedence."
+  :group 'org-link-follow
+  :type 'boolean
+  :safe t)
+
+
+;;; Functions
+
+;;;; Base functions
+(defun org-key (key)
+  "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
+Or return the original if not disputed."
+  (when org-replace-disputed-keys
+    (let* ((nkey (key-description key))
+          (x (cl-find-if (lambda (x) (equal (key-description (car x)) nkey))
+                         org-disputed-keys)))
+      (setq key (if x (cdr x) key))))
+  key)
+
+(defun org-defkey (keymap key def)
+  "Define a key, possibly translated, as returned by `org-key'."
+  (define-key keymap (org-key key) def))
+
+(defun org-remap (map &rest commands)
+  "In MAP, remap the functions given in COMMANDS.
+COMMANDS is a list of alternating OLDDEF NEWDEF command names."
+  (let (new old)
+    (while commands
+      (setq old (pop commands) new (pop commands))
+      (org-defkey map (vector 'remap old) new))))
+
+
+;;; Mouse map
+
+(defvar org-mouse-map (make-sparse-keymap))
+(org-defkey org-mouse-map [mouse-2] 'org-open-at-mouse)
+(org-defkey org-mouse-map [mouse-3] 'org-find-file-at-mouse)
+
+(when org-mouse-1-follows-link
+  (org-defkey org-mouse-map [follow-link] 'mouse-face))
+
+(when org-tab-follows-link
+  (org-defkey org-mouse-map (kbd "<tab>") #'org-open-at-point)
+  (org-defkey org-mouse-map (kbd "TAB") #'org-open-at-point))
+
+
+;;; Read date map
+
+(defvar org-read-date-minibuffer-local-map
+  (let* ((map (make-sparse-keymap)))
+    (set-keymap-parent map minibuffer-local-map)
+    (org-defkey map (kbd ".")
+                (lambda () (interactive)
+                 ;; Are we at the beginning of the prompt?
+                 (if (looking-back "^[^:]+: "
+                                   (let ((inhibit-field-text-motion t))
+                                     (line-beginning-position)))
+                     (org-eval-in-calendar '(calendar-goto-today))
+                   (insert "."))))
+    (org-defkey map (kbd "C-.")
+                (lambda () (interactive)
+                 (org-eval-in-calendar '(calendar-goto-today))))
+    (org-defkey map (kbd "M-S-<left>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-backward-month 1))))
+    (org-defkey map (kbd "ESC S-<left>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-backward-month 1))))
+    (org-defkey map (kbd "M-S-<right>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-forward-month 1))))
+    (org-defkey map (kbd "ESC S-<right>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-forward-month 1))))
+    (org-defkey map (kbd "M-S-<up>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-backward-year 1))))
+    (org-defkey map (kbd "ESC S-<up>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-backward-year 1))))
+    (org-defkey map (kbd "M-S-<down>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-forward-year 1))))
+    (org-defkey map (kbd "ESC S-<down>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-forward-year 1))))
+    (org-defkey map (kbd "S-<up>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-backward-week 1))))
+    (org-defkey map (kbd "S-<down>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-forward-week 1))))
+    (org-defkey map (kbd "S-<left>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-backward-day 1))))
+    (org-defkey map (kbd "S-<right>")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-forward-day 1))))
+    (org-defkey map (kbd "!")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(diary-view-entries))
+                  (message "")))
+    (org-defkey map (kbd ">")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-scroll-left 1))))
+    (org-defkey map (kbd "<")
+                (lambda () (interactive)
+                  (org-eval-in-calendar '(calendar-scroll-right 1))))
+    (org-defkey map (kbd "C-v")
+                (lambda () (interactive)
+                  (org-eval-in-calendar
+                   '(calendar-scroll-left-three-months 1))))
+    (org-defkey map (kbd "M-v")
+                (lambda () (interactive)
+                  (org-eval-in-calendar
+                   '(calendar-scroll-right-three-months 1))))
+    map)
+  "Keymap for minibuffer commands when using `org-read-date'.")
+
+
+;;; Global bindings
+
+;;;; Outline functions
+(define-key org-mode-map [menu-bar headings] 'undefined)
+(define-key org-mode-map [menu-bar hide] 'undefined)
+(define-key org-mode-map [menu-bar show] 'undefined)
+
+(define-key org-mode-map [remap outline-mark-subtree] #'org-mark-subtree)
+(define-key org-mode-map [remap outline-show-subtree] #'org-show-subtree)
+(define-key org-mode-map [remap outline-forward-same-level]
+  #'org-forward-heading-same-level)
+(define-key org-mode-map [remap outline-backward-same-level]
+  #'org-backward-heading-same-level)
+(define-key org-mode-map [remap outline-show-branches]
+  #'org-kill-note-or-show-branches)
+(define-key org-mode-map [remap outline-promote] #'org-promote-subtree)
+(define-key org-mode-map [remap outline-demote] #'org-demote-subtree)
+(define-key org-mode-map [remap outline-insert-heading] #'org-ctrl-c-ret)
+(define-key org-mode-map [remap outline-next-visible-heading]
+  #'org-next-visible-heading)
+(define-key org-mode-map [remap outline-previous-visible-heading]
+  #'org-previous-visible-heading)
+(define-key org-mode-map [remap show-children] #'org-show-children)
+
+;;;; Make `C-c C-x' a prefix key
+(org-defkey org-mode-map (kbd "C-c C-x") (make-sparse-keymap))
+
+;;;; TAB key with modifiers
+(org-defkey org-mode-map (kbd "C-i") #'org-cycle)
+(org-defkey org-mode-map (kbd "<tab>") #'org-cycle)
+(org-defkey org-mode-map (kbd "C-<tab>") #'org-force-cycle-archived)
+;; Override text-mode binding to expose `complete-symbol' for
+;; pcomplete functionality.
+(org-defkey org-mode-map (kbd "M-<tab>") nil)
+(org-defkey org-mode-map (kbd "M-TAB") nil)
+(org-defkey org-mode-map (kbd "ESC <tab>") nil)
+(org-defkey org-mode-map (kbd "ESC TAB") nil)
+
+(org-defkey org-mode-map (kbd "<S-iso-leftab>") #'org-shifttab)
+(org-defkey org-mode-map (kbd "S-<tab>") #'org-shifttab)
+(org-defkey org-mode-map (kbd "S-TAB") #'org-shifttab)
+(define-key org-mode-map (kbd "<backtab>") #'org-shifttab)
+
+;;;; RET/<return> key with modifiers
+(org-defkey org-mode-map (kbd "S-<return>") #'org-table-copy-down)
+(org-defkey org-mode-map (kbd "S-RET") #'org-table-copy-down)
+(org-defkey org-mode-map (kbd "M-S-<return>") #'org-insert-todo-heading)
+(org-defkey org-mode-map (kbd "M-S-RET") #'org-insert-todo-heading)
+(org-defkey org-mode-map (kbd "ESC S-<return>") #'org-insert-todo-heading)
+(org-defkey org-mode-map (kbd "ESC S-RET") #'org-insert-todo-heading)
+(org-defkey org-mode-map (kbd "M-<return>") #'org-meta-return)
+(org-defkey org-mode-map (kbd "M-RET") #'org-meta-return)
+(org-defkey org-mode-map (kbd "ESC <return>") #'org-meta-return)
+(org-defkey org-mode-map (kbd "ESC RET") #'org-meta-return)
+
+;;;; Cursor keys with modifiers
+(org-defkey org-mode-map (kbd "M-<left>") #'org-metaleft)
+(org-defkey org-mode-map (kbd "M-<right>") #'org-metaright)
+(org-defkey org-mode-map (kbd "ESC <right>") #'org-metaright)
+(org-defkey org-mode-map (kbd "M-<up>") #'org-metaup)
+(org-defkey org-mode-map (kbd "ESC <up>") #'org-metaup)
+(org-defkey org-mode-map (kbd "M-<down>") #'org-metadown)
+(org-defkey org-mode-map (kbd "ESC <down>") #'org-metadown)
+
+(org-defkey org-mode-map (kbd "C-M-S-<right>") #'org-increase-number-at-point)
+(org-defkey org-mode-map (kbd "C-M-S-<left>") #'org-decrease-number-at-point)
+(org-defkey org-mode-map (kbd "M-S-<left>") #'org-shiftmetaleft)
+(org-defkey org-mode-map (kbd "ESC S-<left>") #'org-shiftmetaleft)
+(org-defkey org-mode-map (kbd "M-S-<right>") #'org-shiftmetaright)
+(org-defkey org-mode-map (kbd "ESC S-<right>") #'org-shiftmetaright)
+(org-defkey org-mode-map (kbd "M-S-<up>") #'org-shiftmetaup)
+(org-defkey org-mode-map (kbd "ESC S-<up>") #'org-shiftmetaup)
+(org-defkey org-mode-map (kbd "M-S-<down>") #'org-shiftmetadown)
+(org-defkey org-mode-map (kbd "ESC S-<down>") #'org-shiftmetadown)
+
+(org-defkey org-mode-map (kbd "S-<up>") #'org-shiftup)
+(org-defkey org-mode-map (kbd "S-<down>") #'org-shiftdown)
+(org-defkey org-mode-map (kbd "S-<left>") #'org-shiftleft)
+(org-defkey org-mode-map (kbd "S-<right>") #'org-shiftright)
+
+(org-defkey org-mode-map (kbd "C-S-<right>") #'org-shiftcontrolright)
+(org-defkey org-mode-map (kbd "C-S-<left>") #'org-shiftcontrolleft)
+(org-defkey org-mode-map (kbd "C-S-<up>") #'org-shiftcontrolup)
+(org-defkey org-mode-map (kbd "C-S-<down>") #'org-shiftcontroldown)
+
+;;;; Extra keys for TTY access.
+
+;;  We only set them when really needed because otherwise the
+;;  menus don't show the simple keys
+
+(when (or org-use-extra-keys (not window-system))
+  (org-defkey org-mode-map (kbd "C-c C-x c") #'org-table-copy-down)
+  (org-defkey org-mode-map (kbd "C-c C-x m") #'org-meta-return)
+  (org-defkey org-mode-map (kbd "C-c C-x M") #'org-insert-todo-heading)
+  (org-defkey org-mode-map (kbd "C-c C-x RET") #'org-meta-return)
+  (org-defkey org-mode-map (kbd "ESC RET") #'org-meta-return)
+  (org-defkey org-mode-map (kbd "ESC <left>") #'org-metaleft)
+  (org-defkey org-mode-map (kbd "C-c C-x l") #'org-metaleft)
+  (org-defkey org-mode-map (kbd "ESC <right>") #'org-metaright)
+  (org-defkey org-mode-map (kbd "C-c C-x r") #'org-metaright)
+  (org-defkey org-mode-map (kbd "C-c C-x u") #'org-metaup)
+  (org-defkey org-mode-map (kbd "C-c C-x d") #'org-metadown)
+  (org-defkey org-mode-map (kbd "C-c C-x L") #'org-shiftmetaleft)
+  (org-defkey org-mode-map (kbd "C-c C-x R") #'org-shiftmetaright)
+  (org-defkey org-mode-map (kbd "C-c C-x U") #'org-shiftmetaup)
+  (org-defkey org-mode-map (kbd "C-c C-x D") #'org-shiftmetadown)
+  (org-defkey org-mode-map (kbd "C-c <up>") #'org-shiftup)
+  (org-defkey org-mode-map (kbd "C-c <down>") #'org-shiftdown)
+  (org-defkey org-mode-map (kbd "C-c <left>") #'org-shiftleft)
+  (org-defkey org-mode-map (kbd "C-c <right>") #'org-shiftright)
+  (org-defkey org-mode-map (kbd "C-c C-x <right>") #'org-shiftcontrolright)
+  (org-defkey org-mode-map (kbd "C-c C-x <left>") #'org-shiftcontrolleft))
+
+;;;; Narrowing bindings
+(org-defkey org-mode-map (kbd "C-x n s") #'org-narrow-to-subtree)
+(org-defkey org-mode-map (kbd "C-x n b") #'org-narrow-to-block)
+(org-defkey org-mode-map (kbd "C-x n e") #'org-narrow-to-element)
+
+;;;; Remap usual Emacs bindings
+(org-remap org-mode-map
+          'self-insert-command    'org-self-insert-command
+          'delete-char            'org-delete-char
+          'delete-backward-char   'org-delete-backward-char
+          'kill-line              'org-kill-line
+          'open-line              'org-open-line
+          'yank                   'org-yank
+          'comment-dwim           'org-comment-dwim
+          'move-beginning-of-line 'org-beginning-of-line
+          'move-end-of-line       'org-end-of-line
+          'forward-paragraph      'org-forward-paragraph
+          'backward-paragraph     'org-backward-paragraph
+          'backward-sentence      'org-backward-sentence
+          'forward-sentence       'org-forward-sentence
+          'fill-paragraph         'org-fill-paragraph
+          'delete-indentation     'org-delete-indentation
+          'transpose-words        'org-transpose-words)
+
+;;;; All the other keys
+(org-defkey org-mode-map (kbd "|") #'org-force-self-insert)
+(org-defkey org-mode-map (kbd "C-c C-r") #'org-reveal)
+(org-defkey org-mode-map (kbd "C-M-t") #'org-transpose-element)
+(org-defkey org-mode-map (kbd "M-}") #'org-forward-element)
+(org-defkey org-mode-map (kbd "ESC }") #'org-forward-element)
+(org-defkey org-mode-map (kbd "M-{") #'org-backward-element)
+(org-defkey org-mode-map (kbd "ESC {") #'org-backward-element)
+(org-defkey org-mode-map (kbd "C-c C-^") #'org-up-element)
+(org-defkey org-mode-map (kbd "C-c C-_") #'org-down-element)
+(org-defkey org-mode-map (kbd "C-c C-f") #'org-forward-heading-same-level)
+(org-defkey org-mode-map (kbd "C-c C-b") #'org-backward-heading-same-level)
+(org-defkey org-mode-map (kbd "C-c M-f") #'org-next-block)
+(org-defkey org-mode-map (kbd "C-c M-b") #'org-previous-block)
+(org-defkey org-mode-map (kbd "C-c $") #'org-archive-subtree)
+(org-defkey org-mode-map (kbd "C-c C-x C-s") #'org-archive-subtree)
+(org-defkey org-mode-map (kbd "C-c C-x C-a") #'org-archive-subtree-default)
+(org-defkey org-mode-map (kbd "C-c C-x d") #'org-insert-drawer)
+(org-defkey org-mode-map (kbd "C-c C-x a") #'org-toggle-archive-tag)
+(org-defkey org-mode-map (kbd "C-c C-x A") #'org-archive-to-archive-sibling)
+(org-defkey org-mode-map (kbd "C-c C-x b") #'org-tree-to-indirect-buffer)
+(org-defkey org-mode-map (kbd "C-c C-x q") #'org-toggle-tags-groups)
+(org-defkey org-mode-map (kbd "C-c C-j") #'org-goto)
+(org-defkey org-mode-map (kbd "C-c C-t") #'org-todo)
+(org-defkey org-mode-map (kbd "C-c C-q") #'org-set-tags-command)
+(org-defkey org-mode-map (kbd "C-c C-s") #'org-schedule)
+(org-defkey org-mode-map (kbd "C-c C-d") #'org-deadline)
+(org-defkey org-mode-map (kbd "C-c ;") #'org-toggle-comment)
+(org-defkey org-mode-map (kbd "C-c C-w") #'org-refile)
+(org-defkey org-mode-map (kbd "C-c M-w") #'org-copy)
+(org-defkey org-mode-map (kbd "C-c /") #'org-sparse-tree) ;minor-mode reserved
+(org-defkey org-mode-map (kbd "C-c \\") #'org-match-sparse-tree) ;minor-mode r.
+(org-defkey org-mode-map (kbd "C-c RET") #'org-ctrl-c-ret)
+(org-defkey org-mode-map (kbd "C-c C-x c") #'org-clone-subtree-with-time-shift)
+(org-defkey org-mode-map (kbd "C-c C-x v") #'org-copy-visible)
+(org-defkey org-mode-map (kbd "C-<return>") 
#'org-insert-heading-respect-content)
+(org-defkey org-mode-map (kbd "C-S-<return>") 
#'org-insert-todo-heading-respect-content)
+(org-defkey org-mode-map (kbd "C-c C-x C-n") #'org-next-link)
+(org-defkey org-mode-map (kbd "C-c C-x C-p") #'org-previous-link)
+(org-defkey org-mode-map (kbd "C-c C-l") #'org-insert-link)
+(org-defkey org-mode-map (kbd "C-c M-l") #'org-insert-last-stored-link)
+(org-defkey org-mode-map (kbd "C-c C-M-l") #'org-insert-all-links)
+(org-defkey org-mode-map (kbd "C-c C-o") #'org-open-at-point)
+(org-defkey org-mode-map (kbd "C-c %") #'org-mark-ring-push)
+(org-defkey org-mode-map (kbd "C-c &") #'org-mark-ring-goto)
+(org-defkey org-mode-map (kbd "C-c C-z") #'org-add-note) ;alternative binding
+(org-defkey org-mode-map (kbd "C-c .") #'org-time-stamp) ;minor-mode reserved
+(org-defkey org-mode-map (kbd "C-c !") #'org-time-stamp-inactive) ;minor-mode 
r.
+(org-defkey org-mode-map (kbd "C-c ,") #'org-priority) ;minor-mode reserved
+(org-defkey org-mode-map (kbd "C-c C-y") #'org-evaluate-time-range)
+(org-defkey org-mode-map (kbd "C-c >") #'org-goto-calendar)
+(org-defkey org-mode-map (kbd "C-c <") #'org-date-from-calendar)
+(org-defkey org-mode-map (kbd "C-,") #'org-cycle-agenda-files)
+(org-defkey org-mode-map (kbd "C-'") #'org-cycle-agenda-files)
+(org-defkey org-mode-map (kbd "C-c [") #'org-agenda-file-to-front)
+(org-defkey org-mode-map (kbd "C-c ]") #'org-remove-file)
+(org-defkey org-mode-map (kbd "C-c C-x <") #'org-agenda-set-restriction-lock)
+(org-defkey org-mode-map (kbd "C-c C-x >") 
#'org-agenda-remove-restriction-lock)
+(org-defkey org-mode-map (kbd "C-c -") #'org-ctrl-c-minus)
+(org-defkey org-mode-map (kbd "C-c *") #'org-ctrl-c-star)
+(org-defkey org-mode-map (kbd "C-c TAB") #'org-ctrl-c-tab)
+(org-defkey org-mode-map (kbd "C-c ^") #'org-sort)
+(org-defkey org-mode-map (kbd "C-c C-c") #'org-ctrl-c-ctrl-c)
+(org-defkey org-mode-map (kbd "C-c C-k") #'org-kill-note-or-show-branches)
+(org-defkey org-mode-map (kbd "C-c #") #'org-update-statistics-cookies)
+(org-defkey org-mode-map (kbd "RET") #'org-return)
+(org-defkey org-mode-map (kbd "C-j") #'org-return-indent)
+(org-defkey org-mode-map (kbd "C-c ?") #'org-table-field-info)
+(org-defkey org-mode-map (kbd "C-c SPC") #'org-table-blank-field)
+(org-defkey org-mode-map (kbd "C-c +") #'org-table-sum)
+(org-defkey org-mode-map (kbd "C-c =") #'org-table-eval-formula)
+(org-defkey org-mode-map (kbd "C-c '") #'org-edit-special)
+(org-defkey org-mode-map (kbd "C-c `") #'org-table-edit-field)
+(org-defkey org-mode-map (kbd "C-c \" a") #'orgtbl-ascii-plot)
+(org-defkey org-mode-map (kbd "C-c \" g") #'org-plot/gnuplot)
+(org-defkey org-mode-map (kbd "C-c |") 
#'org-table-create-or-convert-from-region)
+(org-defkey org-mode-map (kbd "C-#") #'org-table-rotate-recalc-marks)
+(org-defkey org-mode-map (kbd "C-c ~") #'org-table-create-with-table.el)
+(org-defkey org-mode-map (kbd "C-c C-a") #'org-attach)
+(org-defkey org-mode-map (kbd "C-c }") #'org-table-toggle-coordinate-overlays)
+(org-defkey org-mode-map (kbd "C-c {") #'org-table-toggle-formula-debugger)
+(org-defkey org-mode-map (kbd "C-c C-e") #'org-export-dispatch)
+(org-defkey org-mode-map (kbd "C-c :") #'org-toggle-fixed-width)
+(org-defkey org-mode-map (kbd "C-c C-x C-f") #'org-emphasize)
+(org-defkey org-mode-map (kbd "C-c C-x f") #'org-footnote-action)
+(org-defkey org-mode-map (kbd "C-c @") #'org-mark-subtree)
+(org-defkey org-mode-map (kbd "M-h") #'org-mark-element)
+(org-defkey org-mode-map (kbd "ESC h") #'org-mark-element)
+(org-defkey org-mode-map (kbd "C-c C-*") #'org-list-make-subtree)
+(org-defkey org-mode-map (kbd "C-c C-x C-w") #'org-cut-special)
+(org-defkey org-mode-map (kbd "C-c C-x M-w") #'org-copy-special)
+(org-defkey org-mode-map (kbd "C-c C-x C-y") #'org-paste-special)
+(org-defkey org-mode-map (kbd "C-c C-x C-t") #'org-toggle-time-stamp-overlays)
+(org-defkey org-mode-map (kbd "C-c C-x C-i") #'org-clock-in)
+(org-defkey org-mode-map (kbd "C-c C-x C-x") #'org-clock-in-last)
+(org-defkey org-mode-map (kbd "C-c C-x C-z") #'org-resolve-clocks)
+(org-defkey org-mode-map (kbd "C-c C-x C-o") #'org-clock-out)
+(org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
+(org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
+(org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
+(org-defkey org-mode-map (kbd "C-c C-x x") #'org-dynamic-block-insert-dblock)
+(org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
+(org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-latex-preview)
+(org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
+(org-defkey org-mode-map (kbd "C-c C-x C-M-v") #'org-redisplay-inline-images)
+(org-defkey org-mode-map (kbd "C-c C-x \\") #'org-toggle-pretty-entities)
+(org-defkey org-mode-map (kbd "C-c C-x C-b") #'org-toggle-checkbox)
+(org-defkey org-mode-map (kbd "C-c C-x p") #'org-set-property)
+(org-defkey org-mode-map (kbd "C-c C-x P") #'org-set-property-and-value)
+(org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
+(org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
+(org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
+(org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
+(org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
+(org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
+(org-defkey org-mode-map (kbd "C-c C-x 0") #'org-timer-start)
+(org-defkey org-mode-map (kbd "C-c C-x _") #'org-timer-stop)
+(org-defkey org-mode-map (kbd "C-c C-x ;") #'org-timer-set-timer)
+(org-defkey org-mode-map (kbd "C-c C-x ,") #'org-timer-pause-or-continue)
+(org-defkey org-mode-map (kbd "C-c C-x C-c") #'org-columns)
+(org-defkey org-mode-map (kbd "C-c C-x !") #'org-reload)
+(org-defkey org-mode-map (kbd "C-c C-x g") #'org-feed-update-all)
+(org-defkey org-mode-map (kbd "C-c C-x G") #'org-feed-goto-inbox)
+(org-defkey org-mode-map (kbd "C-c C-x [") #'org-reftex-citation)
+(org-defkey org-mode-map (kbd "C-c C-x I") #'org-info-find-node)
+
+
+;;; Speed keys
+
+(defcustom org-use-speed-commands nil
+  "Non-nil means activate single letter commands at beginning of a headline.
+This may also be a function to test for appropriate locations where speed
+commands should be active.
+
+For example, to activate speed commands when the point is on any
+star at the beginning of the headline, you can do this:
+
+  (setq org-use-speed-commands
+      (lambda () (and (looking-at org-outline-regexp) (looking-back 
\"^\\**\"))))"
+  :group 'org-structure
+  :type '(choice
+         (const :tag "Never" nil)
+         (const :tag "At beginning of headline stars" t)
+         (function)))
+
+(defcustom org-speed-commands-user nil
+  "Alist of additional speed commands.
+This list will be checked before `org-speed-commands-default'
+when the variable `org-use-speed-commands' is non-nil
+and when the cursor is at the beginning of a headline.
+The car of each entry is a string with a single letter, which must
+be assigned to `self-insert-command' in the global map.
+The cdr is either a command to be called interactively, a function
+to be called, or a form to be evaluated.
+An entry that is just a list with a single string will be interpreted
+as a descriptive headline that will be added when listing the speed
+commands in the Help buffer using the `?' speed command."
+  :group 'org-structure
+  :type '(repeat :value ("k" . ignore)
+                (choice :value ("k" . ignore)
+                        (list :tag "Descriptive Headline" (string :tag 
"Headline"))
+                        (cons :tag "Letter and Command"
+                              (string :tag "Command letter")
+                              (choice
+                               (function)
+                               (sexp))))))
+
+(defcustom org-speed-command-hook
+  '(org-speed-command-activate org-babel-speed-command-activate)
+  "Hook for activating speed commands at strategic locations.
+Hook functions are called in sequence until a valid handler is
+found.
+
+Each hook takes a single argument, a user-pressed command key
+which is also a `self-insert-command' from the global map.
+
+Within the hook, examine the cursor position and the command key
+and return nil or a valid handler as appropriate.  Handler could
+be one of an interactive command, a function, or a form.
+
+Set `org-use-speed-commands' to non-nil value to enable this
+hook.  The default setting is `org-speed-command-activate'."
+  :group 'org-structure
+  :version "24.1"
+  :type 'hook)
+
+(defconst org-speed-commands-default
+  '(("Outline Navigation")
+    ("n" . (org-speed-move-safe 'org-next-visible-heading))
+    ("p" . (org-speed-move-safe 'org-previous-visible-heading))
+    ("f" . (org-speed-move-safe 'org-forward-heading-same-level))
+    ("b" . (org-speed-move-safe 'org-backward-heading-same-level))
+    ("F" . org-next-block)
+    ("B" . org-previous-block)
+    ("u" . (org-speed-move-safe 'outline-up-heading))
+    ("j" . org-goto)
+    ("g" . (org-refile t))
+    ("Outline Visibility")
+    ("c" . org-cycle)
+    ("C" . org-shifttab)
+    (" " . org-display-outline-path)
+    ("s" . org-toggle-narrow-to-subtree)
+    ("k" . org-cut-subtree)
+    ("=" . org-columns)
+    ("Outline Structure Editing")
+    ("U" . org-metaup)
+    ("D" . org-metadown)
+    ("r" . org-metaright)
+    ("l" . org-metaleft)
+    ("R" . org-shiftmetaright)
+    ("L" . org-shiftmetaleft)
+    ("i" . (progn (forward-char 1) (call-interactively
+                                   'org-insert-heading-respect-content)))
+    ("^" . org-sort)
+    ("w" . org-refile)
+    ("a" . org-archive-subtree-default-with-confirmation)
+    ("@" . org-mark-subtree)
+    ("#" . org-toggle-comment)
+    ("Clock Commands")
+    ("I" . org-clock-in)
+    ("O" . org-clock-out)
+    ("Meta Data Editing")
+    ("t" . org-todo)
+    ("," . (org-priority))
+    ("0" . (org-priority ?\ ))
+    ("1" . (org-priority ?A))
+    ("2" . (org-priority ?B))
+    ("3" . (org-priority ?C))
+    (":" . org-set-tags-command)
+    ("e" . org-set-effort)
+    ("E" . org-inc-effort)
+    ("W" . (lambda(m) (interactive "sMinutes before warning: ")
+            (org-entry-put (point) "APPT_WARNTIME" m)))
+    ("Agenda Views etc")
+    ("v" . org-agenda)
+    ("/" . org-sparse-tree)
+    ("Misc")
+    ("o" . org-open-at-point)
+    ("?" . org-speed-command-help)
+    ("<" . (org-agenda-set-restriction-lock 'subtree))
+    (">" . (org-agenda-remove-restriction-lock)))
+  "The default speed commands.")
+
+(defun org-print-speed-command (e)
+  (if (> (length (car e)) 1)
+      (progn
+       (princ "\n")
+       (princ (car e))
+       (princ "\n")
+       (princ (make-string (length (car e)) ?-))
+       (princ "\n"))
+    (princ (car e))
+    (princ "   ")
+    (if (symbolp (cdr e))
+       (princ (symbol-name (cdr e)))
+      (prin1 (cdr e)))
+    (princ "\n")))
+
+(defun org-speed-command-help ()
+  "Show the available speed commands."
+  (interactive)
+  (unless org-use-speed-commands
+    (user-error "Speed commands are not activated, customize 
`org-use-speed-commands'"))
+  (with-output-to-temp-buffer "*Help*"
+    (princ "User-defined Speed commands\n===========================\n")
+    (mapc #'org-print-speed-command org-speed-commands-user)
+    (princ "\n")
+    (princ "Built-in Speed commands\n=======================\n")
+    (mapc #'org-print-speed-command org-speed-commands-default))
+  (with-current-buffer "*Help*"
+    (setq truncate-lines t)))
+
+(defun org-speed-move-safe (cmd)
+  "Execute CMD, but make sure that the cursor always ends up in a headline.
+If not, return to the original position and throw an error."
+  (interactive)
+  (let ((pos (point)))
+    (call-interactively cmd)
+    (unless (and (bolp) (org-at-heading-p))
+      (goto-char pos)
+      (error "Boundary reached while executing %s" cmd))))
+
+(defun org-speed-command-activate (keys)
+  "Hook for activating single-letter speed commands.
+`org-speed-commands-default' specifies a minimal command set.
+Use `org-speed-commands-user' for further customization."
+  (when (or (and (bolp) (looking-at org-outline-regexp))
+           (and (functionp org-use-speed-commands)
+                (funcall org-use-speed-commands)))
+    (cdr (assoc keys (append org-speed-commands-user
+                            org-speed-commands-default)))))
+
+
+;;; Babel speed keys
+
+(defvar org-babel-key-prefix "\C-c\C-v"
+  "The key prefix for Babel interactive key-bindings.
+See `org-babel-key-bindings' for the list of interactive Babel
+functions which are assigned key bindings, and see
+`org-babel-map' for the actual babel keymap.")
+
+(defvar org-babel-map (make-sparse-keymap)
+  "The keymap for interactive Babel functions.")
+
+(defvar org-babel-key-bindings
+  '(("p" . org-babel-previous-src-block)
+    ("\C-p" . org-babel-previous-src-block)
+    ("n" . org-babel-next-src-block)
+    ("\C-n" . org-babel-next-src-block)
+    ("e" . org-babel-execute-maybe)
+    ("\C-e" . org-babel-execute-maybe)
+    ("o" . org-babel-open-src-block-result)
+    ("\C-o" . org-babel-open-src-block-result)
+    ("\C-v" . org-babel-expand-src-block)
+    ("v" . org-babel-expand-src-block)
+    ("u" . org-babel-goto-src-block-head)
+    ("\C-u" . org-babel-goto-src-block-head)
+    ("g" . org-babel-goto-named-src-block)
+    ("r" . org-babel-goto-named-result)
+    ("\C-r" . org-babel-goto-named-result)
+    ("\C-b" . org-babel-execute-buffer)
+    ("b" . org-babel-execute-buffer)
+    ("\C-s" . org-babel-execute-subtree)
+    ("s" . org-babel-execute-subtree)
+    ("\C-d" . org-babel-demarcate-block)
+    ("d" . org-babel-demarcate-block)
+    ("\C-t" . org-babel-tangle)
+    ("t" . org-babel-tangle)
+    ("\C-f" . org-babel-tangle-file)
+    ("f" . org-babel-tangle-file)
+    ("\C-c" . org-babel-check-src-block)
+    ("c" . org-babel-check-src-block)
+    ("\C-j" . org-babel-insert-header-arg)
+    ("j" . org-babel-insert-header-arg)
+    ("\C-l" . org-babel-load-in-session)
+    ("l" . org-babel-load-in-session)
+    ("\C-i" . org-babel-lob-ingest)
+    ("i" . org-babel-lob-ingest)
+    ("\C-I" . org-babel-view-src-block-info)
+    ("I" . org-babel-view-src-block-info)
+    ("\C-z" . org-babel-switch-to-session)
+    ("z" . org-babel-switch-to-session-with-code)
+    ("\C-a" . org-babel-sha1-hash)
+    ("a" . org-babel-sha1-hash)
+    ("h" . org-babel-describe-bindings)
+    ("\C-x" . org-babel-do-key-sequence-in-edit-buffer)
+    ("x" . org-babel-do-key-sequence-in-edit-buffer)
+    ("k" . org-babel-remove-result-one-or-many)
+    ("\C-\M-h" . org-babel-mark-block))
+  "Alist of key bindings and interactive Babel functions.
+This list associates interactive Babel functions
+with keys.  Each element of this list will add an entry to the
+`org-babel-map' using the letter key which is the `car' of the
+a-list placed behind the generic `org-babel-key-prefix'.")
+
+(define-key org-mode-map org-babel-key-prefix org-babel-map)
+(pcase-dolist (`(,key . ,def) org-babel-key-bindings)
+  (define-key org-babel-map key def))
+
+(defun org-babel-speed-command-activate (keys)
+  "Hook for activating single-letter code block commands."
+  (when (and (bolp)
+            (let ((case-fold-search t)) (looking-at "[ \t]*#\\+begin_src"))
+            (eq 'src-block (org-element-type (org-element-at-point))))
+    (cdr (assoc keys org-babel-key-bindings))))
+
+;;;###autoload
+(defun org-babel-describe-bindings ()
+  "Describe all keybindings behind `org-babel-key-prefix'."
+  (interactive)
+  (describe-bindings org-babel-key-prefix))
+
+
+(provide 'org-keys)
+;;; org-keys.el ends here
diff --git a/lisp/org/org-lint.el b/lisp/org/org-lint.el
index f915335..5b959db 100644
--- a/lisp/org/org-lint.el
+++ b/lisp/org/org-lint.el
@@ -69,13 +69,13 @@
 ;;   - duplicate footnote definitions
 ;;   - orphaned affiliated keywords
 ;;   - obsolete affiliated keywords
-;;   - missing language in src blocks
+;;   - missing language in source blocks
 ;;   - missing back-end in export blocks
 ;;   - invalid Babel call blocks
 ;;   - NAME values with a colon
 ;;   - deprecated export block syntax
 ;;   - deprecated Babel header properties
-;;   - wrong header arguments in src blocks
+;;   - wrong header arguments in source blocks
 ;;   - misuse of CATEGORY keyword
 ;;   - "coderef" links with unknown destination
 ;;   - "custom-id" links with unknown destination
@@ -100,16 +100,16 @@
 ;;   - indented diary-sexps
 ;;   - obsolete QUOTE section
 ;;   - obsolete "file+application" link
-;;   - blank headlines with tags
+;;   - spurious colons in tags
 
 
 ;;; Code:
 
 (require 'cl-lib)
-(require 'org-element)
+(require 'ob)
+(require 'ol)
 (require 'org-macro)
 (require 'ox)
-(require 'ob)
 
 
 ;;; Checkers
@@ -162,7 +162,7 @@
     :trust 'low)
    (make-org-lint-checker
     :name 'missing-language-in-src-block
-    :description "Report missing language in src blocks"
+    :description "Report missing language in source blocks"
     :categories '(babel))
    (make-org-lint-checker
     :name 'missing-backend-in-export-block
@@ -288,10 +288,14 @@
     :description "Report obsolete \"file+application\" link"
     :categories '(link obsolete))
    (make-org-lint-checker
-    :name 'empty-headline-with-tags
-    :description "Report ambiguous empty headlines with tags"
-    :categories '(headline)
-    :trust 'low))
+    :name 'percent-encoding-link-escape
+    :description "Report obsolete escape syntax in links"
+    :categories '(link obsolete)
+    :trust 'low)
+   (make-org-lint-checker
+    :name 'spurious-colons
+    :description "Report spurious colons in tags"
+    :categories '(tags)))
   "List of all available checkers.")
 
 (defun org-lint--collect-duplicates
@@ -560,8 +564,8 @@ Use :header-args: instead"
 (defun org-lint-link-to-local-file (ast)
   (org-element-map ast 'link
     (lambda (l)
-      (when (equal (org-element-property :type l) "file")
-       (let ((file (org-link-unescape (org-element-property :path l))))
+      (when (equal "file" (org-element-property :type l))
+       (let ((file (org-element-property :path l)))
          (and (not (file-remote-p file))
               (not (file-exists-p file))
               (list (org-element-property :begin l)
@@ -576,12 +580,13 @@ Use :header-args: instead"
     (lambda (k)
       (when (equal (org-element-property :key k) "SETUPFILE")
        (let ((file (org-unbracket-string
-                    "\"" "\""
-                    (org-element-property :value k))))
-         (and (not (file-remote-p file))
+                       "\"" "\""
+                     (org-element-property :value k))))
+         (and (not (org-file-url-p file))
+              (not (file-remote-p file))
               (not (file-exists-p file))
               (list (org-element-property :begin k)
-                    (format "Non-existent setup file \"%s\"" file))))))))
+                    (format "Non-existent setup file %S" file))))))))
 
 (defun org-lint-wrong-include-link-parameter (ast)
   (org-element-map ast 'keyword
@@ -591,7 +596,7 @@ Use :header-args: instead"
               (path
                (and (string-match "^\\(\".+\"\\|\\S-+\\)[ \t]*" value)
                     (save-match-data
-                      (org-unbracket-string "\"" "\"" (match-string 1 
value))))))
+                      (org-strip-quotes (match-string 1 value))))))
          (if (not path)
              (list (org-element-property :post-affiliated k)
                    "Missing location argument in INCLUDE keyword")
@@ -608,14 +613,13 @@ Use :header-args: instead"
                        "Non-existent file argument in INCLUDE keyword")
                (let* ((visiting (if file (find-buffer-visiting file)
                                   (current-buffer)))
-                      (buffer (or visiting (find-file-noselect file))))
+                      (buffer (or visiting (find-file-noselect file)))
+                      (org-link-search-must-match-exact-headline t))
                  (unwind-protect
                      (with-current-buffer buffer
                        (when (and search
-                                  (not
-                                   (ignore-errors
-                                     (let ((org-link-search-inhibit-query t))
-                                       (org-link-search search nil t)))))
+                                  (not (ignore-errors
+                                         (org-link-search search nil t))))
                          (list (org-element-property :post-affiliated k)
                                (format
                                 "Invalid search part \"%s\" in INCLUDE keyword"
@@ -886,6 +890,23 @@ Use \"export %s\" instead"
             (list (org-element-property :begin l)
                   (format "Deprecated \"file+%s\" link type" app)))))))
 
+(defun org-lint-percent-encoding-link-escape (ast)
+  (org-element-map ast 'link
+    (lambda (l)
+      (when (eq 'bracket (org-element-property :format l))
+       (let* ((uri (org-element-property :path l))
+              (start 0)
+              (obsolete-flag
+               (catch :obsolete
+                 (while (string-match "%\\(..\\)?" uri start)
+                   (setq start (match-end 0))
+                   (unless (member (match-string 1 uri) '("25" "5B" "5D" "20"))
+                     (throw :obsolete nil)))
+                 (string-match-p "%" uri))))
+         (when obsolete-flag
+           (list (org-element-property :begin l)
+                 "Link escaped with obsolete percent-encoding syntax")))))))
+
 (defun org-lint-wrong-header-argument (ast)
   (let* ((reports)
         (verify
@@ -1037,14 +1058,13 @@ Use \"export %s\" instead"
                           reports))))))))))))
     reports))
 
-(defun org-lint-empty-headline-with-tags (ast)
+(defun org-lint-spurious-colons (ast)
   (org-element-map ast '(headline inlinetask)
     (lambda (h)
-      (let ((title (org-element-property :raw-value h)))
-       (and (string-match-p "\\`:[[:alnum:]_@#%:]+:\\'" title)
-            (list (org-element-property :begin h)
-                  (format "Headline containing only tags is ambiguous: %S"
-                          title)))))))
+      (when (member "" (org-element-property :tags h))
+       (list (org-element-property :begin h)
+             "Tags contain a spurious colon")))))
+
 
 
 ;;; Reports UI
diff --git a/lisp/org/org-list.el b/lisp/org/org-list.el
index 22692d2..c4aef32 100644
--- a/lisp/org/org-list.el
+++ b/lisp/org/org-list.el
@@ -91,6 +91,7 @@
 (defvar org-drawer-regexp)
 (defvar org-element-all-objects)
 (defvar org-inhibit-startup)
+(defvar org-loop-over-headlines-in-active-region)
 (defvar org-odd-levels-only)
 (defvar org-outline-regexp-bol)
 (defvar org-scheduled-string)
@@ -101,43 +102,31 @@
 (declare-function org-at-heading-p "org" (&optional invisible-ok))
 (declare-function org-back-to-heading "org" (&optional invisible-ok))
 (declare-function org-before-first-heading-p "org" ())
-(declare-function org-combine-plists "org" (&rest plists))
 (declare-function org-current-level "org" ())
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-context "org-element" (&optional element))
 (declare-function org-element-interpret-data "org-element" (data))
-(declare-function
- org-element-lineage "org-element" (blob &optional types with-self))
+(declare-function org-element-lineage "org-element" (blob &optional types 
with-self))
 (declare-function org-element-macro-interpreter "org-element" (macro ##))
-(declare-function
- org-element-map "org-element"
- (data types fun &optional info first-match no-recursion with-affiliated))
+(declare-function org-element-map "org-element" (data types fun &optional info 
first-match no-recursion with-affiliated))
 (declare-function org-element-normalize-string "org-element" (s))
-(declare-function org-element-parse-buffer "org-element"
-                 (&optional granularity visible-only))
+(declare-function org-element-parse-buffer "org-element" (&optional 
granularity visible-only))
 (declare-function org-element-property "org-element" (property element))
-(declare-function org-element-put-property "org-element"
-                 (element property value))
+(declare-function org-element-put-property "org-element" (element property 
value))
 (declare-function org-element-set-element "org-element" (old new))
 (declare-function org-element-type "org-element" (element))
 (declare-function org-element-update-syntax "org-element" ())
 (declare-function org-end-of-meta-data "org" (&optional full))
-(declare-function org-entry-get "org"
-                 (pom property &optional inherit literal-nil))
+(declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
 (declare-function org-export-create-backend "ox" (&rest rest) t)
 (declare-function org-export-data-with-backend "ox" (data backend info))
 (declare-function org-export-get-backend "ox" (name))
-(declare-function org-export-get-environment "ox"
-                 (&optional backend subtreep ext-plist))
-(declare-function org-export-get-next-element "ox"
-                 (blob info &optional n))
-(declare-function org-export-with-backend "ox"
-                 (backend data &optional contents info))
+(declare-function org-export-get-environment "ox" (&optional backend subtreep 
ext-plist))
+(declare-function org-export-get-next-element "ox" (blob info &optional n))
+(declare-function org-export-with-backend "ox" (backend data &optional 
contents info))
 (declare-function org-fix-tags-on-the-fly "org" ())
-(declare-function org-get-indentation "org" (&optional line))
 (declare-function org-get-todo-state "org" ())
 (declare-function org-in-block-p "org" (names))
-(declare-function org-in-regexp "org" (re &optional nlines visually))
 (declare-function org-inlinetask-goto-beginning "org-inlinetask" ())
 (declare-function org-inlinetask-goto-end "org-inlinetask" ())
 (declare-function org-inlinetask-in-task-p "org-inlinetask" ())
@@ -147,16 +136,12 @@
 (declare-function org-outline-level "org" ())
 (declare-function org-previous-line-empty-p "org" ())
 (declare-function org-reduced-level "org" (L))
-(declare-function org-remove-indentation "org" (code &optional n))
+(declare-function org-set-tags "org" (tags))
 (declare-function org-show-subtree "org" ())
 (declare-function org-sort-remove-invisible "org" (S))
 (declare-function org-time-string-to-seconds "org" (s))
 (declare-function org-timer-hms-to-secs "org-timer" (hms))
 (declare-function org-timer-item "org-timer" (&optional arg))
-(declare-function org-trim "org" (s &optional keep-lead))
-(declare-function org-uniquify "org" (list))
-(declare-function org-invisible-p "org" (&optional pos))
-(declare-function outline-flag-region "outline" (from to flag))
 (declare-function outline-next-heading "outline" ())
 (declare-function outline-previous-heading "outline" ())
 
@@ -343,13 +328,6 @@ with the word \"recursive\" in the value."
   :group 'org-plain-lists
   :type 'boolean)
 
-(defcustom org-list-description-max-indent 20
-  "Maximum indentation for the second line of a description list.
-When the indentation would be larger than this, it will become
-5 characters instead."
-  :group 'org-plain-lists
-  :type 'integer)
-
 (defcustom org-list-indent-offset 0
   "Additional indentation for sub-items in a list.
 By setting this to a small number, usually 1 or 2, one can more
@@ -358,45 +336,10 @@ clearly distinguish sub-items in a list."
   :version "24.1"
   :type 'integer)
 
-(defcustom org-list-radio-list-templates
-  '((latex-mode "% BEGIN RECEIVE ORGLST %n
-% END RECEIVE ORGLST %n
-\\begin{comment}
-#+ORGLST: SEND %n org-list-to-latex
--
-\\end{comment}\n")
-    (texinfo-mode "@c BEGIN RECEIVE ORGLST %n
-@c END RECEIVE ORGLST %n
-@ignore
-#+ORGLST: SEND %n org-list-to-texinfo
--
-@end ignore\n")
-    (html-mode "<!-- BEGIN RECEIVE ORGLST %n -->
-<!-- END RECEIVE ORGLST %n -->
-<!--
-#+ORGLST: SEND %n org-list-to-html
--
--->\n"))
-  "Templates for radio lists in different major modes.
-All occurrences of %n in a template will be replaced with the name of the
-list, obtained by prompting the user."
-  :group 'org-plain-lists
-  :type '(repeat
-         (list (symbol :tag "Major mode")
-               (string :tag "Format"))))
-
 (defvar org-list-forbidden-blocks '("example" "verse" "src" "export")
   "Names of blocks where lists are not allowed.
 Names must be in lower case.")
 
-(defvar org-list-export-context '(block inlinetask)
-  "Context types where lists will be interpreted during export.
-
-Valid types are `drawer', `inlinetask' and `block'.  More
-specifically, type `block' is determined by the variable
-`org-list-forbidden-blocks'.")
-
-
 
 ;;; Predicates and regexps
 
@@ -462,7 +405,7 @@ group 4: description tag")
           (ind-ref (if (or (looking-at "^[ \t]*$")
                            (and inlinetask-re (looking-at inlinetask-re)))
                        10000
-                     (org-get-indentation))))
+                     (current-indentation))))
       (cond
        ((eq (nth 2 context) 'invalid) nil)
        ((looking-at item-re) (point))
@@ -484,7 +427,7 @@ group 4: description tag")
        ;; Look for an item, less indented that reference line.
        (catch 'exit
          (while t
-           (let ((ind (org-get-indentation)))
+           (let ((ind (current-indentation)))
              (cond
               ;; This is exactly what we want.
               ((and (looking-at item-re) (< ind ind-ref))
@@ -654,7 +597,7 @@ Assume point is at an item."
           (item-re (org-item-re))
           (inlinetask-re (and (featurep 'org-inlinetask)
                               (org-inlinetask-outline-regexp)))
-          (beg-cell (cons (point) (org-get-indentation)))
+          (beg-cell (cons (point) (current-indentation)))
            itm-lst itm-lst-2 end-lst end-lst-2 struct
           (assoc-at-point
            (function
@@ -682,7 +625,7 @@ Assume point is at an item."
       (save-excursion
        (catch 'exit
          (while t
-           (let ((ind (org-get-indentation)))
+           (let ((ind (current-indentation)))
              (cond
               ((<= (point) lim-up)
                ;; At upward limit: if we ended at an item, store it,
@@ -742,7 +685,7 @@ Assume point is at an item."
       ;;    position of items in END-LST-2.
       (catch 'exit
        (while t
-         (let ((ind (org-get-indentation)))
+         (let ((ind (current-indentation)))
            (cond
             ((>= (point) lim-down)
              ;; At downward limit: this is de facto the end of the
@@ -861,6 +804,17 @@ This function modifies STRUCT."
                       (t (cons pos (cdar ind-to-ori))))))
                  (cdr struct)))))
 
+(defun org-list--delete-metadata ()
+  "Delete metadata from the heading at point.
+Metadata are tags, planning information and properties drawers."
+  (save-match-data
+    (org-with-wide-buffer
+     (org-set-tags nil)
+     (delete-region (line-beginning-position 2)
+                   (save-excursion
+                     (org-end-of-meta-data)
+                     (org-skip-whitespace)
+                     (if (eobp) (point) (line-beginning-position)))))))
 
 
 ;;; Accessors
@@ -1281,10 +1235,18 @@ function ends.
 
 This function modifies STRUCT."
   (let ((case-fold-search t))
-    ;; 1. Get information about list: position of point with regards
-    ;;    to item start (BEFOREP), blank lines number separating items
-    ;;    (BLANK-NB), if we're allowed to (SPLIT-LINE-P).
-    (let* ((item (progn (goto-char pos) (goto-char (org-list-get-item-begin))))
+    ;; 1. Get information about list: ITEM containing POS, position of
+    ;;    point with regards to item start (BEFOREP), blank lines
+    ;;    number separating items (BLANK-NB), if we're allowed to
+    ;;    (SPLIT-LINE-P).
+    (let* ((item (goto-char (catch :exit
+                             (let ((inner-item 0))
+                               (pcase-dolist (`(,i . ,_) struct)
+                                 (cond
+                                  ((= i pos) (throw :exit i))
+                                  ((< i pos) (setq inner-item i))
+                                  (t (throw :exit inner-item))))
+                               inner-item))))
           (item-end (org-list-get-item-end item struct))
           (item-end-no-blank (org-list-get-item-end-before-blank item struct))
           (beforep
@@ -1497,8 +1459,8 @@ This function returns, destructively, the new list 
structure."
         (org-M-RET-may-split-line nil)
         ;; Store inner overlays (to preserve visibility).
         (overlays (cl-remove-if (lambda (o) (or (< (overlay-start o) item)
-                                            (> (overlay-end o) item)))
-                                 (overlays-in item item-end))))
+                                                (> (overlay-end o) item)))
+                                (overlays-in item item-end))))
     (cond
      ((eq dest 'delete) (org-list-delete-item item struct))
      ((eq dest 'kill)
@@ -1590,23 +1552,6 @@ STRUCT may be modified if 
`org-list-demote-modify-bullet' matches
 bullets between START and END."
   (let* (acc
         (set-assoc (lambda (cell) (push cell acc) cell))
-        (change-bullet-maybe
-         (function
-          (lambda (item)
-            (let ((new-bul-p
-                   (cdr (assoc
-                         ;; Normalize ordered bullets.
-                         (let ((bul (org-trim
-                                     (org-list-get-bullet item struct))))
-                           (cond ((string-match "[A-Z]\\." bul) "A.")
-                                 ((string-match "[A-Z])" bul) "A)")
-                                 ((string-match "[a-z]\\." bul) "a.")
-                                 ((string-match "[a-z])" bul) "a)")
-                                 ((string-match "[0-9]\\." bul) "1.")
-                                 ((string-match "[0-9])" bul) "1)")
-                                 (t bul)))
-                         org-list-demote-modify-bullet))))
-              (when new-bul-p (org-list-set-bullet item struct new-bul-p))))))
         (ind
          (lambda (cell)
            (let* ((item (car cell))
@@ -1622,11 +1567,24 @@ bullets between START and END."
                ;; Item is in zone...
                (let ((prev (org-list-get-prev-item item struct prevs)))
                  ;; Check if bullet needs to be changed.
-                 (funcall change-bullet-maybe item)
+                 (pcase (assoc (let ((b (org-list-get-bullet item struct))
+                                     (case-fold-search nil))
+                                 (cond ((string-match "[A-Z]\\." b) "A.")
+                                       ((string-match "[A-Z])" b) "A)")
+                                       ((string-match "[a-z]\\." b) "a.")
+                                       ((string-match "[a-z])" b) "a)")
+                                       ((string-match "[0-9]\\." b) "1.")
+                                       ((string-match "[0-9])" b) "1)")
+                                       (t (org-trim b))))
+                               org-list-demote-modify-bullet)
+                   (`(,_ . ,bullet)
+                    (org-list-set-bullet
+                     item struct (org-list-bullet-string bullet)))
+                   (_ nil))
                  (cond
                   ;; First item indented but not parent: error
-                  ((and (not prev) (< parent start))
-                   (error "Cannot indent the first item of a list"))
+                  ((and (not prev) (or (not parent) (< parent start)))
+                   (user-error "Cannot indent the first item of a list"))
                   ;; First item and parent indented: keep same
                   ;; parent.
                   ((not prev) (funcall set-assoc cell))
@@ -1899,7 +1857,7 @@ Initial position of cursor is restored after the changes."
                 (org-inlinetask-goto-beginning))
                ;; Shift only non-empty lines.
                ((looking-at-p "^[ \t]*\\S-")
-                (indent-line-to (+ (org-get-indentation) delta))))
+                (indent-line-to (+ (current-indentation) delta))))
               (forward-line -1)))))
          (modify-item
           (function
@@ -1908,7 +1866,7 @@ Initial position of cursor is restored after the changes."
           (lambda (item)
             (goto-char item)
             (let* ((new-ind (org-list-get-ind item struct))
-                   (old-ind (org-get-indentation))
+                   (old-ind (current-indentation))
                    (new-bul (org-list-bullet-string
                              (org-list-get-bullet item struct)))
                    (old-bul (org-list-get-bullet item old-struct))
@@ -1983,7 +1941,7 @@ Initial position of cursor is restored after the changes."
                        ;; Ignore empty lines.  Also ignore blocks and
                        ;; drawers contents.
                        (unless (looking-at-p "[ \t]*$")
-                         (setq min-ind (min (org-get-indentation) min-ind))
+                         (setq min-ind (min (current-indentation) min-ind))
                          (cond
                           ((and (looking-at "#\\+BEGIN\\(:\\|_\\S-+\\)")
                                 (re-search-forward
@@ -2037,7 +1995,9 @@ doesn't correspond anymore to the real list in buffer."
       ;; 5. Eventually fix checkboxes.
       (org-list-struct-fix-box struct parents prevs))
     ;; 6. Apply structure modifications to buffer.
-    (org-list-struct-apply-struct struct old-struct)))
+    (org-list-struct-apply-struct struct old-struct))
+  ;; 7. Return the updated structure
+  struct)
 
 
 
@@ -2078,8 +2038,8 @@ Possible values are: `folded', `children' or `subtree'.  
See
    ((eq view 'folded)
     (let ((item-end (org-list-get-item-end-before-blank item struct)))
       ;; Hide from eol
-      (outline-flag-region (save-excursion (goto-char item) (point-at-eol))
-                          item-end t)))
+      (org-flag-region (save-excursion (goto-char item) (line-end-position))
+                      item-end t 'outline)))
    ((eq view 'children)
     ;; First show everything.
     (org-list-set-item-visibility item struct 'subtree)
@@ -2092,31 +2052,19 @@ Possible values are: `folded', `children' or `subtree'. 
 See
    ((eq view 'subtree)
     ;; Show everything
     (let ((item-end (org-list-get-item-end item struct)))
-      (outline-flag-region item item-end nil)))))
+      (org-flag-region item item-end nil 'outline)))))
 
 (defun org-list-item-body-column (item)
   "Return column at which body of ITEM should start."
   (save-excursion
     (goto-char item)
-    (if (save-excursion
-         (end-of-line)
-         (re-search-backward
-          "[ \t]::\\([ \t]\\|$\\)" (line-beginning-position) t))
-       ;; Descriptive list item.  Body starts after item's tag, if
-       ;; possible.
-       (let ((start (1+ (- (match-beginning 1) (line-beginning-position))))
-             (ind (org-get-indentation)))
-         (if (> start (+ ind org-list-description-max-indent))
-             (+ ind 5)
-           start))
-      ;; Regular item.  Body starts after bullet.
-      (looking-at "[ \t]*\\(\\S-+\\)")
-      (+ (progn (goto-char (match-end 1)) (current-column))
-        (if (and org-list-two-spaces-after-bullet-regexp
-                 (string-match-p org-list-two-spaces-after-bullet-regexp
-                                 (match-string 1)))
-            2
-          1)))))
+    (looking-at "[ \t]*\\(\\S-+\\)")
+    (+ (progn (goto-char (match-end 1)) (current-column))
+       (if (and org-list-two-spaces-after-bullet-regexp
+               (string-match-p org-list-two-spaces-after-bullet-regexp
+                               (match-string 1)))
+          2
+        1))))
 
 
 
@@ -2280,7 +2228,7 @@ item is invisible."
                                (string-match "[.)]" (match-string 1))))
                         (match-beginning 4)
                       (match-end 0)))
-         (if desc (backward-char 1))
+         (when desc (backward-char 1))
          t)))))
 
 (defun org-list-repair ()
@@ -2707,11 +2655,12 @@ Return t if successful."
          (error "Cannot outdent an item without its children"))
         ;; Normal shifting
         (t
-         (let* ((new-parents
+         (let* ((old-struct (copy-tree struct))
+                (new-parents
                  (if (< arg 0)
                      (org-list-struct-outdent beg end struct parents)
                    (org-list-struct-indent beg end struct parents prevs))))
-           (org-list-write-struct struct new-parents))
+           (org-list-write-struct struct new-parents old-struct))
          (org-update-checkbox-count-maybe))))))
   t)
 
@@ -2840,7 +2789,8 @@ Sorting can be alphabetically, numerically, by date/time 
as given
 by a time stamp, by a property or by priority.
 
 Comparing entries ignores case by default.  However, with an
-optional argument WITH-CASE, the sorting considers case as well.
+optional argument WITH-CASE, the sorting considers case as well,
+if the current locale allows for it.
 
 The command prompts for the sorting type unless it has been given
 to the function through the SORTING-TYPE argument, which needs to
@@ -2886,7 +2836,7 @@ function is being called interactively."
                   (error "Missing key extractor"))))
         (sort-func
          (cond
-          ((= dcst ?a) #'string<)
+          ((= dcst ?a) #'org-string-collate-lessp)
           ((= dcst ?f)
            (or compare-func
                (and interactive?
@@ -2977,7 +2927,7 @@ With a prefix argument ARG, change the region in a single 
item."
             (save-excursion
               (catch 'exit
                 (while (< (point) end)
-                  (let ((i (org-get-indentation)))
+                  (let ((i (current-indentation)))
                     (cond
                      ;; Skip blank lines and inline tasks.
                      ((looking-at "^[ \t]*$"))
@@ -2993,7 +2943,7 @@ With a prefix argument ARG, change the region in a single 
item."
               (while (< (point) end)
                 (unless (or (looking-at "^[ \t]*$")
                             (looking-at org-outline-regexp-bol))
-                  (indent-line-to (+ (org-get-indentation) delta)))
+                  (indent-line-to (+ (current-indentation) delta)))
                 (forward-line))))))
        (skip-blanks
         (lambda (pos)
@@ -3027,6 +2977,9 @@ With a prefix argument ARG, change the region in a single 
item."
           (forward-line)))
        ;; Case 2. Start at an heading: convert to items.
        ((org-at-heading-p)
+        ;; Remove metadata
+        (let (org-loop-over-headlines-in-active-region)
+          (org-list--delete-metadata))
         (let* ((bul (org-list-bullet-string "-"))
                (bul-len (length bul))
                ;; Indentation of the first heading.  It should be
@@ -3047,6 +3000,9 @@ With a prefix argument ARG, change the region in a single 
item."
               ;; one, set it as reference, in order to preserve
               ;; subtrees.
               (when (< level ref-level) (setq ref-level level))
+              ;; Remove metadata
+              (let (org-loop-over-headlines-in-active-region)
+                (org-list--delete-metadata))
               ;; Remove stars and TODO keyword.
               (let ((case-fold-search nil)) (looking-at org-todo-line-regexp))
               (delete-region (point) (or (match-beginning 3)
@@ -3079,7 +3035,7 @@ With a prefix argument ARG, change the region in a single 
item."
        ;;         set them as item's body.
        (arg (let* ((bul (org-list-bullet-string "-"))
                    (bul-len (length bul))
-                   (ref-ind (org-get-indentation)))
+                   (ref-ind (current-indentation)))
               (skip-chars-forward " \t")
               (insert bul)
               (forward-line)
@@ -3195,80 +3151,14 @@ Point is left at list's end."
 (defun org-list-make-subtree ()
   "Convert the plain list at point into a subtree."
   (interactive)
-  (if (not (ignore-errors (goto-char (org-in-item-p))))
-      (error "Not in a list")
-    (let ((list (save-excursion (org-list-to-lisp t))))
-      (insert (org-list-to-subtree list)))))
-
-(defun org-list-insert-radio-list ()
-  "Insert a radio list template appropriate for this major mode."
-  (interactive)
-  (let* ((e (cl-assoc-if #'derived-mode-p org-list-radio-list-templates))
-        (txt (nth 1 e))
-        name pos)
-    (unless e (error "No radio list setup defined for %s" major-mode))
-    (setq name (read-string "List name: "))
-    (while (string-match "%n" txt)
-      (setq txt (replace-match name t t txt)))
-    (or (bolp) (insert "\n"))
-    (setq pos (point))
-    (insert txt)
-    (goto-char pos)))
-
-(defun org-list-send-list (&optional maybe)
-  "Send a transformed version of this list to the receiver position.
-With argument MAYBE, fail quietly if no transformation is defined
-for this list."
-  (interactive)
-  (catch 'exit
-    (unless (org-at-item-p) (error "Not at a list item"))
-    (save-excursion
-      (let ((case-fold-search t))
-       (re-search-backward "^[ \t]*#\\+ORGLST:" nil t)
-       (unless (looking-at
-                "[ \t]*#\\+ORGLST:[ \t]+SEND[ \t]+\\(\\S-+\\)[ \t]+\\([^ 
\t\n]+\\)")
-         (if maybe (throw 'exit nil)
-           (error "Don't know how to transform this list")))))
-    (let* ((name (regexp-quote (match-string 1)))
-          (transform (intern (match-string 2)))
-          (bottom-point
-           (save-excursion
-             (re-search-forward
-              "\\(\\\\end{comment}\\|@end ignore\\|-->\\)" nil t)
-             (match-beginning 0)))
-          (top-point
-           (progn
-             (re-search-backward "#\\+ORGLST" nil t)
-             (re-search-forward (org-item-beginning-re) bottom-point t)
-             (match-beginning 0)))
-          (plain-list (save-excursion
-                        (goto-char top-point)
-                        (org-list-to-lisp))))
-      (unless (fboundp transform)
-       (error "No such transformation function %s" transform))
-      (let ((txt (funcall transform plain-list)))
-       ;; Find the insertion(s) place(s).
-       (save-excursion
-         (goto-char (point-min))
-         (let ((receiver-count 0)
-               (begin-re (format "BEGIN +RECEIVE +ORGLST +%s\\([ \t]\\|$\\)"
-                                 name))
-               (end-re (format "END +RECEIVE +ORGLST +%s\\([ \t]\\|$\\)"
-                               name)))
-           (while (re-search-forward begin-re nil t)
-             (cl-incf receiver-count)
-             (let ((beg (line-beginning-position 2)))
-               (unless (re-search-forward end-re nil t)
-                 (user-error "Cannot find end of receiver location at %d" beg))
-               (beginning-of-line)
-               (delete-region beg (point))
-               (insert txt "\n")))
-           (cond
-            ((> receiver-count 1)
-             (message "List converted and installed at receiver locations"))
-            ((= receiver-count 1)
-             (message "List converted and installed at receiver location"))
-            (t (user-error "No valid receiver location found")))))))))
+  (let ((item (org-in-item-p)))
+    (unless item (error "Not in a list"))
+    (goto-char item)
+    (let ((level (pcase (org-current-level)
+                  (`nil 1)
+                  (l (1+ (org-reduced-level l)))))
+         (list (save-excursion (org-list-to-lisp t))))
+      (insert (org-list-to-subtree list level) "\n"))))
 
 (defun org-list-to-generic (list params)
   "Convert a LIST parsed through `org-list-to-lisp' to a custom format.
@@ -3577,21 +3467,22 @@ with overruling parameters for `org-list-to-generic'."
                 :cbtrans "[-] ")))
     (org-list-to-generic list (org-combine-plists defaults params))))
 
-(defun org-list-to-subtree (list &optional params)
+(defun org-list-to-subtree (list &optional start-level params)
   "Convert LIST into an Org subtree.
-LIST is as returned by `org-list-to-lisp'.  PARAMS is a property
-list with overruling parameters for `org-list-to-generic'."
+LIST is as returned by `org-list-to-lisp'.  Subtree starts at
+START-LEVEL or level 1 if nil.  PARAMS is a property list with
+overruling parameters for `org-list-to-generic'."
   (let* ((blank (pcase (cdr (assq 'heading org-blank-before-new-entry))
                  (`t t)
                  (`auto (save-excursion
                           (org-with-limited-levels (outline-previous-heading))
                           (org-previous-line-empty-p)))))
-        (level (org-reduced-level (or (org-current-level) 0)))
+        (level (or start-level 1))
         (make-stars
          (lambda (_type depth &optional _count)
            ;; Return the string for the heading, depending on DEPTH
            ;; of current sub-list.
-           (let ((oddeven-level (+ level depth)))
+           (let ((oddeven-level (+ level (1- depth))))
              (concat (make-string (if org-odd-levels-only
                                       (1- (* 2 oddeven-level))
                                     oddeven-level)
diff --git a/lisp/org/org-macro.el b/lisp/org/org-macro.el
index a151e1e..c928ea7 100644
--- a/lisp/org/org-macro.el
+++ b/lisp/org/org-macro.el
@@ -52,18 +52,24 @@
 
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-context "org-element" (&optional element))
+(declare-function org-element-copy "org-element" (datum))
 (declare-function org-element-macro-parser "org-element" ())
+(declare-function org-element-parse-secondary-string "org-element" (string 
restriction &optional parent))
 (declare-function org-element-property "org-element" (property element))
+(declare-function org-element-restriction "org-element" (element))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
 (declare-function org-file-contents "org" (file &optional noerror nocache))
 (declare-function org-file-url-p "org" (file))
 (declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
+(declare-function org-link-search "ol" (s &optional avoid-pos stealth))
 (declare-function org-mode "org" ())
-(declare-function org-trim "org" (s &optional keep-lead))
 (declare-function vc-backend "vc-hooks" (f))
 (declare-function vc-call "vc-hooks" (fun file &rest args) t)
 (declare-function vc-exec-after "vc-dispatcher" (code))
 
+(defvar org-link-search-must-match-exact-headline)
+
 ;;; Variables
 
 (defvar-local org-macro-templates nil
@@ -77,95 +83,100 @@ directly, use instead:
 
 ;;; Functions
 
-(defun org-macro--collect-macros ()
+(defun org-macro--set-template (name value templates)
+  "Set template for the macro NAME.
+VALUE is the template of the macro.  The new value override the
+previous one, unless VALUE is nil.  TEMPLATES is the list of
+templates.  Return the updated list."
+  (when value
+    (let ((old-definition (assoc name templates)))
+      (if old-definition
+         (setcdr old-definition value)
+       (push (cons name value) templates))))
+  templates)
+
+(defun org-macro--collect-macros (&optional files templates)
   "Collect macro definitions in current buffer and setup files.
-Return an alist containing all macro templates found."
-  (letrec ((collect-macros
-           (lambda (files templates)
-             ;; Return an alist of macro templates.  FILES is a list
-             ;; of setup files names read so far, used to avoid
-             ;; circular dependencies.  TEMPLATES is the alist
-             ;; collected so far.
-             (let ((case-fold-search t))
-               (org-with-wide-buffer
-                (goto-char (point-min))
-                (while (re-search-forward
-                        "^[ \t]*#\\+\\(MACRO\\|SETUPFILE\\):" nil t)
-                  (let ((element (org-element-at-point)))
-                    (when (eq (org-element-type element) 'keyword)
-                      (let ((val (org-element-property :value element)))
-                        (if (equal (org-element-property :key element) "MACRO")
-                            ;; Install macro in TEMPLATES.
-                            (when (string-match
-                                   "^\\(.*?\\)\\(?:\\s-+\\(.*\\)\\)?\\s-*$" 
val)
-                              (let* ((name (match-string 1 val))
-                                     (template (or (match-string 2 val) ""))
-                                     (old-cell (assoc name templates)))
-                                (if old-cell (setcdr old-cell template)
-                                  (push (cons name template) templates))))
-                          ;; Enter setup file.
-                          (let* ((uri (org-unbracket-string "\"" "\"" 
(org-trim val)))
-                                 (uri-is-url (org-file-url-p uri))
-                                 (uri (if uri-is-url
-                                          uri
-                                        (expand-file-name uri))))
-                            ;; Avoid circular dependencies.
-                            (unless (member uri files)
-                              (with-temp-buffer
-                                (unless uri-is-url
-                                  (setq default-directory
-                                        (file-name-directory uri)))
-                                (org-mode)
-                                (insert (org-file-contents uri 'noerror))
-                                (setq templates
-                                      (funcall collect-macros (cons uri files)
-                                               templates)))))))))))
-               templates))))
-    (funcall collect-macros nil nil)))
+Return an alist containing all macro templates found.
+
+FILES is a list of setup files names read so far, used to avoid
+circular dependencies.  TEMPLATES is the alist collected so far.
+The two arguments are used in recursive calls."
+  (let ((case-fold-search t))
+    (org-with-point-at 1
+      (while (re-search-forward "^[ \t]*#\\+\\(MACRO\\|SETUPFILE\\):" nil t)
+       (let ((element (org-element-at-point)))
+         (when (eq (org-element-type element) 'keyword)
+           (let ((val (org-element-property :value element)))
+             (if (equal "MACRO" (org-element-property :key element))
+                 ;; Install macro in TEMPLATES.
+                 (when (string-match "^\\(\\S-+\\)[ \t]*" val)
+                   (let ((name (match-string 1 val))
+                         (value (substring val (match-end 0))))
+                     (setq templates
+                           (org-macro--set-template name value templates))))
+               ;; Enter setup file.
+               (let* ((uri (org-strip-quotes val))
+                      (uri-is-url (org-file-url-p uri))
+                      (uri (if uri-is-url
+                               uri
+                             (expand-file-name uri))))
+                 ;; Avoid circular dependencies.
+                 (unless (member uri files)
+                   (with-temp-buffer
+                     (unless uri-is-url
+                       (setq default-directory (file-name-directory uri)))
+                     (org-mode)
+                     (insert (org-file-contents uri 'noerror))
+                     (setq templates
+                           (org-macro--collect-macros
+                            (cons uri files) templates)))))))))))
+    (let ((macros `(("author" . ,(org-macro--find-keyword-value "AUTHOR"))
+                   ("email" . ,(org-macro--find-keyword-value "EMAIL"))
+                   ("title" . ,(org-macro--find-keyword-value "TITLE" t))
+                   ("date" . ,(org-macro--find-date)))))
+      (pcase-dolist (`(,name . ,value) macros)
+       (setq templates (org-macro--set-template name value templates))))
+    templates))
 
 (defun org-macro-initialize-templates ()
   "Collect macro templates defined in current buffer.
+
 Templates are stored in buffer-local variable
-`org-macro-templates'.  In addition to buffer-defined macros, the
-function installs the following ones: \"property\",
-\"time\". and, if the buffer is associated to a file,
-\"input-file\" and \"modification-time\"."
-  (let* ((templates nil)
-        (update-templates
-         (lambda (cell)
-           (let ((old-template (assoc (car cell) templates)))
-             (if old-template (setcdr old-template (cdr cell))
-               (push cell templates))))))
-    ;; Install "property", "time" macros.
-    (mapc update-templates
-         (list (cons "property"
-                     "(eval (save-excursion
-        (let ((l \"$2\"))
-          (when (org-string-nw-p l)
-            (condition-case _
-                (let ((org-link-search-must-match-exact-headline t))
-                  (org-link-search l nil t))
-              (error
-               (error \"Macro property failed: cannot find location %s\"
-                      l)))))
-        (org-entry-get nil \"$1\" 'selective)))")
-               (cons "time" "(eval (format-time-string \"$1\"))")))
-    ;; Install "input-file", "modification-time" macros.
-    (let ((visited-file (buffer-file-name (buffer-base-buffer))))
-      (when (and visited-file (file-exists-p visited-file))
-       (mapc update-templates
-             (list (cons "input-file" (file-name-nondirectory visited-file))
-                   (cons "modification-time"
-                         (format "(eval (format-time-string \"$1\" (or (and 
(org-string-nw-p \"$2\") (org-macro--vc-modified-time %s)) '%s)))"
-                                 (prin1-to-string visited-file)
-                                 (prin1-to-string
-                                  (file-attribute-modification-time
-                                   (file-attributes visited-file)))))))))
-    ;; Initialize and install "n" macro.
-    (org-macro--counter-initialize)
-    (funcall update-templates
-            (cons "n" "(eval (org-macro--counter-increment \"$1\" \"$2\"))"))
-    (setq org-macro-templates (nconc (org-macro--collect-macros) templates))))
+`org-macro-templates'.
+
+In addition to buffer-defined macros, the function installs the
+following ones: \"n\", \"author\", \"email\", \"keyword\",
+\"time\", \"property\", and, if the buffer is associated to
+a file, \"input-file\" and \"modification-time\"."
+  (require 'org-element)
+  (org-macro--counter-initialize)      ;for "n" macro
+  (setq org-macro-templates
+       (nconc
+        ;; Install user-defined macros.
+        (org-macro--collect-macros)
+        ;; Install file-specific macros.
+        (let ((visited-file (buffer-file-name (buffer-base-buffer))))
+          (and visited-file
+               (file-exists-p visited-file)
+               (list
+                `("input-file" . ,(file-name-nondirectory visited-file))
+                `("modification-time" .
+                  ,(format "(eval
+\(format-time-string $1
+                     (or (and (org-string-nw-p $2)
+                              (org-macro--vc-modified-time %s))
+                     '%s)))"
+                           (prin1-to-string visited-file)
+                           (prin1-to-string
+                            (file-attribute-modification-time
+                             (file-attributes visited-file))))))))
+        ;; Install generic macros.
+        (list
+         '("n" . "(eval (org-macro--counter-increment $1 $2))")
+         '("keyword" . "(eval (org-macro--find-keyword-value $1))")
+         '("time" . "(eval (format-time-string $1))")
+         '("property" . "(eval (org-macro--get-property $1 $2))")))))
 
 (defun org-macro-expand (macro templates)
   "Return expanded MACRO, as a string.
@@ -177,31 +188,35 @@ default value.  Return nil if no template was found."
         ;; Macro names are case-insensitive.
         (cdr (assoc-string (org-element-property :key macro) templates t))))
     (when template
-      (let ((value (replace-regexp-in-string
-                    "\\$[0-9]+"
-                    (lambda (arg)
-                      (or (nth (1- (string-to-number (substring arg 1)))
-                               (org-element-property :args macro))
-                          ;; No argument: remove place-holder.
-                          ""))
-                    template nil 'literal)))
-        ;; VALUE starts with "(eval": it is a s-exp, `eval' it.
-        (when (string-match "\\`(eval\\>" value)
-          (setq value (eval (read value))))
-        ;; Return string.
+      (let* ((eval? (string-match-p "\\`(eval\\>" template))
+            (value
+             (replace-regexp-in-string
+              "\\$[0-9]+"
+              (lambda (m)
+                (let ((arg (or (nth (1- (string-to-number (substring m 1)))
+                                    (org-element-property :args macro))
+                               ;; No argument: remove place-holder.
+                               "")))
+                  ;; `eval' implies arguments are strings.
+                  (if eval? (format "%S" arg) arg)))
+              template nil 'literal)))
+        (when eval?
+          (setq value (eval (condition-case nil (read value)
+                             (error (debug))))))
+        ;; Force return value to be a string.
         (format "%s" (or value ""))))))
 
-(defun org-macro-replace-all (templates &optional finalize keywords)
+(defun org-macro-replace-all (templates &optional keywords)
   "Replace all macros in current buffer by their expansion.
 
 TEMPLATES is an alist of templates used for expansion.  See
 `org-macro-templates' for a buffer-local default value.
 
-If optional arg FINALIZE is non-nil, raise an error if a macro is
-found in the buffer with no definition in TEMPLATES.
-
 Optional argument KEYWORDS, when non-nil is a list of keywords,
-as strings, where macro expansion is allowed."
+as strings, where macro expansion is allowed.
+
+Return an error if a macro in the buffer cannot be associated to
+a definition in TEMPLATES."
   (org-with-wide-buffer
    (goto-char (point-min))
    (let ((properties-regexp (format "\\`EXPORT_%s\\+?\\'"
@@ -225,7 +240,8 @@ as strings, where macro expansion is allowed."
                     (goto-char (match-beginning 0))
                     (org-element-macro-parser))))))
           (when macro
-            (let* ((value (org-macro-expand macro templates))
+            (let* ((key (org-element-property :key macro))
+                   (value (org-macro-expand macro templates))
                    (begin (org-element-property :begin macro))
                    (signature (list begin
                                     macro
@@ -234,8 +250,7 @@ as strings, where macro expansion is allowed."
               ;; macro with the same arguments is expanded at the
               ;; same position twice.
               (cond ((member signature record)
-                     (error "Circular macro expansion: %s"
-                            (org-element-property :key macro)))
+                     (error "Circular macro expansion: %s" key))
                     (value
                      (push signature record)
                      (delete-region
@@ -247,7 +262,11 @@ as strings, where macro expansion is allowed."
                      ;; Leave point before replacement in case of
                      ;; recursive expansions.
                      (save-excursion (insert value)))
-                    (finalize
+                    ;; Special "results" macro: if it is not defined,
+                    ;; simply leave it as-is.  It will be expanded in
+                    ;; a second phase.
+                    ((equal key "results"))
+                    (t
                      (error "Undefined Org macro: %s; aborting"
                             (org-element-property :key macro))))))))))))
 
@@ -295,6 +314,53 @@ Return a list of arguments, as strings.  This is the 
opposite of
 
 ;;; Helper functions and variables for internal macros
 
+(defun org-macro--get-property (property location)
+  "Find PROPERTY's value at LOCATION.
+PROPERTY is a string.  LOCATION is a search string, as expected
+by `org-link-search', or the empty string."
+  (save-excursion
+    (when (org-string-nw-p location)
+      (condition-case _
+         (let ((org-link-search-must-match-exact-headline t))
+           (org-link-search location nil t))
+        (error
+        (error "Macro property failed: cannot find location %s" location))))
+    (org-entry-get nil property 'selective)))
+
+(defun org-macro--find-keyword-value (name &optional collect)
+  "Find value for keyword NAME in current buffer.
+Return value associated to the keywords named after NAME, as
+a string, or nil.  When optional argument COLLECT is non-nil,
+concatenate values, separated with a space, from various keywords
+in the buffer."
+  (org-with-point-at 1
+    (let ((regexp (format "^[ \t]*#\\+%s:" (regexp-quote name)))
+         (case-fold-search t)
+         (result nil))
+      (catch :exit
+       (while (re-search-forward regexp nil t)
+         (let ((element (org-element-at-point)))
+           (when (eq 'keyword (org-element-type element))
+             (let ((value (org-element-property :value element)))
+               (if (not collect) (throw :exit value)
+                 (setq result (concat result " " value)))))))
+       (and result (org-trim result))))))
+
+(defun org-macro--find-date ()
+  "Find value for DATE in current buffer.
+Return value as a string."
+  (let* ((value (org-macro--find-keyword-value "DATE"))
+        (date (org-element-parse-secondary-string
+               value (org-element-restriction 'keyword))))
+    (if (and (consp date)
+            (not (cdr date))
+            (eq 'timestamp (org-element-type (car date))))
+       (format "(eval (if (org-string-nw-p $1) %s %S))"
+               (format "(org-timestamp-format '%S $1)"
+                       (org-element-copy (car date)))
+               value)
+      value)))
+
 (defun org-macro--vc-modified-time (file)
   (save-window-excursion
     (when (vc-backend file)
@@ -313,7 +379,7 @@ Return a list of arguments, as strings.  This is the 
opposite of
                                  (buffer-substring
                                   (point) (line-end-position)))))
                       (when (cl-some #'identity time)
-                        (setq date (encode-time time))))))))
+                        (setq date (apply #'encode-time time))))))))
              (let ((proc (get-buffer-process buf)))
                (while (and proc (accept-process-output proc .5 nil t)))))
          (kill-buffer buf))
diff --git a/lisp/org/org-macs.el b/lisp/org/org-macs.el
index bb96a06..3cc6810 100644
--- a/lisp/org/org-macs.el
+++ b/lisp/org/org-macs.el
@@ -32,6 +32,14 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'format-spec)
+
+(declare-function org-string-collate-lessp "org-compat" (s1 s2 &optional 
locale ignore-case))
+
+(defvar org-ts-regexp0)
+
+
+;;; Macros
 
 (defmacro org-with-gensyms (symbols &rest body)
   (declare (debug (sexp body)) (indent 1))
@@ -40,113 +48,8 @@
                  symbols)
      ,@body))
 
-(defun org-string-nw-p (s)
-  "Return S if S is a string containing a non-blank character.
-Otherwise, return nil."
-  (and (stringp s)
-       (string-match-p "[^ \r\t\n]" s)
-       s))
-
-(defun org-split-string (string &optional separators)
-  "Splits STRING into substrings at SEPARATORS.
-
-SEPARATORS is a regular expression.  When nil, it defaults to
-\"[ \f\t\n\r\v]+\".
-
-Unlike `split-string', matching SEPARATORS at the beginning and
-end of string are ignored."
-  (let ((separators (or separators "[ \f\t\n\r\v]+")))
-    (when (string-match (concat "\\`" separators) string)
-      (setq string (replace-match "" nil nil string)))
-    (when (string-match (concat separators "\\'") string)
-      (setq string (replace-match "" nil nil string)))
-    (split-string string separators)))
-
-(defun org-string-display (string)
-  "Return STRING as it is displayed in the current buffer.
-This function takes into consideration `invisible' and `display'
-text properties."
-  (let* ((build-from-parts
-         (lambda (s property filter)
-           ;; Build a new string out of string S.  On every group of
-           ;; contiguous characters with the same PROPERTY value,
-           ;; call FILTER on the properties list at the beginning of
-           ;; the group.  If it returns a string, replace the
-           ;; characters in the group with it.  Otherwise, preserve
-           ;; those characters.
-           (let ((len (length s))
-                 (new "")
-                 (i 0)
-                 (cursor 0))
-             (while (setq i (text-property-not-all i len property nil s))
-               (let ((end (next-single-property-change i property s len))
-                     (value (funcall filter (text-properties-at i s))))
-                 (when value
-                   (setq new (concat new (substring s cursor i) value))
-                   (setq cursor end))
-                 (setq i end)))
-             (concat new (substring s cursor)))))
-        (prune-invisible
-         (lambda (s)
-           (funcall build-from-parts s 'invisible
-                    (lambda (props)
-                      ;; If `invisible' property in PROPS means text
-                      ;; is to be invisible, return the empty string.
-                      ;; Otherwise return nil so that the part is
-                      ;; skipped.
-                      (and (or (eq t buffer-invisibility-spec)
-                               (assoc-string (plist-get props 'invisible)
-                                             buffer-invisibility-spec))
-                           "")))))
-        (replace-display
-         (lambda (s)
-           (funcall build-from-parts s 'display
-                    (lambda (props)
-                      ;; If there is any string specification in
-                      ;; `display' property return it.  Also attach
-                      ;; other text properties on the part to that
-                      ;; string (face...).
-                      (let* ((display (plist-get props 'display))
-                             (value (if (stringp display) display
-                                      (cl-some #'stringp display))))
-                        (when value
-                          (apply #'propertize
-                                 ;; Displayed string could contain
-                                 ;; invisible parts, but no nested
-                                 ;; display.
-                                 (funcall prune-invisible value)
-                                 'display
-                                 (and (not (stringp display))
-                                      (cl-remove-if #'stringp display))
-                                 props))))))))
-    ;; `display' property overrides `invisible' one.  So we first
-    ;; replace characters with `display' property.  Then we remove
-    ;; invisible characters.
-    (funcall prune-invisible (funcall replace-display string))))
-
-(defun org-string-width (string)
-  "Return width of STRING when displayed in the current buffer.
-Unlike `string-width', this function takes into consideration
-`invisible' and `display' text properties."
-  (string-width (org-string-display string)))
-
-(defun org-not-nil (v)
-  "If V not nil, and also not the string \"nil\", then return V.
-Otherwise return nil."
-  (and v (not (equal v "nil")) v))
-
-(defmacro org-preserve-lc (&rest body)
-  (declare (debug (body)))
-  (org-with-gensyms (line col)
-    `(let ((,line (org-current-line))
-          (,col (current-column)))
-       (unwind-protect
-          (progn ,@body)
-        (org-goto-line ,line)
-        (org-move-to-column ,col)))))
-
-;; Use `org-with-silent-modifications' to ignore cosmetic changes and
-;; `org-unmodified' to ignore real text modifications
+;; Use `with-silent-modifications' to ignore cosmetic changes and
+;; `org-unmodified' to ignore real text modifications.
 (defmacro org-unmodified (&rest body)
   "Run BODY while preserving the buffer's `buffer-modified-p' state."
   (declare (debug (body)))
@@ -176,7 +79,7 @@ Otherwise return nil."
   (org-with-gensyms (mpom)
     `(let ((,mpom ,pom))
        (save-excursion
-        (if (markerp ,mpom) (set-buffer (marker-buffer ,mpom)))
+        (when (markerp ,mpom) (set-buffer (marker-buffer ,mpom)))
         (org-with-wide-buffer
          (goto-char (or ,mpom (point)))
          ,@body)))))
@@ -211,107 +114,38 @@ Otherwise return nil."
   (declare (debug (body)))
   `(let ((inhibit-read-only t)) ,@body))
 
-(defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
-                                  rear-nonsticky t mouse-map t fontified t
-                                  org-emphasis t)
-  "Properties to remove when a string without properties is wanted.")
-
-(defsubst org-no-properties (s &optional restricted)
-  "Remove all text properties from string S.
-When RESTRICTED is non-nil, only remove the properties listed
-in `org-rm-props'."
-  (if restricted (remove-text-properties 0 (length s) org-rm-props s)
-    (set-text-properties 0 (length s) nil s))
-  s)
-
-(defsubst org-get-alist-option (option key)
-  (cond ((eq key t) t)
-       ((eq option t) t)
-       ((assoc key option) (cdr (assoc key option)))
-       (t (let ((r (cdr (assq 'default option))))
-            (if (listp r) (delq nil r) r)))))
-
-(defsubst org-check-external-command (cmd &optional use no-error)
-  "Check if external program CMD for USE exists, error if not.
-When the program does exist, return its path.
-When it does not exist and NO-ERROR is set, return nil.
-Otherwise, throw an error.  The optional argument USE can describe what this
-program is needed for, so that the error message can be more informative."
-  (or (executable-find cmd)
-      (if no-error
-         nil
-       (error "Can't find `%s'%s" cmd
-              (if use (format " (%s)" use) "")))))
-
-(defsubst org-last (list)
-  "Return the last element of LIST."
-  (car (last list)))
-
-(defun org-let (list &rest body)
-  (eval (cons 'let (cons list body))))
-(put 'org-let 'lisp-indent-function 1)
-
-(defun org-let2 (list1 list2 &rest body)
-  (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
-(put 'org-let2 'lisp-indent-function 2)
-
-(defsubst org-call-with-arg (command arg)
-  "Call COMMAND interactively, but pretend prefix arg was ARG."
-  (let ((current-prefix-arg arg)) (call-interactively command)))
-
-(defsubst org-current-line (&optional pos)
-  (save-excursion
-    (and pos (goto-char pos))
-    ;; works also in narrowed buffer, because we start at 1, not point-min
-    (+ (if (bolp) 1 0) (count-lines 1 (point)))))
-
-(defsubst org-goto-line (N)
-  (save-restriction
-    (widen)
-    (goto-char (point-min))
-    (forward-line (1- N))))
-
-(defsubst org-current-line-string (&optional to-here)
-  (buffer-substring (point-at-bol) (if to-here (point) (point-at-eol))))
-
-(defsubst org-pos-in-match-range (pos n)
-  (and (match-beginning n)
-       (<= (match-beginning n) pos)
-       (>= (match-end n) pos)))
-
-(defun org-match-line (regexp)
-  "Match REGEXP at the beginning of the current line."
-  (save-excursion
-    (beginning-of-line)
-    (looking-at regexp)))
-
-(defun org-plist-delete (plist property)
-  "Delete PROPERTY from PLIST.
-This is in contrast to merely setting it to 0."
-  (let (p)
-    (while plist
-      (if (not (eq property (car plist)))
-         (setq p (plist-put p (car plist) (nth 1 plist))))
-      (setq plist (cddr plist)))
-    p))
-
 (defmacro org-save-outline-visibility (use-markers &rest body)
   "Save and restore outline visibility around BODY.
-If USE-MARKERS is non-nil, use markers for the positions.
-This means that the buffer may change while running BODY,
-but it also means that the buffer should stay alive
-during the operation, because otherwise all these markers will
-point nowhere."
+If USE-MARKERS is non-nil, use markers for the positions.  This
+means that the buffer may change while running BODY, but it also
+means that the buffer should stay alive during the operation,
+because otherwise all these markers will point to nowhere."
   (declare (debug (form body)) (indent 1))
-  (org-with-gensyms (data)
-    `(let ((,data (org-outline-overlay-data ,use-markers)))
-       (unwind-protect
-          (prog1 (progn ,@body)
-            (org-set-outline-overlay-data ,data))
-        (when ,use-markers
-          (dolist (c ,data)
-            (when (markerp (car c)) (move-marker (car c) nil))
-            (when (markerp (cdr c)) (move-marker (cdr c) nil))))))))
+  (org-with-gensyms (data invisible-types markers?)
+    `(let* ((,invisible-types '(org-hide-block org-hide-drawer outline))
+           (,markers? ,use-markers)
+           (,data
+            (mapcar (lambda (o)
+                      (let ((beg (overlay-start o))
+                            (end (overlay-end o))
+                            (type (overlay-get o 'invisible)))
+                        (and beg end
+                             (> end beg)
+                             (memq type ,invisible-types)
+                             (list (if ,markers? (copy-marker beg) beg)
+                                   (if ,markers? (copy-marker end t) end)
+                                   type))))
+                    (org-with-wide-buffer
+                     (overlays-in (point-min) (point-max))))))
+       (unwind-protect (progn ,@body)
+        (org-with-wide-buffer
+         (dolist (type ,invisible-types)
+           (remove-overlays (point-min) (point-max) 'invisible type))
+         (pcase-dolist (`(,beg ,end ,type) (delq nil ,data))
+           (org-flag-region beg end t type)
+           (when ,markers?
+             (set-marker beg nil)
+             (set-marker end nil))))))))
 
 (defmacro org-with-wide-buffer (&rest body)
   "Execute body while temporarily widening the buffer."
@@ -335,49 +169,190 @@ point nowhere."
             (org-outline-regexp-bol (concat "^" org-outline-regexp)))
        ,@body)))
 
-(defvar org-outline-regexp) ; defined in org.el
-(defvar org-odd-levels-only) ; defined in org.el
-(defvar org-inlinetask-min-level) ; defined in org-inlinetask.el
-(defun org-get-limited-outline-regexp ()
-  "Return outline-regexp with limited number of levels.
-The number of levels is controlled by `org-inlinetask-min-level'."
-  (cond ((not (derived-mode-p 'org-mode))
-        outline-regexp)
-       ((not (featurep 'org-inlinetask))
-        org-outline-regexp)
-       (t
-        (let* ((limit-level (1- org-inlinetask-min-level))
-               (nstars (if org-odd-levels-only
-                           (1- (* limit-level 2))
-                         limit-level)))
-          (format "\\*\\{1,%d\\} " nstars)))))
-
 (defmacro org-eval-in-environment (environment form)
   (declare (debug (form form)) (indent 1))
   `(eval (list 'let ,environment ',form)))
 
-(defun org-make-parameter-alist (flat)
-  "Return alist based on FLAT.
-FLAT is a list with alternating symbol names and values.  The
-returned alist is a list of lists with the symbol name in car and
-the value in cdr."
-  (when flat
-    (cons (list (car flat) (cadr flat))
-         (org-make-parameter-alist (cddr flat)))))
-
 ;;;###autoload
 (defmacro org-load-noerror-mustsuffix (file)
   "Load FILE with optional arguments NOERROR and MUSTSUFFIX."
   `(load ,file 'noerror nil nil 'mustsuffix))
 
-(defun org-unbracket-string (pre post string)
-  "Remove PRE/POST from the beginning/end of STRING.
-Both PRE and POST must be pre-/suffixes of STRING, or neither is
-removed."
-  (if (and (string-prefix-p pre string)
-          (string-suffix-p post string))
-      (substring string (length pre) (- (length post)))
-    string))
+(defmacro org-preserve-local-variables (&rest body)
+  "Execute BODY while preserving local variables."
+  (declare (debug (body)))
+  `(let ((local-variables
+         (org-with-wide-buffer
+          (goto-char (point-max))
+          (let ((case-fold-search t))
+            (and (re-search-backward "^[ \t]*# +Local Variables:"
+                                     (max (- (point) 3000) 1)
+                                     t)
+                 (delete-and-extract-region (point) (point-max)))))))
+     (unwind-protect (progn ,@body)
+       (when local-variables
+        (org-with-wide-buffer
+         (goto-char (point-max))
+         ;; If last section is folded, make sure to also hide file
+         ;; local variables after inserting them back.
+         (let ((overlay
+                (cl-find-if (lambda (o)
+                              (eq 'outline (overlay-get o 'invisible)))
+                            (overlays-at (1- (point))))))
+           (unless (bolp) (insert "\n"))
+           (insert local-variables)
+           (when overlay
+             (move-overlay overlay (overlay-start overlay) (point-max)))))))))
+
+(defmacro org-no-popups (&rest body)
+  "Suppress popup windows and evaluate BODY."
+  `(let (pop-up-frames display-buffer-alist)
+     ,@body))
+
+
+;;; Buffer and windows
+
+(defun org-base-buffer (buffer)
+  "Return the base buffer of BUFFER, if it has one.  Else return the buffer."
+  (when buffer
+    (or (buffer-base-buffer buffer)
+       buffer)))
+
+(defun org-find-base-buffer-visiting (file)
+  "Like `find-buffer-visiting' but always return the base buffer and
+not an indirect buffer."
+  (let ((buf (or (get-file-buffer file)
+                (find-buffer-visiting file))))
+    (org-base-buffer buf)))
+
+(defun org-switch-to-buffer-other-window (&rest args)
+  "Switch to buffer in a second window on the current frame.
+In particular, do not allow pop-up frames.
+Returns the newly created buffer."
+  (org-no-popups (apply #'switch-to-buffer-other-window args)))
+
+(defun org-fit-window-to-buffer (&optional window max-height min-height
+                                           shrink-only)
+  "Fit WINDOW to the buffer, but only if it is not a side-by-side window.
+WINDOW defaults to the selected window.  MAX-HEIGHT and MIN-HEIGHT are
+passed through to `fit-window-to-buffer'.  If SHRINK-ONLY is set, call
+`shrink-window-if-larger-than-buffer' instead, the height limit is
+ignored in this case."
+  (cond ((if (fboundp 'window-full-width-p)
+             (not (window-full-width-p window))
+           ;; Do nothing if another window would suffer.
+           (> (frame-width) (window-width window))))
+        ((and (fboundp 'fit-window-to-buffer) (not shrink-only))
+         (fit-window-to-buffer window max-height min-height))
+        ((fboundp 'shrink-window-if-larger-than-buffer)
+         (shrink-window-if-larger-than-buffer window)))
+  (or window (selected-window)))
+
+
+
+;;; File
+
+(defun org-file-newer-than-p (file time)
+  "Non-nil if FILE is newer than TIME.
+FILE is a filename, as a string, TIME is a list of integers, as
+returned by, e.g., `current-time'."
+  (and (file-exists-p file)
+       ;; Only compare times up to whole seconds as some file-systems
+       ;; (e.g. HFS+) do not retain any finer granularity.  As
+       ;; a consequence, make sure we return non-nil when the two
+       ;; times are equal.
+       (not (time-less-p (cl-subseq (nth 5 (file-attributes file)) 0 2)
+                        (cl-subseq time 0 2)))))
+
+(defun org-compile-file (source process ext &optional err-msg log-buf spec)
+  "Compile a SOURCE file using PROCESS.
+
+PROCESS is either a function or a list of shell commands, as
+strings.  EXT is a file extension, without the leading dot, as
+a string.  It is used to check if the process actually succeeded.
+
+PROCESS must create a file with the same base name and directory
+as SOURCE, but ending with EXT.  The function then returns its
+filename.  Otherwise, it raises an error.  The error message can
+then be refined by providing string ERR-MSG, which is appended to
+the standard message.
+
+If PROCESS is a function, it is called with a single argument:
+the SOURCE file.
+
+If it is a list of commands, each of them is called using
+`shell-command'.  By default, in each command, %b, %f, %F, %o and
+%O are replaced with, respectively, SOURCE base name, name, full
+name, directory and absolute output file name.  It is possible,
+however, to use more place-holders by specifying them in optional
+argument SPEC, as an alist following the pattern
+
+  (CHARACTER . REPLACEMENT-STRING).
+
+When PROCESS is a list of commands, optional argument LOG-BUF can
+be set to a buffer or a buffer name.  `shell-command' then uses
+it for output."
+  (let* ((base-name (file-name-base source))
+        (full-name (file-truename source))
+        (out-dir (or (file-name-directory source) "./"))
+        (output (expand-file-name (concat base-name "." ext) out-dir))
+        (time (current-time))
+        (err-msg (if (stringp err-msg) (concat ".  " err-msg) "")))
+    (save-window-excursion
+      (pcase process
+       ((pred functionp) (funcall process (shell-quote-argument source)))
+       ((pred consp)
+        (let ((log-buf (and log-buf (get-buffer-create log-buf)))
+              (spec (append spec
+                            `((?b . ,(shell-quote-argument base-name))
+                              (?f . ,(shell-quote-argument source))
+                              (?F . ,(shell-quote-argument full-name))
+                              (?o . ,(shell-quote-argument out-dir))
+                              (?O . ,(shell-quote-argument output))))))
+          (dolist (command process)
+            (shell-command (format-spec command spec) log-buf))
+          (when log-buf (with-current-buffer log-buf (compilation-mode)))))
+       (_ (error "No valid command to process %S%s" source err-msg))))
+    ;; Check for process failure.  Output file is expected to be
+    ;; located in the same directory as SOURCE.
+    (unless (org-file-newer-than-p output time)
+      (error (format "File %S wasn't produced%s" output err-msg)))
+    output))
+
+
+
+;;; Indentation
+
+(defun org-do-remove-indentation (&optional n)
+  "Remove the maximum common indentation from the buffer.
+When optional argument N is a positive integer, remove exactly
+that much characters from indentation, if possible.  Return nil
+if it fails."
+  (catch :exit
+    (goto-char (point-min))
+    ;; Find maximum common indentation, if not specified.
+    (let ((n (or n
+                (let ((min-ind (point-max)))
+                  (save-excursion
+                    (while (re-search-forward "^[ \t]*\\S-" nil t)
+                      (let ((ind (current-indentation)))
+                        (if (zerop ind) (throw :exit nil)
+                          (setq min-ind (min min-ind ind))))))
+                  min-ind))))
+      (if (zerop n) (throw :exit nil)
+       ;; Remove exactly N indentation, but give up if not possible.
+       (while (not (eobp))
+         (let ((ind (progn (skip-chars-forward " \t") (current-column))))
+           (cond ((eolp) (delete-region (line-beginning-position) (point)))
+                 ((< ind n) (throw :exit nil))
+                 (t (indent-line-to (- ind n))))
+           (forward-line)))
+       ;; Signal success.
+       t))))
+
+
+
+;;; Input
 
 (defun org-read-function (prompt &optional allow-empty?)
   "Prompt for a function.
@@ -389,6 +364,191 @@ error when the user input is empty."
          (allow-empty? nil)
          (t (user-error "Empty input is not valid")))))
 
+(defun org-completing-read (&rest args)
+  "Completing-read with SPACE being a normal character."
+  (let ((enable-recursive-minibuffers t)
+       (minibuffer-local-completion-map
+        (copy-keymap minibuffer-local-completion-map)))
+    (define-key minibuffer-local-completion-map " " 'self-insert-command)
+    (define-key minibuffer-local-completion-map "?" 'self-insert-command)
+    (define-key minibuffer-local-completion-map (kbd "C-c !")
+      'org-time-stamp-inactive)
+    (apply #'completing-read args)))
+
+(defun org--mks-read-key (allowed-keys prompt)
+  "Read a key and ensure it is a member of ALLOWED-KEYS.
+TAB, SPC and RET are treated equivalently."
+  (let* ((key (char-to-string
+              (pcase (read-char-exclusive prompt)
+                ((or ?\s ?\t ?\r) ?\t)
+                (char char)))))
+    (if (member key allowed-keys)
+        key
+      (message "Invalid key: `%s'" key)
+      (sit-for 1)
+      (org--mks-read-key allowed-keys prompt))))
+
+(defun org-mks (table title &optional prompt specials)
+  "Select a member of an alist with multiple keys.
+
+TABLE is the alist which should contain entries where the car is a string.
+There should be two types of entries.
+
+1. prefix descriptions like (\"a\" \"Description\")
+   This indicates that `a' is a prefix key for multi-letter selection, and
+   that there are entries following with keys like \"ab\", \"ax\"...
+
+2. Select-able members must have more than two elements, with the first
+   being the string of keys that lead to selecting it, and the second a
+   short description string of the item.
+
+The command will then make a temporary buffer listing all entries
+that can be selected with a single key, and all the single key
+prefixes.  When you press the key for a single-letter entry, it is selected.
+When you press a prefix key, the commands (and maybe further prefixes)
+under this key will be shown and offered for selection.
+
+TITLE will be placed over the selection in the temporary buffer,
+PROMPT will be used when prompting for a key.  SPECIALS is an
+alist with (\"key\" \"description\") entries.  When one of these
+is selected, only the bare key is returned."
+  (save-window-excursion
+    (let ((inhibit-quit t)
+         (buffer (org-switch-to-buffer-other-window "*Org Select*"))
+         (prompt (or prompt "Select: "))
+         current)
+      (unwind-protect
+         (catch 'exit
+           (while t
+             (erase-buffer)
+             (insert title "\n\n")
+             (let ((des-keys nil)
+                   (allowed-keys '("\C-g"))
+                   (tab-alternatives '("\s" "\t" "\r"))
+                   (cursor-type nil))
+               ;; Populate allowed keys and descriptions keys
+               ;; available with CURRENT selector.
+               (let ((re (format "\\`%s\\(.\\)\\'"
+                                 (if current (regexp-quote current) "")))
+                     (prefix (if current (concat current " ") "")))
+                 (dolist (entry table)
+                   (pcase entry
+                     ;; Description.
+                     (`(,(and key (pred (string-match re))) ,desc)
+                      (let ((k (match-string 1 key)))
+                        (push k des-keys)
+                        ;; Keys ending in tab, space or RET are equivalent.
+                        (if (member k tab-alternatives)
+                            (push "\t" allowed-keys)
+                          (push k allowed-keys))
+                        (insert prefix "[" k "]" "..." "  " desc "..." "\n")))
+                     ;; Usable entry.
+                     (`(,(and key (pred (string-match re))) ,desc . ,_)
+                      (let ((k (match-string 1 key)))
+                        (insert prefix "[" k "]" "     " desc "\n")
+                        (push k allowed-keys)))
+                     (_ nil))))
+               ;; Insert special entries, if any.
+               (when specials
+                 (insert "----------------------------------------------------\
+---------------------------\n")
+                 (pcase-dolist (`(,key ,description) specials)
+                   (insert (format "[%s]     %s\n" key description))
+                   (push key allowed-keys)))
+               ;; Display UI and let user select an entry or
+               ;; a sub-level prefix.
+               (goto-char (point-min))
+               (unless (pos-visible-in-window-p (point-max))
+                 (org-fit-window-to-buffer))
+               (let ((pressed (org--mks-read-key allowed-keys prompt)))
+                 (setq current (concat current pressed))
+                 (cond
+                  ((equal pressed "\C-g") (user-error "Abort"))
+                  ;; Selection is a prefix: open a new menu.
+                  ((member pressed des-keys))
+                  ;; Selection matches an association: return it.
+                  ((let ((entry (assoc current table)))
+                     (and entry (throw 'exit entry))))
+                  ;; Selection matches a special entry: return the
+                  ;; selection prefix.
+                  ((assoc current specials) (throw 'exit current))
+                  (t (error "No entry available")))))))
+       (when buffer (kill-buffer buffer))))))
+
+
+;;; List manipulation
+
+(defsubst org-get-alist-option (option key)
+  (cond ((eq key t) t)
+       ((eq option t) t)
+       ((assoc key option) (cdr (assoc key option)))
+       (t (let ((r (cdr (assq 'default option))))
+            (if (listp r) (delq nil r) r)))))
+
+(defsubst org-last (list)
+  "Return the last element of LIST."
+  (car (last list)))
+
+(defsubst org-uniquify (list)
+  "Non-destructively remove duplicate elements from LIST."
+  (let ((res (copy-sequence list))) (delete-dups res)))
+
+(defun org-uniquify-alist (alist)
+  "Merge elements of ALIST with the same key.
+
+For example, in this alist:
+
+\(org-uniquify-alist \\='((a 1) (b 2) (a 3)))
+  => \\='((a 1 3) (b 2))
+
+merge (a 1) and (a 3) into (a 1 3).
+
+The function returns the new ALIST."
+  (let (rtn)
+    (dolist (e alist rtn)
+      (let (n)
+       (if (not (assoc (car e) rtn))
+           (push e rtn)
+         (setq n (cons (car e) (append (cdr (assoc (car e) rtn)) (cdr e))))
+         (setq rtn (assq-delete-all (car e) rtn))
+         (push n rtn))))))
+
+(defun org-delete-all (elts list)
+  "Remove all elements in ELTS from LIST.
+Comparison is done with `equal'.  It is a destructive operation
+that may remove elements by altering the list structure."
+  (while elts
+    (setq list (delete (pop elts) list)))
+  list)
+
+(defun org-plist-delete (plist property)
+  "Delete PROPERTY from PLIST.
+This is in contrast to merely setting it to 0."
+  (let (p)
+    (while plist
+      (if (not (eq property (car plist)))
+         (setq p (plist-put p (car plist) (nth 1 plist))))
+      (setq plist (cddr plist)))
+    p))
+
+(defun org-combine-plists (&rest plists)
+  "Create a single property list from all plists in PLISTS.
+The process starts by copying the first list, and then setting properties
+from the other lists.  Settings in the last list are the most significant
+ones and overrule settings in the other lists."
+  (let ((rtn (copy-sequence (pop plists)))
+       p v ls)
+    (while plists
+      (setq ls (pop plists))
+      (while ls
+       (setq p (pop ls) v (pop ls))
+       (setq rtn (plist-put rtn p v))))
+    rtn))
+
+
+
+;;; Local variables
+
 (defconst org-unique-local-variables
   '(org-element--cache
     org-element--cache-objects
@@ -425,6 +585,604 @@ Optional argument REGEXP selects variables to clone."
                  (or (null regexp) (string-match-p regexp (symbol-name name))))
         (ignore-errors (set (make-local-variable name) value)))))))
 
+
+;;; Miscellaneous
+
+(defsubst org-call-with-arg (command arg)
+  "Call COMMAND interactively, but pretend prefix arg was ARG."
+  (let ((current-prefix-arg arg)) (call-interactively command)))
+
+(defsubst org-check-external-command (cmd &optional use no-error)
+  "Check if external program CMD for USE exists, error if not.
+When the program does exist, return its path.
+When it does not exist and NO-ERROR is set, return nil.
+Otherwise, throw an error.  The optional argument USE can describe what this
+program is needed for, so that the error message can be more informative."
+  (or (executable-find cmd)
+      (if no-error
+         nil
+       (error "Can't find `%s'%s" cmd
+              (if use (format " (%s)" use) "")))))
+
+(defun org-display-warning (message)
+  "Display the given MESSAGE as a warning."
+  (display-warning 'org message :warning))
+
+(defun org-unlogged-message (&rest args)
+  "Display a message, but avoid logging it in the *Messages* buffer."
+  (let ((message-log-max nil))
+    (apply #'message args)))
+
+(defun org-let (list &rest body)
+  (eval (cons 'let (cons list body))))
+(put 'org-let 'lisp-indent-function 1)
+
+(defun org-let2 (list1 list2 &rest body)
+  (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
+(put 'org-let2 'lisp-indent-function 2)
+
+(defun org-eval (form)
+  "Eval FORM and return result."
+  (condition-case error
+      (eval form)
+    (error (format "%%![Error: %s]" error))))
+
+(defvar org-outline-regexp) ; defined in org.el
+(defvar org-odd-levels-only) ; defined in org.el
+(defvar org-inlinetask-min-level) ; defined in org-inlinetask.el
+(defun org-get-limited-outline-regexp ()
+  "Return outline-regexp with limited number of levels.
+The number of levels is controlled by `org-inlinetask-min-level'."
+  (cond ((not (derived-mode-p 'org-mode))
+        outline-regexp)
+       ((not (featurep 'org-inlinetask))
+        org-outline-regexp)
+       (t
+        (let* ((limit-level (1- org-inlinetask-min-level))
+               (nstars (if org-odd-levels-only
+                           (1- (* limit-level 2))
+                         limit-level)))
+          (format "\\*\\{1,%d\\} " nstars)))))
+
+
+
+;;; Motion
+
+(defsubst org-goto-line (N)
+  (save-restriction
+    (widen)
+    (goto-char (point-min))
+    (forward-line (1- N))))
+
+(defsubst org-current-line (&optional pos)
+  (save-excursion
+    (and pos (goto-char pos))
+    ;; works also in narrowed buffer, because we start at 1, not point-min
+    (+ (if (bolp) 1 0) (count-lines 1 (point)))))
+
+
+
+;;; Overlays
+
+(defun org-overlay-display (ovl text &optional face evap)
+  "Make overlay OVL display TEXT with face FACE."
+  (overlay-put ovl 'display text)
+  (when face (overlay-put ovl 'face face))
+  (when evap (overlay-put ovl 'evaporate t)))
+
+(defun org-overlay-before-string (ovl text &optional face evap)
+  "Make overlay OVL display TEXT with face FACE."
+  (when face (org-add-props text nil 'face face))
+  (overlay-put ovl 'before-string text)
+  (when evap (overlay-put ovl 'evaporate t)))
+
+(defun org-find-overlays (prop &optional pos delete)
+  "Find all overlays specifying PROP at POS or point.
+If DELETE is non-nil, delete all those overlays."
+  (let (found)
+    (dolist (ov (overlays-at (or pos (point))) found)
+      (cond ((not (overlay-get ov prop)))
+           (delete (delete-overlay ov))
+           (t (push ov found))))))
+
+(defun org-flag-region (from to flag spec)
+  "Hide or show lines from FROM to TO, according to FLAG.
+SPEC is the invisibility spec, as a symbol."
+  (remove-overlays from to 'invisible spec)
+  ;; Use `front-advance' since text right before to the beginning of
+  ;; the overlay belongs to the visible line than to the contents.
+  (when flag
+    (let ((o (make-overlay from to nil 'front-advance)))
+      (overlay-put o 'evaporate t)
+      (overlay-put o 'invisible spec)
+      (overlay-put o 'isearch-open-invisible #'delete-overlay))))
+
+
+
+;;; Regexp matching
+
+(defsubst org-pos-in-match-range (pos n)
+  (and (match-beginning n)
+       (<= (match-beginning n) pos)
+       (>= (match-end n) pos)))
+
+(defun org-skip-whitespace ()
+  "Skip over space, tabs and newline characters."
+  (skip-chars-forward " \t\n\r"))
+
+(defun org-match-line (regexp)
+  "Match REGEXP at the beginning of the current line."
+  (save-excursion
+    (beginning-of-line)
+    (looking-at regexp)))
+
+(defun org-match-any-p (re list)
+  "Non-nil if regexp RE matches an element in LIST."
+  (cl-some (lambda (x) (string-match-p re x)) list))
+
+(defun org-in-regexp (regexp &optional nlines visually)
+  "Check if point is inside a match of REGEXP.
+
+Normally only the current line is checked, but you can include
+NLINES extra lines around point into the search.  If VISUALLY is
+set, require that the cursor is not after the match but really
+on, so that the block visually is on the match.
+
+Return nil or a cons cell (BEG . END) where BEG and END are,
+respectively, the positions at the beginning and the end of the
+match."
+  (catch :exit
+    (let ((pos (point))
+          (eol (line-end-position (if nlines (1+ nlines) 1))))
+      (save-excursion
+       (beginning-of-line (- 1 (or nlines 0)))
+       (while (and (re-search-forward regexp eol t)
+                   (<= (match-beginning 0) pos))
+         (let ((end (match-end 0)))
+           (when (or (> end pos) (and (= end pos) (not visually)))
+             (throw :exit (cons (match-beginning 0) (match-end 0))))))))))
+
+(defun org-point-in-group (point group &optional context)
+  "Check if POINT is in match-group GROUP.
+If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
+match.  If the match group does not exist or point is not inside it,
+return nil."
+  (and (match-beginning group)
+       (>= point (match-beginning group))
+       (<= point (match-end group))
+       (if context
+          (list context (match-beginning group) (match-end group))
+        t)))
+
+
+
+;;; String manipulation
+
+(defun org-string< (a b)
+  (org-string-collate-lessp a b))
+
+(defun org-string<= (a b)
+  (or (string= a b) (org-string-collate-lessp a b)))
+
+(defun org-string>= (a b)
+  (not (org-string-collate-lessp a b)))
+
+(defun org-string> (a b)
+  (and (not (string= a b))
+       (not (org-string-collate-lessp a b))))
+
+(defun org-string<> (a b)
+  (not (string= a b)))
+
+(defsubst org-trim (s &optional keep-lead)
+  "Remove whitespace at the beginning and the end of string S.
+When optional argument KEEP-LEAD is non-nil, removing blank lines
+at the beginning of the string does not affect leading indentation."
+  (replace-regexp-in-string
+   (if keep-lead "\\`\\([ \t]*\n\\)+" "\\`[ \t\n\r]+") ""
+   (replace-regexp-in-string "[ \t\n\r]+\\'" "" s)))
+
+(defun org-string-nw-p (s)
+  "Return S if S is a string containing a non-blank character.
+Otherwise, return nil."
+  (and (stringp s)
+       (string-match-p "[^ \r\t\n]" s)
+       s))
+
+(defun org-reverse-string (string)
+  "Return the reverse of STRING."
+  (apply #'string (nreverse (string-to-list string))))
+
+(defun org-split-string (string &optional separators)
+  "Splits STRING into substrings at SEPARATORS.
+
+SEPARATORS is a regular expression.  When nil, it defaults to
+\"[ \f\t\n\r\v]+\".
+
+Unlike `split-string', matching SEPARATORS at the beginning and
+end of string are ignored."
+  (let ((separators (or separators "[ \f\t\n\r\v]+")))
+    (if (not (string-match separators string)) (list string)
+      (let ((i (match-end 0))
+           (results
+            (and (/= 0 (match-beginning 0)) ;skip leading separator
+                 (list (substring string 0 (match-beginning 0))))))
+       (while (string-match separators string i)
+         (push (substring string i (match-beginning 0))
+               results)
+         (setq i (match-end 0)))
+       (nreverse (if (= i (length string))
+                     results           ;skip trailing separator
+                   (cons (substring string i) results)))))))
+
+(defun org--string-from-props (s property beg end)
+  "Return the visible part of string S.
+Visible part is determined according to text PROPERTY, which is
+either `invisible' or `display'.  BEG and END are 0-indices
+delimiting S."
+  (let ((width 0)
+       (cursor beg))
+    (while (setq beg (text-property-not-all beg end property nil s))
+      (let* ((next (next-single-property-change beg property s end))
+            (props (text-properties-at beg s))
+            (spec (plist-get props property))
+            (value
+             (pcase property
+               (`invisible
+                ;; If `invisible' property in PROPS means text is to
+                ;; be invisible, return 0.  Otherwise return nil so
+                ;; as to resume search.
+                (and (or (eq t buffer-invisibility-spec)
+                         (assoc-string spec buffer-invisibility-spec))
+                     0))
+               (`display
+                (pcase spec
+                  (`nil nil)
+                  (`(space . ,props)
+                   (let ((width (plist-get props :width)))
+                     (and (wholenump width) width)))
+                  (`(image . ,_)
+                   (ceiling (car (image-size spec))))
+                  ((pred stringp)
+                   ;; Displayed string could contain invisible parts,
+                   ;; but no nested display.
+                   (org--string-from-props spec 'invisible 0 (length spec)))
+                  (_
+                   ;; Un-handled `display' value.  Ignore it.
+                   ;; Consider the original string instead.
+                   nil)))
+               (_ (error "Unknown property: %S" property)))))
+       (when value
+         (cl-incf width
+                  ;; When looking for `display' parts, we still need
+                  ;; to look for `invisible' property elsewhere.
+                  (+ (cond ((eq property 'display)
+                            (org--string-from-props s 'invisible cursor beg))
+                           ((= cursor beg) 0)
+                           (t (string-width (substring s cursor beg))))
+                     value))
+         (setq cursor next))
+       (setq beg next)))
+    (+ width
+       ;; Look for `invisible' property in the last part of the
+       ;; string.  See above.
+       (cond ((eq property 'display)
+             (org--string-from-props s 'invisible cursor end))
+            ((= cursor end) 0)
+            (t (string-width (substring s cursor end)))))))
+
+(defun org-string-width (string)
+  "Return width of STRING when displayed in the current buffer.
+Unlike `string-width', this function takes into consideration
+`invisible' and `display' text properties.  It supports the
+latter in a limited way, mostly for combinations used in Org.
+Results may be off sometimes if it cannot handle a given
+`display' value."
+  (org--string-from-props string 'display 0 (length string)))
+
+(defun org-not-nil (v)
+  "If V not nil, and also not the string \"nil\", then return V.
+Otherwise return nil."
+  (and v (not (equal v "nil")) v))
+
+(defun org-unbracket-string (pre post string)
+  "Remove PRE/POST from the beginning/end of STRING.
+Both PRE and POST must be pre-/suffixes of STRING, or neither is
+removed.  Return the new string.  If STRING is nil, return nil."
+  (declare (indent 2))
+  (and string
+       (if (and (string-prefix-p pre string)
+               (string-suffix-p post string))
+          (substring string (length pre) (- (length post)))
+        string)))
+
+(defun org-strip-quotes (string)
+  "Strip double quotes from around STRING, if applicable.
+If STRING is nil, return nil."
+  (org-unbracket-string "\"" "\"" string))
+
+(defsubst org-current-line-string (&optional to-here)
+  "Return current line, as a string.
+If optional argument TO-HERE is non-nil, return string from
+beginning of line up to point."
+  (buffer-substring (line-beginning-position)
+                   (if to-here (point) (line-end-position))))
+
+(defun org-shorten-string (s maxlength)
+  "Shorten string S so that it is no longer than MAXLENGTH characters.
+If the string is shorter or has length MAXLENGTH, just return the
+original string.  If it is longer, the functions finds a space in the
+string, breaks this string off at that locations and adds three dots
+as ellipsis.  Including the ellipsis, the string will not be longer
+than MAXLENGTH.  If finding a good breaking point in the string does
+not work, the string is just chopped off in the middle of a word
+if necessary."
+  (if (<= (length s) maxlength)
+      s
+    (let* ((n (max (- maxlength 4) 1))
+          (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ 
]\\|\\'\\)")))
+      (if (string-match re s)
+         (concat (match-string 1 s) "...")
+       (concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
+
+(defun org-remove-tabs (s &optional width)
+  "Replace tabulators in S with spaces.
+Assumes that s is a single line, starting in column 0."
+  (setq width (or width tab-width))
+  (while (string-match "\t" s)
+    (setq s (replace-match
+            (make-string
+             (- (* width (/ (+ (match-beginning 0) width) width))
+                (match-beginning 0)) ?\ )
+            t t s)))
+  s)
+
+(defun org-wrap (string &optional width lines)
+  "Wrap string to either a number of lines, or a width in characters.
+If WIDTH is non-nil, the string is wrapped to that width, however many lines
+that costs.  If there is a word longer than WIDTH, the text is actually
+wrapped to the length of that word.
+IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
+many lines, whatever width that takes.
+The return value is a list of lines, without newlines at the end."
+  (let* ((words (split-string string))
+        (maxword (apply 'max (mapcar 'org-string-width words)))
+        w ll)
+    (cond (width
+          (org--do-wrap words (max maxword width)))
+         (lines
+          (setq w maxword)
+          (setq ll (org--do-wrap words maxword))
+          (if (<= (length ll) lines)
+              ll
+            (setq ll words)
+            (while (> (length ll) lines)
+              (setq w (1+ w))
+              (setq ll (org--do-wrap words w)))
+            ll))
+         (t (error "Cannot wrap this")))))
+
+(defun org--do-wrap (words width)
+  "Create lines of maximum width WIDTH (in characters) from word list WORDS."
+  (let (lines line)
+    (while words
+      (setq line (pop words))
+      (while (and words (< (+ (length line) (length (car words))) width))
+       (setq line (concat line " " (pop words))))
+      (setq lines (push line lines)))
+    (nreverse lines)))
+
+(defun org-remove-indentation (code &optional n)
+  "Remove maximum common indentation in string CODE and return it.
+N may optionally be the number of columns to remove.  Return CODE
+as-is if removal failed."
+  (with-temp-buffer
+    (insert code)
+    (if (org-do-remove-indentation n) (buffer-string) code)))
+
+(defun org-fill-template (template alist)
+  "Find each %key of ALIST in TEMPLATE and replace it."
+  (let ((case-fold-search nil))
+    (dolist (entry (sort (copy-sequence alist)
+                         (lambda (a b) (< (length (car a)) (length (car b))))))
+      (setq template
+           (replace-regexp-in-string
+            (concat "%" (regexp-quote (car entry)))
+            (or (cdr entry) "") template t t)))
+    template))
+
+(defun org-replace-escapes (string table)
+  "Replace %-escapes in STRING with values in TABLE.
+TABLE is an association list with keys like \"%a\" and string values.
+The sequences in STRING may contain normal field width and padding information,
+for example \"%-5s\".  Replacements happen in the sequence given by TABLE,
+so values can contain further %-escapes if they are define later in TABLE."
+  (let ((tbl (copy-alist table))
+       (case-fold-search nil)
+        (pchg 0)
+        re rpl)
+    (dolist (e tbl)
+      (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
+      (when (and (cdr e) (string-match re (cdr e)))
+        (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
+              (safe "SREF"))
+          (add-text-properties 0 3 (list 'sref sref) safe)
+          (setcdr e (replace-match safe t t (cdr e)))))
+      (while (string-match re string)
+        (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
+                          (cdr e)))
+        (setq string (replace-match rpl t t string))))
+    (while (setq pchg (next-property-change pchg string))
+      (let ((sref (get-text-property pchg 'sref string)))
+       (when (and sref (string-match "SREF" string pchg))
+         (setq string (replace-match sref t t string)))))
+    string))
+
+
+;;; Text properties
+
+(defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
+                                  rear-nonsticky t mouse-map t fontified t
+                                  org-emphasis t)
+  "Properties to remove when a string without properties is wanted.")
+
+(defsubst org-no-properties (s &optional restricted)
+  "Remove all text properties from string S.
+When RESTRICTED is non-nil, only remove the properties listed
+in `org-rm-props'."
+  (if restricted (remove-text-properties 0 (length s) org-rm-props s)
+    (set-text-properties 0 (length s) nil s))
+  s)
+(defun org-add-props (string plist &rest props)
+  "Add text properties to entire string, from beginning to end.
+PLIST may be a list of properties, PROPS are individual properties and values
+that will be added to PLIST.  Returns the string that was modified."
+  (declare (indent 2))
+  (add-text-properties
+   0 (length string) (if props (append plist props) plist) string)
+  string)
+
+(defun org-make-parameter-alist (flat)
+  "Return alist based on FLAT.
+FLAT is a list with alternating symbol names and values.  The
+returned alist is a list of lists with the symbol name in car and
+the value in cdr."
+  (when flat
+    (cons (list (car flat) (cadr flat))
+         (org-make-parameter-alist (cddr flat)))))
+
+(defsubst org-get-at-bol (property)
+  "Get text property PROPERTY at the beginning of line."
+  (get-text-property (point-at-bol) property))
+
+(defun org-get-at-eol (property n)
+  "Get text property PROPERTY at the end of line less N characters."
+  (get-text-property (- (point-at-eol) n) property))
+
+(defun org-find-text-property-in-string (prop s)
+  "Return the first non-nil value of property PROP in string S."
+  (or (get-text-property 0 prop s)
+      (get-text-property (or (next-single-property-change 0 prop s) 0)
+                        prop s)))
+
+(defun org-invisible-p (&optional pos)
+  "Non-nil if the character after POS is invisible.
+If POS is nil, use `point' instead."
+  (get-char-property (or pos (point)) 'invisible))
+
+(defun org-truely-invisible-p ()
+  "Check if point is at a character currently not visible.
+This version does not only check the character property, but also
+`visible-mode'."
+  (unless (bound-and-true-p visible-mode)
+    (org-invisible-p)))
+
+(defun org-invisible-p2 ()
+  "Check if point is at a character currently not visible.
+If the point is at EOL (and not at the beginning of a buffer too),
+move it back by one char before doing this check."
+  (save-excursion
+    (when (and (eolp) (not (bobp)))
+      (backward-char 1))
+    (org-invisible-p)))
+
+
+;;; Time
+
+(defun org-2ft (s)
+  "Convert S to a floating point time.
+If S is already a number, just return it.  If it is a string,
+parse it as a time string and apply `float-time' to it.  If S is
+nil, just return 0."
+  (cond
+   ((numberp s) s)
+   ((stringp s)
+    (condition-case nil
+       (float-time (apply #'encode-time (org-parse-time-string s)))
+      (error 0)))
+   (t 0)))
+
+(defun org-time= (a b)
+  (let ((a (org-2ft a))
+       (b (org-2ft b)))
+    (and (> a 0) (> b 0) (= a b))))
+
+(defun org-time< (a b)
+  (let ((a (org-2ft a))
+       (b (org-2ft b)))
+    (and (> a 0) (> b 0) (< a b))))
+
+(defun org-time<= (a b)
+  (let ((a (org-2ft a))
+       (b (org-2ft b)))
+    (and (> a 0) (> b 0) (<= a b))))
+
+(defun org-time> (a b)
+  (let ((a (org-2ft a))
+       (b (org-2ft b)))
+    (and (> a 0) (> b 0) (> a b))))
+
+(defun org-time>= (a b)
+  (let ((a (org-2ft a))
+       (b (org-2ft b)))
+    (and (> a 0) (> b 0) (>= a b))))
+
+(defun org-time<> (a b)
+  (let ((a (org-2ft a))
+       (b (org-2ft b)))
+    (and (> a 0) (> b 0) (\= a b))))
+
+(defun org-parse-time-string (s &optional nodefault)
+  "Parse Org time string S.
+
+If time is not given, defaults to 0:00.  However, with optional
+NODEFAULT, hour and minute fields are nil if not given.
+
+Throw an error if S does not contain a valid Org time string.
+Note that the first match for YYYY-MM-DD will be used (e.g.,
+\"-52000-02-03\" will be taken as \"2000-02-03\").
+
+This should be a lot faster than the `parse-time-string'."
+  (unless (string-match org-ts-regexp0 s)
+    (error "Not an Org time string: %s" s))
+  (list 0
+       (cond ((match-beginning 8) (string-to-number (match-string 8 s)))
+             (nodefault nil)
+             (t 0))
+       (cond ((match-beginning 7) (string-to-number (match-string 7 s)))
+             (nodefault nil)
+             (t 0))
+       (string-to-number (match-string 4 s))
+       (string-to-number (match-string 3 s))
+       (string-to-number (match-string 2 s))
+       nil nil nil))
+
+(defun org-matcher-time (s)
+  "Interpret a time comparison value S as a floating point time.
+
+S can be an Org time stamp, a modifier, e.g., \"<+2d>\", or the
+following special strings: \"<now>\", \"<today>\",
+\"<tomorrow>\", and \"<yesterday>\".
+
+Return 0. if S is not recognized as a valid value."
+  (let ((today (float-time (apply #'encode-time
+                                 (append '(0 0 0) (nthcdr 3 (decode-time)))))))
+    (save-match-data
+      (cond
+       ((string= s "<now>") (float-time))
+       ((string= s "<today>") today)
+       ((string= s "<tomorrow>") (+ 86400.0 today))
+       ((string= s "<yesterday>") (- today 86400.0))
+       ((string-match "\\`<\\([-+][0-9]+\\)\\([hdwmy]\\)>\\'" s)
+       (+ today
+          (* (string-to-number (match-string 1 s))
+             (cdr (assoc (match-string 2 s)
+                         '(("d" . 86400.0)   ("w" . 604800.0)
+                           ("m" . 2678400.0) ("y" . 31557600.0)))))))
+       ((string-match org-ts-regexp0 s) (org-2ft s))
+       (t 0.)))))
+
+
 
 (provide 'org-macs)
 
diff --git a/lisp/org/org-mobile.el b/lisp/org/org-mobile.el
index dba6ca2..26a3f57 100644
--- a/lisp/org/org-mobile.el
+++ b/lisp/org/org-mobile.el
@@ -24,18 +24,17 @@
 ;;
 ;;; Commentary:
 ;;
-;; This file contains the code to interact with Richard Moreland's
-;; iPhone application MobileOrg, as well as with the Android version
-;; by Matthew Jones.  This code is documented in Appendix B of the Org
-;; manual.  The code is not specific for the iPhone and Android - any
-;; external viewer/flagging/editing application that uses the same
-;; conventions could be used.
+;; This file contains the code to interact with a mobile application,
+;; such as Richard Moreland's iPhone application MobileOrg, or the
+;; Android version by Matthew Jones.  This code is documented in
+;; Appendix B of the Org manual.  The code is not specific for the
+;; iPhone and Android - any external viewer/flagging/editing
+;; application that uses the same conventions could be used.
 
+(require 'cl-lib)
 (require 'org)
 (require 'org-agenda)
-(require 'cl-lib)
-
-(defvar org-agenda-keep-restricted-file-list)
+(require 'ol)
 
 ;;; Code:
 
@@ -45,15 +44,17 @@
   :group 'org)
 
 (defcustom org-mobile-files '(org-agenda-files)
-  "Files to be staged for MobileOrg.
+  "Files to be staged for the mobile application.
+
 This is basically a list of files and directories.  Files will be staged
-directly.  Directories will be search for files with the extension `.org'.
+directly.  Directories will be search for files with the extension \".org\".
 In addition to this, the list may also contain the following symbols:
 
-org-agenda-files
+`org-agenda-files'
      This means include the complete, unrestricted list of files given in
      the variable `org-agenda-files'.
-org-agenda-text-search-extra-files
+
+`org-agenda-text-search-extra-files'
      Include the files given in the variable
      `org-agenda-text-search-extra-files'."
   :group 'org-mobile
@@ -84,12 +85,14 @@ org-agenda-text-search-extra-files
 
 (defcustom org-mobile-use-encryption nil
   "Non-nil means keep only encrypted files on the WebDAV server.
+
 Encryption uses AES-256, with a password given in
-`org-mobile-encryption-password'.
-When nil, plain files are kept on the server.
-Turning on encryption requires setting the same password in the MobileOrg
-application.  Before turning this on, check of MobileOrg does already
-support it - at the time of this writing it did not yet."
+`org-mobile-encryption-password'.  When nil, plain files are kept
+on the server.
+
+Turning on encryption requires setting the same password in the
+mobile application.  Before turning this on, check if the mobile
+application does support it."
   :group 'org-mobile
   :version "24.1"
   :type 'boolean)
@@ -104,9 +107,10 @@ You might want to put this file into a directory where 
only you have access."
 
 (defcustom org-mobile-encryption-password ""
   "Password for encrypting files uploaded to the server.
+
 This is a single password which is used for AES-256 encryption.  The same
-password must also be set in the MobileOrg application.  All Org files,
-including mobileorg.org will be encrypted using this password.
+password must also be set in the mobile application.  All Org files,
+including \"mobileorg.org\" will be encrypted using this password.
 
 SECURITY CONSIDERATIONS:
 
@@ -129,12 +133,12 @@ session."
   (or (org-string-nw-p org-mobile-encryption-password)
       (org-string-nw-p org-mobile-encryption-password-session)
       (setq org-mobile-encryption-password-session
-           (read-passwd "Password for MobileOrg: " t))))
+           (read-passwd "Password for mobile application: " t))))
 
 (defcustom org-mobile-inbox-for-pull "~/org/from-mobile.org"
   "The file where captured notes and flags will be appended to.
 During the execution of `org-mobile-pull', the file
-`org-mobile-capture-file' will be emptied it's contents have
+`org-mobile-capture-file' is emptied as soon as its contents have
 been appended to the file given here.  This file should be in
 `org-directory', and not in the staging area or on the web server."
   :group 'org-mobile
@@ -142,23 +146,25 @@ been appended to the file given here.  This file should 
be in
 
 (defconst org-mobile-capture-file "mobileorg.org"
   "The capture file where the mobile stores captured notes and flags.
-This should not be changed, because MobileOrg assumes this name.")
+This must not be changed, because the mobile application assumes this name.")
 
 (defcustom org-mobile-index-file "index.org"
-  "The index file with links to all Org files that should be loaded by 
MobileOrg.
-Relative to `org-mobile-directory'.  The Address field in the MobileOrg setup
-should point to this file."
+  "Index file with links to all Org files.
+It should be loaded by the mobile application.  The file name is
+relative to `org-mobile-directory'.  The \"Address\" field in the
+mobile application setup should point to this file."
   :group 'org-mobile
   :type 'file)
 
 (defcustom org-mobile-agendas 'all
-  "The agendas that should be pushed to MobileOrg.
+  "The agendas that should be pushed to the mobile application.
+
 Allowed values:
 
-default  the weekly agenda and the global TODO list
-custom   all custom agendas defined by the user
-all      the custom agendas and the default ones
-list     a list of selection key(s) as string."
+`default'  the weekly agenda and the global TODO list
+`custom'   all custom agendas defined by the user
+`all'      the custom agendas and the default ones
+`list'     a list of selection key(s) as string."
   :group 'org-mobile
   :version "24.1"
   :type '(choice
@@ -229,7 +235,9 @@ using `rsync' or `scp'.")
 
 (defconst org-mobile-action-alist '(("edit" . org-mobile-edit))
   "Alist with flags and actions for mobile sync.
-When flagging an entry, MobileOrg will create entries that look like
+
+When flagging an entry, the mobile application creates entries
+that look like
 
   * F(action:data)  [[id:entry-id][entry title]]
 
@@ -311,6 +319,11 @@ create all custom agenda views, for upload to the mobile 
phone."
   (let ((org-agenda-buffer-name "*SUMO*")
        (org-agenda-tag-filter org-agenda-tag-filter)
        (org-agenda-redo-command org-agenda-redo-command))
+    ;; Offer to save agenda-related buffers before pushing, preventing
+    ;; "Non-existent agenda file" prompt for lock files (see #19448).
+    (let ((agenda-buffers (org-buffer-list 'agenda)))
+      (save-some-buffers nil
+                        (lambda () (memq (current-buffer) agenda-buffers))))
     (save-excursion
       (save-restriction
        (save-window-excursion
@@ -656,8 +669,7 @@ The table of checksums is written to the file 
mobile-checksums."
            (org-mobile-escape-olp (nth 4 (org-heading-components))))))
 
 (defun org-mobile-escape-olp (s)
-  (let  ((table '(?: ?/)))
-    (org-link-escape s table)))
+  (org-link-encode s '(?: ?/)))
 
 (defun org-mobile-create-sumo-agenda ()
   "Create a file that contains all custom agenda views."
@@ -869,7 +881,7 @@ If BEG and END are given, only do this in that region."
                (funcall cmd data old new)
                (unless (member data '("delete" "archive" "archive-sibling"
                                       "addheading"))
-                 (when (member "FLAGGED" (org-get-tags))
+                 (when (member "FLAGGED" (org-get-tags nil t))
                    (add-to-list 'org-mobile-last-flagged-files
                                 (buffer-file-name)))))
            (error (setq org-mobile-error msg)))
@@ -951,7 +963,7 @@ is currently a noop.")
        (if (not (string-match "\\`olp:\\(.*?\\)$" link))
            nil
          (let ((file (match-string 1 link)))
-           (setq file (org-link-unescape file))
+           (setq file (org-link-decode file))
            (setq file (expand-file-name file org-directory))
            (save-excursion
              (find-file file)
@@ -961,9 +973,9 @@ is currently a noop.")
              (point-marker))))
       (let ((file (match-string 1 link))
            (path (match-string 2 link)))
-       (setq file (org-link-unescape file))
+       (setq file (org-link-decode file))
        (setq file (expand-file-name file org-directory))
-       (setq path (mapcar 'org-link-unescape
+       (setq path (mapcar #'org-link-decode
                           (org-split-string path "/")))
        (org-find-olp (cons file path))))))
 
@@ -994,7 +1006,7 @@ be returned that indicates what went wrong."
                 old current))))
 
      ((eq what 'tags)
-      (setq current (org-get-tags)
+      (setq current (org-get-tags nil t)
            new1 (and new (org-split-string new ":+"))
            old1 (and old (org-split-string old ":+")))
       (cond
@@ -1002,7 +1014,7 @@ be returned that indicates what went wrong."
        ((or (org-mobile-tags-same-p current old1)
            (eq org-mobile-force-mobile-change t)
            (memq 'tags org-mobile-force-mobile-change))
-       (org-set-tags-to new1) t)
+       (org-set-tags new1) t)
        (t (error "Tags before change were expected as \"%s\", but are \"%s\""
                 (or old "") (or current "")))))
 
@@ -1031,8 +1043,10 @@ be returned that indicates what went wrong."
              (goto-char (match-beginning 4))
              (insert new)
              (delete-region (point) (+ (point) (length current)))
-             (org-set-tags nil 'align))
-            (t (error "Heading changed in MobileOrg and on the computer")))))))
+             (org-align-tags))
+            (t
+             (error
+              "Heading changed in the mobile device and on the computer")))))))
 
      ((eq what 'addheading)
       (if (org-at-heading-p)   ; if false we are in top-level of file
@@ -1085,7 +1099,8 @@ be returned that indicates what went wrong."
                                        (outline-next-heading)
                                        (point))))
        t)
-       (t (error "Body was changed in MobileOrg and on the computer")))))))
+       (t (error
+          "Body was changed in the mobile device and on the computer")))))))
 
 (defun org-mobile-tags-same-p (list1 list2)
   "Are the two tag lists the same?"
diff --git a/lisp/org/org-mouse.el b/lisp/org/org-mouse.el
index a3dcb77..13d88da 100644
--- a/lisp/org/org-mouse.el
+++ b/lisp/org/org-mouse.el
@@ -422,7 +422,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
 (defun org-mouse-tag-menu ()           ;todo
   "Create the tags menu."
   (append
-   (let ((tags (org-get-tags)))
+   (let ((tags (org-get-tags nil t)))
      (org-mouse-keyword-menu
       (sort (mapcar 'car (org-get-buffer-tags)) 'string-lessp)
       `(lambda (tag)
@@ -434,22 +434,12 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
       `(lambda (tag) (member tag (quote ,tags)))
       ))
    '("--"
-     ["Align Tags Here" (org-set-tags nil t) t]
-     ["Align Tags in Buffer" (org-set-tags t t) t]
-     ["Set Tags ..." (org-set-tags) t])))
+     ["Align Tags Here" (org-align-tags) t]
+     ["Align Tags in Buffer" (org-align-tags t) t]
+     ["Set Tags ..." (org-set-tags-command) t])))
 
 (defun org-mouse-set-tags (tags)
-  (save-excursion
-    ;; remove existing tags first
-    (beginning-of-line)
-    (when (org-mouse-re-search-line ":\\(\\([A-Za-z_]+:\\)+\\)")
-      (replace-match ""))
-
-    ;; set new tags if any
-    (when tags
-      (end-of-line)
-      (insert " :" (mapconcat 'identity tags ":") ":")
-      (org-set-tags nil t))))
+  (org-set-tags tags))
 
 (defun org-mouse-insert-checkbox ()
   (interactive)
@@ -498,7 +488,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
    `("Main Menu"
      ["Show Overview" org-mouse-show-overview t]
      ["Show Headlines" org-mouse-show-headlines t]
-     ["Show All" outline-show-all t]
+     ["Show All" org-show-all t]
      ["Remove Highlights" org-remove-occur-highlights
       :visible org-occur-highlights]
      "--"
diff --git a/lisp/org/org-num.el b/lisp/org/org-num.el
new file mode 100644
index 0000000..5604819
--- /dev/null
+++ b/lisp/org/org-num.el
@@ -0,0 +1,469 @@
+;;; org-num.el --- Dynamic Headlines Numbering  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2018-2019  Free Software Foundation, Inc.
+
+;; Author: Nicolas Goaziou <address@hidden>
+;; Keywords: outlines, hypermedia, calendar, wp
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides dynamic numbering for Org headlines.  Use
+;;
+;;     <M-x org-num-mode>
+;;
+;; to toggle it.
+;;
+;; You can select what is numbered according to level, tags, COMMENT
+;; keyword, or UNNUMBERED property. You can also skip footnotes
+;; sections. See `org-num-max-level', `org-num-skip-tags',
+;; `org-num-skip-commented', `org-num-skip-unnumbered', and
+;; `org-num-skip-footnotes' for details.
+;;
+;; You can also control how the numbering is displayed by setting
+;;`org-num-face' and `org-num-format-function'.
+;;
+;; Internally, the library handles an ordered list, per buffer
+;; position, of overlays in `org-num--overlays'.  These overlays are
+;; marked with the `org-num' property set to a non-nil value.
+;;
+;; Overlays store the level of the headline in the `level' property,
+;; and the face used for the numbering in `numbering-face'.
+;;
+;; The `skip' property is set to t when the corresponding headline has
+;; some characteristic -- e.g., a node property, or a tag -- that
+;; prevents it from being numbered.
+;;
+;; An overlay with `org-num' property set to `invalid' is called an
+;; invalid overlay.  Modified overlays automatically become invalid
+;; and set `org-num--invalid-flag' to a non-nil value.  After
+;; a change, `org-num--invalid-flag' indicates numbering needs to be
+;; updated and invalid overlays indicate where the buffer needs to be
+;; parsed.  So does `org-num--missing-overlay' variable.  See
+;; `org-num--verify' function for details.
+;;
+;; Numbering display is done through the `after-string' property.
+
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'org-macs)
+
+(defvar org-comment-string)
+(defvar org-complex-heading-regexp)
+(defvar org-cycle-level-faces)
+(defvar org-footnote-section)
+(defvar org-level-faces)
+(defvar org-n-level-faces)
+(defvar org-odd-levels-only)
+
+(declare-function org-back-to-heading "org" (&optional invisible-ok))
+(declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
+(declare-function org-reduced-level "org" (l))
+
+
+;;; Customization
+
+(defcustom org-num-face nil
+  "Face to use for numbering.
+When nil, use the same face as the headline.  This value is
+ignored if `org-num-format-function' specifies a face for its
+output."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type '(choice (const :tag "Like the headline" nil)
+                 (face :tag "Use face"))
+  :safe (lambda (val) (or (null val) (facep val))))
+
+(defcustom org-num-format-function 'org-num-default-format
+  "Function used to display numbering.
+It is called with one argument, a list of numbers, and should
+return a string, or nil.  When nil, no numbering is displayed.
+Any `face' text property on the returned string overrides
+`org-num-face'."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type 'function
+  :safe nil)
+
+(defcustom org-num-max-level nil
+  "Level below which headlines are not numbered.
+When set to nil, all headlines are numbered."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type '(choice (const :tag "Number everything" nil)
+                 (integer :tag "Stop numbering at level"))
+  :safe (lambda (val) (or (null val) (wholenump val))))
+
+(defcustom org-num-skip-commented nil
+  "Non-nil means commented sub-trees are not numbered."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type 'boolean
+  :safe #'booleanp)
+
+(defcustom org-num-skip-footnotes nil
+  "Non-nil means footnotes sections are not numbered."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type 'boolean
+  :safe #'booleanp)
+
+(defcustom org-num-skip-tags nil
+  "List of tags preventing the numbering of sub-trees.
+
+For example, add \"ARCHIVE\" to this list to avoid numbering
+archived sub-trees.
+
+Tag in this list prevent numbering the whole sub-tree,
+irrespective to `org-use-tags-inheritance', or other means to
+control tag inheritance."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type '(repeat (string :tag "Tag"))
+  :safe (lambda (val) (and (listp val) (cl-every #'stringp val))))
+
+(defcustom org-num-skip-unnumbered nil
+  "Non-nil means numbering obeys to UNNUMBERED property."
+  :group 'org-appearance
+  :package-version '(Org . "9.3")
+  :type 'boolean
+  :safe #'booleanp)
+
+
+;;; Internal Variables
+
+(defconst org-num--comment-re (format "\\`%s\\(?: \\|$\\)" org-comment-string)
+  "Regexp matching a COMMENT keyword at headline beginning.")
+
+(defvar-local org-num--overlays nil
+  "Ordered list of overlays used for numbering outlines.")
+
+(defvar-local org-num--skip-level nil
+  "Level below which headlines from current tree are not numbered.
+When nil, all headlines are numbered.  It is used to handle
+inheritance of no-numbering attributes.")
+
+(defvar-local org-num--numbering nil
+  "Current headline numbering.
+A numbering is a list of integers, in reverse order.  So numbering
+for headline \"1.2.3\" is (3 2 1).")
+
+(defvar-local org-num--missing-overlay nil
+  "Buffer position signaling a headline without an overlay.")
+
+(defvar-local org-num--invalid-flag nil
+  "Non-nil means an overlay became invalid since last update.")
+
+
+;;; Internal Functions
+
+(defsubst org-num--headline-regexp ()
+  "Return regexp matching a numbered headline."
+  (if (null org-num-max-level) (org-with-limited-levels org-outline-regexp-bol)
+    (format "^\\*\\{1,%d\\} "
+            (if org-odd-levels-only (1- (* 2 org-num-max-level))
+              org-num-max-level))))
+
+(defsubst org-num--overlay-p (o)
+  "Non-nil if overlay O is a numbering overlay."
+  (overlay-get o 'org-num))
+
+(defsubst org-num--valid-overlay-p (o)
+  "Non-nil if overlay O is still active in the buffer."
+  (not (eq 'invalid (overlay-get o 'org-num))))
+
+(defsubst org-num--invalidate-overlay (o)
+  "Mark overlay O as invalid.
+Update `org-num--invalid-flag' accordingly."
+  (overlay-put o 'org-num 'invalid)
+  (setq org-num--invalid-flag t))
+
+(defun org-num--clear ()
+  "Remove all numbering overlays in current buffer."
+  (mapc #'delete-overlay org-num--overlays)
+  (setq org-num--overlays nil))
+
+(defun org-num--make-overlay (numbering level skip)
+  "Return overlay for numbering headline at point.
+
+NUMBERING is the numbering to use, as a list of integers, or nil
+if nothing should be displayed.  LEVEL is the level of the
+headline.  SKIP is its skip value.
+
+Assume point is at a headline."
+  (let ((after-edit-functions
+         (list (lambda (o &rest _) (org-num--invalidate-overlay o))))
+        (o (save-excursion
+             (beginning-of-line)
+             (skip-chars-forward "*")
+             (make-overlay (line-beginning-position) (1+ (point))))))
+    (overlay-put o 'org-num t)
+    (overlay-put o 'skip skip)
+    (overlay-put o 'level level)
+    (overlay-put o 'numbering-face
+                 (or org-num-face
+                     ;; Compute face that would be used at the
+                     ;; headline.  We cannot extract it from the
+                     ;; buffer: at the time the overlay is created,
+                     ;; Font Lock has not proceeded yet.
+                     (nth (if org-cycle-level-faces
+                              (% (1- level) org-n-level-faces)
+                            (1- (min level org-n-level-faces)))
+                          org-level-faces)))
+    (overlay-put o 'modification-hooks after-edit-functions)
+    (overlay-put o 'insert-in-front-hooks after-edit-functions)
+    (org-num--refresh-display o numbering)
+    o))
+
+(defun org-num--refresh-display (overlay numbering)
+  "Refresh OVERLAY's display.
+NUMBERING specifies the new numbering, as a list of integers, or
+nil if nothing should be displayed.  Assume OVERLAY is valid."
+  (let ((display (and numbering
+                      (funcall org-num-format-function (reverse numbering)))))
+    (when (and display (not (get-text-property 0 'face display)))
+      (org-add-props display `(face ,(overlay-get overlay 'numbering-face))))
+    (overlay-put overlay 'after-string display)))
+
+(defun org-num--skip-value ()
+  "Return skip value for headline at point.
+Value is t when headline should not be numbered, and nil
+otherwise."
+  (org-match-line org-complex-heading-regexp)
+  (let ((title (match-string 4))
+        (tags (and org-num-skip-tags
+                   (match-end 5)
+                   (org-split-string (match-string 5) ":"))))
+    (or (and org-num-skip-footnotes
+             org-footnote-section
+             (equal title org-footnote-section))
+        (and org-num-skip-commented
+             (let ((case-fold-search nil))
+               (string-match org-num--comment-re title))
+             t)
+        (and org-num-skip-tags
+             (cl-some (lambda (tag) (member tag org-num-skip-tags))
+                      tags)
+             t)
+        (and org-num-skip-unnumbered
+             (org-entry-get (point) "UNNUMBERED")
+             t))))
+
+(defun org-num--current-numbering (level skip)
+  "Return numbering for current headline.
+LEVEL is headline's level, and SKIP its skip value.  Return nil
+if headline should be skipped."
+  (cond
+   ;; Skipped by inheritance.
+   ((and org-num--skip-level (> level org-num--skip-level)) nil)
+   ;; Skipped by a non-nil skip value; set `org-num--skip-level'
+   ;; to skip the whole sub-tree later on.
+   (skip (setq org-num--skip-level level) nil)
+   (t
+    (setq org-num--skip-level nil)
+    ;; Compute next numbering, and update `org-num--numbering'.
+    (let ((last-level (length org-num--numbering)))
+      (setq org-num--numbering
+            (cond
+             ;; First headline : nil => (1), or (1 0)...
+             ((null org-num--numbering) (cons 1 (make-list (1- level) 0)))
+             ;; Sibling: (1 1) => (2 1).
+             ((= level last-level)
+              (cons (1+ (car org-num--numbering)) (cdr org-num--numbering)))
+             ;; Parent: (1 1 1) => (2 1), or (2).
+             ((< level last-level)
+              (let ((suffix (nthcdr (- last-level level) org-num--numbering)))
+                (cons (1+ (car suffix)) (cdr suffix))))
+             ;; Child: (1 1) => (1 1 1), or (1 0 1 1)...
+             (t
+              (append (cons 1 (make-list (- level last-level 1) 0))
+                      org-num--numbering))))))))
+
+(defun org-num--number-region (start end)
+  "Add numbering overlays between START and END positions.
+When START or END are nil, use buffer boundaries.  Narrowing, if
+any, is ignored.  Return the list of created overlays, newest
+first."
+  (org-with-point-at (or start 1)
+    ;; Do not match headline starting at START.
+    (when start (end-of-line))
+    (let ((regexp (org-num--headline-regexp))
+          (new nil))
+      (while (re-search-forward regexp end t)
+        (let* ((level (org-reduced-level
+                       (- (match-end 0) (match-beginning 0) 1)))
+               (skip (org-num--skip-value))
+               (numbering (org-num--current-numbering level skip)))
+          ;; Apply numbering to current headline.  Store overlay for
+          ;; the return value.
+          (push (org-num--make-overlay numbering level skip)
+                new)))
+      new)))
+
+(defun org-num--update ()
+  "Update buffer's numbering.
+This function removes invalid overlays and refreshes numbering
+for the valid ones in the numbering overlays list.  It also adds
+missing overlays to that list."
+  (setq org-num--skip-level nil)
+  (setq org-num--numbering nil)
+  (let ((new-overlays nil)
+        (overlay nil))
+    (while (setq overlay (pop org-num--overlays))
+      (cond
+       ;; Valid overlay.
+       ;;
+       ;; First handle possible missing overlays OVERLAY.  If missing
+       ;; overlay marker is pointing before next overlay and after the
+       ;; last known overlay, make sure to parse the buffer between
+       ;; these two overlays.
+       ((org-num--valid-overlay-p overlay)
+        (let ((next (overlay-start overlay))
+              (last (and new-overlays (overlay-start (car new-overlays)))))
+          (cond
+           ((null org-num--missing-overlay))
+           ((> org-num--missing-overlay next))
+           ((or (null last) (> org-num--missing-overlay last))
+            (setq org-num--missing-overlay nil)
+            (setq new-overlays (nconc (org-num--number-region last next)
+                                      new-overlays)))
+           ;; If it is already after the last known overlay, reset it:
+           ;; some previous invalid overlay already triggered the
+           ;; necessary parsing.
+           (t
+            (setq org-num--missing-overlay nil))))
+        ;; Update OVERLAY's numbering.
+        (let* ((level (overlay-get overlay 'level))
+               (skip (overlay-get overlay 'skip))
+               (numbering (org-num--current-numbering level skip)))
+          (org-num--refresh-display overlay numbering)
+          (push overlay new-overlays)))
+       ;; Invalid overlay.  It indicates that the buffer needs to be
+       ;; parsed again between the two surrounding valid overlays or
+       ;; buffer boundaries.
+       (t
+        ;; Delete all consecutive invalid overlays: we re-create all
+        ;; overlays between last valid overlay and the next one.
+        (delete-overlay overlay)
+        (while (and org-num--overlays
+                    (not (org-num--valid-overlay-p (car org-num--overlays))))
+          (delete-overlay (pop org-num--overlays)))
+        ;; Create and register new overlays.
+        (let ((last (and new-overlays (overlay-start (car new-overlays))))
+              (next (and org-num--overlays
+                         (overlay-start (car org-num--overlays)))))
+          (setq new-overlays (nconc (org-num--number-region last next)
+                                    new-overlays))))))
+    ;; If invalid position hasn't been handled yet, it must be located
+    ;; between last valid overlay and end of the buffer.  Parse that
+    ;; area before returning.
+    (when org-num--missing-overlay
+      (let ((last (and new-overlays (overlay-start (car new-overlays)))))
+        (setq new-overlays (nconc (org-num--number-region last nil)
+                                  new-overlays))))
+    ;; Numbering is now up-to-date.  Reset invalid flag.  Also return
+    ;; `org-num--overlays' in a sorted fashion.
+    (setq org-num--invalid-flag nil)
+    (setq org-num--overlays (nreverse new-overlays))))
+
+(defun org-num--verify (beg end _)
+  "Check numbering integrity; update it if necessary.
+This function is meant to be used in `after-change-functions'.
+See this variable for the meaning of BEG and END."
+  (setq org-num--missing-overlay nil)
+  (save-match-data
+    (org-with-point-at beg
+      (let ((regexp (org-num--headline-regexp)))
+        ;; At this point, directly altered overlays between BEG and
+        ;; END are marked as invalid and will trigger a full update.
+        ;; However, there are still two cases to handle.
+        ;;
+        ;; First, some valid overlays may need to be invalidated, due
+        ;; to an indirect change.  That happens when the skip value --
+        ;; see `org-num--skip-value' -- of the heading BEG belongs to
+        ;; is altered, or when deleting the newline character right
+        ;; before the next headline.
+        (save-excursion
+          ;; Bail out if we're before first headline or within
+          ;; a headline too deep to be numbered.
+          (when (and (org-with-limited-levels
+                      (ignore-errors (org-back-to-heading t)))
+                     (looking-at regexp))
+            (pcase (get-char-property-and-overlay (point) 'org-num)
+              (`(nil)
+               ;; At a headline, without a numbering overlay: change
+               ;; just created one.  Mark it for parsing.
+               (setq org-num--missing-overlay (point)))
+              (`(t . ,o)
+               ;; Check if skip value changed.  Invalidate overlay
+               ;; accordingly.
+               (unless (eq (org-num--skip-value) (overlay-get o 'skip))
+                 (org-num--invalidate-overlay o)))
+              (_ nil))))
+        ;; Deleting the newline character before a numbering overlay
+        ;; doesn't invalidate it, even though it could land in the
+        ;; middle of a line.  Be sure to catch this case.
+        (when (and (= beg end) (not (bolp)))
+          (pcase (get-char-property-and-overlay (point) 'org-num)
+            (`(t . ,o) (org-num--invalidate-overlay o))
+            (_ nil)))
+        ;; Second, if nothing is marked as invalid, and therefore if
+        ;; no full update is due so far, changes may still have
+        ;; created new headlines, at BEG -- which is actually handled
+        ;; by the previous phase --, or, in case of a multi-line
+        ;; insertion, at END, or in-between.
+        (unless (or org-num--invalid-flag
+                    org-num--missing-overlay
+                    (<= end (line-end-position))) ;single line change
+          (forward-line)
+          (when (or (re-search-forward regexp end 'move)
+                    ;; Check if change created a headline after END.
+                    (progn (skip-chars-backward "*") (looking-at regexp)))
+            (setq org-num--missing-overlay (line-beginning-position))))))
+    ;; Update numbering only if a headline was altered or created.
+    (when (or org-num--missing-overlay org-num--invalid-flag)
+      (org-num--update))))
+
+
+;;; Public Functions
+
+;;;###autoload
+(defun org-num-default-format (numbering)
+  "Default numbering display function.
+NUMBERING is a list of numbers."
+  (concat (mapconcat #'number-to-string numbering ".") " "))
+
+;;;###autoload
+(define-minor-mode org-num-mode
+  "Dynamic numbering of headlines in an Org buffer."
+  :lighter " o#"
+  (cond
+   (org-num-mode
+    (unless (derived-mode-p 'org-mode)
+      (user-error "Cannot activate headline numbering outside Org mode"))
+    (setq org-num--numbering nil)
+    (setq org-num--overlays (nreverse (org-num--number-region nil nil)))
+    (add-hook 'after-change-functions #'org-num--verify nil t)
+    (add-hook 'change-major-mode-hook #'org-num--clear nil t))
+   (t
+    (org-num--clear)
+    (remove-hook 'after-change-functions #'org-num--verify t)
+    (remove-hook 'change-major-mode-hook #'org-num--clear t))))
+
+
+(provide 'org-num)
+;;; org-num.el ends here
diff --git a/lisp/org/org-pcomplete.el b/lisp/org/org-pcomplete.el
index cf272de..e557b1a 100644
--- a/lisp/org/org-pcomplete.el
+++ b/lisp/org/org-pcomplete.el
@@ -31,70 +31,126 @@
 (require 'org-compat)
 (require 'pcomplete)
 
-(declare-function org-make-org-heading-search-string "org" (&optional string))
-(declare-function org-get-buffer-tags "org" ())
-(declare-function org-get-tags "org" ())
-(declare-function org-buffer-property-keys "org"
-                 (&optional specials defaults columns ignore-malformed))
+(declare-function org-at-heading-p "org" (&optional ignored))
+(declare-function org-before-first-heading-p "org" ())
+(declare-function org-buffer-property-keys "org" (&optional specials defaults 
columns))
+(declare-function org-element-at-point "org-element" ())
+(declare-function org-element-property "org-element" property element)
+(declare-function org-element-type "org-element" (element))
+(declare-function org-end-of-meta-data "org" (&optional full))
 (declare-function org-entry-properties "org" (&optional pom which))
+(declare-function org-export-backend-options "ox" (cl-x) t)
+(declare-function org-get-buffer-tags "org" ())
+(declare-function org-get-export-keywords "org" ())
+(declare-function org-get-heading "org" (&optional no-tags no-todo no-priority 
no-comment))
+(declare-function org-get-tags "org" (&optional pos local))
+(declare-function org-link-heading-search-string "ol" (&optional string))
 (declare-function org-tag-alist-to-string "org" (alist &optional skip-key))
 
-;;;; Customization variables
-
+(defvar org-current-tag-alist)
+(defvar org-default-priority)
 (defvar org-drawer-regexp)
+(defvar org-element-affiliated-keywords)
+(defvar org-entities)
+(defvar org-export-default-language)
+(defvar org-export-exclude-tags)
+(defvar org-export-select-tags)
+(defvar org-file-tags)
+(defvar org-highest-priority)
+(defvar org-link-abbrev-alist)
+(defvar org-link-abbrev-alist-local)
+(defvar org-lowest-priority)
+(defvar org-options-keywords)
+(defvar org-outline-regexp)
 (defvar org-property-re)
-(defvar org-current-tag-alist)
+(defvar org-startup-options)
+(defvar org-tag-re)
+(defvar org-time-stamp-formats)
+(defvar org-todo-keywords-1)
+(defvar org-todo-line-regexp)
+
+
+;;; Internal Functions
 
 (defun org-thing-at-point ()
   "Examine the thing at point and let the caller know what it is.
 The return value is a string naming the thing at point."
-  (let ((beg1 (save-excursion
-               (skip-chars-backward "-[:alnum:]_@")
-               (point)))
-       (beg (save-excursion
-              (skip-chars-backward "-a-zA-Z0-9_:$")
-              (point)))
-       (line-to-here (buffer-substring (point-at-bol) (point))))
+  (let ((line-to-here (org-current-line-string t))
+       (case-fold-search t))
     (cond
-     ((string-match "\\`[ \t]*#\\+begin: clocktable[ \t]+" line-to-here)
+     ;; Parameters on a clock table opening line.
+     ((org-match-line "[ \t]*#\\+BEGIN: clocktable[ \t]")
       (cons "block-option" "clocktable"))
-     ((string-match "\\`[ \t]*#\\+begin_src[ \t]+" line-to-here)
+     ;; Flags and parameters on a source block opening line.
+     ((org-match-line "[ \t]*#\\+BEGIN_SRC[ \t]")
       (cons "block-option" "src"))
-     ((save-excursion
-       (re-search-backward "^[ \t]*#\\+\\([A-Z_]+\\):.*"
-                           (line-beginning-position) t))
+     ;; Value for a known keyword.
+     ((org-match-line "[ \t]*#\\+\\(\\S-+\\):")
       (cons "file-option" (match-string-no-properties 1)))
-     ((string-match "\\`[ \t]*#\\+[a-zA-Z_]*\\'" line-to-here)
+     ;; Keyword name.
+     ((and (org-match-line "[ \t]*#\\+[a-zA-Z_]*$")
+          (looking-at-p "[ \t]*$"))
       (cons "file-option" nil))
-     ((equal (char-before beg) ?\[)
+     ;; Link abbreviation.
+     ((save-excursion
+       (skip-chars-backward "-A-Za-z0-9_")
+       (and (eq ?\[ (char-before))
+            (eq ?\[ (char-before (1- (point))))))
       (cons "link" nil))
-     ((equal (char-before beg) ?\\)
+     ;; Entities.  Some of them accept numbers, but only at their end.
+     ;; So, we first skip numbers, then letters.
+     ((eq ?\\ (save-excursion
+               (skip-chars-backward "0-9")
+               (skip-chars-backward "a-zA-Z")
+               (char-before)))
       (cons "tex" nil))
-     ((string-match "\\`\\*+[ \t]+\\'"
-                   (buffer-substring (point-at-bol) beg))
+     ;; Tags on a headline.
+     ((and (org-match-line
+           (format "\\*+ \\(?:.+? \\)?\\(:\\)\\(\\(?::\\|%s\\)+\\)?[ \t]*$"
+                   org-tag-re))
+          (or (org-point-in-group (point) 2)
+              (= (point) (match-end 1))))
+      (cons "tag" nil))
+     ;; TODO keywords on an empty headline.
+     ((and (string-match "^\\*+ +\\S-*$" line-to-here)
+          (looking-at-p "[ \t]*$"))
       (cons "todo" nil))
-     ((equal (char-before beg) ?*)
+     ;; Heading after a star for search strings or links.
+     ((save-excursion
+       (skip-chars-backward "^*" (line-beginning-position))
+       (and (eq ?* (char-before))
+            (eq (char-before (1- (point))) '?\[)
+            (eq (char-before (- (point) 2)) '?\[)))
       (cons "searchhead" nil))
-     ((and (equal (char-before beg1) ?:)
-          (equal (char-after (point-at-bol)) ?*))
-      (cons "tag" nil))
-     ((and (equal (char-before beg1) ?:)
-          (not (equal (char-after (point-at-bol)) ?*))
-          (save-excursion
-            (move-beginning-of-line 1)
-            (skip-chars-backward " \t\n")
-            ;; org-drawer-regexp matches a whole line but while
-            ;; looking-back, we just ignore trailing whitespaces
-            (or (looking-back (substring org-drawer-regexp 0 -1)
-                              (line-beginning-position))
-                (looking-back org-property-re
-                              (line-beginning-position)))))
-      (cons "prop" nil))
-     ((and (equal (char-before beg1) ?:)
-          (not (equal (char-after (point-at-bol)) ?*)))
-      (cons "drawer" nil))
+     ;; Property or drawer name, depending on point.  If point is at
+     ;; a valid location for a node property, offer completion on all
+     ;; node properties in the buffer. Otherwise, offer completion on
+     ;; all drawer names, including "PROPERTIES".
+     ((and (string-match "^[ \t]*:\\S-*$" line-to-here)
+          (looking-at-p "[ \t]*$"))
+      (let ((origin (line-beginning-position)))
+       (if (org-before-first-heading-p) (cons "drawer" nil)
+         (save-excursion
+           (org-end-of-meta-data)
+           (if (or (= origin (point))
+                   (not (org-match-line "[ \t]*:PROPERTIES:[ \t]*$")))
+               (cons "drawer" nil)
+             (while (org-match-line org-property-re)
+               (forward-line))
+             (if (= origin (point)) (cons "prop" nil)
+               (cons "drawer" nil)))))))
      (t nil))))
 
+(defun org-pcomplete-case-double (list)
+  "Return list with both upcase and downcase version of all strings in LIST."
+  (let (e res)
+    (while (setq e (pop list))
+      (setq res (cons (downcase e) (cons (upcase e) res))))
+    (nreverse res)))
+
+
+;;; Completion API
+
 (defun org-command-at-point ()
   "Return the qualified name of the Org completion entity at point.
 When completing for #+STARTUP, for example, this function returns
@@ -133,9 +189,9 @@ When completing for #+STARTUP, for example, this function 
returns
                 (car (org-thing-at-point)))
                pcomplete-default-completion-function))))
 
-(defvar org-options-keywords)           ; From org.el
-(defvar org-element-affiliated-keywords) ; From org-element.el
-(declare-function org-get-export-keywords "org" ())
+
+;;; Completion functions
+
 (defun pcomplete/org-mode/file-option ()
   "Complete against all valid file options."
   (require 'org-element)
@@ -167,7 +223,6 @@ When completing for #+STARTUP, for example, this function 
returns
   "Complete arguments for the #+AUTHOR file option."
   (pcomplete-here (list user-full-name)))
 
-(defvar org-time-stamp-formats)
 (defun pcomplete/org-mode/file-option/date ()
   "Complete arguments for the #+DATE file option."
   (pcomplete-here (list (format-time-string (car org-time-stamp-formats)))))
@@ -176,7 +231,6 @@ When completing for #+STARTUP, for example, this function 
returns
   "Complete arguments for the #+EMAIL file option."
   (pcomplete-here (list user-mail-address)))
 
-(defvar org-export-exclude-tags)
 (defun pcomplete/org-mode/file-option/exclude_tags ()
   "Complete arguments for the #+EXCLUDE_TAGS file option."
   (require 'ox)
@@ -184,12 +238,10 @@ When completing for #+STARTUP, for example, this function 
returns
    (and org-export-exclude-tags
        (list (mapconcat 'identity org-export-exclude-tags " ")))))
 
-(defvar org-file-tags)
 (defun pcomplete/org-mode/file-option/filetags ()
   "Complete arguments for the #+FILETAGS file option."
   (pcomplete-here (and org-file-tags (mapconcat 'identity org-file-tags " "))))
 
-(defvar org-export-default-language)
 (defun pcomplete/org-mode/file-option/language ()
   "Complete arguments for the #+LANGUAGE file option."
   (require 'ox)
@@ -197,9 +249,6 @@ When completing for #+STARTUP, for example, this function 
returns
    (pcomplete-uniquify-list
     (list org-export-default-language "en"))))
 
-(defvar org-default-priority)
-(defvar org-highest-priority)
-(defvar org-lowest-priority)
 (defun pcomplete/org-mode/file-option/priorities ()
   "Complete arguments for the #+PRIORITIES file option."
   (pcomplete-here (list (format "%c %c %c"
@@ -207,7 +256,6 @@ When completing for #+STARTUP, for example, this function 
returns
                                org-lowest-priority
                                org-default-priority))))
 
-(defvar org-export-select-tags)
 (defun pcomplete/org-mode/file-option/select_tags ()
   "Complete arguments for the #+SELECT_TAGS file option."
   (require 'ox)
@@ -215,7 +263,6 @@ When completing for #+STARTUP, for example, this function 
returns
    (and org-export-select-tags
        (list (mapconcat 'identity org-export-select-tags " ")))))
 
-(defvar org-startup-options)
 (defun pcomplete/org-mode/file-option/startup ()
   "Complete arguments for the #+STARTUP file option."
   (while (pcomplete-here
@@ -244,7 +291,6 @@ When completing for #+STARTUP, for example, this function 
returns
               (buffer-name (buffer-base-buffer)))))))
 
 
-(declare-function org-export-backend-options "ox" (cl-x) t)
 (defun pcomplete/org-mode/file-option/options ()
   "Complete arguments for the #+OPTIONS file option."
   (while (pcomplete-here
@@ -275,20 +321,18 @@ When completing for #+STARTUP, for example, this function 
returns
   "Complete arguments for the #+BIND file option, which are variable names."
   (let (vars)
     (mapatoms
-     (lambda (a) (if (boundp a) (setq vars (cons (symbol-name a) vars)))))
+     (lambda (a) (when (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-uniquify-list
     (copy-sequence
-     (append (mapcar 'car org-link-abbrev-alist-local)
-            (mapcar 'car org-link-abbrev-alist))))))
+     (mapcar (lambda (e) (concat (car e) ":"))
+            (append org-link-abbrev-alist-local
+                    org-link-abbrev-alist))))))
 
-(defvar org-entities)
 (defun pcomplete/org-mode/tex ()
   "Complete against TeX-style HTML entity names."
   (require 'org-entities)
@@ -296,27 +340,24 @@ When completing for #+STARTUP, for example, this function 
returns
          (pcomplete-uniquify-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-uniquify-list (copy-sequence 
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."
-  (while
-      (pcomplete-here
-       (save-excursion
-        (goto-char (point-min))
-        (let (tbl)
-          (let ((case-fold-search nil))
-            (while (re-search-forward org-todo-line-regexp nil t)
-              (push (org-make-org-heading-search-string
-                     (match-string-no-properties 3))
-                    tbl)))
-          (pcomplete-uniquify-list tbl)))
-       (substring pcomplete-stub 1))))
+  (while (pcomplete-here
+         (save-excursion
+           (goto-char (point-min))
+           (let (tbl)
+             (while (re-search-forward org-outline-regexp nil t)
+               (push (org-link-heading-search-string (org-get-heading t t t t))
+                     tbl))
+             (pcomplete-uniquify-list tbl)))
+         ;; When completing a bracketed link, i.e., "[[*", argument
+         ;; starts at the star, so remove this character.
+         (substring pcomplete-stub 1))))
 
 (defun pcomplete/org-mode/tag ()
   "Complete a tag name.  Omit tags already set."
@@ -328,28 +369,47 @@ This needs more work, to handle headings with lots of 
spaces in them."
                                   (mapcar (lambda (x) (org-string-nw-p (car 
x)))
                                           org-current-tag-alist))
                                  (mapcar #'car (org-get-buffer-tags))))))
-                   (dolist (tag (org-get-tags))
+                   (dolist (tag (org-get-tags nil t))
                      (setq lst (delete tag lst)))
                    lst))
          (and (string-match ".*:" pcomplete-stub)
-              (substring pcomplete-stub (match-end 0))))))
+              (substring pcomplete-stub (match-end 0)))
+         t)))
+
+(defun pcomplete/org-mode/drawer ()
+  "Complete a drawer name, including \"PROPERTIES\"."
+  (pcomplete-here
+   (org-pcomplete-case-double
+    (mapcar (lambda (x) (concat x ":"))
+           (let ((names (list "PROPERTIES")))
+             (save-excursion
+               (goto-char (point-min))
+               (while (re-search-forward org-drawer-regexp nil t)
+                 (let ((drawer (org-element-at-point)))
+                   (when (memq (org-element-type drawer)
+                               '(drawer property-drawer))
+                     (push (org-element-property :drawer-name drawer) names)
+                     (goto-char (org-element-property :end drawer))))))
+             (pcomplete-uniquify-list names))))
+   (substring pcomplete-stub 1)))      ;remove initial colon
 
 (defun pcomplete/org-mode/prop ()
   "Complete a property name.  Omit properties already set."
   (pcomplete-here
-   (mapcar (lambda (x)
-            (concat x ": "))
-          (let ((lst (pcomplete-uniquify-list
-                      (copy-sequence
-                       (org-buffer-property-keys nil t t t)))))
-            (dolist (prop (org-entry-properties))
-              (setq lst (delete (car prop) lst)))
-            lst))
+   (org-pcomplete-case-double
+    (mapcar (lambda (x)
+             (concat x ": "))
+           (let ((lst (pcomplete-uniquify-list
+                       (copy-sequence (org-buffer-property-keys nil t t)))))
+             (dolist (prop (org-entry-properties))
+               (setq lst (delete (car prop) lst)))
+             lst)))
    (substring pcomplete-stub 1)))
 
 (defun pcomplete/org-mode/block-option/src ()
-  "Complete the arguments of a begin_src block.
-Complete a language in the first field, the header arguments and switches."
+  "Complete the arguments of a source block.
+Complete a language in the first field, the header arguments and
+switches."
   (pcomplete-here
    (mapcar
     (lambda(x) (symbol-name (nth 3 x)))
@@ -369,17 +429,12 @@ Complete a language in the first field, the header 
arguments and switches."
                           ":tstart" ":tend" ":block" ":step"
                           ":stepskip0" ":fileskip0"
                           ":emphasize" ":link" ":narrow" ":indent"
-                          ":tcolumns" ":level" ":compact" ":timestamp"
-                          ":formula" ":formatter" ":wstart" ":mstart"))))
-
-(defun org-pcomplete-case-double (list)
-  "Return list with both upcase and downcase version of all strings in LIST."
-  (let (e res)
-    (while (setq e (pop list))
-      (setq res (cons (downcase e) (cons (upcase e) res))))
-    (nreverse res)))
+                          ":hidefiles" ":tcolumns" ":level" ":compact"
+                          ":timestamp" ":formula" ":formatter"
+                          ":wstart" ":mstart"))))
 
-;;;; Finish up
+
+;;; Finish up
 
 (provide 'org-pcomplete)
 
diff --git a/lisp/org/org-plot.el b/lisp/org/org-plot.el
index a5635e3..4e84dbe 100644
--- a/lisp/org/org-plot.el
+++ b/lisp/org/org-plot.el
@@ -131,7 +131,7 @@ Pass PARAMS through to `orgtbl-to-generic' when exporting 
TABLE."
   "Export the data in TABLE to DATA-FILE for gnuplot.
 This means in a format appropriate for grid plotting by gnuplot.
 PARAMS specifies which columns of TABLE should be plotted as independent
-and dependant variables."
+and dependent variables."
   (interactive)
   (let* ((ind (- (plist-get params :ind) 1))
         (deps (if (plist-member params :deps)
diff --git a/lisp/org/org-protocol.el b/lisp/org/org-protocol.el
index 016105e..44c6abb 100644
--- a/lisp/org/org-protocol.el
+++ b/lisp/org/org-protocol.el
@@ -116,12 +116,14 @@
 ;;; Code:
 
 (require 'org)
+(require 'ol)
 
 (declare-function org-publish-get-project-from-filename "ox-publish"
                  (filename &optional up))
 (declare-function server-edit "server" (&optional arg))
 
 (defvar org-capture-link-is-already-stored)
+(defvar org-capture-templates)
 
 (defgroup org-protocol nil
   "Intercept calls from emacsclient to trigger custom actions.
@@ -297,11 +299,9 @@ SEPARATOR is specified or SEPARATOR is nil, assume \"/+\". 
 The
 results of that splitting are returned as a list."
   (let* ((sep (or separator "/+\\|\\?"))
          (split-parts (split-string data sep)))
-    (if unhexify
-       (if (fboundp unhexify)
-           (mapcar unhexify split-parts)
-         (mapcar 'org-link-unescape split-parts))
-      split-parts)))
+    (cond ((not unhexify) split-parts)
+         ((fboundp unhexify) (mapcar unhexify split-parts))
+         (t (mapcar #'org-link-decode split-parts)))))
 
 (defun org-protocol-flatten-greedy (param-list &optional strip-path 
replacement)
   "Transform PARAM-LIST into a flat list for greedy handlers.
@@ -381,11 +381,8 @@ If INFO is already a property list, return it unchanged."
              result)
          (while data
            (setq result
-                 (append
-                  result
-                  (list
-                   (pop data)
-                   (org-link-unescape (pop data))))))
+                 (append result
+                         (list (pop data) (org-link-decode (pop data))))))
          result)
       (let ((data (org-protocol-split-data info t 
org-protocol-data-separator)))
        (if default-order
@@ -444,9 +441,9 @@ form URL/TITLE can also be used."
     (when (boundp 'org-stored-links)
       (push (list uri title) org-stored-links))
     (kill-new uri)
-    (message "`%s' to insert new org-link, `%s' to insert `%s'"
-             (substitute-command-keys "`\\[org-insert-link]'")
-             (substitute-command-keys "`\\[yank]'")
+    (message "`%s' to insert new Org link, `%s' to insert %S"
+             (substitute-command-keys "\\[org-insert-link]")
+             (substitute-command-keys "\\[yank]")
              uri))
   nil)
 
@@ -471,51 +468,53 @@ You may specify the template with a template= query 
parameter, like this:
   javascript:location.href = \\='org-protocol://capture?template=b\\='+ ...
 
 Now template ?b will be used."
-  (if (and (boundp 'org-stored-links)
-          (org-protocol-do-capture info))
-      (message "Item captured."))
-  nil)
-
-(defun org-protocol-convert-query-to-plist (query)
-  "Convert QUERY key=value pairs in the URL to a property list."
-  (if query
-      (apply 'append (mapcar (lambda (x)
-                              (let ((c (split-string x "=")))
-                                (list (intern (concat ":" (car c))) (cadr c))))
-                            (split-string query "&")))))
-
-(defun org-protocol-do-capture (info)
-  "Perform the actual capture based on INFO."
-  (let* ((temp-parts (org-protocol-parse-parameters info))
-        (parts
-         (cond
-          ((and (listp info) (symbolp (car info))) info)
-          ((= (length (car temp-parts)) 1) ;; First parameter is exactly one 
character long
-           (org-protocol-assign-parameters temp-parts '(:template :url :title 
:body)))
-          (t
-           (org-protocol-assign-parameters temp-parts '(:url :title :body)))))
+  (let* ((parts
+         (pcase (org-protocol-parse-parameters info)
+           ;; New style links are parsed as a plist.
+           ((let `(,(pred keywordp) . ,_) info) info)
+           ;; Old style links, with or without template key, are
+           ;; parsed as a list of strings.
+           (p
+            (let ((k (if (= 1 (length (car p)))
+                         '(:template :url :title :body)
+                       '(:url :title :body))))
+              (org-protocol-assign-parameters p k)))))
         (template (or (plist-get parts :template)
                       org-protocol-default-template-key))
-        (url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get 
parts :url))))
-        (type (and url (if (string-match "^\\([a-z]+\\):" url)
-                           (match-string 1 url))))
+        (url (and (plist-get parts :url)
+                  (org-protocol-sanitize-uri (plist-get parts :url))))
+        (type (and url
+                   (string-match "^\\([a-z]+\\):" url)
+                   (match-string 1 url)))
         (title (or (plist-get parts :title) ""))
         (region (or (plist-get parts :body) ""))
-        (orglink (if url
-                     (org-make-link-string
-                      url (if (string-match "[^[:space:]]" title) title url))
-                   title))
-        (org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
-    (setq org-stored-links
-         (cons (list url title) org-stored-links))
-    (org-store-link-props :type type
+        (orglink
+         (if (null url) title
+           (org-link-make-string url (or (org-string-nw-p title) url))))
+        ;; Avoid call to `org-store-link'.
+        (org-capture-link-is-already-stored t))
+    ;; Only store link if there's a URL to insert later on.
+    (when url (push (list url title) org-stored-links))
+    (org-link-store-props :type type
                          :link url
                          :description title
                          :annotation orglink
                          :initial region
                          :query parts)
     (raise-frame)
-    (funcall 'org-capture nil template)))
+    (org-capture nil template)
+    (message "Item captured.")
+    ;; Make sure we do not return a string, as `server-visit-files',
+    ;; through `server-edit', would interpret it as a file name.
+    nil))
+
+(defun org-protocol-convert-query-to-plist (query)
+  "Convert QUERY key=value pairs in the URL to a property list."
+  (when query
+    (apply 'append (mapcar (lambda (x)
+                            (let ((c (split-string x "=")))
+                              (list (intern (concat ":" (car c))) (cadr c))))
+                          (split-string query "&")))))
 
 (defun org-protocol-open-source (fname)
   "Process an org-protocol://open-source?url= style URL with FNAME.
diff --git a/lisp/org/org-src.el b/lisp/org/org-src.el
index d8f2cef..5e50a1b 100644
--- a/lisp/org/org-src.el
+++ b/lisp/org/org-src.el
@@ -32,13 +32,11 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'ob-comint)
 (require 'org-macs)
 (require 'org-compat)
-(require 'ob-keys)
-(require 'ob-comint)
+(require 'org-keys)
 
-(declare-function org-base-buffer "org" (buffer))
-(declare-function org-do-remove-indentation "org" (&optional n))
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-class "org-element" (datum &optional parent))
 (declare-function org-element-context "org-element" (&optional element))
@@ -48,9 +46,6 @@
 (declare-function org-element-type "org-element" (element))
 (declare-function org-footnote-goto-definition "org-footnote"
                  (label &optional location))
-(declare-function org-get-indentation "org" (&optional line))
-(declare-function org-switch-to-buffer-other-window "org" (&rest args))
-(declare-function org-trim "org" (s &optional keep-lead))
 
 (defvar org-inhibit-startup)
 
@@ -128,7 +123,8 @@ editing it with `\\[org-edit-src-code]'.
 
 It has no effect if `org-src-preserve-indentation' is non-nil."
   :group 'org-edit-structure
-  :type 'integer)
+  :type 'integer
+  :safe #'wholenump)
 
 (defcustom org-edit-src-persistent-message t
   "Non-nil means show persistent exit help message while editing src examples.
@@ -152,17 +148,23 @@ the existing edit buffer."
   "How the source code edit buffer should be displayed.
 Possible values for this option are:
 
-current-window    Show edit buffer in the current window, keeping all other
-                  windows.
-other-window      Use `switch-to-buffer-other-window' to display edit buffer.
-reorganize-frame  Show only two windows on the current frame, the current
-                  window and the edit buffer.  When exiting the edit buffer,
-                  return to one window.
-other-frame       Use `switch-to-buffer-other-frame' to display edit buffer.
-                  Also, when exiting the edit buffer, kill that frame."
+current-window     Show edit buffer in the current window, keeping all other
+                   windows.
+split-window-below Show edit buffer below the current window, keeping all
+                   other windows.
+split-window-right Show edit buffer to the right of the current window,
+                   keeping all other windows.
+other-window       Use `switch-to-buffer-other-window' to display edit buffer.
+reorganize-frame   Show only two windows on the current frame, the current
+                   window and the edit buffer.  When exiting the edit buffer,
+                   return to one window.
+other-frame        Use `switch-to-buffer-other-frame' to display edit buffer.
+                   Also, when exiting the edit buffer, kill that frame."
   :group 'org-edit-structure
   :type '(choice
          (const current-window)
+         (const split-window-below)
+         (const split-window-right)
          (const other-frame)
          (const other-window)
          (const reorganize-frame)))
@@ -179,17 +181,29 @@ or similar things which you want to have when editing a 
source code file,
 but which mess up the display of a snippet in Org exported files.")
 
 (defcustom org-src-lang-modes
-  '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist)
-    ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql)
-    ("calc" . fundamental) ("C" . c) ("cpp" . c++) ("C++" . c++)
-    ("screen" . shell-script) ("shell" . sh) ("bash" . sh))
+  '(("C" . c)
+    ("C++" . c++)
+    ("asymptote" . asy)
+    ("bash" . sh)
+    ("beamer" . latex)
+    ("calc" . fundamental)
+    ("cpp" . c++)
+    ("ditaa" . artist)
+    ("dot" . fundamental)
+    ("elisp" . emacs-lisp)
+    ("ocaml" . tuareg)
+    ("screen" . shell-script)
+    ("shell" . sh)
+    ("sqlite" . sql))
   "Alist mapping languages to their major mode.
-The key is the language name, the value is the string that should
-be inserted as the name of the major mode.  For many languages this is
-simple, but for language where this is not the case, this variable
-provides a way to simplify things on the user side.
-For example, there is no ocaml-mode in Emacs, but the mode to use is
-`tuareg-mode'."
+
+The key is the language name.  The value is the mode name, as
+a string or a symbol, without the \"-mode\" suffix.
+
+For many languages this is simple, but for language where this is
+not the case, this variable provides a way to simplify things on
+the user side.  For example, there is no `ocaml-mode' in Emacs,
+but the mode to use is `tuareg-mode'."
   :group 'org-edit-structure
   :type '(repeat
          (cons
@@ -229,23 +243,52 @@ issued in the language major mode buffer."
 
 ;;; Internal functions and variables
 
-(defvar org-src--allow-write-back t)
-(defvar org-src--auto-save-timer nil)
-(defvar org-src--babel-info nil)
-(defvar org-src--beg-marker nil)
-(defvar org-src--block-indentation nil)
-(defvar org-src--end-marker nil)
-(defvar org-src--from-org-mode nil)
-(defvar org-src--overlay nil)
-(defvar org-src--preserve-indentation nil)
-(defvar org-src--remote nil)
-(defvar org-src--saved-temp-window-config nil)
-(defvar org-src--source-type nil
+(defvar org-src--auto-save-timer nil
+  "Idle Timer auto-saving remote editing buffers.")
+
+(defvar-local org-src--allow-write-back t)
+(put 'org-src--allow-write-back 'permanent-local t)
+
+(defvar-local org-src--babel-info nil)
+(put 'org-src--babel-info 'permanent-local t)
+
+(defvar-local org-src--beg-marker nil)
+(put 'org-src--beg-marker 'permanent-local t)
+
+(defvar-local org-src--block-indentation nil)
+(put 'org-src--block-indentation 'permanent-local t)
+
+(defvar-local org-src--content-indentation nil)
+(put 'org-src--content-indentation 'permanent-local t)
+
+(defvar-local org-src--end-marker nil)
+(put 'org-src--end-marker 'permanent-local t)
+
+(defvar-local org-src--from-org-mode nil)
+(put 'org-src--from-org-mode 'permanent-local t)
+
+(defvar-local org-src--overlay nil)
+(put 'org-src--overlay 'permanent-local t)
+
+(defvar-local org-src--preserve-indentation nil)
+(put 'org-src--preserve-indentation 'permanent-local t)
+
+(defvar-local org-src--remote nil)
+(put 'org-src--remote 'permanent-local t)
+
+(defvar-local org-src--source-type nil
   "Type of element being edited, as a symbol.")
-(defvar org-src--tab-width nil
+(put 'org-src--source-type 'permanent-local t)
+
+(defvar-local org-src--tab-width nil
   "Contains `tab-width' value from Org source buffer.
 However, if `indent-tabs-mode' is nil in that buffer, its value
 is 0.")
+(put 'org-src--tab-width 'permanent-local t)
+
+(defvar-local org-src-source-file-name nil
+  "File name associated to Org source buffer, or nil.")
+(put 'org-src-source-file-name 'permanent-local t)
 
 (defun org-src--construct-edit-buffer-name (org-buffer-name lang)
   "Construct the buffer name for a source editing buffer."
@@ -264,21 +307,6 @@ Return nil if there is no such buffer."
             (eq (marker-buffer end) (marker-buffer org-src--end-marker))
             (throw 'exit b))))))
 
-(defun org-src--source-buffer ()
-  "Return source buffer edited by current buffer."
-  (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
-  (or (marker-buffer org-src--beg-marker)
-      (error "No source buffer available for current editing session")))
-
-(defun org-src--get-lang-mode (lang)
-  "Return major mode that should be used for LANG.
-LANG is a string, and the returned major mode is a symbol."
-  (intern
-   (concat
-    (let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
-      (if (symbolp l) (symbol-name l) l))
-    "-mode")))
-
 (defun org-src--coordinates (pos beg end)
   "Return coordinates of POS relatively to BEG and END.
 POS, BEG and END are buffer positions.  Return value is either
@@ -397,7 +425,7 @@ Assume point is in the corresponding edit buffer."
         (if org-src--preserve-indentation 0
           (+ (or org-src--block-indentation 0)
              (if (memq org-src--source-type '(example-block src-block))
-                 org-edit-src-content-indentation
+                 org-src--content-indentation
                0))))
        (use-tabs? (and (> org-src--tab-width 0) t))
        (source-tab-width org-src--tab-width)
@@ -405,8 +433,8 @@ Assume point is in the corresponding edit buffer."
        (write-back org-src--allow-write-back))
     (with-temp-buffer
       ;; Reproduce indentation parameters from source buffer.
-      (setq-local indent-tabs-mode use-tabs?)
-      (when (> source-tab-width 0) (setq-local tab-width source-tab-width))
+      (setq indent-tabs-mode use-tabs?)
+      (when (> source-tab-width 0) (setq tab-width source-tab-width))
       ;; Apply WRITE-BACK function on edit buffer contents.
       (insert (org-no-properties contents))
       (goto-char (point-min))
@@ -441,7 +469,6 @@ When REMOTE is non-nil, do not try to preserve point or 
mark when
 moving from the edit area to the source.
 
 Leave point in edit buffer."
-  (setq org-src--saved-temp-window-config (current-window-configuration))
   (let* ((area (org-src--contents-area datum))
         (beg (copy-marker (nth 0 area)))
         (end (copy-marker (nth 1 area) t))
@@ -457,11 +484,12 @@ Leave point in edit buffer."
        (with-current-buffer old-edit-buffer (org-src--remove-overlay))
        (kill-buffer old-edit-buffer))
       (let* ((org-mode-p (derived-mode-p 'org-mode))
+            (source-file-name (buffer-file-name (buffer-base-buffer)))
             (source-tab-width (if indent-tabs-mode tab-width 0))
             (type (org-element-type datum))
-            (ind (org-with-wide-buffer
-                  (goto-char (org-element-property :begin datum))
-                  (org-get-indentation)))
+            (block-ind (org-with-point-at (org-element-property :begin datum)
+                         (current-indentation)))
+            (content-ind org-edit-src-content-indentation)
             (preserve-ind
              (and (memq type '(example-block src-block))
                   (or (org-element-property :preserve-indent datum)
@@ -498,16 +526,18 @@ Leave point in edit buffer."
        ;; Transmit buffer-local variables for exit function.  It must
        ;; be done after initializing major mode, as this operation
        ;; may reset them otherwise.
-       (setq-local org-src--tab-width source-tab-width)
-       (setq-local org-src--from-org-mode org-mode-p)
-       (setq-local org-src--beg-marker beg)
-       (setq-local org-src--end-marker end)
-       (setq-local org-src--remote remote)
-       (setq-local org-src--source-type type)
-       (setq-local org-src--block-indentation ind)
-       (setq-local org-src--preserve-indentation preserve-ind)
-       (setq-local org-src--overlay overlay)
-       (setq-local org-src--allow-write-back write-back)
+       (setq org-src--tab-width source-tab-width)
+       (setq org-src--from-org-mode org-mode-p)
+       (setq org-src--beg-marker beg)
+       (setq org-src--end-marker end)
+       (setq org-src--remote remote)
+       (setq org-src--source-type type)
+       (setq org-src--block-indentation block-ind)
+       (setq org-src--content-indentation content-ind)
+       (setq org-src--preserve-indentation preserve-ind)
+       (setq org-src--overlay overlay)
+       (setq org-src--allow-write-back write-back)
+       (setq org-src-source-file-name source-file-name)
        ;; Start minor mode.
        (org-src-mode)
        ;; Move mark and point in edit buffer to the corresponding
@@ -536,7 +566,7 @@ Leave point in edit buffer."
   "Fontify code block.
 This function is called by emacs automatic fontification, as long
 as `org-src-fontify-natively' is non-nil."
-  (let ((lang-mode (org-src--get-lang-mode lang)))
+  (let ((lang-mode (org-src-get-lang-mode lang)))
     (when (fboundp lang-mode)
       (let ((string (buffer-substring-no-properties start end))
            (modified (buffer-modified-p))
@@ -631,13 +661,12 @@ This minor mode is turned on in two situations:
 See also `org-src-mode-hook'."
   nil " OrgSrc" nil
   (when org-edit-src-persistent-message
-    (setq-local
-     header-line-format
-     (substitute-command-keys
-      (if org-src--allow-write-back
-         "Edit, then exit with `\\[org-edit-src-exit]' or abort with \
+    (setq header-line-format
+         (substitute-command-keys
+          (if org-src--allow-write-back
+              "Edit, then exit with `\\[org-edit-src-exit]' or abort with \
 `\\[org-edit-src-abort]'"
-       "Exit with `\\[org-edit-src-exit]' or abort with \
+            "Exit with `\\[org-edit-src-exit]' or abort with \
 `\\[org-edit-src-abort]'"))))
   ;; Possibly activate various auto-save features (for the edit buffer
   ;; or the source buffer).
@@ -646,7 +675,8 @@ See also `org-src-mode-hook'."
          (concat (make-temp-name "org-src-")
                  (format-time-string "-%Y-%d-%m")
                  ".txt")))
-  (unless (or org-src--auto-save-timer (zerop 
org-edit-src-auto-save-idle-delay))
+  (unless (or org-src--auto-save-timer
+             (= 0 org-edit-src-auto-save-idle-delay))
     (setq org-src--auto-save-timer
          (run-with-idle-timer
           org-edit-src-auto-save-idle-delay t
@@ -663,15 +693,13 @@ See also `org-src-mode-hook'."
                   (setq org-src--auto-save-timer nil)))))))))
 
 (defun org-src-mode-configure-edit-buffer ()
+  "Configure the src edit buffer."
   (when (bound-and-true-p org-src--from-org-mode)
     (add-hook 'kill-buffer-hook #'org-src--remove-overlay nil 'local)
     (if (bound-and-true-p org-src--allow-write-back)
        (progn
          (setq buffer-offer-save t)
-         (setq buffer-file-name
-               (concat (buffer-file-name (marker-buffer org-src--beg-marker))
-                       "[" (buffer-name) "]"))
-         (setq-local write-contents-functions '(org-edit-src-save)))
+         (setq write-contents-functions '(org-edit-src-save)))
       (setq buffer-read-only t))))
 
 (add-hook 'org-src-mode-hook #'org-src-mode-configure-edit-buffer)
@@ -732,6 +760,15 @@ Org-babel commands."
     (org-src-do-at-code-block
      (call-interactively (lookup-key org-babel-map key)))))
 
+(defun org-src-get-lang-mode (lang)
+  "Return major mode that should be used for LANG.
+LANG is a string, and the returned major mode is a symbol."
+  (intern
+   (concat
+    (let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
+      (if (symbolp l) (symbol-name l) l))
+    "-mode")))
+
 (defun org-src-edit-buffer-p (&optional buffer)
   "Non-nil when current buffer is a source editing buffer.
 If BUFFER is non-nil, test it instead."
@@ -740,11 +777,34 @@ If BUFFER is non-nil, test it instead."
         (local-variable-p 'org-src--beg-marker buffer)
         (local-variable-p 'org-src--end-marker buffer))))
 
+(defun org-src-source-buffer ()
+  "Return source buffer edited in current buffer.
+Raise an error when current buffer is not a source editing buffer."
+  (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
+  (or (marker-buffer org-src--beg-marker)
+      (error "No source buffer available for current editing session")))
+
+(defun org-src-source-type ()
+  "Return type of element edited in current buffer.
+Raise an error when current buffer is not a source editing buffer."
+  (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
+  org-src--source-type)
+
 (defun org-src-switch-to-buffer (buffer context)
   (pcase org-src-window-setup
     (`current-window (pop-to-buffer-same-window buffer))
     (`other-window
      (switch-to-buffer-other-window buffer))
+    (`split-window-below
+     (if (eq context 'exit)
+        (delete-window)
+       (select-window (split-window-vertically)))
+     (pop-to-buffer-same-window buffer))
+    (`split-window-right
+     (if (eq context 'exit)
+        (delete-window)
+       (select-window (split-window-horizontally)))
+     (pop-to-buffer-same-window buffer))
     (`other-frame
      (pcase context
        (`exit
@@ -900,7 +960,7 @@ the LaTeX environment in the Org mode buffer."
     (org-src--edit-element
      element
      (org-src--construct-edit-buffer-name (buffer-name) "LaTeX environment")
-     (org-src--get-lang-mode "latex")
+     (org-src-get-lang-mode "latex")
      t)
     t))
 
@@ -925,7 +985,7 @@ Throw an error when not at an export block."
                               ;; Missing export-block type.  Fallback
                               ;; to default mode.
                               "fundamental")))
-          (mode (org-src--get-lang-mode type)))
+          (mode (org-src-get-lang-mode type)))
       (unless (functionp mode) (error "No such language mode: %s" mode))
       (org-src--edit-element
        element
@@ -958,7 +1018,7 @@ name of the sub-editing buffer."
     (let* ((lang
            (if (eq type 'src-block) (org-element-property :language element)
              "example"))
-          (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang)))
+          (lang-f (and (eq type 'src-block) (org-src-get-lang-mode lang)))
           (babel-info (and (eq type 'src-block)
                            (org-babel-get-src-block-info 'light)))
           deactivate-mark)
@@ -977,7 +1037,7 @@ name of the sub-editing buffer."
                  (or (org-element-property :label-fmt element)
                      org-coderef-label-format))
       (when (eq type 'src-block)
-       (setq-local org-src--babel-info babel-info)
+       (setq org-src--babel-info babel-info)
        (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
          (when (fboundp edit-prep-func)
            (funcall edit-prep-func babel-info))))
@@ -991,7 +1051,7 @@ name of the sub-editing buffer."
                 (org-src--on-datum-p context))
       (user-error "Not on inline source code"))
     (let* ((lang (org-element-property :language context))
-          (lang-f (org-src--get-lang-mode lang))
+          (lang-f (org-src-get-lang-mode lang))
           (babel-info (org-babel-get-src-block-info 'light))
           deactivate-mark)
       (unless (functionp lang-f) (error "No such language mode: %s" lang-f))
@@ -1000,7 +1060,7 @@ name of the sub-editing buffer."
        (org-src--construct-edit-buffer-name (buffer-name) lang)
        lang-f
        (lambda ()
-        ;; Inline src blocks are limited to one line.
+        ;; Inline source blocks are limited to one line.
         (while (re-search-forward "\n[ \t]*" nil t) (replace-match " "))
         ;; Trim contents.
         (goto-char (point-min))
@@ -1010,8 +1070,8 @@ name of the sub-editing buffer."
         (skip-chars-backward " \t")
         (delete-region (point) (point-max))))
       ;; Finalize buffer.
-      (setq-local org-src--babel-info babel-info)
-      (setq-local org-src--preserve-indentation t)
+      (setq org-src--babel-info babel-info)
+      (setq org-src--preserve-indentation t)
       (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
        (when (fboundp edit-prep-func) (funcall edit-prep-func babel-info)))
       ;; Return success.
@@ -1066,7 +1126,7 @@ Throw an error if there is no such buffer."
        (beg org-src--beg-marker)
        (end org-src--end-marker)
        (overlay org-src--overlay))
-    (with-current-buffer (org-src--source-buffer)
+    (with-current-buffer (org-src-source-buffer)
       (undo-boundary)
       (goto-char beg)
       ;; Temporarily disable read-only features of OVERLAY in order to
@@ -1122,10 +1182,7 @@ Throw an error if there is no such buffer."
        (write-back (org-src--goto-coordinates coordinates beg end))))
     ;; Clean up left-over markers and restore window configuration.
     (set-marker beg nil)
-    (set-marker end nil)
-    (when org-src--saved-temp-window-config
-      (set-window-configuration org-src--saved-temp-window-config)
-      (setq org-src--saved-temp-window-config nil))))
+    (set-marker end nil)))
 
 
 (provide 'org-src)
diff --git a/lisp/org/org-table.el b/lisp/org/org-table.el
index a65629b..a21587a 100644
--- a/lisp/org/org-table.el
+++ b/lisp/org/org-table.el
@@ -35,51 +35,66 @@
 ;;; Code:
 
 (require 'cl-lib)
-(require 'org)
+(require 'org-macs)
+(require 'org-compat)
+(require 'org-keys)
 
+(declare-function calc-eval "calc" (str &optional separator &rest args))
+(declare-function org-at-timestamp-p "org" (&optional extended))
+(declare-function org-delete-backward-char "org" (N))
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-contents "org-element" (element))
 (declare-function org-element-extract-element "org-element" (element))
 (declare-function org-element-interpret-data "org-element" (data))
-(declare-function org-element-lineage "org-element"
-                 (blob &optional types with-self))
-(declare-function org-element-map "org-element"
-                 (data types fun
-                       &optional info first-match no-recursion 
with-affiliated))
-(declare-function org-element-parse-buffer "org-element"
-                 (&optional granularity visible-only))
+(declare-function org-element-lineage "org-element" (blob &optional types 
with-self))
+(declare-function org-element-map "org-element" (data types fun &optional info 
first-match no-recursion with-affiliated))
+(declare-function org-element-parse-buffer "org-element" (&optional 
granularity visible-only))
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-type "org-element" (element))
-
+(declare-function org-entry-get "org" (pom property &optional inherit 
literal-nil))
 (declare-function org-export-create-backend "ox" (&rest rest) t)
 (declare-function org-export-data-with-backend "ox" (data backend info))
-(declare-function org-export-filter-apply-functions "ox"
-                 (filters value info))
+(declare-function org-export-filter-apply-functions "ox" (filters value info))
 (declare-function org-export-first-sibling-p "ox" (blob info))
 (declare-function org-export-get-backend "ox" (name))
-(declare-function org-export-get-environment "ox"
-                 (&optional backend subtreep ext-plist))
+(declare-function org-export-get-environment "ox" (&optional backend subtreep 
ext-plist))
 (declare-function org-export-install-filters "ox" (info))
 (declare-function org-export-table-has-special-column-p "ox" (table))
 (declare-function org-export-table-row-is-special-p "ox" (table-row info))
-
-(declare-function calc-eval "calc" (str &optional separator &rest args))
+(declare-function org-id-find "org-id" (id &optional markerp))
+(declare-function org-indent-line "org" ())
+(declare-function org-load-modules-maybe "org" (&optional force))
+(declare-function org-restart-font-lock "org" ())
+(declare-function org-sort-remove-invisible "org" (s))
+(declare-function org-time-stamp-format "org" (&optional long inactive))
+(declare-function org-time-string-to-absolute "org" (s &optional daynr prefer 
buffer pos))
+(declare-function org-time-string-to-time "org" (s))
+(declare-function org-timestamp-up-day "org" (&optional arg))
 
 (defvar constants-unit-system)
+(defvar org-M-RET-may-split-line)
 (defvar org-element-use-cache)
 (defvar org-export-filters-alist)
-(defvar org-table-follow-field-mode)
-(defvar orgtbl-mode) ; defined below
-(defvar orgtbl-mode-menu) ; defined when orgtbl mode get initialized
+(defvar org-finish-function)
+(defvar org-inhibit-highlight-removal)
+(defvar org-inhibit-startup)
+(defvar org-selected-window)
+(defvar org-self-insert-cluster-for-undo)
+(defvar org-self-insert-command-undo-counter)
+(defvar org-ts-regexp)
+(defvar org-ts-regexp-both)
+(defvar org-ts-regexp-inactive)
+(defvar org-ts-regexp3)
+(defvar org-window-configuration)
 (defvar sort-fold-case)
 
-(defvar orgtbl-after-send-table-hook nil
-  "Hook for functions attaching to `C-c C-c', if the table is sent.
-This can be used to add additional functionality after the table is sent
-to the receiver position, otherwise, if table is not sent, the functions
-are not run.")
+
+;;; Customizables
 
-(defvar org-table-TBLFM-begin-regexp "^[ \t]*|.*\n[ \t]*#\\+TBLFM: ")
+(defgroup org-table nil
+  "Options concerning tables in Org mode."
+  :tag "Org Table"
+  :group 'org)
 
 (defcustom orgtbl-optimized t
   "Non-nil means use the optimized table editor version for `orgtbl-mode'.
@@ -193,6 +208,15 @@ alignment to the right border applies."
   :group 'org-table-settings
   :type 'number)
 
+(defcustom org-table-formula-field-format "%s"
+  "Format for fields which contain the result of a formula.
+For example, using \"~%s~\" will display the result within tilde
+characters.  Beware that modifying the display can prevent the
+field from being used in another formula."
+  :group 'org-table-settings
+  :version "24.1"
+  :type 'string)
+
 (defgroup org-table-editing nil
   "Behavior of tables during editing in Org mode."
   :tag "Org Table Editing"
@@ -231,9 +255,6 @@ fields."
          (const :tag "with yes-or-no" yes-or-no-p)
          (const :tag "with y-or-n" y-or-n-p)
          (const :tag "no confirmation" nil)))
-(put 'org-table-fix-formulas-confirm
-     'safe-local-variable
-     #'(lambda (x) (member x '(yes-or-no-p y-or-n-p))))
 
 (defcustom org-table-tab-jumps-over-hlines t
   "Non-nil means tab in the last column of a table with jump over a hline.
@@ -244,6 +265,13 @@ this line."
   :group 'org-table-editing
   :type 'boolean)
 
+(defcustom org-table-shrunk-column-indicator "…"
+  "String to be displayed in a shrunk column."
+  :group 'org-table-editing
+  :type 'string
+  :package-version '(Org . "9.2")
+  :safe (lambda (v) (and (stringp v) (not (equal v "")))))
+
 (defgroup org-table-calculation nil
   "Options concerning tables in Org mode."
   :tag "Org Table Calculation"
@@ -279,8 +307,7 @@ t       accept as input and present for editing"
                       calc-prefer-frac   nil
                       calc-symbolic-mode nil
                       calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" 
mm))
-                      calc-display-working-message t
-                      )
+                      calc-display-working-message t)
   "List with Calc mode settings for use in `calc-eval' for table formulas.
 The list must contain alternating symbols (Calc modes variables and values).
 Don't remove any of the default settings, just change the values.  Org mode
@@ -313,15 +340,6 @@ So this is about 08:32:34 versus 8:33:34."
   :type 'boolean
   :safe #'booleanp)
 
-(defcustom org-table-formula-field-format "%s"
-  "Format for fields which contain the result of a formula.
-For example, using \"~%s~\" will display the result within tilde
-characters.  Beware that modifying the display can prevent the
-field from being used in another formula."
-  :group 'org-table-settings
-  :version "24.1"
-  :type 'string)
-
 (defcustom org-table-formula-evaluate-inline t
   "Non-nil means TAB and RET evaluate a formula in current table field.
 If the current field starts with an equal sign, it is assumed to be a formula
@@ -393,7 +411,6 @@ many columns as needed.  When set to `warn', issue a 
warning when
 doing so.  When set to `prompt', ask user before creating a new
 column.  Otherwise, throw an error."
   :group 'org-table-calculation
-  :version "26.1"
   :package-version '(Org . "8.3")
   :type '(choice
          (const :tag "Out-of-bounds field generates an error (default)" nil)
@@ -419,12 +436,38 @@ available parameters."
   "Max lines that `org-table-convert-region' will attempt to process.
 
 The function can be slow on larger regions; this safety feature
-prevents it from hanging emacs."
+prevents it from hanging Emacs."
   :group 'org-table-import-export
   :type 'integer
-  :version "26.1"
   :package-version '(Org . "8.3"))
 
+
+;;; Regexps Constants
+
+(defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)"
+  "Detect an org-type or table-type table.")
+
+(defconst org-table-line-regexp "^[ \t]*|"
+  "Detect an org-type table line.")
+
+(defconst org-table-dataline-regexp "^[ \t]*|[^-]"
+  "Detect an org-type table line.")
+
+(defconst org-table-hline-regexp "^[ \t]*|-"
+  "Detect an org-type table hline.")
+
+(defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]"
+  "Detect a table-type table hline.")
+
+(defconst org-table-any-border-regexp "^[ \t]*[^|+ \t]"
+  "Detect the first line outside a table when searching from within it.
+This works for both table types.")
+
+(defconst org-TBLFM-regexp "^[ \t]*#\\+TBLFM: "
+  "Detect a #+TBLFM line.")
+
+(defvar org-table-TBLFM-begin-regexp "^[ \t]*|.*\n[ \t]*#\\+TBLFM: ")
+
 (defconst org-table-auto-recalculate-regexp "^[ \t]*| *# *\\(|\\|$\\)"
   "Regexp matching a line marked for automatic recalculation.")
 
@@ -437,10 +480,52 @@ prevents it from hanging emacs."
 (defconst org-table-border-regexp "^[ \t]*[^| \t]"
   "Regexp matching any line outside an Org table.")
 
+(defconst org-table-range-regexp
+  
"@\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\(\\.\\.@?\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\)?"
+  ;;   1                        2                    3          4              
          5
+  "Regular expression for matching ranges in formulas.")
+
+(defconst org-table-range-regexp2
+  (concat
+   "\\(" "@[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" 
"\\$[a-zA-Z0-9]+" "\\)"
+   "\\.\\."
+   "\\(" "@?[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" 
"\\$[a-zA-Z0-9]+" "\\)")
+  "Match a range for reference display.")
+
+(defconst org-table-translate-regexp
+  (concat "\\(" "@[-0-9I$]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\)")
+  "Match a reference that needs translation, for reference display.")
+
+(defconst org-table-separator-space
+  (propertize " " 'display '(space :relative-width 1))
+  "Space used around fields when aligning the table.
+This space serves as a segment separator for the purposes of the
+bidirectional reordering.")
+
+
+;;; Internal Variables
+
 (defvar org-table-last-highlighted-reference nil)
 
 (defvar org-table-formula-history nil)
 
+(defvar org-field-marker nil)
+(defvar org-table-buffer-is-an nil)
+
+(defvar-local org-table-formula-constants-local nil
+  "Local version of `org-table-formula-constants'.")
+
+(defvar org-table-may-need-update t
+  "Indicates that a table might need an update.
+This variable is set by `org-before-change-function'.
+`org-table-align' sets it back to nil.")
+
+(defvar orgtbl-after-send-table-hook nil
+  "Hook for functions attaching to `C-c C-c', if the table is sent.
+This can be used to add additional functionality after the table is sent
+to the receiver position, otherwise, if table is not sent, the functions
+are not run.")
+
 (defvar org-table-column-names nil
   "Alist with column names, derived from the `!' line.
 This variable is initialized with `org-table-analyze'.")
@@ -483,21 +568,84 @@ variable is initialized with `org-table-analyze'.")
 Line numbers are counted from the beginning of the table.  This
 variable is initialized with `org-table-analyze'.")
 
-(defconst org-table-range-regexp
-  
"@\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\(\\.\\.@?\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\)?"
-  ;;   1                       2                    3          4               
        5
-  "Regular expression for matching ranges in formulas.")
+(defvar org-table-aligned-begin-marker (make-marker)
+  "Marker at the beginning of the table last aligned.
+Used to check if cursor still is in that table, to minimize realignment.")
 
-(defconst org-table-range-regexp2
-  (concat
-   "\\(" "@[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" 
"\\$[a-zA-Z0-9]+" "\\)"
-   "\\.\\."
-   "\\(" "@?[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" 
"\\$[a-zA-Z0-9]+" "\\)")
-  "Match a range for reference display.")
+(defvar org-table-aligned-end-marker (make-marker)
+  "Marker at the end of the table last aligned.
+Used to check if cursor still is in that table, to minimize realignment.")
 
-(defconst org-table-translate-regexp
-  (concat "\\(" "@[-0-9I$]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\)")
-  "Match a reference that needs translation, for reference display.")
+(defvar org-table-last-alignment nil
+  "List of flags for flushright alignment, from the last re-alignment.
+This is being used to correctly align a single field after TAB or RET.")
+
+(defvar org-table-last-column-widths nil
+  "List of max width of fields in each column.
+This is being used to correctly align a single field after TAB or RET.")
+
+(defvar-local org-table-formula-debug nil
+  "Non-nil means debug table formulas.
+When nil, simply write \"#ERROR\" in corrupted fields.")
+
+(defvar-local org-table-overlay-coordinates nil
+  "Overlay coordinates after each align of a table.")
+
+(defvar org-last-recalc-line nil)
+
+(defvar org-show-positions nil)
+
+(defvar org-table-rectangle-overlays nil)
+
+(defvar org-table-clip nil
+  "Clipboard for table regions.")
+
+(defvar org-timecnt nil)
+
+(defvar org-recalc-commands nil
+  "List of commands triggering the recalculation of a line.
+Will be filled automatically during use.")
+
+(defvar org-recalc-marks
+  '((" " . "Unmarked: no special line, no automatic recalculation")
+    ("#" . "Automatically recalculate this line upon TAB, RET, and C-c C-c in 
the line")
+    ("*" . "Recalculate only when entire table is recalculated with `C-u C-c 
*'")
+    ("!" . "Column name definition line.  Reference in formula as $name.")
+    ("$" . "Parameter definition line name=value.  Reference in formula as 
$name.")
+    ("_" . "Names for values in row below this one.")
+    ("^" . "Names for values in row above this one.")))
+
+(defvar org-tbl-calc-modes nil)
+
+(defvar org-pos nil)
+
+
+;;; Macros and Inlined Functions
+
+(defmacro org-table-with-shrunk-columns (&rest body)
+  "Expand all columns before executing BODY, then shrink them again."
+  (declare (debug (body)))
+  (org-with-gensyms (shrunk-columns begin end)
+    `(let ((,begin (copy-marker (org-table-begin)))
+          (,end (copy-marker (org-table-end) t))
+          (,shrunk-columns (org-table--list-shrunk-columns)))
+       (org-with-point-at ,begin (org-table-expand ,begin ,end))
+       (unwind-protect
+          (progn ,@body)
+        (org-table--shrink-columns ,shrunk-columns ,begin ,end)
+        (set-marker ,begin nil)
+        (set-marker ,end nil)))))
+
+(defmacro org-table-with-shrunk-field (&rest body)
+  "Save field shrunk state, execute BODY and restore state."
+  (declare (debug (body)))
+  (org-with-gensyms (end shrunk size)
+    `(let* ((,shrunk (save-match-data (org-table--shrunk-field)))
+           (,end (and ,shrunk (copy-marker (overlay-end ,shrunk) t)))
+           (,size (and ,shrunk (- ,end (overlay-start ,shrunk)))))
+       (when ,shrunk (delete-overlay ,shrunk))
+       (unwind-protect (progn ,@body)
+        (when ,shrunk (move-overlay ,shrunk (- ,end ,size) ,end))))))
 
 (defmacro org-table-save-field (&rest body)
   "Save current field; execute BODY; restore field.
@@ -512,6 +660,66 @@ Field is restored even in case of abnormal exit."
         (org-table-goto-column ,column)
         (set-marker ,line nil)))))
 
+(defsubst org-table--set-calc-mode (var &optional value)
+  (if (stringp var)
+      (setq var (assoc var '(("D" calc-angle-mode deg)
+                            ("R" calc-angle-mode rad)
+                            ("F" calc-prefer-frac t)
+                            ("S" calc-symbolic-mode t)))
+           value (nth 2 var) var (nth 1 var)))
+  (if (memq var org-tbl-calc-modes)
+      (setcar (cdr (memq var org-tbl-calc-modes)) value)
+    (cons var (cons value org-tbl-calc-modes)))
+  org-tbl-calc-modes)
+
+
+;;; Predicates
+
+(defun org-at-TBLFM-p (&optional pos)
+  "Non-nil when point (or POS) is in #+TBLFM line."
+  (save-excursion
+    (goto-char (or pos (point)))
+    (beginning-of-line)
+    (and (let ((case-fold-search t)) (looking-at org-TBLFM-regexp))
+        (eq (org-element-type (org-element-at-point)) 'table))))
+
+(defun org-at-table-p (&optional table-type)
+  "Non-nil if the cursor is inside an Org table.
+If TABLE-TYPE is non-nil, also check for table.el-type tables."
+  (and (org-match-line (if table-type "[ \t]*[|+]" "[ \t]*|"))
+       (or (not (derived-mode-p 'org-mode))
+          (let ((e (org-element-lineage (org-element-at-point) '(table) t)))
+            (and e (or table-type
+                       (eq 'org (org-element-property :type e))))))))
+
+(defun org-at-table.el-p ()
+  "Non-nil when point is at a table.el table."
+  (and (org-match-line "[ \t]*[|+]")
+       (let ((element (org-element-at-point)))
+        (and (eq (org-element-type element) 'table)
+             (eq (org-element-property :type element) 'table.el)))))
+
+(defun org-at-table-hline-p ()
+  "Non-nil when point is inside a hline in a table.
+Assume point is already in a table."
+  (org-match-line org-table-hline-regexp))
+
+(defun org-table-check-inside-data-field (&optional noerror assume-table)
+  "Non-nil when point is inside a table data field.
+Raise an error otherwise, unless NOERROR is non-nil.  In that
+case, return nil if point is not inside a data field.  When
+optional argument ASSUME-TABLE is non-nil, assume point is within
+a table."
+  (cond ((and (or assume-table (org-at-table-p))
+             (not (save-excursion (skip-chars-backward " \t") (bolp)))
+             (not (org-at-table-hline-p))
+             (not (looking-at-p "[ \t]*$"))))
+       (noerror nil)
+       (t (user-error "Not in table data field"))))
+
+
+;;; Create, Import, and Convert Tables
+
 ;;;###autoload
 (defun org-table-create-with-table.el ()
   "Use the table.el package to insert a new table.
@@ -520,13 +728,13 @@ and table.el tables."
   (interactive)
   (require 'table)
   (cond
-   ((org-at-table.el-p)
-    (if (y-or-n-p "Convert table to Org table? ")
-       (org-table-convert)))
-   ((org-at-table-p)
-    (when (y-or-n-p "Convert table to table.el table? ")
-      (org-table-align)
-      (org-table-convert)))
+   ((and (org-at-table.el-p)
+        (y-or-n-p "Convert table to Org table? "))
+    (org-table-convert))
+   ((and (org-at-table-p)
+        (y-or-n-p "Convert table to table.el table? "))
+    (org-table-align)
+    (org-table-convert))
    (t (call-interactively 'table-insert))))
 
 ;;;###autoload
@@ -567,12 +775,11 @@ SIZE is a string Columns x Rows like for example \"3x2\"."
     ;; (mapcar (lambda (x) (insert line)) (make-list rows t))
     (dotimes (_ rows) (insert line))
     (goto-char pos)
-    (if (> rows 1)
-       ;; Insert a hline after the first row.
-       (progn
-         (end-of-line 1)
-         (insert "\n|-")
-         (goto-char pos)))
+    (when (> rows 1)
+      ;; Insert a hline after the first row.
+      (end-of-line 1)
+      (insert "\n|-")
+      (goto-char pos))
     (org-table-align)))
 
 ;;;###autoload
@@ -602,8 +809,8 @@ nil      When nil, the command tries to be smart and figure 
out the
     (if (> (count-lines beg end) org-table-convert-region-max-lines)
        (user-error "Region is longer than `org-table-convert-region-max-lines' 
(%s) lines; not converting"
                    org-table-convert-region-max-lines)
-      (if (equal separator '(64))
-         (setq separator (read-regexp "Regexp for field separator")))
+      (when (equal separator '(64))
+       (setq separator (read-regexp "Regexp for field separator")))
       (goto-char beg)
       (beginning-of-line 1)
       (setq beg (point-marker))
@@ -672,353 +879,99 @@ regexp  When a regular expression, use it to match the 
separator."
     (insert-file-contents file)
     (org-table-convert-region beg (+ (point) (- (point-max) pm)) separator)))
 
+(defun org-table-convert ()
+  "Convert from Org table to table.el and back.
+Obviously, this only works within limits.  When an Org table is converted
+to table.el, all horizontal separator lines get lost, because table.el uses
+these as cell boundaries and has no notion of horizontal lines.  A table.el
+table can be converted to an Org table only if it does not do row or column
+spanning.  Multiline cells will become multiple cells.  Beware, Org mode
+does not test if the table can be successfully converted - it blindly
+applies a recipe that works for simple tables."
+  (interactive)
+  (require 'table)
+  (if (org-at-table.el-p)
+      ;; convert to Org table
+      (let ((beg (copy-marker (org-table-begin t)))
+           (end (copy-marker (org-table-end t))))
+       (table-unrecognize-region beg end)
+       (goto-char beg)
+       (while (re-search-forward "^\\([ \t]*\\)\\+-.*\n" end t)
+         (replace-match ""))
+       (goto-char beg))
+    (if (org-at-table-p)
+       ;; convert to table.el table
+       (let ((beg (copy-marker (org-table-begin)))
+             (end (copy-marker (org-table-end))))
+         ;; first, get rid of all horizontal lines
+         (goto-char beg)
+         (while (re-search-forward "^\\([ \t]*\\)|-.*\n" end t)
+           (replace-match ""))
+         ;; insert a hline before first
+         (goto-char beg)
+         (org-table-insert-hline 'above)
+         (beginning-of-line -1)
+         ;; insert a hline after each line
+         (while (progn (beginning-of-line 3) (< (point) end))
+           (org-table-insert-hline))
+         (goto-char beg)
+         (setq end (move-marker end (org-table-end)))
+         ;; replace "+" at beginning and ending of hlines
+         (while (re-search-forward "^\\([ \t]*\\)|-" end t)
+           (replace-match "\\1+-"))
+         (goto-char beg)
+         (while (re-search-forward "-|[ \t]*$" end t)
+           (replace-match "-+"))
+         (goto-char beg)))))
+
+
+;;; Navigation and Structure Editing
 
 ;;;###autoload
-(defun org-table-export (&optional file format)
-  "Export table to a file, with configurable format.
-Such a file can be imported into usual spreadsheet programs.
+(defun org-table-begin (&optional table-type)
+  "Find the beginning of the table and return its position.
+With a non-nil optional argument TABLE-TYPE, return the beginning
+of a table.el-type table.  This function assumes point is on
+a table."
+  (cond (table-type
+        (org-element-property :post-affiliated (org-element-at-point)))
+       ((save-excursion
+          (and (re-search-backward org-table-border-regexp nil t)
+               (line-beginning-position 2))))
+       (t (point-min))))
 
-FILE can be the output file name.  If not given, it will be taken
-from a TABLE_EXPORT_FILE property in the current entry or higher
-up in the hierarchy, or the user will be prompted for a file
-name.  FORMAT can be an export format, of the same kind as it
-used when `orgtbl-mode' sends a table in a different format.
+;;;###autoload
+(defun org-table-end (&optional table-type)
+  "Find the end of the table and return its position.
+With a non-nil optional argument TABLE-TYPE, return the end of
+a table.el-type table.  This function assumes point is on
+a table."
+  (save-excursion
+    (cond (table-type
+          (goto-char (org-element-property :end (org-element-at-point)))
+          (skip-chars-backward " \t\n")
+          (line-beginning-position 2))
+         ((re-search-forward org-table-border-regexp nil t)
+          (match-beginning 0))
+         ;; When the line right after the table is the last line in
+         ;; the buffer with trailing spaces but no final newline
+         ;; character, be sure to catch the correct ending at its
+         ;; beginning.  In any other case, ending is expected to be
+         ;; at point max.
+         (t (goto-char (point-max))
+            (skip-chars-backward " \t")
+            (if (bolp) (point) (line-end-position))))))
 
-The command suggests a format depending on TABLE_EXPORT_FORMAT,
-whether it is set locally or up in the hierarchy, then on the
-extension of the given file name, and finally on the variable
-`org-table-export-default-format'."
-  (interactive)
-  (unless (org-at-table-p) (user-error "No table at point"))
-  (org-table-align)           ; Make sure we have everything we need.
-  (let ((file (or file (org-entry-get (point) "TABLE_EXPORT_FILE" t))))
-    (unless file
-      (setq file (read-file-name "Export table to: "))
-      (unless (or (not (file-exists-p file))
-                 (y-or-n-p (format "Overwrite file %s? " file)))
-       (user-error "File not written")))
-    (when (file-directory-p file)
-      (user-error "This is a directory path, not a file"))
-    (when (and (buffer-file-name (buffer-base-buffer))
-              (file-equal-p
-               (file-truename file)
-               (file-truename (buffer-file-name (buffer-base-buffer)))))
-      (user-error "Please specify a file name that is different from current"))
-    (let ((fileext (concat (file-name-extension file) "$"))
-         (format (or format (org-entry-get (point) "TABLE_EXPORT_FORMAT" t))))
-      (unless format
-       (let* ((formats '("orgtbl-to-tsv" "orgtbl-to-csv" "orgtbl-to-latex"
-                         "orgtbl-to-html" "orgtbl-to-generic"
-                         "orgtbl-to-texinfo" "orgtbl-to-orgtbl"
-                         "orgtbl-to-unicode"))
-              (deffmt-readable
-                (replace-regexp-in-string
-                 "\t" "\\t"
-                 (replace-regexp-in-string
-                  "\n" "\\n"
-                  (or (car (delq nil
-                                 (mapcar
-                                  (lambda (f)
-                                    (and (string-match-p fileext f) f))
-                                  formats)))
-                      org-table-export-default-format)
-                  t t) t t)))
-         (setq format
-               (org-completing-read
-                "Format: " formats nil nil deffmt-readable))))
-      (if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format)
-         (let ((transform (intern (match-string 1 format)))
-               (params (and (match-end 2)
-                            (read (concat "(" (match-string 2 format) ")"))))
-               (table (org-table-to-lisp
-                       (buffer-substring-no-properties
-                        (org-table-begin) (org-table-end)))))
-           (unless (fboundp transform)
-             (user-error "No such transformation function %s" transform))
-           (let (buf)
-             (with-current-buffer (find-file-noselect file)
-               (setq buf (current-buffer))
-               (erase-buffer)
-               (fundamental-mode)
-               (insert (funcall transform table params) "\n")
-               (save-buffer))
-             (kill-buffer buf))
-           (message "Export done."))
-       (user-error "TABLE_EXPORT_FORMAT invalid")))))
-
-(defvar org-table-aligned-begin-marker (make-marker)
-  "Marker at the beginning of the table last aligned.
-Used to check if cursor still is in that table, to minimize realignment.")
-(defvar org-table-aligned-end-marker (make-marker)
-  "Marker at the end of the table last aligned.
-Used to check if cursor still is in that table, to minimize realignment.")
-(defvar org-table-last-alignment nil
-  "List of flags for flushright alignment, from the last re-alignment.
-This is being used to correctly align a single field after TAB or RET.")
-(defvar org-table-last-column-widths nil
-  "List of max width of fields in each column.
-This is being used to correctly align a single field after TAB or RET.")
-(defvar-local org-table-formula-debug nil
-  "Non-nil means debug table formulas.
-When nil, simply write \"#ERROR\" in corrupted fields.")
-(defvar-local org-table-overlay-coordinates nil
-  "Overlay coordinates after each align of a table.")
-
-(defvar org-last-recalc-line nil)
-(defvar org-table-do-narrow t)   ; for dynamic scoping
-(defconst org-narrow-column-arrow "=>"
-  "Used as display property in narrowed table columns.")
-
-;;;###autoload
-(defun org-table-align ()
-  "Align the table at point by aligning all vertical bars."
-  (interactive)
-  (let* ((beg (org-table-begin))
-         (end (copy-marker (org-table-end))))
-    (org-table-save-field
-     ;; Make sure invisible characters in the table are at the right
-     ;; place since column widths take them into account.
-     (font-lock-fontify-region beg end)
-     (move-marker org-table-aligned-begin-marker beg)
-     (move-marker org-table-aligned-end-marker end)
-     (goto-char beg)
-     (let* ((indent (progn (looking-at "[ \t]*") (match-string 0)))
-            ;; Table's rows.  Separators are replaced by nil.  Trailing
-            ;; spaces are also removed.
-            (lines (mapcar (lambda (l)
-                             (and (not (string-match-p "\\`[ \t]*|-" l))
-                                  (let ((l (org-trim l)))
-                                    (remove-text-properties
-                                     0 (length l) '(display t org-cwidth t) l)
-                                    l)))
-                           (org-split-string (buffer-substring beg end) "\n")))
-            ;; Get the data fields by splitting the lines.
-            (fields (mapcar (lambda (l) (org-split-string l " *| *"))
-                            (remq nil lines)))
-            ;; Compute number of fields in the longest line.  If the
-            ;; table contains no field, create a default table.
-            (maxfields (if fields (apply #'max (mapcar #'length fields))
-                         (kill-region beg end)
-                         (org-table-create org-table-default-size)
-                         (user-error "Empty table - created default table")))
-            ;; A list of empty strings to fill any short rows on output.
-            (emptycells (make-list maxfields ""))
-            lengths typenums)
-       ;; Check for special formatting.
-       (dotimes (i maxfields)
-         (let ((column (mapcar (lambda (x) (or (nth i x) "")) fields))
-               fmax falign)
-           ;; Look for an explicit width or alignment.
-           (when (save-excursion
-                   (or (re-search-forward "| *<[lrc][0-9]*> *\\(|\\|$\\)" end 
t)
-                       (and org-table-do-narrow
-                            (re-search-forward
-                             "| *<[lrc]?[0-9]+> *\\(|\\|$\\)" end t))))
-             (catch :exit
-               (dolist (cell column)
-                 (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" cell)
-                   (when (match-end 1) (setq falign (match-string 1 cell)))
-                   (when (and org-table-do-narrow (match-end 2))
-                     (setq fmax (string-to-number (match-string 2 cell))))
-                   (when (or falign fmax) (throw :exit nil)))))
-             ;; Find fields that are wider than FMAX, and shorten them.
-             (when fmax
-               (dolist (x column)
-                 (when (> (string-width x) fmax)
-                   (org-add-props x nil
-                     'help-echo
-                     (concat
-                     "Clipped table field, use `\\[org-table-edit-field]' to \
-edit.  Full value is:\n"
-                      (substring-no-properties x)))
-                   (let ((l (length x))
-                         (f1 (min fmax
-                                  (or (string-match org-bracket-link-regexp x)
-                                      fmax)))
-                         (f2 1))
-                     (unless (> f1 1)
-                       (user-error
-                        "Cannot narrow field starting with wide link \"%s\""
-                        (match-string 0 x)))
-                     (if (= (org-string-width x) l) (setq f2 f1)
-                       (setq f2 1)
-                       (while (< (org-string-width (substring x 0 f2)) f1)
-                         (cl-incf f2)))
-                     (add-text-properties f2 l (list 'org-cwidth t) x)
-                     (add-text-properties
-                      (if (>= (string-width (substring x (1- f2) f2)) 2) (1- 
f2)
-                        (- f2 2))
-                      f2
-                      (list 'display org-narrow-column-arrow)
-                      x))))))
-           ;; Get the maximum width for each column
-           (push (or fmax (apply #'max 1 (mapcar #'org-string-width column)))
-                 lengths)
-           ;; Get the fraction of numbers among non-empty cells to
-           ;; decide about alignment of the column.
-           (if falign (push (equal (downcase falign) "r") typenums)
-             (let ((cnt 0)
-                   (frac 0.0))
-               (dolist (x column)
-                 (unless (equal x "")
-                   (setq frac
-                         (/ (+ (* frac cnt)
-                               (if (string-match-p org-table-number-regexp x)
-                                   1
-                                 0))
-                            (cl-incf cnt)))))
-               (push (>= frac org-table-number-fraction) typenums)))))
-       (setq lengths (nreverse lengths))
-       (setq typenums (nreverse typenums))
-       ;; Store alignment of this table, for later editing of single
-       ;; fields.
-       (setq org-table-last-alignment typenums)
-       (setq org-table-last-column-widths lengths)
-       ;; With invisible characters, `format' does not get the field
-       ;; width right So we need to make these fields wide by hand.
-       ;; Invisible characters may be introduced by fontified links,
-       ;; emphasis, macros or sub/superscripts.
-       (when (or (text-property-any beg end 'invisible 'org-link)
-                 (text-property-any beg end 'invisible t))
-         (dotimes (i maxfields)
-           (let ((len (nth i lengths)))
-             (dotimes (j (length fields))
-               (let* ((c (nthcdr i (nth j fields)))
-                      (cell (car c)))
-                 (when (and
-                        (stringp cell)
-                        (let ((l (length cell)))
-                          (or (text-property-any 0 l 'invisible 'org-link cell)
-                              (text-property-any beg end 'invisible t)))
-                        (< (org-string-width cell) len))
-                   (let ((s (make-string (- len (org-string-width cell)) ?\s)))
-                     (setcar c (if (nth i typenums) (concat s cell)
-                                 (concat cell s))))))))))
-
-       ;; Compute the formats needed for output of the table.
-       (let ((hfmt (concat indent "|"))
-             (rfmt (concat indent "|"))
-             (rfmt1 " %%%s%ds |")
-             (hfmt1 "-%s-+"))
-         (dolist (l lengths (setq hfmt (concat (substring hfmt 0 -1) "|")))
-           (let ((ty (if (pop typenums) "" "-"))) ; Flush numbers right.
-             (setq rfmt (concat rfmt (format rfmt1 ty l)))
-             (setq hfmt (concat hfmt (format hfmt1 (make-string l ?-))))))
-         ;; Replace modified lines only.  Check not only contents, but
-         ;; also columns' width.
-         (dolist (l lines)
-           (let ((line
-                  (if l (apply #'format rfmt (append (pop fields) emptycells))
-                    hfmt))
-                 (previous (buffer-substring (point) (line-end-position))))
-             (if (and (equal previous line)
-                      (let ((a 0)
-                            (b 0))
-                        (while (and (progn
-                                      (setq a (next-single-property-change
-                                               a 'org-cwidth previous))
-                                      (setq b (next-single-property-change
-                                               b 'org-cwidth line)))
-                                    (eq a b)))
-                        (eq a b)))
-                 (forward-line)
-               (insert line "\n")
-               (delete-region (point) (line-beginning-position 2))))))
-       (when (and orgtbl-mode (not (derived-mode-p 'org-mode)))
-         (goto-char org-table-aligned-begin-marker)
-         (while (org-hide-wide-columns org-table-aligned-end-marker)))
-       (set-marker end nil)
-       (when org-table-overlay-coordinates (org-table-overlay-coordinates))
-       (setq org-table-may-need-update nil)))))
-
-;;;###autoload
-(defun org-table-begin (&optional table-type)
-  "Find the beginning of the table and return its position.
-With a non-nil optional argument TABLE-TYPE, return the beginning
-of a table.el-type table.  This function assumes point is on
-a table."
-  (cond (table-type
-        (org-element-property :post-affiliated (org-element-at-point)))
-       ((save-excursion
-          (and (re-search-backward org-table-border-regexp nil t)
-               (line-beginning-position 2))))
-       (t (point-min))))
-
-;;;###autoload
-(defun org-table-end (&optional table-type)
-  "Find the end of the table and return its position.
-With a non-nil optional argument TABLE-TYPE, return the end of
-a table.el-type table.  This function assumes point is on
-a table."
-  (save-excursion
-    (cond (table-type
-          (goto-char (org-element-property :end (org-element-at-point)))
-          (skip-chars-backward " \t\n")
-          (line-beginning-position 2))
-         ((re-search-forward org-table-border-regexp nil t)
-          (match-beginning 0))
-         ;; When the line right after the table is the last line in
-         ;; the buffer with trailing spaces but no final newline
-         ;; character, be sure to catch the correct ending at its
-         ;; beginning.  In any other case, ending is expected to be
-         ;; at point max.
-         (t (goto-char (point-max))
-            (skip-chars-backward " \t")
-            (if (bolp) (point) (line-end-position))))))
-
-;;;###autoload
-(defun org-table-justify-field-maybe (&optional new)
-  "Justify the current field, text to left, number to right.
-Optional argument NEW may specify text to replace the current field content."
-  (cond
-   ((and (not new) org-table-may-need-update)) ; Realignment will happen anyway
-   ((org-at-table-hline-p))
-   ((and (not new)
-        (or (not (eq (marker-buffer org-table-aligned-begin-marker)
-                     (current-buffer)))
-            (< (point) org-table-aligned-begin-marker)
-            (>= (point) org-table-aligned-end-marker)))
-    ;; This is not the same table, force a full re-align.
-    (setq org-table-may-need-update t))
-   (t
-    ;; Realign the current field, based on previous full realign.
-    (let ((pos (point))
-         (col (org-table-current-column)))
-      (when (> col 0)
-       (skip-chars-backward "^|")
-       (if (not (looking-at " *\\([^|\n]*?\\) *\\(|\\|$\\)"))
-           (setq org-table-may-need-update t)
-         (let* ((numbers? (nth (1- col) org-table-last-alignment))
-                (cell (match-string 0))
-                (field (match-string 1))
-                (len (max 1 (- (org-string-width cell) 3)))
-                (properly-closed? (/= (match-beginning 2) (match-end 2)))
-                (fmt (format (if numbers? " %%%ds %s" " %%-%ds %s")
-                             len
-                             (if properly-closed? "|"
-                               (setq org-table-may-need-update t)
-                               "")))
-                (new-cell
-                 (cond ((not new) (format fmt field))
-                       ((<= (org-string-width new) len) (format fmt new))
-                       (t
-                        (setq org-table-may-need-update t)
-                        (format " %s |" new)))))
-           (unless (equal new-cell cell)
-             (let (org-table-may-need-update)
-               (replace-match new-cell t t)))
-           (goto-char pos))))))))
-
-;;;###autoload
-(defun org-table-next-field ()
-  "Go to the next field in the current table, creating new lines as needed.
-Before doing so, re-align the table if necessary."
+;;;###autoload
+(defun org-table-next-field ()
+  "Go to the next field in the current table, creating new lines as needed.
+Before doing so, re-align the table if necessary."
   (interactive)
   (org-table-maybe-eval-formula)
   (org-table-maybe-recalculate-line)
-  (if (and org-table-automatic-realign
-          org-table-may-need-update)
-      (org-table-align))
+  (when (and org-table-automatic-realign
+            org-table-may-need-update)
+    (org-table-align))
   (let ((end (org-table-end)))
     (if (org-at-table-hline-p)
        (end-of-line 1))
@@ -1078,7 +1031,7 @@ With numeric argument N, move N-1 fields backward first."
        (user-error "No more table fields before the current")
       (goto-char (match-end 0))
       (and (looking-at " ") (forward-char 1)))
-    (if (>= (point) pos) (org-table-beginning-of-field 2))))
+    (when (>= (point) pos) (org-table-beginning-of-field 2))))
 
 (defun org-table-end-of-field (&optional n)
   "Move to the end of the current table field.
@@ -1092,9 +1045,9 @@ With numeric argument N, move N-1 fields forward first."
     (when (re-search-forward "|" (point-at-eol 1) t)
       (backward-char 1)
       (skip-chars-backward " ")
-      (if (and (equal (char-before (point)) ?|) (looking-at " "))
-         (forward-char 1)))
-    (if (<= (point) pos) (org-table-end-of-field 2))))
+      (when (and (equal (char-before (point)) ?|) (equal (char-after (point)) 
?\s))
+       (forward-char 1)))
+    (when (<= (point) pos) (org-table-end-of-field 2))))
 
 ;;;###autoload
 (defun org-table-next-row ()
@@ -1108,6 +1061,7 @@ Before doing so, re-align the table if necessary."
       (org-table-align))
   (let ((col (org-table-current-column)))
     (beginning-of-line 2)
+    (unless (bolp) (insert "\n"))      ;missing newline at eob
     (when (or (not (org-at-table-p))
              (org-at-table-hline-p))
       (beginning-of-line 0)
@@ -1116,106 +1070,6 @@ Before doing so, re-align the table if necessary."
     (skip-chars-backward "^|\n\r")
     (when (looking-at " ") (forward-char))))
 
-;;;###autoload
-(defun org-table-copy-down (n)
-  "Copy the value of the current field one row below.
-
-If the field at the cursor is empty, copy the content of the
-nearest non-empty field above.  With argument N, use the Nth
-non-empty field.
-
-If the current field is not empty, it is copied down to the next
-row, and the cursor is moved with it.  Therefore, repeating this
-command causes the column to be filled row-by-row.
-
-If the variable `org-table-copy-increment' is non-nil and the
-field is an integer or a timestamp, it will be incremented while
-copying.  By default, increment by the difference between the
-value in the current field and the one in the field above.  To
-increment using a fixed integer, set `org-table-copy-increment'
-to a number.  In the case of a timestamp, increment by days."
-  (interactive "p")
-  (let* ((colpos (org-table-current-column))
-        (col (current-column))
-        (field (save-excursion (org-table-get-field)))
-        (field-up (or (save-excursion
-                        (org-table-get (1- (org-table-current-line))
-                                       (org-table-current-column))) ""))
-        (non-empty (string-match "[^ \t]" field))
-        (non-empty-up (string-match "[^ \t]" field-up))
-        (beg (org-table-begin))
-        (orig-n n)
-        txt txt-up inc)
-    (org-table-check-inside-data-field)
-    (if (not non-empty)
-       (save-excursion
-         (setq txt
-               (catch 'exit
-                 (while (progn (beginning-of-line 1)
-                               (re-search-backward org-table-dataline-regexp
-                                                   beg t))
-                   (org-table-goto-column colpos t)
-                   (if (and (looking-at
-                             "|[ \t]*\\([^| \t][^|]*?\\)[ \t]*|")
-                            (<= (setq n (1- n)) 0))
-                       (throw 'exit (match-string 1))))))
-         (setq field-up
-               (catch 'exit
-                 (while (progn (beginning-of-line 1)
-                               (re-search-backward org-table-dataline-regexp
-                                                   beg t))
-                   (org-table-goto-column colpos t)
-                   (if (and (looking-at
-                             "|[ \t]*\\([^| \t][^|]*?\\)[ \t]*|")
-                            (<= (setq n (1- n)) 0))
-                       (throw 'exit (match-string 1))))))
-         (setq non-empty-up (and field-up (string-match "[^ \t]" field-up))))
-      ;; Above field was not empty, go down to the next row
-      (setq txt (org-trim field))
-      (org-table-next-row)
-      (org-table-blank-field))
-    (if non-empty-up (setq txt-up (org-trim field-up)))
-    (setq inc (cond
-              ((numberp org-table-copy-increment) org-table-copy-increment)
-              (txt-up (cond ((and (string-match org-ts-regexp3 txt-up)
-                                  (string-match org-ts-regexp3 txt))
-                             (- (org-time-string-to-absolute txt)
-                                (org-time-string-to-absolute txt-up)))
-                            ((string-match org-ts-regexp3 txt) 1)
-                            ((string-match 
"\\([-+]\\)?[0-9]*\\(?:\\.[0-9]+\\)?" txt-up)
-                             (- (string-to-number txt)
-                                (string-to-number (match-string 0 txt-up))))
-                            (t 1)))
-              (t 1)))
-    (if (not txt)
-       (user-error "No non-empty field found")
-      (if (and org-table-copy-increment
-              (not (equal orig-n 0))
-              (string-match-p "^[-+^/*0-9eE.]+$" txt)
-              (< (string-to-number txt) 100000000))
-         (setq txt (calc-eval (concat txt "+" (number-to-string inc)))))
-      (insert txt)
-      (org-move-to-column col)
-      (if (and org-table-copy-increment (org-at-timestamp-p 'lax))
-         (org-timestamp-up-day inc)
-       (org-table-maybe-recalculate-line))
-      (org-table-align)
-      (org-move-to-column col))))
-
-(defun org-table-check-inside-data-field (&optional noerror)
-  "Is point inside a table data field?
-I.e. not on a hline or before the first or after the last column?
-This actually throws an error, so it aborts the current command."
-  (cond ((and (org-at-table-p)
-             (not (save-excursion (skip-chars-backward " \t") (bolp)))
-             (not (org-at-table-hline-p))
-             (not (looking-at "[ \t]*$"))))
-       (noerror nil)
-       (t (user-error "Not in table data field"))))
-
-(defvar org-table-clip nil
-  "Clipboard for table regions.")
-
 (defun org-table-get (line column)
   "Get the field in table line LINE, column COLUMN.
 If LINE is larger than the number of data lines in the table, the function
@@ -1248,6 +1102,30 @@ When ALIGN is set, also realign the table."
                  (< (point-at-eol) pos))))
     cnt))
 
+(defun org-table-current-column ()
+  "Return current column number."
+  (interactive)
+  (save-excursion
+    (let ((pos (point)))
+      (beginning-of-line)
+      (if (not (search-forward "|" pos t)) 0
+       (let ((column 1)
+             (separator (if (org-at-table-hline-p) "[+|]" "|")))
+         (while (re-search-forward separator pos t) (cl-incf column))
+         column)))))
+
+(defun org-table-current-dline ()
+  "Find out what table data line we are in.
+Only data lines count for this."
+  (save-excursion
+    (let ((c 0)
+         (pos (line-beginning-position)))
+      (goto-char (org-table-begin))
+      (while (<= (point) pos)
+       (when (looking-at org-table-dataline-regexp) (cl-incf c))
+       (forward-line))
+      c)))
+
 (defun org-table-goto-line (N)
   "Go to the Nth data line in the current table.
 Return t when the line exists, nil if it does not exist."
@@ -1289,7 +1167,8 @@ value."
     (let* ((pos (match-beginning 0))
           (val (buffer-substring pos (match-end 0))))
       (when replace
-       (replace-match (if (equal replace "") " " replace) t t))
+       (org-table-with-shrunk-field
+        (replace-match (if (equal replace "") " " replace) t t)))
       (goto-char (min (line-end-position) (1+ pos)))
       val)))
 
@@ -1341,26 +1220,36 @@ value."
                             (car eqn) "=" (cdr eqn))))
                 "")))))
 
-(defun org-table-current-column ()
-  "Find out which column we are in."
-  (interactive)
-  (save-excursion
-    (let ((column 0) (pos (point)))
-      (beginning-of-line)
-      (while (search-forward "|" pos t) (cl-incf column))
-      column)))
+(defun org-table-goto-field (ref &optional create-column-p)
+  "Move point to a specific field in the current table.
 
-(defun org-table-current-dline ()
-  "Find out what table data line we are in.
-Only data lines count for this."
-  (save-excursion
-    (let ((c 0)
-         (pos (line-beginning-position)))
-      (goto-char (org-table-begin))
-      (while (<= (point) pos)
-       (when (looking-at org-table-dataline-regexp) (cl-incf c))
-       (forward-line))
-      c)))
+REF is either the name of a field its absolute reference, as
+a string.  No column is created unless CREATE-COLUMN-P is
+non-nil.  If it is a function, it is called with the column
+number as its argument as is used as a predicate to know if the
+column can be created.
+
+This function assumes the table is already analyzed (i.e., using
+`org-table-analyze')."
+  (let* ((coordinates
+         (cond
+          ((cdr (assoc ref org-table-named-field-locations)))
+          ((string-match "\\`@\\([1-9][0-9]*\\)\\$\\([1-9][0-9]*\\)\\'" ref)
+           (list (condition-case nil
+                     (aref org-table-dlines
+                           (string-to-number (match-string 1 ref)))
+                   (error (user-error "Invalid row number in %s" ref)))
+                 (string-to-number (match-string 2 ref))))
+          (t (user-error "Unknown field: %s" ref))))
+        (line (car coordinates))
+        (column (nth 1 coordinates))
+        (create-new-column (if (functionp create-column-p)
+                               (funcall create-column-p column)
+                             create-column-p)))
+    (when coordinates
+      (goto-char org-table-current-begin-pos)
+      (forward-line line)
+      (org-table-goto-column column nil create-new-column))))
 
 ;;;###autoload
 (defun org-table-goto-column (n &optional on-delim force)
@@ -1391,41 +1280,50 @@ However, when FORCE is non-nil, create new columns if 
necessary."
   (interactive)
   (unless (org-at-table-p) (user-error "Not at a table"))
   (org-table-find-dataline)
-  (let* ((col (max 1 (org-table-current-column)))
-        (beg (org-table-begin))
-        (end (copy-marker (org-table-end))))
-    (org-table-save-field
-     (goto-char beg)
-     (while (< (point) end)
-       (unless (org-at-table-hline-p)
-        (org-table-goto-column col t)
-        (insert "|   "))
-       (forward-line)))
-    (set-marker end nil)
+  (let ((col (max 1 (org-table-current-column)))
+       (beg (org-table-begin))
+       (end (copy-marker (org-table-end)))
+       (shrunk-columns (org-table--list-shrunk-columns)))
+    (org-table-expand beg end)
+    (save-excursion
+      (goto-char beg)
+      (while (< (point) end)
+       (unless (org-at-table-hline-p)
+         (org-table-goto-column col t)
+         (unless (search-forward "|" (line-end-position) t 2)
+           ;; Add missing vertical bar at the end of the row.
+           (end-of-line)
+           (insert "|"))
+         (insert "  |"))
+       (forward-line)))
+    (org-table-goto-column (1+ col))
     (org-table-align)
+    ;; Shift appropriately stored shrunk column numbers, then hide the
+    ;; columns again.
+    (org-table--shrink-columns (mapcar (lambda (c) (if (<= c col) c (1+ c)))
+                                      shrunk-columns)
+                              beg end)
+    (set-marker end nil)
+    ;; Fix TBLFM formulas, if desirable.
     (when (or (not org-table-fix-formulas-confirm)
              (funcall org-table-fix-formulas-confirm "Fix formulas? "))
       (org-table-fix-formulas "$" nil (1- col) 1)
       (org-table-fix-formulas "$LR" nil (1- col) 1))))
 
 (defun org-table-find-dataline ()
-  "Find a data line in the current table, which is needed for column commands."
-  (if (and (org-at-table-p)
-          (not (org-at-table-hline-p)))
-      t
-    (let ((col (current-column))
-         (end (org-table-end)))
-      (org-move-to-column col)
-      (while (and (< (point) end)
-                 (or (not (= (current-column) col))
-                     (org-at-table-hline-p)))
-       (beginning-of-line 2)
-       (org-move-to-column col))
-      (if (and (org-at-table-p)
-              (not (org-at-table-hline-p)))
-         t
-       (user-error
-        "Please position cursor in a data line for column operations")))))
+  "Find a data line in the current table, which is needed for column commands.
+This function assumes point is in a table.  Raise an error when
+there is no data row below."
+  (or (not (org-at-table-hline-p))
+      (let ((col (current-column))
+           (end (org-table-end)))
+       (forward-line)
+       (while (and (< (point) end) (org-at-table-hline-p))
+         (forward-line))
+       (when (>= (point) end)
+         (user-error "Cannot find data row for column operation"))
+       (org-move-to-column col)
+       t)))
 
 (defun org-table-line-to-dline (line &optional above)
   "Turn a buffer line number into a data line number.
@@ -1440,7 +1338,7 @@ non-nil, the one above is used."
     (cond ((or (> (aref org-table-dlines min) line)
               (< (aref org-table-dlines max) line))
           nil)
-         ((= (aref org-table-dlines max) line) max)
+         ((= line (aref org-table-dlines max)) max)
          (t (catch 'exit
               (while (> (- max min) 1)
                 (let* ((mean (/ (+ max min) 2))
@@ -1448,7 +1346,84 @@ non-nil, the one above is used."
                   (cond ((= v line) (throw 'exit mean))
                         ((> v line) (setq max mean))
                         (t (setq min mean)))))
-              (if above min max))))))
+              (cond ((= line (aref org-table-dlines max)) max)
+                    ((= line (aref org-table-dlines min)) min)
+                    (above min)
+                    (t max)))))))
+
+(defun org-table--swap-cells (row1 col1 row2 col2)
+  "Swap two cells indicated by the coordinates provided.
+ROW1, COL1, ROW2, COL2 are integers indicating the row/column
+position of the two cells that will be swapped in the table."
+  (let ((content1 (org-table-get row1 col1))
+       (content2 (org-table-get row2 col2)))
+    (org-table-put row1 col1 content2)
+    (org-table-put row2 col2 content1)))
+
+(defun org-table--move-cell (direction)
+  "Move the current cell in a cardinal direction.
+DIRECTION is a symbol among `up', `down', `left', and `right'.
+The contents the current cell are swapped with cell in the
+indicated direction.  Raise an error if the move cannot be done."
+  (let ((row-shift (pcase direction (`up -1) (`down 1) (_ 0)))
+       (column-shift (pcase direction (`left -1) (`right 1) (_ 0))))
+    (when (and (= 0 row-shift) (= 0 column-shift))
+      (error "Invalid direction: %S" direction))
+    ;; Initialize `org-table-current-ncol' and `org-table-dlines'.
+    (org-table-analyze)
+    (let* ((row (org-table-current-line))
+          (column (org-table-current-column))
+          (target-row (+ row row-shift))
+          (target-column (+ column column-shift))
+          (org-table-current-nrow (1- (length org-table-dlines))))
+      (when (or (< target-column 1)
+               (< target-row 1)
+               (> target-column org-table-current-ncol)
+               (> target-row org-table-current-nrow))
+       (user-error "Cannot move cell further"))
+      (org-table--swap-cells row column target-row target-column)
+      (org-table-goto-line target-row)
+      (org-table-goto-column target-column))))
+
+;;;###autoload
+(defun org-table-move-cell-up ()
+  "Move a single cell up in a table.
+Swap with anything in target cell."
+  (interactive)
+  (unless (org-table-check-inside-data-field)
+    (error "No table at point"))
+  (org-table--move-cell 'up)
+  (org-table-align))
+
+;;;###autoload
+(defun org-table-move-cell-down ()
+  "Move a single cell down in a table.
+Swap with anything in target cell."
+  (interactive)
+  (unless (org-table-check-inside-data-field)
+    (error "No table at point"))
+  (org-table--move-cell 'down)
+  (org-table-align))
+
+;;;###autoload
+(defun org-table-move-cell-left ()
+  "Move a single cell left in a table.
+Swap with anything in target cell."
+  (interactive)
+  (unless (org-table-check-inside-data-field)
+    (error "No table at point"))
+  (org-table--move-cell 'left)
+  (org-table-align))
+
+;;;###autoload
+(defun org-table-move-cell-right ()
+  "Move a single cell right in a table.
+Swap with anything in target cell."
+  (interactive)
+  (unless (org-table-check-inside-data-field)
+    (error "No table at point"))
+  (org-table--move-cell 'right)
+  (org-table-align))
 
 ;;;###autoload
 (defun org-table-delete-column ()
@@ -1456,10 +1431,12 @@ non-nil, the one above is used."
   (interactive)
   (unless (org-at-table-p) (user-error "Not at a table"))
   (org-table-find-dataline)
-  (org-table-check-inside-data-field)
-  (let ((col (org-table-current-column))
-       (beg (org-table-begin))
-       (end (copy-marker (org-table-end))))
+  (org-table-check-inside-data-field nil t)
+  (let* ((col (org-table-current-column))
+        (beg (org-table-begin))
+        (end (copy-marker (org-table-end)))
+        (shrunk-columns (remq col (org-table--list-shrunk-columns))))
+    (org-table-expand beg end)
     (org-table-save-field
      (goto-char beg)
      (while (< (point) end)
@@ -1469,9 +1446,15 @@ non-nil, the one above is used."
         (and (looking-at "|[^|\n]+|")
              (replace-match "|")))
        (forward-line)))
-    (set-marker end nil)
     (org-table-goto-column (max 1 (1- col)))
     (org-table-align)
+    ;; Shift appropriately stored shrunk column numbers, then hide the
+    ;; columns again.
+    (org-table--shrink-columns (mapcar (lambda (c) (if (< c col) c (1- c)))
+                                      shrunk-columns)
+                              beg end)
+    (set-marker end nil)
+    ;; Fix TBLFM formulas, if desirable.
     (when (or (not org-table-fix-formulas-confirm)
              (funcall org-table-fix-formulas-confirm "Fix formulas? "))
       (org-table-fix-formulas
@@ -1484,6 +1467,7 @@ non-nil, the one above is used."
   "Move column to the right."
   (interactive)
   (org-table-move-column nil))
+
 ;;;###autoload
 (defun org-table-move-column-left ()
   "Move column to the left."
@@ -1496,7 +1480,7 @@ non-nil, the one above is used."
   (interactive "P")
   (unless (org-at-table-p) (user-error "Not at a table"))
   (org-table-find-dataline)
-  (org-table-check-inside-data-field)
+  (org-table-check-inside-data-field nil t)
   (let* ((col (org-table-current-column))
         (col1 (if left (1- col) col))
         (colpos (if left (1- col) (1+ col)))
@@ -1506,33 +1490,49 @@ non-nil, the one above is used."
       (user-error "Cannot move column further left"))
     (when (and (not left) (looking-at "[^|\n]*|[^|\n]*$"))
       (user-error "Cannot move column further right"))
-    (org-table-save-field
-     (goto-char beg)
-     (while (< (point) end)
-       (unless (org-at-table-hline-p)
-        (org-table-goto-column col1 t)
-        (when (looking-at "|\\([^|\n]+\\)|\\([^|\n]+\\)|")
-           (transpose-regions
-            (match-beginning 1) (match-end 1)
-            (match-beginning 2) (match-end 2))))
-       (forward-line)))
-    (set-marker end nil)
-    (org-table-goto-column colpos)
-    (org-table-align)
-    (when (or (not org-table-fix-formulas-confirm)
-             (funcall org-table-fix-formulas-confirm "Fix formulas? "))
-      (org-table-fix-formulas
-       "$" (list (cons (number-to-string col) (number-to-string colpos))
-                (cons (number-to-string colpos) (number-to-string col))))
-      (org-table-fix-formulas
-       "$LR" (list (cons (number-to-string col) (number-to-string colpos))
-                  (cons (number-to-string colpos) (number-to-string col)))))))
+    (let ((shrunk-columns (org-table--list-shrunk-columns)))
+      (org-table-expand beg end)
+      (org-table-save-field
+       (goto-char beg)
+       (while (< (point) end)
+        (unless (org-at-table-hline-p)
+          (org-table-goto-column col1 t)
+          (when (looking-at "|\\([^|\n]+\\)|\\([^|\n]+\\)|")
+            (transpose-regions
+             (match-beginning 1) (match-end 1)
+             (match-beginning 2) (match-end 2))))
+        (forward-line)))
+      (org-table-goto-column colpos)
+      (org-table-align)
+      ;; Shift appropriately stored shrunk column numbers, then shrink
+      ;; the columns again.
+      (org-table--shrink-columns
+       (mapcar (lambda (c)
+                (cond ((and (= col c) left) (1- c))
+                      ((= col c) (1+ c))
+                      ((and (= col (1+ c)) left) (1+ c))
+                      ((and (= col (1- c)) (not left) (1- c)))
+                      (t c)))
+              shrunk-columns)
+       beg end)
+      (set-marker end nil)
+      ;; Fix TBLFM formulas, if desirable.
+      (when (or (not org-table-fix-formulas-confirm)
+               (funcall org-table-fix-formulas-confirm "Fix formulas? "))
+       (org-table-fix-formulas
+        "$" (list (cons (number-to-string col) (number-to-string colpos))
+                  (cons (number-to-string colpos) (number-to-string col))))
+       (org-table-fix-formulas
+        "$LR" (list
+               (cons (number-to-string col) (number-to-string colpos))
+               (cons (number-to-string colpos) (number-to-string col))))))))
 
 ;;;###autoload
 (defun org-table-move-row-down ()
   "Move table row down."
   (interactive)
   (org-table-move-row nil))
+
 ;;;###autoload
 (defun org-table-move-row-up ()
   "Move table row up."
@@ -1557,24 +1557,25 @@ non-nil, the one above is used."
     (when (or (and (not up) (eobp)) (not (org-at-table-p)))
       (goto-char pos)
       (user-error "Cannot move row further"))
-    (setq hline2p (looking-at org-table-hline-regexp))
-    (goto-char pos)
-    (let ((row (delete-and-extract-region (line-beginning-position)
-                                         (line-beginning-position 2))))
-      (beginning-of-line tonew)
-      (unless (bolp) (insert "\n"))    ;at eob without a newline
-      (insert row)
-      (unless (bolp) (insert "\n"))    ;missing final newline in ROW
-      (beginning-of-line 0)
-      (org-move-to-column col)
-      (unless (or hline1p hline2p
-                 (not (or (not org-table-fix-formulas-confirm)
-                          (funcall org-table-fix-formulas-confirm
-                                   "Fix formulas? "))))
-       (org-table-fix-formulas
-        "@" (list
-             (cons (number-to-string dline1) (number-to-string dline2))
-             (cons (number-to-string dline2) (number-to-string dline1))))))))
+    (org-table-with-shrunk-columns
+     (setq hline2p (looking-at org-table-hline-regexp))
+     (goto-char pos)
+     (let ((row (delete-and-extract-region (line-beginning-position)
+                                          (line-beginning-position 2))))
+       (beginning-of-line tonew)
+       (unless (bolp) (insert "\n"))   ;at eob without a newline
+       (insert row)
+       (unless (bolp) (insert "\n"))   ;missing final newline in ROW
+       (beginning-of-line 0)
+       (org-move-to-column col)
+       (unless (or hline1p hline2p
+                  (not (or (not org-table-fix-formulas-confirm)
+                           (funcall org-table-fix-formulas-confirm
+                                    "Fix formulas? "))))
+        (org-table-fix-formulas
+         "@" (list
+              (cons (number-to-string dline1) (number-to-string dline2))
+              (cons (number-to-string dline2) (number-to-string dline1)))))))))
 
 ;;;###autoload
 (defun org-table-insert-row (&optional arg)
@@ -1582,47 +1583,48 @@ non-nil, the one above is used."
 With prefix ARG, insert below the current line."
   (interactive "P")
   (unless (org-at-table-p) (user-error "Not at a table"))
-  (let* ((line (buffer-substring (line-beginning-position) 
(line-end-position)))
-        (new (org-table-clean-line line)))
-    ;; Fix the first field if necessary
-    (if (string-match "^[ \t]*| *[#$] *|" line)
-       (setq new (replace-match (match-string 0 line) t t new)))
-    (beginning-of-line (if arg 2 1))
-    ;; Buffer may not end of a newline character, so ensure
-    ;; (beginning-of-line 2) moves point to a new line.
-    (unless (bolp) (insert "\n"))
-    (let (org-table-may-need-update) (insert-before-markers new "\n"))
-    (beginning-of-line 0)
-    (re-search-forward "| ?" (line-end-position) t)
-    (when (or org-table-may-need-update org-table-overlay-coordinates)
-      (org-table-align))
-    (when (or (not org-table-fix-formulas-confirm)
-             (funcall org-table-fix-formulas-confirm "Fix formulas? "))
-      (org-table-fix-formulas "@" nil (1- (org-table-current-dline)) 1))))
+  (org-table-with-shrunk-columns
+   (let* ((line (buffer-substring (line-beginning-position) 
(line-end-position)))
+         (new (org-table-clean-line line)))
+     ;; Fix the first field if necessary
+     (when (string-match "^[ \t]*| *[#*$] *|" line)
+       (setq new (replace-match (match-string 0 line) t t new)))
+     (beginning-of-line (if arg 2 1))
+     ;; Buffer may not end of a newline character, so ensure
+     ;; (beginning-of-line 2) moves point to a new line.
+     (unless (bolp) (insert "\n"))
+     (let (org-table-may-need-update) (insert-before-markers new "\n"))
+     (beginning-of-line 0)
+     (re-search-forward "| ?" (line-end-position) t)
+     (when (or org-table-may-need-update org-table-overlay-coordinates)
+       (org-table-align))
+     (when (or (not org-table-fix-formulas-confirm)
+              (funcall org-table-fix-formulas-confirm "Fix formulas? "))
+       (org-table-fix-formulas "@" nil (1- (org-table-current-dline)) 1)))))
 
 ;;;###autoload
 (defun org-table-insert-hline (&optional above)
   "Insert a horizontal-line below the current line into the table.
 With prefix ABOVE, insert above the current line."
   (interactive "P")
-  (if (not (org-at-table-p))
-      (user-error "Not at a table"))
-  (when (eobp) (insert "\n") (backward-char 1))
-  (if (not (string-match-p "|[ \t]*$" (org-current-line-string)))
-      (org-table-align))
-  (let ((line (org-table-clean-line
-              (buffer-substring (point-at-bol) (point-at-eol))))
-       (col (current-column)))
-    (while (string-match "|\\( +\\)|" line)
-      (setq line (replace-match
-                 (concat "+" (make-string (- (match-end 1) (match-beginning 1))
-                                          ?-) "|") t t line)))
-    (and (string-match "\\+" line) (setq line (replace-match "|" t t line)))
-    (beginning-of-line (if above 1 2))
-    (insert line "\n")
-    (beginning-of-line (if above 1 -1))
-    (org-move-to-column col)
-    (and org-table-overlay-coordinates (org-table-align))))
+  (unless (org-at-table-p) (user-error "Not at a table"))
+  (when (eobp) (save-excursion (insert "\n")))
+  (unless (string-match-p "|[ \t]*$" (org-current-line-string))
+    (org-table-align))
+  (org-table-with-shrunk-columns
+   (let ((line (org-table-clean-line
+               (buffer-substring (point-at-bol) (point-at-eol))))
+        (col (current-column)))
+     (while (string-match "|\\( +\\)|" line)
+       (setq line (replace-match
+                  (concat "+" (make-string (- (match-end 1) (match-beginning 
1))
+                                           ?-) "|") t t line)))
+     (and (string-match "\\+" line) (setq line (replace-match "|" t t line)))
+     (beginning-of-line (if above 1 2))
+     (insert line "\n")
+     (beginning-of-line (if above 1 -1))
+     (org-move-to-column col)
+     (when org-table-overlay-coordinates (org-table-align)))))
 
 ;;;###autoload
 (defun org-table-hline-and-move (&optional same-column)
@@ -1655,142 +1657,19 @@ In particular, this does handle wide and invisible 
characters."
 (defun org-table-kill-row ()
   "Delete the current row or horizontal line from the table."
   (interactive)
-  (if (not (org-at-table-p))
-      (user-error "Not at a table"))
+  (unless (org-at-table-p) (user-error "Not at a table"))
   (let ((col (current-column))
        (dline (and (not (org-match-line org-table-hline-regexp))
                    (org-table-current-dline))))
-    (kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
-    (if (not (org-at-table-p)) (beginning-of-line 0))
-    (org-move-to-column col)
-    (when (and dline
-              (or (not org-table-fix-formulas-confirm)
-                  (funcall org-table-fix-formulas-confirm "Fix formulas? ")))
-      (org-table-fix-formulas "@" (list (cons (number-to-string dline) 
"INVALID"))
-                             dline -1 dline))))
-
-;;;###autoload
-(defun org-table-sort-lines
-    (&optional with-case sorting-type getkey-func compare-func interactive?)
-  "Sort table lines according to the column at point.
-
-The position of point indicates the column to be used for
-sorting, and the range of lines is the range between the nearest
-horizontal separator lines, or the entire table of no such lines
-exist.  If point is before the first column, you will be prompted
-for the sorting column.  If there is an active region, the mark
-specifies the first line and the sorting column, while point
-should be in the last line to be included into the sorting.
-
-The command then prompts for the sorting type which can be
-alphabetically, numerically, or by time (as given in a time stamp
-in the field, or as a HH:MM value).  Sorting in reverse order is
-also possible.
-
-With prefix argument WITH-CASE, alphabetic sorting will be case-sensitive.
-
-If SORTING-TYPE is specified when this function is called from a Lisp
-program, no prompting will take place.  SORTING-TYPE must be a character,
-any of (?a ?A ?n ?N ?t ?T ?f ?F) where the capital letters indicate that
-sorting should be done in reverse order.
-
-If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies
-a function to be called to extract the key.  It must return a value
-that is compatible with COMPARE-FUNC, the function used to compare
-entries.
-
-A non-nil value for INTERACTIVE? is used to signal that this
-function is being called interactively."
-  (interactive (list current-prefix-arg nil nil nil t))
-  (when (org-region-active-p) (goto-char (region-beginning)))
-  ;; Point must be either within a field or before a data line.
-  (save-excursion
-    (skip-chars-backward " \t")
-    (when (bolp) (search-forward "|" (line-end-position) t))
-    (org-table-check-inside-data-field))
-  ;; Set appropriate case sensitivity and column used for sorting.
-  (let ((column (let ((c (org-table-current-column)))
-                 (cond ((> c 0) c)
-                       (interactive?
-                        (read-number "Use column N for sorting: "))
-                       (t 1))))
-       (sorting-type
-        (or sorting-type
-            (read-char-exclusive "Sort Table: [a]lphabetic, [n]umeric, \
-\[t]ime, [f]unc.  A/N/T/F means reversed: "))))
-    (save-restriction
-      ;; Narrow buffer to appropriate sorting area.
-      (if (org-region-active-p)
-         (progn (goto-char (region-beginning))
-                (narrow-to-region
-                 (point)
-                 (save-excursion (goto-char (region-end))
-                                 (line-beginning-position 2))))
-       (let ((start (org-table-begin))
-             (end (org-table-end)))
-         (narrow-to-region
-          (save-excursion
-            (if (re-search-backward org-table-hline-regexp start t)
-                (line-beginning-position 2)
-              start))
-          (if (save-excursion (re-search-forward org-table-hline-regexp end t))
-              (match-beginning 0)
-            end))))
-      ;; Determine arguments for `sort-subr'.  Also record original
-      ;; position.  `org-table-save-field' cannot help here since
-      ;; sorting is too much destructive.
-      (let* ((sort-fold-case (not with-case))
-            (coordinates
-             (cons (count-lines (point-min) (line-beginning-position))
-                   (current-column)))
-            (extract-key-from-field
-             ;; Function to be called on the contents of the field
-             ;; used for sorting in the current row.
-             (cl-case sorting-type
-               ((?n ?N) #'string-to-number)
-               ((?a ?A) #'org-sort-remove-invisible)
-               ((?t ?T)
-                (lambda (f)
-                  (cond ((string-match org-ts-regexp-both f)
-                         (float-time
-                          (org-time-string-to-time (match-string 0 f))))
-                        ((org-duration-p f) (org-duration-to-minutes f))
-                        ((string-match "\\<[0-9]+:[0-9]\\{2\\}\\>" f)
-                         (org-duration-to-minutes (match-string 0 f)))
-                        (t 0))))
-               ((?f ?F)
-                (or getkey-func
-                    (and interactive?
-                         (org-read-function "Function for extracting keys: "))
-                    (error "Missing key extractor to sort rows")))
-               (t (user-error "Invalid sorting type `%c'" sorting-type))))
-            (predicate
-             (cl-case sorting-type
-               ((?n ?N ?t ?T) #'<)
-               ((?a ?A) #'string<)
-               ((?f ?F)
-                (or compare-func
-                    (and interactive?
-                         (org-read-function
-                          (concat "Function for comparing keys "
-                                  "(empty for default `sort-subr' predicate): 
")
-                          'allow-empty)))))))
-       (goto-char (point-min))
-       (sort-subr (memq sorting-type '(?A ?N ?T ?F))
-                  (lambda ()
-                    (forward-line)
-                    (while (and (not (eobp))
-                                (not (looking-at org-table-dataline-regexp)))
-                      (forward-line)))
-                  #'end-of-line
-                  (lambda ()
-                    (funcall extract-key-from-field
-                             (org-trim (org-table-get-field column))))
-                  nil
-                  predicate)
-       ;; Move back to initial field.
-       (forward-line (car coordinates))
-       (move-to-column (cdr coordinates))))))
+    (org-table-with-shrunk-columns
+     (kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
+     (if (not (org-at-table-p)) (beginning-of-line 0))
+     (org-move-to-column col)
+     (when (and dline
+               (or (not org-table-fix-formulas-confirm)
+                   (funcall org-table-fix-formulas-confirm "Fix formulas? ")))
+       (org-table-fix-formulas
+       "@" (list (cons (number-to-string dline) "INVALID")) dline -1 dline)))))
 
 ;;;###autoload
 (defun org-table-cut-region (beg end)
@@ -1801,11 +1680,177 @@ If there is no active region, use just the field at 
point."
                (if (org-region-active-p) (region-end) (point))))
   (org-table-copy-region beg end 'cut))
 
+(defun org-table--increment-field (field previous)
+  "Increment string FIELD according to PREVIOUS field.
+
+Increment FIELD only if it is a string representing a number, per
+Emacs Lisp syntax, a timestamp, or is either prefixed or suffixed
+with a number.  In any other case, return FIELD as-is.
+
+If PREVIOUS has the same structure as FIELD, e.g.,
+a number-prefixed string with the same pattern, the increment
+step is the difference between numbers (or timestamps, measured
+in days) in PREVIOUS and FIELD.  Otherwise, it uses
+`org-table-copy-increment', if the variable contains a number, or
+default to 1.
+
+The function assumes `org-table-copy-increment' is non-nil."
+  (let* ((default-step (if (numberp org-table-copy-increment)
+                          org-table-copy-increment
+                        1))
+        (number-regexp                 ;Lisp read syntax for numbers
+         (rx (and string-start
+                  (opt (any "+-"))
+                  (or (and (one-or-more digit) (opt "."))
+                      (and (zero-or-more digit) "." (one-or-more digit)))
+                  (opt (any "eE") (opt (opt (any "+-")) (one-or-more digit)))
+                  string-end)))
+        (number-prefix-regexp (rx (and string-start (one-or-more digit))))
+        (number-suffix-regexp (rx (and (one-or-more digit) string-end)))
+        (analyze
+         (lambda (field)
+           ;; Analyse string FIELD and return information related to
+           ;; increment or nil.  When non-nil, return value has the
+           ;; following scheme: (TYPE VALUE PATTERN) where
+           ;; - TYPE is a symbol among `number', `prefix', `suffix'
+           ;;   and `timestamp',
+           ;; - VALUE is a timestamp if TYPE is `timestamp', or
+           ;;   a number otherwise,
+           ;; - PATTERN is the field without its prefix, or suffix if
+           ;;   TYPE is either `prefix' or `suffix' , or nil
+           ;;   otherwise.
+           (cond ((not (org-string-nw-p field)) nil)
+                 ((string-match-p number-regexp field)
+                  (list 'number
+                        (string-to-number field)
+                        nil))
+                 ((string-match number-prefix-regexp field)
+                  (list 'prefix
+                        (string-to-number (match-string 0 field))
+                        (substring field (match-end 0))))
+                 ((string-match number-suffix-regexp field)
+                  (list 'suffix
+                        (string-to-number (match-string 0 field))
+                        (substring field 0 (match-beginning 0))))
+                 ((string-match-p org-ts-regexp3 field)
+                  (list 'timestamp field nil))
+                 (t nil))))
+        (next-number-string
+         (lambda (n1 &optional n2)
+           ;; Increment number N1 and return it as a string.  If N2
+           ;; is also a number, deduce increment step from the
+           ;; difference between N1 and N2.  Otherwise, increment
+           ;; step is `default-step'.
+           (number-to-string (if n2 (+ n1 (- n1 n2)) (+ n1 default-step)))))
+        (shift-timestamp
+         (lambda (t1 &optional t2)
+           ;; Increment timestamp T1 and return it.  If T2 is also
+           ;; a timestamp, deduce increment step from the difference,
+           ;; in days, between T1 and T2.  Otherwise, increment by
+           ;; `default-step' days.
+           (with-temp-buffer
+             (insert t1)
+             (org-timestamp-up-day (if (not t2) default-step
+                                     (- (org-time-string-to-absolute t1)
+                                        (org-time-string-to-absolute t2))))
+             (buffer-string)))))
+    ;; Check if both PREVIOUS and FIELD have the same type.  Also, if
+    ;; the case of prefixed or suffixed numbers, make sure their
+    ;; pattern, i.e., the part of the string without the prefix or the
+    ;; suffix, is the same.
+    (pcase (cons (funcall analyze field) (funcall analyze previous))
+      (`((number ,n1 ,_) . (number ,n2 ,_))
+       (funcall next-number-string n1 n2))
+      (`((number ,n ,_) . ,_)
+       (funcall next-number-string n))
+      (`((prefix ,n1 ,p1) . (prefix ,n2 ,p2))
+       (concat (funcall next-number-string n1 (and (equal p1 p2) n2)) p1))
+      (`((prefix ,n ,p) . ,_)
+       (concat (funcall next-number-string n) p))
+      (`((suffix ,n1 ,p1) . (suffix ,n2 ,p2))
+       (concat p1 (funcall next-number-string n1 (and (equal p1 p2) n2))))
+      (`((suffix ,n ,p) . ,_)
+       (concat p (funcall next-number-string n)))
+      (`((timestamp ,t1 ,_) . (timestamp ,t2 ,_))
+       (funcall shift-timestamp t1 t2))
+      (`((timestamp ,t1 ,_) . ,_)
+       (funcall shift-timestamp t1))
+      (_ field))))
+
+;;;###autoload
+(defun org-table-copy-down (n)
+  "Copy the value of the current field one row below.
+
+If the field at the cursor is empty, copy the content of the
+nearest non-empty field above.  With argument N, use the Nth
+non-empty field.
+
+If the current field is not empty, it is copied down to the next
+row, and the cursor is moved with it.  Therefore, repeating this
+command causes the column to be filled row-by-row.
+
+If the variable `org-table-copy-increment' is non-nil and the
+field is a number, a timestamp, or is either prefixed or suffixed
+with a number, it will be incremented while copying.  By default,
+increment by the difference between the value in the current
+field and the one in the field above, if any.  To increment using
+a fixed integer, set `org-table-copy-increment' to a number.  In
+the case of a timestamp, increment by days.
+
+However, when N is 0, do not increment the field at all."
+  (interactive "p")
+  (org-table-check-inside-data-field)
+  (let* ((beg (org-table-begin))
+        (column (org-table-current-column))
+        (initial-field (save-excursion
+                         (let ((f (org-string-nw-p (org-table-get-field))))
+                           (and f (org-trim f)))))
+        field field-above next-field)
+    (save-excursion
+      ;; Get reference field.
+      (if initial-field (setq field initial-field)
+       (beginning-of-line)
+       (setq field
+             (catch :exit
+               (while (re-search-backward org-table-dataline-regexp beg t)
+                 (let ((f (org-string-nw-p (org-table-get-field column))))
+                   (cond ((and (> n 1) f) (cl-decf n))
+                         (f (throw :exit (org-trim f)))
+                         (t nil))
+                   (beginning-of-line)))
+               (user-error "No non-empty field found"))))
+      ;; Check if increment is appropriate, and how it should be done.
+      (when (and org-table-copy-increment (/= n 0))
+       ;; If increment step is not explicit, get non-empty field just
+       ;; above the field being incremented to guess it.
+       (unless (numberp org-table-copy-increment)
+         (setq field-above
+               (let ((f (unless (= beg (line-beginning-position))
+                          (forward-line -1)
+                          (not (org-at-table-hline-p))
+                          (org-table-get-field column))))
+                 (and (org-string-nw-p f)
+                      (org-trim f)))))
+       ;; Compute next field.
+       (setq next-field (org-table--increment-field field field-above))))
+    ;; Since initial field in not empty, we modify row below instead.
+    ;; Skip alignment since we do it at the end of the process anyway.
+    (when initial-field
+      (let ((org-table-may-need-update nil)) (org-table-next-row))
+      (org-table-blank-field))
+    ;; Insert the new field.  NEW-FIELD may be nil if
+    ;; `org-table-increment' is nil, or N = 0.  In that case, copy
+    ;; FIELD.
+    (insert (or next-field field))
+    (org-table-maybe-recalculate-line)
+    (org-table-align)))
+
 ;;;###autoload
 (defun org-table-copy-region (beg end &optional cut)
   "Copy rectangular region in table to clipboard.
-A special clipboard is used which can only be accessed
-with `org-table-paste-rectangle'."
+A special clipboard is used which can only be accessed with
+`org-table-paste-rectangle'.  Return the region copied, as a list
+of lists of fields."
   (interactive (list
                (if (org-region-active-p) (region-beginning) (point))
                (if (org-region-active-p) (region-end) (point))
@@ -1816,7 +1861,7 @@ with `org-table-paste-rectangle'."
        (c01 (org-table-current-column))
        region)
     (goto-char (max beg end))
-    (org-table-check-inside-data-field)
+    (org-table-check-inside-data-field nil t)
     (let* ((end (copy-marker (line-end-position)))
           (c02 (org-table-current-column))
           (column-start (min c01 c02))
@@ -1834,6 +1879,8 @@ with `org-table-paste-rectangle'."
        (forward-line))
       (set-marker end nil))
     (when cut (org-table-align))
+    (message (substitute-command-keys "Cells in the region copied, use \
+\\[org-table-paste-rectangle] to paste them in a table."))
     (setq org-table-clip (nreverse region))))
 
 ;;;###autoload
@@ -1864,160 +1911,26 @@ lines."
        (forward-line)))
     (org-table-align)))
 
-;;;###autoload
-(defun org-table-convert ()
-  "Convert from `org-mode' table to table.el and back.
-Obviously, this only works within limits.  When an Org table is converted
-to table.el, all horizontal separator lines get lost, because table.el uses
-these as cell boundaries and has no notion of horizontal lines.  A table.el
-table can be converted to an Org table only if it does not do row or column
-spanning.  Multiline cells will become multiple cells.  Beware, Org mode
-does not test if the table can be successfully converted - it blindly
-applies a recipe that works for simple tables."
-  (interactive)
-  (require 'table)
-  (if (org-at-table.el-p)
-      ;; convert to Org table
-      (let ((beg (copy-marker (org-table-begin t)))
-           (end (copy-marker (org-table-end t))))
-       (table-unrecognize-region beg end)
-       (goto-char beg)
-       (while (re-search-forward "^\\([ \t]*\\)\\+-.*\n" end t)
-         (replace-match ""))
-       (goto-char beg))
-    (if (org-at-table-p)
-       ;; convert to table.el table
-       (let ((beg (copy-marker (org-table-begin)))
-             (end (copy-marker (org-table-end))))
-         ;; first, get rid of all horizontal lines
-         (goto-char beg)
-         (while (re-search-forward "^\\([ \t]*\\)|-.*\n" end t)
-           (replace-match ""))
-         ;; insert a hline before first
-         (goto-char beg)
-         (org-table-insert-hline 'above)
-         (beginning-of-line -1)
-         ;; insert a hline after each line
-         (while (progn (beginning-of-line 3) (< (point) end))
-           (org-table-insert-hline))
-         (goto-char beg)
-         (setq end (move-marker end (org-table-end)))
-         ;; replace "+" at beginning and ending of hlines
-         (while (re-search-forward "^\\([ \t]*\\)|-" end t)
-           (replace-match "\\1+-"))
-         (goto-char beg)
-         (while (re-search-forward "-|[ \t]*$" end t)
-           (replace-match "-+"))
-         (goto-char beg)))))
+
+;;; Follow Field minor mode
 
-(defun org-table-transpose-table-at-point ()
-  "Transpose Org table at point and eliminate hlines.
-So a table like
-
-| 1 | 2 | 4 | 5 |
-|---+---+---+---|
-| a | b | c | d |
-| e | f | g | h |
-
-will be transposed as
-
-| 1 | a | e |
-| 2 | b | f |
-| 4 | c | g |
-| 5 | d | h |
-
-Note that horizontal lines disappear."
-  (interactive)
-  (let* ((table (delete 'hline (org-table-to-lisp)))
-        (dline_old (org-table-current-line))
-        (col_old (org-table-current-column))
-        (contents (mapcar (lambda (_)
-                            (let ((tp table))
-                              (mapcar
-                               (lambda (_)
-                                 (prog1
-                                     (pop (car tp))
-                                   (setq tp (cdr tp))))
-                               table)))
-                          (car table))))
-    (goto-char (org-table-begin))
-    (re-search-forward "|")
-    (backward-char)
-    (delete-region (point) (org-table-end))
-    (insert (mapconcat
-            (lambda(x)
-              (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
-            contents ""))
-    (org-table-goto-line col_old)
-    (org-table-goto-column dline_old))
-  (org-table-align))
-
-;;;###autoload
-(defun org-table-wrap-region (arg)
-  "Wrap several fields in a column like a paragraph.
-This is useful if you'd like to spread the contents of a field over several
-lines, in order to keep the table compact.
-
-If there is an active region, and both point and mark are in the same column,
-the text in the column is wrapped to minimum width for the given number of
-lines.  Generally, this makes the table more compact.  A prefix ARG may be
-used to change the number of desired lines.  For example, \
-`C-2 \\[org-table-wrap-region]'
-formats the selected text to two lines.  If the region was longer than two
-lines, the remaining lines remain empty.  A negative prefix argument reduces
-the current number of lines by that amount.  The wrapped text is pasted back
-into the table.  If you formatted it to more lines than it was before, fields
-further down in the table get overwritten - so you might need to make space in
-the table first.
-
-If there is no region, the current field is split at the cursor position and
-the text fragment to the right of the cursor is prepended to the field one
-line down.
-
-If there is no region, but you specify a prefix ARG, the current field gets
-blank, and the content is appended to the field above."
-  (interactive "P")
-  (org-table-check-inside-data-field)
-  (if (org-region-active-p)
-      ;; There is a region: fill as a paragraph.
-      (let ((start (region-beginning)))
-       (org-table-cut-region (region-beginning) (region-end))
-       (when (> (length (car org-table-clip)) 1)
-         (user-error "Region must be limited to single column"))
-       (let ((nlines (cond ((not arg) (length org-table-clip))
-                           ((< arg 1) (+ (length org-table-clip) arg))
-                           (t arg))))
-         (setq org-table-clip
-               (mapcar #'list
-                       (org-wrap (mapconcat #'car org-table-clip " ")
-                                 nil
-                                 nlines))))
-       (goto-char start)
-       (org-table-paste-rectangle))
-    ;; No region, split the current field at point.
-    (unless (org-get-alist-option org-M-RET-may-split-line 'table)
-      (skip-chars-forward "^\r\n|"))
-    (cond
-     (arg                              ; Combine with field above.
-      (let ((s (org-table-blank-field))
-           (col (org-table-current-column)))
-       (forward-line -1)
-       (while (org-at-table-hline-p) (forward-line -1))
-       (org-table-goto-column col)
-       (skip-chars-forward "^|")
-       (skip-chars-backward " ")
-       (insert " " (org-trim s))
-       (org-table-align)))
-     ((looking-at "\\([^|]+\\)+|")     ; Split field.
-      (let ((s (match-string 1)))
-       (replace-match " |")
-       (goto-char (match-beginning 0))
-       (org-table-next-row)
-       (insert (org-trim s) " ")
-       (org-table-align)))
-     (t (org-table-next-row)))))
-
-(defvar org-field-marker nil)
+(define-minor-mode org-table-follow-field-mode
+  "Minor mode to make the table field editor window follow the cursor.
+When this mode is active, the field editor window will always show the
+current field.  The mode exits automatically when the cursor leaves the
+table (but see `org-table-exit-follow-field-mode-when-leaving-table')."
+  nil " TblFollow" nil
+  (if org-table-follow-field-mode
+      (add-hook 'post-command-hook 'org-table-follow-fields-with-editor
+               'append 'local)
+    (remove-hook 'post-command-hook 'org-table-follow-fields-with-editor 
'local)
+    (let* ((buf (get-buffer "*Org Table Edit Field*"))
+          (win (and buf (get-buffer-window buf))))
+      (when win (delete-window win))
+      (when buf
+       (with-current-buffer buf
+         (move-marker org-field-marker nil))
+       (kill-buffer buf)))))
 
 ;;;###autoload
 (defun org-table-edit-field (arg)
@@ -2037,8 +1950,7 @@ toggle `org-table-follow-field-mode'."
    (arg
     (let ((b (save-excursion (skip-chars-backward "^|") (point)))
          (e (save-excursion (skip-chars-forward "^|\r\n") (point))))
-      (remove-text-properties b e '(org-cwidth t invisible t
-                                              display t intangible t))
+      (remove-text-properties b e '(invisible t intangible t))
       (if (and (boundp 'font-lock-mode) font-lock-mode)
          (font-lock-fontify-block))))
    (t
@@ -2065,15 +1977,24 @@ toggle `org-table-follow-field-mode'."
       (setq word-wrap t)
       (goto-char (setq p (point-max)))
       (insert (org-trim field))
-      (remove-text-properties p (point-max)
-                             '(invisible t org-cwidth t display t
-                                         intangible t))
+      (remove-text-properties p (point-max) '(invisible t intangible t))
       (goto-char p)
       (setq-local org-finish-function 'org-table-finish-edit-field)
       (setq-local org-window-configuration cw)
       (setq-local org-field-marker pos)
       (message "Edit and finish with C-c C-c")))))
 
+(defun org-table-follow-fields-with-editor ()
+  (if (and org-table-exit-follow-field-mode-when-leaving-table
+          (not (org-at-table-p)))
+      ;; We have left the table, exit the follow mode
+      (org-table-follow-field-mode -1)
+    (when (org-table-check-inside-data-field 'noerror)
+      (let ((win (selected-window)))
+       (org-table-edit-field nil)
+       (org-fit-window-to-buffer)
+       (select-window win)))))
+
 (defun org-table-finish-edit-field ()
   "Finish editing a table data field.
 Remove all newline characters, insert the result into the table, realign
@@ -2097,114 +2018,8 @@ the table and kill the editing buffer."
     (org-table-align)
     (message "New field value inserted")))
 
-(define-minor-mode org-table-follow-field-mode
-  "Minor mode to make the table field editor window follow the cursor.
-When this mode is active, the field editor window will always show the
-current field.  The mode exits automatically when the cursor leaves the
-table (but see `org-table-exit-follow-field-mode-when-leaving-table')."
-  nil " TblFollow" nil
-  (if org-table-follow-field-mode
-      (add-hook 'post-command-hook 'org-table-follow-fields-with-editor
-               'append 'local)
-    (remove-hook 'post-command-hook 'org-table-follow-fields-with-editor 
'local)
-    (let* ((buf (get-buffer "*Org Table Edit Field*"))
-          (win (and buf (get-buffer-window buf))))
-      (when win (delete-window win))
-      (when buf
-       (with-current-buffer buf
-         (move-marker org-field-marker nil))
-       (kill-buffer buf)))))
-
-(defun org-table-follow-fields-with-editor ()
-  (if (and org-table-exit-follow-field-mode-when-leaving-table
-          (not (org-at-table-p)))
-      ;; We have left the table, exit the follow mode
-      (org-table-follow-field-mode -1)
-    (when (org-table-check-inside-data-field 'noerror)
-      (let ((win (selected-window)))
-       (org-table-edit-field nil)
-       (org-fit-window-to-buffer)
-       (select-window win)))))
-
-(defvar org-timecnt) ; dynamically scoped parameter
-
-;;;###autoload
-(defun org-table-sum (&optional beg end nlast)
-  "Sum numbers in region of current table column.
-The result will be displayed in the echo area, and will be available
-as kill to be inserted with \\[yank].
-
-If there is an active region, it is interpreted as a rectangle and all
-numbers in that rectangle will be summed.  If there is no active
-region and point is located in a table column, sum all numbers in that
-column.
-
-If at least one number looks like a time HH:MM or HH:MM:SS, all other
-numbers are assumed to be times as well (in decimal hours) and the
-numbers are added as such.
-
-If NLAST is a number, only the NLAST fields will actually be summed."
-  (interactive)
-  (save-excursion
-    (let (col (org-timecnt 0) diff h m s org-table-clip)
-      (cond
-       ((and beg end))   ; beg and end given explicitly
-       ((org-region-active-p)
-       (setq beg (region-beginning) end (region-end)))
-       (t
-       (setq col (org-table-current-column))
-       (goto-char (org-table-begin))
-       (unless (re-search-forward "^[ \t]*|[^-]" nil t)
-         (user-error "No table data"))
-       (org-table-goto-column col)
-       (setq beg (point))
-       (goto-char (org-table-end))
-       (unless (re-search-backward "^[ \t]*|[^-]" nil t)
-         (user-error "No table data"))
-       (org-table-goto-column col)
-       (setq end (point))))
-      (let* ((items (apply 'append (org-table-copy-region beg end)))
-            (items1 (cond ((not nlast) items)
-                          ((>= nlast (length items)) items)
-                          (t (setq items (reverse items))
-                             (setcdr (nthcdr (1- nlast) items) nil)
-                             (nreverse items))))
-            (numbers (delq nil (mapcar 'org-table-get-number-for-summing
-                                       items1)))
-            (res (apply '+ numbers))
-            (sres (if (= org-timecnt 0)
-                      (number-to-string res)
-                    (setq diff (* 3600 res)
-                          h (floor diff 3600) diff (mod diff 3600)
-                          m (floor diff 60) diff (mod diff 60)
-                          s diff)
-                    (format "%.0f:%02.0f:%02.0f" h m s))))
-       (kill-new sres)
-       (when (called-interactively-p 'interactive)
-           (message "%s" (substitute-command-keys
-                          (format "Sum of %d items: %-20s     \
-\(\\[yank] will insert result into buffer)" (length numbers) sres))))
-       sres))))
-
-(defun org-table-get-number-for-summing (s)
-  (let (n)
-    (if (string-match "^ *|? *" s)
-       (setq s (replace-match "" nil nil s)))
-    (if (string-match " *|? *$" s)
-       (setq s (replace-match "" nil nil s)))
-    (setq n (string-to-number s))
-    (cond
-     ((and (string-match "0" s)
-          (string-match "\\`[-+ \t0.edED]+\\'" s)) 0)
-     ((string-match "\\`[ \t]+\\'" s) nil)
-     ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?\\'" s)
-      (let ((h (string-to-number (or (match-string 1 s) "0")))
-           (m (string-to-number (or (match-string 2 s) "0")))
-           (s (string-to-number (or (match-string 4 s) "0"))))
-       (if (boundp 'org-timecnt) (setq org-timecnt (1+ org-timecnt)))
-       (* 1.0 (+ h (/ m 60.0) (/ s 3600.0)))))
-     ((equal n 0) nil)
-     (t n))))
+
+;;; Formulas
 
 (defun org-table-current-field-formula (&optional key noerror)
   "Return the formula active for the current field.
@@ -2253,34 +2068,31 @@ When NAMED is non-nil, look for a named equation."
         (eq (cond
              ((and stored equation (string-match-p "^ *=? *$" equation))
               stored)
-             ((stringp equation)
-              equation)
-             (t (org-table-formula-from-user
-                 (read-string
-                  (org-table-formula-to-user
-                   (format "%s formula %s="
-                           (if named "Field" "Column")
-                           scol))
-                  (if stored (org-table-formula-to-user stored) "")
-                  'org-table-formula-history
-                  )))))
+             ((stringp equation) equation)
+             (t
+              (org-table-formula-from-user
+               (read-string
+                (org-table-formula-to-user
+                 (format "%s formula %s=" (if named "Field" "Column") scol))
+                (if stored (org-table-formula-to-user stored) "")
+                'org-table-formula-history)))))
         mustsave)
-    (when (not (string-match "\\S-" eq))
-      ;; remove formula
+    (unless (org-string-nw-p eq)
+      ;; Remove formula.
       (setq stored-list (delq (assoc scol stored-list) stored-list))
       (org-table-store-formulas stored-list)
       (user-error "Formula removed"))
-    (if (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq)))
-    (if (string-match " *$" eq) (setq eq (replace-match "" t t eq)))
-    (if (and name (not named))
-       ;; We set the column equation, delete the named one.
-       (setq stored-list (delq (assoc name stored-list) stored-list)
-             mustsave t))
+    (when (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq)))
+    (when (string-match " *$" eq) (setq eq (replace-match "" t t eq)))
+    (when (and name (not named))
+      ;; We set the column equation, delete the named one.
+      (setq stored-list (delq (assoc name stored-list) stored-list)
+           mustsave t))
     (if stored
        (setcdr (assoc scol stored-list) eq)
       (setq stored-list (cons (cons scol eq) stored-list)))
-    (if (or mustsave (not (equal stored eq)))
-       (org-table-store-formulas stored-list))
+    (when (or mustsave (not (equal stored eq)))
+      (org-table-store-formulas stored-list))
     eq))
 
 (defun org-table-store-formulas (alist &optional location)
@@ -2348,7 +2160,7 @@ LOCATION is a buffer position, consider the formulas 
there."
              eq-alist seen)
          (dolist (string strings (nreverse eq-alist))
            (when (string-match "\\`\\(@[-+I<>0-9.$@]+\\|\\$\\([_a-zA-Z0-9]+\\|\
-[<>]+\\)\\) *= *\\(.*[^ \t]\\)"
+\[<>]+\\)\\) *= *\\(.*[^ \t]\\)"
                                string)
              (let ((lhs
                     (let ((m (match-string 1 string)))
@@ -2425,19 +2237,6 @@ If yes, store the formula and apply it."
        (org-table-eval-formula (and named '(4))
                                (org-table-formula-from-user eq))))))
 
-(defvar org-recalc-commands nil
-  "List of commands triggering the recalculation of a line.
-Will be filled automatically during use.")
-
-(defvar org-recalc-marks
-  '((" " . "Unmarked: no special line, no automatic recalculation")
-    ("#" . "Automatically recalculate this line upon TAB, RET, and C-c C-c in 
the line")
-    ("*" . "Recalculate only when entire table is recalculated with `C-u C-c 
*'")
-    ("!" . "Column name definition line.  Reference in formula as $name.")
-    ("$" . "Parameter definition line name=value.  Reference in formula as 
$name.")
-    ("_" . "Names for values in row below this one.")
-    ("^" . "Names for values in row above this one.")))
-
 ;;;###autoload
 (defun org-table-rotate-recalc-marks (&optional newchar)
   "Rotate the recalculation mark in the first column.
@@ -2509,169 +2308,21 @@ of the new mark."
       (message "%s" (cdr (assoc newchar org-recalc-marks))))))
 
 ;;;###autoload
-(defun org-table-analyze ()
-  "Analyze table at point and store results.
+(defun org-table-maybe-recalculate-line ()
+  "Recompute the current line if marked for it, and if we haven't just done 
it."
+  (interactive)
+  (and org-table-allow-automatic-line-recalculation
+       (not (and (memq last-command org-recalc-commands)
+                (eq org-last-recalc-line (line-beginning-position))))
+       (save-excursion (beginning-of-line 1)
+                      (looking-at org-table-auto-recalculate-regexp))
+       (org-table-recalculate) t))
 
-This function sets up the following dynamically scoped variables:
-
- `org-table-column-name-regexp',
- `org-table-column-names',
- `org-table-current-begin-pos',
- `org-table-current-line-types',
- `org-table-current-ncol',
- `org-table-dlines',
- `org-table-hlines',
- `org-table-local-parameters',
- `org-table-named-field-locations'."
-  (let ((beg (org-table-begin))
-       (end (org-table-end)))
-    (save-excursion
-      (goto-char beg)
-      ;; Extract column names.
-      (setq org-table-column-names nil)
-      (when (save-excursion
-             (re-search-forward "^[ \t]*| *! *\\(|.*\\)" end t))
-       (let ((c 1))
-         (dolist (name (org-split-string (match-string 1) " *| *"))
-           (cl-incf c)
-           (when (string-match "\\`[a-zA-Z][_a-zA-Z0-9]*\\'" name)
-             (push (cons name (int-to-string c)) org-table-column-names)))))
-      (setq org-table-column-names (nreverse org-table-column-names))
-      (setq org-table-column-name-regexp
-           (format "\\$\\(%s\\)\\>"
-                   (regexp-opt (mapcar #'car org-table-column-names) t)))
-      ;; Extract local parameters.
-      (setq org-table-local-parameters nil)
-      (save-excursion
-       (while (re-search-forward "^[ \t]*| *\\$ *\\(|.*\\)" end t)
-         (dolist (field (org-split-string (match-string 1) " *| *"))
-           (when (string-match
-                  "\\`\\([a-zA-Z][_a-zA-Z0-9]*\\|%\\) *= *\\(.*\\)" field)
-             (push (cons (match-string 1 field) (match-string 2 field))
-                   org-table-local-parameters)))))
-      ;; Update named fields locations.  We minimize `count-lines'
-      ;; processing by storing last known number of lines in LAST.
-      (setq org-table-named-field-locations nil)
-      (save-excursion
-       (let ((last (cons (point) 0)))
-         (while (re-search-forward "^[ \t]*| *\\([_^]\\) *\\(|.*\\)" end t)
-           (let ((c (match-string 1))
-                 (fields (org-split-string (match-string 2) " *| *")))
-             (save-excursion
-               (forward-line (if (equal c "_") 1 -1))
-               (let ((fields1
-                      (and (looking-at "^[ \t]*|[^|]*\\(|.*\\)")
-                           (org-split-string (match-string 1) " *| *")))
-                     (line (cl-incf (cdr last) (count-lines (car last) 
(point))))
-                     (col 1))
-                 (setcar last (point)) ; Update last known position.
-                 (while (and fields fields1)
-                   (let ((field (pop fields))
-                         (v (pop fields1)))
-                     (cl-incf col)
-                     (when (and (stringp field)
-                                (stringp v)
-                                (string-match "\\`[a-zA-Z][_a-zA-Z0-9]*\\'"
-                                              field))
-                       (push (cons field v) org-table-local-parameters)
-                       (push (list field line col)
-                             org-table-named-field-locations))))))))))
-      ;; Re-use existing markers when possible.
-      (if (markerp org-table-current-begin-pos)
-         (move-marker org-table-current-begin-pos (point))
-       (setq org-table-current-begin-pos (point-marker)))
-      ;; Analyze the line types.
-      (let ((l 0) hlines dlines types)
-       (while (looking-at "[ \t]*|\\(-\\)?")
-         (push (if (match-end 1) 'hline 'dline) types)
-         (if (match-end 1) (push l hlines) (push l dlines))
-         (forward-line)
-         (cl-incf l))
-       (push 'hline types) ; Add an imaginary extra hline to the end.
-       (setq org-table-current-line-types (apply #'vector (nreverse types)))
-       (setq org-table-dlines (apply #'vector (cons nil (nreverse dlines))))
-       (setq org-table-hlines (apply #'vector (cons nil (nreverse hlines)))))
-      ;; Get the number of columns from the first data line in table.
-      (goto-char beg)
-      (forward-line (aref org-table-dlines 1))
-      (let* ((fields
-             (org-split-string
-              (buffer-substring (line-beginning-position) (line-end-position))
-              "[ \t]*|[ \t]*"))
-            (nfields (length fields))
-            al al2)
-       (setq org-table-current-ncol nfields)
-       (let ((last-dline
-              (aref org-table-dlines (1- (length org-table-dlines)))))
-         (dotimes (i nfields)
-           (let ((column (1+ i)))
-             (push (list (format "LR%d" column) last-dline column) al)
-             (push (cons (format "LR%d" column) (nth i fields)) al2))))
-       (setq org-table-named-field-locations
-             (append org-table-named-field-locations al))
-       (setq org-table-local-parameters
-             (append org-table-local-parameters al2))))))
-
-(defun org-table-goto-field (ref &optional create-column-p)
-  "Move point to a specific field in the current table.
-
-REF is either the name of a field its absolute reference, as
-a string.  No column is created unless CREATE-COLUMN-P is
-non-nil.  If it is a function, it is called with the column
-number as its argument as is used as a predicate to know if the
-column can be created.
-
-This function assumes the table is already analyzed (i.e., using
-`org-table-analyze')."
-  (let* ((coordinates
-         (cond
-          ((cdr (assoc ref org-table-named-field-locations)))
-          ((string-match "\\`@\\([1-9][0-9]*\\)\\$\\([1-9][0-9]*\\)\\'" ref)
-           (list (condition-case nil
-                     (aref org-table-dlines
-                           (string-to-number (match-string 1 ref)))
-                   (error (user-error "Invalid row number in %s" ref)))
-                 (string-to-number (match-string 2 ref))))
-          (t (user-error "Unknown field: %s" ref))))
-        (line (car coordinates))
-        (column (nth 1 coordinates))
-        (create-new-column (if (functionp create-column-p)
-                               (funcall create-column-p column)
-                             create-column-p)))
-    (when coordinates
-      (goto-char org-table-current-begin-pos)
-      (forward-line line)
-      (org-table-goto-column column nil create-new-column))))
-
-;;;###autoload
-(defun org-table-maybe-recalculate-line ()
-  "Recompute the current line if marked for it, and if we haven't just done 
it."
-  (interactive)
-  (and org-table-allow-automatic-line-recalculation
-       (not (and (memq last-command org-recalc-commands)
-                (eq org-last-recalc-line (line-beginning-position))))
-       (save-excursion (beginning-of-line 1)
-                      (looking-at org-table-auto-recalculate-regexp))
-       (org-table-recalculate) t))
-
-(defvar org-tbl-calc-modes) ;; Dynamically bound in `org-table-eval-formula'
-(defsubst org-set-calc-mode (var &optional value)
-  (if (stringp var)
-      (setq var (assoc var '(("D" calc-angle-mode deg)
-                            ("R" calc-angle-mode rad)
-                            ("F" calc-prefer-frac t)
-                            ("S" calc-symbolic-mode t)))
-           value (nth 2 var) var (nth 1 var)))
-  (if (memq var org-tbl-calc-modes)
-      (setcar (cdr (memq var org-tbl-calc-modes)) value)
-    (cons var (cons value org-tbl-calc-modes)))
-  org-tbl-calc-modes)
-
-;;;###autoload
-(defun org-table-eval-formula (&optional arg equation
-                                        suppress-align suppress-const
-                                        suppress-store suppress-analysis)
-  "Replace the table field value at the cursor by the result of a calculation.
+;;;###autoload
+(defun org-table-eval-formula (&optional arg equation
+                                        suppress-align suppress-const
+                                        suppress-store suppress-analysis)
+  "Replace the table field value at the cursor by the result of a calculation.
 
 In a table, this command replaces the value in the current field with the
 result of a formula.  It also installs the formula as the \"current\" column
@@ -2714,7 +2365,7 @@ SUPPRESS-ANALYSIS prevents analyzing the table and 
checking
 location of point."
   (interactive "P")
   (unless suppress-analysis
-    (org-table-check-inside-data-field)
+    (org-table-check-inside-data-field nil t)
     (org-table-analyze))
   (if (equal arg '(16))
       (let ((eq (org-table-current-field-formula)))
@@ -2746,9 +2397,10 @@ location of point."
              (setq c (string-to-char (match-string 1 fmt))
                    n (string-to-number (match-string 2 fmt)))
              (if (= c ?p)
-                 (setq org-tbl-calc-modes (org-set-calc-mode 
'calc-internal-prec n))
+                 (setq org-tbl-calc-modes
+                       (org-table--set-calc-mode 'calc-internal-prec n))
                (setq org-tbl-calc-modes
-                     (org-set-calc-mode
+                     (org-table--set-calc-mode
                       'calc-float-format
                       (list (cdr (assoc c '((?n . float) (?f . fix)
                                             (?s . sci) (?e . eng))))
@@ -2772,7 +2424,8 @@ location of point."
                (setq keep-empty t
                      fmt (replace-match "" t t fmt)))
            (while (string-match "[DRFS]" fmt)
-             (setq org-tbl-calc-modes (org-set-calc-mode (match-string 0 fmt)))
+             (setq org-tbl-calc-modes
+                   (org-table--set-calc-mode (match-string 0 fmt)))
              (setq fmt (replace-match "" t t fmt)))
            (unless (string-match "\\S-" fmt)
              (setq fmt nil))))
@@ -2909,8 +2562,8 @@ location of point."
                     (format-time-string
                      (org-time-stamp-format
                       (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts))
-                     (encode-time
-                      (save-match-data (org-parse-time-string ts))))))
+                     (apply #'encode-time
+                            (save-match-data (org-parse-time-string ts))))))
                 form t t))
 
          (setq ev (if (and duration (string-match 
"^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" form))
@@ -3169,7 +2822,7 @@ ARGS are passed as arguments to the `message' function.  
Returns
 current time if a message is printed, otherwise returns T1.  If
 T1 is nil, always messages."
   (let ((curtime (current-time)))
-    (if (or (not t1) (time-less-p 1 (time-subtract curtime t1)))
+    (if (or (not t1) (org-time-less-p 1 (org-time-subtract curtime t1)))
        (progn (apply 'message args)
               curtime)
       t1)))
@@ -3204,139 +2857,139 @@ known that the table will be realigned a little later 
anyway."
           beg end eqlcol eqlfield)
       ;; Insert constants in all formulas.
       (when eqlist
-       (org-table-save-field
-        ;; Expand equations, then split the equation list between
-        ;; column formulas and field formulas.
-        (dolist (eq eqlist)
-          (let* ((rhs (org-table-formula-substitute-names
-                       (org-table-formula-handle-first/last-rc (cdr eq))))
-                 (old-lhs (car eq))
-                 (lhs
-                  (org-table-formula-handle-first/last-rc
-                   (cond
-                    ((string-match "\\`@-?I+" old-lhs)
-                     (user-error "Can't assign to hline relative reference"))
-                    ((string-match "\\`\\$[<>]" old-lhs)
-                     (let ((new (org-table-formula-handle-first/last-rc
-                                 old-lhs)))
-                       (when (assoc new eqlist)
-                         (user-error "\"%s=\" formula tries to overwrite \
+       (org-table-with-shrunk-columns
+        (org-table-save-field
+         ;; Expand equations, then split the equation list between
+         ;; column formulas and field formulas.
+         (dolist (eq eqlist)
+           (let* ((rhs (org-table-formula-substitute-names
+                        (org-table-formula-handle-first/last-rc (cdr eq))))
+                  (old-lhs (car eq))
+                  (lhs
+                   (org-table-formula-handle-first/last-rc
+                    (cond
+                     ((string-match "\\`@-?I+" old-lhs)
+                      (user-error "Can't assign to hline relative reference"))
+                     ((string-match "\\`\\$[<>]" old-lhs)
+                      (let ((new (org-table-formula-handle-first/last-rc
+                                  old-lhs)))
+                        (when (assoc new eqlist)
+                          (user-error "\"%s=\" formula tries to overwrite \
 existing formula for column %s"
-                                     old-lhs
-                                     new))
-                       new))
-                    (t old-lhs)))))
-            (if (string-match-p "\\`\\$[0-9]+\\'" lhs)
-                (push (cons lhs rhs) eqlcol)
-              (push (cons lhs rhs) eqlfield))))
-        (setq eqlcol (nreverse eqlcol))
-        ;; Expand ranges in lhs of formulas
-        (setq eqlfield (org-table-expand-lhs-ranges (nreverse eqlfield)))
-        ;; Get the correct line range to process.
-        (if all
-            (progn
-              (setq end (copy-marker (org-table-end)))
-              (goto-char (setq beg org-table-current-begin-pos))
-              (cond
-               ((re-search-forward org-table-calculate-mark-regexp end t)
-                ;; This is a table with marked lines, compute selected
-                ;; lines.
-                (setq line-re org-table-recalculate-regexp))
-               ;; Move forward to the first non-header line.
-               ((and (re-search-forward org-table-dataline-regexp end t)
-                     (re-search-forward org-table-hline-regexp end t)
-                     (re-search-forward org-table-dataline-regexp end t))
-                (setq beg (match-beginning 0)))
-               ;; Just leave BEG at the start of the table.
-               (t nil)))
-          (setq beg (line-beginning-position)
-                end (copy-marker (line-beginning-position 2))))
-        (goto-char beg)
-        ;; Mark named fields untouchable.  Also check if several
-        ;; field/range formulas try to set the same field.
-        (remove-text-properties beg end '(:org-untouchable t))
-        (let ((current-line (count-lines org-table-current-begin-pos
-                                         (line-beginning-position)))
-              seen-fields)
-          (dolist (eq eqlfield)
-            (let* ((name (car eq))
-                   (location (assoc name org-table-named-field-locations))
-                   (eq-line (or (nth 1 location)
-                                (and (string-match "\\`@\\([0-9]+\\)" name)
-                                     (aref org-table-dlines
-                                           (string-to-number
-                                            (match-string 1 name))))))
-                   (reference
-                    (if location
-                        ;; Turn field coordinates associated to NAME
-                        ;; into an absolute reference.
-                        (format "@%d$%d"
-                                (org-table-line-to-dline eq-line)
-                                (nth 2 location))
-                      name)))
-              (when (member reference seen-fields)
-                (user-error "Several field/range formulas try to set %s"
-                            reference))
-              (push reference seen-fields)
-              (when (or all (eq eq-line current-line))
-                (org-table-goto-field name)
-                (org-table-put-field-property :org-untouchable t)))))
-        ;; Evaluate the column formulas, but skip fields covered by
-        ;; field formulas.
-        (goto-char beg)
-        (while (re-search-forward line-re end t)
-          (unless (string-match "\\` *[_^!$/] *\\'" (org-table-get-field 1))
-            ;; Unprotected line, recalculate.
-            (cl-incf cnt)
-            (when all
-              (setq log-last-time
-                    (org-table-message-once-per-second
-                     log-last-time
-                     "Re-applying formulas to full table...(line %d)" cnt)))
-            (if (markerp org-last-recalc-line)
-                (move-marker org-last-recalc-line (line-beginning-position))
-              (setq org-last-recalc-line
-                    (copy-marker (line-beginning-position))))
-            (dolist (entry eqlcol)
-              (goto-char org-last-recalc-line)
-              (org-table-goto-column
-               (string-to-number (substring (car entry) 1)) nil 'force)
-              (unless (get-text-property (point) :org-untouchable)
-                (org-table-eval-formula
-                 nil (cdr entry) 'noalign 'nocst 'nostore 'noanalysis)))))
-        ;; Evaluate the field formulas.
-        (dolist (eq eqlfield)
-          (let ((reference (car eq))
-                (formula (cdr eq)))
-            (setq log-last-time
-                  (org-table-message-once-per-second
-                   (and all log-last-time)
-                   "Re-applying formula to field: %s" (car eq)))
-            (org-table-goto-field
-             reference
-             ;; Possibly create a new column, as long as
-             ;; `org-table-formula-create-columns' allows it.
-             (let ((column-count (progn (end-of-line)
-                                        (1- (org-table-current-column)))))
-               (lambda (column)
-                 (when (> column 1000)
-                   (user-error "Formula column target too large"))
-                 (and (> column column-count)
-                      (or (eq org-table-formula-create-columns t)
-                          (and (eq org-table-formula-create-columns 'warn)
-                               (progn
-                                 (org-display-warning
-                                  "Out-of-bounds formula added columns")
-                                 t))
-                          (and (eq org-table-formula-create-columns 'prompt)
-                               (yes-or-no-p
-                                "Out-of-bounds formula.  Add columns? "))
-                          (user-error
-                           "Missing columns in the table.  Aborting"))))))
-            (org-table-eval-formula nil formula t t t t))))
-       ;; Clean up markers and internal text property.
-       (remove-text-properties (point-min) (point-max) '(org-untouchable t))
-       (set-marker end nil)
+                                      old-lhs
+                                      new))
+                        new))
+                     (t old-lhs)))))
+             (if (string-match-p "\\`\\$[0-9]+\\'" lhs)
+                 (push (cons lhs rhs) eqlcol)
+               (push (cons lhs rhs) eqlfield))))
+         (setq eqlcol (nreverse eqlcol))
+         ;; Expand ranges in lhs of formulas
+         (setq eqlfield (org-table-expand-lhs-ranges (nreverse eqlfield)))
+         ;; Get the correct line range to process.
+         (if all
+             (progn
+               (setq end (copy-marker (org-table-end)))
+               (goto-char (setq beg org-table-current-begin-pos))
+               (cond
+                ((re-search-forward org-table-calculate-mark-regexp end t)
+                 ;; This is a table with marked lines, compute selected
+                 ;; lines.
+                 (setq line-re org-table-recalculate-regexp))
+                ;; Move forward to the first non-header line.
+                ((and (re-search-forward org-table-dataline-regexp end t)
+                      (re-search-forward org-table-hline-regexp end t)
+                      (re-search-forward org-table-dataline-regexp end t))
+                 (setq beg (match-beginning 0)))
+                ;; Just leave BEG at the start of the table.
+                (t nil)))
+           (setq beg (line-beginning-position)
+                 end (copy-marker (line-beginning-position 2))))
+         (goto-char beg)
+         ;; Mark named fields untouchable.  Also check if several
+         ;; field/range formulas try to set the same field.
+         (remove-text-properties beg end '(:org-untouchable t))
+         (let ((current-line (count-lines org-table-current-begin-pos
+                                          (line-beginning-position)))
+               seen-fields)
+           (dolist (eq eqlfield)
+             (let* ((name (car eq))
+                    (location (assoc name org-table-named-field-locations))
+                    (eq-line (or (nth 1 location)
+                                 (and (string-match "\\`@\\([0-9]+\\)" name)
+                                      (aref org-table-dlines
+                                            (string-to-number
+                                             (match-string 1 name))))))
+                    (reference
+                     (if location
+                         ;; Turn field coordinates associated to NAME
+                         ;; into an absolute reference.
+                         (format "@%d$%d"
+                                 (org-table-line-to-dline eq-line)
+                                 (nth 2 location))
+                       name)))
+               (when (member reference seen-fields)
+                 (user-error "Several field/range formulas try to set %s"
+                             reference))
+               (push reference seen-fields)
+               (when (or all (eq eq-line current-line))
+                 (org-table-goto-field name)
+                 (org-table-put-field-property :org-untouchable t)))))
+         ;; Evaluate the column formulas, but skip fields covered by
+         ;; field formulas.
+         (goto-char beg)
+         (while (re-search-forward line-re end t)
+           (unless (string-match "\\` *[_^!$/] *\\'" (org-table-get-field 1))
+             ;; Unprotected line, recalculate.
+             (cl-incf cnt)
+             (when all
+               (setq log-last-time
+                     (org-table-message-once-per-second
+                      log-last-time
+                      "Re-applying formulas to full table...(line %d)" cnt)))
+             (if (markerp org-last-recalc-line)
+                 (move-marker org-last-recalc-line (line-beginning-position))
+               (setq org-last-recalc-line
+                     (copy-marker (line-beginning-position))))
+             (dolist (entry eqlcol)
+               (goto-char org-last-recalc-line)
+               (org-table-goto-column
+                (string-to-number (substring (car entry) 1)) nil 'force)
+               (unless (get-text-property (point) :org-untouchable)
+                 (org-table-eval-formula
+                  nil (cdr entry) 'noalign 'nocst 'nostore 'noanalysis)))))
+         ;; Evaluate the field formulas.
+         (dolist (eq eqlfield)
+           (let ((reference (car eq))
+                 (formula (cdr eq)))
+             (setq log-last-time
+                   (org-table-message-once-per-second
+                    (and all log-last-time)
+                    "Re-applying formula to field: %s" (car eq)))
+             (org-table-goto-field
+              reference
+              ;; Possibly create a new column, as long as
+              ;; `org-table-formula-create-columns' allows it.
+              (let ((column-count (progn (end-of-line)
+                                         (1- (org-table-current-column)))))
+                (lambda (column)
+                  (when (> column 1000)
+                    (user-error "Formula column target too large"))
+                  (and (> column column-count)
+                       (or (eq org-table-formula-create-columns t)
+                           (and (eq org-table-formula-create-columns 'warn)
+                                (progn
+                                  (org-display-warning
+                                   "Out-of-bounds formula added columns")
+                                  t))
+                           (and (eq org-table-formula-create-columns 'prompt)
+                                (yes-or-no-p
+                                 "Out-of-bounds formula.  Add columns? "))
+                           (user-error
+                            "Missing columns in the table.  Aborting"))))))
+             (org-table-eval-formula nil formula t t t t)))
+         ;; Clean up marker.
+         (set-marker end nil)))
        (unless noalign
          (when org-table-may-need-update (org-table-align))
          (when all
@@ -3597,7 +3250,6 @@ Parameters get priority."
     ["Standard Refs (B3 instead of @3$2)" org-table-fedit-toggle-ref-type
      :style toggle :selected org-table-buffer-is-an]))
 
-(defvar org-pos)
 (defvar org-table--fedit-source nil
   "Position of the TBLFM line being edited.")
 
@@ -3830,44 +3482,47 @@ minutes or seconds."
   "Shift the reference at point one row/hline up."
   (interactive)
   (org-table-fedit-shift-reference 'up))
+
 (defun org-table-fedit-ref-down ()
   "Shift the reference at point one row/hline down."
   (interactive)
   (org-table-fedit-shift-reference 'down))
+
 (defun org-table-fedit-ref-left ()
   "Shift the reference at point one field to the left."
   (interactive)
   (org-table-fedit-shift-reference 'left))
+
 (defun org-table-fedit-ref-right ()
   "Shift the reference at point one field to the right."
   (interactive)
   (org-table-fedit-shift-reference 'right))
 
+(defun org-table--rematch-and-replace (n &optional decr hline)
+  "Re-match the group N, and replace it with the shifted reference."
+  (or (match-end n) (user-error "Cannot shift reference in this direction"))
+  (goto-char (match-beginning n))
+  (and (looking-at (regexp-quote (match-string n)))
+       (replace-match (org-table-shift-refpart (match-string 0) decr hline)
+                     t t)))
+
 (defun org-table-fedit-shift-reference (dir)
   (cond
    ((org-in-regexp "\\(\\<[a-zA-Z]\\)&")
     (if (memq dir '(left right))
-       (org-rematch-and-replace 1 (eq dir 'left))
+       (org-table--rematch-and-replace 1 (eq dir 'left))
       (user-error "Cannot shift reference in this direction")))
    ((org-in-regexp "\\(\\<[a-zA-Z]\\{1,2\\}\\)\\([0-9]+\\)")
     ;; A B3-like reference
     (if (memq dir '(up down))
-       (org-rematch-and-replace 2 (eq dir 'up))
-      (org-rematch-and-replace 1 (eq dir 'left))))
+       (org-table--rematch-and-replace 2 (eq dir 'up))
+      (org-table--rematch-and-replace 1 (eq dir 'left))))
    ((org-in-regexp
      
"\\(@\\|\\.\\.\\)\\([-+]?\\(I+\\>\\|[0-9]+\\)\\)\\(\\$\\([-+]?[0-9]+\\)\\)?")
     ;; An internal reference
     (if (memq dir '(up down))
-       (org-rematch-and-replace 2 (eq dir 'up) (match-end 3))
-      (org-rematch-and-replace 5 (eq dir 'left))))))
-
-(defun org-rematch-and-replace (n &optional decr hline)
-  "Re-match the group N, and replace it with the shifted reference."
-  (or (match-end n) (user-error "Cannot shift reference in this direction"))
-  (goto-char (match-beginning n))
-  (and (looking-at (regexp-quote (match-string n)))
-       (replace-match (org-table-shift-refpart (match-string 0) decr hline)
-                     t t)))
+       (org-table--rematch-and-replace 2 (eq dir 'up) (match-end 3))
+      (org-table--rematch-and-replace 5 (eq dir 'left))))))
 
 (defun org-table-shift-refpart (ref &optional decr hline)
   "Shift a reference part REF.
@@ -3995,7 +3650,1207 @@ With prefix ARG, apply the new formulas to the table."
       (goto-char beg))
      (t nil))))
 
-(defvar org-show-positions nil)
+(defun org-table-fedit-line-up ()
+  "Move cursor one line up in the window showing the table."
+  (interactive)
+  (org-table-fedit-move 'previous-line))
+
+(defun org-table-fedit-line-down ()
+  "Move cursor one line down in the window showing the table."
+  (interactive)
+  (org-table-fedit-move 'next-line))
+
+(defun org-table-fedit-move (command)
+  "Move the cursor in the window showing the table.
+Use COMMAND to do the motion, repeat if necessary to end up in a data line."
+  (let ((org-table-allow-automatic-line-recalculation nil)
+       (pos org-pos) (win (selected-window)) p)
+    (select-window (get-buffer-window (marker-buffer org-pos)))
+    (setq p (point))
+    (call-interactively command)
+    (while (and (org-at-table-p)
+               (org-at-table-hline-p))
+      (call-interactively command))
+    (or (org-at-table-p) (goto-char p))
+    (move-marker pos (point))
+    (select-window win)))
+
+(defun org-table-fedit-scroll (N)
+  (interactive "p")
+  (let ((other-window-scroll-buffer (marker-buffer org-pos)))
+    (scroll-other-window N)))
+
+(defun org-table-fedit-scroll-down (N)
+  (interactive "p")
+  (org-table-fedit-scroll (- N)))
+
+(defun org-table-add-rectangle-overlay (beg end &optional face)
+  "Add a new overlay."
+  (let ((ov (make-overlay beg end)))
+    (overlay-put ov 'face (or face 'secondary-selection))
+    (push ov org-table-rectangle-overlays)))
+
+(defun org-table-highlight-rectangle (&optional beg end face)
+  "Highlight rectangular region in a table.
+When buffer positions BEG and END are provided, use them to
+delimit the region to highlight.  Otherwise, refer to point.  Use
+FACE, when non-nil, for the highlight."
+  (let* ((beg (or beg (point)))
+        (end (or end (point)))
+        (b (min beg end))
+        (e (max beg end))
+        (start-coordinates
+         (save-excursion
+           (goto-char b)
+           (cons (line-beginning-position) (org-table-current-column))))
+        (end-coordinates
+         (save-excursion
+           (goto-char e)
+           (cons (line-beginning-position) (org-table-current-column)))))
+    (when (boundp 'org-show-positions)
+      (setq org-show-positions (cons b (cons e org-show-positions))))
+    (goto-char (car start-coordinates))
+    (let ((column-start (min (cdr start-coordinates) (cdr end-coordinates)))
+         (column-end (max (cdr start-coordinates) (cdr end-coordinates)))
+         (last-row (car end-coordinates)))
+      (while (<= (point) last-row)
+       (when (looking-at org-table-dataline-regexp)
+         (org-table-goto-column column-start)
+         (skip-chars-backward "^|\n")
+         (let ((p (point)))
+           (org-table-goto-column column-end)
+           (skip-chars-forward "^|\n")
+           (org-table-add-rectangle-overlay p (point) face)))
+       (forward-line)))
+    (goto-char (car start-coordinates)))
+  (add-hook 'before-change-functions #'org-table-remove-rectangle-highlight))
+
+(defun org-table-remove-rectangle-highlight (&rest _ignore)
+  "Remove the rectangle overlays."
+  (unless org-inhibit-highlight-removal
+    (remove-hook 'before-change-functions 
'org-table-remove-rectangle-highlight)
+    (mapc 'delete-overlay org-table-rectangle-overlays)
+    (setq org-table-rectangle-overlays nil)))
+
+(defvar-local org-table-coordinate-overlays nil
+  "Collects the coordinate grid overlays, so that they can be removed.")
+
+(defun org-table-overlay-coordinates ()
+  "Add overlays to the table at point, to show row/column coordinates."
+  (interactive)
+  (mapc 'delete-overlay org-table-coordinate-overlays)
+  (setq org-table-coordinate-overlays nil)
+  (save-excursion
+    (let ((id 0) (ih 0) hline eol str ov)
+      (goto-char (org-table-begin))
+      (while (org-at-table-p)
+       (setq eol (point-at-eol))
+       (setq ov (make-overlay (point-at-bol) (1+ (point-at-bol))))
+       (push ov org-table-coordinate-overlays)
+       (setq hline (looking-at org-table-hline-regexp))
+       (setq str (if hline (format "I*%-2d" (setq ih (1+ ih)))
+                   (format "%4d" (setq id (1+ id)))))
+       (org-overlay-before-string ov str 'org-special-keyword 'evaporate)
+       (when hline
+         (let ((ic 0))
+           (while (re-search-forward "[+|]\\(-+\\)" eol t)
+             (cl-incf ic)
+             (let* ((beg (1+ (match-beginning 0)))
+                    (s1 (format "$%d" ic))
+                    (s2 (org-number-to-letters ic))
+                    (str (if (eq t org-table-use-standard-references) s2 s1))
+                    (ov (make-overlay beg (+ beg (length str)))))
+               (push ov org-table-coordinate-overlays)
+               (org-overlay-display ov str 'org-special-keyword 'evaporate)))))
+       (forward-line)))))
+
+;;;###autoload
+(defun org-table-toggle-coordinate-overlays ()
+  "Toggle the display of Row/Column numbers in tables."
+  (interactive)
+  (setq org-table-overlay-coordinates (not org-table-overlay-coordinates))
+  (message "Tables Row/Column numbers display turned %s"
+          (if org-table-overlay-coordinates "on" "off"))
+  (when (and (org-at-table-p) org-table-overlay-coordinates)
+    (org-table-align))
+  (unless org-table-overlay-coordinates
+    (mapc 'delete-overlay org-table-coordinate-overlays)
+    (setq org-table-coordinate-overlays nil)))
+
+;;;###autoload
+(defun org-table-toggle-formula-debugger ()
+  "Toggle the formula debugger in tables."
+  (interactive)
+  (setq org-table-formula-debug (not org-table-formula-debug))
+  (message "Formula debugging has been turned %s"
+          (if org-table-formula-debug "on" "off")))
+
+
+;;; Columns Shrinking
+
+(defun org-table--shrunk-field ()
+  "Non-nil if current field is narrowed.
+When non-nil, return the overlay narrowing the field."
+  (cl-some (lambda (o)
+            (and (eq 'table-column-hide (overlay-get o 'org-overlay-type))
+                 o))
+          (overlays-at (save-excursion
+                         (skip-chars-forward (if (org-at-table-hline-p) "^+|"
+                                               "^|")
+                                             (line-end-position))
+                         (1- (point))))))
+
+(defun org-table--list-shrunk-columns ()
+  "List currently shrunk columns in table at point."
+  (save-excursion
+    ;; We really check shrunk columns in current row only.  It could
+    ;; be wrong if all rows do not contain the same number of columns
+    ;; (i.e. the table is not properly aligned).  As a consequence,
+    ;; some columns may not be shrunk again upon aligning the table.
+    ;;
+    ;; For example, in the following table, cursor is on first row and
+    ;; "<>" indicates a shrunk column.
+    ;;
+    ;; | |
+    ;; | | <> |
+    ;;
+    ;; Aligning table from the first row will not shrink again the
+    ;; second row, which was not visible initially.
+    ;;
+    ;; However, fixing it requires to check every row, which may be
+    ;; slow on large tables.  Moreover, the hindrance of this
+    ;; pathological case is very limited.
+    (beginning-of-line)
+    (search-forward "|")
+    (let ((separator (if (org-at-table-hline-p) "+" "|"))
+         (column 1)
+         (shrunk (and (org-table--shrunk-field) (list 1)))
+         (end (line-end-position)))
+      (while (search-forward separator end t)
+       (cl-incf column)
+       (when (org-table--shrunk-field) (push column shrunk)))
+      (nreverse shrunk))))
+
+(defun org-table--make-shrinking-overlay (start end display field &optional 
pre)
+  "Create an overlay to shrink text between START and END.
+
+Use string DISPLAY instead of the real text between the two
+buffer positions.  FIELD is the real contents of the field, as
+a string, or nil.  It is meant to be displayed upon moving the
+mouse onto the overlay.
+
+When optional argument PRE is non-nil, assume the overlay is
+located at the beginning of the field, and prepend
+`org-table-separator-space' to it.  Otherwise, concatenate
+`org-table-shrunk-column-indicator' at its end.
+
+Return the overlay."
+  (let ((show-before-edit
+        (lambda (o &rest _)
+          ;; Removing one overlay removes all other overlays in the
+          ;; same column.
+          (mapc #'delete-overlay
+                (cdr (overlay-get o 'org-table-column-overlays)))))
+       (o (make-overlay start end)))
+    (overlay-put o 'insert-behind-hooks (list show-before-edit))
+    (overlay-put o 'insert-in-front-hooks (list show-before-edit))
+    (overlay-put o 'modification-hooks (list show-before-edit))
+    (overlay-put o 'org-overlay-type 'table-column-hide)
+    (when (stringp field) (overlay-put o 'help-echo field))
+    ;; Make sure overlays stays on top of table coordinates overlays.
+    ;; See `org-table-overlay-coordinates'.
+    (overlay-put o 'priority 1)
+    (let ((d (if pre (concat org-table-separator-space display)
+              (concat display org-table-shrunk-column-indicator))))
+      (org-overlay-display o d 'org-table t))
+    o))
+
+(defun org-table--shrink-field (width align start end contents)
+  "Shrink a table field to a specified width.
+
+WIDTH is an integer representing the number of characters to
+display, in addition to `org-table-shrunk-column-indicator'.
+ALIGN is the alignment of the current column, as either \"l\",
+\"c\" or \"r\".  START and END are, respectively, the beginning
+and ending positions of the field.  CONTENTS is its trimmed
+contents, as a string, or `hline' for table rules.
+
+Real field is hidden under one or two overlays.  They have the
+following properties:
+
+  `org-overlay-type'
+
+    Set to `table-column-hide'.  Used to identify overlays
+    responsible for shrinking columns in a table.
+
+  `org-table-column-overlays'
+
+    It is a list with the pattern (siblings . COLUMN-OVERLAYS)
+    where COLUMN-OVERLAYS is the list of all overlays hiding the
+    same column.
+
+Whenever the text behind or next to the overlay is modified, all
+the overlays in the column are deleted, effectively displaying
+the column again.
+
+Return a list of overlays hiding the field, or nil if field is
+already hidden."
+  (cond
+   ((= start end) nil)                 ;no field to narrow
+   ((org-table--shrunk-field) nil)     ;already shrunk
+   ((= 0 width)                                ;shrink to one character
+    (list (org-table--make-shrinking-overlay
+          start end "" (if (eq 'hline contents) "" contents))))
+   ((eq contents 'hline)
+    (list (org-table--make-shrinking-overlay
+          start end (make-string (1+ width) ?-) "")))
+   ((equal contents "")                        ;no contents to hide
+    (list
+     (let ((w (org-string-width (buffer-substring start end)))
+          ;; We really want WIDTH + 2 whitespace, to include blanks
+          ;; around fields.
+          (full (+ 2 width)))
+       (if (<= w full)
+          (org-table--make-shrinking-overlay
+           (1- end) end (make-string (- full w) ?\s) "")
+        (org-table--make-shrinking-overlay (- end (- w full) 1) end "" "")))))
+   (t
+    ;; If the field is not empty, display exactly WIDTH characters.
+    ;; It can mean to partly hide the field, or extend it with virtual
+    ;; blanks.  To that effect, we use one or two overlays.  The
+    ;; first, optional, one may add or hide white spaces before the
+    ;; contents of the field.  The other, mandatory, one cuts the
+    ;; field or displays white spaces at the end of the field.  It
+    ;; also always displays `org-table-shrunk-column-indicator'.
+    (let* ((lead (org-with-point-at start (skip-chars-forward " ")))
+          (trail (org-with-point-at end (abs (skip-chars-backward " "))))
+          (contents-width (org-string-width
+                           (buffer-substring (+ start lead) (- end trail)))))
+      (cond
+       ;; Contents are too large to fit in WIDTH character.  Limit, if
+       ;; possible, blanks at the beginning of the field to a single
+       ;; white space, and cut the field at an appropriate location.
+       ((<= width contents-width)
+       (let ((pre
+              (and (> lead 0)
+                   (org-table--make-shrinking-overlay
+                    start (+ start lead) "" contents t)))
+             (post
+              (org-table--make-shrinking-overlay
+               ;; Find cut location so that WIDTH characters are
+               ;; visible using dichotomy.
+               (let* ((begin (+ start lead))
+                      (lower begin)
+                      (upper (1- end))
+                      ;; Compensate the absence of leading space,
+                      ;; thus preserving alignment.
+                      (width (if (= lead 0) (1+ width) width)))
+                 (catch :exit
+                   (while (> (- upper lower) 1)
+                     (let ((mean (+ (ash lower -1)
+                                    (ash upper -1)
+                                    (logand lower upper 1))))
+                       (pcase (org-string-width (buffer-substring begin mean))
+                         ((pred (= width)) (throw :exit mean))
+                         ((pred (< width)) (setq upper mean))
+                         (_ (setq lower mean)))))
+                   upper))
+               end "" contents)))
+         (if pre (list pre post) (list post))))
+       ;; Contents fit it WIDTH characters.  First compute number of
+       ;; white spaces needed on each side of contents, then expand or
+       ;; compact blanks on each side of the field in order to
+       ;; preserve width and obey to alignment constraints.
+       (t
+       (let* ((required (- width contents-width))
+              (before
+               (pcase align
+                 ;; Compensate the absence of leading space, thus
+                 ;; preserving alignment.
+                 ((guard (= lead 0)) -1)
+                 ("l" 0)
+                 ("r" required)
+                 ("c" (/ required 2))))
+              (after (- required before))
+              (pre
+               (pcase (1- lead)
+                 ((or (guard (= lead 0)) (pred (= before))) nil)
+                 ((pred (< before))
+                  (org-table--make-shrinking-overlay
+                   start (+ start (- lead before)) "" contents t))
+                 (_
+                  (org-table--make-shrinking-overlay
+                   start (1+ start)
+                   (make-string (- before (1- lead)) ?\s)
+                   contents t))))
+              (post
+               (pcase (1- trail)
+                 ((pred (= after))
+                  (org-table--make-shrinking-overlay (1- end) end "" contents))
+                 ((pred (< after))
+                  (org-table--make-shrinking-overlay
+                   (+ after (- end trail)) end "" contents))
+                 (_
+                  (org-table--make-shrinking-overlay
+                   (1- end) end
+                   (make-string (- after (1- trail)) ?\s)
+                   contents)))))
+         (if pre (list pre post) (list post)))))))))
+
+(defun org-table--read-column-selection (select max)
+  "Read column selection select as a list of numbers.
+
+SELECT is a string containing column ranges, separated by white
+space characters, see `org-table-hide-column' for details.  MAX
+is the maximum column number.
+
+Return value is a sorted list of numbers.  Ignore any number
+outside of the [1;MAX] range."
+  (catch :all
+    (sort
+     (delete-dups
+      (cl-mapcan
+       (lambda (s)
+        (cond
+         ((member s '("-" "1-")) (throw :all (number-sequence 1 max)))
+         ((string-match-p "\\`[0-9]+\\'" s)
+          (let ((n (string-to-number s)))
+            (and (> n 0) (<= n max) (list n))))
+         ((string-match "\\`\\([0-9]+\\)?-\\([0-9]+\\)?\\'" s)
+          (let ((n (match-string 1 s))
+                (m (match-string 2 s)))
+            (number-sequence (if n (max 1 (string-to-number n))
+                               1)
+                             (if m (min max (string-to-number m))
+                               max))))
+         (t nil)))                     ;invalid specification
+       (split-string select)))
+     #'<)))
+
+(defun org-table--shrink-columns (columns beg end)
+  "Shrink COLUMNS in a table.
+COLUMNS is a sorted list of column numbers.  BEG and END are,
+respectively, the beginning position and the end position of the
+table."
+  (org-with-wide-buffer
+   (org-font-lock-ensure beg end)
+   (dolist (c columns)
+     (goto-char beg)
+     (let ((align nil)
+          (width nil)
+          (fields nil))
+       (while (< (point) end)
+        (catch :continue
+          (let* ((hline? (org-at-table-hline-p))
+                 (separator (if hline? "+" "|")))
+            ;; Move to COLUMN.
+            (search-forward "|")
+            (or (= c 1)                ;already there
+                (search-forward separator (line-end-position) t (1- c))
+                (throw :continue nil)) ;skip invalid columns
+            ;; Extract boundaries and contents from current field.
+            ;; Also set the column's width if we encounter a width
+            ;; cookie for the first time.
+            (let* ((start (point))
+                   (end (progn
+                          (skip-chars-forward (concat "^|" separator)
+                                              (line-end-position))
+                          (point)))
+                   (contents (if hline? 'hline
+                               (org-trim (buffer-substring start end)))))
+              (push (list start end contents) fields)
+              (when (and (not hline?)
+                         (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)>\\'"
+                                       contents))
+                (unless align (setq align (match-string 1 contents)))
+                (unless width
+                  (setq width (string-to-number (match-string 2 
contents))))))))
+        (forward-line))
+       ;; Link overlays for current field to the other overlays in the
+       ;; same column.
+       (let ((chain (list 'siblings)))
+        (dolist (field fields)
+          (dolist (new (apply #'org-table--shrink-field
+                              (or width 0) (or align "l") field))
+            (push new (cdr chain))
+            (overlay-put new 'org-table-column-overlays chain))))))))
+
+;;;###autoload
+(defun org-table-toggle-column-width (&optional arg)
+  "Shrink or expand current column in an Org table.
+
+If a width cookie specifies a width W for the column, the first
+W visible characters are displayed.  Otherwise, the column is
+shrunk to a single character.
+
+When point is before the first column or after the last one, ask
+for the columns to shrink or expand, as a list of ranges.
+A column range can be one of the following patterns:
+
+  N    column N only
+  N-M  every column between N and M (both inclusive)
+  N-   every column between N (inclusive) and the last column
+  -M   every column between the first one and M (inclusive)
+  -    every column
+
+When optional argument ARG is a string, use it as white space
+separated list of column ranges.
+
+When called with `\\[universal-argument]' prefix, call \
+`org-table-shrink', i.e.,
+shrink columns with a width cookie and expand the others.
+
+When called with `\\[universal-argument] \\[universal-argument]' \
+prefix, expand all columns."
+  (interactive "P")
+  (unless (org-at-table-p) (user-error "Not in a table"))
+  (let* ((begin (org-table-begin))
+        (end (org-table-end))
+        ;; Compute an upper bound for the number of columns.
+        ;; Nonexistent columns are ignored anyway.
+        (max-columns (/ (- (line-end-position) (line-beginning-position)) 2))
+        (shrunk (org-table--list-shrunk-columns))
+        (columns
+         (pcase arg
+           (`nil
+            (if (save-excursion
+                  (skip-chars-backward "^|" (line-beginning-position))
+                  (or (bolp) (looking-at-p "[ \t]*$")))
+                ;; Point is either before first column or past last
+                ;; one.  Ask for columns to operate on.
+                (org-table--read-column-selection
+                 (read-string "Column ranges (e.g. 2-4 6-): ")
+                 max-columns)
+              (list (org-table-current-column))))
+           ((pred stringp) (org-table--read-column-selection arg max-columns))
+           ((or `(4) `(16)) nil)
+           (_ (user-error "Invalid argument: %S" arg)))))
+    (pcase arg
+      (`(4) (org-table-shrink begin end))
+      (`(16) (org-table-expand begin end))
+      (_
+       (org-table-expand begin end)
+       (org-table--shrink-columns
+       (cl-set-exclusive-or columns shrunk) begin end)))))
+
+;;;###autoload
+(defun org-table-shrink (&optional begin end)
+  "Shrink all columns with a width cookie in the table at point.
+
+Columns without a width cookie are expanded.
+
+Optional arguments BEGIN and END, when non-nil, specify the
+beginning and end position of the current table."
+  (interactive)
+  (unless (or begin (org-at-table-p)) (user-error "Not at a table"))
+  (org-with-wide-buffer
+   (let ((begin (or begin (org-table-begin)))
+        (end (or end (org-table-end)))
+        (regexp "|[ \t]*<[lrc]?[0-9]+>[ \t]*\\(|\\|$\\)")
+        (columns))
+     (goto-char begin)
+     (while (re-search-forward regexp end t)
+       (goto-char (match-beginning 1))
+       (cl-pushnew (org-table-current-column) columns))
+     (org-table-expand begin end)
+     ;; Make sure invisible characters in the table are at the right
+     ;; place since column widths take them into account.
+     (org-font-lock-ensure begin end)
+     (org-table--shrink-columns (sort columns #'<) begin end))))
+
+;;;###autoload
+(defun org-table-expand (&optional begin end)
+  "Expand all columns in the table at point.
+Optional arguments BEGIN and END, when non-nil, specify the
+beginning and end position of the current table."
+  (interactive)
+  (unless (or begin (org-at-table-p)) (user-error "Not at a table"))
+  (org-with-wide-buffer
+   (let ((begin (or begin (org-table-begin)))
+        (end (or end (org-table-end))))
+     (remove-overlays begin end 'org-overlay-type 'table-column-hide))))
+
+
+;;; Generic Tools
+
+;;;###autoload
+(defun org-table-map-tables (f &optional quietly)
+  "Apply function F to the start of all tables in the buffer."
+  (org-with-point-at 1
+    (while (re-search-forward org-table-line-regexp nil t)
+      (let ((table (org-element-lineage (org-element-at-point) '(table) t)))
+       (when table
+         (unless quietly
+           (message "Mapping tables: %d%%"
+                    (floor (* 100.0 (point)) (buffer-size))))
+         (goto-char (org-element-property :post-affiliated table))
+         (let ((end (copy-marker (org-element-property :end table))))
+           (unwind-protect
+               (progn (funcall f) (goto-char end))
+             (set-marker end nil)))))))
+  (unless quietly (message "Mapping tables: done")))
+
+;;;###autoload
+(defun org-table-export (&optional file format)
+  "Export table to a file, with configurable format.
+Such a file can be imported into usual spreadsheet programs.
+
+FILE can be the output file name.  If not given, it will be taken
+from a TABLE_EXPORT_FILE property in the current entry or higher
+up in the hierarchy, or the user will be prompted for a file
+name.  FORMAT can be an export format, of the same kind as it
+used when `-mode' sends a table in a different format.
+
+The command suggests a format depending on TABLE_EXPORT_FORMAT,
+whether it is set locally or up in the hierarchy, then on the
+extension of the given file name, and finally on the variable
+`org-table-export-default-format'."
+  (interactive)
+  (unless (org-at-table-p) (user-error "No table at point"))
+  (org-table-align)           ; Make sure we have everything we need.
+  (let ((file (or file (org-entry-get (point) "TABLE_EXPORT_FILE" t))))
+    (unless file
+      (setq file (read-file-name "Export table to: "))
+      (unless (or (not (file-exists-p file))
+                 (y-or-n-p (format "Overwrite file %s? " file)))
+       (user-error "File not written")))
+    (when (file-directory-p file)
+      (user-error "This is a directory path, not a file"))
+    (when (and (buffer-file-name (buffer-base-buffer))
+              (file-equal-p
+               (file-truename file)
+               (file-truename (buffer-file-name (buffer-base-buffer)))))
+      (user-error "Please specify a file name that is different from current"))
+    (let ((fileext (concat (file-name-extension file) "$"))
+         (format (or format (org-entry-get (point) "TABLE_EXPORT_FORMAT" t))))
+      (unless format
+       (let* ((formats '("orgtbl-to-tsv" "orgtbl-to-csv" "orgtbl-to-latex"
+                         "orgtbl-to-html" "orgtbl-to-generic"
+                         "orgtbl-to-texinfo" "orgtbl-to-orgtbl"
+                         "orgtbl-to-unicode"))
+              (deffmt-readable
+                (replace-regexp-in-string
+                 "\t" "\\t"
+                 (replace-regexp-in-string
+                  "\n" "\\n"
+                  (or (car (delq nil
+                                 (mapcar
+                                  (lambda (f)
+                                    (and (string-match-p fileext f) f))
+                                  formats)))
+                      org-table-export-default-format)
+                  t t) t t)))
+         (setq format
+               (org-completing-read
+                "Format: " formats nil nil deffmt-readable))))
+      (if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format)
+         (let ((transform (intern (match-string 1 format)))
+               (params (and (match-end 2)
+                            (read (concat "(" (match-string 2 format) ")"))))
+               (table (org-table-to-lisp
+                       (buffer-substring-no-properties
+                        (org-table-begin) (org-table-end)))))
+           (unless (fboundp transform)
+             (user-error "No such transformation function %s" transform))
+           (let (buf)
+             (with-current-buffer (find-file-noselect file)
+               (setq buf (current-buffer))
+               (erase-buffer)
+               (fundamental-mode)
+               (insert (funcall transform table params) "\n")
+               (save-buffer))
+             (kill-buffer buf))
+           (message "Export done."))
+       (user-error "TABLE_EXPORT_FORMAT invalid")))))
+
+;;;###autoload
+(defun org-table--align-field (field width align)
+  "Format FIELD according to column WIDTH and alignment ALIGN.
+FIELD is a string.  WIDTH is a number.  ALIGN is either \"c\",
+\"l\" or\"r\"."
+  (let* ((spaces (- width (org-string-width field)))
+        (prefix (pcase align
+                  ("l" "")
+                  ("r" (make-string spaces ?\s))
+                  ("c" (make-string (/ spaces 2) ?\s))))
+        (suffix (make-string (- spaces (length prefix)) ?\s)))
+    (concat org-table-separator-space
+           prefix
+           field
+           suffix
+           org-table-separator-space)))
+
+(defun org-table-align ()
+  "Align the table at point by aligning all vertical bars."
+  (interactive)
+  (let ((beg (org-table-begin))
+       (end (copy-marker (org-table-end))))
+    (org-table-save-field
+     ;; Make sure invisible characters in the table are at the right
+     ;; place since column widths take them into account.
+     (org-font-lock-ensure beg end)
+     (move-marker org-table-aligned-begin-marker beg)
+     (move-marker org-table-aligned-end-marker end)
+     (goto-char beg)
+     (org-table-with-shrunk-columns
+      (let* ((indent (progn (looking-at "[ \t]*") (match-string 0)))
+            ;; Table's rows as lists of fields.  Rules are replaced
+            ;; by nil.  Trailing spaces are removed.
+            (fields (mapcar
+                     (lambda (l)
+                       (and (not (string-match-p org-table-hline-regexp l))
+                            (org-split-string l "[ \t]*|[ \t]*")))
+                     (split-string (buffer-substring beg end) "\n" t)))
+            ;; Compute number of columns.  If the table contains no
+            ;; field, create a default table and bail out.
+            (columns-number
+             (if fields (apply #'max (mapcar #'length fields))
+               (kill-region beg end)
+               (org-table-create org-table-default-size)
+               (user-error "Empty table - created default table")))
+            (widths nil)
+            (alignments nil))
+       ;; Compute alignment and width for each column.
+       (dotimes (i columns-number)
+         (let* ((max-width 1)
+                (fixed-align? nil)
+                (numbers 0)
+                (non-empty 0))
+           (dolist (row fields)
+             (let ((cell (or (nth i row) "")))
+               (setq max-width (max max-width (org-string-width cell)))
+               (cond (fixed-align? nil)
+                     ((equal cell "") nil)
+                     ((string-match "\\`<\\([lrc]\\)[0-9]*>\\'" cell)
+                      (setq fixed-align? (match-string 1 cell)))
+                     (t
+                      (cl-incf non-empty)
+                      (when (string-match-p org-table-number-regexp cell)
+                        (cl-incf numbers))))))
+           (push max-width widths)
+           (push (cond
+                  (fixed-align?)
+                  ((>= numbers (* org-table-number-fraction non-empty)) "r")
+                  (t "l"))
+                 alignments)))
+       (setq widths (nreverse widths))
+       (setq alignments (nreverse alignments))
+       ;; Store alignment of this table, for later editing of single
+       ;; fields.
+       (setq org-table-last-alignment alignments)
+       (setq org-table-last-column-widths widths)
+       ;; Build new table rows.  Only replace rows that actually
+       ;; changed.
+       (dolist (row fields)
+         (let ((previous (buffer-substring (point) (line-end-position)))
+               (new
+                (format "%s|%s|"
+                        indent
+                        (if (null row) ;horizontal rule
+                            (mapconcat (lambda (w) (make-string (+ 2 w) ?-))
+                                       widths
+                                       "+")
+                          (let ((cells ;add missing fields
+                                 (append row
+                                         (make-list (- columns-number
+                                                       (length row))
+                                                    ""))))
+                            (mapconcat #'identity
+                                       (cl-mapcar #'org-table--align-field
+                                                  cells
+                                                  widths
+                                                  alignments)
+                                       "|"))))))
+           (if (equal new previous)
+               (forward-line)
+             (insert new "\n")
+             (delete-region (point) (line-beginning-position 2)))))
+       (set-marker end nil)
+       (when org-table-overlay-coordinates (org-table-overlay-coordinates))
+       (setq org-table-may-need-update nil))))))
+
+;;;###autoload
+(defun org-table-justify-field-maybe (&optional new)
+  "Justify the current field, text to left, number to right.
+Optional argument NEW may specify text to replace the current field content."
+  (cond
+   ((and (not new) org-table-may-need-update)) ; Realignment will happen anyway
+   ((org-at-table-hline-p))
+   ((and (not new)
+        (or (not (eq (marker-buffer org-table-aligned-begin-marker)
+                     (current-buffer)))
+            (< (point) org-table-aligned-begin-marker)
+            (>= (point) org-table-aligned-end-marker)))
+    ;; This is not the same table, force a full re-align.
+    (setq org-table-may-need-update t))
+   (t
+    ;; Realign the current field, based on previous full realign.
+    (let ((pos (point))
+         (col (org-table-current-column)))
+      (when (> col 0)
+       (skip-chars-backward "^|")
+       (if (not (looking-at " *\\([^|\n]*?\\) *\\(|\\|$\\)"))
+           (setq org-table-may-need-update t)
+         (let* ((align (nth (1- col) org-table-last-alignment))
+                (width (nth (1- col) org-table-last-column-widths))
+                (cell (match-string 0))
+                (field (match-string 1))
+                (properly-closed? (/= (match-beginning 2) (match-end 2)))
+                (new-cell
+                 (save-match-data
+                   (cond (org-table-may-need-update
+                          (format " %s |" (or new field)))
+                         ((not properly-closed?)
+                          (setq org-table-may-need-update t)
+                          (format " %s |" (or new field)))
+                         ((not new)
+                          (concat (org-table--align-field field width align)
+                                  "|"))
+                         ((<= (org-string-width new) width)
+                          (concat (org-table--align-field new width align)
+                                  "|"))
+                         (t
+                          (setq org-table-may-need-update t)
+                          (format " %s |" new))))))
+           (unless (equal new-cell cell)
+             (let (org-table-may-need-update)
+               (replace-match new-cell t t)))
+           (goto-char pos))))))))
+
+;;;###autoload
+(defun org-table-sort-lines
+    (&optional with-case sorting-type getkey-func compare-func interactive?)
+  "Sort table lines according to the column at point.
+
+The position of point indicates the column to be used for
+sorting, and the range of lines is the range between the nearest
+horizontal separator lines, or the entire table of no such lines
+exist.  If point is before the first column, you will be prompted
+for the sorting column.  If there is an active region, the mark
+specifies the first line and the sorting column, while point
+should be in the last line to be included into the sorting.
+
+The command then prompts for the sorting type which can be
+alphabetically, numerically, or by time (as given in a time stamp
+in the field, or as a HH:MM value).  Sorting in reverse order is
+also possible.
+
+With prefix argument WITH-CASE, alphabetic sorting will be case-sensitive
+if the locale allows for it.
+
+If SORTING-TYPE is specified when this function is called from a Lisp
+program, no prompting will take place.  SORTING-TYPE must be a character,
+any of (?a ?A ?n ?N ?t ?T ?f ?F) where the capital letters indicate that
+sorting should be done in reverse order.
+
+If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies
+a function to be called to extract the key.  It must return a value
+that is compatible with COMPARE-FUNC, the function used to compare
+entries.
+
+A non-nil value for INTERACTIVE? is used to signal that this
+function is being called interactively."
+  (interactive (list current-prefix-arg nil nil nil t))
+  (when (org-region-active-p) (goto-char (region-beginning)))
+  ;; Point must be either within a field or before a data line.
+  (save-excursion
+    (skip-chars-backward " \t")
+    (when (bolp) (search-forward "|" (line-end-position) t))
+    (org-table-check-inside-data-field))
+  ;; Set appropriate case sensitivity and column used for sorting.
+  (let ((column (let ((c (org-table-current-column)))
+                 (cond ((> c 0) c)
+                       (interactive?
+                        (read-number "Use column N for sorting: "))
+                       (t 1))))
+       (sorting-type
+        (or sorting-type
+            (read-char-exclusive "Sort Table: [a]lphabetic, [n]umeric, \
+\[t]ime, [f]unc.  A/N/T/F means reversed: ")))
+       (start (org-table-begin))
+       (end (org-table-end)))
+    (save-restriction
+      ;; Narrow buffer to appropriate sorting area.
+      (if (org-region-active-p)
+         (progn (goto-char (region-beginning))
+                (narrow-to-region
+                 (point)
+                 (save-excursion (goto-char (region-end))
+                                 (line-beginning-position 2))))
+       (narrow-to-region
+        (save-excursion
+          (if (re-search-backward org-table-hline-regexp start t)
+              (line-beginning-position 2)
+            start))
+        (if (save-excursion (re-search-forward org-table-hline-regexp end t))
+            (match-beginning 0)
+          end)))
+      ;; Determine arguments for `sort-subr'.  Also record original
+      ;; position.  `org-table-save-field' cannot help here since
+      ;; sorting is too much destructive.
+      (let* ((coordinates
+             (cons (count-lines (point-min) (line-beginning-position))
+                   (current-column)))
+            (extract-key-from-field
+             ;; Function to be called on the contents of the field
+             ;; used for sorting in the current row.
+             (cl-case sorting-type
+               ((?n ?N) #'string-to-number)
+               ((?a ?A) #'org-sort-remove-invisible)
+               ((?t ?T)
+                (lambda (f)
+                  (cond ((string-match org-ts-regexp-both f)
+                         (float-time
+                          (org-time-string-to-time (match-string 0 f))))
+                        ((org-duration-p f) (org-duration-to-minutes f))
+                        ((string-match "\\<[0-9]+:[0-9]\\{2\\}\\>" f)
+                         (org-duration-to-minutes (match-string 0 f)))
+                        (t 0))))
+               ((?f ?F)
+                (or getkey-func
+                    (and interactive?
+                         (org-read-function "Function for extracting keys: "))
+                    (error "Missing key extractor to sort rows")))
+               (t (user-error "Invalid sorting type `%c'" sorting-type))))
+            (predicate
+             (cl-case sorting-type
+               ((?n ?N ?t ?T) #'<)
+               ((?a ?A) (if with-case #'org-string-collate-lessp
+                          (lambda (s1 s2) (org-string-collate-lessp s1 s2 nil 
t))))
+               ((?f ?F)
+                (or compare-func
+                    (and interactive?
+                         (org-read-function
+                          "Function for comparing keys (empty for default \
+`sort-subr' predicate): "
+                          'allow-empty))))))
+            (shrunk-columns (remq column (org-table--list-shrunk-columns))))
+       (goto-char (point-min))
+       (sort-subr (memq sorting-type '(?A ?N ?T ?F))
+                  (lambda ()
+                    (forward-line)
+                    (while (and (not (eobp))
+                                (not (looking-at org-table-dataline-regexp)))
+                      (forward-line)))
+                  #'end-of-line
+                  (lambda ()
+                    (funcall extract-key-from-field
+                             (org-trim (org-table-get-field column))))
+                  nil
+                  predicate)
+       ;; Hide all columns but the one being sorted.
+       (org-table--shrink-columns shrunk-columns start end)
+       ;; Move back to initial field.
+       (forward-line (car coordinates))
+       (move-to-column (cdr coordinates))))))
+
+(defun org-table-transpose-table-at-point ()
+  "Transpose Org table at point and eliminate hlines.
+So a table like
+
+| 1 | 2 | 4 | 5 |
+|---+---+---+---|
+| a | b | c | d |
+| e | f | g | h |
+
+will be transposed as
+
+| 1 | a | e |
+| 2 | b | f |
+| 4 | c | g |
+| 5 | d | h |
+
+Note that horizontal lines disappear."
+  (interactive)
+  (let* ((table (delete 'hline (org-table-to-lisp)))
+        (dline_old (org-table-current-line))
+        (col_old (org-table-current-column))
+        (contents (mapcar (lambda (_)
+                            (let ((tp table))
+                              (mapcar
+                               (lambda (_)
+                                 (prog1
+                                     (pop (car tp))
+                                   (setq tp (cdr tp))))
+                               table)))
+                          (car table))))
+    (goto-char (org-table-begin))
+    (re-search-forward "|")
+    (backward-char)
+    (delete-region (point) (org-table-end))
+    (insert (mapconcat
+            (lambda(x)
+              (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
+            contents ""))
+    (org-table-goto-line col_old)
+    (org-table-goto-column dline_old))
+  (org-table-align))
+
+;;;###autoload
+(defun org-table-wrap-region (arg)
+  "Wrap several fields in a column like a paragraph.
+This is useful if you'd like to spread the contents of a field over several
+lines, in order to keep the table compact.
+
+If there is an active region, and both point and mark are in the same column,
+the text in the column is wrapped to minimum width for the given number of
+lines.  Generally, this makes the table more compact.  A prefix ARG may be
+used to change the number of desired lines.  For example, \
+`C-2 \\[org-table-wrap-region]'
+formats the selected text to two lines.  If the region was longer than two
+lines, the remaining lines remain empty.  A negative prefix argument reduces
+the current number of lines by that amount.  The wrapped text is pasted back
+into the table.  If you formatted it to more lines than it was before, fields
+further down in the table get overwritten - so you might need to make space in
+the table first.
+
+If there is no region, the current field is split at the cursor position and
+the text fragment to the right of the cursor is prepended to the field one
+line down.
+
+If there is no region, but you specify a prefix ARG, the current field gets
+blank, and the content is appended to the field above."
+  (interactive "P")
+  (org-table-check-inside-data-field)
+  (if (org-region-active-p)
+      ;; There is a region: fill as a paragraph.
+      (let ((start (region-beginning)))
+       (org-table-cut-region (region-beginning) (region-end))
+       (when (> (length (car org-table-clip)) 1)
+         (user-error "Region must be limited to single column"))
+       (let ((nlines (cond ((not arg) (length org-table-clip))
+                           ((< arg 1) (+ (length org-table-clip) arg))
+                           (t arg))))
+         (setq org-table-clip
+               (mapcar #'list
+                       (org-wrap (mapconcat #'car org-table-clip " ")
+                                 nil
+                                 nlines))))
+       (goto-char start)
+       (org-table-paste-rectangle))
+    ;; No region, split the current field at point.
+    (unless (org-get-alist-option org-M-RET-may-split-line 'table)
+      (skip-chars-forward "^\r\n|"))
+    (cond
+     (arg                              ; Combine with field above.
+      (let ((s (org-table-blank-field))
+           (col (org-table-current-column)))
+       (forward-line -1)
+       (while (org-at-table-hline-p) (forward-line -1))
+       (org-table-goto-column col)
+       (skip-chars-forward "^|")
+       (skip-chars-backward " ")
+       (insert " " (org-trim s))
+       (org-table-align)))
+     ((looking-at "\\([^|]+\\)+|")     ; Split field.
+      (let ((s (match-string 1)))
+       (replace-match " |")
+       (goto-char (match-beginning 0))
+       (org-table-next-row)
+       (insert (org-trim s) " ")
+       (org-table-align)))
+     (t (org-table-next-row)))))
+
+(defun org-table--number-for-summing (s)
+  (let (n)
+    (if (string-match "^ *|? *" s)
+       (setq s (replace-match "" nil nil s)))
+    (if (string-match " *|? *$" s)
+       (setq s (replace-match "" nil nil s)))
+    (setq n (string-to-number s))
+    (cond
+     ((and (string-match "0" s)
+          (string-match "\\`[-+ \t0.edED]+\\'" s)) 0)
+     ((string-match "\\`[ \t]+\\'" s) nil)
+     ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?\\'" s)
+      (let ((h (string-to-number (or (match-string 1 s) "0")))
+           (m (string-to-number (or (match-string 2 s) "0")))
+           (s (string-to-number (or (match-string 4 s) "0"))))
+       (if (boundp 'org-timecnt) (setq org-timecnt (1+ org-timecnt)))
+       (* 1.0 (+ h (/ m 60.0) (/ s 3600.0)))))
+     ((equal n 0) nil)
+     (t n))))
+
+;;;###autoload
+(defun org-table-sum (&optional beg end nlast)
+  "Sum numbers in region of current table column.
+The result will be displayed in the echo area, and will be available
+as kill to be inserted with \\[yank].
+
+If there is an active region, it is interpreted as a rectangle and all
+numbers in that rectangle will be summed.  If there is no active
+region and point is located in a table column, sum all numbers in that
+column.
+
+If at least one number looks like a time HH:MM or HH:MM:SS, all other
+numbers are assumed to be times as well (in decimal hours) and the
+numbers are added as such.
+
+If NLAST is a number, only the NLAST fields will actually be summed."
+  (interactive)
+  (save-excursion
+    (let (col (org-timecnt 0) diff h m s org-table-clip)
+      (cond
+       ((and beg end))                 ; beg and end given explicitly
+       ((org-region-active-p)
+       (setq beg (region-beginning) end (region-end)))
+       (t
+       (setq col (org-table-current-column))
+       (goto-char (org-table-begin))
+       (unless (re-search-forward "^[ \t]*|[^-]" nil t)
+         (user-error "No table data"))
+       (org-table-goto-column col)
+       (setq beg (point))
+       (goto-char (org-table-end))
+       (unless (re-search-backward "^[ \t]*|[^-]" nil t)
+         (user-error "No table data"))
+       (org-table-goto-column col)
+       (setq end (point))))
+      (let* ((items (apply 'append (org-table-copy-region beg end)))
+            (items1 (cond ((not nlast) items)
+                          ((>= nlast (length items)) items)
+                          (t (setq items (reverse items))
+                             (setcdr (nthcdr (1- nlast) items) nil)
+                             (nreverse items))))
+            (numbers (delq nil (mapcar #'org-table--number-for-summing
+                                       items1)))
+            (res (apply '+ numbers))
+            (sres (if (= org-timecnt 0)
+                      (number-to-string res)
+                    (setq diff (* 3600 res)
+                          h (floor diff 3600) diff (mod diff 3600)
+                          m (floor diff 60) diff (mod diff 60)
+                          s diff)
+                    (format "%.0f:%02.0f:%02.0f" h m s))))
+       (kill-new sres)
+       (when (called-interactively-p 'interactive)
+         (message (substitute-command-keys
+                   (format "Sum of %d items: %-20s     \
+\(\\[yank] will insert result into buffer)"
+                           (length numbers)
+                           sres))))
+       sres))))
+
+;;;###autoload
+(defun org-table-analyze ()
+  "Analyze table at point and store results.
+
+This function sets up the following dynamically scoped variables:
+
+ `org-table-column-name-regexp',
+ `org-table-column-names',
+ `org-table-current-begin-pos',
+ `org-table-current-line-types',
+ `org-table-current-ncol',
+ `org-table-dlines',
+ `org-table-hlines',
+ `org-table-local-parameters',
+ `org-table-named-field-locations'."
+  (let ((beg (org-table-begin))
+       (end (org-table-end)))
+    (save-excursion
+      (goto-char beg)
+      ;; Extract column names.
+      (setq org-table-column-names nil)
+      (when (save-excursion
+             (re-search-forward "^[ \t]*| *! *\\(|.*\\)" end t))
+       (let ((c 1))
+         (dolist (name (org-split-string (match-string 1) " *| *"))
+           (cl-incf c)
+           (when (string-match "\\`[a-zA-Z][_a-zA-Z0-9]*\\'" name)
+             (push (cons name (int-to-string c)) org-table-column-names)))))
+      (setq org-table-column-names (nreverse org-table-column-names))
+      (setq org-table-column-name-regexp
+           (format "\\$\\(%s\\)\\>"
+                   (regexp-opt (mapcar #'car org-table-column-names) t)))
+      ;; Extract local parameters.
+      (setq org-table-local-parameters nil)
+      (save-excursion
+       (while (re-search-forward "^[ \t]*| *\\$ *\\(|.*\\)" end t)
+         (dolist (field (org-split-string (match-string 1) " *| *"))
+           (when (string-match
+                  "\\`\\([a-zA-Z][_a-zA-Z0-9]*\\|%\\) *= *\\(.*\\)" field)
+             (push (cons (match-string 1 field) (match-string 2 field))
+                   org-table-local-parameters)))))
+      ;; Update named fields locations.  We minimize `count-lines'
+      ;; processing by storing last known number of lines in LAST.
+      (setq org-table-named-field-locations nil)
+      (save-excursion
+       (let ((last (cons (point) 0)))
+         (while (re-search-forward "^[ \t]*| *\\([_^]\\) *\\(|.*\\)" end t)
+           (let ((c (match-string 1))
+                 (fields (org-split-string (match-string 2) " *| *")))
+             (save-excursion
+               (forward-line (if (equal c "_") 1 -1))
+               (let ((fields1
+                      (and (looking-at "^[ \t]*|[^|]*\\(|.*\\)")
+                           (org-split-string (match-string 1) " *| *")))
+                     (line (cl-incf (cdr last) (count-lines (car last) 
(point))))
+                     (col 1))
+                 (setcar last (point)) ; Update last known position.
+                 (while (and fields fields1)
+                   (let ((field (pop fields))
+                         (v (pop fields1)))
+                     (cl-incf col)
+                     (when (and (stringp field)
+                                (stringp v)
+                                (string-match "\\`[a-zA-Z][_a-zA-Z0-9]*\\'"
+                                              field))
+                       (push (cons field v) org-table-local-parameters)
+                       (push (list field line col)
+                             org-table-named-field-locations))))))))))
+      ;; Re-use existing markers when possible.
+      (if (markerp org-table-current-begin-pos)
+         (move-marker org-table-current-begin-pos (point))
+       (setq org-table-current-begin-pos (point-marker)))
+      ;; Analyze the line types.
+      (let ((l 0) hlines dlines types)
+       (while (looking-at "[ \t]*|\\(-\\)?")
+         (push (if (match-end 1) 'hline 'dline) types)
+         (if (match-end 1) (push l hlines) (push l dlines))
+         (forward-line)
+         (cl-incf l))
+       (push 'hline types) ; Add an imaginary extra hline to the end.
+       (setq org-table-current-line-types (apply #'vector (nreverse types)))
+       (setq org-table-dlines (apply #'vector (cons nil (nreverse dlines))))
+       (setq org-table-hlines (apply #'vector (cons nil (nreverse hlines)))))
+      ;; Get the number of columns from the first data line in table.
+      (goto-char beg)
+      (forward-line (aref org-table-dlines 1))
+      (let* ((fields
+             (org-split-string
+              (buffer-substring (line-beginning-position) (line-end-position))
+              "[ \t]*|[ \t]*"))
+            (nfields (length fields))
+            al al2)
+       (setq org-table-current-ncol nfields)
+       (let ((last-dline
+              (aref org-table-dlines (1- (length org-table-dlines)))))
+         (dotimes (i nfields)
+           (let ((column (1+ i)))
+             (push (list (format "LR%d" column) last-dline column) al)
+             (push (cons (format "LR%d" column) (nth i fields)) al2))))
+       (setq org-table-named-field-locations
+             (append org-table-named-field-locations al))
+       (setq org-table-local-parameters
+             (append org-table-local-parameters al2))))))
+
+(defun org-table--force-dataline ()
+  "Move point to the closest data line in a table.
+Raise an error if the table contains no data line.  Preserve
+column when moving point."
+  (unless (org-match-line org-table-dataline-regexp)
+    (let* ((re org-table-dataline-regexp)
+          (column (current-column))
+          (p1 (save-excursion (re-search-forward re (org-table-end) t)))
+          (p2 (save-excursion (re-search-backward re (org-table-begin) t))))
+      (cond ((and p1 p2)
+            (goto-char (if (< (abs (- p1 (point))) (abs (- p2 (point))))
+                           p1
+                         p2)))
+           ((or p1 p2) (goto-char (or p1 p2)))
+           (t (user-error "No table data line around here")))
+      (org-move-to-column column))))
 
 (defun org-table-show-reference (&optional local)
   "Show the location/value of the $ expression at point.
@@ -4056,7 +4911,7 @@ When LOCAL is non-nil, show references for the table at 
point."
            (org-switch-to-buffer-other-window (get-buffer-window
                                                (marker-buffer pos)))))
       (goto-char pos)
-      (org-table-force-dataline)
+      (org-table--force-dataline)
       (let ((table-start
             (if local org-table-current-begin-pos (org-table-begin))))
        (when dest
@@ -4128,158 +4983,8 @@ When LOCAL is non-nil, show references for the table at 
point."
                (set-window-start (selected-window) max)))))
       (select-window win))))
 
-(defun org-table-force-dataline ()
-  "Make sure the cursor is in a dataline in a table."
-  (unless (save-excursion
-           (beginning-of-line 1)
-           (looking-at org-table-dataline-regexp))
-    (let* ((re org-table-dataline-regexp)
-          (p1 (save-excursion (re-search-forward re nil 'move)))
-          (p2 (save-excursion (re-search-backward re nil 'move))))
-      (cond ((and p1 p2)
-            (goto-char (if (< (abs (- p1 (point))) (abs (- p2 (point))))
-                           p1 p2)))
-           ((or p1 p2) (goto-char (or p1 p2)))
-           (t (user-error "No table dataline around here"))))))
-
-(defun org-table-fedit-line-up ()
-  "Move cursor one line up in the window showing the table."
-  (interactive)
-  (org-table-fedit-move 'previous-line))
-
-(defun org-table-fedit-line-down ()
-  "Move cursor one line down in the window showing the table."
-  (interactive)
-  (org-table-fedit-move 'next-line))
-
-(defun org-table-fedit-move (command)
-  "Move the cursor in the window showing the table.
-Use COMMAND to do the motion, repeat if necessary to end up in a data line."
-  (let ((org-table-allow-automatic-line-recalculation nil)
-       (pos org-pos) (win (selected-window)) p)
-    (select-window (get-buffer-window (marker-buffer org-pos)))
-    (setq p (point))
-    (call-interactively command)
-    (while (and (org-at-table-p)
-               (org-at-table-hline-p))
-      (call-interactively command))
-    (or (org-at-table-p) (goto-char p))
-    (move-marker pos (point))
-    (select-window win)))
-
-(defun org-table-fedit-scroll (N)
-  (interactive "p")
-  (let ((other-window-scroll-buffer (marker-buffer org-pos)))
-    (scroll-other-window N)))
-
-(defun org-table-fedit-scroll-down (N)
-  (interactive "p")
-  (org-table-fedit-scroll (- N)))
-
-(defvar org-table-rectangle-overlays nil)
-
-(defun org-table-add-rectangle-overlay (beg end &optional face)
-  "Add a new overlay."
-  (let ((ov (make-overlay beg end)))
-    (overlay-put ov 'face (or face 'secondary-selection))
-    (push ov org-table-rectangle-overlays)))
-
-(defun org-table-highlight-rectangle (&optional beg end face)
-  "Highlight rectangular region in a table.
-When buffer positions BEG and END are provided, use them to
-delimit the region to highlight.  Otherwise, refer to point.  Use
-FACE, when non-nil, for the highlight."
-  (let* ((beg (or beg (point)))
-        (end (or end (point)))
-        (b (min beg end))
-        (e (max beg end))
-        (start-coordinates
-         (save-excursion
-           (goto-char b)
-           (cons (line-beginning-position) (org-table-current-column))))
-        (end-coordinates
-         (save-excursion
-           (goto-char e)
-           (cons (line-beginning-position) (org-table-current-column)))))
-    (when (boundp 'org-show-positions)
-      (setq org-show-positions (cons b (cons e org-show-positions))))
-    (goto-char (car start-coordinates))
-    (let ((column-start (min (cdr start-coordinates) (cdr end-coordinates)))
-         (column-end (max (cdr start-coordinates) (cdr end-coordinates)))
-         (last-row (car end-coordinates)))
-      (while (<= (point) last-row)
-       (when (looking-at org-table-dataline-regexp)
-         (org-table-goto-column column-start)
-         (skip-chars-backward "^|\n")
-         (let ((p (point)))
-           (org-table-goto-column column-end)
-           (skip-chars-forward "^|\n")
-           (org-table-add-rectangle-overlay p (point) face)))
-       (forward-line)))
-    (goto-char (car start-coordinates)))
-  (add-hook 'before-change-functions #'org-table-remove-rectangle-highlight))
-
-(defun org-table-remove-rectangle-highlight (&rest _ignore)
-  "Remove the rectangle overlays."
-  (unless org-inhibit-highlight-removal
-    (remove-hook 'before-change-functions 
'org-table-remove-rectangle-highlight)
-    (mapc 'delete-overlay org-table-rectangle-overlays)
-    (setq org-table-rectangle-overlays nil)))
-
-(defvar-local org-table-coordinate-overlays nil
-  "Collects the coordinate grid overlays, so that they can be removed.")
-
-(defun org-table-overlay-coordinates ()
-  "Add overlays to the table at point, to show row/column coordinates."
-  (interactive)
-  (mapc 'delete-overlay org-table-coordinate-overlays)
-  (setq org-table-coordinate-overlays nil)
-  (save-excursion
-    (let ((id 0) (ih 0) hline eol s1 s2 str ic ov beg)
-      (goto-char (org-table-begin))
-      (while (org-at-table-p)
-       (setq eol (point-at-eol))
-       (setq ov (make-overlay (point-at-bol) (1+ (point-at-bol))))
-       (push ov org-table-coordinate-overlays)
-       (setq hline (looking-at org-table-hline-regexp))
-       (setq str (if hline (format "I*%-2d" (setq ih (1+ ih)))
-                   (format "%4d" (setq id (1+ id)))))
-       (org-overlay-before-string ov str 'org-special-keyword 'evaporate)
-       (when hline
-         (setq ic 0)
-         (while (re-search-forward "[+|]\\(-+\\)" eol t)
-           (setq beg (1+ (match-beginning 0))
-                 ic (1+ ic)
-                 s1 (concat "$" (int-to-string ic))
-                 s2 (org-number-to-letters ic)
-                 str (if (eq org-table-use-standard-references t) s2 s1))
-           (setq ov (make-overlay beg (+ beg (length str))))
-           (push ov org-table-coordinate-overlays)
-           (org-overlay-display ov str 'org-special-keyword 'evaporate)))
-       (beginning-of-line 2)))))
-
-;;;###autoload
-(defun org-table-toggle-coordinate-overlays ()
-  "Toggle the display of Row/Column numbers in tables."
-  (interactive)
-  (setq org-table-overlay-coordinates (not org-table-overlay-coordinates))
-  (message "Tables Row/Column numbers display turned %s"
-          (if org-table-overlay-coordinates "on" "off"))
-  (if (and (org-at-table-p) org-table-overlay-coordinates)
-      (org-table-align))
-  (unless org-table-overlay-coordinates
-    (mapc 'delete-overlay org-table-coordinate-overlays)
-    (setq org-table-coordinate-overlays nil)))
-
-;;;###autoload
-(defun org-table-toggle-formula-debugger ()
-  "Toggle the formula debugger in tables."
-  (interactive)
-  (setq org-table-formula-debug (not org-table-formula-debug))
-  (message "Formula debugging has been turned %s"
-          (if org-table-formula-debug "on" "off")))
-
-;;; The orgtbl minor mode
+
+;;; The Orgtbl minor mode
 
 ;; Define a minor mode which can be used in other modes in order to
 ;; integrate the Org table editor.
@@ -4308,7 +5013,6 @@ FACE, when non-nil, for the highlight."
 ;; active, this binding is ignored inside tables and replaced with a
 ;; modified self-insert.
 
-
 (defvar orgtbl-mode-map (make-keymap)
   "Keymap for `orgtbl-mode'.")
 
@@ -4324,10 +5028,78 @@ FACE, when non-nil, for the highlight."
              0 (quote 'org-table) 'prepend))
   "Extra `font-lock-keywords' to be added when `orgtbl-mode' is active.")
 
+;;;###autoload
+(defun turn-on-orgtbl ()
+  "Unconditionally turn on `orgtbl-mode'."
+  (require 'org-table)
+  (orgtbl-mode 1))
+
 ;; Install it as a minor mode.
 (put 'orgtbl-mode :included t)
 (put 'orgtbl-mode :menu-tag "Org Table Mode")
 
+(easy-menu-define orgtbl-mode-menu orgtbl-mode-map "OrgTbl menu"
+      '("OrgTbl"
+       ["Create or convert" org-table-create-or-convert-from-region
+        :active (not (org-at-table-p)) :keys "C-c |" ]
+       "--"
+       ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p) :keys "C-c C-c"]
+       ["Next Field" org-cycle :active (org-at-table-p) :keys "TAB"]
+       ["Previous Field" org-shifttab :active (org-at-table-p) :keys "S-TAB"]
+       ["Next Row" org-return :active (org-at-table-p) :keys "RET"]
+       "--"
+       ["Blank Field" org-table-blank-field :active (org-at-table-p) :keys 
"C-c SPC"]
+       ["Edit Field" org-table-edit-field :active (org-at-table-p) :keys "C-c 
` "]
+       ["Copy Field from Above"
+        org-table-copy-down :active (org-at-table-p) :keys "S-RET"]
+       "--"
+       ("Column"
+        ["Move Column Left" org-metaleft :active (org-at-table-p) :keys 
"M-<left>"]
+        ["Move Column Right" org-metaright :active (org-at-table-p) :keys 
"M-<right>"]
+        ["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys 
"M-S-<left>"]
+        ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys 
"M-S-<right>"])
+       ("Row"
+        ["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
+        ["Move Row Down" org-metadown :active (org-at-table-p) :keys 
"M-<down>"]
+        ["Delete Row" org-shiftmetaup :active (org-at-table-p) :keys 
"M-S-<up>"]
+        ["Insert Row" org-shiftmetadown :active (org-at-table-p) :keys 
"M-S-<down>"]
+        ["Sort lines in region" org-table-sort-lines :active (org-at-table-p) 
:keys "C-c ^"]
+        "--"
+        ["Insert Hline" org-table-insert-hline :active (org-at-table-p) :keys 
"C-c -"])
+       ("Rectangle"
+        ["Copy Rectangle" org-copy-special :active (org-at-table-p)]
+        ["Cut Rectangle" org-cut-special :active (org-at-table-p)]
+        ["Paste Rectangle" org-paste-special :active (org-at-table-p)]
+        ["Fill Rectangle" org-table-wrap-region :active (org-at-table-p)])
+       "--"
+       ("Radio tables"
+        ["Insert table template" orgtbl-insert-radio-table
+         (cl-assoc-if #'derived-mode-p orgtbl-radio-table-templates)]
+        ["Comment/uncomment table" orgtbl-toggle-comment t])
+       "--"
+       ["Set Column Formula" org-table-eval-formula :active (org-at-table-p) 
:keys "C-c ="]
+       ["Set Field Formula" (org-table-eval-formula '(4)) :active 
(org-at-table-p) :keys "C-u C-c ="]
+       ["Edit Formulas" org-table-edit-formulas :active (org-at-table-p) :keys 
"C-c '"]
+       ["Recalculate line" org-table-recalculate :active (org-at-table-p) 
:keys "C-c *"]
+       ["Recalculate all" (org-table-recalculate '(4)) :active 
(org-at-table-p) :keys "C-u C-c *"]
+       ["Iterate all" (org-table-recalculate '(16)) :active (org-at-table-p) 
:keys "C-u C-u C-c *"]
+       ["Toggle Recalculate Mark" org-table-rotate-recalc-marks :active 
(org-at-table-p) :keys "C-c #"]
+       ["Sum Column/Rectangle" org-table-sum
+        :active (or (org-at-table-p) (org-region-active-p)) :keys "C-c +"]
+       ["Which Column?" org-table-current-column :active (org-at-table-p) 
:keys "C-c ?"]
+       ["Debug Formulas"
+        org-table-toggle-formula-debugger :active (org-at-table-p)
+        :keys "C-c {"
+        :style toggle :selected org-table-formula-debug]
+       ["Show Col/Row Numbers"
+        org-table-toggle-coordinate-overlays :active (org-at-table-p)
+        :keys "C-c }"
+        :style toggle :selected org-table-overlay-coordinates]
+       "--"
+       ("Plot"
+        ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c \" 
a"]
+        ["Gnuplot" org-plot/gnuplot :active (org-at-table-p) :keys "C-c \" 
g"])))
+
 ;;;###autoload
 (define-minor-mode orgtbl-mode
   "The Org mode table editor as a minor mode for use in other modes."
@@ -4355,15 +5127,12 @@ FACE, when non-nil, for the highlight."
                    (concat orgtbl-line-start-regexp "\\|"
                            auto-fill-inhibit-regexp)
                  orgtbl-line-start-regexp))
-    (add-to-invisibility-spec '(org-cwidth))
     (when (fboundp 'font-lock-add-keywords)
       (font-lock-add-keywords nil orgtbl-extra-font-lock-keywords)
       (org-restart-font-lock))
     (easy-menu-add orgtbl-mode-menu))
    (t
     (setq auto-fill-inhibit-regexp org-old-auto-fill-inhibit-regexp)
-    (org-table-cleanup-narrow-column-properties)
-    (org-remove-from-invisibility-spec '(org-cwidth))
     (remove-hook 'before-change-functions 'org-before-change-function t)
     (when (fboundp 'font-lock-remove-keywords)
       (font-lock-remove-keywords nil orgtbl-extra-font-lock-keywords)
@@ -4371,19 +5140,6 @@ FACE, when non-nil, for the highlight."
     (easy-menu-remove orgtbl-mode-menu)
     (force-mode-line-update 'all))))
 
-(defun org-table-cleanup-narrow-column-properties ()
-  "Remove all properties related to narrow-column invisibility."
-  (let ((s (point-min)))
-    (while (setq s (text-property-any s (point-max)
-                                     'display org-narrow-column-arrow))
-      (remove-text-properties s (1+ s) '(display t)))
-    (setq s (point-min))
-    (while (setq s (text-property-any s (point-max) 'org-cwidth 1))
-      (remove-text-properties s (1+ s) '(org-cwidth t)))
-    (setq s (point-min))
-    (while (setq s (text-property-any s (point-max) 'invisible 'org-cwidth))
-      (remove-text-properties s (1+ s) '(invisible t)))))
-
 (defun orgtbl-make-binding (fun n &rest keys)
   "Create a function for binding in the table minor mode.
 FUN is the command to call inside a table.  N is used to create a unique
@@ -4498,67 +5254,6 @@ to execute outside of tables."
                 'delete-char 'org-delete-char
                 'delete-backward-char 'org-delete-backward-char)
       (org-defkey orgtbl-mode-map "|" 'org-force-self-insert))
-    (easy-menu-define orgtbl-mode-menu orgtbl-mode-map "OrgTbl menu"
-      '("OrgTbl"
-       ["Create or convert" org-table-create-or-convert-from-region
-        :active (not (org-at-table-p)) :keys "C-c |" ]
-       "--"
-       ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p) :keys "C-c C-c"]
-       ["Next Field" org-cycle :active (org-at-table-p) :keys "TAB"]
-       ["Previous Field" org-shifttab :active (org-at-table-p) :keys "S-TAB"]
-       ["Next Row" org-return :active (org-at-table-p) :keys "RET"]
-       "--"
-       ["Blank Field" org-table-blank-field :active (org-at-table-p) :keys 
"C-c SPC"]
-       ["Edit Field" org-table-edit-field :active (org-at-table-p) :keys "C-c 
` "]
-       ["Copy Field from Above"
-        org-table-copy-down :active (org-at-table-p) :keys "S-RET"]
-       "--"
-       ("Column"
-        ["Move Column Left" org-metaleft :active (org-at-table-p) :keys 
"M-<left>"]
-        ["Move Column Right" org-metaright :active (org-at-table-p) :keys 
"M-<right>"]
-        ["Delete Column" org-shiftmetaleft :active (org-at-table-p) :keys 
"M-S-<left>"]
-        ["Insert Column" org-shiftmetaright :active (org-at-table-p) :keys 
"M-S-<right>"])
-       ("Row"
-        ["Move Row Up" org-metaup :active (org-at-table-p) :keys "M-<up>"]
-        ["Move Row Down" org-metadown :active (org-at-table-p) :keys 
"M-<down>"]
-        ["Delete Row" org-shiftmetaup :active (org-at-table-p) :keys 
"M-S-<up>"]
-        ["Insert Row" org-shiftmetadown :active (org-at-table-p) :keys 
"M-S-<down>"]
-        ["Sort lines in region" org-table-sort-lines :active (org-at-table-p) 
:keys "C-c ^"]
-        "--"
-        ["Insert Hline" org-table-insert-hline :active (org-at-table-p) :keys 
"C-c -"])
-       ("Rectangle"
-        ["Copy Rectangle" org-copy-special :active (org-at-table-p)]
-        ["Cut Rectangle" org-cut-special :active (org-at-table-p)]
-        ["Paste Rectangle" org-paste-special :active (org-at-table-p)]
-        ["Fill Rectangle" org-table-wrap-region :active (org-at-table-p)])
-       "--"
-       ("Radio tables"
-        ["Insert table template" orgtbl-insert-radio-table
-         (cl-assoc-if #'derived-mode-p orgtbl-radio-table-templates)]
-        ["Comment/uncomment table" orgtbl-toggle-comment t])
-       "--"
-       ["Set Column Formula" org-table-eval-formula :active (org-at-table-p) 
:keys "C-c ="]
-       ["Set Field Formula" (org-table-eval-formula '(4)) :active 
(org-at-table-p) :keys "C-u C-c ="]
-       ["Edit Formulas" org-table-edit-formulas :active (org-at-table-p) :keys 
"C-c '"]
-       ["Recalculate line" org-table-recalculate :active (org-at-table-p) 
:keys "C-c *"]
-       ["Recalculate all" (org-table-recalculate '(4)) :active 
(org-at-table-p) :keys "C-u C-c *"]
-       ["Iterate all" (org-table-recalculate '(16)) :active (org-at-table-p) 
:keys "C-u C-u C-c *"]
-       ["Toggle Recalculate Mark" org-table-rotate-recalc-marks :active 
(org-at-table-p) :keys "C-c #"]
-       ["Sum Column/Rectangle" org-table-sum
-        :active (or (org-at-table-p) (org-region-active-p)) :keys "C-c +"]
-       ["Which Column?" org-table-current-column :active (org-at-table-p) 
:keys "C-c ?"]
-       ["Debug Formulas"
-        org-table-toggle-formula-debugger :active (org-at-table-p)
-        :keys "C-c {"
-        :style toggle :selected org-table-formula-debug]
-       ["Show Col/Row Numbers"
-        org-table-toggle-coordinate-overlays :active (org-at-table-p)
-        :keys "C-c }"
-        :style toggle :selected org-table-overlay-coordinates]
-       "--"
-       ("Plot"
-        ["Ascii plot" orgtbl-ascii-plot :active (org-at-table-p) :keys "C-c \" 
a"]
-        ["Gnuplot" org-plot/gnuplot :active (org-at-table-p) :keys "C-c \" 
g"])))
     t))
 
 (defun orgtbl-ctrl-c-ctrl-c (arg)
@@ -5476,9 +6171,9 @@ list of the fields in the rectangle."
          org-table-current-line-types
          org-table-current-begin-pos org-table-dlines
          org-table-current-ncol
-         org-table-hlines org-table-last-alignment
-         org-table-last-column-widths org-table-last-alignment
+         org-table-hlines
          org-table-last-column-widths
+         org-table-last-alignment
          buffer loc)
       (setq form (org-table-convert-refs-to-rc form))
       (org-with-wide-buffer
diff --git a/lisp/org/org-tempo.el b/lisp/org/org-tempo.el
new file mode 100644
index 0000000..78424b2
--- /dev/null
+++ b/lisp/org/org-tempo.el
@@ -0,0 +1,188 @@
+;;; org-tempo.el --- Template expansion for Org structures -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2017-2019 Free Software Foundation, Inc.
+;;
+;; Author: Rasmus Pank Roulund <emacs at pank dot eu>
+;; Keywords: outlines, hypermedia, calendar, wp
+;; Homepage: http://orgmode.org
+;;
+;; This file is part of GNU Emacs.
+;;
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+;;
+;;; Commentary:
+;;
+;; Org Tempo reimplements completions of structure template before
+;; point like `org-try-structure-completion' in Org v9.1 and earlier.
+;; For example, strings like "<e" at the beginning of the line will be
+;; expanded to an example block.
+;;
+;; All blocks defined in `org-structure-template-alist' are added as
+;; Org Tempo shortcuts, in addition to keywords defined in
+;; `org-tempo-keywords-alist'.
+;;
+;; `tempo' can also be used to define more sophisticated keywords
+;; completions.  See the section "Additional keywords" below for
+;; examples.
+;;
+;;; Code:
+
+(require 'tempo)
+(require 'cl-lib)
+(require 'org)
+
+(defvar org-structure-template-alist)
+
+
+(defgroup org-tempo nil
+  "Template expansion of Org structures."
+  :tag "Org structure"
+  :group 'org)
+
+(defvar org-tempo-tags nil
+  "Tempo tags for Org mode.")
+
+(defcustom org-tempo-keywords-alist
+  '(("L" . "latex")
+    ("H" . "html")
+    ("A" . "ascii")
+    ("i" . "index"))
+  "Keyword completion elements.
+
+This is an alist of KEY characters and corresponding KEYWORDS,
+just like `org-structure-template-alist'.  The tempo snippet
+\"<KEY\" will be expanded using the KEYWORD value.  For example
+\"<L\" at the beginning of a line is expanded to \"#+latex:\".
+
+Do not use \"I\" as a KEY, as it it reserved for expanding
+\"#+include\"."
+  :group 'org-tempo
+  :type '(repeat (cons (string :tag "Key")
+                      (string :tag "Keyword")))
+  :package-version '(Org . "9.2"))
+
+
+
+;;; Org Tempo functions and setup.
+
+(defun org-tempo-setup ()
+  "Setup tempo tags and match finder for the current buffer."
+  (org-tempo--update-maybe)
+  (tempo-use-tag-list 'org-tempo-tags)
+  (setq-local tempo-match-finder "^ *\\(<[[:word:]]+\\)\\="))
+
+(defun org-tempo--keys ()
+  "Return a list of all Org Tempo expansion strings, like \"<s\"."
+  (mapcar (lambda (pair) (format "<%s" (car pair)))
+         (append org-structure-template-alist
+                 org-tempo-keywords-alist)))
+
+(defun org-tempo--update-maybe ()
+  "Check and add new Org Tempo templates if necessary.
+In particular, if new entries were added to
+`org-structure-template-alist' or `org-tempo-keywords-alist', new
+Tempo templates will be added."
+  (unless (cl-every (lambda (key) (assoc key org-tempo-tags))
+                   (org-tempo--keys))
+    (org-tempo-add-templates)))
+
+(defun org-tempo-add-templates ()
+  "Update all Org Tempo templates.
+
+Go through `org-structure-template-alist' and
+`org-tempo-keywords-alist' and update tempo templates."
+  (mapc 'org--check-org-structure-template-alist '(org-structure-template-alist
+                                                  org-tempo-keywords-alist))
+  (let ((keys (org-tempo--keys)))
+    ;; Check for duplicated snippet keys and warn if any are found.
+    (when (> (length keys) (length (delete-dups keys)))
+      (warn
+       "Duplicated keys in `org-structure-template-alist' and 
`org-tempo-keywords-alist'"))
+    ;; Remove any keys already defined in case they have been updated.
+    (setq org-tempo-tags
+         (cl-remove-if (lambda (tag) (member (car tag) keys)) org-tempo-tags))
+    (mapc #'org-tempo-add-block org-structure-template-alist)
+    (mapc #'org-tempo-add-keyword org-tempo-keywords-alist)))
+
+(defun org-tempo-add-block (entry)
+  "Add block entry from `org-structure-template-alist'."
+  (let* ((key (format "<%s" (car entry)))
+        (name (cdr entry))
+        (special (member name '("src" "export"))))
+    (tempo-define-template (format "org-%s" (replace-regexp-in-string " " "-" 
name))
+                          `(,(format "#+begin_%s%s" name (if special " " ""))
+                            ,(when special 'p) '> n '> ,(unless special 'p) n
+                            ,(format "#+end_%s" (car (split-string name " ")))
+                            >)
+                          key
+                          (format "Insert a %s block" name)
+                          'org-tempo-tags)))
+
+(defun org-tempo-add-keyword (entry)
+  "Add keyword entry from `org-tempo-keywords-alist'."
+  (let* ((key (format "<%s" (car entry)))
+        (name (cdr entry)))
+    (tempo-define-template (format "org-%s" (replace-regexp-in-string " " "-" 
name))
+                          `(,(format "#+%s: " name) p '>)
+                          key
+                          (format "Insert a %s keyword" name)
+                          'org-tempo-tags)))
+
+(defun org-tempo-complete-tag (&rest _)
+  "Look for a tag and expand it silently.
+Unlike to `tempo-complete-tag', do not give a signal if a partial
+completion or no match at all is found.  Return nil if expansion
+didn't succeed."
+  (org-tempo--update-maybe)
+  ;; `tempo-complete-tag' returns its SILENT argument when there is no
+  ;; completion available at all.
+  (not (eq 'fail (tempo-complete-tag 'fail))))
+
+
+;;; Additional keywords
+
+(defun org-tempo--include-file ()
+  "Add #+include: and a file name."
+  (let ((inhibit-quit t))
+    (unless (with-local-quit
+             (prog1 t
+               (insert
+                (format "#+include: %S "
+                        (file-relative-name
+                         (read-file-name "Include file: "))))))
+      (insert "<I")
+      (setq quit-flag nil))))
+
+(tempo-define-template "org-include"
+                      '((org-tempo--include-file)
+                        p >)
+                      "<I"
+                      "Include keyword"
+                      'org-tempo-tags)
+
+;;; Setup of Org Tempo
+;;
+;; Org Tempo is set up with each new Org buffer and potentially in the
+;; current Org buffer.
+
+(add-hook 'org-mode-hook 'org-tempo-setup)
+(add-hook 'org-tab-before-tab-emulation-hook 'org-tempo-complete-tag)
+
+;; Enable Org Tempo in all open Org buffers.
+(dolist (b (org-buffer-list 'files))
+  (with-current-buffer b (org-tempo-setup)))
+
+(provide 'org-tempo)
+
+;;; org-tempo.el ends here
diff --git a/lisp/org/org-timer.el b/lisp/org/org-timer.el
index e1bbfa9..68fe966 100644
--- a/lisp/org/org-timer.el
+++ b/lisp/org/org-timer.el
@@ -139,7 +139,7 @@ the region 0:00:00."
                   (format "Restart timer with offset [%s]: " def)))
          (unless (string-match "\\S-" s) (setq s def))
          (setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete s)))))
-       (setq org-timer-start-time (time-since delta)))
+       (setq org-timer-start-time (org-time-since delta)))
       (setq org-timer-pause-time nil)
       (org-timer-set-mode-line 'on)
       (message "Timer start time set to %s, current value is %s"
@@ -147,6 +147,7 @@ the region 0:00:00."
               (org-timer-secs-to-hms (or delta 0)))
       (run-hooks 'org-timer-start-hook)))))
 
+;;;###autoload
 (defun org-timer-pause-or-continue (&optional stop)
   "Pause or continue the relative or countdown timer.
 With prefix arg STOP, stop it entirely."
@@ -162,9 +163,9 @@ With prefix arg STOP, stop it entirely."
            (setq org-timer-countdown-timer
                  (org-timer--run-countdown-timer
                   new-secs org-timer-countdown-timer-title))
-           (setq org-timer-start-time (time-add nil new-secs)))
+           (setq org-timer-start-time (org-time-add nil new-secs)))
        (setq org-timer-start-time
-             (time-since (- pause-secs start-secs))))
+             (org-time-since (- pause-secs start-secs))))
       (setq org-timer-pause-time nil)
       (org-timer-set-mode-line 'on)
       (run-hooks 'org-timer-continue-hook)
@@ -179,6 +180,7 @@ With prefix arg STOP, stop it entirely."
     (org-timer-set-mode-line 'paused)
     (message "Timer paused at %s" (org-timer-value-string)))))
 
+;;;###autoload
 (defun org-timer-stop ()
   "Stop the relative or countdown timer."
   (interactive)
@@ -217,15 +219,12 @@ it in the buffer."
       (insert (org-timer-value-string)))))
 
 (defun org-timer-value-string ()
-  "Set the timer string."
+  "Return current timer string."
   (format org-timer-format
          (org-timer-secs-to-hms
-          (abs (floor (org-timer-seconds))))))
-
-(defun org-timer-seconds ()
-  (let ((s (float-time (time-subtract org-timer-pause-time
-                                     org-timer-start-time))))
-    (if org-timer-countdown-timer (- s) s)))
+          (let ((time (- (float-time org-timer-pause-time)
+                         (float-time org-timer-start-time))))
+            (abs (floor (if org-timer-countdown-timer (- time) time)))))))
 
 ;;;###autoload
 (defun org-timer-change-times-in-region (beg end delta)
@@ -385,7 +384,10 @@ VALUE can be `on', `off', or `paused'."
        "No timer set"
      (format-seconds
       "%m minute(s) %s seconds left before next time out"
-      (time-subtract (timer--time org-timer-countdown-timer) nil)))))
+      ;; Note: Once our minimal require is Emacs 27, we can drop this
+      ;; org-time-convert-to-integer call.
+      (org-time-convert-to-integer
+       (org-time-subtract (timer--time org-timer-countdown-timer) nil))))))
 
 ;;;###autoload
 (defun org-timer-set-timer (&optional opt)
@@ -417,7 +419,9 @@ using three `C-u' prefix arguments."
           (if (numberp org-timer-default-timer)
               (number-to-string org-timer-default-timer)
             org-timer-default-timer))
-        (effort-minutes (ignore-errors (floor (org-get-at-eol 'effort-minutes 
1))))
+        (effort-minutes (let ((effort (org-entry-get nil org-effort-property)))
+                          (when (org-string-nw-p effort)
+                            (floor (org-duration-to-minutes effort)))))
         (minutes (or (and (numberp opt) (number-to-string opt))
                      (and (not (equal opt '(64)))
                           effort-minutes
@@ -444,7 +448,7 @@ using three `C-u' prefix arguments."
                (org-timer--run-countdown-timer
                 secs org-timer-countdown-timer-title))
          (run-hooks 'org-timer-set-hook)
-         (setq org-timer-start-time (time-add nil secs))
+         (setq org-timer-start-time (org-time-add nil secs))
          (setq org-timer-pause-time nil)
          (org-timer-set-mode-line 'on))))))
 
@@ -462,7 +466,8 @@ time is up."
                 (run-hooks 'org-timer-done-hook)))))
 
 (defun org-timer--get-timer-title ()
-  "Construct timer title from heading or file name of Org buffer."
+  "Construct timer title.
+Try to use an Org header, otherwise use the buffer name."
   (cond
    ((derived-mode-p 'org-agenda-mode)
     (let* ((marker (or (get-text-property (point) 'org-marker)
@@ -478,7 +483,7 @@ time is up."
    ((derived-mode-p 'org-mode)
     (or (ignore-errors (org-get-heading))
        (buffer-name (buffer-base-buffer))))
-   (t (error "Not in an Org buffer"))))
+   (t (buffer-name (buffer-base-buffer)))))
 
 (provide 'org-timer)
 
diff --git a/lisp/org/org-version.el b/lisp/org/org-version.el
index 132ad2b..2a78387 100644
--- a/lisp/org/org-version.el
+++ b/lisp/org/org-version.el
@@ -5,13 +5,13 @@
 (defun org-release ()
   "The release version of Org.
 Inserted by installing Org mode or when a release is made."
-   (let ((org-release "9.1.9"))
+   (let ((org-release "9.3"))
      org-release))
 ;;;###autoload
 (defun org-git-version ()
   "The Git version of Org mode.
 Inserted by installing Org or when a release is made."
-   (let ((org-git-version "release_9.1.9-65-g5e4542"))
+   (let ((org-git-version "release_9.3"))
      org-git-version))
 
 (provide 'org-version)
diff --git a/lisp/org/org.el b/lisp/org/org.el
index 73848a4..b37beeb 100644
--- a/lisp/org/org.el
+++ b/lisp/org/org.el
@@ -6,7 +6,7 @@
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: https://orgmode.org
-;; Version: 9.1.9
+;; Version: 9.3
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -64,8 +64,7 @@
 ;;; Code:
 
 (defvar org-inhibit-highlight-removal nil) ; dynamically scoped param
-(defvar-local org-table-formula-constants-local nil
-  "Local version of `org-table-formula-constants'.")
+(defvar org-inlinetask-min-level)
 
 ;;;; Require other packages
 
@@ -88,16 +87,14 @@
        (message "You need to run \"make\" or \"make autoloads\" from Org lisp 
directory")
        (sit-for 3))))
 
-(require 'org-macs)
+(eval-and-compile (require 'org-macs))
 (require 'org-compat)
+(require 'org-keys)
+(require 'ol)
+(require 'org-table)
 
 ;; `org-outline-regexp' ought to be a defconst but is let-bound in
 ;; some places -- e.g. see the macro `org-with-limited-levels'.
-;;
-;; In Org buffers, the value of `outline-regexp' is that of
-;; `org-outline-regexp'.  The only function still directly relying on
-;; `outline-regexp' is `org-overview' so that `org-cycle' can do its
-;; job when `orgstruct-mode' is active.
 (defvar org-outline-regexp "\\*+ "
   "Regexp to match Org headlines.")
 
@@ -112,17 +109,31 @@ Stars are put in group 1 and the trimmed body in group 
2.")
 
 (declare-function calendar-check-holidays "holidays" (date))
 (declare-function cdlatex-environment "ext:cdlatex" (environment item))
+(declare-function cdlatex-math-symbol "ext:cdlatex")
+(declare-function Info-goto-node "info" (nodename &optional fork strict-case))
 (declare-function isearch-no-upper-case-p "isearch" (string regexp-flag))
 (declare-function org-add-archive-files "org-archive" (files))
 (declare-function org-agenda-entry-get-agenda-timestamp "org-agenda" (pom))
 (declare-function org-agenda-list "org-agenda" (&optional arg start-day span 
with-hour))
 (declare-function org-agenda-redo "org-agenda" (&optional all))
+(declare-function org-agenda-remove-restriction-lock "org-agenda" (&optional 
noupdate))
+(declare-function org-archive-subtree "org-archive" (&optional find-done))
+(declare-function org-archive-subtree-default "org-archive" ())
+(declare-function org-archive-to-archive-sibling "org-archive" ())
+(declare-function org-attach "org-attach" ())
 (declare-function org-babel-do-in-edit-buffer "ob-core" (&rest body) t)
 (declare-function org-babel-tangle-file "ob-tangle" (file &optional 
target-file lang))
 (declare-function org-beamer-mode "ox-beamer" (&optional prefix) t)
+(declare-function org-clock-cancel "org-clock" ())
+(declare-function org-clock-display "org-clock" (&optional arg))
 (declare-function org-clock-get-last-clock-out-time "org-clock" ())
+(declare-function org-clock-goto "org-clock" (&optional select))
+(declare-function org-clock-in "org-clock" (&optional select start-time))
+(declare-function org-clock-in-last "org-clock" (&optional arg))
 (declare-function org-clock-out "org-clock" (&optional switch-to-state 
fail-quietly at-time))
+(declare-function org-clock-out-if-current "org-clock" ())
 (declare-function org-clock-remove-overlays "org-clock" (&optional beg end 
noremove))
+(declare-function org-clock-report "org-clock" (&optional arg))
 (declare-function org-clock-sum "org-clock" (&optional tstart tend 
headline-filter propname))
 (declare-function org-clock-sum-current-item "org-clock" (&optional tstart))
 (declare-function org-clock-timestamps-down "org-clock" (&optional n))
@@ -130,14 +141,15 @@ Stars are put in group 1 and the trimmed body in group 
2.")
 (declare-function org-clock-update-time-maybe "org-clock" ())
 (declare-function org-clocking-buffer "org-clock" ())
 (declare-function org-clocktable-shift "org-clock" (dir n))
-(declare-function
- org-duration-from-minutes "org-duration" (minutes &optional fmt canonical))
+(declare-function org-columns-insert-dblock "org-colview" ())
+(declare-function org-duration-from-minutes "org-duration" (minutes &optional 
fmt canonical))
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-cache-refresh "org-element" (pos))
 (declare-function org-element-cache-reset "org-element" (&optional all))
 (declare-function org-element-contents "org-element" (element))
 (declare-function org-element-context "org-element" (&optional element))
 (declare-function org-element-copy "org-element" (datum))
+(declare-function org-element-create "org-element" (type &optional props &rest 
children))
 (declare-function org-element-interpret-data "org-element" (data))
 (declare-function org-element-lineage "org-element" (blob &optional types 
with-self))
 (declare-function org-element-link-parser "org-element" ())
@@ -146,60 +158,37 @@ Stars are put in group 1 and the trimmed body in group 
2.")
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-put-property "org-element" (element property 
value))
 (declare-function org-element-swap-A-B "org-element" (elem-a elem-b))
+(declare-function org-element-timestamp-parser "org-element" ())
 (declare-function org-element-type "org-element" (element))
-(declare-function org-element-update-syntax "org-element" ())
+(declare-function org-export-dispatch "ox" (&optional arg))
+(declare-function org-export-get-backend "ox" (name))
+(declare-function org-export-get-environment "ox" (&optional backend subtreep 
ext-plist))
+(declare-function org-feed-goto-inbox "org-feed" (feed))
+(declare-function org-feed-update-all "org-feed" ())
+(declare-function org-goto "org-goto" (&optional alternative-interface))
 (declare-function org-id-find-id-file "org-id" (id))
 (declare-function org-id-get-create "org-id" (&optional force))
 (declare-function org-inlinetask-at-task-p "org-inlinetask" ())
 (declare-function org-inlinetask-outline-regexp "org-inlinetask" ())
 (declare-function org-inlinetask-toggle-visibility "org-inlinetask" ())
+(declare-function org-latex-make-preamble "ox-latex" (info &optional template 
snippet?))
 (declare-function org-plot/gnuplot "org-plot" (&optional params))
-(declare-function org-table-align "org-table" ())
-(declare-function org-table-begin "org-table" (&optional table-type))
-(declare-function org-table-beginning-of-field "org-table" (&optional n))
-(declare-function org-table-blank-field "org-table" ())
-(declare-function org-table-calc-current-TBLFM "org-table" (&optional arg))
-(declare-function org-table-copy-region "org-table" (beg end &optional cut))
-(declare-function org-table-cut-region "org-table" (beg end))
-(declare-function org-table-edit-field "org-table" (arg))
-(declare-function org-table-end "org-table" (&optional table-type))
-(declare-function org-table-end-of-field "org-table" (&optional n))
-(declare-function org-table-insert-row "org-table" (&optional arg))
-(declare-function org-table-justify-field-maybe "org-table" (&optional new))
-(declare-function org-table-maybe-eval-formula "org-table" ())
-(declare-function org-table-maybe-recalculate-line "org-table" ())
-(declare-function org-table-next-row "org-table" ())
-(declare-function org-table-paste-rectangle "org-table" ())
-(declare-function org-table-recalculate "org-table" (&optional all noalign))
-(declare-function
- org-table-sort-lines "org-table"
- (&optional with-case sorting-type getkey-func compare-func interactive?))
-(declare-function org-table-wrap-region "org-table" (arg))
 (declare-function org-tags-view "org-agenda" (&optional todo-only match))
-(declare-function orgtbl-ascii-plot "org-table" (&optional ask))
-(declare-function orgtbl-mode "org-table" (&optional arg))
-(declare-function org-export-get-backend "ox" (name))
-(declare-function org-export-get-environment "ox" (&optional backend subtreep 
ext-plist))
-(declare-function org-latex-make-preamble "ox-latex" (info &optional template 
snippet?))
+(declare-function org-timer "org-timer" (&optional restart no-insert))
+(declare-function org-timer-item "org-timer" (&optional arg))
+(declare-function org-timer-pause-or-continue "org-timer" (&optional stop))
+(declare-function org-timer-set-timer "org-timer" (&optional opt))
+(declare-function org-timer-start "org-timer" (&optional offset))
+(declare-function org-timer-stop "org-timer" ())
+(declare-function org-toggle-archive-tag "org-archive" (&optional find-done))
+(declare-function org-update-radio-target-regexp "ol" ())
 
 (defvar ffap-url-regexp)
 (defvar org-element-paragraph-separate)
-
-(defsubst org-uniquify (list)
-  "Non-destructively remove duplicate elements from LIST."
-  (let ((res (copy-sequence list))) (delete-dups res)))
-
-(defsubst org-get-at-bol (property)
-  "Get text property PROPERTY at the beginning of line."
-  (get-text-property (point-at-bol) property))
-
-(defsubst org-trim (s &optional keep-lead)
-  "Remove whitespace at the beginning and the end of string S.
-When optional argument KEEP-LEAD is non-nil, removing blank lines
-at the beginning of the string does not affect leading indentation."
-  (replace-regexp-in-string
-   (if keep-lead "\\`\\([ \t]*\n\\)+" "\\`[ \t\n\r]+") ""
-   (replace-regexp-in-string "[ \t\n\r]+\\'" "" s)))
+(defvar org-indent-indentation-per-level)
+(defvar org-radio-target-regexp)
+(defvar org-target-link-regexp)
+(defvar org-target-regexp)
 
 ;; load languages based on value of `org-babel-load-languages'
 (defvar org-babel-load-languages)
@@ -212,53 +201,48 @@ at the beginning of the string does not affect leading 
indentation."
     (let ((active (cdr pair)) (lang (symbol-name (car pair))))
       (if active
          (require (intern (concat "ob-" lang)))
-       (funcall 'fmakunbound
-                (intern (concat "org-babel-execute:" lang)))
-       (funcall 'fmakunbound
-                (intern (concat "org-babel-expand-body:" lang)))))))
+       (fmakunbound
+        (intern (concat "org-babel-execute:" lang)))
+       (fmakunbound
+        (intern (concat "org-babel-expand-body:" lang)))))))
+
 
-(declare-function org-babel-tangle-file "ob-tangle" (file &optional 
target-file lang))
 ;;;###autoload
 (defun org-babel-load-file (file &optional compile)
   "Load Emacs Lisp source code blocks in the Org FILE.
 This function exports the source code using `org-babel-tangle'
-and then loads the resulting file using `load-file'.  With prefix
-arg (noninteractively: 2nd arg) COMPILE the tangled Emacs Lisp
-file to byte-code before it is loaded."
+and then loads the resulting file using `load-file'.  With
+optional prefix argument COMPILE, the tangled Emacs Lisp file is
+byte-compiled before it is loaded."
   (interactive "fFile to load: \nP")
-  (let* ((age (lambda (file)
-               (float-time
-                (time-since
-                 (file-attribute-modification-time
-                  (or (file-attributes (file-truename file))
-                      (file-attributes file)))))))
-        (base-name (file-name-sans-extension file))
-        (exported-file (concat base-name ".el")))
-    ;; tangle if the Org file is newer than the elisp file
-    (unless (and (file-exists-p exported-file)
-                (> (funcall age file) (funcall age exported-file)))
-      ;; Tangle-file traversal returns reversed list of tangled files
-      ;; and we want to evaluate the first target.
-      (setq exported-file
-           (car (last (org-babel-tangle-file file exported-file 
"emacs-lisp")))))
-    (message "%s %s"
-            (if compile
-                (progn (byte-compile-file exported-file 'load)
-                       "Compiled and loaded")
-              (progn (load-file exported-file) "Loaded"))
-            exported-file)))
+  (let* ((tangled-file (concat (file-name-sans-extension file) ".el")))
+    ;; Tangle only if the Org file is newer than the Elisp file.
+    (unless (org-file-newer-than-p
+            tangled-file
+            (file-attribute-modification-time (file-attributes file)))
+      (org-babel-tangle-file file tangled-file "emacs-lisp"))
+    (if compile
+       (progn
+         (byte-compile-file tangled-file 'load)
+         (message "Compiled and loaded %s" tangled-file))
+      (load-file tangled-file)
+      (message "Loaded %s" tangled-file))))
 
 (defcustom org-babel-load-languages '((emacs-lisp . t))
   "Languages which can be evaluated in Org buffers.
+\\<org-mode-map>
 This list can be used to load support for any of the languages
-below, note that each language will depend on a different set of
-system executables and/or Emacs modes.  When a language is
-\"loaded\", then code blocks in that language can be evaluated
-with `org-babel-execute-src-block' bound by default to C-c
-C-c (note the `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can
-be set to remove code block evaluation from the C-c C-c
-keybinding.  By default only Emacs Lisp (which has no
-requirements) is loaded."
+below.  Each language will depend on a different set of system
+executables and/or Emacs modes.
+
+When a language is \"loaded\", code blocks in that language can
+be evaluated with `org-babel-execute-src-block', which is bound
+by default to \\[org-ctrl-c-ctrl-c].
+
+The `org-babel-no-eval-on-ctrl-c-ctrl-c' option can be set to
+remove code block evaluation from \\[org-ctrl-c-ctrl-c].  By
+default, only Emacs Lisp is loaded, since it has no specific
+requirement."
   :group 'org-babel
   :set 'org-babel-do-load-languages
   :version "24.1"
@@ -537,6 +521,20 @@ but the stars and the body are.")
 An archived subtree does not open during visibility cycling, and does
 not contribute to the agenda listings.")
 
+(defconst org-tag-re "[[:alnum:]_@#%]+"
+  "Regexp matching a single tag.")
+
+(defconst org-tag-group-re "[ \t]+\\(:\\([[:alnum:]_@#%:]+\\):\\)[ \t]*$"
+  "Regexp matching the tag group at the end of a line, with leading spaces.
+Tags are stored in match group 1.  Match group 2 stores the tags
+without the enclosing colons.")
+
+(defconst org-tag-line-re
+  "^\\*+ \\(?:.*[ \t]\\)?\\(:\\([[:alnum:]_@#%:]+\\):\\)[ \t]*$"
+  "Regexp matching tags in a headline.
+Tags are stored in match group 1.  Match group 2 stores the tags
+without the enclosing colons.")
+
 (eval-and-compile
   (defconst org-comment-string "COMMENT"
     "Entries starting with this keyword will never be exported.
@@ -564,30 +562,6 @@ An entry can be toggled between COMMENT and normal with
   "The property that is being used to keep track of effort estimates.
 Effort estimates given in this property need to have the format H:MM.")
 
-;;;; Table
-
-(defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)"
-  "Detect an org-type or table-type table.")
-
-(defconst org-table-line-regexp "^[ \t]*|"
-  "Detect an org-type table line.")
-
-(defconst org-table-dataline-regexp "^[ \t]*|[^-]"
-  "Detect an org-type table line.")
-
-(defconst org-table-hline-regexp "^[ \t]*|-"
-  "Detect an org-type table hline.")
-
-(defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]"
-  "Detect a table-type table hline.")
-
-(defconst org-table-any-border-regexp "^[ \t]*[^|+ \t]"
-  "Detect the first line outside a table when searching from within it.
-This works for both table types.")
-
-(defconst org-TBLFM-regexp "^[ \t]*#\\+TBLFM: "
-  "Detect a #+TBLFM line.")
-
 ;;;; Timestamp
 
 (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} 
?[^\r\n>]*?\\)>"
@@ -633,7 +607,8 @@ on a string that terminates immediately after the date.")
 The time stamps may be either active or inactive.")
 
 (defconst org-repeat-re
-  "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] 
[^>\n]*?\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
+  "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\
+\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
   "Regular expression for specifying repeated events.
 After a match, group 1 contains the repeat expression.")
 
@@ -684,7 +659,7 @@ After a match, group 1 contains the repeat expression.")
     (org-load-modules-maybe 'force)
     (org-element-cache-reset 'all)))
 
-(defcustom org-modules '(org-w3m org-bbdb org-bibtex org-docview org-gnus 
org-info org-irc org-mhe org-rmail)
+(defcustom org-modules '(ol-w3m ol-bbdb ol-bibtex ol-docview ol-gnus ol-info 
ol-irc ol-mhe ol-rmail ol-eww)
   "Modules that should always be loaded together with org.el.
 
 If a description starts with <C>, the file is not part of Emacs
@@ -701,63 +676,63 @@ to add the symbol `xyz', and the package must have a call 
to:
 For export specific modules, see also `org-export-backends'."
   :group 'org
   :set 'org-set-modules
-  :version "24.4"
-  :package-version '(Org . "8.0")
+  :version "26.1"
+  :package-version '(Org . "9.2")
   :type
   '(set :greedy t
-       (const :tag "   bbdb:              Links to BBDB entries" org-bbdb)
-       (const :tag "   bibtex:            Links to BibTeX entries" org-bibtex)
+       (const :tag "   bbdb:              Links to BBDB entries" ol-bbdb)
+       (const :tag "   bibtex:            Links to BibTeX entries" ol-bibtex)
        (const :tag "   crypt:             Encryption of subtrees" org-crypt)
        (const :tag "   ctags:             Access to Emacs tags with links" 
org-ctags)
-       (const :tag "   docview:           Links to doc-view buffers" 
org-docview)
-       (const :tag "   eww:               Store link to url of eww" org-eww)
-       (const :tag "   gnus:              Links to GNUS folders/messages" 
org-gnus)
+       (const :tag "   docview:           Links to Docview buffers" ol-docview)
+       (const :tag "   eww:               Store link to URL of Eww" ol-eww)
+       (const :tag "   gnus:              Links to GNUS folders/messages" 
ol-gnus)
        (const :tag "   habit:             Track your consistency with habits" 
org-habit)
        (const :tag "   id:                Global IDs for identifying entries" 
org-id)
-       (const :tag "   info:              Links to Info nodes" org-info)
+       (const :tag "   info:              Links to Info nodes" ol-info)
        (const :tag "   inlinetask:        Tasks independent of outline 
hierarchy" org-inlinetask)
-       (const :tag "   irc:               Links to IRC/ERC chat sessions" 
org-irc)
-       (const :tag "   mhe:               Links to MHE folders/messages" 
org-mhe)
+       (const :tag "   irc:               Links to IRC/ERC chat sessions" 
ol-irc)
+       (const :tag "   mhe:               Links to MHE folders/messages" 
ol-mhe)
        (const :tag "   mouse:             Additional mouse support" org-mouse)
        (const :tag "   protocol:          Intercept calls from emacsclient" 
org-protocol)
-       (const :tag "   rmail:             Links to RMAIL folders/messages" 
org-rmail)
-       (const :tag "   w3m:               Special cut/paste from w3m to Org 
mode." org-w3m)
+       (const :tag "   rmail:             Links to RMAIL folders/messages" 
ol-rmail)
+       (const :tag "   tempo:             Fast completion for structures" 
org-tempo)
+       (const :tag "   w3m:               Special cut/paste from w3m to Org 
mode." ol-w3m)
+       (const :tag "   eshell:            Links to working directories in 
Eshell" ol-eshell)
 
-       (const :tag "C  annotate-file:     Annotate a file with org syntax" 
org-annotate-file)
-       (const :tag "C  bookmark:          Org links to bookmarks" org-bookmark)
+       (const :tag "C  annotate-file:     Annotate a file with Org syntax" 
org-annotate-file)
+       (const :tag "C  bookmark:          Links to bookmarks" ol-bookmark)
        (const :tag "C  checklist:         Extra functions for checklists in 
repeated tasks" org-checklist)
        (const :tag "C  choose:            Use TODO keywords to mark decisions 
states" org-choose)
        (const :tag "C  collector:         Collect properties into tables" 
org-collector)
        (const :tag "C  depend:            TODO dependencies for Org 
mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend)
-       (const :tag "C  drill:             Flashcards and spaced repetition for 
Org mode" org-drill)
-       (const :tag "C  elisp-symbol:      Org links to emacs-lisp symbols" 
org-elisp-symbol)
-       (const :tag "C  eshell             Support for links to working 
directories in eshell" org-eshell)
+       (const :tag "C  elisp-symbol:      Links to emacs-lisp symbols" 
ol-elisp-symbol)
        (const :tag "C  eval-light:        Evaluate inbuffer-code on demand" 
org-eval-light)
        (const :tag "C  eval:              Include command output as text" 
org-eval)
        (const :tag "C  expiry:            Expiry mechanism for Org entries" 
org-expiry)
-       (const :tag "C  favtable:          Lookup table of favorite references 
and links" org-favtable)
-       (const :tag "C  git-link:          Provide org links to specific file 
version" org-git-link)
+       (const :tag "C  git-link:          Links to specific file version" 
ol-git-link)
        (const :tag "C  interactive-query: Interactive modification of tags 
query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" 
org-interactive-query)
         (const :tag "C  invoice:           Help manage client invoices in Org 
mode" org-invoice)
        (const :tag "C  learn:             SuperMemo's incremental learning 
algorithm" org-learn)
-       (const :tag "C  mac-iCal           Imports events from iCal.app to the 
Emacs diary" org-mac-iCal)
+       (const :tag "C  mac-iCal:          Imports events from iCal.app to the 
Emacs diary" org-mac-iCal)
        (const :tag "C  mac-link:          Grab links and url from various mac 
Applications" org-mac-link)
        (const :tag "C  mairix:            Hook mairix search into Org for 
different MUAs" org-mairix)
-       (const :tag "C  man:               Support for links to manpages in Org 
mode" org-man)
-       (const :tag "C  mew:               Links to Mew folders/messages" 
org-mew)
-       (const :tag "C  mtags:             Support for muse-like tags" 
org-mtags)
-       (const :tag "C  notmuch:           Provide org links to notmuch 
searches or messages" org-notmuch)
+       (const :tag "C  man:               Links to man pages in Org mode" 
ol-man)
+       (const :tag "C  mew:               Links to Mew folders/messages" 
ol-mew)
+       (const :tag "C  notify:            Notifications for Org mode" 
org-notify)
+       (const :tag "C  notmuch:           Provide Org links to notmuch 
searches or messages" ol-notmuch)
        (const :tag "C  panel:             Simple routines for us with bad 
memory" org-panel)
        (const :tag "C  registry:          A registry for Org links" 
org-registry)
-       (const :tag "C  screen:            Visit screen sessions through Org 
links" org-screen)
+       (const :tag "C  screen:            Visit screen sessions through links" 
org-screen)
+       (const :tag "C  screenshot:        Take and manage screenshots in Org 
files" org-screenshot)
        (const :tag "C  secretary:         Team management with Org" 
org-secretary)
        (const :tag "C  sqlinsert:         Convert Org tables to SQL 
insertions" orgtbl-sqlinsert)
        (const :tag "C  toc:               Table of contents for Org buffer" 
org-toc)
        (const :tag "C  track:             Keep up with Org mode development" 
org-track)
        (const :tag "C  velocity           Something like Notational Velocity 
for Org" org-velocity)
-       (const :tag "C  vm:                Links to VM folders/messages" org-vm)
+       (const :tag "C  vm:                Links to VM folders/messages" ol-vm)
        (const :tag "C  wikinodes:         CamelCase wiki-like links" 
org-wikinodes)
-       (const :tag "C  wl:                Links to Wanderlust 
folders/messages" org-wl)
+       (const :tag "C  wl:                Links to Wanderlust 
folders/messages" ol-wl)
        (repeat :tag "External packages" :inline t (symbol :tag "Package"))))
 
 (defvar org-export-registered-backends) ; From ox.el.
@@ -919,7 +894,8 @@ matching headlines within the active region.  Such string 
must be
 a tags/property/todo match as it is used in the agenda tags view.
 
 The list of commands is: `org-schedule', `org-deadline',
-`org-todo', `org-archive-subtree', `org-archive-set-tag' and
+`org-todo', `org-set-tags-command', `org-archive-subtree',
+`org-archive-set-tag', `org-toggle-archive-tag' and
 `org-archive-to-archive-sibling'.  The archiving commands skip
 already archived entries."
   :type '(choice (const :tag "Don't loop" nil)
@@ -930,11 +906,6 @@ already archived entries."
   :group 'org-todo
   :group 'org-archive)
 
-(defgroup org-startup nil
-  "Options concerning startup of Org mode."
-  :tag "Org Startup"
-  :group 'org)
-
 (defcustom org-startup-folded t
   "Non-nil means entering Org mode will switch to OVERVIEW.
 
@@ -1029,8 +1000,6 @@ the following lines anywhere in the buffer:
 
 (defcustom org-startup-align-all-tables nil
   "Non-nil means align all tables when visiting a file.
-This is useful when the column width in tables is forced with <N> cookies
-in table fields.  Such tables will look correct only after the first re-align.
 This can also be configured on a per-file basis by adding one of
 the following lines anywhere in the buffer:
    #+STARTUP: align
@@ -1038,6 +1007,17 @@ the following lines anywhere in the buffer:
   :group 'org-startup
   :type 'boolean)
 
+(defcustom org-startup-shrink-all-tables nil
+  "Non-nil means shrink all table columns with a width cookie.
+This can also be configured on a per-file basis by adding one of
+the following lines anywhere in the buffer:
+   #+STARTUP: shrink"
+  :group 'org-startup
+  :type 'boolean
+  :version "27.1"
+  :package-version '(Org . "9.2")
+  :safe #'booleanp)
+
 (defcustom org-startup-with-inline-images nil
   "Non-nil means show inline images when loading a new Org file.
 This can also be configured on a per-file basis by adding one of
@@ -1070,63 +1050,6 @@ has been set."
   :group 'org-startup
   :type 'boolean)
 
-(defvaralias 'org-CUA-compatible 'org-replace-disputed-keys)
-
-(defcustom org-replace-disputed-keys nil
-  "Non-nil means use alternative key bindings for some keys.
-Org mode uses S-<cursor> keys for changing timestamps and priorities.
-These keys are also used by other packages like shift-selection-mode'
-\(built into Emacs 23), `CUA-mode' or `windmove.el'.
-If you want to use Org mode together with one of these other modes,
-or more generally if you would like to move some Org mode commands to
-other keys, set this variable and configure the keys with the variable
-`org-disputed-keys'.
-
-This option is only relevant at load-time of Org mode, and must be set
-*before* org.el is loaded.  Changing it requires a restart of Emacs to
-become effective."
-  :group 'org-startup
-  :type 'boolean)
-
-(defcustom org-use-extra-keys nil
-  "Non-nil means use extra key sequence definitions for certain commands.
-This happens automatically if `window-system' is nil.  This
-variable lets you do the same manually.  You must set it before
-loading Org."
-  :group 'org-startup
-  :type 'boolean)
-
-(defcustom org-disputed-keys
-  '(([(shift up)]              . [(meta p)])
-    ([(shift down)]            . [(meta n)])
-    ([(shift left)]            . [(meta -)])
-    ([(shift right)]           . [(meta +)])
-    ([(control shift right)]   . [(meta shift +)])
-    ([(control shift left)]    . [(meta shift -)]))
-  "Keys for which Org mode and other modes compete.
-This is an alist, cars are the default keys, second element specifies
-the alternative to use when `org-replace-disputed-keys' is t.
-
-Keys can be specified in any syntax supported by `define-key'.
-The value of this option takes effect only at Org mode startup,
-therefore you'll have to restart Emacs to apply it after changing."
-  :group 'org-startup
-  :type 'alist)
-
-(defun org-key (key)
-  "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
-Or return the original if not disputed."
-  (when org-replace-disputed-keys
-    (let* ((nkey (key-description key))
-          (x (cl-find-if (lambda (x) (equal (key-description (car x)) nkey))
-                         org-disputed-keys)))
-      (setq key (if x (cdr x) key))))
-  key)
-
-(defun org-defkey (keymap key def)
-  "Define a key, possibly translated, as returned by `org-key'."
-  (define-key keymap (org-key key) def))
-
 (defcustom org-ellipsis nil
   "The ellipsis to use in the Org mode outline.
 
@@ -1264,43 +1187,158 @@ new-frame        Make a new frame each time.  Note 
that in this case
          (const :tag "Each time a new frame" new-frame)
          (const :tag "One dedicated frame" dedicated-frame)))
 
-(defcustom org-use-speed-commands nil
-  "Non-nil means activate single letter commands at beginning of a headline.
-This may also be a function to test for appropriate locations where speed
-commands should be active.
+(defconst org-file-apps-gnu
+  '((remote . emacs)
+    (system . mailcap)
+    (t . mailcap))
+  "Default file applications on a UNIX or GNU/Linux system.
+See `org-file-apps'.")
+
+(defconst org-file-apps-macos
+  '((remote . emacs)
+    (system . "open %s")
+    ("ps.gz"  . "gv %s")
+    ("eps.gz" . "gv %s")
+    ("dvi"    . "xdvi %s")
+    ("fig"    . "xfig %s")
+    (t . "open %s"))
+  "Default file applications on a macOS system.
+The system \"open\" is known as a default, but we use X11 applications
+for some files for which the OS does not have a good default.
+See `org-file-apps'.")
+
+(defconst org-file-apps-windowsnt
+  (list '(remote . emacs)
+       (cons 'system (lambda (file _path)
+                       (with-no-warnings (w32-shell-execute "open" file))))
+       (cons t (lambda (file _path)
+                 (with-no-warnings (w32-shell-execute "open" file)))))
+  "Default file applications on a Windows NT system.
+The system \"open\" is used for most files.
+See `org-file-apps'.")
+
+(defcustom org-file-apps
+  '((auto-mode . emacs)
+    ("\\.mm\\'" . default)
+    ("\\.x?html?\\'" . default)
+    ("\\.pdf\\'" . default))
+  "External applications for opening `file:path' items in a document.
+
+\\<org-mode-map>
+Org mode uses system defaults for different file types, but
+you can use this variable to set the application for a given file
+extension.  The entries in this list are cons cells where the car identifies
+files and the cdr the corresponding command.
 
-For example, to activate speed commands when the point is on any
-star at the beginning of the headline, you can do this:
+Possible values for the file identifier are:
 
-  (setq org-use-speed-commands
-      (lambda () (and (looking-at org-outline-regexp) (looking-back 
\"^\\**\"))))"
-  :group 'org-structure
-  :type '(choice
-         (const :tag "Never" nil)
-         (const :tag "At beginning of headline stars" t)
-         (function)))
+ \"string\"    A string as a file identifier can be interpreted in different
+               ways, depending on its contents:
 
-(defcustom org-speed-commands-user nil
-  "Alist of additional speed commands.
-This list will be checked before `org-speed-commands-default'
-when the variable `org-use-speed-commands' is non-nil
-and when the cursor is at the beginning of a headline.
-The car of each entry is a string with a single letter, which must
-be assigned to `self-insert-command' in the global map.
-The cdr is either a command to be called interactively, a function
-to be called, or a form to be evaluated.
-An entry that is just a list with a single string will be interpreted
-as a descriptive headline that will be added when listing the speed
-commands in the Help buffer using the `?' speed command."
-  :group 'org-structure
-  :type '(repeat :value ("k" . ignore)
-                (choice :value ("k" . ignore)
-                        (list :tag "Descriptive Headline" (string :tag 
"Headline"))
-                        (cons :tag "Letter and Command"
-                              (string :tag "Command letter")
-                              (choice
-                               (function)
-                               (sexp))))))
+               - Alphanumeric characters only:
+                 Match links with this file extension.
+                 Example: (\"pdf\" . \"evince %s\")
+                          to open PDFs with evince.
+
+               - Regular expression: Match links where the
+                 filename matches the regexp.  If you want to
+                 use groups here, use shy groups.
+
+                 Example: (\"\\\\.x?html\\\\\\='\" . \"firefox %s\")
+                          (\"\\\\(?:xhtml\\\\|html\\\\)\\\\\\='\" . \"firefox 
%s\")
+                          to open *.html and *.xhtml with firefox.
+
+               - Regular expression which contains (non-shy) groups:
+                 Match links where the whole link, including \"::\", and
+                 anything after that, matches the regexp.
+                 In a custom command string, %1, %2, etc. are replaced with
+                 the parts of the link that were matched by the groups.
+                 For backwards compatibility, if a command string is given
+                 that does not use any of the group matches, this case is
+                 handled identically to the second one (i.e. match against
+                 file name only).
+                 In a custom function, you can access the group matches with
+                 (match-string n link).
+
+                 Example: (\"\\\\.pdf::\\\\([0-9]+\\\\)\\\\\\='\" . \
+\"evince -p %1 %s\")
+                     to open [[file:document.pdf::5]] with evince at page 5.
+
+ `directory'   Matches a directory
+ `remote'      Matches a remote file, accessible through tramp or efs.
+               Remote files most likely should be visited through Emacs
+               because external applications cannot handle such paths.
+`auto-mode'    Matches files that are matched by any entry in 
`auto-mode-alist',
+               so all files Emacs knows how to handle.  Using this with
+               command `emacs' will open most files in Emacs.  Beware that this
+               will also open html files inside Emacs, unless you add
+               (\"html\" . default) to the list as well.
+ `system'      The system command to open files, like `open' on Windows
+               and macOS, and mailcap under GNU/Linux.  This is the command
+               that will be selected if you call `org-open-at-point' with a
+               double prefix argument (`\\[universal-argument] \
+\\[universal-argument] \\[org-open-at-point]').
+ t             Default for files not matched by any of the other options.
+
+Possible values for the command are:
+
+ `emacs'       The file will be visited by the current Emacs process.
+ `default'     Use the default application for this file type, which is the
+               association for t in the list, most likely in the 
system-specific
+               part.  This can be used to overrule an unwanted setting in the
+               system-specific variable.
+ `system'      Use the system command for opening files, like \"open\".
+               This command is specified by the entry whose car is `system'.
+               Most likely, the system-specific version of this variable
+               does define this command, but you can overrule/replace it
+               here.
+`mailcap'      Use command specified in the mailcaps.
+ string        A command to be executed by a shell; %s will be replaced
+               by the path to the file.
+ function      A Lisp function, which will be called with two arguments:
+               the file path and the original link string, without the
+               \"file:\" prefix.
+
+For more examples, see the system specific constants
+`org-file-apps-macos'
+`org-file-apps-windowsnt'
+`org-file-apps-gnu'."
+  :group 'org
+  :type '(repeat
+         (cons (choice :value ""
+                       (string :tag "Extension")
+                       (const :tag "System command to open files" system)
+                       (const :tag "Default for unrecognized files" t)
+                       (const :tag "Remote file" remote)
+                       (const :tag "Links to a directory" directory)
+                       (const :tag "Any files that have Emacs modes"
+                              auto-mode))
+               (choice :value ""
+                       (const :tag "Visit with Emacs" emacs)
+                       (const :tag "Use default" default)
+                       (const :tag "Use the system command" system)
+                       (string :tag "Command")
+                       (function :tag "Function")))))
+
+(defcustom org-open-non-existing-files nil
+  "Non-nil means `org-open-file' opens non-existing files.
+
+When nil, an error is thrown.
+
+This variable applies only to external applications because they
+might choke on non-existing files.  If the link is to a file that
+will be opened in Emacs, the variable is ignored."
+  :group 'org
+  :type 'boolean
+  :safe #'booleanp)
+
+(defcustom org-open-directory-means-index-dot-org nil
+  "When non-nil a link to a directory really means to \"index.org\".
+When nil, following a directory link runs Dired or opens
+a finder/explorer window on that directory."
+  :group 'org
+  :type 'boolean
+  :safe #'booleanp)
 
 (defcustom org-bookmark-names-plist
   '(:last-capture "org-capture-last-stored"
@@ -1428,7 +1466,6 @@ the values `folded', `children', or `subtree'."
   :type 'hook)
 
 (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
-                           org-cycle-hide-drawers
                            org-cycle-show-empty-lines
                            org-optimize-window-after-visibility-change)
   "Hook that is run after `org-cycle' has changed the buffer visibility.
@@ -1483,11 +1520,12 @@ stars).  The following issues are influenced by this 
variable:
   a headline will be indented when this variable is set.
 
 Note that this is all about true indentation, by adding and
-removing space characters.  See also `org-indent.el' which does
+removing space characters.  See also \"org-indent.el\" which does
 level-dependent indentation in a virtual way, i.e. at display
 time in Emacs."
   :group 'org-edit-structure
-  :type 'boolean)
+  :type 'boolean
+  :safe #'booleanp)
 
 (defvaralias 'org-special-ctrl-a 'org-special-ctrl-a/e)
 
@@ -1658,26 +1696,6 @@ make an intelligent decision whether to insert a blank 
line or not."
   :group 'org-edit-structure
   :type 'hook)
 
-(defcustom org-enable-fixed-width-editor t
-  "Non-nil means lines starting with \":\" are treated as fixed-width.
-This currently only means they are never auto-wrapped.
-When nil, such lines will be treated like ordinary lines."
-  :group 'org-edit-structure
-  :type 'boolean)
-
-(defcustom org-goto-auto-isearch t
-  "Non-nil means typing characters in `org-goto' starts incremental search.
-When nil, you can use these keybindings to navigate the buffer:
-
-  q    Quit the org-goto interface
-  n    Go to the next visible heading
-  p    Go to the previous visible heading
-  f    Go one heading forward on same level
-  b    Go one heading backward on same level
-  u    Go one heading up"
-  :group 'org-edit-structure
-  :type 'boolean)
-
 (defgroup org-sparse-trees nil
   "Options concerning sparse trees in Org mode."
   :tag "Org Sparse Trees"
@@ -1696,8 +1714,8 @@ changed by an edit command."
 Such highlights are created by `org-occur' and `org-clock-display'.
 When nil, `\\[org-ctrl-c-ctrl-c]' needs to be used \
 to get rid of the highlights.
-The highlights created by `org-toggle-latex-fragment' always need
-`\\[org-toggle-latex-fragment]' to be removed."
+The highlights created by `org-latex-preview' always need
+`\\[org-latex-preview]' to be removed."
   :group 'org-sparse-trees
   :group 'org-time
   :type 'boolean)
@@ -1720,22 +1738,6 @@ as possible."
   :group 'org-sparse-trees
   :type 'hook)
 
-(defgroup org-imenu-and-speedbar nil
-  "Options concerning imenu and speedbar in Org mode."
-  :tag "Org Imenu and Speedbar"
-  :group 'org-structure)
-
-(defcustom org-imenu-depth 2
-  "The maximum level for Imenu access to Org headlines.
-This also applied for speedbar access."
-  :group 'org-imenu-and-speedbar
-  :type 'integer)
-
-(defgroup org-table nil
-  "Options concerning tables in Org mode."
-  :tag "Org Table"
-  :group 'org)
-
 (defcustom org-self-insert-cluster-for-undo nil
   "Non-nil means cluster self-insert commands for undo when possible.
 If this is set, then, like in the Emacs command loop, 20 consecutive
@@ -1744,155 +1746,6 @@ This is configurable, because there is some impact on 
typing performance."
   :group 'org-table
   :type 'boolean)
 
-(defcustom org-table-tab-recognizes-table.el t
-  "Non-nil means TAB will automatically notice a table.el table.
-When it sees such a table, it moves point into it and - if necessary -
-calls `table-recognize-table'."
-  :group 'org-table-editing
-  :type 'boolean)
-
-(defgroup org-link nil
-  "Options concerning links in Org mode."
-  :tag "Org Link"
-  :group 'org)
-
-(defvar-local org-link-abbrev-alist-local nil
-  "Buffer-local version of `org-link-abbrev-alist', which see.
-The value of this is taken from the #+LINK lines.")
-
-(defcustom org-link-parameters
-  '(("doi" :follow org--open-doi-link)
-    ("elisp" :follow org--open-elisp-link)
-    ("file" :complete org-file-complete-link)
-    ("ftp" :follow (lambda (path) (browse-url (concat "ftp:" path))))
-    ("help" :follow org--open-help-link)
-    ("http" :follow (lambda (path) (browse-url (concat "http:" path))))
-    ("https" :follow (lambda (path) (browse-url (concat "https:" path))))
-    ("mailto" :follow (lambda (path) (browse-url (concat "mailto:"; path))))
-    ("news" :follow (lambda (path) (browse-url (concat "news:"; path))))
-    ("shell" :follow org--open-shell-link))
-  "An alist of properties that defines all the links in Org mode.
-The key in each association is a string of the link type.
-Subsequent optional elements make up a p-list of link properties.
-
-:follow - A function that takes the link path as an argument.
-
-:export - A function that takes the link path, description and
-export-backend as arguments.
-
-:store - A function responsible for storing the link.  See the
-function `org-store-link-functions'.
-
-:complete - A function that inserts a link with completion.  The
-function takes one optional prefix arg.
-
-:face - A face for the link, or a function that returns a face.
-The function takes one argument which is the link path.  The
-default face is `org-link'.
-
-:mouse-face - The mouse-face. The default is `highlight'.
-
-:display - `full' will not fold the link in descriptive
-display.  Default is `org-link'.
-
-:help-echo - A string or function that takes (window object position)
-as arguments and returns a string.
-
-:keymap - A keymap that is active on the link.  The default is
-`org-mouse-map'.
-
-:htmlize-link - A function for the htmlize-link.  Defaults
-to (list :uri \"type:path\")
-
-:activate-func - A function to run at the end of font-lock
-activation.  The function must accept (link-start link-end path bracketp)
-as arguments."
-  :group 'org-link
-  :type '(alist :tag "Link display parameters"
-               :value-type plist)
-  :version "26.1"
-  :package-version '(Org . "9.1"))
-
-(defun org-link-get-parameter (type key)
-  "Get TYPE link property for KEY.
-TYPE is a string and KEY is a plist keyword."
-  (plist-get
-   (cdr (assoc type org-link-parameters))
-   key))
-
-(defun org-link-set-parameters (type &rest parameters)
-  "Set link TYPE properties to PARAMETERS.
-  PARAMETERS should be :key val pairs."
-  (let ((data (assoc type org-link-parameters)))
-    (if data (setcdr data (org-combine-plists (cdr data) parameters))
-      (push (cons type parameters) org-link-parameters)
-      (org-make-link-regexps)
-      (org-element-update-syntax))))
-
-(defun org-link-types ()
-  "Return a list of known link types."
-  (mapcar #'car org-link-parameters))
-
-(defcustom org-link-abbrev-alist nil
-  "Alist of link abbreviations.
-The car of each element is a string, to be replaced at the start of a link.
-The cdrs are replacement values, like (\"linkkey\" . REPLACE).  Abbreviated
-links in Org buffers can have an optional tag after a double colon, e.g.,
-
-     [[linkkey:tag][description]]
-
-The `linkkey' must be a single word, starting with a letter, followed
-by letters, numbers, `-' or `_'.
-
-If REPLACE is a string, the tag will simply be appended to create the link.
-If the string contains \"%s\", the tag will be inserted there.  If the string
-contains \"%h\", it will cause a url-encoded version of the tag to be inserted
-at that point (see the function `url-hexify-string').  If the string contains
-the specifier \"%(my-function)\", then the custom function `my-function' will
-be invoked: this function takes the tag as its only argument and must return
-a string.
-
-REPLACE may also be a function that will be called with the tag as the
-only argument to create the link, which should be returned as a string.
-
-See the manual for examples."
-  :group 'org-link
-  :type '(repeat
-         (cons
-          (string :tag "Protocol")
-          (choice
-           (string :tag "Format")
-           (function)))))
-
-(defcustom org-descriptive-links t
-  "Non-nil means Org will display descriptive links.
-E.g. [[https://orgmode.org][Org website]] will be displayed as
-\"Org Website\", hiding the link itself and just displaying its
-description.  When set to nil, Org will display the full links
-literally.
-
-You can interactively set the value of this variable by calling
-`org-toggle-link-display' or from the menu Org>Hyperlinks menu."
-  :group 'org-link
-  :type 'boolean)
-
-(defcustom org-link-file-path-type 'adaptive
-  "How the path name in file links should be stored.
-Valid values are:
-
-relative  Relative to the current directory, i.e. the directory of the file
-          into which the link is being inserted.
-absolute  Absolute path, if possible with ~ for home directory.
-noabbrev  Absolute path, no abbreviation of home directory.
-adaptive  Use relative path for files in the current directory and sub-
-          directories of it.  For other files, use an absolute path."
-  :group 'org-link
-  :type '(choice
-         (const relative)
-         (const absolute)
-         (const noabbrev)
-         (const adaptive)))
-
 (defvaralias 'org-activate-links 'org-highlight-links)
 (defcustom org-highlight-links '(bracket angle plain radio tag date footnote)
   "Types of links that should be highlighted in Org files.
@@ -1917,7 +1770,6 @@ footnote  Footnote labels.
 
 If you set this variable during an Emacs session, use `org-mode-restart'
 in the Org buffer so that the change takes effect."
-  :group 'org-link
   :group 'org-appearance
   :type '(set :greedy t
              (const :tag "Double bracket links" bracket)
@@ -1928,441 +1780,16 @@ in the Org buffer so that the change takes effect."
              (const :tag "Timestamps" date)
              (const :tag "Footnotes" footnote)))
 
-(defcustom org-make-link-description-function nil
-  "Function to use for generating link descriptions from links.
-This function must take two parameters: the first one is the
-link, the second one is the description generated by
-`org-insert-link'.  The function should return the description to
-use."
-  :group 'org-link
-  :type '(choice (const nil) (function)))
-
-(defgroup org-link-store nil
-  "Options concerning storing links in Org mode."
-  :tag "Org Store Link"
-  :group 'org-link)
-
-(defcustom org-url-hexify-p t
-  "When non-nil, hexify URL when creating a link."
-  :type 'boolean
-  :version "24.3"
-  :group 'org-link-store)
-
-(defcustom org-email-link-description-format "Email %c: %.30s"
-  "Format of the description part of a link to an email or usenet message.
-The following %-escapes will be replaced by corresponding information:
-
-%F   full \"From\" field
-%f   name, taken from \"From\" field, address if no name
-%T   full \"To\" field
-%t   first name in \"To\" field, address if no name
-%c   correspondent.  Usually \"from NAME\", but if you sent it yourself, it
-     will be \"to NAME\".  See also the variable `org-from-is-user-regexp'.
-%s   subject
-%d   date
-%m   message-id.
-
-You may use normal field width specification between the % and the letter.
-This is for example useful to limit the length of the subject.
-
-Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
-  :group 'org-link-store
-  :type 'string)
-
-(defcustom org-from-is-user-regexp
-  (let (r1 r2)
-    (when (and user-mail-address (not (string= user-mail-address "")))
-      (setq r1 (concat "\\<" (regexp-quote user-mail-address) "\\>")))
-    (when (and user-full-name (not (string= user-full-name "")))
-      (setq r2 (concat "\\<" (regexp-quote user-full-name) "\\>")))
-    (if (and r1 r2) (concat r1 "\\|" r2) (or r1 r2)))
-  "Regexp matched against the \"From:\" header of an email or usenet message.
-It should match if the message is from the user him/herself."
-  :group 'org-link-store
-  :type 'regexp)
-
-(defcustom org-context-in-file-links t
-  "Non-nil means file links from `org-store-link' contain context.
-\\<org-mode-map>
-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'.  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' (`\\[universal-argument] \
-\\[org-store-link]')
-negates this setting for the duration of the command."
-  :group 'org-link-store
-  :type '(choice boolean integer))
-
-(defcustom org-keep-stored-link-after-insertion nil
-  "Non-nil means keep link in list for entire session.
-\\<org-mode-map>
-The command `org-store-link' adds a link pointing to the current
-location to an internal list.  These links accumulate during a session.
-The command `org-insert-link' can be used to insert links into any
-Org file (offering completion for all stored links).
-
-When this option is nil, every link which has been inserted once using
-`\\[org-insert-link]' will be removed from the list, to make completing the \
-unused
-links more efficient."
-  :group 'org-link-store
-  :type 'boolean)
-
-(defgroup org-link-follow nil
-  "Options concerning following links in Org mode."
-  :tag "Org Follow Link"
-  :group 'org-link)
-
-(defcustom org-link-translation-function nil
-  "Function to translate links with different syntax to Org syntax.
-This can be used to translate links created for example by the Planner
-or emacs-wiki packages to Org syntax.
-The function must accept two parameters, a TYPE containing the link
-protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
-which is everything after the link protocol.  It should return a cons
-with possibly modified values of type and path.
-Org contains a function for this, so if you set this variable to
-`org-translate-link-from-planner', you should be able follow many
-links created by planner."
-  :group 'org-link-follow
-  :type '(choice (const nil) (function)))
-
-(defcustom org-follow-link-hook nil
-  "Hook that is run after a link has been followed."
+(defcustom org-mark-ring-length 4
+  "Number of different positions to be recorded in the ring.
+Changing this requires a restart of Emacs to work correctly."
   :group 'org-link-follow
-  :type 'hook)
+  :type 'integer)
 
-(defcustom org-tab-follows-link nil
-  "Non-nil means on links TAB will follow the link.
-Needs to be set before org.el is loaded.
-This really should not be used, it does not make sense, and the
-implementation is bad."
-  :group 'org-link-follow
-  :type 'boolean)
-
-(defcustom org-return-follows-link nil
-  "Non-nil means on links RET will follow the link.
-In tables, the special behavior of RET has precedence."
-  :group 'org-link-follow
-  :type 'boolean)
-
-(defcustom org-mouse-1-follows-link
-  (if (boundp 'mouse-1-click-follows-link) mouse-1-click-follows-link t)
-  "Non-nil means mouse-1 on a link will follow the link.
-A longer mouse click will still set point.  Needs to be set
-before org.el is loaded."
-  :group 'org-link-follow
-  :version "26.1"
-  :package-version '(Org . "8.3")
-  :type '(choice
-         (const :tag "A double click follows the link" double)
-         (const :tag "Unconditionally follow the link with mouse-1" t)
-         (integer :tag "mouse-1 click does not follow the link if longer than 
N ms" 450)))
-
-(defcustom org-mark-ring-length 4
-  "Number of different positions to be recorded in the ring.
-Changing this requires a restart of Emacs to work correctly."
-  :group 'org-link-follow
-  :type 'integer)
-
-(defcustom org-link-search-must-match-exact-headline 'query-to-create
-  "Non-nil means internal fuzzy links can only match headlines.
-
-When nil, the a fuzzy link may point to a target or a named
-construct in the document.  When set to the special value
-`query-to-create', offer to create a new headline when none
-matched.
-
-Spaces and statistics cookies are ignored during heading searches."
-  :group 'org-link-follow
-  :version "24.1"
-  :type '(choice
-         (const :tag "Use fuzzy text search" nil)
-         (const :tag "Match only exact headline" t)
-         (const :tag "Match exact headline or query to create it"
-                query-to-create))
-  :safe #'symbolp)
-
-(defcustom org-link-frame-setup
-  '((vm . vm-visit-folder-other-frame)
-    (vm-imap . vm-visit-imap-folder-other-frame)
-    (gnus . org-gnus-no-new-news)
-    (file . find-file-other-window)
-    (wl . wl-other-frame))
-  "Setup the frame configuration for following links.
-When following a link with Emacs, it may often be useful to display
-this link in another window or frame.  This variable can be used to
-set this up for the different types of links.
-For VM, use any of
-    `vm-visit-folder'
-    `vm-visit-folder-other-window'
-    `vm-visit-folder-other-frame'
-For Gnus, use any of
-    `gnus'
-    `gnus-other-frame'
-    `org-gnus-no-new-news'
-For FILE, use any of
-    `find-file'
-    `find-file-other-window'
-    `find-file-other-frame'
-For Wanderlust use any of
-    `wl'
-    `wl-other-frame'
-For the calendar, use the variable `calendar-setup'.
-For BBDB, it is currently only possible to display the matches in
-another window."
-  :group 'org-link-follow
-  :type '(list
-         (cons (const vm)
-               (choice
-                (const vm-visit-folder)
-                (const vm-visit-folder-other-window)
-                (const vm-visit-folder-other-frame)))
-         (cons (const vm-imap)
-               (choice
-                (const vm-visit-imap-folder)
-                (const vm-visit-imap-folder-other-window)
-                (const vm-visit-imap-folder-other-frame)))
-         (cons (const gnus)
-               (choice
-                (const gnus)
-                (const gnus-other-frame)
-                (const org-gnus-no-new-news)))
-         (cons (const file)
-               (choice
-                (const find-file)
-                (const find-file-other-window)
-                (const find-file-other-frame)))
-         (cons (const wl)
-               (choice
-                (const wl)
-                (const wl-other-frame)))))
-
-(defcustom org-display-internal-link-with-indirect-buffer nil
-  "Non-nil means use indirect buffer to display infile links.
-Activating internal links (from one location in a file to another location
-in the same file) normally just jumps to the location.  When the link is
-activated with a `\\[universal-argument]' prefix (or with mouse-3), the link \
-is displayed in
-another window.  When this option is set, the other window actually displays
-an indirect buffer clone of the current buffer, to avoid any visibility
-changes to the current buffer."
-  :group 'org-link-follow
-  :type 'boolean)
-
-(defcustom org-open-non-existing-files nil
-  "Non-nil means `org-open-file' will open non-existing files.
-When nil, an error will be generated.
-This variable applies only to external applications because they
-might choke on non-existing files.  If the link is to a file that
-will be opened in Emacs, the variable is ignored."
-  :group 'org-link-follow
-  :type 'boolean)
-
-(defcustom org-open-directory-means-index-dot-org nil
-  "Non-nil means a link to a directory really means to index.org.
-When nil, following a directory link will run dired or open a finder/explorer
-window on that directory."
-  :group 'org-link-follow
-  :type 'boolean)
-
-(defcustom org-confirm-shell-link-function 'yes-or-no-p
-  "Non-nil means ask for confirmation before executing shell links.
-Shell links can be dangerous: just think about a link
-
-     [[shell:rm -rf ~/*][Google Search]]
-
-This link would show up in your Org document as \"Google Search\",
-but really it would remove your entire home directory.
-Therefore we advise against setting this variable to nil.
-Just change it to `y-or-n-p' if you want to confirm with a
-single keystroke rather than having to type \"yes\"."
-  :group 'org-link-follow
-  :type '(choice
-         (const :tag "with yes-or-no (safer)" yes-or-no-p)
-         (const :tag "with y-or-n (faster)" y-or-n-p)
-         (const :tag "no confirmation (dangerous)" nil)))
-(put 'org-confirm-shell-link-function
-     'safe-local-variable
-     (lambda (x) (member x '(yes-or-no-p y-or-n-p))))
-
-(defcustom org-confirm-shell-link-not-regexp ""
-  "A regexp to skip confirmation for shell links."
-  :group 'org-link-follow
-  :version "24.1"
-  :type 'regexp)
-
-(defcustom org-confirm-elisp-link-function 'yes-or-no-p
-  "Non-nil means ask for confirmation before executing Emacs Lisp links.
-Elisp links can be dangerous: just think about a link
-
-     [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
-
-This link would show up in your Org document as \"Google Search\",
-but really it would remove your entire home directory.
-Therefore we advise against setting this variable to nil.
-Just change it to `y-or-n-p' if you want to confirm with a
-single keystroke rather than having to type \"yes\"."
-  :group 'org-link-follow
-  :type '(choice
-         (const :tag "with yes-or-no (safer)" yes-or-no-p)
-         (const :tag "with y-or-n (faster)" y-or-n-p)
-         (const :tag "no confirmation (dangerous)" nil)))
-(put 'org-confirm-shell-link-function
-     'safe-local-variable
-     (lambda (x) (member x '(yes-or-no-p y-or-n-p))))
-
-(defcustom org-confirm-elisp-link-not-regexp ""
-  "A regexp to skip confirmation for Elisp links."
-  :group 'org-link-follow
-  :version "24.1"
-  :type 'regexp)
-
-(defconst org-file-apps-defaults-gnu
-  '((remote . emacs)
-    (system . mailcap)
-    (t . mailcap))
-  "Default file applications on a UNIX or GNU/Linux system.
-See `org-file-apps'.")
-
-(defconst org-file-apps-defaults-macosx
-  '((remote . emacs)
-    (system . "open %s")
-    ("ps.gz"  . "gv %s")
-    ("eps.gz" . "gv %s")
-    ("dvi"    . "xdvi %s")
-    ("fig"    . "xfig %s")
-    (t . "open %s"))
-  "Default file applications on a macOS system.
-The system \"open\" is known as a default, but we use X11 applications
-for some files for which the OS does not have a good default.
-See `org-file-apps'.")
-
-(defconst org-file-apps-defaults-windowsnt
-  (list '(remote . emacs)
-       (cons 'system (lambda (file _path)
-                       (with-no-warnings (w32-shell-execute "open" file))))
-       (cons t (lambda (file _path)
-                 (with-no-warnings (w32-shell-execute "open" file)))))
-  "Default file applications on a Windows NT system.
-The system \"open\" is used for most files.
-See `org-file-apps'.")
-
-(defcustom org-file-apps
-  '((auto-mode . emacs)
-    ("\\.mm\\'" . default)
-    ("\\.x?html?\\'" . default)
-    ("\\.pdf\\'" . default))
-  "External applications for opening `file:path' items in a document.
-\\<org-mode-map>
-Org mode uses system defaults for different file types, but
-you can use this variable to set the application for a given file
-extension.  The entries in this list are cons cells where the car identifies
-files and the cdr the corresponding command.
-
-Possible values for the file identifier are:
-
- \"string\"    A string as a file identifier can be interpreted in different
-               ways, depending on its contents:
-
-               - Alphanumeric characters only:
-                 Match links with this file extension.
-                 Example: (\"pdf\" . \"evince %s\")
-                          to open PDFs with evince.
-
-               - Regular expression: Match links where the
-                 filename matches the regexp.  If you want to
-                 use groups here, use shy groups.
-
-                 Example: (\"\\\\.x?html\\\\\\='\" . \"firefox %s\")
-                          (\"\\\\(?:xhtml\\\\|html\\\\)\\\\\\='\" . \"firefox 
%s\")
-                          to open *.html and *.xhtml with firefox.
-
-               - Regular expression which contains (non-shy) groups:
-                 Match links where the whole link, including \"::\", and
-                 anything after that, matches the regexp.
-                 In a custom command string, %1, %2, etc. are replaced with
-                 the parts of the link that were matched by the groups.
-                 For backwards compatibility, if a command string is given
-                 that does not use any of the group matches, this case is
-                 handled identically to the second one (i.e. match against
-                 file name only).
-                 In a custom function, you can access the group matches with
-                 (match-string n link).
-
-                 Example: (\"\\\\.pdf::\\\\(\\\\d+\\\\)\\\\\\='\" . \
-\"evince -p %1 %s\")
-                     to open [[file:document.pdf::5]] with evince at page 5.
-
- `directory'   Matches a directory
- `remote'      Matches a remote file, accessible through tramp or efs.
-               Remote files most likely should be visited through Emacs
-               because external applications cannot handle such paths.
-`auto-mode'    Matches files that are matched by any entry in 
`auto-mode-alist',
-               so all files Emacs knows how to handle.  Using this with
-               command `emacs' will open most files in Emacs.  Beware that this
-               will also open html files inside Emacs, unless you add
-               (\"html\" . default) to the list as well.
- `system'      The system command to open files, like `open' on Windows
-               and macOS, and mailcap under GNU/Linux.  This is the command
-               that will be selected if you call `org-open-at-point' with a
-               double prefix argument (`\\[universal-argument] \
-\\[universal-argument] \\[org-open-at-point]').
- t             Default for files not matched by any of the other options.
-
-Possible values for the command are:
-
- `emacs'       The file will be visited by the current Emacs process.
- `default'     Use the default application for this file type, which is the
-               association for t in the list, most likely in the 
system-specific
-               part.  This can be used to overrule an unwanted setting in the
-               system-specific variable.
- `system'      Use the system command for opening files, like \"open\".
-               This command is specified by the entry whose car is `system'.
-               Most likely, the system-specific version of this variable
-               does define this command, but you can overrule/replace it
-               here.
-`mailcap'      Use command specified in the mailcaps.
- string        A command to be executed by a shell; %s will be replaced
-               by the path to the file.
- function      A Lisp function, which will be called with two arguments:
-               the file path and the original link string, without the
-               \"file:\" prefix.
-
-For more examples, see the system specific constants
-`org-file-apps-defaults-macosx'
-`org-file-apps-defaults-windowsnt'
-`org-file-apps-defaults-gnu'."
-  :group 'org-link-follow
-  :type '(repeat
-         (cons (choice :value ""
-                       (string :tag "Extension")
-                       (const :tag "System command to open files" system)
-                       (const :tag "Default for unrecognized files" t)
-                       (const :tag "Remote file" remote)
-                       (const :tag "Links to a directory" directory)
-                       (const :tag "Any files that have Emacs modes"
-                              auto-mode))
-               (choice :value ""
-                       (const :tag "Visit with Emacs" emacs)
-                       (const :tag "Use default" default)
-                       (const :tag "Use the system command" system)
-                       (string :tag "Command")
-                       (function :tag "Function")))))
-
-(defcustom org-doi-server-url "https://doi.org/";
-  "The URL of the DOI server."
-  :type 'string
-  :version "24.3"
-  :group 'org-link-follow)
-
-(defgroup org-refile nil
-  "Options concerning refiling entries in Org mode."
-  :tag "Org Refile"
-  :group 'org)
+(defgroup org-refile nil
+  "Options concerning refiling entries in Org mode."
+  :tag "Org Refile"
+  :group 'org)
 
 (defcustom org-directory "~/org"
   "Directory with Org files.
@@ -2388,25 +1815,6 @@ do not specify a target file."
   :group 'org-capture
   :type 'file)
 
-(defcustom org-goto-interface 'outline
-  "The default interface to be used for `org-goto'.
-Allowed values are:
-outline                  The interface shows an outline of the relevant file
-                         and the correct heading is found by moving through
-                         the outline or by searching with incremental search.
-outline-path-completion  Headlines in the current buffer are offered via
-                         completion.  This is the interface also used by
-                         the refile command."
-  :group 'org-refile
-  :type '(choice
-         (const :tag "Outline" outline)
-         (const :tag "Outline-path-completion" outline-path-completion)))
-
-(defcustom org-goto-max-level 5
-  "Maximum target level when running `org-goto' with refile interface."
-  :group 'org-refile
-  :type 'integer)
-
 (defcustom org-reverse-note-order nil
   "Non-nil means store new notes at the beginning of a file or entry.
 When nil, new notes will be filed to the end of a file or entry.
@@ -2438,8 +1846,8 @@ This option can also be set with on a per-file-basis with
 You can have local logging settings for a subtree by setting the LOGGING
 property to one or more of these keywords.
 
-When bulk-refiling from the agenda, the value `note' is forbidden and
-will temporarily be changed to `time'."
+When bulk-refiling, e.g., from the agenda, the value `note' is
+forbidden and will temporarily be changed to `time'."
   :group 'org-refile
   :group 'org-progress
   :version "24.1"
@@ -2700,31 +2108,35 @@ more information."
   :type '(choice (const sequence)
                 (const type)))
 
-(defcustom org-use-fast-todo-selection t
+(defcustom org-use-fast-todo-selection 'auto
   "\\<org-mode-map>\
 Non-nil means use the fast todo selection scheme with `\\[org-todo]'.
 This variable describes if and under what circumstances the cycling
 mechanism for TODO keywords will be replaced by a single-key, direct
-selection scheme.
+selection scheme, where the choices are displayed in a little window.
 
-When nil, fast selection is never used.
+When nil, fast selection is never used.  This means that the command
+will always switch to the next state.
 
-When the symbol `prefix', it will be used when `org-todo' is called
-with a prefix argument, i.e. `\\[universal-argument] \\[org-todo]' \
-in an Org buffer, and
-`\\[universal-argument] t' in an agenda buffer.
+When it is the symbol `auto', fast selection is whenever selection
+keys have been defined.
 
-When t, fast selection is used by default.  In this case, the prefix
-argument forces cycling instead.
+`expert' is like `auto', but no special window with the keyword
+will be shown, choices will only be listed in the prompt.
 
 In all cases, the special interface is only used if access keys have
 actually been assigned by the user, i.e. if keywords in the configuration
 are followed by a letter in parenthesis, like TODO(t)."
   :group 'org-todo
+  :set (lambda (var val)
+        (cond
+         ((eq var t) (set var 'auto))
+         ((eq var 'prefix) (set var nil))
+         (t (set var val))))
   :type '(choice
          (const :tag "Never" nil)
-         (const :tag "By default" t)
-         (const :tag "Only with C-u C-c C-t" prefix)))
+         (const :tag "Automatically, when key letter have been defined" auto)
+         (const :tag "Automatically, but don't show the selection window" 
expert)))
 
 (defcustom org-provide-todo-statistics t
   "Non-nil means update todo statistics after insert and toggle.
@@ -2818,7 +2230,7 @@ When non-nil, you first need to check off all check boxes 
before the TODO
 entry can be switched to DONE.
 This variable needs to be set before org.el is loaded, and you need to
 restart Emacs after a change to make the change effective.  The only way
-to change is while Emacs is running is through the customize interface."
+to change it while Emacs is running is through the customize interface."
   :set (lambda (var val)
         (set var val)
         (if val
@@ -2897,7 +2309,7 @@ property to one or more of these keywords."
   (setq org-log-done 'note)))
 
 (defcustom org-log-reschedule nil
-  "Information to record when the scheduling date of a tasks is modified.
+  "Information to record when the scheduling date of a task is modified.
 
 Possible values are:
 
@@ -2909,16 +2321,22 @@ This option can also be set with on a per-file-basis 
with
 
    #+STARTUP: nologreschedule
    #+STARTUP: logreschedule
-   #+STARTUP: lognotereschedule"
+   #+STARTUP: lognotereschedule
+
+You can have local logging settings for a subtree by setting the LOGGING
+property to one or more of these keywords.
+
+This variable has an effect when calling `org-schedule' or
+`org-agenda-schedule' only."
   :group 'org-todo
   :group 'org-progress
   :type '(choice
          (const :tag "No logging" nil)
          (const :tag "Record timestamp" time)
-         (const :tag "Record timestamp with note." note)))
+         (const :tag "Record timestamp with note" note)))
 
 (defcustom org-log-redeadline nil
-  "Information to record when the deadline date of a tasks is modified.
+  "Information to record when the deadline date of a task is modified.
 
 Possible values are:
 
@@ -2933,7 +2351,10 @@ This option can also be set with on a per-file-basis with
    #+STARTUP: lognoteredeadline
 
 You can have local logging settings for a subtree by setting the LOGGING
-property to one or more of these keywords."
+property to one or more of these keywords.
+
+This variable has an effect when calling `org-deadline' or
+`org-agenda-deadline' only."
   :group 'org-todo
   :group 'org-progress
   :type '(choice
@@ -3077,13 +2498,17 @@ This option can also be set with on a per-file-basis 
with
 
 (defcustom org-todo-repeat-to-state nil
   "The TODO state to which a repeater should return the repeating task.
-By default this is the first task in a TODO sequence, or the previous state
-in a TODO_TYP set.  But you can specify another task here.
-alternatively, set the :REPEAT_TO_STATE: property of the entry."
+By default this is the first task of a TODO sequence or the
+previous state of a TYPE_TODO set.  But you can specify to use
+the previous state in a TODO sequence or a string.
+
+Alternatively, you can set the :REPEAT_TO_STATE: property of the
+entry, which has precedence over this option."
   :group 'org-todo
   :version "24.1"
-  :type '(choice (const :tag "Head of sequence" nil)
-                (string :tag "Specific state")))
+  :type '(choice (const :tag "Use the previous TODO state" t)
+                (const :tag "Use the head of the TODO sequence" nil)
+                (string :tag "Use a specific TODO state")))
 
 (defcustom org-log-repeat 'time
   "Non-nil means record moving through the DONE state when triggering repeat.
@@ -3112,6 +2537,11 @@ property to one or more of these keywords."
          (const :tag "Force recording the DONE state" time)
          (const :tag "Force recording a note with the DONE state" note)))
 
+(defcustom org-todo-repeat-hook nil
+  "Hook that is run after a task has been repeated."
+  :package-version '(Org . "9.2")
+  :group 'org-todo
+  :type 'hook)
 
 (defgroup org-priorities nil
   "Priorities in Org mode."
@@ -3311,7 +2741,7 @@ Depending on the system Emacs is running on, certain 
dates cannot
 be represented with the type used internally to represent time.
 Dates between 1970-1-1 and 2038-1-1 can always be represented
 correctly.  Some systems allow for earlier dates, some for later,
-some for both.  One way to find out it to insert any date into an
+some for both.  One way to find out is to insert any date into an
 Org buffer, putting the cursor on the year and hitting S-up and
 S-down to test the range.
 
@@ -3319,7 +2749,7 @@ When this variable is set to t, the date/time prompt will 
not let
 you specify dates outside the 1970-2037 range, so it is certain that
 these dates will work in whatever version of Emacs you are
 running, and also that you can move a file from one Emacs implementation
-to another.  WHenever Org is forcing the year for you, it will display
+to another.  Whenever Org is forcing the year for you, it will display
 a message and beep.
 
 When this variable is nil, Org will check if the date is
@@ -3415,7 +2845,7 @@ The value of this variable is an alist.  Associations 
either:
 where TAG is a tag as a string, SELECT is character, used to
 select that tag through the fast tag selection interface, and
 SPECIAL is one of the following keywords: `:startgroup',
-`:startgrouptag', `:grouptags', `:engroup', `:endgrouptag' or
+`:startgrouptag', `:grouptags', `:endgroup', `:endgrouptag' or
 `:newline'.  These keywords are used to define a hierarchy of
 tags.  See manual for details.
 
@@ -3452,7 +2882,7 @@ The value of this variable is an alist.  Associations 
either:
 where TAG is a tag as a string, SELECT is a character, used to
 select that tag through the fast tag selection interface, and
 SPECIAL is one of the following keywords: `:startgroup',
-`:startgrouptag', `:grouptags', `:engroup', `:endgrouptag' or
+`:startgrouptag', `:grouptags', `:endgroup', `:endgrouptag' or
 `:newline'.  These keywords are used to define a hierarchy of
 tags.  See manual for details.
 
@@ -3477,9 +2907,9 @@ 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 capture buffers, because there no list of
-tags in that file can be created dynamically (there are none).
+
+Setting this variable locally allows for dynamic generation of tag
+completions in capture buffers.
 
   (add-hook \\='org-capture-mode-hook
             (lambda ()
@@ -3610,8 +3040,8 @@ is better to limit inheritance to certain tags using the 
variables
   :group 'org-tags
   :type '(choice
          (const :tag "No sorting" nil)
-         (const :tag "Alphabetical" string<)
-         (const :tag "Reverse alphabetical" string>)
+         (const :tag "Alphabetical" org-string-collate-lessp)
+         (const :tag "Reverse alphabetical" org-string-collate-greaterp)
          (function :tag "Custom function" nil)))
 
 (defvar org-tags-history nil
@@ -3707,6 +3137,18 @@ This variable can be set on the per-file basis by 
inserting a line
   :group 'org-properties
   :type 'string)
 
+(defcustom org-columns-default-format-for-agenda nil
+  "The default column format in an agenda buffer.
+This will be used for column view in the agenda unless a format has
+been set by adding `org-overriding-columns-format' to the local
+settings list of a custom agenda view.  When nil, the columns format
+for the first item in the agenda list will be used, or as a fall-back,
+`org-columns-default-format'."
+  :group 'org-properties
+  :type '(choice
+         (const :tag "No default" nil)
+         (string :tag "Format string")))
+
 (defcustom org-columns-ellipses ".."
   "The ellipses to be used when a field in column view is truncated.
 When this is the empty string, as many characters as possible are shown,
@@ -3824,25 +3266,6 @@ A nil value means to remove them, after a query, from 
the list."
   :group 'org-agenda
   :type 'boolean)
 
-(defcustom org-calendar-to-agenda-key [?c]
-  "The key to be installed in `calendar-mode-map' for switching to the agenda.
-The command `org-calendar-goto-agenda' will be bound to this key.  The
-default is the character `c' because then `c' can be used to switch back and
-forth between agenda and calendar."
-  :group 'org-agenda
-  :type 'sexp)
-
-(defcustom org-calendar-insert-diary-entry-key [?i]
-  "The key to be installed in `calendar-mode-map' for adding diary entries.
-This option is irrelevant until `org-agenda-diary-file' has been configured
-to point to an Org file.  When that is the case, the command
-`org-agenda-diary-entry' will be bound to the key given here, by default
-`i'.  In the calendar, `i' normally adds entries to `diary-file'.  So
-if you want to continue doing this, you need to change this to a different
-key."
-  :group 'org-agenda
-  :type 'sexp)
-
 (defcustom org-agenda-diary-file 'diary-file
   "File to which to add new entries with the `i' key in agenda and calendar.
 When this is the symbol `diary-file', the functionality in the Emacs
@@ -3853,17 +3276,6 @@ points to a file, `org-agenda-diary-entry' will be used 
instead."
          (const :tag "The standard Emacs diary file" diary-file)
          (file :tag "Special Org file diary entries")))
 
-(eval-after-load "calendar"
-  '(progn
-     (org-defkey calendar-mode-map org-calendar-to-agenda-key
-                'org-calendar-goto-agenda)
-     (add-hook 'calendar-mode-hook
-              (lambda ()
-                (unless (eq org-agenda-diary-file 'diary-file)
-                  (define-key calendar-mode-map
-                    org-calendar-insert-diary-entry-key
-                    'org-agenda-diary-entry))))))
-
 (defgroup org-latex nil
   "Options for embedding LaTeX code into Org mode."
   :tag "Org LaTeX"
@@ -3955,12 +3367,11 @@ All available processes and theirs documents can be 
found in
      :image-output-type "png"
      :image-size-adjust (1.0 . 1.0)
      :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
-     :image-converter ("dvipng -fg %F -bg %B -D %D -T tight -o %O %f"))
+     :image-converter ("dvipng -D %D -T tight -o %O %f"))
     (dvisvgm
      :programs ("latex" "dvisvgm")
      :description "dvi > svg"
      :message "you need to install the programs: latex and dvisvgm."
-     :use-xcolor t
      :image-input-type "dvi"
      :image-output-type "svg"
      :image-size-adjust (1.7 . 1.5)
@@ -3970,7 +3381,6 @@ All available processes and theirs documents can be found 
in
      :programs ("latex" "convert")
      :description "pdf > png"
      :message "you need to install the programs: latex and imagemagick."
-     :use-xcolor t
      :image-input-type "pdf"
      :image-output-type "png"
      :image-size-adjust (1.0 . 1.0)
@@ -3990,11 +3400,6 @@ PROPERTIES accepts the following attributes:
   :message            string, message it when required programs cannot be 
found.
   :image-input-type   string, input file type of image converter (e.g., 
\"dvi\").
   :image-output-type  string, output file type of image converter (e.g., 
\"png\").
-  :use-xcolor         boolean, when non-nil, LaTeX \"xcolor\" macro is used to
-                      deal with background and foreground color of image.
-                      Otherwise, dvipng style background and foreground color
-                      format are generated.  You may then refer to them in
-                      command options with \"%F\" and \"%B\".
   :image-size-adjust  cons of numbers, the car element is used to adjust LaTeX
                       image size showed in buffer and the cdr element is for
                       HTML file.  This option is only useful for process
@@ -4026,8 +3431,6 @@ Place-holders used by `:image-converter' and 
`:latex-compiler':
 
 Place-holders only used by `:image-converter':
 
-  %F    foreground of image
-  %B    background of image
   %D    dpi, which is used to adjust image size by some processing commands.
   %S    the image size scale ratio, which is used to adjust image size by some
         processing commands."
@@ -4151,10 +3554,12 @@ A cell is of the format
 
 If SNIPPET-FLAG is non-nil, the package also needs to be included
 when compiling LaTeX snippets into images for inclusion into
-non-LaTeX output.  COMPILERS is a list of compilers that should
-include the package, see `org-latex-compiler'.  If the document
-compiler is not in the list, and the list is non-nil, the package
-will not be inserted in the final document.
+non-LaTeX output.
+
+COMPILERS is a list of compilers that should include the package,
+see `org-latex-compiler'.  If the document compiler is not in the
+list, and the list is non-nil, the package will not be inserted
+in the final document.
 
 A string will be inserted as-is in the header of the document."
   :group 'org-latex
@@ -4182,12 +3587,17 @@ Each element is either a cell or a string.
 
 A cell is of the format:
 
-    (\"options\" \"package\" SNIPPET-FLAG)
+    (\"options\" \"package\" SNIPPET-FLAG COMPILERS)
 
 SNIPPET-FLAG, when non-nil, indicates that this package is also
 needed when turning LaTeX snippets into images for inclusion into
 non-LaTeX output.
 
+COMPILERS is a list of compilers that should include the package,
+see `org-latex-compiler'.  If the document compiler is not in the
+list, and the list is non-nil, the package will not be inserted
+in the final document.
+
 A string will be inserted as-is in the header of the document.
 
 Make sure that you only list packages here which:
@@ -4278,10 +3688,18 @@ org-level-* faces."
   :group 'org-appearance
   :type 'boolean)
 
+(defcustom org-fontify-whole-block-delimiter-line t
+  "Non-nil means fontify the whole line for begin/end lines of blocks.
+This is useful when setting a background color for the
+org-block-begin-line and org-block-end-line faces."
+  :group 'org-appearance
+  :type 'boolean)
+
 (defcustom org-highlight-latex-and-related nil
   "Non-nil means highlight LaTeX related syntax in the buffer.
 When non-nil, the value should be a list containing any of the
 following symbols:
+  `native'   Highlight LaTeX snippets and environments natively.
   `latex'    Highlight LaTeX snippets and environments.
   `script'   Highlight subscript and superscript.
   `entities' Highlight entities."
@@ -4291,6 +3709,7 @@ following symbols:
   :type '(choice
          (const :tag "No highlighting" nil)
          (set :greedy t :tag "Highlight"
+              (const :tag "LaTeX snippets and environments (native)" native)
               (const :tag "LaTeX snippets and environments" latex)
               (const :tag "Subscript and superscript" script)
               (const :tag "Entities" entities))))
@@ -4298,7 +3717,8 @@ following symbols:
 (defcustom org-hide-emphasis-markers nil
   "Non-nil mean font-lock should hide the emphasis marker characters."
   :group 'org-appearance
-  :type 'boolean)
+  :type 'boolean
+  :safe #'booleanp)
 
 (defcustom org-hide-macro-markers nil
   "Non-nil mean font-lock should hide the brackets marking macro calls."
@@ -4356,7 +3776,7 @@ After a match, the match groups contain these elements:
 ;; set this option proved cumbersome.  See this message/thread:
 ;; http://article.gmane.org/gmane.emacs.orgmode/68681
 (defvar org-emphasis-regexp-components
-  '("- \t('\"{" "- \t.,:!?;'\")}\\[" " \t\r\n" "." 1)
+  '("-[:space:]('\"{" "-[:space:].,:!?;'\")}\\[" "[:space:]" "." 1)
   "Components used to build the regular expression for emphasis.
 This is a list with five entries.  Terminology:  In an emphasis string
 like \" *strong word* \", we call the initial space PREMATCH, the final
@@ -4371,7 +3791,7 @@ body-regexp  A regexp like \".\" to match a body 
character.  Don't use
              non-shy groups here, and don't allow newline here.
 newline      The maximum number of newlines allowed in an emphasis exp.
 
-You need to reload Org or to restart Emacs after customizing this.")
+You need to reload Org or to restart Emacs after setting this.")
 
 (defcustom org-emphasis-alist
   '(("*" bold)
@@ -4434,23 +3854,22 @@ This is needed for font-lock setup.")
                  "org-agenda"
                  (extra txt &optional level category tags dotime
                         remove-re habitp))
-(declare-function org-agenda-maybe-redo "org-agenda" ())
 (declare-function org-agenda-new-marker "org-agenda" (&optional pos))
 (declare-function org-agenda-save-markers-for-cut-and-paste
                  "org-agenda"
                  (beg end))
 (declare-function org-agenda-set-restriction-lock "org-agenda" (&optional 
type))
 (declare-function org-agenda-skip "org-agenda" ())
-(declare-function org-attach-reveal "org-attach" (&optional if-exists))
+(declare-function org-attach-expand "org-attach" (file))
+(declare-function org-attach-reveal "org-attach" ())
+(declare-function org-attach-reveal-in-emacs "org-attach" ())
 (declare-function org-gnus-follow-link "org-gnus" (&optional group article))
 (declare-function org-indent-mode "org-indent" (&optional arg))
 (declare-function org-inlinetask-goto-beginning "org-inlinetask" ())
 (declare-function org-inlinetask-goto-end "org-inlinetask" ())
 (declare-function org-inlinetask-in-task-p "org-inlinetask" ())
 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
-(declare-function orgtbl-send-table "org-table" (&optional maybe))
 (declare-function parse-time-string "parse-time" (string))
-(declare-function speedbar-line-directory "speedbar" (&optional depth))
 
 (defvar align-mode-rules-list)
 (defvar calc-embedded-close-formula)
@@ -4462,64 +3881,11 @@ This is needed for font-lock setup.")
 (defvar remember-data-file)
 (defvar texmathp-why)
 
-;;;###autoload
-(defun turn-on-orgtbl ()
-  "Unconditionally turn on `orgtbl-mode'."
-  (require 'org-table)
-  (orgtbl-mode 1))
-
-(defun org-at-table-p (&optional table-type)
-  "Non-nil if the cursor is inside an Org table.
-If TABLE-TYPE is non-nil, also check for table.el-type tables."
-  (and (org-match-line (if table-type "[ \t]*[|+]" "[ \t]*|"))
-       (or (not (derived-mode-p 'org-mode))
-          (let ((e (org-element-lineage (org-element-at-point) '(table) t)))
-            (and e (or table-type
-                       (eq 'org (org-element-property :type e))))))))
-
-(defun org-at-table.el-p ()
-  "Non-nil when point is at a table.el table."
-  (and (org-match-line "[ \t]*[|+]")
-       (let ((element (org-element-at-point)))
-        (and (eq (org-element-type element) 'table)
-             (eq (org-element-property :type element) 'table.el)))))
-
-(defun org-at-table-hline-p ()
-  "Non-nil when point is inside a hline in a table.
-Assume point is already in a table."
-  (org-match-line org-table-hline-regexp))
-
-(defun org-table-map-tables (function &optional quietly)
-  "Apply FUNCTION to the start of all tables in the buffer."
-  (org-with-wide-buffer
-   (goto-char (point-min))
-   (while (re-search-forward org-table-any-line-regexp nil t)
-     (unless quietly
-       (message "Mapping tables: %d%%"
-               (floor (* 100.0 (point)) (buffer-size))))
-     (beginning-of-line 1)
-     (when (and (looking-at org-table-line-regexp)
-               ;; Exclude tables in src/example/verbatim/clocktable blocks
-               (not (org-in-block-p '("src" "example" "verbatim" 
"clocktable"))))
-       (save-excursion (funcall function))
-       (or (looking-at org-table-line-regexp)
-          (forward-char 1)))
-     (re-search-forward org-table-any-border-regexp nil 1)))
-  (unless quietly (message "Mapping tables: done")))
-
 (declare-function org-clock-save-markers-for-cut-and-paste "org-clock" (beg 
end))
-(declare-function org-clock-update-mode-line "org-clock" ())
+(declare-function org-clock-update-mode-line "org-clock" (&optional refresh))
 (declare-function org-resolve-clocks "org-clock"
                  (&optional also-non-dangling-p prompt last-valid))
 
-(defun org-at-TBLFM-p (&optional pos)
-  "Non-nil when point (or POS) is in #+TBLFM line."
-  (save-excursion
-    (goto-char (or pos (point)))
-    (beginning-of-line)
-    (and (let ((case-fold-search t)) (looking-at org-TBLFM-regexp))
-        (eq (org-element-type (org-element-at-point)) 'table))))
-
 (defvar org-clock-start-time)
 (defvar org-clock-marker (make-marker)
   "Marker recording the last clock-in.")
@@ -4704,19 +4070,17 @@ STATE should be one of the symbols listed in the 
docstring of
      ;; Include headline point is currently on.
      (beginning-of-line)
      (while (and (< (point) end) (re-search-forward re end t))
-       (when (member org-archive-tag (org-get-tags))
+       (when (member org-archive-tag (org-get-tags nil t))
         (org-flag-subtree t)
         (org-end-of-subtree t))))))
 
-(declare-function outline-end-of-heading "outline" ())
-(declare-function outline-flag-region "outline" (from to flag))
 (defun org-flag-subtree (flag)
   (save-excursion
     (org-back-to-heading t)
-    (outline-end-of-heading)
-    (outline-flag-region (point)
-                        (progn (org-end-of-subtree t) (point))
-                        flag)))
+    (org-flag-region (line-end-position)
+                    (progn (org-end-of-subtree t) (point))
+                    flag
+                    'outline)))
 
 (defalias 'org-advertized-archive-subtree 'org-archive-subtree)
 
@@ -4831,6 +4195,7 @@ After a match, the following groups carry important 
information:
     ("oddeven" org-odd-levels-only nil)
     ("align" org-startup-align-all-tables t)
     ("noalign" org-startup-align-all-tables nil)
+    ("shrink" org-startup-shrink-all-tables t)
     ("inlineimages" org-startup-with-inline-images t)
     ("noinlineimages" org-startup-with-inline-images nil)
     ("latexpreview" org-startup-with-latex-preview t)
@@ -4903,17 +4268,39 @@ Support for group tags is controlled by the option
   (message "Groups tags support has been turned %s"
           (if org-group-tags "on" "off")))
 
-(defun org-tag-add-to-alist (alist1 alist2)
-  "Append ALIST1 elements to ALIST2 if they are not there yet."
+(defun org--tag-add-to-alist (alist1 alist2)
+  "Merge tags from ALIST1 into ALIST2.
+
+Duplicates tags outside a group are removed.  Keywords and order
+are preserved.
+
+The function assumes ALIST1 and ALIST2 are proper tag alists.
+See `org-tag-alist' for their structure."
   (cond
    ((null alist2) alist1)
    ((null alist1) alist2)
-   (t (let ((alist2-cars (mapcar (lambda (x) (car-safe x)) alist2))
-           to-add)
-       (dolist (i alist1)
-         (unless (member (car-safe i) alist2-cars)
-           (push i to-add)))
-       (append to-add alist2)))))
+   (t
+    (let ((to-add nil)
+         (group-flag nil))
+      (dolist (tag-pair alist1)
+       (pcase tag-pair
+         (`(,(or :startgrouptag :startgroup))
+          (setq group-flag t)
+          (push tag-pair to-add))
+         (`(,(or :endgrouptag :endgroup))
+          (setq group-flag nil)
+          (push tag-pair to-add))
+         (`(,(or :grouptags :newline))
+          (push tag-pair to-add))
+         (`(,tag . ,_)
+          ;; Remove duplicates from ALIST1, unless they are in
+          ;; a group.  Indeed, it makes sense to have a tag appear in
+          ;; multiple groups.
+          (when (or group-flag (not (assoc tag alist2)))
+            (push tag-pair to-add)))
+         (_ (error "Invalid association in tag alist: %S" tag-pair))))
+      ;; Preserve order of ALIST1.
+      (append (nreverse to-add) alist2)))))
 
 (defun org-set-regexps-and-options (&optional tags-only)
   "Precompute regular expressions used in the current buffer.
@@ -4943,7 +4330,7 @@ related expressions."
                  (mapcar #'org-add-prop-inherited
                          (cdr (assq 'filetags alist))))
       (setq org-current-tag-alist
-           (org-tag-add-to-alist
+           (org--tag-add-to-alist
             org-tag-persistent-alist
             (let ((tags (cdr (assq 'tags alist))))
               (if tags (org-tag-string-to-alist tags)
@@ -5167,8 +4554,7 @@ Return value contains the following keys: `archive', 
`category',
              ((equal key "SETUPFILE")
               (unless buffer-read-only ; Do not check in Gnus messages.
                 (let ((f (and (org-string-nw-p value)
-                              (expand-file-name
-                               (org-unbracket-string "\"" "\"" value)))))
+                              (expand-file-name (org-strip-quotes value)))))
                   (when (and f (file-readable-p f) (not (member f files)))
                     (with-temp-buffer
                       (setq default-directory (file-name-directory f))
@@ -5187,8 +4573,7 @@ S is a value for TAGS keyword or produced with
 `org-tag-alist-to-string'.  Return value is an alist suitable for
 `org-tag-alist' or `org-tag-persistent-alist'."
   (let ((lines (mapcar #'split-string (split-string s "\n" t)))
-       (tag-re (concat "\\`\\([[:alnum:]_@#%]+"
-                       "\\|{.+?}\\)"   ; regular expression
+       (tag-re (concat "\\`\\(" org-tag-re "\\|{.+?}\\)" ; regular expression
                        "\\(?:(\\(.\\))\\)?\\'"))
        alist group-flag)
     (dolist (tokens lines (cdr (nreverse alist)))
@@ -5387,12 +4772,6 @@ This is for getting out of special buffers like 
capture.")
 
 ;;;; Define the Org mode
 
-;; We use a before-change function to check if a table might need
-;; an update.
-(defvar org-table-may-need-update t
-  "Indicates that a table might need an update.
-This variable is set by `org-before-change-function'.
-`org-table-align' sets it back to nil.")
 (defun org-before-change-function (_beg _end)
   "Every change indicates that a table might need an update."
   (setq org-table-may-need-update t))
@@ -5401,7 +4780,6 @@ This variable is set by `org-before-change-function'.
 (defvar org-agenda-keep-modes nil)      ; Dynamically-scoped param.
 (defvar org-inhibit-logging nil)        ; Dynamically-scoped param.
 (defvar org-inhibit-blocking nil)       ; Dynamically-scoped param.
-(defvar org-table-buffer-is-an nil)
 
 (defvar bidi-paragraph-direction)
 (defvar buffer-face-mode-face)
@@ -5447,20 +4825,11 @@ can be exported as a structured ASCII or HTML file.
 The following commands are available:
 
 \\{org-mode-map}"
-
-  ;; Get rid of Outline menus, they are not needed
-  ;; Need to do this here because define-derived-mode sets up
-  ;; the keymap so late.  Still, it is a waste to call this each time
-  ;; we switch another buffer into Org mode.
-  (define-key org-mode-map [menu-bar headings] 'undefined)
-  (define-key org-mode-map [menu-bar hide] 'undefined)
-  (define-key org-mode-map [menu-bar show] 'undefined)
-
   (org-load-modules-maybe)
   (org-install-agenda-files-menu)
-  (when org-descriptive-links (add-to-invisibility-spec '(org-link)))
-  (add-to-invisibility-spec '(org-cwidth))
+  (when org-link-descriptive (add-to-invisibility-spec '(org-link)))
   (add-to-invisibility-spec '(org-hide-block . t))
+  (add-to-invisibility-spec '(org-hide-drawer . t))
   (setq-local outline-regexp org-outline-regexp)
   (setq-local outline-level 'org-outline-level)
   (setq bidi-paragraph-direction 'left-to-right)
@@ -5480,10 +4849,11 @@ The following commands are available:
   ;; Calc embedded
   (setq-local calc-embedded-open-mode "# ")
   ;; Modify a few syntax entries
-  (modify-syntax-entry ?@ "w")
   (modify-syntax-entry ?\" "\"")
   (modify-syntax-entry ?\\ "_")
   (modify-syntax-entry ?~ "_")
+  (modify-syntax-entry ?< "(>")
+  (modify-syntax-entry ?> ")<")
   (setq-local font-lock-unfontify-region-function 'org-unfontify-region)
   ;; Activate before-change-function
   (setq-local org-table-may-need-update t)
@@ -5513,6 +4883,8 @@ The following commands are available:
                  (forward-char -1))))
   ;; Next error for sparse trees
   (setq-local next-error-function 'org-occur-next-match)
+  ;; Make commit log messages from Org documents easier.
+  (setq-local add-log-current-defun-function #'org-add-log-current-headline)
   ;; Make sure dependence stuff works reliably, even for users who set it
   ;; too late :-(
   (if org-enforce-todo-dependencies
@@ -5533,9 +4905,6 @@ The following commands are available:
       (regexp . "^[ \t]*#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
       (modes . '(org-mode)))))
 
-  ;; Imenu
-  (setq-local imenu-create-index-function 'org-imenu-get-tree)
-
   ;; Make isearch reveal context
   (setq-local outline-isearch-open-invisible-function
              (lambda (&rest _) (org-show-context 'isearch)))
@@ -5559,14 +4928,19 @@ The following commands are available:
   (unless org-inhibit-startup
     (org-unmodified
      (when org-startup-with-beamer-mode (org-beamer-mode))
-     (when org-startup-align-all-tables
-       (org-table-map-tables #'org-table-align t))
+     (when (or org-startup-align-all-tables org-startup-shrink-all-tables)
+       (org-table-map-tables
+       (cond ((and org-startup-align-all-tables
+                   org-startup-shrink-all-tables)
+              (lambda () (org-table-align) (org-table-shrink)))
+             (org-startup-align-all-tables #'org-table-align)
+             (t #'org-table-shrink))
+       t))
      (when org-startup-with-inline-images (org-display-inline-images))
-     (when org-startup-with-latex-preview (org-toggle-latex-fragment '(16)))
+     (when org-startup-with-latex-preview (org-latex-preview '(16)))
      (unless org-inhibit-startup-visibility-stuff (org-set-startup-visibility))
      (when org-startup-truncated (setq truncate-lines t))
-     (when org-startup-indented (require 'org-indent) (org-indent-mode 1))
-     (org-refresh-effort-properties)))
+     (when org-startup-indented (require 'org-indent) (org-indent-mode 1))))
   ;; Try to set `org-hide' face correctly.
   (let ((foreground (org-find-invisible-foreground)))
     (when foreground
@@ -5580,7 +4954,8 @@ The following commands are available:
                   ("8.2.7" . "24.4")
                   ("8.3" . "26.1")
                   ("9.0" . "26.1")
-                  ("9.1" . "26.1")))
+                  ("9.1" . "26.1")
+                  ("9.2" . "27.1")))
 
 (defvar org-mode-transpose-word-syntax-table
   (let ((st (make-syntax-table text-mode-syntax-table)))
@@ -5618,56 +4993,19 @@ the rounding returns a past time."
       (let* ((time (decode-time now))
             (res (apply #'encode-time 0 (* r (round (nth 1 time) r))
                         (nthcdr 2 time))))
-       (if (or (not past) (time-less-p res now))
+       (if (or (not past) (org-time-less-p res now))
            res
-         (time-subtract res (* r 60)))))))
+         (org-time-subtract res (* r 60)))))))
 
 (defun org-today ()
   "Return today date, considering `org-extend-today-until'."
   (time-to-days
-   (time-since (* 3600 org-extend-today-until))))
+   (org-time-since (* 3600 org-extend-today-until))))
 
 ;;;; Font-Lock stuff, including the activators
 
-(defvar org-mouse-map (make-sparse-keymap))
-(org-defkey org-mouse-map [mouse-2] 'org-open-at-mouse)
-(org-defkey org-mouse-map [mouse-3] 'org-find-file-at-mouse)
-(when org-mouse-1-follows-link
-  (org-defkey org-mouse-map [follow-link] 'mouse-face))
-(when org-tab-follows-link
-  (org-defkey org-mouse-map [(tab)] 'org-open-at-point)
-  (org-defkey org-mouse-map "\C-i" 'org-open-at-point))
-
 (require 'font-lock)
 
-(defconst org-non-link-chars "]\t\n\r<>")
-(defvar org-link-types-re nil
-  "Matches a link that has a url-like prefix like \"http:\"")
-(defvar org-link-re-with-space nil
-  "Matches a link with spaces, optional angular brackets around it.")
-(defvar org-link-re-with-space2 nil
-  "Matches a link with spaces, optional angular brackets around it.")
-(defvar org-link-re-with-space3 nil
-  "Matches a link with spaces, only for internal part in bracket links.")
-(defvar org-angle-link-re nil
-  "Matches link with angular brackets, spaces are allowed.")
-(defvar org-plain-link-re nil
-  "Matches plain link, without spaces.")
-(defvar org-bracket-link-regexp nil
-  "Matches a link in double brackets.")
-(defvar org-bracket-link-analytic-regexp nil
-  "Regular expression used to analyze links.
-Here is what the match groups contain after a match:
-1: http:
-2: http
-3: path
-4: [desc]
-5: desc")
-(defvar org-bracket-link-analytic-regexp++ nil
-  "Like `org-bracket-link-analytic-regexp', but include coderef internal 
type.")
-(defvar org-any-link-re nil
-  "Regular expression matching any link.")
-
 (defconst org-match-sexp-depth 3
   "Number of stacked braces for sub/superscript matching.")
 
@@ -5705,59 +5043,6 @@ stacked delimiters is N.  Escaping delimiters is not 
possible."
    "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)")
   "The regular expression matching a sub- or superscript, forcing braces.")
 
-(defun org-make-link-regexps ()
-  "Update the link regular expressions.
-This should be called after the variable `org-link-parameters' has changed."
-  (let ((types-re (regexp-opt (org-link-types) t)))
-    (setq org-link-types-re
-         (concat "\\`" types-re ":")
-         org-link-re-with-space
-         (concat "<?" types-re ":"
-                 "\\([^" org-non-link-chars " ]"
-                 "[^" org-non-link-chars "]*"
-                 "[^" org-non-link-chars " ]\\)>?")
-         org-link-re-with-space2
-         (concat "<?" types-re ":"
-                 "\\([^" org-non-link-chars " ]"
-                 "[^\t\n\r]*"
-                 "[^" org-non-link-chars " ]\\)>?")
-         org-link-re-with-space3
-         (concat "<?" types-re ":"
-                 "\\([^" org-non-link-chars " ]"
-                 "[^\t\n\r]*\\)")
-         org-angle-link-re
-         (format "<%s:\\([^>\n]*\\(?:\n[ \t]*[^> \t\n][^>\n]*\\)*\\)>"
-                 types-re)
-         org-plain-link-re
-         (concat
-          "\\<" types-re ":"
-          "\\([^][ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] 
\t\n]\\|/\\)\\)\\)")
-         ;;     "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
-         org-bracket-link-regexp
-         "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
-         org-bracket-link-analytic-regexp
-         (concat
-          "\\[\\["
-          "\\(" types-re ":\\)?"
-          "\\([^]]+\\)"
-          "\\]"
-          "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
-          "\\]")
-         org-bracket-link-analytic-regexp++
-         (concat
-          "\\[\\["
-          "\\(" (regexp-opt (cons "coderef" (org-link-types)) t) ":\\)?"
-          "\\([^]]+\\)"
-          "\\]"
-          "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
-          "\\]")
-         org-any-link-re
-         (concat "\\(" org-bracket-link-regexp "\\)\\|\\("
-                 org-angle-link-re "\\)\\|\\("
-                 org-plain-link-re "\\)"))))
-
-(org-make-link-regexps)
-
 (defvar org-emph-face nil)
 
 (defun org-do-emphasis-faces (limit)
@@ -5796,7 +5081,9 @@ This should be called after the variable 
`org-link-parameters' has changed."
               (match-beginning 2) (match-end 2) 'face face)
              (when verbatim?
                (org-remove-flyspell-overlays-in
-                (match-beginning 0) (match-end 0)))
+                (match-beginning 0) (match-end 0))
+               (remove-text-properties (match-beginning 2) (match-end 2)
+                                       '(display t invisible t intangible t)))
              (add-text-properties (match-beginning 2) (match-end 2)
                                   '(font-lock-multiline t org-emphasis t))
              (when org-hide-emphasis-markers
@@ -5861,13 +5148,18 @@ prompted for."
   "Add link properties to links.
 This includes angle, plain, and bracket links."
   (catch :exit
-    (while (re-search-forward org-any-link-re limit t)
+    (while (re-search-forward org-link-any-re limit t)
       (let* ((start (match-beginning 0))
             (end (match-end 0))
+            (visible-start (or (match-beginning 3) (match-beginning 2)))
+            (visible-end (or (match-end 3) (match-end 2)))
             (style (cond ((eq ?< (char-after start)) 'angle)
                          ((eq ?\[ (char-after (1+ start))) 'bracket)
                          (t 'plain))))
        (when (and (memq style org-highlight-links)
+                  ;; Do not span over paragraph boundaries.
+                  (not (string-match-p org-element-paragraph-separate
+                                       (match-string 0)))
                   ;; Do not confuse plain links with tags.
                   (not (and (eq style 'plain)
                             (let ((face (get-text-property
@@ -5910,9 +5202,7 @@ This includes angle, plain, and bracket links."
                     (append `(invisible
                               ,(or (org-link-get-parameter type :display)
                                    'org-link))
-                            properties))
-                   (visible-start (or (match-beginning 4) (match-beginning 2)))
-                   (visible-end (or (match-end 4) (match-end 2))))
+                            properties)))
                (add-text-properties start visible-start hidden)
                (add-text-properties visible-start visible-end properties)
                (add-text-properties visible-end end hidden)
@@ -5962,57 +5252,64 @@ by a #."
           "^\\([ \t]*#\\(\\(\\+[a-zA-Z]+:?\\| 
\\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
           limit t)
       (let ((beg (match-beginning 0))
-           (block-start (match-end 0))
-           (block-end nil)
-           (lang (match-string 7))
-           (beg1 (line-beginning-position 2))
+           (end-of-beginline (match-end 0))
+           (block-start (match-end 0))  ; includes the \n at end of #+begin 
line
+           (block-end nil)              ; will include \n after end of block 
content
+           (lang (match-string 7))      ; the language, if it is an src block
+           (bol-after-beginline (line-beginning-position 2))
            (dc1 (downcase (match-string 2)))
            (dc3 (downcase (match-string 3)))
-           end end1 quoting block-type)
+           (whole-blockline org-fontify-whole-block-delimiter-line)
+           beg-of-endline end-of-endline nl-before-endline quoting block-type)
        (cond
         ((and (match-end 4) (equal dc3 "+begin"))
          ;; Truly a block
          (setq block-type (downcase (match-string 5))
-               quoting (member block-type org-protecting-blocks))
+               quoting (member block-type org-protecting-blocks)) ; src, 
example, export, maybe more
          (when (re-search-forward
                 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
                 nil t)  ;; on purpose, we look further than LIMIT
-           (setq end (min (point-max) (match-end 0))
-                 end1 (min (point-max) (1- (match-beginning 0))))
-           (setq block-end (match-beginning 0))
+           ;; We do have a matching #+end line
+           (setq beg-of-endline (match-beginning 0)
+                 end-of-endline (match-end 0)
+                 nl-before-endline (1- (match-beginning 0)))
+           (setq block-end (match-beginning 0)) ; includes the final newline.
            (when quoting
-             (org-remove-flyspell-overlays-in beg1 end1)
-             (remove-text-properties beg end
+             (org-remove-flyspell-overlays-in bol-after-beginline 
nl-before-endline)
+             (remove-text-properties beg end-of-endline
                                      '(display t invisible t intangible t)))
            (add-text-properties
-            beg end '(font-lock-fontified t font-lock-multiline t))
-           (add-text-properties beg beg1 '(face org-meta-line))
-           (org-remove-flyspell-overlays-in beg beg1)
-           (add-text-properties        ; For end_src
-            end1 (min (point-max) (1+ end)) '(face org-meta-line))
-           (org-remove-flyspell-overlays-in end1 end)
+            beg end-of-endline '(font-lock-fontified t font-lock-multiline t))
+           (org-remove-flyspell-overlays-in beg bol-after-beginline)
+           (org-remove-flyspell-overlays-in nl-before-endline end-of-endline)
            (cond
             ((and lang (not (string= lang "")) org-src-fontify-natively)
              (org-src-font-lock-fontify-block lang block-start block-end)
-             (add-text-properties beg1 block-end '(src-block t)))
+             (add-text-properties bol-after-beginline block-end '(src-block 
t)))
             (quoting
-             (add-text-properties beg1 (min (point-max) (1+ end1))
-                                  (list 'face
-                                        (list :inherit
-                                              (let ((face-name
-                                                     (intern (format 
"org-block-%s" lang))))
-                                                (append (and (facep face-name) 
(list face-name))
-                                                        '(org-block))))))) ; 
end of source block
+             (add-text-properties
+              bol-after-beginline beg-of-endline
+              (list 'face
+                    (list :inherit
+                          (let ((face-name
+                                 (intern (format "org-block-%s" lang))))
+                            (append (and (facep face-name) (list face-name))
+                                    '(org-block)))))))
             ((not org-fontify-quote-and-verse-blocks))
             ((string= block-type "quote")
              (add-face-text-property
-              beg1 (min (point-max) (1+ end1)) 'org-quote t))
+              bol-after-beginline beg-of-endline 'org-quote t))
             ((string= block-type "verse")
              (add-face-text-property
-              beg1 (min (point-max) (1+ end1)) 'org-verse t)))
-           (add-text-properties beg beg1 '(face org-block-begin-line))
-           (add-text-properties (min (point-max) (1+ end)) (min (point-max) 
(1+ end1))
-                                '(face org-block-end-line))
+              bol-after-beginline beg-of-endline 'org-verse t)))
+           ;; Fontify the #+begin and #+end lines of the blocks
+           (add-text-properties
+            beg (if whole-blockline bol-after-beginline end-of-beginline)
+            '(face org-block-begin-line))
+           (add-text-properties
+            beg-of-endline
+            (min (point-max) (if whole-blockline (min (point-max) (1+ 
end-of-endline)) end-of-endline))
+            '(face org-block-end-line))
            t))
         ((member dc1 '("+title:" "+author:" "+email:" "+date:"))
          (org-remove-flyspell-overlays-in
@@ -6042,6 +5339,7 @@ by a #."
                               '(font-lock-fontified t face org-block))
          t)
         ((member dc3 '(" " ""))
+                                        ; Just a comment, the plus was not 
there
          (org-remove-flyspell-overlays-in beg (match-end 0))
          (add-text-properties
           beg (match-end 0)
@@ -6058,9 +5356,10 @@ by a #."
   "Fontify drawers."
   (when (re-search-forward org-drawer-regexp limit t)
     (add-text-properties
-     (match-beginning 0) (match-end 0)
-     '(font-lock-fontified t face org-special-keyword))
-    (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
+     (line-beginning-position) (line-beginning-position 2)
+     '(font-lock-fontified t face org-drawer))
+    (org-remove-flyspell-overlays-in
+     (line-beginning-position) (line-beginning-position 2))
     t))
 
 (defun org-fontify-macros (limit)
@@ -6081,6 +5380,24 @@ by a #."
            (add-text-properties closing-start end '(invisible t)))
          t)))))
 
+(defun org-fontify-extend-region (beg end _old-len)
+  (let ((begin-re "\\(\\\\\\[\\|\\(#\\+begin_\\|\\\\begin{\\)\\S-+\\)")
+       (end-re "\\(\\\\\\]\\|\\(#\\+end_\\|\\\\end{\\)\\S-+\\)")
+       (extend (lambda (r1 r2 dir)
+                 (let ((re (replace-regexp-in-string "\\(begin\\|end\\)" r1
+                                                     (replace-regexp-in-string 
"[][]" r2
+                                                                               
(match-string-no-properties 0)))))
+                   (re-search-forward (regexp-quote re) nil t dir)))))
+    (save-match-data
+      (save-excursion
+       (goto-char beg)
+       (back-to-indentation)
+       (cond ((looking-at end-re)
+              (cons (or (funcall extend "begin" "[" -1) beg) end))
+             ((looking-at begin-re)
+              (cons beg (or (funcall extend "end" "]" 1) end)))
+             (t (cons beg end)))))))
+
 (defun org-activate-footnote-links (limit)
   "Add text properties for footnotes."
   (let ((fn (org-footnote-next-reference-or-definition limit)))
@@ -6120,25 +5437,13 @@ by a #."
       (org-display-custom-time (match-beginning 1) (match-end 1)))
     t))
 
-(defvar-local org-target-link-regexp nil
-  "Regular expression matching radio targets in plain text.")
-
-(defconst org-target-regexp (let ((border "[^<>\n\r \t]"))
-                             (format "<<\\(%s\\|%s[^<>\n\r]*%s\\)>>"
-                                     border border border))
-  "Regular expression matching a link target.")
-
-(defconst org-radio-target-regexp (format "<%s>" org-target-regexp)
-  "Regular expression matching a radio target.")
-
-(defconst org-any-target-regexp
-  (format "%s\\|%s" org-radio-target-regexp org-target-regexp)
-  "Regular expression matching any target.")
-
 (defun org-activate-target-links (limit)
   "Add text properties for target matches."
   (when org-target-link-regexp
     (let ((case-fold-search t))
+      ;; `org-target-link-regexp' matches one character before the
+      ;; actual target.
+      (unless (bolp) (forward-char -1))
       (when (re-search-forward org-target-link-regexp limit t)
        (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
        (add-text-properties (match-beginning 1) (match-end 1)
@@ -6149,113 +5454,57 @@ by a #."
        (org-rear-nonsticky-at (match-end 1))
        t))))
 
-(defun org-update-radio-target-regexp ()
-  "Find all radio targets in this file and update the regular expression.
-Also refresh fontification if needed."
-  (interactive)
-  (let ((old-regexp org-target-link-regexp)
-       (before-re "\\(?:^\\|[^[:alnum:]]\\)\\(")
-       (after-re "\\)\\(?:$\\|[^[:alnum:]]\\)")
-       (targets
-        (org-with-wide-buffer
-         (goto-char (point-min))
-         (let (rtn)
-           (while (re-search-forward org-radio-target-regexp nil t)
-             ;; Make sure point is really within the object.
-             (backward-char)
-             (let ((obj (org-element-context)))
-               (when (eq (org-element-type obj) 'radio-target)
-                 (cl-pushnew (org-element-property :value obj) rtn
-                             :test #'equal))))
-           rtn))))
-    (setq org-target-link-regexp
-         (and targets
-              (concat before-re
-                      (mapconcat
-                       (lambda (x)
-                         (replace-regexp-in-string
-                          " +" "\\s-+" (regexp-quote x) t t))
-                       targets
-                       "\\|")
-                      after-re)))
-    (unless (equal old-regexp org-target-link-regexp)
-      ;; Clean-up cache.
-      (let ((regexp (cond ((not old-regexp) org-target-link-regexp)
-                         ((not org-target-link-regexp) old-regexp)
-                         (t
-                          (concat before-re
-                                  (mapconcat
-                                   (lambda (re)
-                                     (substring re (length before-re)
-                                                (- (length after-re))))
-                                   (list old-regexp org-target-link-regexp)
-                                   "\\|")
-                                  after-re)))))
-       (org-with-wide-buffer
-        (goto-char (point-min))
-        (while (re-search-forward regexp nil t)
-          (org-element-cache-refresh (match-beginning 1)))))
-      ;; Re fontify buffer.
-      (when (memq 'radio org-highlight-links)
-       (org-restart-font-lock)))))
-
-(defun org-hide-wide-columns (limit)
-  (let (s e)
-    (setq s (text-property-any (point) (or limit (point-max))
-                              'org-cwidth t))
-    (when s
-      (setq e (next-single-property-change s 'org-cwidth))
-      (add-text-properties s e '(invisible org-cwidth))
-      (goto-char e)
-      t)))
-
 (defvar org-latex-and-related-regexp nil
   "Regular expression for highlighting LaTeX, entities and sub/superscript.")
 
 (defun org-compute-latex-and-related-regexp ()
   "Compute regular expression for LaTeX, entities and sub/superscript.
 Result depends on variable `org-highlight-latex-and-related'."
-  (setq-local
-   org-latex-and-related-regexp
-   (let* ((re-sub
-          (cond ((not (memq 'script org-highlight-latex-and-related)) nil)
-                ((eq org-use-sub-superscripts '{})
-                 (list org-match-substring-with-braces-regexp))
-                (org-use-sub-superscripts (list org-match-substring-regexp))))
-         (re-latex
-          (when (memq 'latex org-highlight-latex-and-related)
-            (let ((matchers (plist-get org-format-latex-options :matchers)))
-              (delq nil
-                    (mapcar (lambda (x)
-                              (and (member (car x) matchers) (nth 1 x)))
-                            org-latex-regexps)))))
-         (re-entities
-          (when (memq 'entities org-highlight-latex-and-related)
-            (list 
"\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\)"))))
-     (mapconcat 'identity (append re-latex re-entities re-sub) "\\|"))))
-
-(defun org-do-latex-and-related (limit)
+  (let ((re-sub
+        (cond ((not (memq 'script org-highlight-latex-and-related)) nil)
+              ((eq org-use-sub-superscripts '{})
+               (list org-match-substring-with-braces-regexp))
+              (org-use-sub-superscripts (list org-match-substring-regexp))))
+       (re-latex
+        (when (or (memq 'latex org-highlight-latex-and-related)
+                  (memq 'native org-highlight-latex-and-related))
+          (let ((matchers (plist-get org-format-latex-options :matchers)))
+            (delq nil
+                  (mapcar (lambda (x)
+                            (and (member (car x) matchers) (nth 1 x)))
+                          org-latex-regexps)))))
+       (re-entities
+        (when (memq 'entities org-highlight-latex-and-related)
+          (list "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\
+\\($\\|{}\\|[^[:alpha:]]\\)"))))
+    (setq-local org-latex-and-related-regexp
+               (mapconcat #'identity
+                          (append re-latex re-entities re-sub)
+                          "\\|"))))
+
+(defun org-do-latex-and-related (_limit)
   "Highlight LaTeX snippets and environments, entities and sub/superscript.
-LIMIT bounds the search for syntax to highlight.  Stop at first
-highlighted object, if any.  Return t if some highlighting was
-done, nil otherwise."
+Stop at first highlighted object, if any.  Return t if some
+highlighting was done, nil otherwise."
   (when (org-string-nw-p org-latex-and-related-regexp)
     (catch 'found
-      (while (re-search-forward org-latex-and-related-regexp limit t)
-       (unless
-           (cl-some
-            (lambda (f)
-              (memq f '(org-code org-verbatim underline org-special-keyword)))
-            (save-excursion
-              (goto-char (1+ (match-beginning 0)))
-              (face-at-point nil t)))
-         (let ((offset (if (memq (char-after (1+ (match-beginning 0)))
-                                 '(?_ ?^))
-                           1
-                         0)))
-           (font-lock-prepend-text-property
-            (+ offset (match-beginning 0)) (match-end 0)
-            'face 'org-latex-and-related)
+      (while (re-search-forward org-latex-and-related-regexp
+                               nil t) ;; on purpose, we ignore LIMIT
+       (unless (cl-some (lambda (f) (memq f '(org-code org-verbatim underline
+                                                       org-special-keyword)))
+                        (save-excursion
+                          (goto-char (1+ (match-beginning 0)))
+                          (face-at-point nil t)))
+         (let* ((offset (if (memq (char-after (1+ (match-beginning 0)))
+                                  '(?_ ?^))
+                            1
+                          0))
+                (start (+ offset (match-beginning 0)))
+                (end (match-end 0)))
+           (if (memq 'native org-highlight-latex-and-related)
+               (org-src-font-lock-fontify-block "latex" start end)
+             (font-lock-prepend-text-property start end
+                                              'face 'org-latex-and-related))
            (add-text-properties (+ offset (match-beginning 0)) (match-end 0)
                                 '(font-lock-multiline t)))
          (throw 'found t)))
@@ -6268,8 +5517,7 @@ done, nil otherwise."
     (font-lock-mode 1)))
 
 (defun org-activate-tags (limit)
-  (when (re-search-forward
-        "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$" limit t)
+  (when (re-search-forward org-tag-line-re limit t)
     (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
     (add-text-properties (match-beginning 1) (match-end 1)
                         (list 'mouse-face 'highlight
@@ -6365,12 +5613,12 @@ needs to be inserted at a specific position in the 
font-lock sequence.")
           '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
           '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
           '("| *\\(<[lrc]?[0-9]*>\\)" (1 'org-formula t))
-          ;; Drawers
-          '(org-fontify-drawers)
           ;; Properties
           (list org-property-re
                 '(1 'org-special-keyword t)
                 '(3 'org-property-value t))
+          ;; Drawers
+          '(org-fontify-drawers)
           ;; Link related fontification.
           '(org-activate-links)
           (when (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
@@ -6378,12 +5626,12 @@ needs to be inserted at a specific position in the 
font-lock sequence.")
           (when (memq 'date lk) '(org-activate-dates (0 'org-date t)))
           (when (memq 'footnote lk) '(org-activate-footnote-links))
            ;; Targets.
-           (list org-any-target-regexp '(0 'org-target t))
+           (list org-radio-target-regexp '(0 'org-target t))
+          (list org-target-regexp '(0 'org-target t))
           ;; Diary sexps.
           '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
           ;; Macro
           '(org-fontify-macros)
-          '(org-hide-wide-columns (0 nil append))
           ;; TODO keyword
           (list (format org-heading-keyword-regexp-format
                         org-todo-regexp)
@@ -6448,6 +5696,8 @@ needs to be inserted at a specific position in the 
font-lock sequence.")
     (setq-local org-font-lock-keywords org-font-lock-extra-keywords)
     (setq-local font-lock-defaults
                '(org-font-lock-keywords t nil nil backward-paragraph))
+    (setq-local font-lock-extend-after-change-region-function
+               #'org-fontify-extend-region)
     (kill-local-variable 'font-lock-keywords)
     nil))
 
@@ -6660,21 +5910,250 @@ and subscripts."
                               (list 'invisible t))))
       t)))
 
-;;;; Visibility cycling, including org-goto and indirect buffer
+(defun org-remove-empty-overlays-at (pos)
+  "Remove outline overlays that do not contain non-white stuff."
+  (dolist (o (overlays-at pos))
+    (and (eq 'outline (overlay-get o 'invisible))
+        (not (string-match "\\S-" (buffer-substring (overlay-start o)
+                                                    (overlay-end o))))
+        (delete-overlay o))))
+
+(defun org-show-empty-lines-in-parent ()
+  "Move to the parent and re-show empty lines before visible headlines."
+  (save-excursion
+    (let ((context (if (org-up-heading-safe) 'children 'overview)))
+      (org-cycle-show-empty-lines context))))
+
+(defun org-files-list ()
+  "Return `org-agenda-files' list, plus all open Org files.
+This is useful for operations that need to scan all of a user's
+open and agenda-wise Org files."
+  (let ((files (mapcar #'expand-file-name (org-agenda-files))))
+    (dolist (buf (buffer-list))
+      (with-current-buffer buf
+       (when (and (derived-mode-p 'org-mode) (buffer-file-name))
+         (cl-pushnew (expand-file-name (buffer-file-name)) files
+                     :test #'equal))))
+    files))
+
+(defsubst org-entry-beginning-position ()
+  "Return the beginning position of the current entry."
+  (save-excursion (org-back-to-heading t) (point)))
+
+(defsubst org-entry-end-position ()
+  "Return the end position of the current entry."
+  (save-excursion (outline-next-heading) (point)))
+
+(defun org-subtree-end-visible-p ()
+  "Is the end of the current subtree visible?"
+  (pos-visible-in-window-p
+   (save-excursion (org-end-of-subtree t) (point))))
+
+(defun org-first-headline-recenter ()
+  "Move cursor to the first headline and recenter the headline."
+  (let ((window (get-buffer-window)))
+    (when window
+      (goto-char (point-min))
+      (when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
+       (set-window-start window (line-beginning-position))))))
+
+
+;;; Visibility (headlines, blocks, drawers)
+
+;;;; Headlines visibility
+
+(defun org-show-entry ()
+  "Show the body directly following this heading.
+Show the heading too, if it is currently invisible."
+  (interactive)
+  (save-excursion
+    (ignore-errors
+      (org-back-to-heading t)
+      (org-flag-region
+       (line-end-position 0)
+       (save-excursion
+        (if (re-search-forward
+             (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
+            (match-beginning 1)
+          (point-max)))
+       nil
+       'outline))))
+
+(defun org-show-children (&optional level)
+  "Show all direct subheadings of this heading.
+Prefix arg LEVEL is how many levels below the current level
+should be shown.  Default is enough to cause the following
+heading to appear."
+  (interactive "p")
+  (save-excursion
+    (org-back-to-heading t)
+    (let* ((current-level (funcall outline-level))
+          (max-level (org-get-valid-level
+                      current-level
+                      (if level (prefix-numeric-value level) 1)))
+          (end (save-excursion (org-end-of-subtree t t)))
+          (regexp-fmt "^\\*\\{%d,%s\\}\\(?: \\|$\\)")
+          (past-first-child nil)
+          ;; Make sure to skip inlinetasks.
+          (re (format regexp-fmt
+                      current-level
+                      (cond
+                       ((not (featurep 'org-inlinetask)) "")
+                       (org-odd-levels-only (- (* 2 org-inlinetask-min-level)
+                                               3))
+                       (t (1- org-inlinetask-min-level))))))
+      ;; Display parent heading.
+      (org-flag-heading nil)
+      (forward-line)
+      ;; Display children.  First child may be deeper than expected
+      ;; MAX-LEVEL.  Since we want to display it anyway, adjust
+      ;; MAX-LEVEL accordingly.
+      (while (re-search-forward re end t)
+       (unless past-first-child
+         (setq re (format regexp-fmt
+                          current-level
+                          (max (funcall outline-level) max-level)))
+         (setq past-first-child t))
+       (org-flag-heading nil)))))
+
+(defun org-show-subtree ()
+  "Show everything after this heading at deeper levels."
+  (interactive)
+  (org-flag-region
+   (point) (save-excursion (org-end-of-subtree t t)) nil 'outline))
+
+;;;; Blocks visibility
+
+(defun org-hide-block-toggle-maybe ()
+  "Toggle visibility of block at point.
+Unlike to `org-hide-block-toggle', this function does not throw
+an error.  Return a non-nil value when toggling is successful."
+  (interactive)
+  (ignore-errors (org-hide-block-toggle)))
+
+(defun org-hide-block-toggle (&optional force)
+  "Toggle the visibility of the current block.
+When optional argument FORCE is `off', make block visible.  If it
+is non-nil, hide it unconditionally.  Throw an error when not at
+a block.  Return a non-nil value when toggling is successful."
+  (interactive)
+  (let ((element (org-element-at-point)))
+    (unless (memq (org-element-type element)
+                 '(center-block comment-block dynamic-block example-block
+                                export-block quote-block special-block
+                                src-block verse-block))
+      (user-error "Not at a block"))
+    (let* ((post (org-element-property :post-affiliated element))
+          (start (save-excursion
+                   (goto-char post)
+                   (line-end-position)))
+          (end (save-excursion
+                 (goto-char (org-element-property :end element))
+                 (skip-chars-backward " \t\n")
+                 (line-end-position))))
+      ;; Do nothing when not before or at the block opening line or at
+      ;; the block closing line.
+      (unless (let ((eol (line-end-position))) (and (> eol start) (/= eol 
end)))
+       (cond ((eq force 'off)
+              (org-flag-region start end nil 'org-hide-block))
+             (force
+              (org-flag-region start end t 'org-hide-block))
+             ((eq (get-char-property start 'invisible) 'org-hide-block)
+              (org-flag-region start end nil 'org-hide-block))
+             (t
+              (org-flag-region start end t 'org-hide-block)))
+       ;; When the block is hidden away, make sure point is left in
+       ;; a visible part of the buffer.
+       (when (invisible-p (max (1- (point)) (point-min)))
+         (goto-char post))
+       ;; Signal success.
+       t))))
+
+(defun org-hide-block-toggle-all ()
+  "Toggle the visibility of all blocks in the current buffer."
+  (org-block-map 'org-hide-block-toggle))
+
+(defun org-hide-block-all ()
+  "Fold all blocks in the current buffer."
+  (interactive)
+  (org-show-all '(blocks))
+  (org-block-map 'org-hide-block-toggle-maybe))
+
+;;;; Drawers visibility
+
+(defun org-cycle-hide-drawers (state &optional exceptions)
+  "Re-hide all drawers after a visibility state change.
+STATE should be one of the symbols listed in the docstring of
+`org-cycle-hook'.  When non-nil, optional argument EXCEPTIONS is
+a list of strings specifying which drawers should not be hidden."
+  (when (and (derived-mode-p 'org-mode)
+            (not (memq state '(overview folded contents))))
+    (save-excursion
+      (let* ((globalp (eq state 'all))
+             (beg (if globalp (point-min) (point)))
+             (end (if globalp (point-max)
+                   (if (eq state 'children)
+                       (save-excursion (outline-next-heading) (point))
+                     (org-end-of-subtree t)))))
+       (goto-char beg)
+       (while (re-search-forward org-drawer-regexp (max end (point)) t)
+         (unless (member-ignore-case (match-string 1) exceptions)
+           (let ((drawer (org-element-at-point)))
+             (when (memq (org-element-type drawer) '(drawer property-drawer))
+               (org-flag-drawer t drawer)
+               ;; Make sure to skip drawer entirely or we might flag
+               ;; it another time when matching its ending line with
+               ;; `org-drawer-regexp'.
+               (goto-char (org-element-property :end drawer))))))))))
+
+(defun org-flag-drawer (flag &optional element beg end)
+  "When FLAG is non-nil, hide the drawer we are at.
+Otherwise make it visible.
+
+When optional argument ELEMENT is a parsed drawer, as returned by
+`org-element-at-point', hide or show that drawer instead.
 
-;;; Cycling
+When buffer positions BEG and END are provided, hide or show that
+region as a drawer without further ado."
+  (if (and beg end) (org-flag-region beg end flag 'org-hide-drawer)
+    (let ((drawer (or element
+                     (and (save-excursion
+                            (beginning-of-line)
+                            (looking-at-p org-drawer-regexp))
+                          (org-element-at-point)))))
+      (when (memq (org-element-type drawer) '(drawer property-drawer))
+       (let ((post (org-element-property :post-affiliated drawer)))
+         (org-flag-region
+          (save-excursion (goto-char post) (line-end-position))
+          (save-excursion (goto-char (org-element-property :end drawer))
+                          (skip-chars-backward " \t\n")
+                          (line-end-position))
+          flag 'org-hide-drawer)
+         ;; When the drawer is hidden away, make sure point lies in
+         ;; a visible part of the buffer.
+         (when (invisible-p (max (1- (point)) (point-min)))
+           (goto-char post)))))))
+
+;;;; Visibility cycling
 
 (defvar-local org-cycle-global-status nil)
 (put 'org-cycle-global-status 'org-state t)
 (defvar-local org-cycle-subtree-status nil)
 (put 'org-cycle-subtree-status 'org-state t)
 
-(defvar org-inlinetask-min-level)
-
-(defun org-unlogged-message (&rest args)
-  "Display a message, but avoid logging it in the *Messages* buffer."
-  (let ((message-log-max nil))
-    (apply 'message args)))
+(defun org-show-all (&optional types)
+  "Show all contents in the visible part of the buffer.
+By default, the function expands headings, blocks and drawers.
+When optional argument TYPE is a list of symbols among `blocks',
+`drawers' and `headings', to only expand one specific type."
+  (interactive)
+  (dolist (type (or types '(blocks drawers headings)))
+    (org-flag-region (point-min) (point-max) nil
+                    (pcase type
+                      (`blocks 'org-hide-block)
+                      (`drawers 'org-hide-drawer)
+                      (`headings 'outline)
+                      (_ (error "Invalid type: %S" type))))))
 
 ;;;###autoload
 (defun org-cycle (&optional arg)
@@ -6766,7 +6245,7 @@ if the variable `org-cycle-global-at-bob' is t."
        (org-unlogged-message "Startup visibility, plus VISIBILITY properties"))
 
        ((equal arg '(64))
-       (outline-show-all)
+       (org-show-all)
        (org-unlogged-message "Entire buffer visible, including drawers"))
 
        ((equal arg '(4)) (org-cycle-internal-global))
@@ -6825,8 +6304,6 @@ Use `\\[org-edit-special]' to edit table.el tables"))
        ((run-hook-with-args-until-success
         'org-tab-after-check-for-cycling-hook))
 
-       ((org-try-structure-completion))
-
        ((run-hook-with-args-until-success
         'org-tab-before-tab-emulation-hook))
 
@@ -6869,7 +6346,7 @@ Use `\\[org-edit-special]' to edit table.el tables"))
           (eq org-cycle-global-status 'contents))
       ;; We just showed the table of contents - now show everything
       (run-hook-with-args 'org-pre-cycle-hook 'all)
-      (outline-show-all)
+      (org-show-all '(headings blocks))
       (unless ga (org-unlogged-message "SHOW ALL"))
       (setq org-cycle-global-status 'all)
       (run-hook-with-args 'org-cycle-hook 'all))
@@ -6885,11 +6362,6 @@ Use `\\[org-edit-special]' to edit table.el tables"))
 (defvar org-called-with-limited-levels nil
   "Non-nil when `org-with-limited-levels' is currently active.")
 
-(defun org-invisible-p (&optional pos)
-  "Non-nil if the character after POS is invisible.
-If POS is nil, use `point' instead."
-  (get-char-property (or pos (point)) 'invisible))
-
 (defun org-cycle-internal-local ()
   "Do the local cycling action."
   (let ((goal-column 0) eoh eol eos has-children children-skipped struct)
@@ -6947,11 +6419,6 @@ If POS is nil, use `point' instead."
        (org-show-entry)
        (org-with-limited-levels (org-show-children))
        (org-show-set-visibility 'canonical)
-       ;; FIXME: This slows down the func way too much.
-       ;; How keep drawers hidden in subtree anyway?
-       ;; (when (memq 'org-cycle-hide-drawers org-cycle-hook)
-       ;;   (org-cycle-hide-drawers 'subtree))
-
        ;; Fold every list in subtree to top-level items.
        (when (eq org-cycle-include-plain-lists 'integrate)
          (save-excursion
@@ -6979,7 +6446,7 @@ If POS is nil, use `point' instead."
       ;; now show everything.
       (unless (org-before-first-heading-p)
        (run-hook-with-args 'org-pre-cycle-hook 'subtree))
-      (outline-flag-region eoh eos nil)
+      (org-flag-region eoh eos nil 'outline)
       (org-unlogged-message
        (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
       (setq org-cycle-subtree-status 'subtree)
@@ -6988,7 +6455,7 @@ If POS is nil, use `point' instead."
      (t
       ;; Default action: hide the subtree.
       (run-hook-with-args 'org-pre-cycle-hook 'folded)
-      (outline-flag-region eoh eos t)
+      (org-flag-region eoh eos t 'outline)
       (org-unlogged-message "FOLDED")
       (setq org-cycle-subtree-status 'folded)
       (unless (org-before-first-heading-p)
@@ -7004,7 +6471,7 @@ With a numeric prefix, show all headlines up to that 
level."
         (if (derived-mode-p 'org-mode) org-cycle-include-plain-lists nil)))
     (cond
      ((integerp arg)
-      (outline-show-all)
+      (org-show-all '(headings blocks))
       (outline-hide-sublevels arg)
       (setq org-cycle-global-status 'contents))
      ((equal arg '(4))
@@ -7022,49 +6489,42 @@ With a numeric prefix, show all headlines up to that 
level."
     (org-content))
    ((or (eq org-startup-folded 'showeverything)
        (eq org-startup-folded nil))
-    (outline-show-all)))
+    (org-show-all)))
   (unless (eq org-startup-folded 'showeverything)
     (when org-hide-block-startup (org-hide-block-all))
-    (org-set-visibility-according-to-property 'no-cleanup)
+    (org-set-visibility-according-to-property)
     (org-cycle-hide-archived-subtrees 'all)
     (org-cycle-hide-drawers 'all)
     (org-cycle-show-empty-lines t)))
 
-(defun org-set-visibility-according-to-property (&optional no-cleanup)
-  "Switch subtree visibilities according to :VISIBILITY: property."
+(defun org-set-visibility-according-to-property ()
+  "Switch subtree visibility according to VISIBILITY property."
   (interactive)
-  (org-with-wide-buffer
-   (goto-char (point-min))
-   (while (re-search-forward "^[ \t]*:VISIBILITY:" nil t)
-     (if (not (org-at-property-p)) (outline-next-heading)
-       (let ((state (match-string 3)))
-        (save-excursion
-          (org-back-to-heading t)
-          (outline-hide-subtree)
-          (org-reveal))
-        (cond
-         ((equal state "folded")
-          (outline-hide-subtree)
-          (org-end-of-subtree t t))
-         ((equal state "children")
-          (org-show-hidden-entry)
-          (org-show-children))
-         ((equal state "content")
-          (save-excursion
-            (save-restriction
-              (org-narrow-to-subtree)
-              (org-content)))
-          (org-end-of-subtree t t))
-         ((member state '("all" "showall"))
-          (outline-show-subtree))))))
-   (unless no-cleanup
-     (org-cycle-hide-archived-subtrees 'all)
-     (org-cycle-hide-drawers 'all)
-     (org-cycle-show-empty-lines 'all))))
-
-;; This function uses outline-regexp instead of the more fundamental
-;; org-outline-regexp so that org-cycle-global works outside of Org
-;; buffers, where outline-regexp is needed.
+  (let ((regexp (org-re-property "VISIBILITY")))
+    (org-with-point-at 1
+      (while (re-search-forward regexp nil t)
+       (let ((state (match-string 3)))
+         (if (not (org-at-property-p)) (outline-next-heading)
+           (save-excursion
+             (org-back-to-heading t)
+             (org-flag-subtree t)
+             (org-reveal)
+             (pcase state
+               ("folded"
+                (org-flag-subtree t))
+               ("children"
+                (org-show-hidden-entry)
+                (org-show-children))
+               ("content"
+                (save-excursion
+                  (save-restriction
+                    (org-narrow-to-subtree)
+                    (org-content))))
+               ((or "all" "showall")
+                (outline-show-subtree))
+               (_ nil)))
+           (org-end-of-subtree)))))))
+
 (defun org-overview ()
   "Switch to overview mode, showing only top-level headlines.
 This shows all headlines with a level equal or greater than the level
@@ -7076,7 +6536,7 @@ results."
     (let ((level
           (save-excursion
             (goto-char (point-min))
-            (when (re-search-forward (concat "^" outline-regexp) nil t)
+            (when (re-search-forward org-outline-regexp-bol nil t)
               (goto-char (match-beginning 0))
               (funcall outline-level)))))
       (and level (outline-hide-sublevels level)))))
@@ -7112,14 +6572,6 @@ This function is the default value of the hook 
`org-cycle-hook'."
      ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
      ((eq state 'subtree)  (or (org-subtree-end-visible-p) (recenter 1))))))
 
-(defun org-remove-empty-overlays-at (pos)
-  "Remove outline overlays that do not contain non-white stuff."
-  (dolist (o (overlays-at pos))
-    (and (eq 'outline (overlay-get o 'invisible))
-        (not (string-match "\\S-" (buffer-substring (overlay-start o)
-                                                    (overlay-end o))))
-        (delete-overlay o))))
-
 (defun org-clean-visibility-after-subtree-move ()
   "Fix visibility issues after moving a subtree."
   ;; First, find a reasonable region to look at:
@@ -7145,11 +6597,10 @@ This function is the default value of the hook 
`org-cycle-hook'."
          (goto-char (point-min))
          (while (re-search-forward re nil t)
            (when (and (not (org-invisible-p))
-                      (save-excursion
-                        (goto-char (point-at-eol)) (org-invisible-p)))
+                      (org-invisible-p (line-end-position)))
              (outline-hide-entry))))
-       (org-cycle-show-empty-lines 'overview)
-       (org-cycle-hide-drawers 'overview)))))
+       (org-cycle-hide-drawers 'all)
+       (org-cycle-show-empty-lines 'overview)))))
 
 (defun org-cycle-show-empty-lines (state)
   "Show empty lines above all visible headlines.
@@ -7185,7 +6636,7 @@ are at least `org-cycle-separator-lines' empty lines 
before the headline."
                           (goto-char (match-beginning 0))
                           (skip-chars-backward " \t\n")
                           (line-end-position)))))
-               (outline-flag-region b e nil))))))))
+               (org-flag-region b e nil 'outline))))))))
   ;; Never hide empty lines at the end of the file.
   (save-excursion
     (goto-char (point-max))
@@ -7193,434 +6644,80 @@ are at least `org-cycle-separator-lines' empty lines 
before the headline."
     (outline-end-of-heading)
     (when (and (looking-at "[ \t\n]+")
               (= (match-end 0) (point-max)))
-      (outline-flag-region (point) (match-end 0) nil))))
+      (org-flag-region (point) (match-end 0) nil 'outline))))
 
-(defun org-show-empty-lines-in-parent ()
-  "Move to the parent and re-show empty lines before visible headlines."
-  (save-excursion
-    (let ((context (if (org-up-heading-safe) 'children 'overview)))
-      (org-cycle-show-empty-lines context))))
+;;;; Reveal point location
 
-(defun org-files-list ()
-  "Return `org-agenda-files' list, plus all open Org files.
-This is useful for operations that need to scan all of a user's
-open and agenda-wise Org files."
-  (let ((files (mapcar #'expand-file-name (org-agenda-files))))
-    (dolist (buf (buffer-list))
-      (with-current-buffer buf
-       (when (and (derived-mode-p 'org-mode) (buffer-file-name))
-         (cl-pushnew (expand-file-name (buffer-file-name)) files
-                     :test #'equal))))
-    files))
+(defun org-show-context (&optional key)
+  "Make sure point and context are visible.
+Optional argument KEY, when non-nil, is a symbol.  See
+`org-show-context-detail' for allowed values and how much is to
+be shown."
+  (org-show-set-visibility
+   (cond ((symbolp org-show-context-detail) org-show-context-detail)
+        ((cdr (assq key org-show-context-detail)))
+        (t (cdr (assq 'default org-show-context-detail))))))
 
-(defsubst org-entry-beginning-position ()
-  "Return the beginning position of the current entry."
-  (save-excursion (org-back-to-heading t) (point)))
+(defun org-show-set-visibility (detail)
+  "Set visibility around point according to DETAIL.
+DETAIL is either nil, `minimal', `local', `ancestors', `lineage',
+`tree', `canonical' or t.  See `org-show-context-detail' for more
+information."
+  ;; Show current heading and possibly its entry, following headline
+  ;; or all children.
+  (if (and (org-at-heading-p) (not (eq detail 'local)))
+      (org-flag-heading nil)
+    (org-show-entry)
+    ;; If point is hidden within a drawer or a block, make sure to
+    ;; expose it.
+    (dolist (o (overlays-at (point)))
+      (when (memq (overlay-get o 'invisible)
+                 '(org-hide-block org-hide-drawer outline))
+       (delete-overlay o)))
+    (unless (org-before-first-heading-p)
+      (org-with-limited-levels
+       (cl-case detail
+        ((tree canonical t) (org-show-children))
+        ((nil minimal ancestors))
+        (t (save-excursion
+             (outline-next-heading)
+             (org-flag-heading nil)))))))
+  ;; Show all siblings.
+  (when (eq detail 'lineage) (org-show-siblings))
+  ;; Show ancestors, possibly with their children.
+  (when (memq detail '(ancestors lineage tree canonical t))
+    (save-excursion
+      (while (org-up-heading-safe)
+       (org-flag-heading nil)
+       (when (memq detail '(canonical t)) (org-show-entry))
+       (when (memq detail '(tree canonical t)) (org-show-children))))))
 
-(defsubst org-entry-end-position ()
-  "Return the end position of the current entry."
-  (save-excursion (outline-next-heading) (point)))
-
-(defun org-cycle-hide-drawers (state &optional exceptions)
-  "Re-hide all drawers after a visibility state change.
-STATE should be one of the symbols listed in the docstring of
-`org-cycle-hook'.  When non-nil, optional argument EXCEPTIONS is
-a list of strings specifying which drawers should not be hidden."
-  (when (and (derived-mode-p 'org-mode)
-            (not (memq state '(overview folded contents))))
-    (save-excursion
-      (let* ((globalp (eq state 'all))
-             (beg (if globalp (point-min) (point)))
-             (end (if globalp (point-max)
-                   (if (eq state 'children)
-                       (save-excursion (outline-next-heading) (point))
-                     (org-end-of-subtree t)))))
-       (goto-char beg)
-       (while (re-search-forward org-drawer-regexp (max end (point)) t)
-         (unless (member-ignore-case (match-string 1) exceptions)
-           (let ((drawer (org-element-at-point)))
-             (when (memq (org-element-type drawer) '(drawer property-drawer))
-               (org-flag-drawer t drawer)
-               ;; Make sure to skip drawer entirely or we might flag
-               ;; it another time when matching its ending line with
-               ;; `org-drawer-regexp'.
-               (goto-char (org-element-property :end drawer))))))))))
-
-(defun org-flag-drawer (flag &optional element)
-  "When FLAG is non-nil, hide the drawer we are at.
-Otherwise make it visible.  When optional argument ELEMENT is
-a parsed drawer, as returned by `org-element-at-point', hide or
-show that drawer instead."
-  (let ((drawer (or element
-                   (and (save-excursion
-                          (beginning-of-line)
-                          (looking-at-p org-drawer-regexp))
-                        (org-element-at-point)))))
-    (when (memq (org-element-type drawer) '(drawer property-drawer))
-      (let ((post (org-element-property :post-affiliated drawer)))
-       (save-excursion
-         (outline-flag-region
-          (progn (goto-char post) (line-end-position))
-          (progn (goto-char (org-element-property :end drawer))
-                 (skip-chars-backward " \r\t\n")
-                 (line-end-position))
-          flag))
-       ;; When the drawer is hidden away, make sure point lies in
-       ;; a visible part of the buffer.
-       (when (and flag (> (line-beginning-position) post))
-         (goto-char post))))))
-
-(defun org-subtree-end-visible-p ()
-  "Is the end of the current subtree visible?"
-  (pos-visible-in-window-p
-   (save-excursion (org-end-of-subtree t) (point))))
-
-(defun org-first-headline-recenter ()
-  "Move cursor to the first headline and recenter the headline."
-  (let ((window (get-buffer-window)))
-    (when window
-      (goto-char (point-min))
-      (when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
-       (set-window-start window (line-beginning-position))))))
-
-;;; Saving and restoring visibility
-
-(defun org-outline-overlay-data (&optional use-markers)
-  "Return a list of the locations of all outline overlays.
-These are overlays with the `invisible' property value `outline'.
-The return value is a list of cons cells, with start and stop
-positions for each overlay.
-If USE-MARKERS is set, return the positions as markers."
-  (let (beg end)
-    (org-with-wide-buffer
-     (delq nil
-          (mapcar (lambda (o)
-                    (when (eq (overlay-get o 'invisible) 'outline)
-                      (setq beg (overlay-start o)
-                            end (overlay-end o))
-                      (and beg end (> end beg)
-                           (if use-markers
-                               (cons (copy-marker beg)
-                                     (copy-marker end t))
-                             (cons beg end)))))
-                  (overlays-in (point-min) (point-max)))))))
-
-(defun org-set-outline-overlay-data (data)
-  "Create visibility overlays for all positions in DATA.
-DATA should have been made by `org-outline-overlay-data'."
-  (org-with-wide-buffer
-   (outline-show-all)
-   (dolist (c data) (outline-flag-region (car c) (cdr c) t))))
-
-;;; Folding of blocks
-
-(defvar-local org-hide-block-overlays nil
-  "Overlays hiding blocks.")
-
-(defun org-block-map (function &optional start end)
-  "Call FUNCTION at the head of all source blocks in the current buffer.
-Optional arguments START and END can be used to limit the range."
-  (let ((start (or start (point-min)))
-        (end (or end (point-max))))
-    (save-excursion
-      (goto-char start)
-      (while (and (< (point) end) (re-search-forward org-block-regexp end t))
-       (save-excursion
-         (save-match-data
-            (goto-char (match-beginning 0))
-            (funcall function)))))))
-
-(defun org-hide-block-toggle-all ()
-  "Toggle the visibility of all blocks in the current buffer."
-  (org-block-map 'org-hide-block-toggle))
-
-(defun org-hide-block-all ()
-  "Fold all blocks in the current buffer."
-  (interactive)
-  (org-show-block-all)
-  (org-block-map 'org-hide-block-toggle-maybe))
+(defvar org-reveal-start-hook nil
+  "Hook run before revealing a location.")
 
-(defun org-show-block-all ()
-  "Unfold all blocks in the current buffer."
-  (interactive)
-  (mapc #'delete-overlay org-hide-block-overlays)
-  (setq org-hide-block-overlays nil))
+(defun org-reveal (&optional siblings)
+  "Show current entry, hierarchy above it, and the following headline.
 
-(defun org-hide-block-toggle-maybe ()
-  "Toggle visibility of block at point.
-Unlike to `org-hide-block-toggle', this function does not throw
-an error.  Return a non-nil value when toggling is successful."
-  (interactive)
-  (ignore-errors (org-hide-block-toggle)))
+This can be used to show a consistent set of context around
+locations exposed with `org-show-context'.
 
-(defun org-hide-block-toggle (&optional force)
-  "Toggle the visibility of the current block.
-When optional argument FORCE is `off', make block visible.  If it
-is non-nil, hide it unconditionally.  Throw an error when not at
-a block.  Return a non-nil value when toggling is successful."
-  (interactive)
-  (let ((element (org-element-at-point)))
-    (unless (memq (org-element-type element)
-                 '(center-block comment-block dynamic-block example-block
-                                export-block quote-block special-block
-                                src-block verse-block))
-      (user-error "Not at a block"))
-    (let* ((start (save-excursion
-                   (goto-char (org-element-property :post-affiliated element))
-                   (line-end-position)))
-          (end (save-excursion
-                 (goto-char (org-element-property :end element))
-                 (skip-chars-backward " \r\t\n")
-                 (line-end-position)))
-          (overlays (overlays-at start)))
-      (cond
-       ;; Do nothing when not before or at the block opening line or
-       ;; at the block closing line.
-       ((let ((eol (line-end-position))) (and (> eol start) (/= eol end))) nil)
-       ((and (not (eq force 'off))
-            (not (memq t (mapcar
-                          (lambda (o)
-                            (eq (overlay-get o 'invisible) 'org-hide-block))
-                          overlays))))
-       (let ((ov (make-overlay start end)))
-         (overlay-put ov 'invisible 'org-hide-block)
-         ;; Make the block accessible to `isearch'.
-         (overlay-put
-          ov 'isearch-open-invisible
-          (lambda (ov)
-            (when (memq ov org-hide-block-overlays)
-              (setq org-hide-block-overlays (delq ov org-hide-block-overlays)))
-            (when (eq (overlay-get ov 'invisible) 'org-hide-block)
-              (delete-overlay ov))))
-         (push ov org-hide-block-overlays)
-         ;; When the block is hidden away, make sure point is left in
-         ;; a visible part of the buffer.
-         (when (> (line-beginning-position) start)
-           (goto-char start)
-           (beginning-of-line))
-         ;; Signal successful toggling.
-         t))
-       ((or (not force) (eq force 'off))
-       (dolist (ov overlays t)
-         (when (memq ov org-hide-block-overlays)
-           (setq org-hide-block-overlays (delq ov org-hide-block-overlays)))
-         (when (eq (overlay-get ov 'invisible) 'org-hide-block)
-           (delete-overlay ov))))))))
-
-;; Remove overlays when changing major mode
-(add-hook 'org-mode-hook
-         (lambda () (add-hook 'change-major-mode-hook
-                              'org-show-block-all 'append 'local)))
-
-;;; Org-goto
-
-(defvar org-goto-window-configuration nil)
-(defvar org-goto-marker nil)
-(defvar org-goto-map)
-(defun org-goto-map ()
-  "Set the keymap `org-goto'."
-  (setq org-goto-map
-       (let ((map (make-sparse-keymap)))
-         (let ((cmds '(isearch-forward isearch-backward kill-ring-save 
set-mark-command
-                                       mouse-drag-region universal-argument 
org-occur)))
-           (dolist (cmd cmds)
-             (substitute-key-definition cmd cmd map global-map)))
-         (suppress-keymap map)
-         (org-defkey map "\C-m"     'org-goto-ret)
-         (org-defkey map [(return)] 'org-goto-ret)
-         (org-defkey map [(left)]   'org-goto-left)
-         (org-defkey map [(right)]  'org-goto-right)
-         (org-defkey map [(control ?g)] 'org-goto-quit)
-         (org-defkey map "\C-i" 'org-cycle)
-         (org-defkey map [(tab)] 'org-cycle)
-         (org-defkey map [(down)] 'outline-next-visible-heading)
-         (org-defkey map [(up)] 'outline-previous-visible-heading)
-         (if org-goto-auto-isearch
-             (if (fboundp 'define-key-after)
-                 (define-key-after map [t] 'org-goto-local-auto-isearch)
-               nil)
-           (org-defkey map "q" 'org-goto-quit)
-           (org-defkey map "n" 'outline-next-visible-heading)
-           (org-defkey map "p" 'outline-previous-visible-heading)
-           (org-defkey map "f" 'outline-forward-same-level)
-           (org-defkey map "b" 'outline-backward-same-level)
-           (org-defkey map "u" 'outline-up-heading))
-         (org-defkey map "/" 'org-occur)
-         (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
-         (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
-         (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
-         (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
-         (org-defkey map "\C-c\C-u" 'outline-up-heading)
-         map)))
-
-(defconst org-goto-help
-  "Browse buffer copy, to find location or copy text.%s
-RET=jump to location             C-g=quit and return to previous location
-\[Up]/[Down]=next/prev headline   TAB=cycle visibility   [/] org-occur")
-
-(defvar org-goto-start-pos) ; dynamically scoped parameter
-
-(defun org-goto (&optional alternative-interface)
-  "Look up a different location in the current file, keeping current 
visibility.
-
-When you want look-up or go to a different location in a
-document, the fastest way is often to fold the entire buffer and
-then dive into the tree.  This method has the disadvantage, that
-the previous location will be folded, which may not be what you
-want.
-
-This command works around this by showing a copy of the current
-buffer in an indirect buffer, in overview mode.  You can dive
-into the tree in that copy, use org-occur and incremental search
-to find a location.  When pressing RET or `Q', the command
-returns to the original buffer in which the visibility is still
-unchanged.  After RET it will also jump to the location selected
-in the indirect buffer and expose the headline hierarchy above.
-
-With a prefix argument, use the alternative interface: e.g., if
-`org-goto-interface' is `outline' use `outline-path-completion'."
-  (interactive "P")
-  (org-goto-map)
-  (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
-        (org-refile-use-outline-path t)
-        (org-refile-target-verify-function nil)
-        (interface
-         (if (not alternative-interface)
-             org-goto-interface
-           (if (eq org-goto-interface 'outline)
-               'outline-path-completion
-             'outline)))
-        (org-goto-start-pos (point))
-        (selected-point
-         (if (eq interface 'outline)
-             (car (org-get-location (current-buffer) org-goto-help))
-           (let ((pa (org-refile-get-location "Goto")))
-             (org-refile-check-position pa)
-             (nth 3 pa)))))
-    (if selected-point
-       (progn
-         (org-mark-ring-push org-goto-start-pos)
-         (goto-char selected-point)
-         (when (or (org-invisible-p) (org-invisible-p2))
-           (org-show-context 'org-goto)))
-      (message "Quit"))))
-
-(defvar org-goto-selected-point nil) ; dynamically scoped parameter
-(defvar org-goto-exit-command nil) ; dynamically scoped parameter
-(defvar org-goto-local-auto-isearch-map) ; defined below
-
-(defun org-get-location (_buf help)
-  "Let the user select a location in current buffer.
-This function uses a recursive edit.  It returns the selected position
-or nil."
-  (org-no-popups
-   (let ((isearch-mode-map org-goto-local-auto-isearch-map)
-        (isearch-hide-immediately nil)
-        (isearch-search-fun-function
-         (lambda () 'org-goto-local-search-headings))
-        (org-goto-selected-point org-goto-exit-command))
-     (save-excursion
-       (save-window-excursion
-        (delete-other-windows)
-        (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
-        (pop-to-buffer-same-window
-         (condition-case nil
-             (make-indirect-buffer (current-buffer) "*org-goto*")
-           (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
-        (with-output-to-temp-buffer "*Org Help*"
-          (princ (format help (if org-goto-auto-isearch
-                                  "  Just type for auto-isearch."
-                                "  n/p/f/b/u to navigate, q to quit."))))
-        (org-fit-window-to-buffer (get-buffer-window "*Org Help*"))
-        (setq buffer-read-only nil)
-        (let ((org-startup-truncated t)
-              (org-startup-folded nil)
-              (org-startup-align-all-tables nil))
-          (org-mode)
-          (org-overview))
-        (setq buffer-read-only t)
-        (if (and (boundp 'org-goto-start-pos)
-                 (integer-or-marker-p org-goto-start-pos))
-            (progn (goto-char org-goto-start-pos)
-                   (when (org-invisible-p)
-                     (org-show-set-visibility 'lineage)))
-          (goto-char (point-min)))
-        (let (org-special-ctrl-a/e) (org-beginning-of-line))
-        (message "Select location and press RET")
-        (use-local-map org-goto-map)
-        (recursive-edit)))
-     (kill-buffer "*org-goto*")
-     (cons org-goto-selected-point org-goto-exit-command))))
-
-(defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
-(set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
-;; `isearch-other-control-char' was removed in Emacs 24.4.
-(if (fboundp 'isearch-other-control-char)
-    (progn
-      (define-key org-goto-local-auto-isearch-map "\C-i" 
'isearch-other-control-char)
-      (define-key org-goto-local-auto-isearch-map "\C-m" 
'isearch-other-control-char))
-  (define-key org-goto-local-auto-isearch-map "\C-i" nil)
-  (define-key org-goto-local-auto-isearch-map "\C-m" nil)
-  (define-key org-goto-local-auto-isearch-map [return] nil))
-
-(defun org-goto-local-search-headings (string bound noerror)
-  "Search and make sure that any matches are in headlines."
-  (catch 'return
-    (while (if isearch-forward
-               (search-forward string bound noerror)
-             (search-backward string bound noerror))
-      (when (save-match-data
-             (and (save-excursion
-                    (beginning-of-line)
-                    (looking-at org-complex-heading-regexp))
-                  (or (not (match-beginning 5))
-                      (< (point) (match-beginning 5)))))
-       (throw 'return (point))))))
-
-(defun org-goto-local-auto-isearch ()
-  "Start isearch."
-  (interactive)
-  (goto-char (point-min))
-  (let ((keys (this-command-keys)))
-    (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
-      (isearch-mode t)
-      (isearch-process-search-char (string-to-char keys)))))
+With optional argument SIBLINGS, on each level of the hierarchy all
+siblings are shown.  This repairs the tree structure to what it would
+look like when opened with hierarchical calls to `org-cycle'.
 
-(defun org-goto-ret (&optional _arg)
-  "Finish `org-goto' by going to the new location."
+With a \\[universal-argument] \\[universal-argument] prefix, \
+go to the parent and show the entire tree."
   (interactive "P")
-  (setq org-goto-selected-point (point))
-  (setq org-goto-exit-command 'return)
-  (throw 'exit nil))
-
-(defun org-goto-left ()
-  "Finish `org-goto' by going to the new location."
-  (interactive)
-  (if (org-at-heading-p)
-      (progn
-       (beginning-of-line 1)
-       (setq org-goto-selected-point (point)
-             org-goto-exit-command 'left)
-       (throw 'exit nil))
-    (user-error "Not on a heading")))
-
-(defun org-goto-right ()
-  "Finish `org-goto' by going to the new location."
-  (interactive)
-  (if (org-at-heading-p)
-      (progn
-       (setq org-goto-selected-point (point)
-             org-goto-exit-command 'right)
-       (throw 'exit nil))
-    (user-error "Not on a heading")))
-
-(defun org-goto-quit ()
-  "Finish `org-goto' without cursor motion."
-  (interactive)
-  (setq org-goto-selected-point nil)
-  (setq org-goto-exit-command 'quit)
-  (throw 'exit nil))
+  (run-hooks 'org-reveal-start-hook)
+  (cond ((equal siblings '(4)) (org-show-set-visibility 'canonical))
+       ((equal siblings '(16))
+        (save-excursion
+          (when (org-up-heading-safe)
+            (org-show-subtree)
+            (run-hook-with-args 'org-cycle-hook 'subtree))))
+       (t (org-show-set-visibility 'lineage))))
 
+
 ;;; Indirect buffer display of subtrees
 
 (defvar org-indirect-dedicated-frame nil
@@ -7688,7 +6785,7 @@ frame is not changed."
       (pop-to-buffer ibuf))
      (t (error "Invalid value")))
     (narrow-to-region beg end)
-    (outline-show-all)
+    (org-show-all '(headings blocks))
     (goto-char pos)
     (run-hook-with-args 'org-cycle-hook 'all)
     (and (window-live-p cwin) (select-window cwin))))
@@ -7799,22 +6896,24 @@ unconditionally."
          (member arg '((4) (16)))
          (and (not invisible-ok)
               (invisible-p (max (1- (point)) (point-min)))))
-      ;; Position point at the location of insertion.
-      (if (not level)                  ;before first headline
-         (org-with-limited-levels (outline-next-heading))
-       ;; Make sure we end up on a visible headline if INVISIBLE-OK
-       ;; is nil.
-       (org-with-limited-levels (org-back-to-heading invisible-ok))
-       (cond ((equal arg '(16))
-              (org-up-heading-safe)
-              (org-end-of-subtree t t))
-             (t
-              (org-end-of-subtree t t))))
-      (unless (bolp) (insert "\n"))   ;ensure final newline
+      ;; Position point at the location of insertion.  Make sure we
+      ;; end up on a visible headline if INVISIBLE-OK is nil.
+      (org-with-limited-levels
+       (if (not level) (outline-next-heading) ;before first headline
+        (org-back-to-heading invisible-ok)
+        (when (equal arg '(16)) (org-up-heading-safe))
+        (org-end-of-subtree)))
+      (unless (bolp) (insert "\n"))
       (unless (and blank? (org-previous-line-empty-p))
        (org-N-empty-lines-before-current (if blank? 1 0)))
-      (insert stars " \n")
-      (forward-char -1))
+      (insert stars " ")
+      ;; When INVISIBLE-OK is non-nil, ensure newly created headline
+      ;; is visible.
+      (unless invisible-ok
+       (pcase (get-char-property-and-overlay (point) 'invisible)
+         (`(outline . ,o)
+          (move-overlay o (overlay-start o) (line-end-position 0)))
+         (_ nil))))
      ;; At a headline...
      ((org-at-heading-p)
       (cond ((bolp)
@@ -7830,17 +6929,15 @@ unconditionally."
             ;; Preserve tags.
             (let ((split (delete-and-extract-region (point) (match-end 4))))
               (if (looking-at "[ \t]*$") (replace-match "")
-                (org-set-tags nil t))
+                (org-align-tags))
               (end-of-line)
               (when blank? (insert "\n"))
               (insert "\n" stars " ")
-              (when (org-string-nw-p split) (insert split))
-              (when (eobp) (save-excursion (insert "\n")))))
+              (when (org-string-nw-p split) (insert split))))
            (t
             (end-of-line)
             (when blank? (insert "\n"))
-            (insert "\n" stars " ")
-            (when (eobp) (save-excursion (insert "\n"))))))
+            (insert "\n" stars " "))))
      ;; On regular text, turn line into a headline or split, if
      ;; appropriate.
      ((bolp)
@@ -7873,27 +6970,27 @@ So this will delete or add empty lines."
 When NO-TAGS is non-nil, don't include tags.
 When NO-TODO is non-nil, don't include TODO keywords.
 When NO-PRIORITY is non-nil, don't include priority cookie.
-When NO-COMMENT is non-nil, don't include COMMENT string."
-  (save-excursion
-    (org-back-to-heading t)
-    (let ((case-fold-search nil))
-      (looking-at org-complex-heading-regexp)
-      (let ((todo (and (not no-todo) (match-string 2)))
-           (priority (and (not no-priority) (match-string 3)))
-           (headline (pcase (match-string 4)
-                       (`nil "")
-                       ((and (guard no-comment) h)
-                        (replace-regexp-in-string
-                         (eval-when-compile
-                           (format "\\`%s[ \t]+" org-comment-string))
-                         "" h))
-                       (h h)))
-           (tags (and (not no-tags) (match-string 5))))
-       (mapconcat #'identity
-                  (delq nil (list todo priority headline tags))
-                  " ")))))
-
-(defvar orgstruct-mode)   ; defined below
+When NO-COMMENT is non-nil, don't include COMMENT string.
+Return nil before first heading."
+  (unless (org-before-first-heading-p)
+    (save-excursion
+      (org-back-to-heading t)
+      (let ((case-fold-search nil))
+       (looking-at org-complex-heading-regexp)
+       (let ((todo (and (not no-todo) (match-string 2)))
+             (priority (and (not no-priority) (match-string 3)))
+             (headline (pcase (match-string 4)
+                         (`nil "")
+                         ((and (guard no-comment) h)
+                          (replace-regexp-in-string
+                           (eval-when-compile
+                             (format "\\`%s[ \t]+" org-comment-string))
+                           "" h))
+                         (h h)))
+             (tags (and (not no-tags) (match-string 5))))
+         (mapconcat #'identity
+                    (delq nil (list todo priority headline tags))
+                    " "))))))
 
 (defun org-heading-components ()
   "Return the components of the current heading.
@@ -7906,24 +7003,13 @@ This is a list with the following elements:
 - the tags string, or nil."
   (save-excursion
     (org-back-to-heading t)
-    (when (let (case-fold-search)
-           (looking-at
-            (if orgstruct-mode
-                org-heading-regexp
-              org-complex-heading-regexp)))
-      (if orgstruct-mode
-         (list (length (match-string 1))
-               (org-reduced-level (length (match-string 1)))
-               nil
-               nil
-               (match-string 2)
-               nil)
-       (list (length (match-string 1))
-             (org-reduced-level (length (match-string 1)))
-             (match-string-no-properties 2)
-             (and (match-end 3) (aref (match-string 3) 2))
-             (match-string-no-properties 4)
-             (match-string-no-properties 5))))))
+    (when (let (case-fold-search) (looking-at org-complex-heading-regexp))
+      (list (length (match-string 1))
+           (org-reduced-level (length (match-string 1)))
+           (match-string-no-properties 2)
+           (and (match-end 3) (aref (match-string 3) 2))
+           (match-string-no-properties 4)
+           (match-string-no-properties 5)))))
 
 (defun org-get-entry ()
   "Get the entry text, after heading, entire subtree."
@@ -7946,7 +7032,7 @@ Set it to HEADING when provided."
           (if old (replace-match new t t nil 4)
             (goto-char (or (match-end 3) (match-end 2) (match-end 1)))
             (insert " " new))
-          (org-set-tags nil t)
+          (org-align-tags)
           (when (looking-at "[ \t]*$") (replace-match ""))))))))
 
 (defun org-insert-heading-after-current ()
@@ -8142,7 +7228,7 @@ odd number.  Returns values greater than 0."
        (user-error "Cannot promote to level 0.  UNDO to recover if necessary"))
       (t (replace-match up-head nil t)))
      (unless (= level 1)
-       (when org-auto-align-tags (org-set-tags nil 'ignore-column))
+       (when org-auto-align-tags (org-align-tags))
        (when org-adapt-indentation (org-fixup-indentation (- diff))))
      (run-hooks 'org-after-promote-entry-hook))))
 
@@ -8156,7 +7242,7 @@ odd number.  Returns values greater than 0."
          (down-head (concat (make-string (org-get-valid-level level 1) ?*) " 
"))
          (diff (abs (- level (length down-head) -1))))
      (replace-match down-head nil t)
-     (when org-auto-align-tags (org-set-tags nil 'ignore-column))
+     (when org-auto-align-tags (org-align-tags))
      (when org-adapt-indentation (org-fixup-indentation diff))
      (run-hooks 'org-after-demote-entry-hook))))
 
@@ -8315,7 +7401,7 @@ Assume point is at a heading or an inlinetask beginning."
          ((looking-at-p org-outline-regexp) (forward-line))
          ((looking-at-p "[ \t]*$") (forward-line))
          (t
-          (indent-line-to (+ (org-get-indentation) diff))
+          (indent-line-to (+ (current-indentation) diff))
           (beginning-of-line)
           (or (and (looking-at-p "[ \t]*#\\+BEGIN_\\(EXAMPLE\\|SRC\\)")
                    (let ((e (org-element-at-point)))
@@ -8384,80 +7470,59 @@ case."
   "Move the current subtree down past ARG headlines of the same level."
   (interactive "p")
   (setq arg (prefix-numeric-value arg))
-  (let ((movfunc (if (> arg 0) 'org-get-next-sibling
-                  'org-get-last-sibling))
-       (ins-point (make-marker))
-       (cnt (abs arg))
-       (col (current-column))
-       beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
-    ;; Select the tree
-    (org-back-to-heading)
-    (setq beg0 (point))
-    (save-excursion
-      (setq ne-beg (org-back-over-empty-lines))
-      (setq beg (point)))
-    (save-match-data
-      (save-excursion (outline-end-of-heading)
-                     (setq folded (org-invisible-p)))
-      (progn (org-end-of-subtree nil t)
-            (unless (eobp) (backward-char))))
-    (outline-next-heading)
-    (setq ne-end (org-back-over-empty-lines))
-    (setq end (point))
-    (goto-char beg0)
-    (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
-      ;; include less whitespace
-      (save-excursion
-       (goto-char beg)
-       (forward-line (- ne-beg ne-end))
-       (setq beg (point))))
-    ;; Find insertion point, with error handling
-    (while (> cnt 0)
-      (or (and (funcall movfunc) (looking-at org-outline-regexp))
-         (progn (goto-char beg0)
-                (user-error "Cannot move past superior level or buffer 
limit")))
-      (setq cnt (1- cnt)))
-    (when (> arg 0)
-      ;; Moving forward - still need to move over subtree
-      (org-end-of-subtree t t)
-      (save-excursion
-       (org-back-over-empty-lines)
-       (or (bolp) (newline))))
-    (setq ne-ins (org-back-over-empty-lines))
-    (move-marker ins-point (point))
-    (setq txt (buffer-substring beg end))
-    (org-save-markers-in-region beg end)
-    (delete-region beg end)
-    (org-remove-empty-overlays-at beg)
-    (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
-    (or (bobp) (outline-flag-region (1- (point)) (point) nil))
-    (and (not (bolp)) (looking-at "\n") (forward-char 1))
-    (let ((bbb (point)))
-      (insert-before-markers txt)
-      (org-reinstall-markers-in-region bbb)
-      (move-marker ins-point bbb))
-    (or (bolp) (insert "\n"))
-    (setq ins-end (point))
-    (goto-char ins-point)
-    (org-skip-whitespace)
-    (when (and (< arg 0)
-              (org-first-sibling-p)
-              (> ne-ins ne-beg))
-      ;; Move whitespace back to beginning
-      (save-excursion
-       (goto-char ins-end)
-       (let ((kill-whole-line t))
-         (kill-line (- ne-ins ne-beg)) (point)))
-      (insert (make-string (- ne-ins ne-beg) ?\n)))
-    (move-marker ins-point nil)
-    (if folded
-       (outline-hide-subtree)
-      (org-show-entry)
-      (org-show-children)
-      (org-cycle-hide-drawers 'children))
-    (org-clean-visibility-after-subtree-move)
-    ;; move back to the initial column we were at
-    (move-to-column col)))
+  (org-preserve-local-variables
+   (let ((movfunc (if (> arg 0) 'org-get-next-sibling
+                   'org-get-last-sibling))
+        (ins-point (make-marker))
+        (cnt (abs arg))
+        (col (current-column))
+        beg end txt folded)
+     ;; Select the tree
+     (org-back-to-heading)
+     (setq beg (point))
+     (save-match-data
+       (save-excursion (outline-end-of-heading)
+                      (setq folded (org-invisible-p)))
+       (progn (org-end-of-subtree nil t)
+             (unless (eobp) (backward-char))))
+     (outline-next-heading)
+     (setq end (point))
+     (goto-char beg)
+     ;; Find insertion point, with error handling
+     (while (> cnt 0)
+       (unless (and (funcall movfunc) (looking-at org-outline-regexp))
+        (goto-char beg)
+        (user-error "Cannot move past superior level or buffer limit"))
+       (setq cnt (1- cnt)))
+     (when (> arg 0)
+       ;; Moving forward - still need to move over subtree
+       (org-end-of-subtree t t)
+       (save-excursion
+        (org-back-over-empty-lines)
+        (or (bolp) (newline))))
+     (move-marker ins-point (point))
+     (setq txt (buffer-substring beg end))
+     (org-save-markers-in-region beg end)
+     (delete-region beg end)
+     (org-remove-empty-overlays-at beg)
+     (unless (= beg (point-min)) (org-flag-region (1- beg) beg nil 'outline))
+     (unless (bobp) (org-flag-region (1- (point)) (point) nil 'outline))
+     (and (not (bolp)) (looking-at "\n") (forward-char 1))
+     (let ((bbb (point)))
+       (insert-before-markers txt)
+       (org-reinstall-markers-in-region bbb)
+       (move-marker ins-point bbb))
+     (or (bolp) (insert "\n"))
+     (goto-char ins-point)
+     (org-skip-whitespace)
+     (move-marker ins-point nil)
+     (if folded
+        (org-flag-subtree t)
+       (org-show-entry)
+       (org-show-children))
+     (org-clean-visibility-after-subtree-move)
+     ;; move back to the initial column we were at
+     (move-to-column col))))
 
 (defvar org-subtree-clip ""
   "Clipboard for cut and paste of subtrees.
@@ -8484,38 +7549,40 @@ If FORCE-STORE-MARKERS is non-nil, store the relative 
locations
 of some markers in the region, even if CUT is non-nil.  This is
 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
   (interactive "p")
-  (let (beg end folded (beg0 (point)))
-    (if (called-interactively-p 'any)
-       (org-back-to-heading nil) ; take what looks like a subtree
-      (org-back-to-heading t)) ; take what is really there
-    (setq beg (point))
-    (skip-chars-forward " \t\r\n")
-    (save-match-data
-      (if nosubtrees
-         (outline-next-heading)
-       (save-excursion (outline-end-of-heading)
-                       (setq folded (org-invisible-p)))
-       (ignore-errors (org-forward-heading-same-level (1- n) t))
-       (org-end-of-subtree t t)))
-    ;; Include the end of an inlinetask
-    (when (and (featurep 'org-inlinetask)
-              (looking-at-p (concat (org-inlinetask-outline-regexp)
-                                    "END[ \t]*$")))
-      (end-of-line))
-    (setq end (point))
-    (goto-char beg0)
-    (when (> end beg)
-      (setq org-subtree-clip-folded folded)
-      (when (or cut force-store-markers)
-       (org-save-markers-in-region beg end))
-      (if cut (kill-region beg end) (copy-region-as-kill beg end))
-      (setq org-subtree-clip (current-kill 0))
-      (message "%s: Subtree(s) with %d characters"
-              (if cut "Cut" "Copied")
-              (length org-subtree-clip)))))
+  (org-preserve-local-variables
+   (let (beg end folded (beg0 (point)))
+     (if (called-interactively-p 'any)
+        (org-back-to-heading nil)    ; take what looks like a subtree
+       (org-back-to-heading t))              ; take what is really there
+     (setq beg (point))
+     (skip-chars-forward " \t\r\n")
+     (save-match-data
+       (if nosubtrees
+          (outline-next-heading)
+        (save-excursion (outline-end-of-heading)
+                        (setq folded (org-invisible-p)))
+        (ignore-errors (org-forward-heading-same-level (1- n) t))
+        (org-end-of-subtree t t)))
+     ;; Include the end of an inlinetask
+     (when (and (featurep 'org-inlinetask)
+               (looking-at-p (concat (org-inlinetask-outline-regexp)
+                                     "END[ \t]*$")))
+       (end-of-line))
+     (setq end (point))
+     (goto-char beg0)
+     (when (> end beg)
+       (setq org-subtree-clip-folded folded)
+       (when (or cut force-store-markers)
+        (org-save-markers-in-region beg end))
+       (if cut (kill-region beg end) (copy-region-as-kill beg end))
+       (setq org-subtree-clip (current-kill 0))
+       (message "%s: Subtree(s) with %d characters"
+               (if cut "Cut" "Copied")
+               (length org-subtree-clip))))))
 
 (defun org-paste-subtree (&optional level tree for-yank remove)
   "Paste the clipboard as a subtree, with modification of headline level.
+
 The entire subtree is promoted or demoted in order to match a new headline
 level.
 
@@ -8543,41 +7610,33 @@ When REMOVE is non-nil, remove the subtree from the 
clipboard."
   (interactive "P")
   (setq tree (or tree (and kill-ring (current-kill 0))))
   (unless (org-kill-is-subtree-p tree)
-    (user-error "%s"
-               (substitute-command-keys
-                "The kill is not a (set of) tree(s) - please use \\[yank] to 
yank anyway")))
+    (user-error
+     (substitute-command-keys
+      "The kill is not a (set of) tree(s).  Use `\\[yank]' to yank anyway")))
   (org-with-limited-levels
    (let* ((visp (not (org-invisible-p)))
          (txt tree)
          (old-level (if (string-match org-outline-regexp-bol txt)
                         (- (match-end 0) (match-beginning 0) 1)
                       -1))
-         (force-level (cond (level (prefix-numeric-value level))
-                            ((and (looking-at "[ \t]*$")
-                                  (string-match
-                                   "^\\*+$" (buffer-substring
-                                             (point-at-bol) (point))))
-                             (- (match-end 0) (match-beginning 0)))
-                            ((and (bolp)
-                                  (looking-at org-outline-regexp))
-                             (- (match-end 0) (point) 1))))
-         (previous-level (save-excursion
-                           (condition-case nil
-                               (progn
-                                 (outline-previous-visible-heading 1)
-                                 (if (looking-at org-outline-regexp-bol)
-                                     (- (match-end 0) (match-beginning 0) 1)
-                                   1))
-                             (error 1))))
-         (next-level (save-excursion
-                       (condition-case nil
-                           (progn
-                             (or (looking-at org-outline-regexp)
-                                 (outline-next-visible-heading 1))
-                             (if (looking-at org-outline-regexp-bol)
-                                 (- (match-end 0) (match-beginning 0) 1)
-                               1))
-                         (error 1))))
+         (force-level
+          (cond
+           (level (prefix-numeric-value level))
+           ;; When point is after the stars in an otherwise empty
+           ;; headline, use the number of stars as the forced level.
+           ((and (org-match-line "^\\*+[ \t]*$")
+                 (not (eq ?* (char-after))))
+            (org-outline-level))
+           ((looking-at-p org-outline-regexp-bol) (org-outline-level))))
+         (previous-level
+          (save-excursion
+            (org-previous-visible-heading 1)
+            (if (org-at-heading-p) (org-outline-level) 1)))
+         (next-level
+          (save-excursion
+            (if (org-at-heading-p) (org-outline-level)
+              (org-next-visible-heading 1)
+              (if (org-at-heading-p) (org-outline-level) 1))))
          (new-level (or force-level (max previous-level next-level)))
          (shift (if (or (= old-level -1)
                         (= new-level -1)
@@ -8585,16 +7644,19 @@ When REMOVE is non-nil, remove the subtree from the 
clipboard."
                     0
                   (- new-level old-level)))
          (delta (if (> shift 0) -1 1))
-         (func (if (> shift 0) 'org-demote 'org-promote))
+         (func (if (> shift 0) #'org-demote #'org-promote))
          (org-odd-levels-only nil)
          beg end newend)
-     ;; Remove the forced level indicator
-     (when force-level
-       (delete-region (point-at-bol) (point)))
-     ;; Paste
-     (beginning-of-line (if (bolp) 1 2))
+     ;; Remove the forced level indicator.
+     (when (and force-level (not level))
+       (delete-region (line-beginning-position) (point)))
+     ;; Paste before the next visible heading or at end of buffer,
+     ;; unless point is at the beginning of a headline.
+     (unless (and (bolp) (org-at-heading-p))
+       (org-next-visible-heading 1)
+       (unless (bolp) (insert "\n")))
      (setq beg (point))
-     (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
+     (when (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
      (insert-before-markers txt)
      (unless (string-suffix-p "\n" txt) (insert "\n"))
      (setq newend (point))
@@ -8605,7 +7667,7 @@ When REMOVE is non-nil, remove the subtree from the 
clipboard."
      (setq beg (point))
      (when (and (org-invisible-p) visp)
        (save-excursion (outline-show-heading)))
-     ;; Shift if necessary
+     ;; Shift if necessary.
      (unless (= shift 0)
        (save-restriction
         (narrow-to-region beg end)
@@ -8614,16 +7676,16 @@ When REMOVE is non-nil, remove the subtree from the 
clipboard."
           (setq shift (+ delta shift)))
         (goto-char (point-min))
         (setq newend (point-max))))
-     (when (or (called-interactively-p 'interactive) for-yank)
+     (when (or for-yank (called-interactively-p 'interactive))
        (message "Clipboard pasted as level %d subtree" new-level))
      (when (and (not for-yank) ; in this case, org-yank will decide about 
folding
                kill-ring
-               (eq org-subtree-clip (current-kill 0))
+               (equal org-subtree-clip (current-kill 0))
                org-subtree-clip-folded)
        ;; The tree was folded before it was killed/copied
-       (outline-hide-subtree))
-     (and for-yank (goto-char newend))
-     (and remove (setq kill-ring (cdr kill-ring))))))
+       (org-flag-subtree t))
+     (when for-yank (goto-char newend))
+     (when remove (pop kill-ring)))))
 
 (defun org-kill-is-subtree-p (&optional txt)
   "Check if the current kill is an outline subtree, or a set of trees.
@@ -8695,6 +7757,13 @@ If yes, remember the marker and the distance to BEG."
               (when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
               (point)))))))
 
+(defun org-toggle-narrow-to-subtree ()
+  "Narrow to the subtree at point or widen a narrowed buffer."
+  (interactive)
+  (if (buffer-narrowed-p)
+      (widen)
+    (org-narrow-to-subtree)))
+
 (defun org-narrow-to-block ()
   "Narrow buffer to the current block."
   (interactive)
@@ -8756,7 +7825,7 @@ with the original repeater."
                "")))                   ;No time shift
         (doshift
          (and (org-string-nw-p shift)
-              (or (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ 
\t]*\\'"
+              (or (string-match "\\`[ \t]*\\([\\+\\-]?[0-9]+\\)\\([dwmy]\\)[ 
\t]*\\'"
                                 shift)
                   (user-error "Invalid shift specification %s" shift)))))
     (goto-char end-of-tree)
@@ -8933,7 +8002,7 @@ function is being called interactively."
       (setq end (point-max))
       (setq what "top-level")
       (goto-char start)
-      (outline-show-all)))
+      (org-show-all '(headings blocks))))
 
     (setq beg (point))
     (when (>= beg end) (goto-char start) (user-error "Nothing to sort"))
@@ -8982,95 +8051,95 @@ function is being called interactively."
             (when (and (eq (org-clock-is-active) (current-buffer))
                        (<= start (marker-position org-clock-marker))
                        (>= end (marker-position org-clock-marker)))
-              (org-with-silent-modifications
-               (put-text-property (1- org-clock-marker) org-clock-marker
-                                  :org-clock-marker-backup t))
+              (with-silent-modifications
+                (put-text-property (1- org-clock-marker) org-clock-marker
+                                   :org-clock-marker-backup t))
               t))
            (dcst (downcase sorting-type))
            (case-fold-search nil)
            (now (current-time)))
-        (sort-subr
-         (/= dcst sorting-type)
-         ;; This function moves to the beginning character of the "record" to
-         ;; be sorted.
-        (lambda nil
-          (if (re-search-forward re nil t)
-              (goto-char (match-beginning 0))
-            (goto-char (point-max))))
-         ;; This function moves to the last character of the "record" being
-         ;; sorted.
-        (lambda nil
-          (save-match-data
-            (condition-case nil
-                (outline-forward-same-level 1)
-              (error
-               (goto-char (point-max))))))
-         ;; This function returns the value that gets sorted against.
-        (lambda nil
-          (cond
-           ((= dcst ?n)
-            (if (looking-at org-complex-heading-regexp)
-                (string-to-number (org-sort-remove-invisible (match-string 4)))
-              nil))
-           ((= dcst ?a)
-            (if (looking-at org-complex-heading-regexp)
-                (funcall case-func (org-sort-remove-invisible (match-string 
4)))
-              nil))
-           ((= dcst ?k)
-            (or (get-text-property (point) :org-clock-minutes) 0))
-           ((= dcst ?t)
-            (let ((end (save-excursion (outline-next-heading) (point))))
-              (if (or (re-search-forward org-ts-regexp end t)
-                      (re-search-forward org-ts-regexp-both end t))
-                  (org-time-string-to-seconds (match-string 0))
-                (float-time now))))
-           ((= dcst ?c)
-            (let ((end (save-excursion (outline-next-heading) (point))))
-              (if (re-search-forward
-                   (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
-                   end t)
-                  (org-time-string-to-seconds (match-string 0))
-                (float-time now))))
-           ((= dcst ?s)
-            (let ((end (save-excursion (outline-next-heading) (point))))
-              (if (re-search-forward org-scheduled-time-regexp end t)
-                  (org-time-string-to-seconds (match-string 1))
-                (float-time now))))
-           ((= dcst ?d)
-            (let ((end (save-excursion (outline-next-heading) (point))))
-              (if (re-search-forward org-deadline-time-regexp end t)
-                  (org-time-string-to-seconds (match-string 1))
-                (float-time now))))
-           ((= dcst ?p)
-            (if (re-search-forward org-priority-regexp (point-at-eol) t)
-                (string-to-char (match-string 2))
-              org-default-priority))
-           ((= dcst ?r)
-            (or (org-entry-get nil property) ""))
-           ((= dcst ?o)
-            (when (looking-at org-complex-heading-regexp)
-              (let* ((m (match-string 2))
-                     (s (if (member m org-done-keywords) '- '+)))
-                (- 99 (funcall s (length (member m org-todo-keywords-1)))))))
-           ((= dcst ?f)
-            (if getkey-func
-                (progn
-                  (setq tmp (funcall getkey-func))
-                  (when (stringp tmp) (setq tmp (funcall case-func tmp)))
-                  tmp)
-              (error "Invalid key function `%s'" getkey-func)))
-           (t (error "Invalid sorting type `%c'" sorting-type))))
-         nil
-         (cond
-          ((= dcst ?a) 'string<)
-          ((= dcst ?f)
-          (or compare-func
-              (and interactive?
-                   (org-read-function
-                    (concat "Function for comparing keys "
-                            "(empty for default `sort-subr' predicate): ")
-                    'allow-empty))))
-          ((member dcst '(?p ?t ?s ?d ?c ?k)) '<)))
+        (org-preserve-local-variables
+        (sort-subr
+         (/= dcst sorting-type)
+         ;; This function moves to the beginning character of the
+         ;; "record" to be sorted.
+         (lambda nil
+           (if (re-search-forward re nil t)
+               (goto-char (match-beginning 0))
+             (goto-char (point-max))))
+         ;; This function moves to the last character of the "record" being
+         ;; sorted.
+         (lambda nil
+           (save-match-data
+             (condition-case nil
+                 (outline-forward-same-level 1)
+               (error
+                (goto-char (point-max))))))
+         ;; This function returns the value that gets sorted against.
+         (lambda ()
+           (cond
+            ((= dcst ?n)
+             (string-to-number
+              (org-sort-remove-invisible (org-get-heading t t t t))))
+            ((= dcst ?a)
+             (funcall case-func
+                      (org-sort-remove-invisible (org-get-heading t t t t))))
+            ((= dcst ?k)
+             (or (get-text-property (point) :org-clock-minutes) 0))
+            ((= dcst ?t)
+             (let ((end (save-excursion (outline-next-heading) (point))))
+               (if (or (re-search-forward org-ts-regexp end t)
+                       (re-search-forward org-ts-regexp-both end t))
+                   (org-time-string-to-seconds (match-string 0))
+                 (float-time now))))
+            ((= dcst ?c)
+             (let ((end (save-excursion (outline-next-heading) (point))))
+               (if (re-search-forward
+                    (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
+                    end t)
+                   (org-time-string-to-seconds (match-string 0))
+                 (float-time now))))
+            ((= dcst ?s)
+             (let ((end (save-excursion (outline-next-heading) (point))))
+               (if (re-search-forward org-scheduled-time-regexp end t)
+                   (org-time-string-to-seconds (match-string 1))
+                 (float-time now))))
+            ((= dcst ?d)
+             (let ((end (save-excursion (outline-next-heading) (point))))
+               (if (re-search-forward org-deadline-time-regexp end t)
+                   (org-time-string-to-seconds (match-string 1))
+                 (float-time now))))
+            ((= dcst ?p)
+             (if (re-search-forward org-priority-regexp (point-at-eol) t)
+                 (string-to-char (match-string 2))
+               org-default-priority))
+            ((= dcst ?r)
+             (or (org-entry-get nil property) ""))
+            ((= dcst ?o)
+             (when (looking-at org-complex-heading-regexp)
+               (let* ((m (match-string 2))
+                      (s (if (member m org-done-keywords) '- '+)))
+                 (- 99 (funcall s (length (member m org-todo-keywords-1)))))))
+            ((= dcst ?f)
+             (if getkey-func
+                 (progn
+                   (setq tmp (funcall getkey-func))
+                   (when (stringp tmp) (setq tmp (funcall case-func tmp)))
+                   tmp)
+               (error "Invalid key function `%s'" getkey-func)))
+            (t (error "Invalid sorting type `%c'" sorting-type))))
+         nil
+         (cond
+          ((= dcst ?a) 'org-string-collate-lessp)
+          ((= dcst ?f)
+           (or compare-func
+               (and interactive?
+                    (org-read-function
+                     (concat "Function for comparing keys "
+                             "(empty for default `sort-subr' predicate): ")
+                     'allow-empty))))
+          ((member dcst '(?p ?t ?s ?d ?c ?k)) '<))))
+       (org-cycle-hide-drawers 'all)
        (when restore-clock?
          (move-marker org-clock-marker
                       (1+ (next-single-property-change
@@ -9080,272 +8149,6 @@ function is being called interactively."
     (run-hooks 'org-after-sorting-entries-or-items-hook)
     (message "Sorting entries...done")))
 
-;;; The orgstruct minor mode
-
-;; Define a minor mode which can be used in other modes in order to
-;; integrate the Org mode structure editing commands.
-
-;; This is really a hack, because the Org mode structure commands use
-;; keys which normally belong to the major mode.  Here is how it
-;; works: The minor mode defines all the keys necessary to operate the
-;; structure commands, but wraps the commands into a function which
-;; tests if the cursor is currently at a headline or a plain list
-;; item.  If that is the case, the structure command is used,
-;; temporarily setting many Org mode variables like regular
-;; expressions for filling etc.  However, when any of those keys is
-;; used at a different location, function uses `key-binding' to look
-;; up if the key has an associated command in another currently active
-;; keymap (minor modes, major mode, global), and executes that
-;; command.  There might be problems if any of the keys is otherwise
-;; used as a prefix key.
-
-(defcustom orgstruct-heading-prefix-regexp ""
-  "Regexp that matches the custom prefix of Org headlines in
-orgstruct(++)-mode."
-  :group 'org
-  :version "26.1"
-  :package-version '(Org . "8.3")
-  :type 'regexp)
-;;;###autoload(put 'orgstruct-heading-prefix-regexp 'safe-local-variable 
'stringp)
-
-(defcustom orgstruct-setup-hook nil
-  "Hook run after orgstruct-mode-map is filled."
-  :group 'org
-  :version "24.4"
-  :package-version '(Org . "8.0")
-  :type 'hook)
-
-(defvar orgstruct-initialized nil)
-
-(defvar org-local-vars nil
-  "List of local variables, for use by `orgstruct-mode'.")
-
-;;;###autoload
-(define-minor-mode orgstruct-mode
-  "Toggle the minor mode `orgstruct-mode'.
-This mode is for using Org mode structure commands in other
-modes.  The following keys behave as if Org mode were active, if
-the cursor is on a headline, or on a plain list item (both as
-defined by Org mode)."
-  nil " OrgStruct" (make-sparse-keymap)
-  (funcall (if orgstruct-mode
-              'add-to-invisibility-spec
-            'remove-from-invisibility-spec)
-          '(outline . t))
-  (when orgstruct-mode
-    (org-load-modules-maybe)
-    (unless orgstruct-initialized
-      (orgstruct-setup)
-      (setq orgstruct-initialized t))))
-
-;;;###autoload
-(defun turn-on-orgstruct ()
-  "Unconditionally turn on `orgstruct-mode'."
-  (orgstruct-mode 1))
-
-(defvar-local orgstruct-is-++ nil
-  "Is `orgstruct-mode' in ++ version in the current-buffer?")
-(defvar-local org-fb-vars nil)
-(defun orgstruct++-mode (&optional arg)
-  "Toggle `orgstruct-mode', the enhanced version of it.
-In addition to setting orgstruct-mode, this also exports all
-indentation and autofilling variables from Org mode into the
-buffer.  It will also recognize item context in multiline items."
-  (interactive "P")
-  (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
-  (if (< arg 1)
-      (progn (orgstruct-mode -1)
-            (dolist (v org-fb-vars)
-              (set (make-local-variable (car v))
-                   (if (eq (car-safe (cadr v)) 'quote)
-                       (cl-cadadr v)
-                     (nth 1 v)))))
-    (orgstruct-mode 1)
-    (setq org-fb-vars nil)
-    (unless org-local-vars
-      (setq org-local-vars (org-get-local-variables)))
-    (let (var val)
-      (dolist (x org-local-vars)
-       (when (string-match
-              "^\\(paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\
-\\|fill-prefix\\|indent-\\)"
-              (symbol-name (car x)))
-         (setq var (car x) val (nth 1 x))
-         (push (list var `(quote ,(eval var))) org-fb-vars)
-         (set (make-local-variable var)
-              (if (eq (car-safe val) 'quote) (nth 1 val) val))))
-      (setq-local orgstruct-is-++ t))))
-
-;;;###autoload
-(defun turn-on-orgstruct++ ()
-  "Unconditionally turn on `orgstruct++-mode'."
-  (orgstruct++-mode 1))
-
-(defun orgstruct-error ()
-  "Error when there is no default binding for a structure key."
-  (interactive)
-  (funcall (if (fboundp 'user-error)
-              'user-error
-            'error)
-          "This key has no function outside structure elements"))
-
-(defun orgstruct-setup ()
-  "Setup orgstruct keymap."
-  (dolist (cell '((org-demote . t)
-                 (org-metaleft . t)
-                 (org-metaright . t)
-                 (org-promote . t)
-                 (org-shiftmetaleft . t)
-                 (org-shiftmetaright . t)
-                 org-backward-element
-                 org-backward-heading-same-level
-                 org-ctrl-c-ret
-                 org-ctrl-c-minus
-                 org-ctrl-c-star
-                 org-cycle
-                 org-force-cycle-archived
-                 org-forward-heading-same-level
-                 org-insert-heading
-                 org-insert-heading-respect-content
-                 org-kill-note-or-show-branches
-                 org-mark-subtree
-                 org-meta-return
-                 org-metadown
-                 org-metaup
-                 org-narrow-to-subtree
-                 org-promote-subtree
-                 org-reveal
-                 org-shiftdown
-                 org-shiftleft
-                 org-shiftmetadown
-                 org-shiftmetaup
-                 org-shiftright
-                 org-shifttab
-                 org-shifttab
-                 org-shiftup
-                 org-show-children
-                 org-show-subtree
-                 org-sort
-                 org-up-element
-                 outline-demote
-                 outline-next-visible-heading
-                 outline-previous-visible-heading
-                 outline-promote
-                 outline-up-heading))
-    (let ((f (or (car-safe cell) cell))
-         (disable-when-heading-prefix (cdr-safe cell)))
-      (when (fboundp f)
-       (let ((new-bindings))
-         (dolist (binding (nconc (where-is-internal f org-mode-map)
-                                 (where-is-internal f outline-mode-map)))
-           (push binding new-bindings)
-           ;; TODO use local-function-key-map
-           (dolist (rep '(("<tab>" . "TAB")
-                          ("<return>" . "RET")
-                          ("<escape>" . "ESC")
-                          ("<delete>" . "DEL")))
-             (setq binding (read-kbd-macro
-                            (let ((case-fold-search))
-                              (replace-regexp-in-string
-                               (regexp-quote (cdr rep))
-                               (car rep)
-                               (key-description binding)))))
-             (cl-pushnew binding new-bindings :test 'equal)))
-         (dolist (binding new-bindings)
-           (let ((key (lookup-key orgstruct-mode-map binding)))
-             (when (or (not key) (numberp key))
-               (ignore-errors
-                 (org-defkey orgstruct-mode-map
-                             binding
-                             (orgstruct-make-binding
-                              f binding disable-when-heading-prefix))))))))))
-  (run-hooks 'orgstruct-setup-hook))
-
-(defun orgstruct-make-binding (fun key disable-when-heading-prefix)
-  "Create a function for binding in the structure minor mode.
-FUN is the command to call inside a table.  KEY is the key that
-should be checked in for a command to execute outside of tables.
-Non-nil `disable-when-heading-prefix' means to disable the command
-if `orgstruct-heading-prefix-regexp' is not empty."
-  (let ((name (concat "orgstruct-hijacker-" (symbol-name fun))))
-    (let ((nname name)
-         (i 0))
-      (while (fboundp (intern nname))
-       (setq nname (format "%s-%d" name (setq i (1+ i)))))
-      (setq name (intern nname)))
-    (eval
-     (let ((bindings '((org-heading-regexp
-                       (concat "^"
-                               orgstruct-heading-prefix-regexp
-                               "\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[                
]*$"))
-                      (org-outline-regexp
-                       (concat orgstruct-heading-prefix-regexp "\\*+ "))
-                      (org-outline-regexp-bol
-                       (concat "^" org-outline-regexp))
-                      (outline-regexp org-outline-regexp)
-                      (outline-heading-end-regexp "\n")
-                      (outline-level 'org-outline-level)
-                      (outline-heading-alist))))
-       `(defun ,name (arg)
-         ,(concat "In Structure, run `" (symbol-name fun) "'.\n"
-                  "Outside of structure, run the binding of `"
-                  (key-description key) "'."
-                  (when disable-when-heading-prefix
-                    (concat
-                     "\nIf `orgstruct-heading-prefix-regexp' is not empty, 
this command will always fall\n"
-                     "back to the default binding due to limitations of Org's 
implementation of\n"
-                     "`" (symbol-name fun) "'.")))
-         (interactive "p")
-         (let* ((disable
-                 ,(and disable-when-heading-prefix
-                       '(not (string= orgstruct-heading-prefix-regexp ""))))
-                (fallback
-                 (or disable
-                     (not
-                      (let* ,bindings
-                        (org-context-p 'headline 'item
-                                       ,(when (memq fun
-                                                    '(org-insert-heading
-                                                      
org-insert-heading-respect-content
-                                                      org-meta-return))
-                                          '(when orgstruct-is-++
-                                             'item-body))))))))
-           (if fallback
-               (let* ((orgstruct-mode)
-                      (binding
-                       (let ((key ,key))
-                         (catch 'exit
-                           (dolist
-                               (rep
-                                '(nil
-                                  ("<\\([^>]*\\)tab>" . "\\1TAB")
-                                  ("<\\([^>]*\\)return>" . "\\1RET")
-                                  ("<\\([^>]*\\)escape>" . "\\1ESC")
-                                  ("<\\([^>]*\\)delete>" . "\\1DEL"))
-                                nil)
-                             (when rep
-                               (setq key (read-kbd-macro
-                                          (let ((case-fold-search))
-                                            (replace-regexp-in-string
-                                             (car rep)
-                                             (cdr rep)
-                                             (key-description key))))))
-                             (when (key-binding key)
-                               (throw 'exit (key-binding key))))))))
-                 (if (keymapp binding)
-                     (org-set-transient-map binding)
-                   (let ((func (or binding
-                                   (unless disable
-                                     'orgstruct-error))))
-                     (when func
-                       (call-interactively func)))))
-             (org-run-like-in-org-mode
-              (lambda ()
-                (interactive)
-                (let* ,bindings
-                  (call-interactively ',fun)))))))))
-    name))
-
 (defun org-contextualize-keys (alist contexts)
   "Return valid elements in ALIST depending on CONTEXTS.
 
@@ -9423,20 +8226,11 @@ definitions."
          (push r res))))
     (delete-dups (delq nil res))))
 
-(defun org-context-p (&rest contexts)
-  "Check if local context is any of CONTEXTS.
-Possible values in the list of contexts are `table', `headline', and `item'."
-  (let ((pos (point)))
-    (goto-char (point-at-bol))
-    (prog1 (or (and (memq 'table contexts)
-                   (looking-at "[ \t]*|"))
-              (and (memq 'headline contexts)
-                   (looking-at org-outline-regexp))
-              (and (memq 'item contexts)
-                   (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
-              (and (memq 'item-body contexts)
-                   (org-in-item-p)))
-      (goto-char pos))))
+;; Defined to provide a value for defcustom, since there is no
+;; string-collate-greaterp in Emacs.
+(defun org-string-collate-greaterp (s1 s2)
+  "Return non-nil if S1 is greater than S2 in collation order."
+  (not (org-string-collate-lessp s1 s2)))
 
 ;;;###autoload
 (defun org-run-like-in-org-mode (cmd)
@@ -9445,10 +8239,8 @@ This will temporarily bind local variables that are 
typically bound in
 Org mode to the values they have in Org mode, and then interactively
 call CMD."
   (org-load-modules-maybe)
-  (unless org-local-vars
-    (setq org-local-vars (org-get-local-variables)))
   (let (binds)
-    (dolist (var org-local-vars)
+    (dolist (var (org-get-local-variables))
       (when (or (not (boundp (car var)))
                (eq (symbol-value (car var))
                    (default-value (car var))))
@@ -9478,16 +8270,16 @@ the value of the drawer property."
         (inherit? (org-property-inherit-p dprop))
         (property-re (org-re-property (concat (regexp-quote dprop) "\\+?") t))
         (global (and inherit? (org--property-global-value dprop nil))))
-    (org-with-silent-modifications
-     (org-with-point-at 1
-       ;; Set global values (e.g., values defined through
-       ;; "#+PROPERTY:" keywords) to the whole buffer.
-       (when global (put-text-property (point-min) (point-max) tprop global))
-       ;; Set local values.
-       (while (re-search-forward property-re nil t)
-        (when (org-at-property-p)
-          (org-refresh-property tprop (org-entry-get (point) dprop) inherit?))
-        (outline-next-heading))))))
+    (with-silent-modifications
+      (org-with-point-at 1
+       ;; Set global values (e.g., values defined through
+       ;; "#+PROPERTY:" keywords) to the whole buffer.
+       (when global (put-text-property (point-min) (point-max) tprop global))
+       ;; Set local values.
+       (while (re-search-forward property-re nil t)
+         (when (org-at-property-p)
+           (org-refresh-property tprop (org-entry-get (point) dprop) inherit?))
+         (outline-next-heading))))))
 
 (defun org-refresh-property (tprop p &optional inherit)
   "Refresh the buffer text property TPROP from the drawer property P.
@@ -9519,49 +8311,49 @@ sub-tree if optional argument INHERIT is non-nil."
                   "???"))
                ((symbolp org-category) (symbol-name org-category))
                (t org-category))))
-    (org-with-silent-modifications
-     (org-with-wide-buffer
-      ;; Set buffer-wide category.  Search last #+CATEGORY keyword.
-      ;; This is the default category for the buffer.  If none is
-      ;; found, fall-back to `org-category' or buffer file name.
-      (put-text-property
-       (point-min) (point-max)
-       'org-category
-       (catch 'buffer-category
-        (goto-char (point-max))
-        (while (re-search-backward "^[ \t]*#\\+CATEGORY:" (point-min) t)
-          (let ((element (org-element-at-point)))
-            (when (eq (org-element-type element) 'keyword)
-              (throw 'buffer-category
-                     (org-element-property :value element)))))
-        default-category))
-      ;; Set sub-tree specific categories.
-      (goto-char (point-min))
-      (let ((regexp (org-re-property "CATEGORY")))
-       (while (re-search-forward regexp nil t)
-         (let ((value (match-string-no-properties 3)))
-           (when (org-at-property-p)
-             (put-text-property
-              (save-excursion (org-back-to-heading t) (point))
-              (save-excursion (org-end-of-subtree t t) (point))
-              'org-category
-              value)))))))))
+    (with-silent-modifications
+      (org-with-wide-buffer
+       ;; Set buffer-wide category.  Search last #+CATEGORY keyword.
+       ;; This is the default category for the buffer.  If none is
+       ;; found, fall-back to `org-category' or buffer file name.
+       (put-text-property
+       (point-min) (point-max)
+       'org-category
+       (catch 'buffer-category
+         (goto-char (point-max))
+         (while (re-search-backward "^[ \t]*#\\+CATEGORY:" (point-min) t)
+           (let ((element (org-element-at-point)))
+             (when (eq (org-element-type element) 'keyword)
+               (throw 'buffer-category
+                      (org-element-property :value element)))))
+         default-category))
+       ;; Set sub-tree specific categories.
+       (goto-char (point-min))
+       (let ((regexp (org-re-property "CATEGORY")))
+        (while (re-search-forward regexp nil t)
+          (let ((value (match-string-no-properties 3)))
+            (when (org-at-property-p)
+              (put-text-property
+               (save-excursion (org-back-to-heading t) (point))
+               (save-excursion (org-end-of-subtree t t) (point))
+               'org-category
+               value)))))))))
 
 (defun org-refresh-stats-properties ()
   "Refresh stats text properties in the buffer."
-  (org-with-silent-modifications
-   (org-with-point-at 1
-     (let ((regexp (concat org-outline-regexp-bol
-                          ".*\\[\\([0-9]*\\)\\(?:%\\|/\\([0-9]*\\)\\)\\]")))
-       (while (re-search-forward regexp nil t)
-        (let* ((numerator (string-to-number (match-string 1)))
-               (denominator (and (match-end 2)
-                                 (string-to-number (match-string 2))))
-               (stats (cond ((not denominator) numerator) ;percent
-                            ((= denominator 0) 0)
-                            (t (/ (* numerator 100) denominator)))))
-          (put-text-property (point) (progn (org-end-of-subtree t t) (point))
-                             'org-stats stats)))))))
+  (with-silent-modifications
+    (org-with-point-at 1
+      (let ((regexp (concat org-outline-regexp-bol
+                           ".*\\[\\([0-9]*\\)\\(?:%\\|/\\([0-9]*\\)\\)\\]")))
+       (while (re-search-forward regexp nil t)
+         (let* ((numerator (string-to-number (match-string 1)))
+                (denominator (and (match-end 2)
+                                  (string-to-number (match-string 2))))
+                (stats (cond ((not denominator) numerator) ;percent
+                             ((= denominator 0) 0)
+                             (t (/ (* numerator 100) denominator)))))
+           (put-text-property (point) (progn (org-end-of-subtree t t) (point))
+                              'org-stats stats)))))))
 
 (defun org-refresh-effort-properties ()
   "Refresh effort properties."
@@ -9570,954 +8362,245 @@ sub-tree if optional argument INHERIT is non-nil."
    '((effort . identity)
      (effort-minutes . org-duration-to-minutes))))
 
-;;;; Link Stuff
-
-;;; Link abbreviations
-
-(defun org-link-expand-abbrev (link)
-  "Apply replacements as defined in `org-link-abbrev-alist'."
-  (if (string-match "^\\([^:]*\\)\\(::?\\(.*\\)\\)?$" link)
-      (let* ((key (match-string 1 link))
-            (as (or (assoc key org-link-abbrev-alist-local)
-                    (assoc key org-link-abbrev-alist)))
-            (tag (and (match-end 2) (match-string 3 link)))
-            rpl)
-       (if (not as)
-           link
-         (setq rpl (cdr as))
-         (cond
-          ((symbolp rpl) (funcall rpl tag))
-          ((string-match "%(\\([^)]+\\))" rpl)
-           (replace-match
-            (save-match-data
-              (funcall (intern-soft (match-string 1 rpl)) tag)) t t rpl))
-          ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
-          ((string-match "%h" rpl)
-           (replace-match (url-hexify-string (or tag "")) t t rpl))
-          (t (concat rpl tag)))))
-    link))
-
-;;; Storing and inserting links
-
-(defvar org-insert-link-history nil
-  "Minibuffer history for links inserted with `org-insert-link'.")
-
-(defvar org-stored-links nil
-  "Contains the links stored with `org-store-link'.")
-
-(defvar org-store-link-plist nil
-  "Plist with info about the most recently link created with 
`org-store-link'.")
-
-(defun org-store-link-functions ()
-  "Return a list of functions that are called to create and store a link.
-The functions defined in the :store property of
-`org-link-parameters'.
-
-Each function will be called in turn until one returns a non-nil
-value.  Each function should check if it is responsible for
-creating this link (for example by looking at the major mode).
-If not, it must exit and return nil.  If yes, it should return
-a non-nil value after calling `org-store-link-props' with a list
-of properties and values.  Special properties are:
-
-:type         The link prefix, like \"http\".  This must be given.
-:link         The link, like \"http://www.astro.uva.nl/~dominik\";.
-              This is obligatory as well.
-:description  Optional default description for the second pair
-              of brackets in an Org mode link.  The user can still change
-              this when inserting this link into an Org mode buffer.
-
-In addition to these, any additional properties can be specified
-and then used in capture templates."
-  (cl-loop for link in org-link-parameters
-          with store-func
-          do (setq store-func (org-link-get-parameter (car link) :store))
-          if store-func
-          collect store-func))
-
-(defvar org-agenda-buffer-name) ; Defined in org-agenda.el
-(defvar org-id-link-to-org-use-id) ; Defined in org-id.el
-
-;;;###autoload
-(defun org-store-link (arg)
-  "Store an org-link to the current location.
-\\<org-mode-map>
-This link is added to `org-stored-links' and can later be inserted
-into an Org buffer with `org-insert-link' (`\\[org-insert-link]').
+(defun org-find-file-at-mouse (ev)
+  "Open file link or URL at mouse."
+  (interactive "e")
+  (mouse-set-point ev)
+  (org-open-at-point 'in-emacs))
 
-For some link types, a `\\[universal-argument]' prefix ARG is interpreted.  \
-A single
-`\\[universal-argument]' negates `org-context-in-file-links' for file links or
-`org-gnus-prefer-web-links' for links to Usenet articles.
+(defun org-open-at-mouse (ev)
+  "Open file link or URL at mouse.
+See the docstring of `org-open-file' for details."
+  (interactive "e")
+  (mouse-set-point ev)
+  (when (eq major-mode 'org-agenda-mode)
+    (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
+  (org-open-at-point))
 
-A `\\[universal-argument] \\[universal-argument]' prefix ARG forces \
-skipping storing functions that are not
-part of Org core.
+(defvar org-window-config-before-follow-link nil
+  "The window configuration before following a link.
+This is saved in case the need arises to restore it.")
 
-A `\\[universal-argument] \\[universal-argument] \\[universal-argument]' \
-prefix ARG forces storing a link for each line in the
-active region."
-  (interactive "P")
-  (org-load-modules-maybe)
-  (if (and (equal arg '(64)) (org-region-active-p))
-      (save-excursion
-       (let ((end (region-end)))
-         (goto-char (region-beginning))
-         (set-mark (point))
-         (while (< (point-at-eol) end)
-           (move-end-of-line 1) (activate-mark)
-           (let (current-prefix-arg)
-             (call-interactively 'org-store-link))
-           (move-beginning-of-line 2)
-           (set-mark (point)))))
-    (setq org-store-link-plist nil)
-    (let (link cpltxt desc description search txt custom-id agenda-link)
-      (cond
-       ;; Store a link using an external link type, if any function is
-       ;; available. If more than one can generate a link from current
-       ;; location, ask which one to use.
-       ((and (not (equal arg '(16)))
-            (let ((results-alist nil))
-              (dolist (f (org-store-link-functions))
-                (when (funcall f)
-                  ;; XXX: return value is not link's plist, so we
-                  ;; store the new value before it is modified.  It
-                  ;; would be cleaner to ask store link functions to
-                  ;; return the plist instead.
-                  (push (cons f (copy-sequence org-store-link-plist))
-                        results-alist)))
-              (pcase results-alist
-                (`nil nil)
-                (`((,_ . ,_)) t)       ;single choice: nothing to do
-                (`((,name . ,_) . ,_)
-                 ;; Reinstate link plist associated to the chosen
-                 ;; function.
-                 (apply #'org-store-link-props
-                        (cdr (assoc-string
-                              (completing-read
-                               "Which function for creating the link? "
-                               (mapcar #'car results-alist)
-                               nil t (symbol-name name))
-                              results-alist)))
-                 t))))
-       (setq link (plist-get org-store-link-plist :link))
-       (setq desc (or (plist-get org-store-link-plist :description)
-                      link)))
-
-       ;; Store a link from a source code buffer.
-       ((org-src-edit-buffer-p)
-       (let ((coderef-format (org-src-coderef-format)))
-         (cond ((save-excursion
-                  (beginning-of-line)
-                  (looking-at (org-src-coderef-regexp coderef-format)))
-                (setq link (format "(%s)" (match-string-no-properties 3))))
-               ((called-interactively-p 'any)
-                (let ((label (read-string "Code line label: ")))
-                  (end-of-line)
-                  (setq link (format coderef-format label))
-                  (let ((gc (- 79 (length link))))
-                    (if (< (current-column) gc)
-                        (org-move-to-column gc t)
-                      (insert " ")))
-                  (insert link)
-                  (setq link (concat "(" label ")"))
-                  (setq desc nil)))
-               (t (setq link nil)))))
-
-       ;; We are in the agenda, link to referenced location
-       ((equal (bound-and-true-p org-agenda-buffer-name) (buffer-name))
-       (let ((m (or (get-text-property (point) 'org-hd-marker)
-                    (get-text-property (point) 'org-marker))))
-         (when m
-           (org-with-point-at m
-             (setq agenda-link
-                   (if (called-interactively-p 'any)
-                       (call-interactively 'org-store-link)
-                     (org-store-link nil)))))))
-
-       ((eq major-mode 'calendar-mode)
-       (let ((cd (calendar-cursor-to-date)))
-         (setq link
-               (format-time-string
-                (car org-time-stamp-formats)
-                (encode-time 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd))))
-         (org-store-link-props :type "calendar" :date cd)))
-
-       ((eq major-mode 'help-mode)
-       (setq link (concat "help:" (save-excursion
-                                    (goto-char (point-min))
-                                    (looking-at "^[^ ]+")
-                                    (match-string 0))))
-       (org-store-link-props :type "help"))
-
-       ((eq major-mode 'w3-mode)
-       (setq cpltxt (if (and (buffer-name)
-                             (not (string-match "Untitled" (buffer-name))))
-                        (buffer-name)
-                      (url-view-url t))
-             link (url-view-url t))
-       (org-store-link-props :type "w3" :url (url-view-url t)))
-
-       ((eq major-mode 'image-mode)
-       (setq cpltxt (concat "file:"
-                            (abbreviate-file-name buffer-file-name))
-             link cpltxt)
-       (org-store-link-props :type "image" :file buffer-file-name))
-
-       ;; In dired, store a link to the file of the current line
-       ((derived-mode-p 'dired-mode)
-       (let ((file (dired-get-filename nil t)))
-         (setq file (if file
-                        (abbreviate-file-name
-                         (expand-file-name (dired-get-filename nil t)))
-                      ;; otherwise, no file so use current directory.
-                      default-directory))
-         (setq cpltxt (concat "file:" file)
-               link cpltxt)))
-
-       ((setq search (run-hook-with-args-until-success
-                     'org-create-file-search-functions))
-       (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
-                          "::" search))
-       (setq cpltxt (or description link)))
-
-       ((and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 
'org-mode))
-       (org-with-limited-levels
-        (setq custom-id (org-entry-get nil "CUSTOM_ID"))
-        (cond
-         ;; Store a link using the target at point
-         ((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
-          (setq cpltxt
-                (concat "file:"
-                        (abbreviate-file-name
-                         (buffer-file-name (buffer-base-buffer)))
-                        "::" (match-string 1))
-                link cpltxt))
-         ((and (featurep 'org-id)
-               (or (eq org-id-link-to-org-use-id t)
-                   (and (called-interactively-p 'any)
-                        (or (eq org-id-link-to-org-use-id 
'create-if-interactive)
-                            (and (eq org-id-link-to-org-use-id
-                                     'create-if-interactive-and-no-custom-id)
-                                 (not custom-id))))
-                   (and org-id-link-to-org-use-id (org-entry-get nil "ID"))))
-          ;; Store a link using the ID at point
-          (setq link (condition-case nil
-                         (prog1 (org-id-store-link)
-                           (setq desc (or (plist-get org-store-link-plist
-                                                     :description)
-                                          "")))
-                       (error
-                        ;; Probably before first headline, link only to file
-                        (concat "file:"
-                                (abbreviate-file-name
-                                 (buffer-file-name (buffer-base-buffer))))))))
-         (t
-          ;; Just link to current headline
-          (setq cpltxt (concat "file:"
-                               (abbreviate-file-name
-                                (buffer-file-name (buffer-base-buffer)))))
-          ;; Add a context search string
-          (when (org-xor org-context-in-file-links
-                         (equal arg '(4)))
-            (let* ((element (org-element-at-point))
-                   (name (org-element-property :name element)))
-              (setq txt (cond
-                         ((org-at-heading-p) nil)
-                         (name)
-                         ((org-region-active-p)
-                          (buffer-substring (region-beginning) (region-end)))))
-              (when (or (null txt) (string-match "\\S-" txt))
-                (setq cpltxt
-                      (concat cpltxt "::"
-                              (condition-case nil
-                                  (org-make-org-heading-search-string txt)
-                                (error "")))
-                      desc (or name
-                               (nth 4 (ignore-errors (org-heading-components)))
-                               "NONE")))))
-          (when (string-match "::\\'" cpltxt)
-            (setq cpltxt (substring cpltxt 0 -2)))
-          (setq link cpltxt)))))
-
-       ((buffer-file-name (buffer-base-buffer))
-       ;; Just link to this file here.
-       (setq cpltxt (concat "file:"
-                            (abbreviate-file-name
-                             (buffer-file-name (buffer-base-buffer)))))
-       ;; Add a context string.
-       (when (org-xor org-context-in-file-links
-                      (equal arg '(4)))
-         (setq txt (if (org-region-active-p)
-                       (buffer-substring (region-beginning) (region-end))
-                     (buffer-substring (point-at-bol) (point-at-eol))))
-         ;; Only use search option if there is some text.
-         (when (string-match "\\S-" txt)
-           (setq cpltxt
-                 (concat cpltxt "::" (org-make-org-heading-search-string txt))
-                 desc "NONE")))
-       (setq link cpltxt))
-
-       ((called-interactively-p 'interactive)
-       (user-error "No method for storing a link from this buffer"))
-
-       (t (setq link nil)))
-
-      ;; We're done setting link and desc, clean up
-      (when (consp link) (setq cpltxt (car link) link (cdr link)))
-      (setq link (or link cpltxt)
-           desc (or desc cpltxt))
-      (cond ((not desc))
-           ((equal desc "NONE") (setq desc nil))
-           (t (setq desc
-                    (replace-regexp-in-string
-                     org-bracket-link-analytic-regexp
-                     (lambda (m) (or (match-string 5 m) (match-string 3 m)))
-                     desc))))
-      ;; Return the link
-      (if (not (and (or (called-interactively-p 'any)
-                       executing-kbd-macro)
-                   link))
-         (or agenda-link (and link (org-make-link-string link desc)))
-       (push (list link desc) org-stored-links)
-       (message "Stored: %s" (or desc link))
-       (when custom-id
-         (setq link (concat "file:" (abbreviate-file-name
-                                     (buffer-file-name)) "::#" custom-id))
-         (push (list link desc) org-stored-links))
-       (car org-stored-links)))))
-
-(defun org-store-link-props (&rest plist)
-  "Store link properties.
-The properties are pre-processed by extracting names, addresses
-and dates."
-  (let ((x (plist-get plist :from)))
-    (when x
-      (let ((adr (mail-extract-address-components x)))
-       (setq plist (plist-put plist :fromname (car adr)))
-       (setq plist (plist-put plist :fromaddress (nth 1 adr))))))
-  (let ((x (plist-get plist :to)))
-    (when x
-      (let ((adr (mail-extract-address-components x)))
-       (setq plist (plist-put plist :toname (car adr)))
-       (setq plist (plist-put plist :toaddress (nth 1 adr))))))
-  (let ((x (ignore-errors (date-to-time (plist-get plist :date)))))
-    (when x
-      (setq plist (plist-put plist :date-timestamp
-                            (format-time-string
-                             (org-time-stamp-format t) x)))
-      (setq plist (plist-put plist :date-timestamp-inactive
-                            (format-time-string
-                             (org-time-stamp-format t t) x)))))
-  (let ((from (plist-get plist :from))
-       (to (plist-get plist :to)))
-    (when (and from to org-from-is-user-regexp)
-      (setq plist
-           (plist-put plist :fromto
-                      (if (string-match org-from-is-user-regexp from)
-                          (concat "to %t")
-                        (concat "from %f"))))))
-  (setq org-store-link-plist plist))
-
-(defun org-add-link-props (&rest plist)
-  "Add these properties to the link property list."
-  (let (key value)
-    (while plist
-      (setq key (pop plist) value (pop plist))
-      (setq org-store-link-plist
-           (plist-put org-store-link-plist key value)))))
-
-(defun org-email-link-description (&optional fmt)
-  "Return the description part of an email link.
-This takes information from `org-store-link-plist' and formats it
-according to FMT (default from `org-email-link-description-format')."
-  (setq fmt (or fmt org-email-link-description-format))
-  (let* ((p org-store-link-plist)
-        (to (plist-get p :toaddress))
-        (from (plist-get p :fromaddress))
-        (table
-         (list
-          (cons "%c" (plist-get p :fromto))
-          (cons "%F" (plist-get p :from))
-          (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) 
"?"))
-          (cons "%T" (plist-get p :to))
-          (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
-          (cons "%s" (plist-get p :subject))
-          (cons "%d" (plist-get p :date))
-          (cons "%m" (plist-get p :message-id)))))
-    (when (string-match "%c" fmt)
-      ;; Check if the user wrote this message
-      (if (and org-from-is-user-regexp from to
-              (save-match-data (string-match org-from-is-user-regexp from)))
-         (setq fmt (replace-match "to %t" t t fmt))
-       (setq fmt (replace-match "from %f" t t fmt))))
-    (org-replace-escapes fmt table)))
-
-(defun org-make-org-heading-search-string (&optional string)
-  "Make search string for the current headline or STRING."
-  (let ((s (or string
-              (and (derived-mode-p 'org-mode)
-                   (save-excursion
-                     (org-back-to-heading t)
-                     (org-element-property :raw-value 
(org-element-at-point))))))
-       (lines org-context-in-file-links))
-    (unless string (setq s (concat "*" s))) ;Add * for headlines
-    (setq s (replace-regexp-in-string "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" "" 
s))
-    (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 (split-string s) " ")))
-
-(defconst org-link-escape-chars
-  ;;%20 %5B %5D %25
-  '(?\s ?\[ ?\] ?%)
-  "List of characters that should be escaped in a link when stored to Org.
-This is the list that is used for internal purposes.")
-
-(defun org-make-link-string (link &optional description)
-  "Make a link with brackets, consisting of LINK and DESCRIPTION."
-  (unless (org-string-nw-p link) (error "Empty link"))
-  (let ((uri (cond ((string-match org-link-types-re link)
-                   (concat (match-string 1 link)
-                           (org-link-escape (substring link (match-end 1)))))
-                  ((or (file-name-absolute-p link)
-                       (string-match-p "\\`\\.\\.?/" link))
-                   (org-link-escape link))
-                  ;; For readability, do not encode space characters
-                  ;; in fuzzy links.
-                  (t (org-link-escape link (remq ?\s org-link-escape-chars)))))
-       (description
-        (and (org-string-nw-p description)
-             ;; Remove brackets from description, as they are fatal.
-             (replace-regexp-in-string
-              "[][]" (lambda (m) (if (equal "[" m) "{" "}"))
-              (org-trim description)))))
-    (format "[[%s]%s]"
-           uri
-           (if description (format "[%s]" description) ""))))
-
-(defun org-link-escape (text &optional table merge)
-  "Return percent escaped representation of TEXT.
-TEXT is a string with the text to escape.
-Optional argument TABLE is a list with characters that should be
-escaped.  When nil, `org-link-escape-chars' is used.
-If optional argument MERGE is set, merge TABLE into
-`org-link-escape-chars'."
-  (let ((characters-to-encode
-        (cond ((null table) org-link-escape-chars)
-              (merge (append org-link-escape-chars table))
-              (t table))))
-    (mapconcat
-     (lambda (c)
-       (if (or (memq c characters-to-encode)
-              (and org-url-hexify-p (or (< c 32) (> c 126))))
-          (mapconcat (lambda (e) (format "%%%.2X" e))
-                     (or (encode-coding-char c 'utf-8)
-                         (error "Unable to percent escape character: %c" c))
-                     "")
-        (char-to-string c)))
-     text "")))
-
-(defun org-link-unescape (str)
-  "Unhex hexified Unicode parts in string STR.
-E.g. `%C3%B6' becomes the german o-Umlaut.  This is the
-reciprocal of `org-link-escape', which see."
-  (if (org-string-nw-p str)
-      (replace-regexp-in-string
-       "\\(%[0-9A-Za-z]\\{2\\}\\)+" #'org-link-unescape-compound str t t)
-    str))
-
-(defun org-link-unescape-compound (hex)
-  "Unhexify Unicode hex-chars.  E.g. `%C3%B6' is the German o-Umlaut.
-Note: this function also decodes single byte encodings like
-`%E1' (a-acute) if not followed by another `%[A-F0-9]{2}' group."
-  (save-match-data
-    (let* ((bytes (cdr (split-string hex "%")))
-          (ret "")
-          (eat 0)
-          (sum 0))
-      (while bytes
-       (let* ((val (string-to-number (pop bytes) 16))
-              (shift-xor
-               (if (= 0 eat)
-                   (cond
-                    ((>= val 252) (cons 6 252))
-                    ((>= val 248) (cons 5 248))
-                    ((>= val 240) (cons 4 240))
-                    ((>= val 224) (cons 3 224))
-                    ((>= val 192) (cons 2 192))
-                    (t (cons 0 0)))
-                 (cons 6 128))))
-         (when (>= val 192) (setq eat (car shift-xor)))
-         (setq val (logxor val (cdr shift-xor)))
-         (setq sum (+ (ash sum (car shift-xor)) val))
-         (when (> eat 0) (setq eat (- eat 1)))
-         (cond
-          ((= 0 eat)                   ;multi byte
-           (setq ret (concat ret (char-to-string sum)))
-           (setq sum 0))
-          ((not bytes)                 ; single byte(s)
-           (setq ret (org-link-unescape-single-byte-sequence hex))))))
-      ret)))
-
-(defun org-link-unescape-single-byte-sequence (hex)
-  "Unhexify hex-encoded single byte character sequences."
-  (mapconcat (lambda (byte)
-              (char-to-string (string-to-number byte 16)))
-            (cdr (split-string hex "%")) ""))
-
-(defun org-fixup-message-id-for-http (s)
-  "Replace special characters in a message id, so it can be used in an http 
query."
-  (when (string-match "%" s)
-    (setq s (mapconcat (lambda (c)
-                        (if (eq c ?%)
-                            "%25"
-                          (char-to-string c)))
-                      s "")))
-  (while (string-match "<" s)
-    (setq s (replace-match "%3C" t t s)))
-  (while (string-match ">" s)
-    (setq s (replace-match "%3E" t t s)))
-  (while (string-match "@" s)
-    (setq s (replace-match "%40" t t s)))
-  s)
+(defun org--file-default-apps ()
+  "Return the default applications for this operating system."
+  (pcase system-type
+    (`darwin org-file-apps-macos)
+    (`windows-nt org-file-apps-windowsnt)
+    (_ org-file-apps-gnu)))
 
-(defun org-link-prettify (link)
-  "Return a human-readable representation of LINK.
-The car of LINK must be a raw link.
-The cdr of LINK must be either a link description or nil."
-  (let ((desc (or (cadr link) "<no description>")))
-    (concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
-           "<" (car link) ">")))
+(defun org--file-apps-entry-dlink-p (entry)
+  "Non-nil if ENTRY should be matched against the link by `org-open-file'.
 
-;;;###autoload
-(defun org-insert-link-global ()
-  "Insert a link like Org mode does.
-This command can be called in any mode to insert a link in Org syntax."
-  (interactive)
-  (org-load-modules-maybe)
-  (org-run-like-in-org-mode 'org-insert-link))
-
-(defun org-insert-all-links (arg &optional pre post)
-  "Insert all links in `org-stored-links'.
-When a universal prefix, do not delete the links from `org-stored-links'.
-When `ARG' is a number, insert the last N link(s).
-`PRE' and `POST' are optional arguments to define a string to
-prepend or to append."
-  (interactive "P")
-  (let ((org-keep-stored-link-after-insertion (equal arg '(4)))
-       (links (copy-sequence org-stored-links))
-       (pr (or pre "- "))
-       (po (or post "\n"))
-       (cnt 1) l)
-    (if (null org-stored-links)
-       (message "No link to insert")
-      (while (and (or (listp arg) (>= arg cnt))
-                 (setq l (if (listp arg)
-                             (pop links)
-                           (pop org-stored-links))))
-       (setq cnt (1+ cnt))
-       (insert pr)
-       (org-insert-link nil (car l) (or (cadr l) "<no description>"))
-       (insert po)))))
-
-(defun org-insert-last-stored-link (arg)
-  "Insert the last link stored in `org-stored-links'."
-  (interactive "p")
-  (org-insert-all-links arg "" "\n"))
-
-(defun org-link-fontify-links-to-this-file ()
-  "Fontify links to the current file in `org-stored-links'."
-  (let ((f (buffer-file-name)) a b)
-    (setq a (mapcar (lambda(l)
-                     (let ((ll (car l)))
-                       (when (and (string-match "^file:\\(.+\\)::" ll)
-                                  (equal f (expand-file-name (match-string 1 
ll))))
-                         ll)))
-                   org-stored-links))
-    (when (featurep 'org-id)
-      (setq b (mapcar (lambda(l)
-                       (let ((ll (car l)))
-                         (when (and (string-match "^id:\\(.+\\)$" ll)
-                                    (equal f (expand-file-name
-                                              (or (org-id-find-id-file
-                                                   (match-string 1 ll)) ""))))
-                           ll)))
-                     org-stored-links)))
-    (mapcar (lambda(l)
-             (put-text-property 0 (length l) 'face 'font-lock-comment-face l))
-           (delq nil (append a b)))))
-
-(defvar org--links-history nil)
-(defun org-insert-link (&optional complete-file link-location 
default-description)
-  "Insert a link.  At the prompt, enter the link.
-
-Completion can be used to insert any of the link protocol prefixes in use.
-
-The history can be used to select a link previously stored with
-`org-store-link'.  When the empty string is entered (i.e. if you just
-press `RET' at the prompt), the link defaults to the most recently
-stored link.  As `SPC' triggers completion in the minibuffer, you need to
-use `M-SPC' or `C-q SPC' to force the insertion of a space character.
-
-You will also be prompted for a description, and if one is given, it will
-be displayed in the buffer instead of the link.
-
-If there is already a link at point, this command will allow you to edit
-link and description parts.
-
-With a `\\[universal-argument]' prefix, prompts for a file to link to.  The \
-file name can be
-selected using completion.  The path to the file will be relative to the
-current directory if the file is in the current directory or a subdirectory.
-Otherwise, the link will be the absolute path as completed in the minibuffer
-\(i.e. normally ~/path/to/file).  You can configure this behavior using the
-option `org-link-file-path-type'.
-
-With a `\\[universal-argument] \\[universal-argument]' prefix, enforce an \
-absolute path even if the file is in
-the current directory or below.
-
-A `\\[universal-argument] \\[universal-argument] \\[universal-argument]' \
-prefix negates `org-keep-stored-link-after-insertion'.
-
-If the LINK-LOCATION parameter is non-nil, this value will be used as
-the link location instead of reading one interactively.
-
-If the DEFAULT-DESCRIPTION parameter is non-nil, this value will
-be used as the default description.  Otherwise, if
-`org-make-link-description-function' is non-nil, this function
-will be called with the link target, and the result will be the
-default link description."
-  (interactive "P")
-  (let* ((wcf (current-window-configuration))
-        (origbuf (current-buffer))
-        (region (when (org-region-active-p)
-                  (buffer-substring (region-beginning) (region-end))))
-        (remove (and region (list (region-beginning) (region-end))))
-        (desc region)
-        (link link-location)
-        (abbrevs org-link-abbrev-alist-local)
-        entry all-prefixes auto-desc)
-    (cond
-     (link-location)                 ; specified by arg, just use it.
-     ((org-in-regexp org-bracket-link-regexp 1)
-      ;; We do have a link at point, and we are going to edit it.
-      (setq remove (list (match-beginning 0) (match-end 0)))
-      (setq desc (when (match-end 3) (match-string-no-properties 3)))
-      (setq link (read-string "Link: "
-                             (org-link-unescape
-                              (match-string-no-properties 1)))))
-     ((or (org-in-regexp org-angle-link-re)
-         (org-in-regexp org-plain-link-re))
-      ;; Convert to bracket link
-      (setq remove (list (match-beginning 0) (match-end 0))
-           link (read-string "Link: "
-                             (org-unbracket-string "<" ">" (match-string 0)))))
-     ((member complete-file '((4) (16)))
-      ;; Completing read for file names.
-      (setq link (org-file-complete-link complete-file)))
-     (t
-      ;; Read link, with completion for stored links.
-      (org-link-fontify-links-to-this-file)
-      (org-switch-to-buffer-other-window "*Org Links*")
-      (with-current-buffer "*Org Links*"
-       (erase-buffer)
-       (insert "Insert a link.
-Use TAB to complete link prefixes, then RET for type-specific completion 
support\n")
-       (when org-stored-links
-         (insert "\nStored links are available with <up>/<down> or M-p/n (most 
recent with RET):\n\n")
-         (insert (mapconcat 'org-link-prettify
-                            (reverse org-stored-links) "\n")))
-       (goto-char (point-min)))
-      (let ((cw (selected-window)))
-       (select-window (get-buffer-window "*Org Links*" 'visible))
-       (with-current-buffer "*Org Links*" (setq truncate-lines t))
-       (unless (pos-visible-in-window-p (point-max))
-         (org-fit-window-to-buffer))
-       (and (window-live-p cw) (select-window cw)))
-      (setq all-prefixes (append (mapcar 'car abbrevs)
-                                (mapcar 'car org-link-abbrev-alist)
-                                (org-link-types)))
-      (unwind-protect
-         ;; Fake a link history, containing the stored links.
-         (let ((org--links-history
-                (append (mapcar #'car org-stored-links)
-                        org-insert-link-history)))
-           (setq link
-                 (org-completing-read
-                  "Link: "
-                  (append
-                   (mapcar (lambda (x) (concat x ":")) all-prefixes)
-                   (mapcar #'car org-stored-links))
-                  nil nil nil
-                  'org--links-history
-                  (caar org-stored-links)))
-           (unless (org-string-nw-p link) (user-error "No link selected"))
-           (dolist (l org-stored-links)
-             (when (equal link (cadr l))
-               (setq link (car l))
-               (setq auto-desc t)))
-           (when (or (member link all-prefixes)
-                     (and (equal ":" (substring link -1))
-                          (member (substring link 0 -1) all-prefixes)
-                          (setq link (substring link 0 -1))))
-             (setq link (with-current-buffer origbuf
-                          (org-link-try-special-completion link)))))
-       (set-window-configuration wcf)
-       (kill-buffer "*Org Links*"))
-      (setq entry (assoc link org-stored-links))
-      (or entry (push link org-insert-link-history))
-      (setq desc (or desc (nth 1 entry)))))
-
-    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
-                  (not org-keep-stored-link-after-insertion))
-      (setq org-stored-links (delq (assoc link org-stored-links)
-                                  org-stored-links)))
-
-    (when (and (string-match org-plain-link-re link)
-              (not (string-match org-ts-regexp link)))
-      ;; URL-like link, normalize the use of angular brackets.
-      (setq link (org-unbracket-string "<" ">" link)))
-
-    ;; Check if we are linking to the current file with a search
-    ;; option If yes, simplify the link by using only the search
-    ;; option.
-    (when (and buffer-file-name
-              (let ((case-fold-search nil))
-                (string-match "\\`file:\\(.+?\\)::" link)))
-      (let ((path (match-string-no-properties 1 link))
-           (search (substring-no-properties link (match-end 0))))
-       (save-match-data
-         (when (equal (file-truename buffer-file-name) (file-truename path))
-           ;; We are linking to this same file, with a search option
-           (setq link search)))))
-
-    ;; Check if we can/should use a relative path.  If yes, simplify
-    ;; the link.
-    (let ((case-fold-search nil))
-      (when (string-match "\\`\\(file\\|docview\\):" link)
-       (let* ((type (match-string-no-properties 0 link))
-              (path-start (match-end 0))
-              (search (and (string-match "::\\(.*\\)\\'" link)
-                           (match-string 1 link)))
-              (path
-               (if search
-                   (substring-no-properties
-                    link path-start (match-beginning 0))
-                 (substring-no-properties link (match-end 0))))
-              (origpath path))
-         (cond
-          ((or (eq org-link-file-path-type 'absolute)
-               (equal complete-file '(16)))
-           (setq path (abbreviate-file-name (expand-file-name path))))
-          ((eq org-link-file-path-type 'noabbrev)
-           (setq path (expand-file-name path)))
-          ((eq org-link-file-path-type 'relative)
-           (setq path (file-relative-name path)))
-          (t
-           (save-match-data
-             (if (string-match (concat "^" (regexp-quote
-                                            (expand-file-name
-                                             (file-name-as-directory
-                                              default-directory))))
-                               (expand-file-name path))
-                 ;; We are linking a file with relative path name.
-                 (setq path (substring (expand-file-name path)
-                                       (match-end 0)))
-               (setq path (abbreviate-file-name (expand-file-name path)))))))
-         (setq link (concat type path (and search (concat "::" search))))
-         (when (equal desc origpath)
-           (setq desc path)))))
-
-    (unless auto-desc
-      (let ((initial-input
-            (cond
-             (default-description)
-             ((not org-make-link-description-function) desc)
-             (t (condition-case nil
-                    (funcall org-make-link-description-function link desc)
-                  (error
-                   (message "Can't get link description from `%s'"
-                            (symbol-name org-make-link-description-function))
-                   (sit-for 2)
-                   nil))))))
-       (setq desc (read-string "Description: " initial-input))))
-
-    (unless (string-match "\\S-" desc) (setq desc nil))
-    (when remove (apply 'delete-region remove))
-    (insert (org-make-link-string link desc))
-    ;; Redisplay so as the new link has proper invisible characters.
-    (sit-for 0)))
-
-(defun org-link-try-special-completion (type)
-  "If there is completion support for link type TYPE, offer it."
-  (let ((fun (org-link-get-parameter type :complete)))
-    (if (functionp fun)
-       (funcall fun)
-      (read-string "Link (no completion support): " (concat type ":")))))
-
-(defun org-file-complete-link (&optional arg)
-  "Create a file link using completion."
-  (let ((file (read-file-name "File: "))
-       (pwd (file-name-as-directory (expand-file-name ".")))
-       (pwd1 (file-name-as-directory (abbreviate-file-name
-                                      (expand-file-name ".")))))
-    (cond ((equal arg '(16))
-          (concat "file:"
-                  (abbreviate-file-name (expand-file-name file))))
-         ((string-match
-           (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
-          (concat "file:" (match-string 1 file)))
-         ((string-match
-           (concat "^" (regexp-quote pwd) "\\(.+\\)")
-           (expand-file-name file))
-          (concat "file:"
-                  (match-string 1 (expand-file-name file))))
-         (t (concat "file:" file)))))
-
-(defun org-completing-read (&rest args)
-  "Completing-read with SPACE being a normal character."
-  (let ((enable-recursive-minibuffers t)
-       (minibuffer-local-completion-map
-        (copy-keymap minibuffer-local-completion-map)))
-    (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
-    (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
-    (org-defkey minibuffer-local-completion-map (kbd "C-c !")
-               'org-time-stamp-inactive)
-    (apply #'completing-read args)))
-
-;;; Opening/following a link
-
-(defvar org-link-search-failed nil)
-
-(defvar org-open-link-functions nil
-  "Hook for functions finding a plain text link.
-These functions must take a single argument, the link content.
-They will be called for links that look like [[link text][description]]
-when LINK TEXT does not have a protocol like \"http:\" and does not look
-like a filename (e.g. \"./blue.png\").
-
-These functions will be called *before* Org attempts to resolve the
-link by doing text searches in the current buffer - so if you want a
-link \"[[target]]\" to still find \"<<target>>\", your function should
-handle this as a special case.
-
-When the function does handle the link, it must return a non-nil value.
-If it decides that it is not responsible for this link, it must return
-nil to indicate that that Org can continue with other options like
-exact and fuzzy text search.")
-
-(defun org-next-link (&optional search-backward)
-  "Move forward to the next link.
-If the link is in hidden text, expose it."
-  (interactive "P")
-  (when (and org-link-search-failed (eq this-command last-command))
-    (goto-char (point-min))
-    (message "Link search wrapped back to beginning of buffer"))
-  (setq org-link-search-failed nil)
-  (let* ((pos (point))
-        (ct (org-context))
-        (a (assq :link ct))
-        (srch-fun (if search-backward 're-search-backward 're-search-forward)))
-    (cond (a (goto-char (nth (if search-backward 1 2) a)))
-         ((looking-at org-any-link-re)
-          ;; Don't stay stuck at link without an org-link face
-          (forward-char (if search-backward -1 1))))
-    (if (funcall srch-fun org-any-link-re nil t)
-       (progn
-         (goto-char (match-beginning 0))
-         (when (org-invisible-p) (org-show-context)))
-      (goto-char pos)
-      (setq org-link-search-failed t)
-      (message "No further link found"))))
+It assumes that is the case when the entry uses a regular
+expression which has at least one grouping construct and the
+action is either a Lisp form or a command string containing
+\"%1\", i.e., using at least one subexpression match as
+a parameter."
+  (pcase entry
+    (`(,selector . ,action)
+     (and (stringp selector)
+         (> (regexp-opt-depth selector) 0)
+         (or (and (stringp action)
+                  (string-match "%[0-9]" action))
+             (consp action))))
+    (_ nil)))
 
-(defun org-previous-link ()
-  "Move backward to the previous link.
-If the link is in hidden text, expose it."
-  (interactive)
-  (funcall 'org-next-link t))
+(defun org--file-apps-regexp-alist (list &optional add-auto-mode)
+  "Convert extensions to regular expressions in the cars of LIST.
 
-(defun org-translate-link (s)
-  "Translate a link string if a translation function has been defined."
-  (with-temp-buffer
-    (insert (org-trim s))
-    (org-trim (org-element-interpret-data (org-element-context)))))
+Also, weed out any non-string entries, because the return value
+is used only for regexp matching.
 
-(defun org-translate-link-from-planner (type path)
-  "Translate a link from Emacs Planner syntax so that Org can follow it.
-This is still an experimental function, your mileage may vary."
-  (cond
-   ((member type '("http" "https" "news" "ftp"))
-    ;; standard Internet links are the same.
-    nil)
-   ((and (equal type "irc") (string-match "^//" path))
-    ;; Planner has two / at the beginning of an irc link, we have 1.
-    ;; We should have zero, actually....
-    (setq path (substring path 1)))
-   ((and (equal type "lisp") (string-match "^/" path))
-    ;; Planner has a slash, we do not.
-    (setq type "elisp" path (substring path 1)))
-   ((string-match "^//\\(.*\\)/\\(<.*>\\)$" path)
-    ;; A typical message link.  Planner has the id after the final slash,
-    ;; we separate it with a hash mark
-    (setq path (concat (match-string 1 path) "#"
-                      (org-unbracket-string "<" ">" (match-string 2 path))))))
-  (cons type path))
+When ADD-AUTO-MODE is non-nil, make all matches in `auto-mode-alist'
+point to the symbol `emacs', indicating that the file should be
+opened in Emacs."
+  (append
+   (delq nil
+        (mapcar (lambda (x)
+                  (unless (not (stringp (car x)))
+                    (if (string-match "\\W" (car x))
+                        x
+                      (cons (concat "\\." (car x) "\\'") (cdr x)))))
+                list))
+   (when add-auto-mode
+     (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
 
-(defun org-find-file-at-mouse (ev)
-  "Open file link or URL at mouse."
-  (interactive "e")
-  (mouse-set-point ev)
-  (org-open-at-point 'in-emacs))
+;;;###autoload
+(defun org-open-file (path &optional in-emacs line search)
+  "Open the file at PATH.
+First, this expands any special file name abbreviations.  Then the
+configuration variable `org-file-apps' is checked if it contains an
+entry for this file type, and if yes, the corresponding command is launched.
 
-(defun org-open-at-mouse (ev)
-  "Open file link or URL at mouse.
-See the docstring of `org-open-file' for details."
-  (interactive "e")
-  (mouse-set-point ev)
-  (when (eq major-mode 'org-agenda-mode)
-    (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
-  (org-open-at-point))
+If no application is found, Emacs simply visits the file.
 
-(defvar org-window-config-before-follow-link nil
-  "The window configuration before following a link.
-This is saved in case the need arises to restore it.")
+With optional prefix argument IN-EMACS, Emacs will visit the file.
+With a double \\[universal-argument] \\[universal-argument] \
+prefix arg, Org tries to avoid opening in Emacs
+and to use an external application to visit the file.
+
+Optional LINE specifies a line to go to, optional SEARCH a string
+to search for.  If LINE or SEARCH is given, the file will be
+opened in Emacs, unless an entry from `org-file-apps' that makes
+use of groups in a regexp matches.
+
+If you want to change the way frames are used when following a
+link, please customize `org-link-frame-setup'.
+
+If the file does not exist, throw an error."
+  (let* ((file (if (equal path "") buffer-file-name
+                (substitute-in-file-name (expand-file-name path))))
+        (file-apps (append org-file-apps (org--file-default-apps)))
+        (apps (cl-remove-if #'org--file-apps-entry-dlink-p file-apps))
+        (apps-dlink (cl-remove-if-not #'org--file-apps-entry-dlink-p
+                                      file-apps))
+        (remp (and (assq 'remote apps) (file-remote-p file)))
+        (dirp (unless remp (file-directory-p file)))
+        (file (if (and dirp org-open-directory-means-index-dot-org)
+                  (concat (file-name-as-directory file) "index.org")
+                file))
+        (a-m-a-p (assq 'auto-mode apps))
+        (dfile (downcase file))
+        ;; Reconstruct the original link from the PATH, LINE and
+        ;; SEARCH args.
+        (link (cond (line (concat file "::" (number-to-string line)))
+                    (search (concat file "::" search))
+                    (t file)))
+        (dlink (downcase link))
+        (ext
+         (and (string-match "\\`.*?\\.\\([a-zA-Z0-9]+\\(\\.gz\\)?\\)\\'" dfile)
+              (match-string 1 dfile)))
+        (save-position-maybe
+         (let ((old-buffer (current-buffer))
+               (old-pos (point))
+               (old-mode major-mode))
+           (lambda ()
+             (and (derived-mode-p 'org-mode)
+                  (eq old-mode 'org-mode)
+                  (or (not (eq old-buffer (current-buffer)))
+                      (not (eq old-pos (point))))
+                  (org-mark-ring-push old-pos old-buffer)))))
+        cmd link-match-data)
+    (cond
+     ((member in-emacs '((16) system))
+      (setq cmd (cdr (assq 'system apps))))
+     (in-emacs (setq cmd 'emacs))
+     (t
+      (setq cmd (or (and remp (cdr (assq 'remote apps)))
+                   (and dirp (cdr (assq 'directory apps)))
+                   ;; First, try matching against apps-dlink if we
+                   ;; get a match here, store the match data for
+                   ;; later.
+                   (let ((match (assoc-default dlink apps-dlink
+                                               'string-match)))
+                     (if match
+                         (progn (setq link-match-data (match-data))
+                                match)
+                       (progn (setq in-emacs (or in-emacs line search))
+                              nil))) ; if we have no match in apps-dlink,
+                                       ; always open the file in emacs if line 
or search
+                                       ; is given (for backwards compatibility)
+                   (assoc-default dfile
+                                  (org--file-apps-regexp-alist apps a-m-a-p)
+                                  'string-match)
+                   (cdr (assoc ext apps))
+                   (cdr (assq t apps))))))
+    (when (eq cmd 'system)
+      (setq cmd (cdr (assq 'system apps))))
+    (when (eq cmd 'default)
+      (setq cmd (cdr (assoc t apps))))
+    (when (eq cmd 'mailcap)
+      (require 'mailcap)
+      (mailcap-parse-mailcaps)
+      (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
+            (command (mailcap-mime-info mime-type)))
+       (if (stringp command)
+           (setq cmd command)
+         (setq cmd 'emacs))))
+    (when (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
+              (not (file-exists-p file))
+              (not org-open-non-existing-files))
+      (user-error "No such file: %s" file))
+    (cond
+     ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
+      ;; Remove quotes around the file name - we'll use shell-quote-argument.
+      (while (string-match "['\"]%s['\"]" cmd)
+       (setq cmd (replace-match "%s" t t cmd)))
+      (setq cmd (replace-regexp-in-string
+                "%s"
+                (shell-quote-argument (convert-standard-filename file))
+                cmd
+                nil t))
+
+      ;; Replace "%1", "%2" etc. in command with group matches from regex
+      (save-match-data
+       (let ((match-index 1)
+             (number-of-groups (- (/ (length link-match-data) 2) 1)))
+         (set-match-data link-match-data)
+         (while (<= match-index number-of-groups)
+           (let ((regex (concat "%" (number-to-string match-index)))
+                 (replace-with (match-string match-index dlink)))
+             (while (string-match regex cmd)
+               (setq cmd (replace-match replace-with t t cmd))))
+           (setq match-index (+ match-index 1)))))
+
+      (save-window-excursion
+       (message "Running %s...done" cmd)
+       (start-process-shell-command cmd nil cmd)
+       (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
+     ((or (stringp cmd)
+         (eq cmd 'emacs))
+      (funcall (cdr (assq 'file org-link-frame-setup)) file)
+      (widen)
+      (cond (line (org-goto-line line)
+                 (when (derived-mode-p 'org-mode) (org-reveal)))
+           (search (condition-case err
+                       (org-link-search search)
+                     ;; Save position before error-ing out so user
+                     ;; can easily move back to the original buffer.
+                     (error (funcall save-position-maybe)
+                            (error (nth 1 err)))))))
+     ((functionp cmd)
+      (save-match-data
+       (set-match-data link-match-data)
+       (condition-case nil
+           (funcall cmd file link)
+         ;; FIXME: Remove this check when most default installations
+         ;; of Emacs have at least Org 9.0.
+         ((debug wrong-number-of-arguments wrong-type-argument
+                 invalid-function)
+          (user-error "Please see Org News for version 9.0 about \
+`org-file-apps'--Lisp error: %S" cmd)))))
+     ((consp cmd)
+      ;; FIXME: Remove this check when most default installations of
+      ;; Emacs have at least Org 9.0.  Heads-up instead of silently
+      ;; fall back to `org-link-frame-setup' for an old usage of
+      ;; `org-file-apps' with sexp instead of a function for `cmd'.
+      (user-error "Please see Org News for version 9.0 about \
+`org-file-apps'--Error: Deprecated usage of %S" cmd))
+     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
+    (funcall save-position-maybe)))
 
 ;;;###autoload
 (defun org-open-at-point-global ()
-  "Follow a link or time-stamp like Org mode does.
-This command can be called in any mode to follow an external link
-or a time-stamp that has Org mode syntax.  Its behavior is
-undefined when called on internal links (e.g., fuzzy links).
-Raise an error when there is nothing to follow."
+  "Follow a link or a time-stamp like Org mode does.
+Also follow links and emails as seen by `thing-at-point'.
+This command can be called in any mode to follow an external
+link or a time-stamp that has Org mode syntax.  Its behavior
+is undefined when called on internal links like fuzzy links.
+Raise a user error when there is nothing to follow."
   (interactive)
-  (cond ((org-in-regexp org-any-link-re)
-        (org-open-link-from-string (match-string-no-properties 0)))
-       ((or (org-in-regexp org-ts-regexp-both nil t)
-            (org-in-regexp org-tsr-regexp-both nil t))
-        (org-follow-timestamp-link))
-       (t (user-error "No link found"))))
-
-;;;###autoload
-(defun org-open-link-from-string (s &optional arg reference-buffer)
-  "Open a link in the string S, as if it was in Org mode."
-  (interactive "sLink: \nP")
-  (let ((reference-buffer (or reference-buffer (current-buffer))))
-    (with-temp-buffer
-      (let ((org-inhibit-startup (not reference-buffer)))
-       (org-mode)
-       (insert s)
-       (goto-char (point-min))
-       (when reference-buffer
-         (setq org-link-abbrev-alist-local
-               (with-current-buffer reference-buffer
-                 org-link-abbrev-alist-local)))
-       (org-open-at-point arg reference-buffer)))))
+  (let ((tap-url (thing-at-point 'url))
+       (tap-email (thing-at-point 'email)))
+    (cond ((org-in-regexp org-link-any-re)
+          (org-link-open-from-string (match-string-no-properties 0)))
+         ((or (org-in-regexp org-ts-regexp-both nil t)
+              (org-in-regexp org-tsr-regexp-both nil t))
+          (org-follow-timestamp-link))
+         (tap-url (org-link-open-from-string tap-url))
+         (tap-email (org-link-open-from-string
+                     (concat "mailto:"; tap-email)))
+         (t (user-error "No link found")))))
 
 (defvar org-open-at-point-functions nil
   "Hook that is run when following a link at point.
@@ -10526,62 +8609,7 @@ Functions in this hook must return t if they identify 
and follow
 a link at point.  If they don't find anything interesting at point,
 they must return nil.")
 
-(defvar org-link-search-inhibit-query nil)
-(defvar clean-buffer-list-kill-buffer-names) ;Defined in midnight.el
-(defun org--open-doi-link (path)
-  "Open a \"doi\" type link.
-PATH is a the path to search for, as a string."
-  (browse-url (url-encode-url (concat org-doi-server-url path))))
-
-(defun org--open-elisp-link (path)
-  "Open a \"elisp\" type link.
-PATH is the sexp to evaluate, as a string."
-  (let ((cmd path))
-    (if (or (and (org-string-nw-p
-                 org-confirm-elisp-link-not-regexp)
-                (string-match-p org-confirm-elisp-link-not-regexp cmd))
-           (not org-confirm-elisp-link-function)
-           (funcall org-confirm-elisp-link-function
-                    (format "Execute \"%s\" as elisp? "
-                            (org-add-props cmd nil 'face 'org-warning))))
-       (message "%s => %s" cmd
-                (if (eq (string-to-char cmd) ?\()
-                    (eval (read cmd))
-                  (call-interactively (read cmd))))
-      (user-error "Abort"))))
-
-(defun org--open-help-link (path)
-  "Open a \"help\" type link.
-PATH is a symbol name, as a string."
-  (pcase (intern path)
-    ((and (pred fboundp) variable) (describe-function variable))
-    ((and (pred boundp) function) (describe-variable function))
-    (name (user-error "Unknown function or variable: %s" name))))
-
-(defun org--open-shell-link (path)
-  "Open a \"shell\" type link.
-PATH is the command to execute, as a string."
-  (let ((buf (generate-new-buffer "*Org Shell Output*"))
-       (cmd path))
-    (if (or (and (org-string-nw-p
-                 org-confirm-shell-link-not-regexp)
-                (string-match
-                 org-confirm-shell-link-not-regexp cmd))
-           (not org-confirm-shell-link-function)
-           (funcall org-confirm-shell-link-function
-                    (format "Execute \"%s\" in shell? "
-                            (org-add-props cmd nil
-                              'face 'org-warning))))
-       (progn
-         (message "Executing %s" cmd)
-         (shell-command cmd buf)
-         (when (featurep 'midnight)
-           (setq clean-buffer-list-kill-buffer-names
-                 (cons (buffer-name buf)
-                       clean-buffer-list-kill-buffer-names))))
-      (user-error "Abort"))))
-
-(defun org-open-at-point (&optional arg reference-buffer)
+(defun org-open-at-point (&optional arg)
   "Open link, timestamp, footnote or tags at point.
 
 When point is on a link, follow it.  Normally, files will be
@@ -10601,153 +8629,101 @@ When point is on a headline, display a list of every 
link in the
 entry, so it is possible to pick one, or all, of them.  If point
 is on a tag, call `org-tags-view' instead.
 
-When optional argument REFERENCE-BUFFER is non-nil, it should
-specify a buffer from where the link search should happen.  This
-is used internally by `org-open-link-from-string'.
-
-On top of syntactically correct links, this function will also
-try to open links and time-stamps in comments, example
-blocks... i.e., whenever point is on something looking like
-a timestamp or a link."
+On top of syntactically correct links, this function also tries
+to open links and time-stamps in comments, node properties, and
+keywords if point is on something looking like a timestamp or
+a link."
   (interactive "P")
-  ;; On a code block, open block's results.
-  (unless (call-interactively 'org-babel-open-src-block-result)
-    (org-load-modules-maybe)
-    (setq org-window-config-before-follow-link (current-window-configuration))
-    (org-remove-occur-highlights nil nil t)
-    (unless (run-hook-with-args-until-success 'org-open-at-point-functions)
-      (let* ((context
-             ;; Only consider supported types, even if they are not
-             ;; the closest one.
-             (org-element-lineage
-              (org-element-context)
-              '(clock footnote-definition footnote-reference headline
-                      inlinetask link timestamp)
-              t))
-            (type (org-element-type context))
-            (value (org-element-property :value context)))
-       (cond
-        ;; On a headline or an inlinetask, but not on a timestamp,
-        ;; a link, a footnote reference.
-        ((memq type '(headline inlinetask))
-         (org-match-line org-complex-heading-regexp)
-         (if (and (match-beginning 5)
-                  (>= (point) (match-beginning 5))
-                  (< (point) (match-end 5)))
-             ;; On tags.
-             (org-tags-view arg (substring (match-string 5) 0 -1))
-           ;; Not on tags.
-           (pcase (org-offer-links-in-entry (current-buffer) (point) arg)
-             (`(nil . ,_)
-              (require 'org-attach)
-              (org-attach-reveal 'if-exists))
-             (`(,links . ,links-end)
-              (dolist (link (if (stringp links) (list links) links))
-                (search-forward link nil links-end)
-                (goto-char (match-beginning 0))
-                (org-open-at-point))))))
-        ;; On a footnote reference or at definition's label.
-        ((or (eq type 'footnote-reference)
-             (and (eq type 'footnote-definition)
-                  (save-excursion
-                    ;; Do not validate action when point is on the
-                    ;; spaces right after the footnote label, in
-                    ;; order to be on par with behavior on links.
-                    (skip-chars-forward " \t")
-                    (let ((begin
-                           (org-element-property :contents-begin context)))
-                      (if begin (< (point) begin)
-                        (= (org-element-property :post-affiliated context)
-                           (line-beginning-position)))))))
-         (org-footnote-action))
-        ;; No valid context.  Ignore catch-all types like `headline'.
-        ;; If point is on something looking like a link or
-        ;; a time-stamp, try opening it.  It may be useful in
-        ;; comments, example blocks...
-        ((memq type '(footnote-definition headline inlinetask nil))
-         (call-interactively #'org-open-at-point-global))
-        ;; On a clock line, make sure point is on the timestamp
-        ;; before opening it.
-        ((and (eq type 'clock)
-              value
-              (>= (point) (org-element-property :begin value))
-              (<= (point) (org-element-property :end value)))
-         (org-follow-timestamp-link))
-        ;; Do nothing on white spaces after an object.
-        ((>= (point)
-             (save-excursion
-               (goto-char (org-element-property :end context))
-               (skip-chars-backward " \t")
-               (point)))
-         (user-error "No link found"))
-        ((eq type 'timestamp) (org-follow-timestamp-link))
-        ((eq type 'link)
-         (let ((type (org-element-property :type context))
-               (path (org-link-unescape (org-element-property :path context))))
-           ;; Switch back to REFERENCE-BUFFER needed when called in
-           ;; a temporary buffer through `org-open-link-from-string'.
-           (with-current-buffer (or reference-buffer (current-buffer))
-             (cond
-              ((equal type "file")
-               (if (string-match "[*?{]" (file-name-nondirectory path))
-                   (dired path)
-                 ;; Look into `org-link-parameters' in order to find
-                 ;; a DEDICATED-FUNCTION to open file.  The function
-                 ;; will be applied on raw link instead of parsed
-                 ;; link due to the limitation in `org-add-link-type'
-                 ;; ("open" function called with a single argument).
-                 ;; If no such function is found, fallback to
-                 ;; `org-open-file'.
-                 (let* ((option (org-element-property :search-option context))
-                        (app (org-element-property :application context))
-                        (dedicated-function
-                         (org-link-get-parameter
-                          (if app (concat type "+" app) type)
-                          :follow)))
-                   (if dedicated-function
-                       (funcall dedicated-function
-                                (concat path
-                                        (and option (concat "::" option))))
-                     (apply #'org-open-file
-                            path
-                            (cond (arg)
-                                  ((equal app "emacs") 'emacs)
-                                  ((equal app "sys") 'system))
-                            (cond ((not option) nil)
-                                  ((string-match-p "\\`[0-9]+\\'" option)
-                                   (list (string-to-number option)))
-                                  (t (list nil
-                                           (org-link-unescape option)))))))))
-              ((functionp (org-link-get-parameter type :follow))
-               (funcall (org-link-get-parameter type :follow) path))
-              ((member type '("coderef" "custom-id" "fuzzy" "radio"))
-               (unless (run-hook-with-args-until-success
-                        'org-open-link-functions path)
-                 (if (not arg) (org-mark-ring-push)
-                   (switch-to-buffer-other-window
-                    (org-get-buffer-for-internal-link (current-buffer))))
-                 (let ((destination
-                        (org-with-wide-buffer
-                         (if (equal type "radio")
-                             (org-search-radio-target
-                              (org-element-property :path context))
-                           (org-link-search
-                            (if (member type '("custom-id" "coderef"))
-                                (org-element-property :raw-link context)
-                              path)
-                            ;; Prevent fuzzy links from matching
-                            ;; themselves.
-                            (and (equal type "fuzzy")
-                                 (+ 2 (org-element-property :begin context)))))
-                         (point))))
-                   (unless (and (<= (point-min) destination)
-                                (>= (point-max) destination))
-                     (widen))
-                   (goto-char destination))))
-              (t (browse-url-at-point))))))
-        (t (user-error "No link found")))))
-    (run-hook-with-args 'org-follow-link-hook)))
+  (org-load-modules-maybe)
+  (setq org-window-config-before-follow-link (current-window-configuration))
+  (org-remove-occur-highlights nil nil t)
+  (unless (run-hook-with-args-until-success 'org-open-at-point-functions)
+    (let* ((context
+           ;; Only consider supported types, even if they are not the
+           ;; closest one.
+           (org-element-lineage
+            (org-element-context)
+            '(clock comment comment-block footnote-definition
+                    footnote-reference headline inline-src-block inlinetask
+                    keyword link node-property planning src-block timestamp)
+            t))
+          (type (org-element-type context))
+          (value (org-element-property :value context)))
+      (cond
+       ((not type) (user-error "No link found"))
+       ;; No valid link at point.  For convenience, look if something
+       ;; looks like a link under point in some specific places.
+       ((memq type '(comment comment-block node-property keyword))
+       (call-interactively #'org-open-at-point-global))
+       ;; On a headline or an inlinetask, but not on a timestamp,
+       ;; a link, a footnote reference.
+       ((memq type '(headline inlinetask))
+       (org-match-line org-complex-heading-regexp)
+       (if (and (match-beginning 5)
+                (>= (point) (match-beginning 5))
+                (< (point) (match-end 5)))
+           ;; On tags.
+           (org-tags-view
+            arg
+            (save-excursion
+              (let* ((beg (match-beginning 5))
+                     (end (match-end 5))
+                     (beg-tag (or (search-backward ":" beg 'at-limit) (point)))
+                     (end-tag (search-forward ":" end nil 2)))
+                (buffer-substring (1+ beg-tag) (1- end-tag)))))
+         ;; Not on tags.
+         (pcase (org-offer-links-in-entry (current-buffer) (point) arg)
+           (`(nil . ,_)
+            (require 'org-attach)
+            (message "Opening attachment-dir")
+            (if (equal arg '(4))
+                (org-attach-reveal-in-emacs)
+              (org-attach-reveal)))
+           (`(,links . ,links-end)
+            (dolist (link (if (stringp links) (list links) links))
+              (search-forward link nil links-end)
+              (goto-char (match-beginning 0))
+              (org-open-at-point arg))))))
+       ;; On a footnote reference or at definition's label.
+       ((or (eq type 'footnote-reference)
+           (and (eq type 'footnote-definition)
+                (save-excursion
+                  ;; Do not validate action when point is on the
+                  ;; spaces right after the footnote label, in order
+                  ;; to be on par with behavior on links.
+                  (skip-chars-forward " \t")
+                  (let ((begin
+                         (org-element-property :contents-begin context)))
+                    (if begin (< (point) begin)
+                      (= (org-element-property :post-affiliated context)
+                         (line-beginning-position)))))))
+       (org-footnote-action))
+       ;; On a planning line.  Check if we are really on a timestamp.
+       ((and (eq type 'planning)
+            (org-in-regexp org-ts-regexp-both nil t))
+       (org-follow-timestamp-link))
+       ;; On a clock line, make sure point is on the timestamp
+       ;; before opening it.
+       ((and (eq type 'clock)
+            value
+            (>= (point) (org-element-property :begin value))
+            (<= (point) (org-element-property :end value)))
+       (org-follow-timestamp-link))
+       ((eq type 'src-block) (org-babel-open-src-block-result))
+       ;; Do nothing on white spaces after an object.
+       ((>= (point)
+           (save-excursion
+             (goto-char (org-element-property :end context))
+             (skip-chars-backward " \t")
+             (point)))
+       (user-error "No link found"))
+       ((eq type 'inline-src-block) (org-babel-open-src-block-result))
+       ((eq type 'timestamp) (org-follow-timestamp-link))
+       ((eq type 'link) (org-link-open context arg))
+       (t (user-error "No link found")))))
+  (run-hook-with-args 'org-follow-link-hook))
 
+;;;###autoload
 (defun org-offer-links-in-entry (buffer marker &optional nth zero)
   "Offer links in the current entry and return the selected link.
 If there is only one link, return it.
@@ -10759,13 +8735,13 @@ there is one, return it."
      (goto-char marker)
      (let ((cnt ?0)
           have-zero end links link c)
-       (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
+       (when (and (stringp zero) (string-match org-link-bracket-re zero))
         (push (match-string 0 zero) links)
         (setq cnt (1- cnt) have-zero t))
        (save-excursion
         (org-back-to-heading t)
         (setq end (save-excursion (outline-next-heading) (point)))
-        (while (re-search-forward org-any-link-re end t)
+        (while (re-search-forward org-link-any-re end t)
           (push (match-string 0) links))
         (setq links (org-uniquify (reverse links))))
        (cond
@@ -10782,12 +8758,12 @@ there is one, return it."
             (with-output-to-temp-buffer "*Select Link*"
               (dolist (l links)
                 (cond
-                 ((not (string-match org-bracket-link-regexp l))
+                 ((not (string-match org-link-bracket-re l))
                   (princ (format "[%c]  %s\n" (cl-incf cnt)
                                  (org-unbracket-string "<" ">" l))))
-                 ((match-end 3)
+                 ((match-end 2)
                   (princ (format "[%c]  %s (%s)\n" (cl-incf cnt)
-                                 (match-string 3 l) (match-string 1 l))))
+                                 (match-string 2 l) (match-string 1 l))))
                  (t (princ (format "[%c]  %s\n" (cl-incf cnt)
                                    (match-string 1 l)))))))
             (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
@@ -10804,268 +8780,8 @@ there is one, return it."
           (setq link (nth (1- nth) links)))))
        (cons link end)))))
 
-;; TODO: These functions are deprecated since `org-open-at-point'
-;; hard-codes behavior for "file+emacs" and "file+sys" types.
-(defun org-open-file-with-system (path)
-  "Open file at PATH using the system way of opening it."
-  (org-open-file path 'system))
-(defun org-open-file-with-emacs (path)
-  "Open file at PATH in Emacs."
-  (org-open-file path 'emacs))
-
-
 ;;; File search
 
-(defvar org-create-file-search-functions nil
-  "List of functions to construct the right search string for a file link.
-These functions are called in turn with point at the location to
-which the link should point.
-
-A function in the hook should first test if it would like to
-handle this file type, for example by checking the `major-mode'
-or the file extension.  If it decides not to handle this file, it
-should just return nil to give other functions a chance.  If it
-does handle the file, it must return the search string to be used
-when following the link.  The search string will be part of the
-file link, given after a double colon, and `org-open-at-point'
-will automatically search for it.  If special measures must be
-taken to make the search successful, another function should be
-added to the companion hook `org-execute-file-search-functions',
-which see.
-
-A function in this hook may also use `setq' to set the variable
-`description' to provide a suggestion for the descriptive text to
-be used for this link when it gets inserted into an Org buffer
-with \\[org-insert-link].")
-
-(defvar org-execute-file-search-functions nil
-  "List of functions to execute a file search triggered by a link.
-
-Functions added to this hook must accept a single argument, the
-search string that was part of the file link, the part after the
-double colon.  The function must first check if it would like to
-handle this search, for example by checking the `major-mode' or
-the file extension.  If it decides not to handle this search, it
-should just return nil to give other functions a chance.  If it
-does handle the search, it must return a non-nil value to keep
-other functions from trying.
-
-Each function can access the current prefix argument through the
-variable `current-prefix-arg'.  Note that a single prefix is used
-to force opening a link in Emacs, so it may be good to only use a
-numeric or double prefix to guide the search function.
-
-In case this is needed, a function in this hook can also restore
-the window configuration before `org-open-at-point' was called using:
-
-    (set-window-configuration org-window-config-before-follow-link)")
-
-(defun org-search-radio-target (target)
-  "Search a radio target matching TARGET in current buffer.
-White spaces are not significant."
-  (let ((re (format "<<<%s>>>"
-                   (mapconcat #'regexp-quote
-                              (split-string target)
-                              "[ \t]+\\(?:\n[ \t]*\\)?")))
-       (origin (point)))
-    (goto-char (point-min))
-    (catch :radio-match
-      (while (re-search-forward re nil t)
-       (backward-char)
-       (let ((object (org-element-context)))
-         (when (eq (org-element-type object) 'radio-target)
-           (goto-char (org-element-property :begin object))
-           (org-show-context 'link-search)
-           (throw :radio-match nil))))
-      (goto-char origin)
-      (user-error "No match for radio target: %s" target))))
-
-(defun org-link-search (s &optional avoid-pos stealth)
-  "Search for a search string S.
-
-If S starts with \"#\", it triggers a custom ID search.
-
-If S is enclosed within parenthesis, it initiates a coderef
-search.
-
-If S is surrounded by forward slashes, it is interpreted as
-a regular expression.  In Org mode files, this will create an
-`org-occur' sparse tree.  In ordinary files, `occur' will be used
-to list matches.  If the current buffer is in `dired-mode', grep
-will be used to search in all files.
-
-When AVOID-POS is given, ignore matches near that position.
-
-When optional argument STEALTH is non-nil, do not modify
-visibility around point, thus ignoring `org-show-context-detail'
-variable.
-
-Search is case-insensitive and ignores white spaces.  Return type
-of matched result, which is either `dedicated' or `fuzzy'."
-  (unless (org-string-nw-p s) (error "Invalid search string \"%s\"" s))
-  (let* ((case-fold-search t)
-        (origin (point))
-        (normalized (replace-regexp-in-string "\n[ \t]*" " " s))
-        (starred (eq (string-to-char normalized) ?*))
-        (words (split-string (if starred (substring s 1) s)))
-        (s-multi-re (mapconcat #'regexp-quote words "\\(?:[ \t\n]+\\)"))
-        (s-single-re (mapconcat #'regexp-quote words "[ \t]+"))
-        type)
-    (cond
-     ;; Check if there are any special search functions.
-     ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
-     ((eq (string-to-char s) ?#)
-      ;; Look for a custom ID S if S starts with "#".
-      (let* ((id (substring normalized 1))
-            (match (org-find-property "CUSTOM_ID" id)))
-       (if match (progn (goto-char match) (setf type 'dedicated))
-         (error "No match for custom ID: %s" id))))
-     ((string-match "\\`(\\(.*\\))\\'" normalized)
-      ;; Look for coderef targets if S is enclosed within parenthesis.
-      (let ((coderef (match-string-no-properties 1 normalized))
-           (re (substring s-single-re 1 -1)))
-       (goto-char (point-min))
-       (catch :coderef-match
-         (while (re-search-forward re nil t)
-           (let ((element (org-element-at-point)))
-             (when (and (memq (org-element-type element)
-                              '(example-block src-block))
-                        ;; Build proper regexp according to current
-                        ;; block's label format.
-                        (let ((label-fmt
-                               (regexp-quote
-                                (or (org-element-property :label-fmt element)
-                                    org-coderef-label-format))))
-                          (save-excursion
-                            (beginning-of-line)
-                            (looking-at (format ".*?\\(%s\\)[ \t]*$"
-                                                (format label-fmt coderef))))))
-               (setq type 'dedicated)
-               (goto-char (match-beginning 1))
-               (throw :coderef-match nil))))
-         (goto-char origin)
-         (error "No match for coderef: %s" coderef))))
-     ((string-match "\\`/\\(.*\\)/\\'" normalized)
-      ;; Look for a regular expression.
-      (funcall (if (derived-mode-p 'org-mode) #'org-occur #'org-do-occur)
-              (match-string 1 s)))
-     ;; From here, we handle fuzzy links.
-     ;;
-     ;; Look for targets, only if not in a headline search.
-     ((and (not starred)
-          (let ((target (format "<<%s>>" s-multi-re)))
-            (catch :target-match
-              (goto-char (point-min))
-              (while (re-search-forward target nil t)
-                (backward-char)
-                (let ((context (org-element-context)))
-                  (when (eq (org-element-type context) 'target)
-                    (setq type 'dedicated)
-                    (goto-char (org-element-property :begin context))
-                    (throw :target-match t))))
-              nil))))
-     ;; Look for elements named after S, only if not in a headline
-     ;; search.
-     ((and (not starred)
-          (let ((name (format "^[ \t]*#\\+NAME: +%s[ \t]*$" s-single-re)))
-            (catch :name-match
-              (goto-char (point-min))
-              (while (re-search-forward name nil t)
-                (let ((element (org-element-at-point)))
-                  (when (equal words
-                               (split-string
-                                (org-element-property :name element)))
-                    (setq type 'dedicated)
-                    (beginning-of-line)
-                    (throw :name-match t))))
-              nil))))
-     ;; Regular text search.  Prefer headlines in Org mode buffers.
-     ;; Ignore COMMENT keyword, TODO keywords, priority cookies,
-     ;; statistics cookies and tags.
-     ((and (derived-mode-p 'org-mode)
-          (let ((title-re
-                 (format "%s.*\\(?:%s[ \t]\\)?.*%s"
-                         org-outline-regexp-bol
-                         org-comment-string
-                         (mapconcat #'regexp-quote words ".+")))
-                (cookie-re "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]")
-                (comment-re (eval-when-compile
-                              (format "\\`%s[ \t]+" org-comment-string))))
-            (goto-char (point-min))
-            (catch :found
-              (while (re-search-forward title-re nil t)
-                (when (equal words
-                             (split-string
-                              (replace-regexp-in-string
-                               cookie-re ""
-                               (replace-regexp-in-string
-                                comment-re "" (org-get-heading t t t)))))
-                  (throw :found t)))
-              nil)))
-      (beginning-of-line)
-      (setq type 'dedicated))
-     ;; Offer to create non-existent headline depending on
-     ;; `org-link-search-must-match-exact-headline'.
-     ((and (derived-mode-p 'org-mode)
-          (not org-link-search-inhibit-query)
-          (eq org-link-search-must-match-exact-headline 'query-to-create)
-          (yes-or-no-p "No match - create this as a new heading? "))
-      (goto-char (point-max))
-      (unless (bolp) (newline))
-      (org-insert-heading nil t t)
-      (insert s "\n")
-      (beginning-of-line 0))
-     ;; Only headlines are looked after.  No need to process
-     ;; further: throw an error.
-     ((and (derived-mode-p 'org-mode)
-          (or starred org-link-search-must-match-exact-headline))
-      (goto-char origin)
-      (error "No match for fuzzy expression: %s" normalized))
-     ;; Regular text search.
-     ((catch :fuzzy-match
-       (goto-char (point-min))
-       (while (re-search-forward s-multi-re nil t)
-         ;; Skip match if it contains AVOID-POS or it is included in
-         ;; a link with a description but outside the description.
-         (unless (or (and avoid-pos
-                          (<= (match-beginning 0) avoid-pos)
-                          (> (match-end 0) avoid-pos))
-                     (and (save-match-data
-                            (org-in-regexp org-bracket-link-regexp))
-                          (match-beginning 3)
-                          (or (> (match-beginning 3) (point))
-                              (<= (match-end 3) (point)))
-                          (org-element-lineage
-                           (save-match-data (org-element-context))
-                           '(link) t)))
-           (goto-char (match-beginning 0))
-           (setq type 'fuzzy)
-           (throw :fuzzy-match t)))
-       nil))
-     ;; All failed.  Throw an error.
-     (t (goto-char origin)
-       (error "No match for fuzzy expression: %s" normalized)))
-    ;; Disclose surroundings of match, if appropriate.
-    (when (and (derived-mode-p 'org-mode) (not stealth))
-      (org-show-context 'link-search))
-    type))
-
-(defun org-get-buffer-for-internal-link (buffer)
-  "Return a buffer to be used for displaying the link target of internal 
links."
-  (cond
-   ((not org-display-internal-link-with-indirect-buffer)
-    buffer)
-   ((string-suffix-p "(Clone)" (buffer-name buffer))
-    (message "Buffer is already a clone, not making another one")
-    ;; we also do not modify visibility in this case
-    buffer)
-   (t ; make a new indirect buffer for displaying the link
-    (let* ((bn (buffer-name buffer))
-          (ibn (concat bn "(Clone)"))
-          (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
-      (with-current-buffer ib (org-overview))
-      ib))))
-
 (defun org-do-occur (regexp &optional cleanup)
   "Call the Emacs command `occur'.
 If CLEANUP is non-nil, remove the printout of the regular expression
@@ -11085,303 +8801,87 @@ to read."
       (goto-char (point-min))
       (select-window cwin))))
 
-;;; The mark ring for links jumps
+
+;;; The Mark Ring
 
 (defvar org-mark-ring nil
   "Mark ring for positions before jumps in Org mode.")
-(defvar org-mark-ring-last-goto nil
-  "Last position in the mark ring used to go back.")
-;; Fill and close the ring
-(setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is 
reloaded
-(dotimes (_ org-mark-ring-length)
-  (push (make-marker) org-mark-ring))
-(setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
-       org-mark-ring)
-
-(defun org-mark-ring-push (&optional pos buffer)
-  "Put the current position or POS into the mark ring and rotate it."
-  (interactive)
-  (setq pos (or pos (point)))
-  (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
-  (move-marker (car org-mark-ring)
-              (or pos (point))
-              (or buffer (current-buffer)))
-  (message "%s"
-          (substitute-command-keys
-           "Position saved to mark ring, go back with \
-`\\[org-mark-ring-goto]'.")))
-
-(defun org-mark-ring-goto (&optional n)
-  "Jump to the previous position in the mark ring.
-With prefix arg N, jump back that many stored positions.  When
-called several times in succession, walk through the entire ring.
-Org mode commands jumping to a different position in the current file,
-or to another Org file, automatically push the old position onto the ring."
-  (interactive "p")
-  (let (p m)
-    (if (eq last-command this-command)
-       (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
-      (setq p org-mark-ring))
-    (setq org-mark-ring-last-goto p)
-    (setq m (car p))
-    (pop-to-buffer-same-window (marker-buffer m))
-    (goto-char m)
-    (when (or (org-invisible-p) (org-invisible-p2)) (org-show-context 
'mark-goto))))
-
-(defun org-add-angle-brackets (s)
-  (unless (equal (substring s 0 1) "<") (setq s (concat "<" s)))
-  (unless (equal (substring s -1) ">") (setq s (concat s ">")))
-  s)
-
-;;; Following specific links
-
-(defvar org-agenda-buffer-tmp-name)
-(defvar org-agenda-start-on-weekday)
-(defun org-follow-timestamp-link ()
-  "Open an agenda view for the time-stamp date/range at point."
-  (cond
-   ((org-at-date-range-p t)
-    (let ((org-agenda-start-on-weekday)
-         (t1 (match-string 1))
-         (t2 (match-string 2)) tt1 tt2)
-      (setq tt1 (time-to-days (org-time-string-to-time t1))
-           tt2 (time-to-days (org-time-string-to-time t2)))
-      (let ((org-agenda-buffer-tmp-name
-            (format "*Org Agenda(a:%s)"
-                    (concat (substring t1 0 10) "--" (substring t2 0 10)))))
-       (org-agenda-list nil tt1 (1+ (- tt2 tt1))))))
-   ((org-at-timestamp-p 'lax)
-    (let ((org-agenda-buffer-tmp-name
-          (format "*Org Agenda(a:%s)" (substring (match-string 1) 0 10))))
-      (org-agenda-list nil (time-to-days (org-time-string-to-time
-                                         (substring (match-string 1) 0 10)))
-                      1)))
-   (t (error "This should not happen"))))
-
-
-;;; Following file links
-(declare-function mailcap-parse-mailcaps "mailcap" (&optional path force))
-(declare-function mailcap-extension-to-mime "mailcap" (extn))
-(declare-function mailcap-mime-info
-                 "mailcap" (string &optional request no-decode))
-(defvar org-wait nil)
-(defun org-open-file (path &optional in-emacs line search)
-  "Open the file at PATH.
-First, this expands any special file name abbreviations.  Then the
-configuration variable `org-file-apps' is checked if it contains an
-entry for this file type, and if yes, the corresponding command is launched.
-
-If no application is found, Emacs simply visits the file.
-
-With optional prefix argument IN-EMACS, Emacs will visit the file.
-With a double \\[universal-argument] \\[universal-argument] \
-prefix arg, Org tries to avoid opening in Emacs
-and to use an external application to visit the file.
-
-Optional LINE specifies a line to go to, optional SEARCH a string
-to search for.  If LINE or SEARCH is given, the file will be
-opened in Emacs, unless an entry from org-file-apps that makes
-use of groups in a regexp matches.
-
-If you want to change the way frames are used when following a
-link, please customize `org-link-frame-setup'.
-
-If the file does not exist, an error is thrown."
-  (let* ((file (if (equal path "")
-                  buffer-file-name
-                (substitute-in-file-name (expand-file-name path))))
-        (file-apps (append org-file-apps (org-default-apps)))
-        (apps (cl-remove-if
-               'org-file-apps-entry-match-against-dlink-p file-apps))
-        (apps-dlink (cl-remove-if-not
-                     'org-file-apps-entry-match-against-dlink-p file-apps))
-        (remp (and (assq 'remote apps) (org-file-remote-p file)))
-        (dirp (unless remp (file-directory-p file)))
-        (file (if (and dirp org-open-directory-means-index-dot-org)
-                  (concat (file-name-as-directory file) "index.org")
-                file))
-        (a-m-a-p (assq 'auto-mode apps))
-        (dfile (downcase file))
-        ;; Reconstruct the original link from the PATH, LINE and
-        ;; SEARCH args.
-        (link (cond (line (concat file "::" (number-to-string line)))
-                    (search (concat file "::" search))
-                    (t file)))
-        (dlink (downcase link))
-        (ext
-         (and (string-match "\\`.*?\\.\\([a-zA-Z0-9]+\\(\\.gz\\)?\\)\\'" dfile)
-              (match-string 1 dfile)))
-        (save-position-maybe
-         (let ((old-buffer (current-buffer))
-               (old-pos (point))
-               (old-mode major-mode))
-           (lambda ()
-             (and (derived-mode-p 'org-mode)
-                  (eq old-mode 'org-mode)
-                  (or (not (eq old-buffer (current-buffer)))
-                      (not (eq old-pos (point))))
-                  (org-mark-ring-push old-pos old-buffer)))))
-        cmd link-match-data)
-    (cond
-     ((member in-emacs '((16) system))
-      (setq cmd (cdr (assq 'system apps))))
-     (in-emacs (setq cmd 'emacs))
-     (t
-      (setq cmd (or (and remp (cdr (assq 'remote apps)))
-                   (and dirp (cdr (assq 'directory apps)))
-                   ;; First, try matching against apps-dlink if we
-                   ;; get a match here, store the match data for
-                   ;; later.
-                   (let ((match (assoc-default dlink apps-dlink
-                                               'string-match)))
-                     (if match
-                         (progn (setq link-match-data (match-data))
-                                match)
-                       (progn (setq in-emacs (or in-emacs line search))
-                              nil))) ; if we have no match in apps-dlink,
-                                       ; always open the file in emacs if line 
or search
-                                       ; is given (for backwards compatibility)
-                   (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
-                                  'string-match)
-                   (cdr (assoc ext apps))
-                   (cdr (assq t apps))))))
-    (when (eq cmd 'system)
-      (setq cmd (cdr (assq 'system apps))))
-    (when (eq cmd 'default)
-      (setq cmd (cdr (assoc t apps))))
-    (when (eq cmd 'mailcap)
-      (require 'mailcap)
-      (mailcap-parse-mailcaps)
-      (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
-            (command (mailcap-mime-info mime-type)))
-       (if (stringp command)
-           (setq cmd command)
-         (setq cmd 'emacs))))
-    (when (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
-              (not (file-exists-p file))
-              (not org-open-non-existing-files))
-      (user-error "No such file: %s" file))
-    (cond
-     ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
-      ;; Remove quotes around the file name - we'll use shell-quote-argument.
-      (while (string-match "['\"]%s['\"]" cmd)
-       (setq cmd (replace-match "%s" t t cmd)))
-      (setq cmd (replace-regexp-in-string
-                "%s"
-                (shell-quote-argument (convert-standard-filename file))
-                cmd
-                nil t))
 
-      ;; Replace "%1", "%2" etc. in command with group matches from regex
-      (save-match-data
-       (let ((match-index 1)
-             (number-of-groups (- (/ (length link-match-data) 2) 1)))
-         (set-match-data link-match-data)
-         (while (<= match-index number-of-groups)
-           (let ((regex (concat "%" (number-to-string match-index)))
-                 (replace-with (match-string match-index dlink)))
-             (while (string-match regex cmd)
-               (setq cmd (replace-match replace-with t t cmd))))
-           (setq match-index (+ match-index 1)))))
+(defvar org-mark-ring-last-goto nil
+  "Last position in the mark ring used to go back.")
 
-      (save-window-excursion
-       (message "Running %s...done" cmd)
-       (start-process-shell-command cmd nil cmd)
-       (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
-     ((or (stringp cmd)
-         (eq cmd 'emacs))
-      (funcall (cdr (assq 'file org-link-frame-setup)) file)
-      (widen)
-      (cond (line (org-goto-line line)
-                 (when (derived-mode-p 'org-mode) (org-reveal)))
-           (search (condition-case err
-                       (org-link-search search)
-                     ;; Save position before error-ing out so user
-                     ;; can easily move back to the original buffer.
-                     (error (funcall save-position-maybe)
-                            (error (nth 1 err)))))))
-     ((functionp cmd)
-      (save-match-data
-       (set-match-data link-match-data)
-       (condition-case nil
-           (funcall cmd file link)
-         ;; FIXME: Remove this check when most default installations
-         ;; of Emacs have at least Org 9.0.
-         ((debug wrong-number-of-arguments wrong-type-argument
-                 invalid-function)
-          (user-error "Please see Org News for version 9.0 about \
-`org-file-apps'--Lisp error: %S" cmd)))))
-     ((consp cmd)
-      ;; FIXME: Remove this check when most default installations of
-      ;; Emacs have at least Org 9.0.  Heads-up instead of silently
-      ;; fall back to `org-link-frame-setup' for an old usage of
-      ;; `org-file-apps' with sexp instead of a function for `cmd'.
-      (user-error "Please see Org News for version 9.0 about \
-`org-file-apps'--Error: Deprecated usage of %S" cmd))
-     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
-    (funcall save-position-maybe)))
+;; Fill and close the ring
+(setq org-mark-ring nil)
+(setq org-mark-ring-last-goto nil) ;in case file is reloaded
 
-(defun org-file-apps-entry-match-against-dlink-p (entry)
-  "This function returns non-nil if `entry' uses a regular
-expression which should be matched against the whole link by
-org-open-file.
+(dotimes (_ org-mark-ring-length) (push (make-marker) org-mark-ring))
+(setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
+       org-mark-ring)
 
-It assumes that is the case when the entry uses a regular
-expression which has at least one grouping construct and the
-action is either a lisp form or a command string containing
-`%1', i.e. using at least one subexpression match as a
-parameter."
-  (let ((selector (car entry))
-       (action (cdr entry)))
-    (if (stringp selector)
-       (and (> (regexp-opt-depth selector) 0)
-            (or (and (stringp action)
-                     (string-match "%[0-9]" action))
-                (consp action)))
-      nil)))
+(defun org-mark-ring-push (&optional pos buffer)
+  "Put the current position into the mark ring and rotate it.
+Also push position into the Emacs mark ring.  If optional
+argument POS and BUFFER are not nil, mark this location instead."
+  (interactive)
+  (let ((pos (or pos (point)))
+       (buffer (or buffer (current-buffer))))
+    (with-current-buffer buffer
+      (org-with-point-at pos (push-mark nil t)))
+    (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
+    (move-marker (car org-mark-ring) pos buffer))
+  (message
+   (substitute-command-keys
+    "Position saved to mark ring, go back with `\\[org-mark-ring-goto]'.")))
 
-(defun org-default-apps ()
-  "Return the default applications for this operating system."
-  (cond
-   ((eq system-type 'darwin)
-    org-file-apps-defaults-macosx)
-   ((eq system-type 'windows-nt)
-    org-file-apps-defaults-windowsnt)
-   (t org-file-apps-defaults-gnu)))
+(defun org-mark-ring-goto (&optional n)
+  "Jump to the previous position in the mark ring.
+With prefix arg N, jump back that many stored positions.  When
+called several times in succession, walk through the entire ring.
+Org mode commands jumping to a different position in the current file,
+or to another Org file, automatically push the old position onto the ring."
+  (interactive "p")
+  (let (p m)
+    (if (eq last-command this-command)
+       (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
+      (setq p org-mark-ring))
+    (setq org-mark-ring-last-goto p)
+    (setq m (car p))
+    (pop-to-buffer-same-window (marker-buffer m))
+    (goto-char m)
+    (when (or (org-invisible-p) (org-invisible-p2)) (org-show-context 
'mark-goto))))
 
-(defun org-apps-regexp-alist (list &optional add-auto-mode)
-  "Convert extensions to regular expressions in the cars of LIST.
-Also, weed out any non-string entries, because the return value is used
-only for regexp matching.
-When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
-point to the symbol `emacs', indicating that the file should
-be opened in Emacs."
-  (append
-   (delq nil
-        (mapcar (lambda (x)
-                  (unless (not (stringp (car x)))
-                    (if (string-match "\\W" (car x))
-                        x
-                      (cons (concat "\\." (car x) "\\'") (cdr x)))))
-                list))
-   (when add-auto-mode
-     (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
+;;; Following specific links
 
-(defvar ange-ftp-name-format)
-(defun org-file-remote-p (file)
-  "Test whether FILE specifies a location on a remote system.
-Return non-nil if the location is indeed remote.
+(defvar org-agenda-buffer-tmp-name)
+(defvar org-agenda-start-on-weekday)
+(defun org-follow-timestamp-link ()
+  "Open an agenda view for the time-stamp date/range at point."
+  (cond
+   ((org-at-date-range-p t)
+    (let ((org-agenda-start-on-weekday)
+         (t1 (match-string 1))
+         (t2 (match-string 2)) tt1 tt2)
+      (setq tt1 (time-to-days (org-time-string-to-time t1))
+           tt2 (time-to-days (org-time-string-to-time t2)))
+      (let ((org-agenda-buffer-tmp-name
+            (format "*Org Agenda(a:%s)"
+                    (concat (substring t1 0 10) "--" (substring t2 0 10)))))
+       (org-agenda-list nil tt1 (1+ (- tt2 tt1))))))
+   ((org-at-timestamp-p 'lax)
+    (let ((org-agenda-buffer-tmp-name
+          (format "*Org Agenda(a:%s)" (substring (match-string 1) 0 10))))
+      (org-agenda-list nil (time-to-days (org-time-string-to-time
+                                         (substring (match-string 1) 0 10)))
+                      1)))
+   (t (error "This should not happen"))))
 
-For example, the filename \"/user@host:/foo\" specifies a location
-on the system \"/user@host:\"."
-  (cond ((fboundp 'file-remote-p)
-         (file-remote-p file))
-        ((fboundp 'tramp-handle-file-remote-p)
-         (tramp-handle-file-remote-p file))
-        ((and (boundp 'ange-ftp-name-format)
-              (string-match (car ange-ftp-name-format) file))
-         t)))
 
+;;; Following file links
+(declare-function mailcap-parse-mailcaps "mailcap" (&optional path force))
+(declare-function mailcap-extension-to-mime "mailcap" (extn))
+(declare-function mailcap-mime-info
+                 "mailcap" (string &optional request no-decode))
+(defvar org-wait nil)
 
 ;;;; Refiling
 
@@ -11554,7 +9054,7 @@ order.")
                                           (buffer-base-buffer))))
                                   (_ nil))
                                 (mapcar (lambda (s) (replace-regexp-in-string
-                                                "/" "\\/" s nil t))
+                                                     "/" "\\/" s nil t))
                                         (org-get-outline-path t t)))
                                "/"))))
                        (push (list target f re (org-refile-marker (point)))
@@ -11697,7 +9197,7 @@ the *old* location.")
   "Like `org-refile', but copy."
   (interactive)
   (let ((org-refile-keep t))
-    (funcall 'org-refile nil nil nil "Copy")))
+    (org-refile nil nil nil "Copy")))
 
 (defun org-refile (&optional arg default-buffer rfloc msg)
   "Move the entry or entries at point to another heading.
@@ -11753,7 +9253,7 @@ prefix argument (`C-u C-u C-u C-c C-w')."
       (setq last-command nil)
       (when regionp
        (goto-char region-start)
-       (or (bolp) (goto-char (point-at-bol)))
+       (beginning-of-line)
        (setq region-start (point))
        (unless (or (org-kill-is-subtree-p
                     (buffer-substring region-start region-end))
@@ -11782,8 +9282,8 @@ prefix argument (`C-u C-u C-u C-c C-w')."
                               (org-back-to-heading t)
                               (setq heading-text
                                     (replace-regexp-in-string
-                                     org-bracket-link-regexp
-                                     "\\3"
+                                     org-link-bracket-re
+                                     "\\2"
                                      (or (nth 4 (org-heading-components))
                                          ""))))
                             (org-refile-get-location
@@ -11841,13 +9341,21 @@ prefix argument (`C-u C-u C-u C-c C-w')."
                   (or (outline-next-heading) (goto-char (point-max)))))
               (unless (bolp) (newline))
               (org-paste-subtree level nil nil t)
-              (when org-log-refile
-                (org-add-log-setup 'refile nil nil org-log-refile)
-                (unless (eq org-log-refile 'note)
-                  (save-excursion (org-add-log-note))))
+              ;; Record information, according to `org-log-refile'.
+              ;; Do not prompt for a note when refiling multiple
+              ;; headlines, however.  Simply add a time stamp.
+              (cond
+               ((not org-log-refile))
+               (regionp
+                (org-map-region
+                 (lambda () (org-add-log-setup 'refile nil nil 'time))
+                 (point)
+                 (+ (point) (- region-end region-start))))
+               (t
+                (org-add-log-setup 'refile nil nil org-log-refile)))
               (and org-auto-align-tags
                    (let ((org-loop-over-headlines-in-active-region nil))
-                     (org-set-tags nil t)))
+                     (org-align-tags)))
               (let ((bookmark-name (plist-get org-bookmark-names-plist
                                               :last-refile)))
                 (when bookmark-name
@@ -11867,9 +9375,10 @@ prefix argument (`C-u C-u C-u C-c C-w')."
            (unless org-refile-keep
              (if regionp
                  (delete-region (point) (+ (point) (- region-end 
region-start)))
-               (delete-region
-                (and (org-back-to-heading t) (point))
-                (min (1+ (buffer-size)) (org-end-of-subtree t t) (point)))))
+               (org-preserve-local-variables
+                (delete-region
+                 (and (org-back-to-heading t) (point))
+                 (min (1+ (buffer-size)) (org-end-of-subtree t t) (point))))))
            (when (featurep 'org-inlinetask)
              (org-inlinetask-remove-END-maybe))
            (setq org-markers-to-move nil)
@@ -12097,6 +9606,42 @@ If COMMAND is not given, use `org-update-dblock'."
        (unless (re-search-forward org-dblock-end-re nil t)
          (error "Dynamic block not terminated"))))))
 
+(defvar org-dynamic-block-alist nil
+  "Alist defining all the Org dynamic blocks.
+
+The key is the dynamic block type name, as a string.  The value
+is the function used to insert the dynamic block.
+
+Use `org-dynamic-block-define' to populate it.")
+
+(defun org-dynamic-block-function (type)
+  "Return function associated to a given dynamic block type.
+TYPE is the dynamic block type, as a string."
+  (cdr (assoc type org-dynamic-block-alist)))
+
+(defun org-dynamic-block-types ()
+  "List all defined dynamic block types."
+  (mapcar #'car org-dynamic-block-alist))
+
+(defun org-dynamic-block-define (type func)
+  "Define dynamic block TYPE with FUNC.
+TYPE is a string.  FUNC is the function creating the dynamic
+block of such type."
+  (pcase (assoc type org-dynamic-block-alist)
+    (`nil (push (cons type func) org-dynamic-block-alist))
+    (def (setcdr def func))))
+
+(defun org-dynamic-block-insert-dblock (type)
+  "Insert a dynamic block of type TYPE.
+When used interactively, select the dynamic block types among
+defined types, per `org-dynamic-block-define'."
+  (interactive (list (completing-read "Dynamic block: "
+                                     (org-dynamic-block-types))))
+  (pcase (org-dynamic-block-function type)
+    (`nil (error "No such dynamic block: %S" type))
+    ((and f (pred functionp)) (funcall f))
+    (_ (error "Invalid function for dynamic block %S" type))))
+
 (defun org-dblock-update (&optional arg)
   "User command for updating dynamic blocks.
 Update the dynamic block at point.  With prefix ARG, update all dynamic
@@ -12186,76 +9731,188 @@ keywords relative to each registered export back-end."
     "TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:"))
 
 (defcustom org-structure-template-alist
-  '(("s" "#+BEGIN_SRC ?\n\n#+END_SRC")
-    ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE")
-    ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE")
-    ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE")
-    ("V" "#+BEGIN_VERBATIM\n?\n#+END_VERBATIM")
-    ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER")
-    ("C" "#+BEGIN_COMMENT\n?\n#+END_COMMENT")
-    ("l" "#+BEGIN_EXPORT latex\n?\n#+END_EXPORT")
-    ("L" "#+LaTeX: ")
-    ("h" "#+BEGIN_EXPORT html\n?\n#+END_EXPORT")
-    ("H" "#+HTML: ")
-    ("a" "#+BEGIN_EXPORT ascii\n?\n#+END_EXPORT")
-    ("A" "#+ASCII: ")
-    ("i" "#+INDEX: ?")
-    ("I" "#+INCLUDE: %file ?"))
-  "Structure completion elements.
-This is a list of abbreviation keys and values.  The value gets inserted
-if you type `<' followed by the key and then press the completion key,
-usually `TAB'.  %file will be replaced by a file name after prompting
-for the file using completion.  The cursor will be placed at the position
-of the `?' in the template.
-There are two templates for each key, the first uses the original Org syntax,
-the second uses Emacs Muse-like syntax tags.  These Muse-like tags become
-the default when the /org-mtags.el/ module has been loaded.  See also the
-variable `org-mtags-prefer-muse-templates'."
+  '(("a" . "export ascii")
+    ("c" . "center")
+    ("C" . "comment")
+    ("e" . "example")
+    ("E" . "export")
+    ("h" . "export html")
+    ("l" . "export latex")
+    ("q" . "quote")
+    ("s" . "src")
+    ("v" . "verse"))
+  "An alist of keys and block types.
+`org-insert-structure-template' will display a menu with this
+list of templates to choose from.  The block type is inserted,
+with \"#+BEGIN_\" and \"#+END_\" added automatically.
+
+The menu keys are defined by the car of each entry in this alist.
+If two entries have the keys \"a\" and \"aa\" respectively, the
+former will be inserted by typing \"a TAB/RET/SPC\" and the
+latter will be inserted by typing \"aa\".  If an entry with the
+key \"aab\" is later added, it can be inserted by typing \"ab\".
+
+If loaded, Org Tempo also uses `org-structure-template-alist'.  A
+block can be inserted by pressing TAB after the string \"<KEY\"."
   :group 'org-edit-structure
   :type '(repeat
-         (list
-          (string :tag "Key")
-          (string :tag "Template")))
-  :version "26.1"
-  :package-version '(Org . "8.3"))
+         (cons (string :tag "Key")
+               (string :tag "Template")))
+  :package-version '(Org . "9.2"))
 
-(defun org-try-structure-completion ()
-  "Try to complete a structure template before point.
-This looks for strings like \"<e\" on an otherwise empty line and
-expands them."
-  (let ((l (buffer-substring (point-at-bol) (point)))
-       a)
-    (when (and (looking-at "[ \t]*$")
-              (string-match "^[ \t]*<\\([a-zA-Z]+\\)$" l)
-              (setq a (assoc (match-string 1 l) org-structure-template-alist)))
-      (org-complete-expand-structure-template (+ -1 (point-at-bol)
-                                                (match-beginning 1)) a)
-      t)))
+(defun org--check-org-structure-template-alist (&optional checklist)
+  "Check whether `org-structure-template-alist' is set up correctly.
+In particular, check if the Org 9.2 format is used as opposed to
+previous format.
+"
+  (let ((elm (cl-remove-if-not (lambda (x) (listp (cdr x)))
+                              (or (eval checklist)
+                                  org-structure-template-alist))))
+    (when elm
+      (org-display-warning
+       (format "
+Please update the entries of `%s'.
+
+In Org 9.2 the format was changed from something like
+
+    (\"s\" \"#+BEGIN_SRC ?\\n#+END_SRC\")
+
+to something like
+
+    (\"s\" . \"src\")
+
+Please refer to the documentation of `org-structure-template-alist'.
+
+The following entries must be updated:
+
+%s"
+              (or checklist 'org-structure-template-alist)
+              (pp-to-string elm))))))
+
+(defun org--insert-structure-template-mks ()
+  "Present `org-structure-template-alist' with `org-mks'.
+
+Menus are added if keys require more than one keystroke.  Tabs
+are added to single key entries when more than one stroke is
+needed.  Keys longer than two characters are reduced to two
+characters."
+  (org--check-org-structure-template-alist)
+  (let* (case-fold-search
+        (templates (append org-structure-template-alist
+                           '(("\t" . "Press TAB, RET or SPC to write block 
name"))))
+         (keys (mapcar #'car templates))
+         (start-letters
+         (delete-dups (mapcar (lambda (key) (substring key 0 1)) keys)))
+        ;; Sort each element of `org-structure-template-alist' into
+        ;; sublists according to the first letter.
+         (superlist
+         (mapcar (lambda (letter)
+                    (list letter
+                         (cl-remove-if-not
+                          (apply-partially #'string-match-p (concat "^" 
letter))
+                          templates :key #'car)))
+                 start-letters)))
+    (org-mks
+     (apply #'append
+           ;; Make an `org-mks' table.  If only one element is
+           ;; present in a sublist, make it part of the top-menu,
+           ;; otherwise make a submenu according to the starting
+           ;; letter and populate it.
+           (mapcar (lambda (sublist)
+                     (if (eq 1 (length (cadr sublist)))
+                          (mapcar (lambda (elm)
+                                   (list (substring (car elm) 0 1)
+                                          (cdr elm) ""))
+                                  (cadr sublist))
+                       ;; Create submenu.
+                        (let* ((topkey (car sublist))
+                              (elms (cadr sublist))
+                              (keys (mapcar #'car elms))
+                              (long (> (length elms) 3)))
+                          (append
+                          (list
+                           ;; Make a description of the submenu.
+                           (list topkey
+                                 (concat
+                                  (mapconcat #'cdr
+                                             (cl-subseq elms 0 (if long 3 
(length elms)))
+                                             ", ")
+                                   (when long ", ..."))))
+                          ;; List of entries in submenu.
+                          (cl-mapcar #'list
+                                     
(org--insert-structure-template-unique-keys keys)
+                                     (mapcar #'cdr elms)
+                                     (make-list (length elms) ""))))))
+                   superlist))
+     "Select a key\n============"
+     "Key: ")))
+
+(defun org--insert-structure-template-unique-keys (keys)
+  "Make a list of unique, two characters long elements from KEYS.
+
+Elements of length one have a tab appended.  Elements of length
+two are kept as is.  Longer elements are truncated to length two.
+
+If an element cannot be made unique, an error is raised."
+  (let ((orderd-keys (cl-sort (copy-sequence keys) #'< :key #'length))
+       menu-keys)
+    (dolist (key orderd-keys)
+      (let ((potential-key
+            (cl-case (length key)
+              (1 (concat key "\t"))
+              (2 key)
+              (otherwise
+               (cl-find-if-not (lambda (k) (assoc k menu-keys))
+                               (mapcar (apply-partially #'concat (substring  
key 0 1))
+                                       (split-string (substring key 1) "" 
t)))))))
+       (if (or (not potential-key) (assoc potential-key menu-keys))
+           (user-error "Could not make unique key for %s." key)
+         (push (cons potential-key key) menu-keys))))
+    (mapcar #'car
+           (cl-sort menu-keys #'<
+                    :key (lambda (elm) (cl-position (cdr elm) keys))))))
+
+(defun org-insert-structure-template (type)
+  "Insert a block structure of the type #+begin_foo/#+end_foo.
+Select a block from `org-structure-template-alist' then type
+either RET, TAB or SPC to write the block type.  With an active
+region, wrap the region in the block.  Otherwise, insert an empty
+block."
+  (interactive
+   (list (pcase (org--insert-structure-template-mks)
+          (`("\t" . ,_) (read-string "Structure type: "))
+          (`(,_ ,choice . ,_) choice))))
+  (let* ((region? (use-region-p))
+        (region-start (and region? (region-beginning)))
+        (region-end (and region? (copy-marker (region-end))))
+        (extended? (string-match-p "\\`\\(src\\|export\\)\\'" type))
+        (verbatim? (string-match-p
+                    (concat "\\`" (regexp-opt '("example" "export" "src")))
+                    type)))
+    (when region? (goto-char region-start))
+    (let ((column (current-indentation)))
+      (if (save-excursion (skip-chars-backward " \t") (bolp))
+         (beginning-of-line)
+       (insert "\n"))
+      (save-excursion
+       (indent-to column)
+       (insert (format "#+begin_%s%s\n" type (if extended? " " "")))
+       (when region?
+         (when verbatim? (org-escape-code-in-region (point) region-end))
+         (goto-char region-end)
+         ;; Ignore empty lines at the end of the region.
+         (skip-chars-backward " \r\t\n")
+         (end-of-line))
+       (unless (bolp) (insert "\n"))
+       (indent-to column)
+       (insert (format "#+end_%s" (car (split-string type))))
+       (if (looking-at "[ \t]*$") (replace-match "")
+         (insert "\n"))
+       (when (and (eobp) (not (bolp))) (insert "\n")))
+      (if extended? (end-of-line)
+       (forward-line)
+       (skip-chars-forward " \t")))))
 
-(defun org-complete-expand-structure-template (start cell)
-  "Expand a structure template."
-  (let ((rpl (nth 1 cell))
-       (ind ""))
-    (delete-region start (point))
-    (when (string-match "\\`[ \t]*#\\+" rpl)
-      (cond
-       ((bolp))
-       ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
-       (setq ind (buffer-substring (point-at-bol) (point))))
-       (t (newline))))
-    (setq start (point))
-    (when (string-match "%file" rpl)
-      (setq rpl (replace-match
-                (concat
-                 "\""
-                 (save-match-data
-                   (abbreviate-file-name (read-file-name "Include file: ")))
-                 "\"")
-                t t rpl)))
-    (setq rpl (mapconcat 'identity (split-string rpl "\n")
-                        (concat "\n" ind)))
-    (insert rpl)
-    (when (re-search-backward "\\?" start t) (delete-char 1))))
 
 ;;;; TODO, DEADLINE, Comments
 
@@ -12282,8 +9939,6 @@ expands them."
 If the last change removed the TODO tag or switched to DONE, then
 this is nil.")
 
-(defvar org-setting-tags nil) ; dynamically skipped
-
 (defvar org-todo-setup-filter-hook nil
   "Hook for functions that pre-filter todo specs.
 Each function takes a todo spec and returns either nil or the spec
@@ -12353,15 +10008,20 @@ By default the available states are \"TODO\" and 
\"DONE\".  So, for this
 example: when the item starts with TODO, it is changed to DONE.
 When it starts with DONE, the DONE is removed.  And when neither TODO nor
 DONE are present, add TODO at the beginning of the heading.
+You can set up single-charcter keys to fast-select the new state.  See the
+`org-todo-keywords' and `org-use-fast-todo-selection' for details.
 
-With `\\[universal-argument]' prefix ARG, use completion to determine the new \
-state.
-With numeric prefix ARG, switch to that state.
+With `\\[universal-argument]' prefix ARG, force logging the state change \
+and take a
+logging note.
 With a `\\[universal-argument] \\[universal-argument]' prefix, switch to the \
 next set of TODO \
 keywords (nextset).
+Another way to achieve this is `S-C-<right>'.
 With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' \
 prefix, circumvent any state blocking.
+With numeric prefix arg, switch to the Nth state.
+
 With a numeric prefix arg of 0, inhibit note taking for the change.
 With a numeric prefix arg of -1, cancel repeater to allow marking as DONE.
 
@@ -12404,6 +10064,7 @@ When called through ELisp, arg is also interpreted in 
the following way:
              (looking-at "\\(?: *\\|[ \t]*$\\)"))
          (let* ((match-data (match-data))
                 (startpos (copy-marker (line-beginning-position)))
+                (force-log (and  (equal arg '(4)) (prog1 t (setq arg nil))))
                 (logging (save-match-data (org-entry-get nil "LOGGING" t t)))
                 (org-log-done org-log-done)
                 (org-log-repeat org-log-repeat)
@@ -12423,34 +10084,19 @@ When called through ELisp, arg is also interpreted in 
the following way:
                 (member (member this org-todo-keywords-1))
                 (tail (cdr member))
                 (org-state (cond
-                            ((and org-todo-key-trigger
-                                  (or (and (equal arg '(4))
-                                           (eq org-use-fast-todo-selection 
'prefix))
-                                      (and (not arg) 
org-use-fast-todo-selection
-                                           (not (eq org-use-fast-todo-selection
-                                                    'prefix)))))
-                             ;; Use fast selection.
-                             (org-fast-todo-selection))
-                            ((and (equal arg '(4))
-                                  (or (not org-use-fast-todo-selection)
-                                      (not org-todo-key-trigger)))
-                             ;; Read a state with completion.
-                             (completing-read
-                              "State: " (mapcar #'list org-todo-keywords-1)
-                              nil t))
                             ((eq arg 'right)
+                             ;; Next state
                              (if this
                                  (if tail (car tail) nil)
                                (car org-todo-keywords-1)))
                             ((eq arg 'left)
+                             ;; Previous state
                              (unless (equal member org-todo-keywords-1)
                                (if this
                                    (nth (- (length org-todo-keywords-1)
                                            (length tail) 2)
                                         org-todo-keywords-1)
                                  (org-last org-todo-keywords-1))))
-                            ((and (eq org-use-fast-todo-selection t) (equal 
arg '(4))
-                                  (setq arg nil))) ;hack to fall back to 
cycling
                             (arg
                              ;; User or caller requests a specific state.
                              (cond
@@ -12469,6 +10115,9 @@ When called through ELisp, arg is also interpreted in 
the following way:
                                (user-error "State `%s' not valid in this file" 
arg))
                               ((nth (1- (prefix-numeric-value arg))
                                     org-todo-keywords-1))))
+                            ((and org-todo-key-trigger 
org-use-fast-todo-selection)
+                             ;; Use fast selection.
+                             (org-fast-todo-selection this))
                             ((null member) (or head (car org-todo-keywords-1)))
                             ((equal this final-done-word) nil) ;-> make empty
                             ((null tail) nil) ;-> first entry
@@ -12484,7 +10133,7 @@ When called through ELisp, arg is also interpreted in 
the following way:
                             (run-hook-with-args-until-success
                              'org-todo-get-default-hook org-state 
org-last-state)
                             org-state))
-                (next (if org-state (concat " " org-state " ") " "))
+                (next (if (org-string-nw-p org-state) (concat " " org-state " 
") " "))
                 (change-plist (list :type 'todo-state-change :from this :to 
org-state
                                     :position startpos))
                 dolog now-done-p)
@@ -12530,11 +10179,13 @@ When called through ELisp, arg is also interpreted in 
the following way:
            (setq now-done-p (and (member org-state org-done-keywords)
                                  (not (member this org-done-keywords))))
            (and logging (org-local-logging logging))
-           (when (and (or org-todo-log-states org-log-done)
-                      (not (eq org-inhibit-logging t))
-                      (not (memq arg '(nextset previousset))))
+           (when (or (and (or org-todo-log-states org-log-done)
+                          (not (eq org-inhibit-logging t))
+                          (not (memq arg '(nextset previousset))))
+                     force-log)
              ;; We need to look at recording a time and note.
-             (setq dolog (or (nth 1 (assoc org-state org-todo-log-states))
+             (setq dolog (or (if force-log 'note)
+                             (nth 1 (assoc org-state org-todo-log-states))
                              (nth 2 (assoc this org-todo-log-states))))
              (when (and (eq dolog 'note) (eq org-inhibit-logging 'note))
                (setq dolog 'time))
@@ -12555,9 +10206,11 @@ When called through ELisp, arg is also interpreted in 
the following way:
                (org-add-log-setup 'state org-state this dolog)))
            ;; Fixup tag positioning.
            (org-todo-trigger-tag-changes org-state)
-           (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil 
t))
+           (when org-auto-align-tags (org-align-tags))
            (when org-provide-todo-statistics
              (org-update-parent-todo-statistics))
+           (when (bound-and-true-p org-clock-out-when-done)
+             (org-clock-out-if-current))
            (run-hooks 'org-after-todo-state-change-hook)
            (when (and arg (not (member org-state org-done-keywords)))
              (setq head (org-get-todo-sequence-head org-state)))
@@ -12577,7 +10230,9 @@ When called through ELisp, arg is also interpreted in 
the following way:
                                       (looking-at org-todo-line-regexp))
                       (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
              (goto-char (or (match-end 2) (match-end 1)))
-             (and (looking-at " ") (just-one-space)))
+             (and (looking-at " ")
+                  (not (looking-at " *:"))
+                  (just-one-space)))
            (when org-trigger-hook
              (save-excursion
                (run-hook-with-args 'org-trigger-hook change-plist)))
@@ -12934,25 +10589,31 @@ right sequence."
       (car org-todo-keywords-1))
      (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
 
-(defun org-fast-todo-selection ()
+(defun org-fast-todo-selection (&optional current-state)
   "Fast TODO keyword selection with single keys.
-Returns the new TODO keyword, or nil if no state change should occur."
+Returns the new TODO keyword, or nil if no state change should occur.
+When CURRENT-STATE is given and selection letters are not unique globally,
+prefer a state in the current sequence over on in another sequence."
   (let* ((fulltable org-todo-key-alist)
+        (head (org-get-todo-sequence-head current-state))
         (done-keywords org-done-keywords) ;; needed for the faces.
         (maxlen (apply 'max (mapcar
                              (lambda (x)
                                (if (stringp (car x)) (string-width (car x)) 0))
                              fulltable)))
-        (expert nil)
+        (expert (equal org-use-fast-todo-selection 'expert))
+        (prompt "")
         (fwidth (+ maxlen 3 1 3))
         (ncol (/ (- (window-width) 4) fwidth))
-        tg cnt e c tbl
-        groups ingroup)
+        tg cnt e c tbl subtable
+        groups ingroup in-current-sequence)
     (save-excursion
       (save-window-excursion
        (if expert
            (set-buffer (get-buffer-create " *Org todo*"))
-         (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
+         (delete-other-windows)
+         (set-window-buffer (split-window-vertically) (get-buffer-create " 
*Org todo*"))
+         (org-switch-to-buffer-other-window " *Org todo*"))
        (erase-buffer)
        (setq-local org-done-keywords done-keywords)
        (setq tbl fulltable cnt 0)
@@ -12963,9 +10624,11 @@ Returns the new TODO keyword, or nil if no state 
change should occur."
            (unless (= cnt 0)
              (setq cnt 0)
              (insert "\n"))
+           (setq prompt (concat prompt "{"))
            (insert "{ "))
           ((equal e '(:endgroup))
-           (setq ingroup nil cnt 0)
+           (setq ingroup nil cnt 0 in-current-sequence nil)
+           (setq prompt (concat prompt "}"))
            (insert "}\n"))
           ((equal e '(:newline))
            (unless (= cnt 0)
@@ -12977,27 +10640,35 @@ Returns the new TODO keyword, or nil if no state 
change should occur."
                (setq tbl (cdr tbl)))))
           (t
            (setq tg (car e) c (cdr e))
+           (if (equal tg head) (setq in-current-sequence t))
            (when ingroup (push tg (car groups)))
+           (when in-current-sequence (push e subtable))
            (setq tg (org-add-props tg nil 'face
                                    (org-get-todo-face tg)))
            (when (and (= cnt 0) (not ingroup)) (insert "  "))
+           (setq prompt (concat prompt "[" (char-to-string c) "] " tg " "))
            (insert "[" c "] " tg (make-string
                                   (- fwidth 4 (length tg)) ?\ ))
-           (when (= (setq cnt (1+ cnt)) ncol)
+           (when (and (= (setq cnt (1+ cnt)) ncol)
+                      ;; Avoid lines with just a closing delimiter.
+                      (not (equal (car tbl) '(:endgroup))))
              (insert "\n")
              (when ingroup (insert "  "))
              (setq cnt 0)))))
        (insert "\n")
        (goto-char (point-min))
        (unless expert (org-fit-window-to-buffer))
-       (message "[a-z..]:Set [SPC]:clear")
+       (message (concat "[a-z..]:Set [SPC]:clear"
+                        (if expert (concat "\n" prompt) "")))
        (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
+       (setq subtable (nreverse subtable))
        (cond
         ((or (= c ?\C-g)
              (and (= c ?q) (not (rassoc c fulltable))))
          (setq quit-flag t))
         ((= c ?\ ) nil)
-        ((setq e (rassoc c fulltable) tg (car e))
+        ((setq e (or (rassoc c subtable) (rassoc c fulltable))
+               tg (car e))
          tg)
         (t (setq quit-flag t)))))))
 
@@ -13084,114 +10755,109 @@ This function is run automatically after each state 
change to a DONE state."
         (org-log-done nil)
         (org-todo-log-states nil)
         (end (copy-marker (org-entry-end-position))))
-    (unwind-protect
-       (when (and repeat (not (zerop (string-to-number (substring repeat 1)))))
-         (when (eq org-log-repeat t) (setq org-log-repeat 'state))
-         (let ((to-state (or (org-entry-get nil "REPEAT_TO_STATE" 'selective)
-                             org-todo-repeat-to-state)))
-           (org-todo (cond
-                      ((and to-state (member to-state org-todo-keywords-1))
-                       to-state)
-                      ((eq interpret 'type) org-last-state)
-                      (head)
-                      (t 'none))))
-         (org-back-to-heading t)
-         (org-add-planning-info nil nil 'closed)
-         ;; When `org-log-repeat' is non-nil or entry contains
-         ;; a clock, set LAST_REPEAT property.
-         (when (or org-log-repeat
-                   (catch :clock
-                     (save-excursion
-                       (while (re-search-forward org-clock-line-re end t)
-                         (when (org-at-clock-log-p) (throw :clock t))))))
-           (org-entry-put nil "LAST_REPEAT" (format-time-string
-                                             (org-time-stamp-format t t))))
-         (when org-log-repeat
-           (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
-                   (memq 'org-add-log-note post-command-hook))
-               ;; We are already setup for some record.
-               (when (eq org-log-repeat 'note)
-                 ;; Make sure we take a note, not only a time stamp.
-                 (setq org-log-note-how 'note))
-             ;; Set up for taking a record.
-             (org-add-log-setup 'state
-                                (or done-word (car org-done-keywords))
-                                org-last-state
-                                org-log-repeat)))
-         (let ((planning-re (regexp-opt
-                             (list org-scheduled-string org-deadline-string))))
-           (while (re-search-forward org-ts-regexp end t)
-             (let* ((ts (match-string 0))
-                    (planning? (org-at-planning-p))
-                    (type (if (not planning?) "Plain:"
-                            (save-excursion
-                              (re-search-backward
-                               planning-re (line-beginning-position) t)
-                              (match-string 0)))))
-               (cond
-                ;; Ignore fake time-stamps (e.g., within comments).
-                ((not (org-at-timestamp-p 'agenda)))
-                ;; Time-stamps without a repeater are usually
-                ;; skipped.  However, a SCHEDULED time-stamp without
-                ;; one is removed, as they are no longer relevant.
-                ((not (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)"
-                                    ts))
-                 (when (equal type org-scheduled-string)
-                   (org-remove-timestamp-with-keyword type)))
-                (t
-                 (let ((n (string-to-number (match-string 2 ts)))
-                       (what (match-string 3 ts)))
-                   (when (equal what "w") (setq n (* n 7) what "d"))
-                   (when (and (equal what "h")
-                              (not (string-match-p 
"[0-9]\\{1,2\\}:[0-9]\\{2\\}"
-                                                   ts)))
-                     (user-error
-                      "Cannot repeat in Repeat in %d hour(s) because no hour \
-has been set"
-                      n))
-                   ;; Preparation, see if we need to modify the start
-                   ;; date for the change.
-                   (when (match-end 1)
-                     (let ((time (save-match-data
-                                   (org-time-string-to-time ts))))
-                       (cond
-                        ((equal (match-string 1 ts) ".")
-                         ;; Shift starting date to today
-                         (org-timestamp-change
-                          (- (org-today) (time-to-days time))
-                          'day))
-                        ((equal (match-string 1 ts) "+")
-                         (let ((nshiftmax 10)
-                               (nshift 0))
-                           (while (or (= nshift 0)
-                                      (not (time-less-p nil time)))
-                             (when (= (cl-incf nshift) nshiftmax)
-                               (or (y-or-n-p
-                                    (format "%d repeater intervals were not \
+    (when (and repeat (not (= 0 (string-to-number (substring repeat 1)))))
+      (when (eq org-log-repeat t) (setq org-log-repeat 'state))
+      (let ((to-state (or (org-entry-get nil "REPEAT_TO_STATE" 'selective)
+                         (and (stringp org-todo-repeat-to-state)
+                              org-todo-repeat-to-state)
+                         (and org-todo-repeat-to-state org-last-state))))
+       (org-todo (cond ((and to-state (member to-state org-todo-keywords-1))
+                        to-state)
+                       ((eq interpret 'type) org-last-state)
+                       (head)
+                       (t 'none))))
+      (org-back-to-heading t)
+      (org-add-planning-info nil nil 'closed)
+      ;; When `org-log-repeat' is non-nil or entry contains
+      ;; a clock, set LAST_REPEAT property.
+      (when (or org-log-repeat
+               (catch :clock
+                 (save-excursion
+                   (while (re-search-forward org-clock-line-re end t)
+                     (when (org-at-clock-log-p) (throw :clock t))))))
+       (org-entry-put nil "LAST_REPEAT" (format-time-string
+                                         (org-time-stamp-format t t))))
+      (when org-log-repeat
+       (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
+               (memq 'org-add-log-note post-command-hook))
+           ;; We are already setup for some record.
+           (when (eq org-log-repeat 'note)
+             ;; Make sure we take a note, not only a time stamp.
+             (setq org-log-note-how 'note))
+         ;; Set up for taking a record.
+         (org-add-log-setup 'state
+                            (or done-word (car org-done-keywords))
+                            org-last-state
+                            org-log-repeat)))
+      ;; Time-stamps without a repeater are usually skipped.  However,
+      ;; a SCHEDULED time-stamp without one is removed, as they are no
+      ;; longer relevant.
+      (save-excursion
+       (let ((scheduled (org-entry-get (point) "SCHEDULED")))
+         (when (and scheduled (not (string-match-p org-repeat-re scheduled)))
+           (org-remove-timestamp-with-keyword org-scheduled-string))))
+      ;; Update every time-stamp with a repeater in the entry.
+      (let ((planning-re (regexp-opt
+                         (list org-scheduled-string org-deadline-string))))
+       (while (re-search-forward org-repeat-re end t)
+         (let* ((ts (match-string 0))
+                (type (if (not (org-at-planning-p)) "Plain:"
+                        (save-excursion
+                          (re-search-backward
+                           planning-re (line-beginning-position) t)
+                          (match-string 0)))))
+           (when (and (org-at-timestamp-p 'agenda)
+                      (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" 
ts))
+             (let ((n (string-to-number (match-string 2 ts)))
+                   (what (match-string 3 ts)))
+               (when (equal what "w") (setq n (* n 7) what "d"))
+               (when (and (equal what "h")
+                          (not (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}"
+                                               ts)))
+                 (user-error
+                  "Cannot repeat in %d hour(s) because no hour has been set"
+                  n))
+               ;; Preparation, see if we need to modify the start
+               ;; date for the change.
+               (when (match-end 1)
+                 (let ((time (save-match-data (org-time-string-to-time ts)))
+                       (repeater-type (match-string 1 ts)))
+                   (cond
+                    ((equal "." repeater-type)
+                     ;; Shift starting date to today.
+                     (org-timestamp-change (- (org-today) (time-to-days time))
+                                           'day))
+                    ((equal "+" repeater-type)
+                     (let ((nshiftmax 10)
+                           (nshift 0))
+                       (while (or (= nshift 0)
+                                  (not (org-time-less-p nil time)))
+                         (when (= nshiftmax (cl-incf nshift))
+                           (or (y-or-n-p
+                                (format "%d repeater intervals were not \
 enough to shift date past today.  Continue? "
-                                            nshift))
-                                   (user-error "Abort")))
-                             (org-timestamp-change n (cdr (assoc what whata)))
-                             (org-in-regexp org-ts-regexp3)
-                             (setq ts (match-string 1))
-                             (setq time
-                                   (save-match-data
-                                     (org-time-string-to-time ts)))))
-                         (org-timestamp-change (- n) (cdr (assoc what whata)))
-                         ;; Rematch, so that we have everything in place
-                         ;; for the real shift.
+                                        nshift))
+                               (user-error "Abort")))
+                         (org-timestamp-change n (cdr (assoc what whata)))
                          (org-in-regexp org-ts-regexp3)
                          (setq ts (match-string 1))
-                         (string-match 
"\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)"
-                                       ts)))))
-                   (save-excursion
-                     (org-timestamp-change n (cdr (assoc what whata)) nil t))
-                   (setq msg
-                         (concat
-                          msg type " " org-last-changed-timestamp " "))))))))
-         (setq org-log-post-message msg)
-         (message "%s" msg))
-      (set-marker end nil))))
+                         (setq time
+                               (save-match-data
+                                 (org-time-string-to-time ts)))))
+                     (org-timestamp-change (- n) (cdr (assoc what whata)))
+                     ;; Rematch, so that we have everything in place
+                     ;; for the real shift.
+                     (org-in-regexp org-ts-regexp3)
+                     (setq ts (match-string 1))
+                     (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)"
+                                   ts)))))
+               (save-excursion
+                 (org-timestamp-change n (cdr (assoc what whata)) nil t))
+               (setq msg
+                     (concat msg type " " org-last-changed-timestamp " ")))))))
+      (run-hooks 'org-todo-repeat-hook)
+      (setq org-log-post-message msg)
+      (message msg))))
 
 (defun org-show-todo-tree (arg)
   "Make a compact tree which shows all headlines marked with TODO.
@@ -13203,7 +10869,7 @@ of `org-todo-keywords-1'."
   (interactive "P")
   (let ((case-fold-search nil)
        (kwd-re
-        (cond ((null arg) org-not-done-regexp)
+        (cond ((null arg) (concat org-not-done-regexp "\\s-"))
               ((equal arg '(4))
                (let ((kwd
                       (completing-read "Keyword (or KWD1|KWD2|...): "
@@ -13243,12 +10909,15 @@ TYPE is either `deadline' or `scheduled'.  See 
`org-deadline' or
                            (match-string 1 old-date)))))
     (pcase arg
       (`(4)
-       (when (and old-date log)
-        (org-add-log-setup (if deadline? 'deldeadline 'delschedule)
-                           nil old-date log))
-       (org-remove-timestamp-with-keyword keyword)
-       (message (if deadline? "Item no longer has a deadline."
-                 "Item is no longer scheduled.")))
+       (if (not old-date)
+          (message (if deadline? "Entry had no deadline to remove"
+                     "Entry was not scheduled"))
+        (when (and old-date log)
+          (org-add-log-setup (if deadline? 'deldeadline 'delschedule)
+                             nil old-date log))
+        (org-remove-timestamp-with-keyword keyword)
+        (message (if deadline? "Entry no longer has a deadline."
+                   "Entry is no longer scheduled."))))
       (`(16)
        (save-excursion
         (org-back-to-heading t)
@@ -13413,9 +11082,12 @@ WHAT entry will also be removed."
                         (org-read-date-analyze
                          time default-time (decode-time default-time)))
                ;; If necessary, get the time from the user
-               (or time (org-read-date nil 'to-time nil nil
+               (or time (org-read-date nil 'to-time nil
+                                       (cl-case what
+                                         (deadline "DEADLINE")
+                                         (scheduled "SCHEDULED")
+                                         (otherwise nil))
                                        default-time default-input)))))
-
       (org-with-wide-buffer
        (org-back-to-heading t)
        (forward-line)
@@ -13527,7 +11199,9 @@ narrowing."
             (unless (bolp) (insert "\n"))
             (let ((beg (point)))
               (insert ":" drawer ":\n:END:\n")
-              (org-indent-region beg (point)))
+              (org-indent-region beg (point))
+              (org-flag-region
+               (line-end-position -1) (1- (point)) t 'org-hide-drawer))
             (end-of-line -1)))))
       (t
        (org-end-of-meta-data org-log-state-notes-insert-after-drawers)
@@ -13566,8 +11240,8 @@ EXTRA is additional text that will be inserted into the 
notes buffer."
                      (regexp-quote (cdr (assq 'state org-log-note-headings)))
                      `(("%d" . ,org-ts-regexp-inactive)
                        ("%D" . ,org-ts-regexp)
-                       ("%s" . "\"\\S-+\"")
-                       ("%S" . "\"\\S-+\"")
+                       ("%s" . "\\(?:\"\\S-+\"\\)?")
+                       ("%S" . "\\(?:\"\\S-+\"\\)?")
                        ("%t" . ,org-ts-regexp-inactive)
                        ("%T" . ,org-ts-regexp)
                        ("%u" . ".*?")
@@ -13591,26 +11265,20 @@ EXTRA is additional text that will be inserted into 
the notes buffer."
     (let ((org-inhibit-startup t)) (org-mode))
     (insert (format "# Insert note for %s.
 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
-                   (cond
-                    ((eq org-log-note-purpose 'clock-out) "stopped clock")
-                    ((eq org-log-note-purpose 'done)  "closed todo item")
-                    ((eq org-log-note-purpose 'state)
-                     (format "state change from \"%s\" to \"%s\""
-                             (or org-log-note-previous-state "")
-                             (or org-log-note-state "")))
-                    ((eq org-log-note-purpose 'reschedule)
-                     "rescheduling")
-                    ((eq org-log-note-purpose 'delschedule)
-                     "no longer scheduled")
-                    ((eq org-log-note-purpose 'redeadline)
-                     "changing deadline")
-                    ((eq org-log-note-purpose 'deldeadline)
-                     "removing deadline")
-                    ((eq org-log-note-purpose 'refile)
-                     "refiling")
-                    ((eq org-log-note-purpose 'note)
-                     "this entry")
-                    (t (error "This should not happen")))))
+                   (cl-case org-log-note-purpose
+                     (clock-out "stopped clock")
+                     (done  "closed todo item")
+                     (reschedule "rescheduling")
+                     (delschedule "no longer scheduled")
+                     (redeadline "changing deadline")
+                     (deldeadline "removing deadline")
+                     (refile "refiling")
+                     (note "this entry")
+                     (state
+                      (format "state change from \"%s\" to \"%s\""
+                              (or org-log-note-previous-state "")
+                              (or org-log-note-state "")))
+                     (t (error "This should not happen")))))
     (when org-log-note-extra (insert org-log-note-extra))
     (setq-local org-finish-function 'org-store-log-note)
     (run-hooks 'org-log-buffer-setup-hook)))
@@ -13693,8 +11361,7 @@ EXTRA is additional text that will be inserted into the 
notes buffer."
             (indent-line-to ind)
             (insert line)))
         (message "Note stored")
-        (org-back-to-heading t)
-        (org-cycle-hide-drawers 'children))
+        (org-back-to-heading t))
        ;; Fix `buffer-undo-list' when `org-store-log-note' is called
        ;; from within `org-add-log-note' because `buffer-undo-list'
        ;; is then modified outside of `org-with-remote-undo'.
@@ -13812,125 +11479,57 @@ The function must neither move point nor alter 
narrowing."
     (org-remove-occur-highlights nil nil t))
   (push (cons regexp callback) org-occur-parameters)
   (let ((cnt 0))
-    (save-excursion
-      (goto-char (point-min))
-      (when (or (not keep-previous)        ; do not want to keep
-               (not org-occur-highlights)) ; no previous matches
-       ;; hide everything
-       (org-overview))
-      (let ((case-fold-search (if (eq org-occur-case-fold-search 'smart)
-                                 (isearch-no-upper-case-p regexp t)
-                               org-occur-case-fold-search)))
-       (while (re-search-forward regexp nil t)
-         (when (or (not callback)
-                   (save-match-data (funcall callback)))
-           (setq cnt (1+ cnt))
-           (when org-highlight-sparse-tree-matches
-             (org-highlight-new-match (match-beginning 0) (match-end 0)))
-           (org-show-context 'occur-tree)))))
-    (when org-remove-highlights-with-change
-      (add-hook 'before-change-functions 'org-remove-occur-highlights
-               nil 'local))
-    (unless org-sparse-tree-open-archived-trees
-      (org-hide-archived-subtrees (point-min) (point-max)))
-    (run-hooks 'org-occur-hook)
-    (when (called-interactively-p 'interactive)
-      (message "%d match(es) for regexp %s" cnt regexp))
-    cnt))
-
-(defun org-occur-next-match (&optional n _reset)
-  "Function for `next-error-function' to find sparse tree matches.
-N is the number of matches to move, when negative move backwards.
-This function always goes back to the starting point when no
-match is found."
-  (let* ((limit (if (< n 0) (point-min) (point-max)))
-        (search-func (if (< n 0)
-                         'previous-single-char-property-change
-                       'next-single-char-property-change))
-        (n (abs n))
-        (pos (point))
-        p1)
-    (catch 'exit
-      (while (setq p1 (funcall search-func (point) 'org-type))
-       (when (equal p1 limit)
-         (goto-char pos)
-         (user-error "No more matches"))
-       (when (equal (get-char-property p1 'org-type) 'org-occur)
-         (setq n (1- n))
-         (when (= n 0)
-           (goto-char p1)
-           (throw 'exit (point))))
-       (goto-char p1))
-      (goto-char p1)
-      (user-error "No more matches"))))
-
-(defun org-show-context (&optional key)
-  "Make sure point and context are visible.
-Optional argument KEY, when non-nil, is a symbol.  See
-`org-show-context-detail' for allowed values and how much is to
-be shown."
-  (org-show-set-visibility
-   (cond ((symbolp org-show-context-detail) org-show-context-detail)
-        ((cdr (assq key org-show-context-detail)))
-        (t (cdr (assq 'default org-show-context-detail))))))
-
-(defun org-show-set-visibility (detail)
-  "Set visibility around point according to DETAIL.
-DETAIL is either nil, `minimal', `local', `ancestors', `lineage',
-`tree', `canonical' or t.  See `org-show-context-detail' for more
-information."
-  ;; Show current heading and possibly its entry, following headline
-  ;; or all children.
-  (if (and (org-at-heading-p) (not (eq detail 'local)))
-      (org-flag-heading nil)
-    (org-show-entry)
-    ;; If point is hidden within a drawer or a block, make sure to
-    ;; expose it.
-    (dolist (o (overlays-at (point)))
-      (when (memq (overlay-get o 'invisible) '(org-hide-block outline))
-       (delete-overlay o)))
-    (unless (org-before-first-heading-p)
-      (org-with-limited-levels
-       (cl-case detail
-        ((tree canonical t) (org-show-children))
-        ((nil minimal ancestors))
-        (t (save-excursion
-             (outline-next-heading)
-             (org-flag-heading nil)))))))
-  ;; Show all siblings.
-  (when (eq detail 'lineage) (org-show-siblings))
-  ;; Show ancestors, possibly with their children.
-  (when (memq detail '(ancestors lineage tree canonical t))
-    (save-excursion
-      (while (org-up-heading-safe)
-       (org-flag-heading nil)
-       (when (memq detail '(canonical t)) (org-show-entry))
-       (when (memq detail '(tree canonical t)) (org-show-children))))))
-
-(defvar org-reveal-start-hook nil
-  "Hook run before revealing a location.")
-
-(defun org-reveal (&optional siblings)
-  "Show current entry, hierarchy above it, and the following headline.
-
-This can be used to show a consistent set of context around
-locations exposed with `org-show-context'.
-
-With optional argument SIBLINGS, on each level of the hierarchy all
-siblings are shown.  This repairs the tree structure to what it would
-look like when opened with hierarchical calls to `org-cycle'.
+    (save-excursion
+      (goto-char (point-min))
+      (when (or (not keep-previous)        ; do not want to keep
+               (not org-occur-highlights)) ; no previous matches
+       ;; hide everything
+       (org-overview))
+      (let ((case-fold-search (if (eq org-occur-case-fold-search 'smart)
+                                 (isearch-no-upper-case-p regexp t)
+                               org-occur-case-fold-search)))
+       (while (re-search-forward regexp nil t)
+         (when (or (not callback)
+                   (save-match-data (funcall callback)))
+           (setq cnt (1+ cnt))
+           (when org-highlight-sparse-tree-matches
+             (org-highlight-new-match (match-beginning 0) (match-end 0)))
+           (org-show-context 'occur-tree)))))
+    (when org-remove-highlights-with-change
+      (add-hook 'before-change-functions 'org-remove-occur-highlights
+               nil 'local))
+    (unless org-sparse-tree-open-archived-trees
+      (org-hide-archived-subtrees (point-min) (point-max)))
+    (run-hooks 'org-occur-hook)
+    (when (called-interactively-p 'interactive)
+      (message "%d match(es) for regexp %s" cnt regexp))
+    cnt))
 
-With a \\[universal-argument] \\[universal-argument] prefix, \
-go to the parent and show the entire tree."
-  (interactive "P")
-  (run-hooks 'org-reveal-start-hook)
-  (cond ((equal siblings '(4)) (org-show-set-visibility 'canonical))
-       ((equal siblings '(16))
-        (save-excursion
-          (when (org-up-heading-safe)
-            (org-show-subtree)
-            (run-hook-with-args 'org-cycle-hook 'subtree))))
-       (t (org-show-set-visibility 'lineage))))
+(defun org-occur-next-match (&optional n _reset)
+  "Function for `next-error-function' to find sparse tree matches.
+N is the number of matches to move, when negative move backwards.
+This function always goes back to the starting point when no
+match is found."
+  (let* ((limit (if (< n 0) (point-min) (point-max)))
+        (search-func (if (< n 0)
+                         'previous-single-char-property-change
+                       'next-single-char-property-change))
+        (n (abs n))
+        (pos (point))
+        p1)
+    (catch 'exit
+      (while (setq p1 (funcall search-func (point) 'org-type))
+       (when (equal p1 limit)
+         (goto-char pos)
+         (user-error "No more matches"))
+       (when (equal (get-char-property p1 'org-type) 'org-occur)
+         (setq n (1- n))
+         (when (= n 0)
+           (goto-char p1)
+           (throw 'exit (point))))
+       (goto-char p1))
+      (goto-char p1)
+      (user-error "No more matches"))))
 
 (defun org-highlight-new-match (beg end)
   "Highlight from BEG to END and mark the highlight is an occur headline."
@@ -13969,10 +11568,19 @@ from the `before-change-functions' in the current 
buffer."
   (interactive)
   (org-priority 'down))
 
-(defun org-priority (&optional action _show)
+(defun org-priority (&optional action show)
   "Change the priority of an item.
-ACTION can be `set', `up', `down', or a character."
+
+When called interactively with a `\\[universal-argument]' prefix,
+show the priority in the minibuffer instead of changing it.
+
+When called programmatically, ACTION can be `set', `up', `down',
+or a character."
   (interactive "P")
+  (when show
+    ;; Deprecation warning inserted for Org 9.2; once enough time has
+    ;; passed the SHOW argument should be removed.
+    (warn "`org-priority' called with deprecated SHOW argument"))
   (if (equal action '(4))
       (org-show-priority)
     (unless org-enable-priority-commands
@@ -13998,7 +11606,7 @@ ACTION can be `set', `up', `down', or a character."
          (when (and (= (upcase org-highest-priority) org-highest-priority)
                     (= (upcase org-lowest-priority) org-lowest-priority))
            (setq new (upcase new)))
-         (cond ((equal new ?\ ) (setq remove t))
+         (cond ((equal new ?\s) (setq remove t))
                ((or (< (upcase new) org-highest-priority) (> (upcase new) 
org-lowest-priority))
                 (user-error "Priority must be between `%c' and `%c'"
                             org-highest-priority org-lowest-priority))))
@@ -14047,7 +11655,7 @@ ACTION can be `set', `up', `down', or a character."
                  (insert " [#" news "]"))
              (goto-char (match-beginning 3))
              (insert "[#" news "] "))))
-       (org-set-tags nil 'align))
+       (org-align-tags))
       (if remove
          (message "Priority removed")
        (message "Priority of current item set to %s" news)))))
@@ -14070,7 +11678,7 @@ and by additional input from the age of a schedules or 
deadline entry."
   "Find priority cookie and return priority."
   (save-match-data
     (if (functionp org-get-priority-function)
-       (funcall org-get-priority-function)
+       (funcall org-get-priority-function s)
       (if (not (string-match org-priority-regexp s))
          (* 1000 (- org-lowest-priority org-default-priority))
        (* 1000 (- org-lowest-priority
@@ -14087,9 +11695,9 @@ Can be set by the action argument to `org-scan-tags' 
and `org-map-entries'.")
   "The current tag list while the tags scanner is running.")
 
 (defvar org-trust-scanner-tags nil
-  "Should `org-get-tags-at' use the tags for the scanner.
+  "Should `org-get-tags' use the tags for the scanner.
 This is for internal dynamical scoping only.
-When this is non-nil, the function `org-get-tags-at' will return the value
+When this is non-nil, the function `org-get-tags' will return the value
 of `org-scanner-tags' instead of building the list by itself.  This
 can lead to large speed-ups when the tags scanner is used in a file with
 many entries, and when the list of tags is retrieved, for example to
@@ -14124,9 +11732,8 @@ headlines matching this string."
                         ;; Get the correct level to match
                         (concat "\\*\\{" (number-to-string start-level) "\\} ")
                       org-outline-regexp)
-                    " *\\(\\<\\("
-                    (mapconcat #'regexp-quote org-todo-keywords-1 "\\|")
-                    "\\)\\>\\)? *\\(.*?\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*$"))
+                    " *\\(" (regexp-opt org-todo-keywords-1 'words) "\\)?"
+                    " *\\(.*?\\)\\([ \t]:\\(?:" org-tag-re ":\\)+\\)?[ \t]*$"))
         (props (list 'face 'default
                      'done-face 'org-agenda-done
                      'undone-face 'default
@@ -14156,10 +11763,11 @@ headlines matching this string."
               (re-search-forward re nil t))
        (setq org-map-continue-from nil)
        (catch :skip
-         (setq todo
-               ;; TODO: is the 1-2 difference a bug?
-               (when (match-end 1) (match-string-no-properties 2))
-               tags (when (match-end 4) (match-string-no-properties 4)))
+         ;; Ignore closing parts of inline tasks.
+         (when (and (fboundp 'org-inlinetask-end-p) (org-inlinetask-end-p))
+           (throw :skip t))
+         (setq todo (and (match-end 1) (match-string-no-properties 1)))
+         (setq tags (and (match-end 4) (org-trim (match-string-no-properties 
4))))
          (goto-char (setq lspos (match-beginning 0)))
          (setq level (org-reduced-level (org-outline-level))
                category (org-get-category))
@@ -14331,7 +11939,7 @@ instead of the agenda files."
                  (mapcar
                   (lambda (file)
                     (set-buffer (find-file-noselect file))
-                    (org-tag-add-to-alist
+                    (org--tag-add-to-alist
                      (org-get-buffer-tags)
                      (mapcar (lambda (x)
                                (and (stringp (car-safe x))
@@ -14363,7 +11971,7 @@ See also `org-scan-tags'."
     ;; Get a new match request, with completion against the global
     ;; tags table and the local tags in current buffer.
     (let ((org-last-tags-completion-table
-          (org-tag-add-to-alist
+          (org--tag-add-to-alist
            (org-get-buffer-tags)
            (org-global-tags-completion-table))))
       (setq match
@@ -14372,7 +11980,12 @@ See also `org-scan-tags'."
             'org-tags-completion-function nil nil nil 'org-tags-history))))
 
   (let ((match0 match)
-       (re 
"^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@#%]+\\)")
+       (re (concat
+            "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)"
+            "\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)"
+            "\\([<>=]\\{1,2\\}\\)"
+            "\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)"
+            "\\|" org-tag-re "\\)"))
        (start 0)
        tagsmatch todomatch tagsmatcher todomatcher)
 
@@ -14441,7 +12054,7 @@ See also `org-scan-tags'."
                                                     (if timep 'time strp))))
                        (setq pv (if (or regexp strp) (substring pv 1 -1) pv))
                        (when timep (setq pv (org-matcher-time pv)))
-                       (cond ((and regexp (eq po 'org<>))
+                       (cond ((and regexp (eq po '/=))
                               `(not (string-match ,pv (or ,gv ""))))
                              (regexp `(string-match ,pv (or ,gv "")))
                              (strp `(,po (or ,gv "") ,pv))
@@ -14486,7 +12099,20 @@ See also `org-scan-tags'."
        (setq matcher `(and (member todo org-not-done-keywords) ,matcher)))
       (cons match0 `(lambda (todo tags-list level) ,matcher)))))
 
-(defun org-tags-expand (match &optional single-as-list downcased 
tags-already-expanded)
+(defun org--tags-expand-group (group tag-groups expanded)
+  "Recursively Expand all tags in GROUP, according to TAG-GROUPS.
+TAG-GROUPS is the list of groups used for expansion.  EXPANDED is
+an accumulator used in recursive calls."
+  (dolist (tag group)
+    (unless (member tag expanded)
+      (let ((group (assoc tag tag-groups)))
+       (push tag expanded)
+       (when group
+         (setq expanded
+               (org--tags-expand-group (cdr group) tag-groups expanded))))))
+  expanded)
+
+(defun org-tags-expand (match &optional single-as-list downcased)
   "Expand group tags in MATCH.
 
 This replaces every group tag in MATCH with a regexp tag search.
@@ -14503,7 +12129,7 @@ E.g., this expansion
   Work|Home => {\\(?:Work\\|Lab\\|Conf\\}|Home
 
 will match anything tagged with \"Lab\" and \"Home\", or tagged
-with \"Conf\" and \"Home\" or tagged with \"Work\" and \"home\".
+with \"Conf\" and \"Home\" or tagged with \"Work\" and \"Home\".
 
 A group tag in MATCH can contain regular expressions of its own.
 For example, a group tag \"Proj\" defined as { Proj : {P@.+} }
@@ -14515,240 +12141,78 @@ When the optional argument SINGLE-AS-LIST is 
non-nil, MATCH is
 assumed to be a single group tag, and the function will return
 the list of tags in this group.
 
-When DOWNCASE is non-nil, expand downcased TAGS."
-  (if org-group-tags
+When DOWNCASED is non-nil, expand downcased TAGS."
+  (unless (org-string-nw-p match) (error "Invalid match tag: %S" match))
+  (let ((tag-groups
+        (let ((g (or org-tag-groups-alist-for-agenda org-tag-groups-alist)))
+          (if (not downcased) g
+            (mapcar (lambda (s) (mapcar #'downcase s)) g)))))
+    (cond
+     (single-as-list (org--tags-expand-group (list match) tag-groups nil))
+     (org-group-tags
       (let* ((case-fold-search t)
-            (stable org-mode-syntax-table)
-            (taggroups (or org-tag-groups-alist-for-agenda 
org-tag-groups-alist))
-            (taggroups (if downcased
-                           (mapcar (lambda (tg) (mapcar #'downcase tg))
-                                   taggroups)
-                         taggroups))
-            (taggroups-keys (mapcar #'car taggroups))
-            (return-match (if downcased (downcase match) match))
-            (count 0)
-            (work-already-expanded tags-already-expanded)
-            regexps-in-match tags-in-group regexp-in-group 
regexp-in-group-escaped)
+            (tag-syntax org-mode-syntax-table)
+            (group-keys (mapcar #'car tag-groups))
+            (key-regexp (concat "\\([+-]?\\)" (regexp-opt group-keys 'words)))
+            (return-match (if downcased (downcase match) match)))
+       ;; Mark regexp-expressions in the match-expression so that we
+       ;; do not replace them later on.
+       (let ((s 0))
+         (while (string-match "{.+?}" return-match s)
+           (setq s (match-end 0))
+           (add-text-properties
+            (match-beginning 0) (match-end 0) '(regexp t) return-match)))
        ;; @ and _ are allowed as word-components in tags.
-       (modify-syntax-entry ?@ "w" stable)
-       (modify-syntax-entry ?_ "w" stable)
-       ;; Temporarily replace regexp-expressions in the match-expression.
-       (while (string-match "{.+?}" return-match)
-         (cl-incf count)
-         (push (match-string 0 return-match) regexps-in-match)
-         (setq return-match (replace-match (format "<%d>" count) t nil 
return-match)))
-       (while (and taggroups-keys
-                   (with-syntax-table stable
-                     (string-match
-                      (concat "\\(?1:[+-]?\\)\\(?2:\\<"
-                              (regexp-opt taggroups-keys) "\\>\\)")
-                      return-match)))
-         (let* ((dir (match-string 1 return-match))
-                (tag (match-string 2 return-match))
-                (tag (if downcased (downcase tag) tag)))
-           (unless (or (get-text-property 0 'grouptag (match-string 2 
return-match))
-                       (member tag tags-already-expanded))
-             (setq tags-in-group (assoc tag taggroups))
-             (push tag work-already-expanded)
-             ;; Recursively expand each tag in the group, if the tag hasn't
-             ;; already been expanded.  Restore the match-data after all 
recursive calls.
-             (save-match-data
-               (let (tags-expanded)
-                 (dolist (x (cdr tags-in-group))
-                   (if (and (member x taggroups-keys)
-                            (not (member x work-already-expanded)))
-                       (setq tags-expanded
-                             (delete-dups
-                              (append
-                               (org-tags-expand x t downcased
-                                                work-already-expanded)
-                               tags-expanded)))
-                     (setq tags-expanded
-                           (append (list x) tags-expanded)))
-                   (setq work-already-expanded
-                         (delete-dups
-                          (append tags-expanded
-                                  work-already-expanded))))
-                 (setq tags-in-group
-                       (delete-dups (cons (car tags-in-group)
-                                          tags-expanded)))))
-             ;; Filter tag-regexps from tags.
-             (setq regexp-in-group-escaped
-                   (delq nil (mapcar (lambda (x)
-                                       (if (stringp x)
-                                           (and (equal "{" (substring x 0 1))
-                                                (equal "}" (substring x -1))
-                                                x)
-                                         x))
-                                     tags-in-group))
-                   regexp-in-group
-                   (mapcar (lambda (x)
-                             (substring x 1 -1))
-                           regexp-in-group-escaped)
-                   tags-in-group
-                   (delq nil (mapcar (lambda (x)
-                                       (if (stringp x)
-                                           (and (not (equal "{" (substring x 0 
1)))
-                                                (not (equal "}" (substring x 
-1)))
-                                                x)
-                                         x))
-                                     tags-in-group)))
-             ;; If single-as-list, do no more in the while-loop.
-             (if (not single-as-list)
-                 (progn
-                   (when regexp-in-group
-                     (setq regexp-in-group
-                           (concat "\\|"
-                                   (mapconcat 'identity regexp-in-group
-                                              "\\|"))))
-                   (setq tags-in-group
-                         (concat dir
-                                 "{\\<"
-                                 (regexp-opt tags-in-group)
-                                 "\\>"
-                                 regexp-in-group
-                                 "}"))
-                   (when (stringp tags-in-group)
-                     (org-add-props tags-in-group '(grouptag t)))
-                   (setq return-match
-                         (replace-match tags-in-group t t return-match)))
-               (setq tags-in-group
-                     (append regexp-in-group-escaped tags-in-group))))
-           (setq taggroups-keys (delete tag taggroups-keys))))
-       ;; Add the regular expressions back into the match-expression again.
-       (while regexps-in-match
-         (setq return-match (replace-regexp-in-string (format "<%d>" count)
-                                                      (pop regexps-in-match)
-                                                      return-match t t))
-         (cl-decf count))
-       (if single-as-list
-           (if tags-in-group tags-in-group (list return-match))
-         return-match))
-    (if single-as-list
-       (list (if downcased (downcase match) match))
-      match)))
+       (modify-syntax-entry ?@ "w" tag-syntax)
+       (modify-syntax-entry ?_ "w" tag-syntax)
+       ;; For each tag token found in MATCH, compute a regexp and  it
+       (with-syntax-table tag-syntax
+         (replace-regexp-in-string
+          key-regexp
+          (lambda (m)
+            (if (get-text-property (match-beginning 2) 'regexp m)
+                m                      ;regexp tag: ignore
+              (let* ((operator (match-string 1 m))
+                     (tag-token (let ((tag (match-string 2 m)))
+                                  (list (if downcased (downcase tag) tag))))
+                     regexp-tags regular-tags)
+                ;; Partition tags between regexp and regular tags.
+                ;; Remove curly bracket syntax from regexp tags.
+                (dolist (tag (org--tags-expand-group tag-token tag-groups nil))
+                  (save-match-data
+                    (if (string-match "{\\(.+?\\)}" tag)
+                        (push (match-string 1 tag) regexp-tags)
+                      (push tag regular-tags))))
+                ;; Replace tag token by the appropriate regexp.
+                ;; Regular tags need to be regexp-quoted, whereas
+                ;; regexp-tags are inserted as-is.
+                (let ((regular (regexp-opt regular-tags))
+                      (regexp (mapconcat #'identity regexp-tags "\\|")))
+                  (concat operator
+                          (cond
+                           ((null regular-tags) (format "{%s}" regexp))
+                           ((null regexp-tags) (format "{\\<%s\\>}" regular))
+                           (t (format "{\\<%s\\>\\|%s}" regular regexp))))))))
+          return-match
+          t t))))
+     (t match))))
 
 (defun org-op-to-function (op &optional stringp)
   "Turn an operator into the appropriate function."
   (setq op
        (cond
-        ((equal  op   "<"       ) '(<     string<      org-time<))
+        ((equal  op   "<"       ) '(<     org-string<  org-time<))
         ((equal  op   ">"       ) '(>     org-string>  org-time>))
         ((member op '("<=" "=<")) '(<=    org-string<= org-time<=))
         ((member op '(">=" "=>")) '(>=    org-string>= org-time>=))
         ((member op '("="  "==")) '(=     string=      org-time=))
-        ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
+        ((member op '("<>" "!=")) '(/=    org-string<> org-time<>))))
   (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
 
-(defun org<> (a b) (not (= a b)))
-(defun org-string<= (a b) (or (string= a b) (string< a b)))
-(defun org-string>= (a b) (not (string< a b)))
-(defun org-string>  (a b) (and (not (string= a b)) (not (string< a b))))
-(defun org-string<> (a b) (not (string= a b)))
-(defun org-time=  (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 
0) (=     a b)))
-(defun org-time<  (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 
0) (<     a b)))
-(defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 
0) (<=    a b)))
-(defun org-time>  (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 
0) (>     a b)))
-(defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 
0) (>=    a b)))
-(defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 
0) (org<> a b)))
-(defun org-2ft (s)
-  "Convert S to a floating point time.
-If S is already a number, just return it.  If it is a string, parse
-it as a time string and apply `float-time' to it.  If S is nil, just return 0."
-  (cond
-   ((numberp s) s)
-   ((stringp s)
-    (condition-case nil
-       (float-time (org-time-string-to-time s))
-      (error 0)))
-   (t 0)))
-
-(defun org-time-today ()
-  "Time in seconds today at 0:00.
-Returns the float number of seconds since the beginning of the
-epoch to the beginning of today (00:00)."
-  (float-time (apply #'encode-time 0 0 0 (nthcdr 3 (decode-time)))))
-
-(defun org-matcher-time (s)
-  "Interpret a time comparison value."
-  (save-match-data
-    (cond
-     ((string= s "<now>") (float-time))
-     ((string= s "<today>") (org-time-today))
-     ((string= s "<tomorrow>")   (+ 86400.0 (org-time-today)))
-     ((string= s "<yesterday>")  (- (org-time-today) 86400.0))
-     ((string-match "^<\\([-+][0-9]+\\)\\([hdwmy]\\)>$" s)
-      (+ (org-time-today)
-        (* (string-to-number (match-string 1 s))
-           (cdr (assoc (match-string 2 s)
-                       '(("d" . 86400.0)   ("w" . 604800.0)
-                         ("m" . 2678400.0) ("y" . 31557600.0)))))))
-     (t (org-2ft s)))))
-
-(defun org-match-any-p (re list)
-  "Does re match any element of list?"
-  (setq list (mapcar (lambda (x) (string-match re x)) list))
-  (delq nil list))
-
 (defvar org-add-colon-after-tag-completion nil)  ;; dynamically scoped param
 (defvar org-tags-overlay (make-overlay 1 1))
 (delete-overlay org-tags-overlay)
 
-(defun org-get-local-tags-at (&optional pos)
-  "Get a list of tags defined in the current headline."
-  (org-get-tags-at pos 'local))
-
-(defun org-get-local-tags ()
-  "Get a list of tags defined in the current headline."
-  (org-get-tags-at nil 'local))
-
-(defun org-get-tags-at (&optional pos local)
-  "Get a list of all headline tags applicable at POS.
-POS defaults to point.  If tags are inherited, the list contains
-the targets in the same sequence as the headlines appear, i.e.
-the tags of the current headline come last.
-When LOCAL is non-nil, only return tags from the current headline,
-ignore inherited ones."
-  (interactive)
-  (if (and org-trust-scanner-tags
-          (or (not pos) (equal pos (point)))
-          (not local))
-      org-scanner-tags
-    (let (tags ltags lastpos parent)
-      (save-excursion
-       (save-restriction
-         (widen)
-         (goto-char (or pos (point)))
-         (save-match-data
-           (catch 'done
-             (condition-case nil
-                 (progn
-                   (org-back-to-heading t)
-                   (while (not (equal lastpos (point)))
-                     (setq lastpos (point))
-                     (when (looking-at ".+?:\\([[:alnum:]_@#%:]+\\):[ \t]*$")
-                       (setq ltags (org-split-string
-                                    (match-string-no-properties 1) ":"))
-                       (when parent
-                         (setq ltags (mapcar 'org-add-prop-inherited ltags)))
-                       (setq tags (append
-                                   (if parent
-                                       (org-remove-uninherited-tags ltags)
-                                     ltags)
-                                   tags)))
-                     (or org-use-tag-inheritance (throw 'done t))
-                     (when local (throw 'done t))
-                     (or (org-up-heading-safe) (error nil))
-                     (setq parent t)))
-               (error nil)))))
-       (if local
-           tags
-         (reverse (delete-dups
-                   (reverse (append
-                             (org-remove-uninherited-tags
-                              org-file-tags)
-                              tags)))))))))
-
 (defun org-add-prop-inherited (s)
   (add-text-properties 0 (length s) '(inherited t) s)
   s)
@@ -14759,14 +12223,9 @@ If ONOFF is `on' or `off', don't toggle but set to 
this state."
   (save-excursion
     (org-back-to-heading t)
     (let ((current
-          (when (re-search-forward "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t]*$"
-                                   (line-end-position) t)
-            (let ((tags (match-string 1)))
-              ;; Clear current tags.
-              (replace-match "")
-              ;; Reverse the tags list so any new tag is appended to
-              ;; the current list of tags.
-              (nreverse (org-split-string tags ":")))))
+          ;; Reverse the tags list so any new tag is appended to the
+          ;; current list of tags.
+          (nreverse (org-get-tags nil t)))
          res)
       (pcase onoff
        (`off (setq current (delete tag current)))
@@ -14774,190 +12233,165 @@ If ONOFF is `on' or `off', don't toggle but set to 
this state."
         (setq res t)
         (cl-pushnew tag current :test #'equal))
        (_ (setq current (delete tag current))))
-      (end-of-line)
-      (if current
-         (progn
-           (insert " :" (mapconcat #'identity (nreverse current) ":") ":")
-           (org-set-tags nil t))
-       (delete-horizontal-space))
-      (run-hooks 'org-after-tags-change-hook)
+      (org-set-tags (nreverse current))
       res)))
 
 (defun org--align-tags-here (to-col)
   "Align tags on the current headline to TO-COL.
-Assume point is on a headline."
-  (let ((pos (point)))
-    (beginning-of-line)
-    (if        (or (not (looking-at ".*?\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ 
\t]*$"))
-           (>= pos (match-beginning 2)))
-       ;; No tags or point within tags: do not align.
-       (goto-char pos)
-      (goto-char (match-beginning 1))
-      (let ((shift (max (- (if (>= to-col 0) to-col
-                            (- (abs to-col) (string-width (match-string 2))))
-                          (current-column))
-                       1)))
-       (replace-match (make-string shift ?\s) nil nil nil 1)
-       ;; Preserve initial position, if possible.  In any case, stop
-       ;; before tags.
-       (when (< pos (point)) (goto-char pos))))))
-
-(defun org-set-tags-command (&optional arg just-align)
-  "Call the set-tags command for the current entry."
+Assume point is on a headline.  Preserve point when aligning
+tags."
+  (when (org-match-line org-tag-line-re)
+    (let* ((tags-start (match-beginning 1))
+          (blank-start (save-excursion
+                         (goto-char tags-start)
+                         (skip-chars-backward " \t")
+                         (point)))
+          (new (max (if (>= to-col 0) to-col
+                      (- (abs to-col) (string-width (match-string 1))))
+                    ;; Introduce at least one space after the heading
+                    ;; or the stars.
+                    (save-excursion
+                      (goto-char blank-start)
+                      (1+ (current-column)))))
+          (current
+           (save-excursion (goto-char tags-start) (current-column)))
+          (origin (point-marker))
+          (column (current-column))
+          (in-blank? (and (> origin blank-start) (<= origin tags-start))))
+      (when (/= new current)
+       (delete-region blank-start tags-start)
+       (goto-char blank-start)
+       (let ((indent-tabs-mode nil)) (indent-to new))
+       ;; Try to move back to original position.  If point was in the
+       ;; blanks before the tags, ORIGIN marker is of no use because
+       ;; it now points to BLANK-START.  Use COLUMN instead.
+       (if in-blank? (org-move-to-column column) (goto-char origin))))))
+
+(defun org-set-tags-command (&optional arg)
+  "Set the tags for the current visible entry.
+
+When called with `\\[universal-argument]' prefix argument ARG, \
+realign all tags
+in the current buffer.
+
+When called with `\\[universal-argument] \\[universal-argument]' prefix 
argument, \
+unconditionally do not
+offer the fast tag selection interface.
+
+If a region is active, set tags in the region according to the
+setting of `org-loop-over-headlines-in-active-region'.
+
+This function is for interactive use only;
+in Lisp code use `org-set-tags' instead."
   (interactive "P")
-  (if (or (org-at-heading-p) (and arg (org-before-first-heading-p)))
-      (org-set-tags arg just-align)
-    (save-excursion
-      (unless (and (org-region-active-p)
-                  org-loop-over-headlines-in-active-region)
-       (org-back-to-heading t))
-      (org-set-tags arg just-align))))
-
-(defun org-set-tags-to (data)
-  "Set the tags of the current entry to DATA, replacing current tags.
-DATA may be a tags string like \":aa:bb:cc:\", or a list of tags.
-If DATA is nil or the empty string, all tags are removed."
-  (interactive "sTags: ")
-  (let ((data
-        (pcase (if (stringp data) (org-trim data) data)
-          ((or `nil "") nil)
-          ((pred listp) (format ":%s:" (mapconcat #'identity data ":")))
-          ((pred stringp)
-           (format ":%s:"
-                   (mapconcat #'identity (org-split-string data ":+") ":")))
-          (_ (error "Invalid tag specification: %S" data)))))
-    (org-with-wide-buffer
-     (org-back-to-heading t)
-     (let ((case-fold-search nil)) (looking-at org-complex-heading-regexp))
-     (when (or (match-end 5) data)
-       (goto-char (or (match-beginning 5) (line-end-position)))
-       (skip-chars-backward " \t")
-       (delete-region (point) (line-end-position))
-       (when data
-        (insert " " data)
-        (org-set-tags nil 'align))))))
+  (let ((org-use-fast-tag-selection
+        (unless (equal '(16) arg) org-use-fast-tag-selection)))
+    (cond
+     ((equal '(4) arg) (org-align-tags t))
+     ((and (org-region-active-p) org-loop-over-headlines-in-active-region)
+      (let (org-loop-over-headlines-in-active-region) ;  hint: infinite 
recursion.
+       (org-map-entries
+        #'org-set-tags-command
+        nil
+        (if (eq org-loop-over-headlines-in-active-region 'start-level)
+            'region-start-level
+          'region)
+        (lambda () (when (org-invisible-p) (org-end-of-subtree nil t))))))
+     (t
+      (save-excursion
+       (org-back-to-heading)
+       (let* ((all-tags (org-get-tags))
+              (table (setq org-last-tags-completion-table
+                           (org--tag-add-to-alist
+                            (and org-complete-tags-always-offer-all-agenda-tags
+                                 (org-global-tags-completion-table
+                                  (org-agenda-files)))
+                            (or org-current-tag-alist (org-get-buffer-tags)))))
+              (current-tags
+               (cl-remove-if (lambda (tag) (get-text-property 0 'inherited 
tag))
+                             all-tags))
+              (inherited-tags
+               (cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited 
tag))
+                                 all-tags))
+              (tags
+               (replace-regexp-in-string
+                ;; Ignore all forbidden characters in tags.
+                "[^[:alnum:]_@#%]+" ":"
+                (if (or (eq t org-use-fast-tag-selection)
+                        (and org-use-fast-tag-selection
+                             (delq nil (mapcar #'cdr table))))
+                    (org-fast-tag-selection
+                     current-tags
+                     inherited-tags
+                     table
+                     (and org-fast-tag-selection-include-todo 
org-todo-key-alist))
+                  (let ((org-add-colon-after-tag-completion (< 1 (length 
table))))
+                    (org-trim (completing-read
+                               "Tags: "
+                               #'org-tags-completion-function
+                               nil nil (org-make-tag-string current-tags)
+                               'org-tags-history)))))))
+         (org-set-tags tags)))))))
+
+(defun org-align-tags (&optional all)
+  "Align tags in current entry.
+When optional argument ALL is non-nil, align all tags in the
+visible part of the buffer."
+  (let ((get-indent-column
+        (lambda ()
+          (let ((offset (if (bound-and-true-p org-indent-mode)
+                            (* (1- org-indent-indentation-per-level)
+                               (1- (org-current-level)))
+                          0)))
+            (+ org-tags-column
+               (if (> org-tags-column 0) (- offset) offset))))))
+    (if (and (not all) (org-at-heading-p))
+       (org--align-tags-here (funcall get-indent-column))
+      (save-excursion
+       (if all
+           (progn
+             (goto-char (point-min))
+             (while (re-search-forward org-tag-line-re nil t)
+               (org--align-tags-here (funcall get-indent-column))))
+         (org-back-to-heading t)
+         (org--align-tags-here (funcall get-indent-column)))))))
 
-(defun org-align-all-tags ()
-  "Align the tags in all headings."
-  (interactive)
-  (save-excursion
-    (or (ignore-errors (org-back-to-heading t))
-       (outline-next-heading))
-    (if (org-at-heading-p)
-       (org-set-tags t)
-      (message "No headings"))))
+(defun org-set-tags (tags)
+  "Set the tags of the current entry to TAGS, replacing current tags.
 
-(defvar org-indent-indentation-per-level)
-(defun org-set-tags (&optional arg just-align)
-  "Set the tags for the current headline.
-With prefix ARG, realign all tags in headings in the current buffer.
-When JUST-ALIGN is non-nil, only align tags."
-  (interactive "P")
-  (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
-      (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
-                    'region-start-level
-                 'region))
-            org-loop-over-headlines-in-active-region)
-        (org-map-entries
-         ;; We don't use ARG and JUST-ALIGN here because these args
-         ;; are not useful when looping over headlines.
-         #'org-set-tags
-         org-loop-over-headlines-in-active-region
-         cl
-        '(when (org-invisible-p) (org-end-of-subtree nil t))))
-    (let ((org-setting-tags t))
-      (if arg
-          (save-excursion
-            (goto-char (point-min))
-            (while (re-search-forward org-outline-regexp-bol nil t)
-             (org-set-tags nil t)
-             (end-of-line))
-            (message "All tags realigned to column %d" org-tags-column))
-       (let* ((current (org-get-tags-string))
-              (tags
-               (if just-align current
-                 ;; Get a new set of tags from the user.
-                 (save-excursion
-                   (let* ((table
-                           (setq
-                            org-last-tags-completion-table
-                            (org-tag-add-to-alist
-                             (and
-                              org-complete-tags-always-offer-all-agenda-tags
-                              (org-global-tags-completion-table
-                               (org-agenda-files)))
-                             (or org-current-tag-alist
-                                 (org-get-buffer-tags)))))
-                          (current-tags (org-split-string current ":"))
-                          (inherited-tags
-                           (nreverse (nthcdr (length current-tags)
-                                             (nreverse (org-get-tags-at))))))
-                     (replace-regexp-in-string
-                      "\\([-+&]+\\|,\\)"
-                      ":"
-                      (if (or (eq t org-use-fast-tag-selection)
-                              (and org-use-fast-tag-selection
-                                   (delq nil (mapcar #'cdr table))))
-                          (org-fast-tag-selection
-                           current-tags inherited-tags table
-                           (and org-fast-tag-selection-include-todo
-                                org-todo-key-alist))
-                        (let ((org-add-colon-after-tag-completion
-                               (< 1 (length table))))
-                          (org-trim
-                           (completing-read
-                            "Tags: "
-                            #'org-tags-completion-function
-                            nil nil current 'org-tags-history))))))))))
-
-         (when org-tags-sort-function
-           (setq tags
-                 (mapconcat
-                  #'identity
-                  (sort (org-split-string tags "[^[:alnum:]_@#%]+")
-                        org-tags-sort-function)
-                  ":")))
-
-         (if (or (string= ":" tags)
-                 (string= "::" tags))
-             (setq tags ""))
-         (if (not (org-string-nw-p tags)) (setq tags "")
-           (unless (string-suffix-p ":" tags) (setq tags (concat tags ":")))
-           (unless (string-prefix-p ":" tags) (setq tags (concat ":" tags))))
-
-         ;; Insert new tags at the correct column.
-         (unless (equal current tags)
-           (save-excursion
-             (beginning-of-line)
-             (let ((case-fold-search nil))
-               (looking-at org-complex-heading-regexp))
-             ;; Remove current tags, if any.
-             (when (match-end 5) (replace-match "" nil nil nil 5))
-             ;; Insert new tags, if any.  Otherwise, remove trailing
-             ;; white spaces.
-             (end-of-line)
-             (if (not (equal tags ""))
-                 ;; When text is being inserted on an invisible
-                 ;; region boundary, it can be inadvertently sucked
-                 ;; into invisibility.
-                 (outline-flag-region (point) (progn (insert " " tags) 
(point)) nil)
-               (skip-chars-backward " \t")
-               (delete-region (point) (line-end-position)))))
-         ;; Align tags, if any.  Fix tags column if `org-indent-mode'
-         ;; is on.
-         (unless (equal tags "")
-           (let* ((level (save-excursion
-                           (beginning-of-line)
-                           (skip-chars-forward "*")))
-                  (offset (if (bound-and-true-p org-indent-mode)
-                              (* (1- org-indent-indentation-per-level)
-                                 (1- level))
-                            0))
-                  (tags-column
-                   (+ org-tags-column
-                      (if (> org-tags-column 0) (- offset) offset))))
-             (org--align-tags-here tags-column))))
-        (unless just-align (run-hooks 'org-after-tags-change-hook))))))
+TAGS may be a tags string like \":aa:bb:cc:\", or a list of tags.
+If TAGS is nil or the empty string, all tags are removed.
+
+This function assumes point is on a headline."
+  (org-with-wide-buffer
+   (let ((tags (pcase tags
+                ((pred listp) tags)
+                ((pred stringp) (split-string (org-trim tags) ":" t))
+                (_ (error "Invalid tag specification: %S" tags))))
+        (old-tags (org-get-tags nil t))
+        (tags-change? nil))
+     (when (functionp org-tags-sort-function)
+       (setq tags (sort tags org-tags-sort-function)))
+     (setq tags-change? (not (equal tags old-tags)))
+     (when tags-change?
+       ;; Delete previous tags and any trailing white space.
+       (goto-char (if (org-match-line org-tag-line-re) (match-beginning 1)
+                   (line-end-position)))
+       (skip-chars-backward " \t")
+       (delete-region (point) (line-end-position))
+       ;; Deleting white spaces may break an otherwise empty headline.
+       ;; Re-introduce one space in this case.
+       (unless (org-at-heading-p) (insert " "))
+       (when tags
+        (save-excursion (insert " " (org-make-tag-string tags)))
+        ;; When text is being inserted on an invisible region
+        ;; boundary, it can be inadvertently sucked into
+        ;; invisibility.
+        (unless (org-invisible-p (line-beginning-position))
+          (org-flag-region (point) (line-end-position) nil 'outline))))
+     ;; Align tags, if any.
+     (when tags (org-align-tags))
+     (when tags-change? (run-hooks 'org-after-tags-change-hook)))))
 
 (defun org-change-tag-in-region (beg end tag off)
   "Add or remove TAG for each entry in the region.
@@ -14966,7 +12400,7 @@ This works in the agenda, and also in an Org buffer."
    (list (region-beginning) (region-end)
         (let ((org-last-tags-completion-table
                (if (derived-mode-p 'org-mode)
-                   (org-tag-add-to-alist
+                   (org--tag-add-to-alist
                     (org-get-buffer-tags)
                     (org-global-tags-completion-table))
                  (org-global-tags-completion-table))))
@@ -15001,32 +12435,33 @@ This works in the agenda, and also in an Org buffer."
     (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
 
 (defun org-tags-completion-function (string _predicate &optional flag)
-  (let (s1 s2 rtn (ctable org-last-tags-completion-table)
-          (confirm (lambda (x) (stringp (car x)))))
-    (if (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
-        (setq s1 (match-string 1 string)
-              s2 (match-string 2 string))
-      (setq s1 "" s2 string))
-    (cond
-     ((eq flag nil)
-      ;; try completion
-      (setq rtn (try-completion s2 ctable confirm))
-      (when (stringp rtn)
-       (setq rtn
-             (concat s1 s2 (substring rtn (length s2))
-                     (if (and org-add-colon-after-tag-completion
-                              (assoc rtn ctable))
-                         ":" ""))))
-      rtn)
-     ((eq flag t)
-      ;; all-completions
-      (all-completions s2 ctable confirm))
-     ((eq flag 'lambda)
-      ;; exact match?
-      (assoc s2 ctable)))))
+  "Complete tag STRING.
+FLAG specifies the type of completion operation to perform.  This
+function is passed as a collection function to `completing-read',
+which see."
+  (let ((completion-ignore-case nil)   ;tags are case-sensitive
+       (confirm (lambda (x) (stringp (car x))))
+       (prefix ""))
+    (when (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
+      (setq prefix (match-string 1 string))
+      (setq string (match-string 2 string)))
+    (pcase flag
+      (`t (all-completions string org-last-tags-completion-table confirm))
+      (`lambda (assoc string org-last-tags-completion-table)) ;exact match?
+      (`nil
+       (pcase (try-completion string org-last-tags-completion-table confirm)
+        ((and completion (pred stringp))
+         (concat prefix
+                 completion
+                 (if (and org-add-colon-after-tag-completion
+                          (assoc completion org-last-tags-completion-table))
+                     ":"
+                   "")))
+        (completion completion)))
+      (_ nil))))
 
 (defun org-fast-tag-insert (kwd tags face &optional end)
-  "Insert KDW, and the TAGS, the latter with face FACE.
+  "Insert KWD, and the TAGS, the latter with face FACE.
 Also insert END."
   (insert (format "%-12s" (concat kwd ":"))
          (org-add-props (mapconcat 'identity tags " ") nil 'face face)
@@ -15044,7 +12479,7 @@ Also insert END."
 
 (defun org-set-current-tags-overlay (current prefix)
   "Add an overlay to CURRENT tag with PREFIX."
-  (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
+  (let ((s (org-make-tag-string current)))
     (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
     (org-overlay-display org-tags-overlay (concat prefix s))))
 
@@ -15058,10 +12493,12 @@ TODO keywords, should these have keys assigned to 
them.
 If the keys are nil, a-z are automatically assigned.
 Returns the new tags string, or nil to not change the current settings."
   (let* ((fulltable (append table todo-table))
-        (maxlen (apply 'max (mapcar
-                             (lambda (x)
-                               (if (stringp (car x)) (string-width (car x)) 0))
-                             fulltable)))
+        (maxlen (if (null fulltable) 0
+                  (apply #'max
+                         (mapcar (lambda (x)
+                                   (if (stringp (car x)) (string-width (car x))
+                                     0))
+                                 fulltable))))
         (buf (current-buffer))
         (expert (eq org-fast-tag-selection-single-key 'expert))
         (buffer-tags nil)
@@ -15075,8 +12512,8 @@ Returns the new tags string, or nil to not change the 
current settings."
         (done-keywords org-done-keywords)
         groups ingroup intaggroup)
     (save-excursion
-      (beginning-of-line 1)
-      (if (looking-at ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
+      (beginning-of-line)
+      (if (looking-at org-tag-line-re)
          (setq ov-start (match-beginning 1)
                ov-end (match-end 1)
                ov-prefix "")
@@ -15090,191 +12527,222 @@ Returns the new tags string, or nil to not change 
the current settings."
                   " "
                 (make-string (- org-tags-column (current-column)) ?\ ))))))
     (move-overlay org-tags-overlay ov-start ov-end)
-    (save-window-excursion
-      (if expert
-         (set-buffer (get-buffer-create " *Org tags*"))
-       (delete-other-windows)
-       (set-window-buffer (split-window-vertically) (get-buffer-create " *Org 
tags*"))
-       (org-switch-to-buffer-other-window " *Org tags*"))
-      (erase-buffer)
-      (setq-local org-done-keywords done-keywords)
-      (org-fast-tag-insert "Inherited" inherited i-face "\n")
-      (org-fast-tag-insert "Current" current c-face "\n\n")
-      (org-fast-tag-show-exit exit-after-next)
-      (org-set-current-tags-overlay current ov-prefix)
-      (setq tbl fulltable char ?a cnt 0)
-      (while (setq e (pop tbl))
-       (cond
-        ((eq (car e) :startgroup)
-         (push '() groups) (setq ingroup t)
-         (unless (zerop cnt)
-           (setq cnt 0)
-           (insert "\n"))
-         (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
-        ((eq (car e) :endgroup)
-         (setq ingroup nil cnt 0)
-         (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
-        ((eq (car e) :startgrouptag)
-         (setq intaggroup t)
-         (unless (zerop cnt)
-           (setq cnt 0)
-           (insert "\n"))
-         (insert "[ "))
-        ((eq (car e) :endgrouptag)
-         (setq intaggroup nil cnt 0)
-         (insert "]\n"))
-        ((equal e '(:newline))
-         (unless (zerop cnt)
-           (setq cnt 0)
-           (insert "\n")
-           (setq e (car tbl))
-           (while (equal (car tbl) '(:newline))
+    (save-excursion
+      (save-window-excursion
+       (if expert
+           (set-buffer (get-buffer-create " *Org tags*"))
+         (delete-other-windows)
+         (set-window-buffer (split-window-vertically) (get-buffer-create " 
*Org tags*"))
+         (org-switch-to-buffer-other-window " *Org tags*"))
+       (erase-buffer)
+       (setq-local org-done-keywords done-keywords)
+       (org-fast-tag-insert "Inherited" inherited i-face "\n")
+       (org-fast-tag-insert "Current" current c-face "\n\n")
+       (org-fast-tag-show-exit exit-after-next)
+       (org-set-current-tags-overlay current ov-prefix)
+       (setq tbl fulltable char ?a cnt 0)
+       (while (setq e (pop tbl))
+         (cond
+          ((eq (car e) :startgroup)
+           (push '() groups) (setq ingroup t)
+           (unless (zerop cnt)
+             (setq cnt 0)
+             (insert "\n"))
+           (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
+          ((eq (car e) :endgroup)
+           (setq ingroup nil cnt 0)
+           (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
+          ((eq (car e) :startgrouptag)
+           (setq intaggroup t)
+           (unless (zerop cnt)
+             (setq cnt 0)
+             (insert "\n"))
+           (insert "[ "))
+          ((eq (car e) :endgrouptag)
+           (setq intaggroup nil cnt 0)
+           (insert "]\n"))
+          ((equal e '(:newline))
+           (unless (zerop cnt)
+             (setq cnt 0)
              (insert "\n")
-             (setq tbl (cdr tbl)))))
-        ((equal e '(:grouptags)) (insert " : "))
-        (t
-         (setq tg (copy-sequence (car e)) c2 nil)
-         (if (cdr e)
-             (setq c (cdr e))
-           ;; automatically assign a character.
-           (setq c1 (string-to-char
-                     (downcase (substring
-                                tg (if (= (string-to-char tg) ?@) 1 0)))))
-           (if (or (rassoc c1 ntable) (rassoc c1 table))
-               (while (or (rassoc char ntable) (rassoc char table))
-                 (setq char (1+ char)))
-             (setq c2 c1))
-           (setq c (or c2 char)))
-         (when ingroup (push tg (car groups)))
-         (setq tg (org-add-props tg nil 'face
-                                 (cond
-                                  ((not (assoc tg table))
-                                   (org-get-todo-face tg))
-                                  ((member tg current) c-face)
-                                  ((member tg inherited) i-face))))
-         (when (equal (caar tbl) :grouptags)
-           (org-add-props tg nil 'face 'org-tag-group))
-         (when (and (zerop cnt) (not ingroup) (not intaggroup)) (insert " "))
-         (insert "[" c "] " tg (make-string
-                                (- fwidth 4 (length tg)) ?\ ))
-         (push (cons tg c) ntable)
-         (when (= (cl-incf cnt) ncol)
-           (insert "\n")
-           (when (or ingroup intaggroup) (insert " "))
-           (setq cnt 0)))))
-      (setq ntable (nreverse ntable))
-      (insert "\n")
-      (goto-char (point-min))
-      (unless expert (org-fit-window-to-buffer))
-      (setq rtn
-           (catch 'exit
-             (while t
-               (message "[a-z..]:toggle [SPC]:clear [RET]:accept [TAB]:edit 
[!] %sgroups%s"
-                        (if (not groups) "no " "")
-                        (if expert " [C-c]:window" (if exit-after-next " 
[C-c]:single" " [C-c]:multi")))
-               (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
-               (setq org-last-tag-selection-key c)
-               (cond
-                ((= c ?\r) (throw 'exit t))
-                ((= c ?!)
-                 (setq groups (not groups))
-                 (goto-char (point-min))
-                 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
-                ((= c ?\C-c)
-                 (if (not expert)
-                     (org-fast-tag-show-exit
-                      (setq exit-after-next (not exit-after-next)))
-                   (setq expert nil)
-                   (delete-other-windows)
-                   (set-window-buffer (split-window-vertically) " *Org tags*")
-                   (org-switch-to-buffer-other-window " *Org tags*")
-                   (org-fit-window-to-buffer)))
-                ((or (= c ?\C-g)
-                     (and (= c ?q) (not (rassoc c ntable))))
-                 (delete-overlay org-tags-overlay)
-                 (setq quit-flag t))
-                ((= c ?\ )
-                 (setq current nil)
-                 (when exit-after-next (setq exit-after-next 'now)))
-                ((= c ?\t)
-                 (condition-case nil
-                     (setq tg (completing-read
-                               "Tag: "
-                               (or buffer-tags
-                                   (with-current-buffer buf
-                                     (setq buffer-tags
-                                           (org-get-buffer-tags))))))
-                   (quit (setq tg "")))
-                 (when (string-match "\\S-" tg)
-                   (cl-pushnew (list tg) buffer-tags :test #'equal)
+             (setq e (car tbl))
+             (while (equal (car tbl) '(:newline))
+               (insert "\n")
+               (setq tbl (cdr tbl)))))
+          ((equal e '(:grouptags)) (insert " : "))
+          (t
+           (setq tg (copy-sequence (car e)) c2 nil)
+           (if (cdr e)
+               (setq c (cdr e))
+             ;; automatically assign a character.
+             (setq c1 (string-to-char
+                       (downcase (substring
+                                  tg (if (= (string-to-char tg) ?@) 1 0)))))
+             (if (or (rassoc c1 ntable) (rassoc c1 table))
+                 (while (or (rassoc char ntable) (rassoc char table))
+                   (setq char (1+ char)))
+               (setq c2 c1))
+             (setq c (or c2 char)))
+           (when ingroup (push tg (car groups)))
+           (setq tg (org-add-props tg nil 'face
+                                   (cond
+                                    ((not (assoc tg table))
+                                     (org-get-todo-face tg))
+                                    ((member tg current) c-face)
+                                    ((member tg inherited) i-face))))
+           (when (equal (caar tbl) :grouptags)
+             (org-add-props tg nil 'face 'org-tag-group))
+           (when (and (zerop cnt) (not ingroup) (not intaggroup)) (insert "  
"))
+           (insert "[" c "] " tg (make-string
+                                  (- fwidth 4 (length tg)) ?\ ))
+           (push (cons tg c) ntable)
+           (when (= (cl-incf cnt) ncol)
+             (unless (memq (caar tbl) '(:endgroup :endgrouptag))
+               (insert "\n")
+               (when (or ingroup intaggroup) (insert "  ")))
+             (setq cnt 0)))))
+       (setq ntable (nreverse ntable))
+       (insert "\n")
+       (goto-char (point-min))
+       (unless expert (org-fit-window-to-buffer))
+       (setq rtn
+             (catch 'exit
+               (while t
+                 (message "[a-z..]:toggle [SPC]:clear [RET]:accept [TAB]:edit 
[!] %sgroups%s"
+                          (if (not groups) "no " "")
+                          (if expert " [C-c]:window" (if exit-after-next " 
[C-c]:single" " [C-c]:multi")))
+                 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
+                 (setq org-last-tag-selection-key c)
+                 (cond
+                  ((= c ?\r) (throw 'exit t))
+                  ((= c ?!)
+                   (setq groups (not groups))
+                   (goto-char (point-min))
+                   (while (re-search-forward "[{}]" nil t) (replace-match " 
")))
+                  ((= c ?\C-c)
+                   (if (not expert)
+                       (org-fast-tag-show-exit
+                        (setq exit-after-next (not exit-after-next)))
+                     (setq expert nil)
+                     (delete-other-windows)
+                     (set-window-buffer (split-window-vertically) " *Org 
tags*")
+                     (org-switch-to-buffer-other-window " *Org tags*")
+                     (org-fit-window-to-buffer)))
+                  ((or (= c ?\C-g)
+                       (and (= c ?q) (not (rassoc c ntable))))
+                   (delete-overlay org-tags-overlay)
+                   (setq quit-flag t))
+                  ((= c ?\ )
+                   (setq current nil)
+                   (when exit-after-next (setq exit-after-next 'now)))
+                  ((= c ?\t)
+                   (condition-case nil
+                       (setq tg (completing-read
+                                 "Tag: "
+                                 (or buffer-tags
+                                     (with-current-buffer buf
+                                       (setq buffer-tags
+                                             (org-get-buffer-tags))))))
+                     (quit (setq tg "")))
+                   (when (string-match "\\S-" tg)
+                     (cl-pushnew (list tg) buffer-tags :test #'equal)
+                     (if (member tg current)
+                         (setq current (delete tg current))
+                       (push tg current)))
+                   (when exit-after-next (setq exit-after-next 'now)))
+                  ((setq e (rassoc c todo-table) tg (car e))
+                   (with-current-buffer buf
+                     (save-excursion (org-todo tg)))
+                   (when exit-after-next (setq exit-after-next 'now)))
+                  ((setq e (rassoc c ntable) tg (car e))
                    (if (member tg current)
                        (setq current (delete tg current))
-                     (push tg current)))
-                 (when exit-after-next (setq exit-after-next 'now)))
-                ((setq e (rassoc c todo-table) tg (car e))
-                 (with-current-buffer buf
-                   (save-excursion (org-todo tg)))
-                 (when exit-after-next (setq exit-after-next 'now)))
-                ((setq e (rassoc c ntable) tg (car e))
-                 (if (member tg current)
-                     (setq current (delete tg current))
-                   (cl-loop for g in groups do
-                            (when (member tg g)
-                              (dolist (x g) (setq current (delete x 
current)))))
-                   (push tg current))
-                 (when exit-after-next (setq exit-after-next 'now))))
-
-               ;; Create a sorted list
-               (setq current
-                     (sort current
-                           (lambda (a b)
-                             (assoc b (cdr (memq (assoc a ntable) ntable))))))
-               (when (eq exit-after-next 'now) (throw 'exit t))
-               (goto-char (point-min))
-               (beginning-of-line 2)
-               (delete-region (point) (point-at-eol))
-               (org-fast-tag-insert "Current" current c-face)
-               (org-set-current-tags-overlay current ov-prefix)
-               (while (re-search-forward "\\[.\\] \\([[:alnum:]_@#%]+\\)" nil 
t)
-                 (setq tg (match-string 1))
-                 (add-text-properties
-                  (match-beginning 1) (match-end 1)
-                  (list 'face
-                        (cond
-                         ((member tg current) c-face)
-                         ((member tg inherited) i-face)
-                         (t (get-text-property (match-beginning 1) 'face))))))
-               (goto-char (point-min)))))
-      (delete-overlay org-tags-overlay)
-      (if rtn
-         (mapconcat 'identity current ":")
-       nil))))
-
-(defun org-get-tags-string ()
-  "Get the TAGS string in the current headline."
-  (unless (org-at-heading-p t)
-    (user-error "Not on a heading"))
-  (save-excursion
-    (beginning-of-line 1)
-    (if (looking-at ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
-       (match-string-no-properties 1)
-      "")))
-
-(defun org-get-tags ()
-  "Get the list of tags specified in the current headline."
-  (org-split-string (org-get-tags-string) ":"))
+                     (cl-loop for g in groups do
+                              (when (member tg g)
+                                (dolist (x g) (setq current (delete x 
current)))))
+                     (push tg current))
+                   (when exit-after-next (setq exit-after-next 'now))))
+
+                 ;; Create a sorted list
+                 (setq current
+                       (sort current
+                             (lambda (a b)
+                               (assoc b (cdr (memq (assoc a ntable) 
ntable))))))
+                 (when (eq exit-after-next 'now) (throw 'exit t))
+                 (goto-char (point-min))
+                 (beginning-of-line 2)
+                 (delete-region (point) (point-at-eol))
+                 (org-fast-tag-insert "Current" current c-face)
+                 (org-set-current-tags-overlay current ov-prefix)
+                 (let ((tag-re (concat "\\[.\\] \\(" org-tag-re "\\)")))
+                   (while (re-search-forward tag-re nil t)
+                     (let ((tag (match-string 1)))
+                       (add-text-properties
+                        (match-beginning 1) (match-end 1)
+                        (list 'face
+                              (cond
+                               ((member tag current) c-face)
+                               ((member tag inherited) i-face)
+                               (t (get-text-property (match-beginning 1) '
+                                                     face))))))))
+                 (goto-char (point-min)))))
+       (delete-overlay org-tags-overlay)
+       (if rtn
+           (mapconcat 'identity current ":")
+         nil)))))
+
+(defun org-make-tag-string (tags)
+  "Return string associated to TAGS.
+TAGS is a list of strings."
+  (if (null tags) ""
+    (format ":%s:" (mapconcat #'identity tags ":"))))
+
+(defun org--get-local-tags ()
+  "Return list of tags for the current headline.
+Assume point is at the beginning of the headline."
+  (and (looking-at org-tag-line-re)
+       (split-string (match-string-no-properties 2) ":" t)))
+
+(defun org-get-tags (&optional pos local)
+  "Get the list of tags specified in the current headline.
+
+When argument POS is non-nil, retrieve tags for headline at POS.
+
+According to `org-use-tag-inheritance', tags may be inherited
+from parent headlines, and from the whole document, through
+`org-file-tags'.  In this case, the returned list of tags
+contains tags in this order: file tags, tags inherited from
+parent headlines, local tags.
+
+However, when optional argument LOCAL is non-nil, only return
+tags specified at the headline.
+
+Inherited tags have the `inherited' text property."
+  (if (and org-trust-scanner-tags
+           (or (not pos) (eq pos (point)))
+           (not local))
+      org-scanner-tags
+    (org-with-point-at (or pos (point))
+      (unless (org-before-first-heading-p)
+        (org-back-to-heading t)
+        (let ((ltags (org--get-local-tags)) itags)
+          (if (or local (not org-use-tag-inheritance)) ltags
+            (while (org-up-heading-safe)
+              (setq itags (append (mapcar #'org-add-prop-inherited
+                                          (org--get-local-tags))
+                                  itags)))
+            (setq itags (append org-file-tags itags))
+            (delete-dups
+             (append (org-remove-uninherited-tags itags) ltags))))))))
 
 (defun org-get-buffer-tags ()
   "Get a table of all tags used in the buffer, for completion."
-  (org-with-wide-buffer
-   (goto-char (point-min))
-   (let ((tag-re (concat org-outline-regexp-bol
-                        "\\(?:.*?[ \t]\\)?:\\([[:alnum:]_@#%:]+\\):[ \t]*$"))
-        tags)
-     (while (re-search-forward tag-re nil t)
-       (dolist (tag (org-split-string (match-string-no-properties 1) ":"))
-        (push tag tags)))
-     (mapcar #'list (append org-file-tags (org-uniquify tags))))))
+  (org-with-point-at 1
+    (let (tags)
+      (while (re-search-forward org-tag-line-re nil t)
+       (setq tags (nconc (split-string (match-string-no-properties 2) ":")
+                         tags)))
+      (mapcar #'list (delete-dups (append org-file-tags tags))))))
 
 ;;;; The mapping API
 
@@ -15335,7 +12803,7 @@ the scanner.  The following items can be given here:
 If your function needs to retrieve the tags including inherited tags
 at the *current* entry, you can use the value of the variable
 `org-scanner-tags' which will be much faster than getting the value
-with `org-get-tags-at'.  If your function gets properties with
+with `org-get-tags'.  If your function gets properties with
 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
 to t around the call to `org-entry-properties' to get the same speedup.
 Note that if your function moves around to retrieve tags and properties at
@@ -15504,61 +12972,44 @@ See `org-property-re' for match data, if applicable."
 (defun org-inc-effort ()
   "Increment the value of the effort property in the current entry."
   (interactive)
-  (org-set-effort nil t))
+  (org-set-effort t))
 
 (defvar org-clock-effort)       ; Defined in org-clock.el.
 (defvar org-clock-current-task) ; Defined in org-clock.el.
-(defun org-set-effort (&optional value increment)
+(defun org-set-effort (&optional increment value)
   "Set the effort property of the current entry.
-With numerical prefix arg, use the nth allowed value, 0 stands for the
-10th allowed value.
-
-When INCREMENT is non-nil, set the property to the next allowed value."
+If INCREMENT is non-nil, set the property to the next allowed
+value.  Otherwise, if optional argument VALUE is provided, use
+it.  Eventually, prompt for the new value if none of the previous
+variables is set."
   (interactive "P")
-  (when (equal value 0) (setq value 10))
-  (let* ((completion-ignore-case t)
-        (prop org-effort-property)
-        (cur (org-entry-get nil prop))
-        (allowed (org-property-get-allowed-values nil prop 'table))
-        (existing (mapcar 'list (org-property-values prop)))
-        (heading (nth 4 (org-heading-components)))
-        rpl
-        (val (cond
-              ((stringp value) value)
-              ((and allowed (integerp value))
-               (or (car (nth (1- value) allowed))
-                   (car (org-last allowed))))
-              ((and allowed increment)
-               (or (cl-caadr (member (list cur) allowed))
-                   (user-error "Allowed effort values are not set")))
-              (allowed
-               (message "Select 1-9,0, [RET%s]: %s"
-                        (if cur (concat "=" cur) "")
-                        (mapconcat 'car allowed " "))
-               (setq rpl (read-char-exclusive))
-               (if (equal rpl ?\r)
-                   cur
-                 (setq rpl (- rpl ?0))
-                 (when (equal rpl 0) (setq rpl 10))
-                 (if (and (> rpl 0) (<= rpl (length allowed)))
-                     (car (nth (1- rpl) allowed))
-                   (org-completing-read "Effort: " allowed nil))))
-              (t
-               (org-completing-read
-                (concat "Effort" (and cur (string-match "\\S-" cur)
-                                      (concat " [" cur "]"))
-                        ": ")
-                existing nil nil "" nil cur)))))
-    (unless (equal (org-entry-get nil prop) val)
-      (org-entry-put nil prop val))
-    (org-refresh-property
-     '((effort . identity)
-       (effort-minutes . org-duration-to-minutes))
-     val)
-    (when (equal heading (bound-and-true-p org-clock-current-task))
-      (setq org-clock-effort (get-text-property (point-at-bol) 'effort))
+  (let* ((allowed (org-property-get-allowed-values nil org-effort-property t))
+        (current (org-entry-get nil org-effort-property))
+        (value
+         (cond
+          (increment
+           (unless allowed (user-error "Allowed effort values are not set"))
+           (or (cl-caadr (member (list current) allowed))
+               (user-error "Unknown value %S among allowed values" current)))
+          (value
+           (if (stringp value) value
+             (error "Invalid effort value: %S" value)))
+          (t
+           (let ((must-match
+                  (and allowed
+                       (not (get-text-property 0 'org-unrestricted
+                                               (caar allowed))))))
+             (completing-read "Effort: " allowed nil must-match))))))
+    (unless (equal current value)
+      (org-entry-put nil org-effort-property value))
+    (org-refresh-property '((effort . identity)
+                           (effort-minutes . org-duration-to-minutes))
+                         value)
+    (when (equal (org-get-heading t t t t)
+                (bound-and-true-p org-clock-current-task))
+      (setq org-clock-effort value)
       (org-clock-update-mode-line))
-    (message "%s is now %s" prop val)))
+    (message "%s is now %s" org-effort-property value)))
 
 (defun org-entry-properties (&optional pom which)
   "Get all properties of the current entry.
@@ -15629,14 +13080,15 @@ strings."
                    props)
              (when specific (throw 'exit props)))
            (when (or (not specific) (string= specific "TAGS"))
-             (let ((value (org-string-nw-p (org-get-tags-string))))
-               (when value (push (cons "TAGS" value) props)))
+             (let ((tags (org-get-tags nil t)))
+               (when tags
+                 (push (cons "TAGS" (org-make-tag-string tags))
+                       props)))
              (when specific (throw 'exit props)))
            (when (or (not specific) (string= specific "ALLTAGS"))
-             (let ((value (org-get-tags-at)))
-               (when value
-                 (push (cons "ALLTAGS"
-                             (format ":%s:" (mapconcat #'identity value ":")))
+             (let ((tags (org-get-tags)))
+               (when tags
+                 (push (cons "ALLTAGS" (org-make-tag-string tags))
                        props)))
              (when specific (throw 'exit props)))
            (when (or (not specific) (string= specific "BLOCKED"))
@@ -15987,10 +13439,10 @@ decreases scheduled or deadline date by one day."
              ((not (member value org-todo-keywords-1))
               (user-error "\"%s\" is not a valid TODO state" value)))
        (org-todo value)
-       (org-set-tags nil 'align))
+       (org-align-tags))
        ((equal property "PRIORITY")
        (org-priority (if (org-string-nw-p value) (string-to-char value) ?\s))
-       (org-set-tags nil 'align))
+       (org-align-tags))
        ((equal property "SCHEDULED")
        (forward-line)
        (if (and (looking-at-p org-planning-line-re)
@@ -16033,8 +13485,7 @@ decreases scheduled or deadline date by one day."
          (org-indent-line)))))
     (run-hook-with-args 'org-property-changed-functions property value)))
 
-(defun org-buffer-property-keys
-    (&optional specials defaults columns ignore-malformed)
+(defun org-buffer-property-keys (&optional specials defaults columns)
   "Get all property keys in the current buffer.
 
 When SPECIALS is non-nil, also list the special properties that
@@ -16045,10 +13496,7 @@ special meaning internally: ARCHIVE, CATEGORY, SUMMARY,
 DESCRIPTION, LOCATION, and LOGGING and others.
 
 When COLUMNS in non-nil, also include property names given in
-COLUMN formats in the current buffer.
-
-When IGNORE-MALFORMED is non-nil, malformed drawer repair will not be
-automatically performed, such drawers will be silently ignored."
+COLUMN formats in the current buffer."
   (let ((case-fold-search t)
        (props (append
                (and specials org-special-properties)
@@ -16057,15 +13505,9 @@ automatically performed, such drawers will be silently 
ignored."
     (org-with-wide-buffer
      (goto-char (point-min))
      (while (re-search-forward org-property-start-re nil t)
-       (let ((range (org-get-property-block)))
-        (catch 'skip
-          (unless range
-            (when (and (not ignore-malformed)
-                       (not (org-before-first-heading-p))
-                       (y-or-n-p (format "Malformed drawer at %d, repair?"
-                                         (line-beginning-position))))
-              (org-get-property-block nil t))
-            (throw 'skip nil))
+       (catch :skip
+        (let ((range (org-get-property-block)))
+          (unless range (throw :skip nil))
           (goto-char (car range))
           (let ((begin (car range))
                 (end (cdr range)))
@@ -16083,7 +13525,7 @@ automatically performed, such drawers will be silently 
ignored."
             ;; :PROPERTIES:
             ;; #+END_EXAMPLE
             ;;
-            (if (< begin (point)) (throw 'skip nil) (goto-char begin))
+            (if (< begin (point)) (throw :skip nil) (goto-char begin))
             (while (< (point) end)
               (let ((p (progn (looking-at org-property-re)
                               (match-string-no-properties 2))))
@@ -16121,7 +13563,9 @@ automatically performed, such drawers will be silently 
ignored."
      (delete-dups values))))
 
 (defun org-insert-property-drawer ()
-  "Insert a property drawer into the current entry."
+  "Insert a property drawer into the current entry.
+Do nothing if the drawer already exists.  The newly created
+drawer is immediately hidden."
   (org-with-wide-buffer
    (if (or (not (featurep 'org-inlinetask)) (org-inlinetask-in-task-p))
        (org-back-to-heading t)
@@ -16136,6 +13580,7 @@ automatically performed, such drawers will be silently 
ignored."
      (let ((begin (1+ (point)))
           (inhibit-read-only t))
        (insert "\n:PROPERTIES:\n:END:")
+       (org-flag-drawer t nil (line-end-position 0) (point))
        (when (eobp) (insert "\n"))
        (org-indent-region begin (point))))))
 
@@ -16212,23 +13657,33 @@ This is computed according to 
`org-property-set-functions-alist'."
   (or (cdr (assoc property org-property-set-functions-alist))
       'org-completing-read))
 
-(defun org-read-property-value (property)
-  "Read PROPERTY value from user."
+(defun org-read-property-value (property &optional pom)
+  "Read value for PROPERTY, as a string.
+When optional argument POM is non-nil, completion uses additional
+information, i.e., allowed or existing values at point or marker
+POM."
   (let* ((completion-ignore-case t)
-        (allowed (org-property-get-allowed-values nil property 'table))
-        (cur (org-entry-get nil property))
-        (prompt (concat property " value"
-                        (if (and cur (string-match "\\S-" cur))
-                            (concat " [" cur "]") "") ": "))
-        (set-function (org-set-property-function property))
-        (val (if allowed
-                 (funcall set-function prompt allowed nil
-                          (not (get-text-property 0 'org-unrestricted
-                                                  (caar allowed))))
-               (funcall set-function prompt
-                        (mapcar 'list (org-property-values property))
-                        nil nil "" nil cur))))
-    (org-trim val)))
+        (allowed
+         (or (org-property-get-allowed-values nil property 'table)
+             (and pom (org-property-get-allowed-values pom property 'table))))
+        (current (org-entry-get nil property))
+        (prompt (format "%s value%s: "
+                        property
+                        (if (org-string-nw-p current)
+                            (format " [%s]" current)
+                          "")))
+        (set-function (org-set-property-function property)))
+    (org-trim
+     (if allowed
+        (funcall set-function
+                 prompt allowed nil
+                 (not (get-text-property 0 'org-unrestricted (caar allowed))))
+       (let ((all (mapcar #'list
+                         (append (org-property-values property)
+                                 (and pom
+                                      (org-with-point-at pom
+                                        (org-property-values property)))))))
+        (funcall set-function prompt all nil nil "" nil current))))))
 
 (defvar org-last-set-property nil)
 (defvar org-last-set-property-value nil)
@@ -16562,20 +14017,21 @@ non-nil."
              ((org-at-timestamp-p 'lax) (match-string 0))))
         ;; Default time is either the timestamp at point or today.
         ;; When entering a range, only the range start is considered.
-        (default-time (and ts (org-time-string-to-time ts)))
+         (default-time (and ts (org-time-string-to-time ts)))
          (default-input (and ts (org-get-compact-tod ts)))
          (repeater (and ts
                        (string-match "\\([.+-]+[0-9]+[hdwmy] ?\\)+" ts)
                        (match-string 0 ts)))
         org-time-was-given
         org-end-time-was-given
-        (time (if (equal arg '(16)) (current-time)
-                ;; Preserve `this-command' and `last-command'.
-                (let ((this-command this-command)
-                      (last-command last-command))
-                  (org-read-date
-                   arg 'totime nil nil default-time default-input
-                   inactive)))))
+        (time
+         (if (equal arg '(16)) (current-time)
+           ;; Preserve `this-command' and `last-command'.
+           (let ((this-command this-command)
+                 (last-command last-command))
+             (org-read-date
+              arg 'totime nil nil default-time default-input
+              inactive)))))
     (cond
      ((and ts
            (memq last-command '(org-time-stamp org-time-stamp-inactive))
@@ -16656,78 +14112,6 @@ with the current time without prompting the user."
 (defvar org-read-date-analyze-futurep nil)
 (defvar org-read-date-analyze-forced-year nil)
 (defvar org-read-date-inactive)
-
-(defvar org-read-date-minibuffer-local-map
-  (let* ((map (make-sparse-keymap)))
-    (set-keymap-parent map minibuffer-local-map)
-    (org-defkey map (kbd ".")
-                (lambda () (interactive)
-                 ;; Are we at the beginning of the prompt?
-                 (if (looking-back "^[^:]+: "
-                                   (let ((inhibit-field-text-motion t))
-                                     (line-beginning-position)))
-                     (org-eval-in-calendar '(calendar-goto-today))
-                   (insert "."))))
-    (org-defkey map (kbd "C-.")
-                (lambda () (interactive)
-                 (org-eval-in-calendar '(calendar-goto-today))))
-    (org-defkey map [(meta shift left)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-backward-month 1))))
-    (org-defkey map [(meta shift right)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-forward-month 1))))
-    (org-defkey map [(meta shift up)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-backward-year 1))))
-    (org-defkey map [(meta shift down)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-forward-year 1))))
-    (org-defkey map [?\e (shift left)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-backward-month 1))))
-    (org-defkey map [?\e (shift right)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-forward-month 1))))
-    (org-defkey map [?\e (shift up)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-backward-year 1))))
-    (org-defkey map [?\e (shift down)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-forward-year 1))))
-    (org-defkey map [(shift up)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-backward-week 1))))
-    (org-defkey map [(shift down)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-forward-week 1))))
-    (org-defkey map [(shift left)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-backward-day 1))))
-    (org-defkey map [(shift right)]
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-forward-day 1))))
-    (org-defkey map "!"
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(diary-view-entries))
-                  (message "")))
-    (org-defkey map ">"
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-scroll-left 1))))
-    (org-defkey map "<"
-                (lambda () (interactive)
-                  (org-eval-in-calendar '(calendar-scroll-right 1))))
-    (org-defkey map "\C-v"
-                (lambda () (interactive)
-                  (org-eval-in-calendar
-                   '(calendar-scroll-left-three-months 1))))
-    (org-defkey map "\M-v"
-                (lambda () (interactive)
-                  (org-eval-in-calendar
-                   '(calendar-scroll-right-three-months 1))))
-    map)
-  "Keymap for minibuffer commands when using `org-read-date'.")
-
 (defvar org-def)
 (defvar org-defdecode)
 (defvar org-with-time)
@@ -16808,7 +14192,7 @@ user."
     (when (< (nth 2 org-defdecode) org-extend-today-until)
       (setf (nth 2 org-defdecode) -1)
       (setf (nth 1 org-defdecode) 59)
-      (setq org-def (encode-time org-defdecode))
+      (setq org-def (apply #'encode-time org-defdecode))
       (setq org-defdecode (decode-time org-def)))
     (let* ((timestr (format-time-string
                     (if org-with-time "%Y-%m-%d %H:%M" "%Y-%m-%d")
@@ -16935,12 +14319,9 @@ user."
 (defun org-read-date-analyze (ans def defdecode)
   "Analyze the combined answer of the date prompt."
   ;; FIXME: cleanup and comment
-  ;; Pass `current-time' result to `decode-time' (instead of calling
-  ;; without arguments) so that only `current-time' has to be
-  ;; overridden in tests.
   (let ((org-def def)
        (org-defdecode defdecode)
-       (nowdecode (decode-time (current-time)))
+       (nowdecode (decode-time))
        delta deltan deltaw deltadef year month day
        hour minute second wday pm h2 m2 tl wday1
        iso-year iso-weekday iso-week iso-date futurep kill-year)
@@ -17117,10 +14498,7 @@ user."
      (deltan
       (setq futurep nil)
       (unless deltadef
-       ;; Pass `current-time' result to `decode-time' (instead of
-       ;; calling without arguments) so that only `current-time' has
-       ;; to be overridden in tests.
-       (let ((now (decode-time (current-time))))
+       (let ((now (decode-time)))
          (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
       (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
            ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
@@ -17285,15 +14663,15 @@ The command returns the inserted time stamp."
          time (org-fix-decoded-time t1)
          str (org-add-props
                  (format-time-string
-                  (substring tf 1 -1) (encode-time time))
+                  (substring tf 1 -1) (apply 'encode-time time))
                  nil 'mouse-face 'highlight))
     (put-text-property beg end 'display str)))
 
 (defun org-fix-decoded-time (time)
-  "Set 0 instead of nil for the time-related elements of time.
+  "Set 0 instead of nil for the first 6 elements of time.
 Don't touch the rest."
   (let ((n 0))
-    (mapcar (lambda (x) (if (or (< (setq n (1+ n)) 7) (= n 10)) (or x 0) x)) 
time)))
+    (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
 
 (defun org-time-stamp-to-now (timestamp-string &optional seconds)
   "Difference between TIMESTAMP-STRING and now in days.
@@ -17540,7 +14918,7 @@ days in order to avoid rounding problems."
 
 (defun org-time-string-to-time (s)
   "Convert timestamp string S into internal time."
-  (encode-time (org-parse-time-string s)))
+  (apply #'encode-time (org-parse-time-string s)))
 
 (defun org-time-string-to-seconds (s)
   "Convert a timestamp string S into a number of seconds."
@@ -17761,37 +15139,11 @@ day number."
           (list (nth 4 d) (nth 3 d) (nth 5 d))))
        ((listp d) (list (nth 4 d) (nth 3 d) (nth 5 d)))))
 
-(defun org-parse-time-string (s &optional nodefault)
-  "Parse the standard Org time string.
-
-This should be a lot faster than the normal `parse-time-string'.
-
-If time is not given, defaults to 0:00.  However, with optional
-NODEFAULT, hour and minute fields will be nil if not given."
-  (cond ((string-match org-ts-regexp0 s)
-        (list 0
-              (when (or (match-beginning 8) (not nodefault))
-                (string-to-number (or (match-string 8 s) "0")))
-              (when (or (match-beginning 7) (not nodefault))
-                (string-to-number (or (match-string 7 s) "0")))
-              (string-to-number (match-string 4 s))
-              (string-to-number (match-string 3 s))
-              (string-to-number (match-string 2 s))
-              nil nil nil))
-       ((string-match "^<[^>]+>$" s)
-        ;; FIXME: `decode-time' needs to be called with ZONE as its
-        ;; second argument.  However, this requires at least Emacs
-        ;; 25.1.  We can do it when we switch to this version as our
-        ;; minimal requirement.
-        ;; FIXME: decode-time needs to be called with t as its
-        ;; third argument, but this requires at least Emacs 27.
-        (decode-time (org-matcher-time s)))
-       (t (error "Not a standard Org time string: %s" s))))
-
 (defun org-timestamp-up (&optional arg)
   "Increase the date item at the cursor by one.
 If the cursor is on the year, change the year.  If it is on the month,
-the day or the time, change that.
+the day or the time, change that.  If the cursor is on the enclosing
+bracket, change the timestamp type.
 With prefix ARG, change by that many units."
   (interactive "p")
   (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
@@ -17799,7 +15151,8 @@ With prefix ARG, change by that many units."
 (defun org-timestamp-down (&optional arg)
   "Decrease the date item at the cursor by one.
 If the cursor is on the year, change the year.  If it is on the month,
-the day or the time, change that.
+the day or the time, change that.  If the cursor is on the enclosing
+bracket, change the timestamp type.
 With prefix ARG, change by that many units."
   (interactive "p")
   (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
@@ -17919,10 +15272,16 @@ When matching, the match groups are the following:
 (defvar org-clock-adjust-closest nil)          ; defined in org-clock.el
 (defun org-timestamp-change (n &optional what updown suppress-tmp-delay)
   "Change the date in the time stamp at point.
-The date will be changed by N times WHAT.  WHAT can be `day', `month',
-`year', `minute', `second'.  If WHAT is not given, the cursor position
-in the timestamp determines what will be changed.
-When SUPPRESS-TMP-DELAY is non-nil, suppress delays like \"--2d\"."
+
+The date is changed by N times WHAT.  WHAT can be `day', `month',
+`year', `hour', or `minute'.  If WHAT is not given, the cursor
+position in the timestamp determines what is changed.
+
+When optional argument UPDOWN is non-nil, minutes are rounded
+according to `org-time-stamp-rounding-minutes'.
+
+When SUPPRESS-TMP-DELAY is non-nil, suppress delays like
+\"--2d\"."
   (let ((origin (point))
        (timestamp? (org-at-timestamp-p 'lax))
        origin-cat
@@ -17989,7 +15348,7 @@ When SUPPRESS-TMP-DELAY is non-nil, suppress delays 
like \"--2d\"."
          (setcar time0 (or (car time0) 0))
          (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
          (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
-         (setq time (encode-time time0))))
+         (setq time (apply 'encode-time time0))))
       ;; Insert the new time-stamp, and ensure point stays in the same
       ;; category as before (i.e. not after the last position in that
       ;; category).
@@ -18069,7 +15428,7 @@ When SUPPRESS-TMP-DELAY is non-nil, suppress delays 
like \"--2d\"."
              h (string-to-number (match-string 2 s)))
        (if (org-pos-in-match-range pos 2)
            (setq h (+ h n))
-         (setq n (* dm (with-no-warnings (signum n))))
+         (setq n (* dm (with-no-warnings (cl-signum n))))
          (unless (= 0 (setq rem (% m dm)))
            (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
          (setq m (+ m n)))
@@ -18137,36 +15496,11 @@ If there is already a time stamp at the cursor 
position, update it."
       (org-insert-time-stamp
        (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
 
-(defcustom org-effort-durations
-  `(("min" . 1)
-    ("h" . 60)
-    ("d" . ,(* 60 8))
-    ("w" . ,(* 60 8 5))
-    ("m" . ,(* 60 8 5 4))
-    ("y" . ,(* 60 8 5 40)))
-  "Conversion factor to minutes for an effort modifier.
-
-Each entry has the form (MODIFIER . MINUTES).
-
-In an effort string, a number followed by MODIFIER is multiplied
-by the specified number of MINUTES to obtain an effort in
-minutes.
-
-For example, if the value of this variable is ((\"hours\" . 60)), then an
-effort string \"2hours\" is equivalent to 120 minutes."
-  :group 'org-agenda
-  :version "26.1"
-  :package-version '(Org . "8.3")
-  :type '(alist :key-type (string :tag "Modifier")
-               :value-type (number :tag "Minutes")))
-
 (defcustom org-image-actual-width t
-  "Should we use the actual width of images when inlining them?
-
-When set to t, always use the image width.
+  "When non-nil, use the actual width of images when inlining them.
 
-When set to a number, use imagemagick (when available) to set
-the image's width to this value.
+When set to a number, use imagemagick (when available) to set the
+image's width to this value.
 
 When set to a number in a list, try to get the width from any
 #+ATTR.* keyword if it matches a width specification like
@@ -18178,7 +15512,9 @@ and fall back on that number if none is found.
 When set to nil, try to get the width from an #+ATTR.* keyword
 and fall back on the original width if none is found.
 
-This requires Emacs >= 24.1, build with imagemagick support."
+When set to any other non-nil value, always use the image width.
+
+This requires Emacs >= 24.1, built with imagemagick support."
   :group 'org-appearance
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -18522,7 +15858,7 @@ When a buffer is unmodified, it is just killed.  When 
modified, it is saved
        (pall '(:org-archived t :org-comment t))
        (inhibit-read-only t)
        (org-inhibit-startup org-agenda-inhibit-startup)
-       (rea (concat ":" org-archive-tag ":"))
+       (rea (org-make-tag-string (list org-archive-tag)))
        re pos)
     (setq org-tag-alist-for-agenda nil
          org-tag-groups-alist-for-agenda nil)
@@ -18552,7 +15888,7 @@ When a buffer is unmodified, it is just killed.  When 
modified, it is saved
            (setq org-todo-keyword-alist-for-agenda
                  (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
            (setq org-tag-alist-for-agenda
-                 (org-tag-add-to-alist
+                 (org--tag-add-to-alist
                   org-tag-alist-for-agenda
                   org-current-tag-alist))
            ;; Merge current file's tag groups into global
@@ -18563,20 +15899,20 @@ When a buffer is unmodified, it is just killed.  When 
modified, it is saved
                  (if old
                      (setcdr old (org-uniquify (append (cdr old) (cdr alist))))
                    (push alist org-tag-groups-alist-for-agenda)))))
-           (org-with-silent-modifications
-            (save-excursion
-              (remove-text-properties (point-min) (point-max) pall)
-              (when org-agenda-skip-archived-trees
-                (goto-char (point-min))
-                (while (re-search-forward rea nil t)
-                  (when (org-at-heading-p t)
-                    (add-text-properties (point-at-bol) (org-end-of-subtree t) 
pa))))
-              (goto-char (point-min))
-              (setq re (format "^\\*+ .*\\<%s\\>" org-comment-string))
-              (while (re-search-forward re nil t)
-                (when (save-match-data (org-in-commented-heading-p t))
-                  (add-text-properties
-                   (match-beginning 0) (org-end-of-subtree t) pc)))))
+           (with-silent-modifications
+             (save-excursion
+               (remove-text-properties (point-min) (point-max) pall)
+               (when org-agenda-skip-archived-trees
+                 (goto-char (point-min))
+                 (while (re-search-forward rea nil t)
+                   (when (org-at-heading-p t)
+                     (add-text-properties (point-at-bol) (org-end-of-subtree 
t) pa))))
+               (goto-char (point-min))
+               (setq re (format "^\\*+ .*\\<%s\\>" org-comment-string))
+               (while (re-search-forward re nil t)
+                 (when (save-match-data (org-in-commented-heading-p t))
+                   (add-text-properties
+                    (match-beginning 0) (org-end-of-subtree t) pc)))))
            (goto-char pos)))))
     (setq org-todo-keywords-for-agenda
           (org-uniquify org-todo-keywords-for-agenda))
@@ -18589,11 +15925,11 @@ When a buffer is unmodified, it is just killed.  When 
modified, it is saved
 (defvar org-cdlatex-mode-map (make-sparse-keymap)
   "Keymap for the minor `org-cdlatex-mode'.")
 
-(org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
-(org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
-(org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
-(org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
-(org-defkey org-cdlatex-mode-map "\C-c{" 'org-cdlatex-environment-indent)
+(org-defkey org-cdlatex-mode-map (kbd "_") #'org-cdlatex-underscore-caret)
+(org-defkey org-cdlatex-mode-map (kbd "^") #'org-cdlatex-underscore-caret)
+(org-defkey org-cdlatex-mode-map (kbd "`") #'cdlatex-math-symbol)
+(org-defkey org-cdlatex-mode-map (kbd "'") #'org-cdlatex-math-modify)
+(org-defkey org-cdlatex-mode-map (kbd "C-c {") 
#'org-cdlatex-environment-indent)
 
 (defvar org-cdlatex-texmathp-advice-is-done nil
   "Flag remembering if we have applied the advice to texmathp already.")
@@ -18706,7 +16042,7 @@ environment remains unintended."
       (let ((ind (if (bolp) 0
                   (save-excursion
                     (org-return-indent)
-                    (prog1 (org-get-indentation)
+                    (prog1 (current-indentation)
                       (when (progn (skip-chars-forward " \t") (eolp))
                         (delete-region beg (point)))))))
            (bol (progn (skip-chars-backward " \t") (bolp))))
@@ -18779,7 +16115,7 @@ looks only before point, not after."
     (org-in-regexp
      "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
 
-(defun org--format-latex-make-overlay (beg end image &optional imagetype)
+(defun org--make-preview-overlay (beg end image &optional imagetype)
   "Build an overlay between BEG and END using IMAGE file.
 Argument IMAGETYPE is the extension of the displayed image,
 as a string.  It defaults to \"png\"."
@@ -18795,88 +16131,91 @@ as a string.  It defaults to \"png\"."
                 'display
                 (list 'image :type imagetype :file image :ascent 'center))))
 
-(defun org--list-latex-overlays (&optional beg end)
-  "List all Org LaTeX overlays in current buffer.
-Limit to overlays between BEG and END when those are provided."
-  (cl-remove-if-not
-   (lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay))
-   (overlays-in (or beg (point-min)) (or end (point-max)))))
-
-(defun org-remove-latex-fragment-image-overlays (&optional beg end)
+(defun org-clear-latex-preview (&optional beg end)
   "Remove all overlays with LaTeX fragment images in current buffer.
 When optional arguments BEG and END are non-nil, remove all
 overlays between them instead.  Return a non-nil value when some
 overlays were removed, nil otherwise."
-  (let ((overlays (org--list-latex-overlays beg end)))
+  (let ((overlays
+        (cl-remove-if-not
+         (lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay))
+         (overlays-in (or beg (point-min)) (or end (point-max))))))
     (mapc #'delete-overlay overlays)
     overlays))
 
-(defun org-toggle-latex-fragment (&optional arg)
-  "Preview the LaTeX fragment at point, or all locally or globally.
-
-If the cursor is on a LaTeX fragment, create the image and overlay
-it over the source code, if there is none.  Remove it otherwise.
-If there is no fragment at point, display all fragments in the
-current section.
+(defun org--latex-preview-region (beg end)
+  "Preview LaTeX fragments between BEG and END.
+BEG and END are buffer positions."
+  (let ((file (buffer-file-name (buffer-base-buffer))))
+    (save-excursion
+      (org-format-latex
+       (concat org-preview-latex-image-directory "org-ltximg")
+       beg end
+       ;; Emacs cannot overlay images from remote hosts.  Create it in
+       ;; `temporary-file-directory' instead.
+       (if (or (not file) (file-remote-p file))
+           temporary-file-directory
+        default-directory)
+       'overlays nil 'forbuffer org-preview-latex-default-process))))
+
+(defun org-latex-preview (&optional arg)
+  "Toggle preview of the LaTeX fragment at point.
+
+If the cursor is on a LaTeX fragment, create the image and
+overlay it over the source code, if there is none.  Remove it
+otherwise.  If there is no fragment at point, display images for
+all fragments in the current section.
+
+With a `\\[universal-argument]' prefix argument ARG, clear images \
+for all fragments
+in the current section.
+
+With a `\\[universal-argument] \\[universal-argument]' prefix \
+argument ARG, display image for all
+fragments in the buffer.
 
-With prefix ARG, preview or clear image for all fragments in the
-current subtree or in the whole buffer when used before the first
-headline.  With a prefix ARG `\\[universal-argument] \
-\\[universal-argument]' preview or clear images
-for all fragments in the buffer."
+With a `\\[universal-argument] \\[universal-argument] \
+\\[universal-argument]' prefix argument ARG, clear image for all
+fragments in the buffer."
   (interactive "P")
-  (when (display-graphic-p)
-    (catch 'exit
-      (save-excursion
-       (let (beg end msg)
-         (cond
-          ((or (equal arg '(16))
-               (and (equal arg '(4))
-                    (org-with-limited-levels (org-before-first-heading-p))))
-           (if (org-remove-latex-fragment-image-overlays)
-               (progn (message "LaTeX fragments images removed from buffer")
-                      (throw 'exit nil))
-             (setq msg "Creating images for buffer...")))
-          ((equal arg '(4))
-           (org-with-limited-levels (org-back-to-heading t))
-           (setq beg (point))
-           (setq end (progn (org-end-of-subtree t) (point)))
-           (if (org-remove-latex-fragment-image-overlays beg end)
-               (progn
-                 (message "LaTeX fragment images removed from subtree")
-                 (throw 'exit nil))
-             (setq msg "Creating images for subtree...")))
-          ((let ((datum (org-element-context)))
-             (when (memq (org-element-type datum)
-                         '(latex-environment latex-fragment))
-               (setq beg (org-element-property :begin datum))
-               (setq end (org-element-property :end datum))
-               (if (org-remove-latex-fragment-image-overlays beg end)
-                   (progn (message "LaTeX fragment image removed")
-                          (throw 'exit nil))
-                 (setq msg "Creating image...")))))
-          (t
-           (org-with-limited-levels
-            (setq beg (if (org-at-heading-p) (line-beginning-position)
-                        (outline-previous-heading)
-                        (point)))
-            (setq end (progn (outline-next-heading) (point)))
-            (if (org-remove-latex-fragment-image-overlays beg end)
-                (progn
-                  (message "LaTeX fragment images removed from section")
-                  (throw 'exit nil))
-              (setq msg "Creating images for section...")))))
-         (let ((file (buffer-file-name (buffer-base-buffer))))
-           (org-format-latex
-            (concat org-preview-latex-image-directory "org-ltximg")
-            beg end
-            ;; Emacs cannot overlay images from remote hosts.  Create
-            ;; it in `temporary-file-directory' instead.
-            (if (or (not file) (file-remote-p file))
-                temporary-file-directory
-              default-directory)
-            'overlays msg 'forbuffer org-preview-latex-default-process))
-         (message (concat msg "done")))))))
+  (cond
+   ((not (display-graphic-p)) nil)
+   ;; Clear whole buffer.
+   ((equal arg '(64))
+    (org-clear-latex-preview (point-min) (point-max))
+    (message "LaTeX previews removed from buffer"))
+   ;; Preview whole buffer.
+   ((equal arg '(16))
+    (message "Creating LaTeX previews in buffer...")
+    (org--latex-preview-region (point-min) (point-max))
+    (message "Creating LaTeX previews in buffer... done."))
+   ;; Clear current section.
+   ((equal arg '(4))
+    (org-clear-latex-preview
+     (if (org-before-first-heading-p) (point-min)
+       (save-excursion
+        (org-with-limited-levels (org-back-to-heading t) (point))))
+     (org-with-limited-levels (org-entry-end-position))))
+   ;; Toggle preview on LaTeX code at point.
+   ((let ((datum (org-element-context)))
+      (and (memq (org-element-type datum) '(latex-environment latex-fragment))
+          (let ((beg (org-element-property :begin datum))
+                (end (org-element-property :end datum)))
+            (if (org-clear-latex-preview beg end)
+                (message "LaTeX preview removed")
+              (message "Creating LaTeX preview...")
+              (org--latex-preview-region beg end)
+              (message "Creating LaTeX preview... done."))
+            t))))
+   ;; Preview current section.
+   (t
+    (let ((beg (if (org-before-first-heading-p) (point-min)
+                (save-excursion
+                  (org-with-limited-levels (org-back-to-heading t) (point)))))
+         (end (org-with-limited-levels (org-entry-end-position))))
+      (message "Creating LaTeX previews in section...")
+      (org--latex-preview-region beg end)
+      (message "Creating LaTeX previews in section... done.")))))
 
 (defun org-format-latex
     (prefix &optional beg end dir overlays msg forbuffer processing-type)
@@ -18977,7 +16316,7 @@ Some of the options can be changed using the variable
                            (when (eq (overlay-get o 'org-overlay-type)
                                      'org-latex-overlay)
                              (delete-overlay o)))
-                         (org--format-latex-make-overlay beg end movefile 
imagetype)
+                         (org--make-preview-overlay beg end movefile imagetype)
                          (goto-char end))
                      (delete-region beg end)
                      (insert
@@ -19003,7 +16342,7 @@ Some of the options can be changed using the variable
 (defun org-create-math-formula (latex-frag &optional mathml-file)
   "Convert LATEX-FRAG to MathML and store it in MATHML-FILE.
 Use `org-latex-to-mathml-convert-command'.  If the conversion is
-sucessful, return the portion between \"<math...> </math>\"
+successful, return the portion between \"<math...> </math>\"
 elements otherwise return nil.  When MATHML-FILE is specified,
 write the results in to that file.  When invoked as an
 interactive command, prompt for LATEX-FRAG, with initial value
@@ -19123,7 +16462,6 @@ a HTML file."
          (cdr (assq processing-type org-preview-latex-process-alist)))
         (programs (plist-get processing-info :programs))
         (error-message (or (plist-get processing-info :message) ""))
-        (use-xcolor (plist-get processing-info :use-xcolor))
         (image-input-type (plist-get processing-info :image-input-type))
         (image-output-type (plist-get processing-info :image-output-type))
         (post-clean (or (plist-get processing-info :post-clean)
@@ -19154,36 +16492,23 @@ a HTML file."
         (resize-mini-windows nil)) ;Fix Emacs flicker when creating image.
     (dolist (program programs)
       (org-check-external-command program error-message))
-    (if use-xcolor
-       (progn (if (eq fg 'default)
-                  (setq fg (org-latex-color :foreground))
-                (setq fg (org-latex-color-format fg)))
-              (if (eq bg 'default)
-                  (setq bg (org-latex-color :background))
-                (setq bg (org-latex-color-format
-                          (if (string= bg "Transparent") "white" bg))))
-              (with-temp-file texfile
-                (insert latex-header)
-                (insert "\n\\begin{document}\n"
-                        "\\definecolor{fg}{rgb}{" fg "}\n"
-                        "\\definecolor{bg}{rgb}{" bg "}\n"
-                        "\n\\pagecolor{bg}\n"
-                        "\n{\\color{fg}\n"
-                        string
-                        "\n}\n"
-                        "\n\\end{document}\n")))
-      (if (eq fg 'default)
-         (setq fg (org-dvipng-color :foreground))
-       (unless (string= fg "Transparent")
-         (setq fg (org-dvipng-color-format fg))))
-      (if (eq bg 'default)
-         (setq bg (org-dvipng-color :background))
-       (unless (string= bg "Transparent")
-         (setq bg (org-dvipng-color-format bg))))
-      (with-temp-file texfile
-       (insert latex-header)
-       (insert "\n\\begin{document}\n" string "\n\\end{document}\n")))
-
+    (if (eq fg 'default)
+       (setq fg (org-latex-color :foreground))
+      (setq fg (org-latex-color-format fg)))
+    (if (eq bg 'default)
+       (setq bg (org-latex-color :background))
+      (setq bg (org-latex-color-format
+               (if (string= bg "Transparent") "white" bg))))
+    (with-temp-file texfile
+      (insert latex-header)
+      (insert "\n\\begin{document}\n"
+             "\\definecolor{fg}{rgb}{" fg "}\n"
+             "\\definecolor{bg}{rgb}{" bg "}\n"
+             "\n\\pagecolor{bg}\n"
+             "\n{\\color{fg}\n"
+             string
+             "\n}\n"
+             "\n\\end{document}\n"))
     (let* ((err-msg (format "Please adjust `%s' part of \
 `org-preview-latex-process-alist'."
                            processing-type))
@@ -19193,9 +16518,7 @@ a HTML file."
           (image-output-file
            (org-compile-file
             image-input-file image-converter image-output-type err-msg log-buf
-            `((?F . ,(shell-quote-argument fg))
-              (?B . ,(shell-quote-argument bg))
-              (?D . ,(shell-quote-argument (format "%s" dpi)))
+            `((?D . ,(shell-quote-argument (format "%s" dpi)))
               (?S . ,(shell-quote-argument (format "%s" (/ dpi 140.0))))))))
       (copy-file image-output-file tofile 'replace)
       (dolist (e post-clean)
@@ -19286,7 +16609,6 @@ SNIPPETS-P indicates if this is run to create snippet 
images for HTML."
   "Return string to be used as color value for an RGB component."
   (format "%g" (/ value 65535.0)))
 
-
 
 ;; Image display
 
@@ -19329,7 +16651,10 @@ conventions:
      from `image-file-name-regexp' and it has no contents.
 
   2. Its description consists in a single link of the previous
-     type.
+     type.  In this case, that link must be a well-formed plain
+     or angle link, i.e., it must have an explicit \"file\" type.
+
+Equip each image with the key-map `image-map'.
 
 When optional argument INCLUDE-LINKED is non-nil, also links with
 a text description part will be inlined.  This can be nice for
@@ -19338,96 +16663,123 @@ exported files will look like.
 
 When optional argument REFRESH is non-nil, refresh existing
 images between BEG and END.  This will create new image displays
-only if necessary.  BEG and END default to the buffer
-boundaries."
+only if necessary.
+
+BEG and END define the considered part.  They default to the
+buffer boundaries with possible narrowing."
   (interactive "P")
   (when (display-graphic-p)
     (unless refresh
       (org-remove-inline-images)
       (when (fboundp 'clear-image-cache) (clear-image-cache)))
-    (org-with-wide-buffer
-     (goto-char (or beg (point-min)))
-     (let* ((case-fold-search t)
-           (file-extension-re (image-file-name-regexp))
-           (link-abbrevs (mapcar #'car
-                                 (append org-link-abbrev-alist-local
-                                         org-link-abbrev-alist)))
-           ;; Check absolute, relative file names and explicit
-           ;; "file:" links.  Also check link abbreviations since
-           ;; some might expand to "file" links.
-           (file-types-re (format "[][]\\[\\(?:file\\|[./~]%s\\)"
-                                  (if (not link-abbrevs) ""
-                                    (format "\\|\\(?:%s:\\)"
-                                            (regexp-opt link-abbrevs))))))
-       (while (re-search-forward file-types-re end t)
-        (let ((link (save-match-data (org-element-context))))
-          ;; Check if we're at an inline image, i.e., an image file
-          ;; link without a description (unless INCLUDE-LINKED is
-          ;; non-nil).
-          (when (and (equal "file" (org-element-property :type link))
-                     (or include-linked
-                         (null (org-element-contents link)))
-                     (string-match-p file-extension-re
-                                     (org-element-property :path link)))
-            (let ((file (expand-file-name
-                         (org-link-unescape
-                          (org-element-property :path link)))))
-              (when (file-exists-p file)
-                (let ((width
-                       ;; Apply `org-image-actual-width' specifications.
-                       (cond
-                        ((not (image-type-available-p 'imagemagick)) nil)
-                        ((eq org-image-actual-width t) nil)
-                        ((listp org-image-actual-width)
-                         (or
-                          ;; First try to find a width among
-                          ;; attributes associated to the paragraph
-                          ;; containing link.
-                          (let ((paragraph
-                                 (let ((e link))
-                                   (while (and (setq e (org-element-property
-                                                        :parent e))
-                                               (not (eq (org-element-type e)
-                                                        'paragraph))))
-                                   e)))
-                            (when paragraph
-                              (save-excursion
-                                (goto-char (org-element-property :begin 
paragraph))
-                                (when
-                                    (re-search-forward
-                                     "^[ \t]*#\\+attr_.*?: +.*?:width 
+\\(\\S-+\\)"
-                                     (org-element-property
-                                      :post-affiliated paragraph)
-                                     t)
-                                  (string-to-number (match-string 1))))))
-                          ;; Otherwise, fall-back to provided number.
-                          (car org-image-actual-width)))
-                        ((numberp org-image-actual-width)
-                         org-image-actual-width)))
-                      (old (get-char-property-and-overlay
-                            (org-element-property :begin link)
-                            'org-image-overlay)))
-                  (if (and (car-safe old) refresh)
-                      (image-refresh (overlay-get (cdr old) 'display))
-                    (let ((image (create-image file
-                                               (and width 'imagemagick)
-                                               nil
-                                               :width width)))
-                      (when image
-                        (let ((ov (make-overlay
-                                   (org-element-property :begin link)
-                                   (progn
-                                     (goto-char
-                                      (org-element-property :end link))
-                                     (skip-chars-backward " \t")
-                                     (point)))))
-                          (overlay-put ov 'display image)
-                          (overlay-put ov 'face 'default)
-                          (overlay-put ov 'org-image-overlay t)
-                          (overlay-put
-                           ov 'modification-hooks
-                           (list 'org-display-inline-remove-overlay))
-                          (push ov org-inline-image-overlays)))))))))))))))
+    (let ((end (or end (point-max))))
+      (org-with-point-at (or beg (point-min))
+       (let* ((case-fold-search t)
+              (file-extension-re (image-file-name-regexp))
+              (link-abbrevs (mapcar #'car
+                                    (append org-link-abbrev-alist-local
+                                            org-link-abbrev-alist)))
+              ;; Check absolute, relative file names and explicit
+              ;; "file:" links.  Also check link abbreviations since
+              ;; some might expand to "file" links.
+              (file-types-re
+               (format 
"\\[\\[\\(?:file%s:\\|attachment:\\|[./~]\\)\\|\\]\\[\\(<?file:\\)"
+                       (if (not link-abbrevs) ""
+                         (concat "\\|" (regexp-opt link-abbrevs))))))
+         (while (re-search-forward file-types-re end t)
+           (let* ((link (org-element-lineage
+                         (save-match-data (org-element-context))
+                         '(link) t))
+                   (linktype (org-element-property :type link))
+                  (inner-start (match-beginning 1))
+                  (path
+                   (cond
+                    ;; No link at point; no inline image.
+                    ((not link) nil)
+                    ;; File link without a description.  Also handle
+                    ;; INCLUDE-LINKED here since it should have
+                    ;; precedence over the next case.  I.e., if link
+                    ;; contains filenames in both the path and the
+                    ;; description, prioritize the path only when
+                    ;; INCLUDE-LINKED is non-nil.
+                    ((or (not (org-element-property :contents-begin link))
+                         include-linked)
+                     (and (or (equal "file" linktype)
+                               (equal "attachment" linktype))
+                          (org-element-property :path link)))
+                    ;; Link with a description.  Check if description
+                    ;; is a filename.  Even if Org doesn't have syntax
+                    ;; for those -- clickable image -- constructs, fake
+                    ;; them, as in `org-export-insert-image-links'.
+                    ((not inner-start) nil)
+                    (t
+                     (org-with-point-at inner-start
+                       (and (looking-at
+                             (if (char-equal ?< (char-after inner-start))
+                                 org-link-angle-re
+                               org-link-plain-re))
+                            ;; File name must fill the whole
+                            ;; description.
+                            (= (org-element-property :contents-end link)
+                               (match-end 0))
+                            (match-string 2)))))))
+             (when (and path (string-match-p file-extension-re path))
+               (let ((file (if (equal "attachment" linktype)
+                               (progn
+                                  (require 'org-attach)
+                                 (ignore-errors (org-attach-expand path)))
+                              (expand-file-name path))))
+                 (when (and file (file-exists-p file))
+                   (let ((width
+                          ;; Apply `org-image-actual-width' specifications.
+                          (cond
+                           ((eq org-image-actual-width t) nil)
+                           ((listp org-image-actual-width)
+                            (or
+                             ;; First try to find a width among
+                             ;; attributes associated to the paragraph
+                             ;; containing link.
+                             (pcase (org-element-lineage link '(paragraph))
+                               (`nil nil)
+                               (p
+                                (let* ((case-fold-search t)
+                                       (end (org-element-property 
:post-affiliated p))
+                                       (re "^[ \t]*#\\+attr_.*?: +.*?:width 
+\\(\\S-+\\)"))
+                                  (when (org-with-point-at
+                                            (org-element-property :begin p)
+                                          (re-search-forward re end t))
+                                    (string-to-number (match-string 1))))))
+                             ;; Otherwise, fall-back to provided number.
+                             (car org-image-actual-width)))
+                           ((numberp org-image-actual-width)
+                            org-image-actual-width)
+                           (t nil)))
+                         (old (get-char-property-and-overlay
+                               (org-element-property :begin link)
+                               'org-image-overlay)))
+                     (if (and (car-safe old) refresh)
+                         (image-refresh (overlay-get (cdr old) 'display))
+                       (let ((image (create-image file
+                                                  (and (image-type-available-p 
'imagemagick)
+                                                       width 'imagemagick)
+                                                  nil
+                                                  :width width)))
+                         (when image
+                           (let ((ov (make-overlay
+                                      (org-element-property :begin link)
+                                      (progn
+                                        (goto-char
+                                         (org-element-property :end link))
+                                        (skip-chars-backward " \t")
+                                        (point)))))
+                             (overlay-put ov 'display image)
+                             (overlay-put ov 'face 'default)
+                             (overlay-put ov 'org-image-overlay t)
+                             (overlay-put
+                              ov 'modification-hooks
+                              (list 'org-display-inline-remove-overlay))
+                             (overlay-put ov 'keymap image-map)
+                             (push ov org-inline-image-overlays))))))))))))))))
 
 (defun org-display-inline-remove-overlay (ov after _beg _end &optional _len)
   "Remove inline-display overlay if a corresponding region is modified."
@@ -19442,428 +16794,9 @@ boundaries."
   (mapc #'delete-overlay org-inline-image-overlays)
   (setq org-inline-image-overlays nil))
 
-;;;; Key bindings
-
-(defun org-remap (map &rest commands)
-  "In MAP, remap the functions given in COMMANDS.
-COMMANDS is a list of alternating OLDDEF NEWDEF command names."
-  (let (new old)
-    (while commands
-      (setq old (pop commands) new (pop commands))
-      (org-defkey map (vector 'remap old) new))))
-
-;; Outline functions from `outline-mode-prefix-map'
-;; that can be remapped in Org:
-(define-key org-mode-map [remap outline-mark-subtree] 'org-mark-subtree)
-(define-key org-mode-map [remap outline-show-subtree] 'org-show-subtree)
-(define-key org-mode-map [remap outline-forward-same-level]
-  'org-forward-heading-same-level)
-(define-key org-mode-map [remap outline-backward-same-level]
-  'org-backward-heading-same-level)
-(define-key org-mode-map [remap outline-show-branches]
-  'org-kill-note-or-show-branches)
-(define-key org-mode-map [remap outline-promote] 'org-promote-subtree)
-(define-key org-mode-map [remap outline-demote] 'org-demote-subtree)
-(define-key org-mode-map [remap outline-insert-heading] 'org-ctrl-c-ret)
-(define-key org-mode-map [remap outline-next-visible-heading]
-  'org-next-visible-heading)
-(define-key org-mode-map [remap outline-previous-visible-heading]
-  'org-previous-visible-heading)
-(define-key org-mode-map [remap show-children] 'org-show-children)
-
-;; Outline functions from `outline-mode-prefix-map' that can not
-;; be remapped in Org:
-
-;; - the column "key binding" shows whether the Outline function is still
-;;   available in Org mode on the same key that it has been bound to in
-;;   Outline mode:
-;;   - "overridden": key used for a different functionality in Org mode
-;;   - else: key still bound to the same Outline function in Org mode
-
-;; | Outline function                   | key binding | Org replacement        
  |
-;; 
|------------------------------------+-------------+--------------------------|
-;; | `outline-up-heading'               | `C-c C-u'   | still same function    
  |
-;; | `outline-move-subtree-up'          | overridden  | better: org-shiftup    
  |
-;; | `outline-move-subtree-down'        | overridden  | better: org-shiftdown  
  |
-;; | `show-entry'                       | overridden  | no replacement         
  |
-;; | `show-branches'                    | `C-c C-k'   | still same function    
  |
-;; | `show-subtree'                     | overridden  | visibility cycling     
  |
-;; | `show-all'                         | overridden  | no replacement         
  |
-;; | `hide-subtree'                     | overridden  | visibility cycling     
  |
-;; | `hide-body'                        | overridden  | no replacement         
  |
-;; | `hide-entry'                       | overridden  | visibility cycling     
  |
-;; | `hide-leaves'                      | overridden  | no replacement         
  |
-;; | `hide-sublevels'                   | overridden  | no replacement         
  |
-;; | `hide-other'                       | overridden  | no replacement         
  |
-
-;; Make `C-c C-x' a prefix key
-(org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
-
-;; TAB key with modifiers
-(org-defkey org-mode-map "\C-i"       'org-cycle)
-(org-defkey org-mode-map [(tab)]      'org-cycle)
-(org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
-(org-defkey org-mode-map "\M-\t" nil) ;; Override text-mode binding
-
-;; The following line is necessary under Suse GNU/Linux
-(org-defkey org-mode-map [S-iso-lefttab]  'org-shifttab)
-(org-defkey org-mode-map [(shift tab)]    'org-shifttab)
-(define-key org-mode-map [backtab] 'org-shifttab)
-
-(org-defkey org-mode-map [(shift return)]   'org-table-copy-down)
-(org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
-(org-defkey org-mode-map (kbd "M-RET") #'org-meta-return)
-
-;; Cursor keys with modifiers
-(org-defkey org-mode-map [(meta left)]  'org-metaleft)
-(org-defkey org-mode-map [(meta right)] 'org-metaright)
-(org-defkey org-mode-map [(meta up)]    'org-metaup)
-(org-defkey org-mode-map [(meta down)]  'org-metadown)
-
-(org-defkey org-mode-map [(control meta shift right)] 
'org-increase-number-at-point)
-(org-defkey org-mode-map [(control meta shift left)] 
'org-decrease-number-at-point)
-(org-defkey org-mode-map [(meta shift left)]   'org-shiftmetaleft)
-(org-defkey org-mode-map [(meta shift right)]  'org-shiftmetaright)
-(org-defkey org-mode-map [(meta shift up)]     'org-shiftmetaup)
-(org-defkey org-mode-map [(meta shift down)]   'org-shiftmetadown)
-
-(org-defkey org-mode-map [(shift up)]          'org-shiftup)
-(org-defkey org-mode-map [(shift down)]        'org-shiftdown)
-(org-defkey org-mode-map [(shift left)]        'org-shiftleft)
-(org-defkey org-mode-map [(shift right)]       'org-shiftright)
-
-(org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
-(org-defkey org-mode-map [(control shift left)]  'org-shiftcontrolleft)
-(org-defkey org-mode-map [(control shift up)] 'org-shiftcontrolup)
-(org-defkey org-mode-map [(control shift down)]  'org-shiftcontroldown)
-
-;; Babel keys
-(define-key org-mode-map org-babel-key-prefix org-babel-map)
-(dolist (pair org-babel-key-bindings)
-  (define-key org-babel-map (car pair) (cdr pair)))
-
-;;; Extra keys for tty access.
-;;  We only set them when really needed because otherwise the
-;;  menus don't show the simple keys
-
-(when (or org-use-extra-keys (not window-system))
-  (org-defkey org-mode-map "\C-c\C-xc"    'org-table-copy-down)
-  (org-defkey org-mode-map "\C-c\C-xM"    'org-insert-todo-heading)
-  (org-defkey org-mode-map "\C-c\C-xm"    'org-meta-return)
-  (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
-  (org-defkey org-mode-map [?\e (left)]   'org-metaleft)
-  (org-defkey org-mode-map "\C-c\C-xl"    'org-metaleft)
-  (org-defkey org-mode-map [?\e (right)]  'org-metaright)
-  (org-defkey org-mode-map "\C-c\C-xr"    'org-metaright)
-  (org-defkey org-mode-map [?\e (up)]     'org-metaup)
-  (org-defkey org-mode-map "\C-c\C-xu"    'org-metaup)
-  (org-defkey org-mode-map [?\e (down)]   'org-metadown)
-  (org-defkey org-mode-map "\C-c\C-xd"    'org-metadown)
-  (org-defkey org-mode-map "\C-c\C-xL"    'org-shiftmetaleft)
-  (org-defkey org-mode-map "\C-c\C-xR"    'org-shiftmetaright)
-  (org-defkey org-mode-map "\C-c\C-xU"    'org-shiftmetaup)
-  (org-defkey org-mode-map "\C-c\C-xD"    'org-shiftmetadown)
-  (org-defkey org-mode-map [?\C-c (up)]    'org-shiftup)
-  (org-defkey org-mode-map [?\C-c (down)]  'org-shiftdown)
-  (org-defkey org-mode-map [?\C-c (left)]  'org-shiftleft)
-  (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
-  (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
-  (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
-  (org-defkey org-mode-map [?\e (tab)] nil)  ;; Override text-mode binding
-  (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
-  (org-defkey org-mode-map [?\e (shift left)]   'org-shiftmetaleft)
-  (org-defkey org-mode-map [?\e (shift right)]  'org-shiftmetaright)
-  (org-defkey org-mode-map [?\e (shift up)]     'org-shiftmetaup)
-  (org-defkey org-mode-map [?\e (shift down)]   'org-shiftmetadown))
-
-;; All the other keys
-(org-remap org-mode-map
-          'self-insert-command 'org-self-insert-command
-          'delete-char 'org-delete-char
-          'delete-backward-char 'org-delete-backward-char)
-(org-defkey org-mode-map "|" 'org-force-self-insert)
-
-(org-defkey org-mode-map "\C-c\C-a" 'outline-show-all) ; in case allout messed 
up.
-(org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
-(if (boundp 'narrow-map)
-    (org-defkey narrow-map "s" 'org-narrow-to-subtree)
-  (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
-(if (boundp 'narrow-map)
-    (org-defkey narrow-map "b" 'org-narrow-to-block)
-  (org-defkey org-mode-map "\C-xnb" 'org-narrow-to-block))
-(if (boundp 'narrow-map)
-    (org-defkey narrow-map "e" 'org-narrow-to-element)
-  (org-defkey org-mode-map "\C-xne" 'org-narrow-to-element))
-(org-defkey org-mode-map "\C-\M-t"  'org-transpose-element)
-(org-defkey org-mode-map "\M-}"     'org-forward-element)
-(org-defkey org-mode-map "\M-{"     'org-backward-element)
-(org-defkey org-mode-map "\C-c\C-^" 'org-up-element)
-(org-defkey org-mode-map "\C-c\C-_" 'org-down-element)
-(org-defkey org-mode-map "\C-c\C-f" 'org-forward-heading-same-level)
-(org-defkey org-mode-map "\C-c\C-b" 'org-backward-heading-same-level)
-(org-defkey org-mode-map "\C-c\M-f" 'org-next-block)
-(org-defkey org-mode-map "\C-c\M-b" 'org-previous-block)
-(org-defkey org-mode-map "\C-c$"    'org-archive-subtree)
-(org-defkey org-mode-map "\C-c\C-x\C-s" 'org-archive-subtree)
-(org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
-(org-defkey org-mode-map "\C-c\C-xd" 'org-insert-drawer)
-(org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
-(org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
-(org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
-(org-defkey org-mode-map "\C-c\C-xq" 'org-toggle-tags-groups)
-(org-defkey org-mode-map "\C-c\C-j" 'org-goto)
-(org-defkey org-mode-map "\C-c\C-t" 'org-todo)
-(org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
-(org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
-(org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
-(org-defkey org-mode-map "\C-c;"    'org-toggle-comment)
-(org-defkey org-mode-map "\C-c\C-w" 'org-refile)
-(org-defkey org-mode-map "\C-c\M-w" 'org-copy)
-(org-defkey org-mode-map "\C-c/"    'org-sparse-tree)   ; Minor-mode reserved
-(org-defkey org-mode-map "\C-c\\"   'org-match-sparse-tree) ; Minor-mode res.
-(org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
-(org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
-(org-defkey org-mode-map "\C-c\C-xv" 'org-copy-visible)
-(org-defkey org-mode-map [(control return)] 
'org-insert-heading-respect-content)
-(org-defkey org-mode-map [(shift control return)] 
'org-insert-todo-heading-respect-content)
-(org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
-(org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
-(org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
-(org-defkey org-mode-map "\C-c\M-l" 'org-insert-last-stored-link)
-(org-defkey org-mode-map "\C-c\C-\M-l" 'org-insert-all-links)
-(org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
-(org-defkey org-mode-map "\C-c%"    'org-mark-ring-push)
-(org-defkey org-mode-map "\C-c&"    'org-mark-ring-goto)
-(org-defkey org-mode-map "\C-c\C-z" 'org-add-note)  ; Alternative binding
-(org-defkey org-mode-map "\C-c."    'org-time-stamp)  ; Minor-mode reserved
-(org-defkey org-mode-map "\C-c!"    'org-time-stamp-inactive) ; Minor-mode r.
-(org-defkey org-mode-map "\C-c,"    'org-priority)    ; Minor-mode reserved
-(org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
-(org-defkey org-mode-map "\C-c>"    'org-goto-calendar)
-(org-defkey org-mode-map "\C-c<"    'org-date-from-calendar)
-(org-defkey org-mode-map [(control ?,)]     'org-cycle-agenda-files)
-(org-defkey org-mode-map [(control ?\')]     'org-cycle-agenda-files)
-(org-defkey org-mode-map "\C-c["    'org-agenda-file-to-front)
-(org-defkey org-mode-map "\C-c]"    'org-remove-file)
-(org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
-(org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
-(org-defkey org-mode-map "\C-c-"    'org-ctrl-c-minus)
-(org-defkey org-mode-map "\C-c*"    'org-ctrl-c-star)
-(org-defkey org-mode-map "\C-c^"    'org-sort)
-(org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
-(org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
-(org-defkey org-mode-map "\C-c#"    'org-update-statistics-cookies)
-(org-defkey org-mode-map [remap open-line] 'org-open-line)
-(org-defkey org-mode-map [remap comment-dwim] 'org-comment-dwim)
-(org-defkey org-mode-map [remap forward-paragraph] 'org-forward-paragraph)
-(org-defkey org-mode-map [remap backward-paragraph] 'org-backward-paragraph)
-(org-defkey org-mode-map "\M-^"     'org-delete-indentation)
-(org-defkey org-mode-map "\C-m"     'org-return)
-(org-defkey org-mode-map "\C-j"     'org-return-indent)
-(org-defkey org-mode-map "\C-c?"    'org-table-field-info)
-(org-defkey org-mode-map "\C-c "    'org-table-blank-field)
-(org-defkey org-mode-map "\C-c+"    'org-table-sum)
-(org-defkey org-mode-map "\C-c="    'org-table-eval-formula)
-(org-defkey org-mode-map "\C-c'"    'org-edit-special)
-(org-defkey org-mode-map "\C-c`"    'org-table-edit-field)
-(org-defkey org-mode-map "\C-c\"a"  'orgtbl-ascii-plot)
-(org-defkey org-mode-map "\C-c\"g"  'org-plot/gnuplot)
-(org-defkey org-mode-map "\C-c|"    'org-table-create-or-convert-from-region)
-(org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
-(org-defkey org-mode-map "\C-c~"    'org-table-create-with-table.el)
-(org-defkey org-mode-map "\C-c\C-a" 'org-attach)
-(org-defkey org-mode-map "\C-c}"    'org-table-toggle-coordinate-overlays)
-(org-defkey org-mode-map "\C-c{"    'org-table-toggle-formula-debugger)
-(org-defkey org-mode-map "\C-c\C-e" 'org-export-dispatch)
-(org-defkey org-mode-map "\C-c:"    'org-toggle-fixed-width)
-(org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
-(org-defkey org-mode-map "\C-c\C-xf"    'org-footnote-action)
-(org-defkey org-mode-map "\C-c\C-x\C-mg"    'org-mobile-pull)
-(org-defkey org-mode-map "\C-c\C-x\C-mp"    'org-mobile-push)
-(org-defkey org-mode-map "\C-c@" 'org-mark-subtree)
-(org-defkey org-mode-map "\M-h" 'org-mark-element)
-(org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
-;;(org-defkey org-mode-map [?\C-c (control ?-)] 
'org-list-make-list-from-subtree)
-
-(org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
-(org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
-(org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
-
-(org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
-(org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
-(org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-in-last)
-(org-defkey org-mode-map "\C-c\C-x\C-z" 'org-resolve-clocks)
-(org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
-(org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
-(org-defkey org-mode-map "\C-c\C-x\C-q" 'org-clock-cancel)
-(org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
-(org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
-(org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
-(org-defkey org-mode-map "\C-c\C-x\C-l" 'org-toggle-latex-fragment)
-(org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
-(org-defkey org-mode-map "\C-c\C-x\C-\M-v" 'org-redisplay-inline-images)
-(org-defkey org-mode-map "\C-c\C-x\\"   'org-toggle-pretty-entities)
-(org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
-(org-defkey org-mode-map "\C-c\C-xp"    'org-set-property)
-(org-defkey org-mode-map "\C-c\C-xP"    'org-set-property-and-value)
-(org-defkey org-mode-map "\C-c\C-xe"    'org-set-effort)
-(org-defkey org-mode-map "\C-c\C-xE"    'org-inc-effort)
-(org-defkey org-mode-map "\C-c\C-xo"    'org-toggle-ordered-property)
-(org-defkey org-mode-map "\C-c\C-xi"    'org-columns-insert-dblock)
-(org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
-
-(org-defkey org-mode-map "\C-c\C-x."    'org-timer)
-(org-defkey org-mode-map "\C-c\C-x-"    'org-timer-item)
-(org-defkey org-mode-map "\C-c\C-x0"    'org-timer-start)
-(org-defkey org-mode-map "\C-c\C-x_"    'org-timer-stop)
-(org-defkey org-mode-map "\C-c\C-x,"    'org-timer-pause-or-continue)
-
-(define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
-
-(define-key org-mode-map "\C-c\C-x!" 'org-reload)
-
-(define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
-(define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
-
-(define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
-
-
-(defconst org-speed-commands-default
-  '(
-    ("Outline Navigation")
-    ("n" . (org-speed-move-safe 'org-next-visible-heading))
-    ("p" . (org-speed-move-safe 'org-previous-visible-heading))
-    ("f" . (org-speed-move-safe 'org-forward-heading-same-level))
-    ("b" . (org-speed-move-safe 'org-backward-heading-same-level))
-    ("F" . org-next-block)
-    ("B" . org-previous-block)
-    ("u" . (org-speed-move-safe 'outline-up-heading))
-    ("j" . org-goto)
-    ("g" . (org-refile t))
-    ("Outline Visibility")
-    ("c" . org-cycle)
-    ("C" . org-shifttab)
-    (" " . org-display-outline-path)
-    ("s" . org-narrow-to-subtree)
-    ("=" . org-columns)
-    ("Outline Structure Editing")
-    ("U" . org-metaup)
-    ("D" . org-metadown)
-    ("r" . org-metaright)
-    ("l" . org-metaleft)
-    ("R" . org-shiftmetaright)
-    ("L" . org-shiftmetaleft)
-    ("i" . (progn (forward-char 1) (call-interactively
-                                   'org-insert-heading-respect-content)))
-    ("^" . org-sort)
-    ("w" . org-refile)
-    ("a" . org-archive-subtree-default-with-confirmation)
-    ("@" . org-mark-subtree)
-    ("#" . org-toggle-comment)
-    ("Clock Commands")
-    ("I" . org-clock-in)
-    ("O" . org-clock-out)
-    ("Meta Data Editing")
-    ("t" . org-todo)
-    ("," . (org-priority))
-    ("0" . (org-priority ?\ ))
-    ("1" . (org-priority ?A))
-    ("2" . (org-priority ?B))
-    ("3" . (org-priority ?C))
-    (":" . org-set-tags-command)
-    ("e" . org-set-effort)
-    ("E" . org-inc-effort)
-    ("W" . (lambda(m) (interactive "sMinutes before warning: ")
-            (org-entry-put (point) "APPT_WARNTIME" m)))
-    ("Agenda Views etc")
-    ("v" . org-agenda)
-    ("/" . org-sparse-tree)
-    ("Misc")
-    ("o" . org-open-at-point)
-    ("?" . org-speed-command-help)
-    ("<" . (org-agenda-set-restriction-lock 'subtree))
-    (">" . (org-agenda-remove-restriction-lock))
-    )
-  "The default speed commands.")
-
-(defun org-print-speed-command (e)
-  (if (> (length (car e)) 1)
-      (progn
-       (princ "\n")
-       (princ (car e))
-       (princ "\n")
-       (princ (make-string (length (car e)) ?-))
-       (princ "\n"))
-    (princ (car e))
-    (princ "   ")
-    (if (symbolp (cdr e))
-       (princ (symbol-name (cdr e)))
-      (prin1 (cdr e)))
-    (princ "\n")))
-
-(defun org-speed-command-help ()
-  "Show the available speed commands."
-  (interactive)
-  (if (not org-use-speed-commands)
-      (user-error "Speed commands are not activated, customize 
`org-use-speed-commands'")
-    (with-output-to-temp-buffer "*Help*"
-      (princ "User-defined Speed commands\n===========================\n")
-      (mapc #'org-print-speed-command org-speed-commands-user)
-      (princ "\n")
-      (princ "Built-in Speed commands\n=======================\n")
-      (mapc #'org-print-speed-command org-speed-commands-default))
-    (with-current-buffer "*Help*"
-      (setq truncate-lines t))))
-
-(defun org-speed-move-safe (cmd)
-  "Execute CMD, but make sure that the cursor always ends up in a headline.
-If not, return to the original position and throw an error."
-  (interactive)
-  (let ((pos (point)))
-    (call-interactively cmd)
-    (unless (and (bolp) (org-at-heading-p))
-      (goto-char pos)
-      (error "Boundary reached while executing %s" cmd))))
-
 (defvar org-self-insert-command-undo-counter 0)
-
-(defvar org-table-auto-blank-field) ; defined in org-table.el
 (defvar org-speed-command nil)
 
-(defun org-speed-command-activate (keys)
-  "Hook for activating single-letter speed commands.
-`org-speed-commands-default' specifies a minimal command set.
-Use `org-speed-commands-user' for further customization."
-  (when (or (and (bolp) (looking-at org-outline-regexp))
-           (and (functionp org-use-speed-commands)
-                (funcall org-use-speed-commands)))
-    (cdr (assoc keys (append org-speed-commands-user
-                            org-speed-commands-default)))))
-
-(defun org-babel-speed-command-activate (keys)
-  "Hook for activating single-letter code block commands."
-  (when (and (bolp) (looking-at org-babel-src-block-regexp))
-    (cdr (assoc keys org-babel-key-bindings))))
-
-(defcustom org-speed-command-hook
-  '(org-speed-command-activate org-babel-speed-command-activate)
-  "Hook for activating speed commands at strategic locations.
-Hook functions are called in sequence until a valid handler is
-found.
-
-Each hook takes a single argument, a user-pressed command key
-which is also a `self-insert-command' from the global map.
-
-Within the hook, examine the cursor position and the command key
-and return nil or a valid handler as appropriate.  Handler could
-be one of an interactive command, a function, or a form.
-
-Set `org-use-speed-commands' to non-nil value to enable this
-hook.  The default setting is `org-speed-command-activate'."
-  :group 'org-structure
-  :version "24.1"
-  :type 'hook)
-
 (defun org-self-insert-command (N)
   "Like `self-insert-command', use overwrite-mode for whitespace in tables.
 If the cursor is in a table looking at whitespace, the whitespace is
@@ -19888,12 +16821,13 @@ overwritten, and the table is not marked as requiring 
realignment."
      (t (let (org-use-speed-commands)
          (call-interactively 'org-self-insert-command)))))
    ((and
-     (org-at-table-p)
-     (eq N 1)
+     (= N 1)
      (not (org-region-active-p))
+     (org-at-table-p)
      (progn
        ;; Check if we blank the field, and if that triggers align.
-       (and (featurep 'org-table) org-table-auto-blank-field
+       (and (featurep 'org-table)
+           org-table-auto-blank-field
            (memq last-command
                  '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c))
            (if (or (eq (char-after) ?\s) (looking-at "[^|\n]*  |"))
@@ -19904,10 +16838,16 @@ overwritten, and the table is not marked as requiring 
realignment."
              ;; width.
              (org-table-blank-field)))
        t)
-     (looking-at "[^|\n]* \\( \\)|"))
+     (looking-at "[^|\n]*  |"))
     ;; There is room for insertion without re-aligning the table.
-    (delete-region (match-beginning 1) (match-end 1))
-    (self-insert-command N))
+    (self-insert-command N)
+    (org-table-with-shrunk-field
+     (save-excursion
+       (skip-chars-forward "^|")
+       ;; Do not delete last space, which is
+       ;; `org-table-separator-space', but the regular space before
+       ;; it.
+       (delete-region (- (point) 2) (1- (point))))))
    (t
     (setq org-table-may-need-update t)
     (self-insert-command N)
@@ -19992,12 +16932,11 @@ The detailed reaction depends on the user option 
`org-catch-invisible-edits'."
 
 (defun org-fix-tags-on-the-fly ()
   "Align tags in headline at point.
-Unlike to `org-set-tags', it ignores region and sorting."
-  (when (and (eq (char-after (line-beginning-position)) ?*) ;short-circuit
-            (org-at-heading-p))
-    (let ((org-ignore-region t)
-         (org-tags-sort-function nil))
-      (org-set-tags nil t))))
+Unlike `org-align-tags', this function does nothing if point is
+either not currently on a tagged headline or on a tag."
+  (when (and (org-match-line org-tag-line-re)
+            (< (point) (match-beginning 1)))
+    (org-align-tags)))
 
 (defun org-delete-backward-char (N)
   "Like `delete-backward-char', insert whitespace at field end in tables.
@@ -20008,22 +16947,14 @@ because, in this case the deletion might narrow the 
column."
   (interactive "p")
   (save-match-data
     (org-check-before-invisible-edit 'delete-backward)
-    (if (and (org-at-table-p)
-            (eq N 1)
+    (if (and (= N 1)
+            (not overwrite-mode)
             (not (org-region-active-p))
-            (string-match "|" (buffer-substring (point-at-bol) (point)))
-            (looking-at ".*?|"))
-       (let ((pos (point))
-             (noalign (looking-at "[^|\n\r]*  |"))
-             (c org-table-may-need-update))
-         (backward-delete-char N)
-         (unless overwrite-mode
-           (skip-chars-forward "^|")
-           (insert " ")
-           (goto-char (1- pos)))
-         ;; noalign: if there were two spaces at the end, this field
-         ;; does not determine the width of the column.
-         (when noalign (setq org-table-may-need-update c)))
+            (not (eq (char-before) ?|))
+            (save-excursion (skip-chars-backward " \t") (not (bolp)))
+            (looking-at-p ".*?|")
+            (org-at-table-p))
+       (progn (forward-char -1) (org-delete-char 1))
       (backward-delete-char N)
       (org-fix-tags-on-the-fly))))
 
@@ -20036,23 +16967,28 @@ because, in this case the deletion might narrow the 
column."
   (interactive "p")
   (save-match-data
     (org-check-before-invisible-edit 'delete)
-    (if (and (org-at-table-p)
-            (not (bolp))
-            (not (= (char-after) ?|))
-            (eq N 1))
-       (if (looking-at ".*?|")
-           (let ((pos (point))
-                 (noalign (looking-at "[^|\n\r]*  |"))
-                 (c org-table-may-need-update))
-             (replace-match
-              (concat (substring (match-string 0) 1 -1) " |") nil t)
-             (goto-char pos)
-             ;; noalign: if there were two spaces at the end, this field
-             ;; does not determine the width of the column.
-             (when noalign (setq org-table-may-need-update c)))
-         (delete-char N))
+    (cond
+     ((or (/= N 1)
+         (eq (char-after) ?|)
+         (save-excursion (skip-chars-backward " \t") (bolp))
+         (not (org-at-table-p)))
       (delete-char N)
-      (org-fix-tags-on-the-fly))))
+      (org-fix-tags-on-the-fly))
+     ((looking-at ".\\(.*?\\)|")
+      (let* ((update? org-table-may-need-update)
+            (noalign (looking-at-p ".*?  |")))
+       (delete-char 1)
+       (org-table-with-shrunk-field
+        (save-excursion
+          ;; Last space is `org-table-separator-space', so insert
+          ;; a regular one before it instead.
+          (goto-char (- (match-end 0) 2))
+          (insert " ")))
+       ;; If there were two spaces at the end, this field does not
+       ;; determine the width of the column.
+       (when noalign (setq org-table-may-need-update update?))))
+     (t
+      (delete-char N)))))
 
 ;; Make `delete-selection-mode' work with Org mode and Orgtbl mode
 (put 'org-self-insert-command 'delete-selection
@@ -20085,7 +17021,6 @@ word constituents."
   (interactive)
   (with-syntax-table org-mode-transpose-word-syntax-table
     (call-interactively 'transpose-words)))
-(org-remap org-mode-map 'transpose-words 'org-transpose-words)
 
 (defvar org-ctrl-c-ctrl-c-hook nil
   "Hook for functions attaching themselves to `C-c C-c'.
@@ -20403,12 +17338,20 @@ for more information."
   (cond
    ((run-hook-with-args-until-success 'org-metaup-hook))
    ((org-region-active-p)
-    (let* ((a (min (region-beginning) (region-end)))
-          (b (1- (max (region-beginning) (region-end))))
-          (c (save-excursion (goto-char a)
-                             (move-beginning-of-line 0)))
-          (d (save-excursion (goto-char a)
-                             (move-end-of-line 0) (point))))
+    (let* ((a (save-excursion
+               (goto-char (min (region-beginning) (region-end)))
+               (line-beginning-position)))
+          (b (save-excursion
+               (goto-char (max (region-beginning) (region-end)))
+               (if (bolp) (1- (point)) (line-end-position))))
+          (c (save-excursion
+               (goto-char a)
+               (move-beginning-of-line 0)
+               (point)))
+          (d (save-excursion
+               (goto-char a)
+               (move-end-of-line 0)
+               (point))))
       (transpose-regions a b c d)
       (goto-char c)))
    ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
@@ -20425,12 +17368,20 @@ commands for more information."
   (cond
    ((run-hook-with-args-until-success 'org-metadown-hook))
    ((org-region-active-p)
-    (let* ((a (min (region-beginning) (region-end)))
-          (b (max (region-beginning) (region-end)))
-          (c (save-excursion (goto-char b)
-                             (move-beginning-of-line 1)))
-          (d (save-excursion (goto-char b)
-                             (move-end-of-line 1) (1+ (point)))))
+    (let* ((a (save-excursion
+               (goto-char (min (region-beginning) (region-end)))
+               (line-beginning-position)))
+          (b (save-excursion
+               (goto-char (max (region-beginning) (region-end)))
+               (if (bolp) (1- (point)) (line-end-position))))
+          (c (save-excursion
+               (goto-char b)
+               (move-beginning-of-line (if (bolp) 1 2))
+               (point)))
+          (d (save-excursion
+               (goto-char b)
+               (move-end-of-line (if (bolp) 1 2))
+               (point))))
       (transpose-regions a b c d)
       (goto-char d)))
    ((org-at-table-p) (call-interactively 'org-table-move-row))
@@ -20439,9 +17390,10 @@ commands for more information."
    (t (org-drag-element-forward))))
 
 (defun org-shiftup (&optional arg)
-  "Increase item in timestamp or increase priority of current headline.
-Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
-depending on context.  See the individual commands for more information."
+  "Act on current element according to context.
+Call `org-timestamp-up' or `org-priority-up', or
+`org-previous-item', or `org-table-move-cell-up'.  See the
+individual commands for more information."
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftup-hook))
@@ -20457,15 +17409,17 @@ depending on context.  See the individual commands 
for more information."
    ((and (not org-support-shift-select) (org-at-item-p))
     (call-interactively 'org-previous-item))
    ((org-clocktable-try-shift 'up arg))
+   ((org-at-table-p) (org-table-move-cell-up))
    ((run-hook-with-args-until-success 'org-shiftup-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'previous-line))
    (t (org-shiftselect-error))))
 
 (defun org-shiftdown (&optional arg)
-  "Decrease item in timestamp or decrease priority of current headline.
-Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
-depending on context.  See the individual commands for more information."
+  "Act on current element according to context.
+Call `org-timestamp-down' or `org-priority-down', or
+`org-next-item', or `org-table-move-cell-down'.  See the
+individual commands for more information."
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftdown-hook))
@@ -20481,20 +17435,22 @@ depending on context.  See the individual commands 
for more information."
    ((and (not org-support-shift-select) (org-at-item-p))
     (call-interactively 'org-next-item))
    ((org-clocktable-try-shift 'down arg))
+   ((org-at-table-p) (org-table-move-cell-down))
    ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'next-line))
    (t (org-shiftselect-error))))
 
 (defun org-shiftright (&optional arg)
-  "Cycle the thing at point or in the current line, depending on context.
-Depending on context, this does one of the following:
+  "Act on the current element according to context.
+This does one of the following:
 
 - switch a timestamp at point one day into the future
 - on a headline, switch to the next TODO keyword
 - on an item, switch entire list to the next bullet type
 - on a property line, switch to the next allowed value
-- on a clocktable definition line, move time block into the future"
+- on a clocktable definition line, move time block into the future
+- in a table, move a single cell right"
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftright-hook))
@@ -20517,20 +17473,22 @@ Depending on context, this does one of the following:
         (org-at-property-p))
     (call-interactively 'org-property-next-allowed-value))
    ((org-clocktable-try-shift 'right arg))
+   ((org-at-table-p) (org-table-move-cell-right))
    ((run-hook-with-args-until-success 'org-shiftright-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'forward-char))
    (t (org-shiftselect-error))))
 
 (defun org-shiftleft (&optional arg)
-  "Cycle the thing at point or in the current line, depending on context.
-Depending on context, this does one of the following:
+  "Act on current element according to context.
+This does one of the following:
 
 - switch a timestamp at point one day into the past
 - on a headline, switch to the previous TODO keyword.
 - on an item, switch entire list to the previous bullet type
 - on a property line, switch to the previous allowed value
-- on a clocktable definition line, move time block into the past"
+- on a clocktable definition line, move time block into the past
+- in a table, move a single cell left"
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftleft-hook))
@@ -20553,6 +17511,7 @@ Depending on context, this does one of the following:
         (org-at-property-p))
     (call-interactively 'org-property-previous-allowed-value))
    ((org-clocktable-try-shift 'left arg))
+   ((org-at-table-p) (org-table-move-cell-left))
    ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'backward-char))
@@ -20656,7 +17615,9 @@ this numeric value."
       (let ((next (next-single-char-property-change beg 'invisible nil end)))
        (setq result (concat result (buffer-substring beg next)))
        (setq beg next)))
-    (kill-new result)))
+    (setq deactivate-mark t)
+    (kill-new result)
+    (message "Visible strings have been copied to the kill ring.")))
 
 (defun org-copy-special ()
   "Copy region in table or copy current subtree.
@@ -20691,7 +17652,10 @@ When in a fixed-width region, call 
`org-edit-fixed-width-region'.
 When in an export block, call `org-edit-export-block'.
 When in a LaTeX environment, call `org-edit-latex-environment'.
 When at an #+INCLUDE keyword, visit the included file.
-When at a footnote reference, call `org-edit-footnote-reference'
+When at a footnote reference, call `org-edit-footnote-reference'.
+When at a planning line call, `org-deadline' and/or `org-schedule'.
+When at an active timestamp, call `org-time-stamp'.
+When at an inactive timestamp, call `org-time-stamp-inactive'.
 On a link, call `ffap' to visit the link at point.
 Otherwise, return a user error."
   (interactive "P")
@@ -20705,28 +17669,25 @@ Otherwise, return a user error."
                (params (nth 2 info))
                (session (cdr (assq :session params))))
           (if (not session) (org-edit-src-code)
-            ;; At a src-block with a session and function called with
-            ;; an ARG: switch to the buffer related to the inferior
-            ;; process.
+            ;; At a source block with a session and function called
+            ;; with an ARG: switch to the buffer related to the
+            ;; inferior process.
             (switch-to-buffer
              (funcall (intern (concat "org-babel-prep-session:" lang))
                       session params))))))
       (`keyword
-       (if (member (org-element-property :key element) '("INCLUDE" 
"SETUPFILE"))
-           (org-open-link-from-string
-           (format "[[%s]]"
-                   (expand-file-name
-                    (let ((value (org-element-property :value element)))
-                      (cond ((org-file-url-p value)
-                             (user-error "The file is specified as a URL, 
cannot be edited"))
-                            ((not (org-string-nw-p value))
-                             (user-error "No file to edit"))
-                            ((string-match "\\`\"\\(.*?\\)\"" value)
-                             (match-string 1 value))
-                            ((string-match "\\`[^ \t\"]\\S-*" value)
-                             (match-string 0 value))
-                            (t (user-error "No valid file specified")))))))
-         (user-error "No special environment to edit here")))
+       (unless (member (org-element-property :key element)
+                      '("INCLUDE" "SETUPFILE"))
+        (user-error "No special environment to edit here"))
+       (let ((value (org-element-property :value element)))
+        (unless (org-string-nw-p value) (user-error "No file to edit"))
+        (let ((file (and (string-match "\\`\"\\(.*?\\)\"\\|\\S-+" value)
+                         (or (match-string 1 value)
+                             (match-string 0 value)))))
+          (when (org-file-url-p file)
+            (user-error "Files located with a URL cannot be edited"))
+          (org-link-open-from-string
+           (format "[[%s]]" (expand-file-name file))))))
       (`table
        (if (eq (org-element-property :type element) 'table.el)
            (org-edit-table.el)
@@ -20737,6 +17698,13 @@ Otherwise, return a user error."
       (`export-block (org-edit-export-block))
       (`fixed-width (org-edit-fixed-width-region))
       (`latex-environment (org-edit-latex-environment))
+      (`planning
+       (let ((proplist (cadr element)))
+         (mapc #'call-interactively
+               (remq nil
+                     (list
+                      (when (plist-get proplist :deadline) #'org-deadline)
+                      (when (plist-get proplist :scheduled) 
#'org-schedule))))))
       (_
        ;; No notable element at point.  Though, we may be at a link or
        ;; a footnote reference, which are objects.  Thus, scan deeper.
@@ -20744,10 +17712,12 @@ Otherwise, return a user error."
         (pcase (org-element-type context)
           (`footnote-reference (org-edit-footnote-reference))
           (`inline-src-block (org-edit-inline-src-code))
+          (`timestamp (if (eq 'inactive (org-element-property :type context))
+                          (call-interactively #'org-time-stamp-inactive)
+                        (call-interactively #'org-time-stamp)))
           (`link (call-interactively #'ffap))
           (_ (user-error "No special environment to edit here"))))))))
 
-(defvar org-table-coordinate-overlays) ; defined in org-table.el
 (defun org-ctrl-c-ctrl-c (&optional arg)
   "Set tags in headline, or update according to changed information at point.
 
@@ -20828,7 +17798,7 @@ This command does many different things, depending on 
context:
       ;; Act according to type of element or object at point.
       ;;
       ;; Do nothing on a blank line, except if it is contained in
-      ;; a src block.  Hence, we first check if point is in such
+      ;; a source block.  Hence, we first check if point is in such
       ;; a block and then if it is at a blank line.
       (pcase type
        ((or `inline-src-block `src-block)
@@ -20855,7 +17825,7 @@ This command does many different things, depending on 
context:
        (`footnote-reference (call-interactively #'org-footnote-action))
        ((or `headline `inlinetask)
         (save-excursion (goto-char (org-element-property :begin context))
-                        (call-interactively #'org-set-tags)))
+                        (call-interactively #'org-set-tags-command)))
        (`item
         ;; At an item: `C-u C-u' sets checkbox to "[-]"
         ;; unconditionally, whereas `C-u' will toggle its presence.
@@ -20909,7 +17879,6 @@ This command does many different things, depending on 
context:
         ;; first item in the list.  Without an argument, repair the
         ;; list.
         (let* ((begin (org-element-property :contents-begin context))
-               (beginm (move-marker (make-marker) begin))
                (struct (org-element-property :structure context))
                (old-struct (copy-tree struct))
                (first-box (save-excursion
@@ -20931,10 +17900,12 @@ This command does many different things, depending on 
context:
             ;; item of the list and no argument is provided, simply
             ;; toggle checkbox of that item, if any.
             (org-list-set-checkbox begin struct new-box)))
-          (org-list-write-struct
-           struct (org-list-parents-alist struct) old-struct)
-          (org-update-checkbox-count-maybe)
-          (save-excursion (goto-char beginm) (org-list-send-list 'maybe))))
+          (when (equal
+                 (org-list-write-struct
+                  struct (org-list-parents-alist struct) old-struct)
+                 old-struct)
+            (message "Cannot update this checkbox"))
+          (org-update-checkbox-count-maybe)))
        ((or `property-drawer `node-property)
         (call-interactively #'org-property-action))
        (`radio-target
@@ -20969,7 +17940,7 @@ Use `\\[org-edit-special]' to edit table.el tables"))
        ((and `nil (guard (org-at-heading-p)))
         ;; When point is on an unsupported object type, we can miss
         ;; the fact that it also is at a heading.  Handle it here.
-        (call-interactively #'org-set-tags))
+        (call-interactively #'org-set-tags-command))
        ((guard
          (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)))
        (_
@@ -20987,18 +17958,35 @@ Use `\\[org-edit-special]' to edit table.el tables"))
     (org-reset-file-cache))
   (message "%s restarted" major-mode))
 
+(defun org-flag-above-first-heading (&optional arg)
+  "Hide from bob up to the first heading.
+Move point to the beginning of first heading or end of buffer."
+  (goto-char (point-min))
+  (unless (org-at-heading-p)
+    (outline-next-heading))
+  (unless (bobp)
+    (org-flag-region 1 (1- (point)) (not arg) 'outline)))
+
+(defun org-show-branches-buffer ()
+  "Show all branches in the buffer."
+  (org-flag-above-first-heading)
+  (outline-hide-sublevels 1)
+  (unless (eobp)
+    (outline-show-branches)
+    (while (outline-get-next-sibling)
+      (outline-show-branches)))
+  (goto-char (point-min)))
+
 (defun org-kill-note-or-show-branches ()
-  "Abort storing current note, or call `outline-show-branches'."
+  "Abort storing current note, or show just branches."
   (interactive)
-  (if (not org-finish-function)
-      (save-excursion
-       (save-restriction
-         (org-narrow-to-subtree)
-         (org-flag-subtree t)
-         (call-interactively 'outline-show-branches)
-         (org-hide-archived-subtrees (point-min) (point-max))))
-    (let ((org-note-abort t))
-      (funcall org-finish-function))))
+  (if org-finish-function
+      (let ((org-note-abort t))
+        (funcall org-finish-function))
+    (if (org-before-first-heading-p)
+        (org-show-branches-buffer)
+      (outline-hide-subtree)
+      (outline-show-branches))))
 
 (defun org-delete-indentation (&optional arg)
   "Join current line to previous and fix whitespace at join.
@@ -21029,7 +18017,7 @@ With a non-nil optional argument, join it to the 
following one."
        ;; Adjust alignment of tags.
        (cond
         ((not tags-column))            ;no tags
-        (org-auto-align-tags (org-set-tags nil t))
+        (org-auto-align-tags (org-align-tags))
         (t (org--align-tags-here tags-column)))) ;preserve tags column
     (delete-indentation arg)))
 
@@ -21062,7 +18050,8 @@ object (e.g., within a comment).  In these case, you 
need to use
     (cond
      ;; In a table, call `org-table-next-row'.  However, before first
      ;; column or after last one, split the table.
-     ((or (and (eq (org-element-type context) 'table)
+     ((or (and (eq 'table (org-element-type context))
+              (not (eq 'table.el (org-element-property :type context)))
               (>= (point) (org-element-property :contents-begin context))
               (< (point) (org-element-property :contents-end context)))
          (org-element-lineage context '(table-row table-cell) t))
@@ -21075,15 +18064,21 @@ object (e.g., within a comment).  In these case, you 
need to use
      ;; `org-return-follows-link' allows it.  Tolerate fuzzy
      ;; locations, e.g., in a comment, as `org-open-at-point'.
      ((and org-return-follows-link
-          (or (org-in-regexp org-ts-regexp-both nil t)
+          (or (and (eq 'link (org-element-type context))
+                   ;; Ensure point is not on the white spaces after
+                   ;; the link.
+                   (let ((origin (point)))
+                     (org-with-point-at (org-element-property :end context)
+                       (skip-chars-backward " \t")
+                       (> (point) origin))))
+              (org-in-regexp org-ts-regexp-both nil t)
               (org-in-regexp org-tsr-regexp-both nil  t)
-              (org-in-regexp org-any-link-re nil t)))
+              (org-in-regexp org-link-any-re nil t)))
       (call-interactively #'org-open-at-point))
      ;; Insert newline in heading, but preserve tags.
      ((and (not (bolp))
-          (save-excursion (beginning-of-line)
-                          (let ((case-fold-search nil))
-                            (looking-at org-complex-heading-regexp))))
+          (let ((case-fold-search nil))
+            (org-match-line org-complex-heading-regexp)))
       ;; At headline.  Split line.  However, if point is on keyword,
       ;; priority cookie or tags, do not break any of them: add
       ;; a newline after the headline instead.
@@ -21096,7 +18091,7 @@ object (e.g., within a comment).  In these case, you 
need to use
        ;; Adjust tag alignment.
        (cond
         ((not (and tags-column string)))
-        (org-auto-align-tags (org-set-tags nil t))
+        (org-auto-align-tags (org-align-tags))
         (t (org--align-tags-here tags-column))) ;preserve tags column
        (end-of-line)
        (org-show-entry)
@@ -21125,6 +18120,21 @@ context.  See the individual commands for more 
information."
   (interactive)
   (org-return t))
 
+(defun org-ctrl-c-tab (&optional arg)
+  "Toggle columns width in a table, or show children.
+Call `org-table-toggle-column-width' if point is in a table.
+Otherwise, call `org-show-children'.  ARG is the level to hide."
+  (interactive "p")
+  (if (org-at-table-p)
+      (call-interactively #'org-table-toggle-column-width)
+    (if (org-before-first-heading-p)
+        (progn
+          (org-flag-above-first-heading)
+          (outline-hide-sublevels (or arg 1))
+          (goto-char (point-min)))
+      (outline-hide-subtree)
+      (org-show-children arg))))
+
 (defun org-ctrl-c-star ()
   "Compute table, or change heading status of lines.
 Calls `org-table-recalculate' or `org-toggle-heading',
@@ -21226,7 +18236,12 @@ number of stars to add."
                     (min (org-list-get-bottom-point struct) (1+ end))))
               (save-restriction
                 (narrow-to-region (point) list-end)
-                (insert (org-list-to-subtree (org-list-to-lisp t)) "\n")))
+                (insert (org-list-to-subtree
+                         (org-list-to-lisp t)
+                         (pcase (org-current-level)
+                           (`nil 1)
+                           (l (1+ (org-reduced-level l)))))
+                        "\n")))
             (setq toggled t))
           (forward-line)))
        ;; Case 3. Started at normal text: make every line an heading,
@@ -21235,10 +18250,10 @@ number of stars to add."
                   (make-string
                    (if (numberp nstars) nstars (or (org-current-level) 0)) ?*))
                  (add-stars
-                  (cond (nstars "")                ; stars from prefix only
-                        ((equal stars "") "*")     ; before first heading
+                  (cond (nstars "")    ; stars from prefix only
+                        ((equal stars "") "*") ; before first heading
                         (org-odd-levels-only "**") ; inside heading, odd
-                        (t "*")))                  ; inside heading, oddeven
+                        (t "*")))      ; inside heading, oddeven
                  (rpl (concat stars add-stars " "))
                  (lend (when (listp nstars) (save-excursion (end-of-line) 
(point)))))
             (while (< (point) (if (equal nstars '(4)) lend end))
@@ -21284,7 +18299,8 @@ an argument, unconditionally call `org-insert-heading'."
      ["Move Column Left" org-metaleft (org-at-table-p)]
      ["Move Column Right" org-metaright (org-at-table-p)]
      ["Delete Column" org-shiftmetaleft (org-at-table-p)]
-     ["Insert Column" org-shiftmetaright (org-at-table-p)])
+     ["Insert Column" org-shiftmetaright (org-at-table-p)]
+     ["Shrink Column" org-table-toggle-column-width (org-at-table-p)])
     ("Row"
      ["Move Row Up" org-metaup (org-at-table-p)]
      ["Move Row Down" org-metadown (org-at-table-p)]
@@ -21339,7 +18355,7 @@ an argument, unconditionally call `org-insert-heading'."
      ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
      ["Sparse Tree..." org-sparse-tree t]
      ["Reveal Context" org-reveal t]
-     ["Show All" outline-show-all t]
+     ["Show All" org-show-all t]
      "--"
      ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
     "--"
@@ -21513,7 +18529,8 @@ an argument, unconditionally call `org-insert-heading'."
     "--"
     ("Documentation"
      ["Show Version" org-version t]
-     ["Info Documentation" org-info t])
+     ["Info Documentation" org-info t]
+     ["Browse Org News" org-browse-news t])
     ("Customize"
      ["Browse Org Group" org-customize t]
      "--"
@@ -21524,8 +18541,7 @@ an argument, unconditionally call `org-insert-heading'."
     ("Refresh/Reload"
      ["Refresh setup current buffer" org-mode-restart t]
      ["Reload Org (after update)" org-reload t]
-     ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x !"])
-    ))
+     ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x 
!"])))
 
 (defun org-info (&optional node)
   "Read documentation for Org in the info system.
@@ -21533,6 +18549,11 @@ With optional NODE, go directly to that node."
   (interactive)
   (info (format "(org)%s" (or node ""))))
 
+(defun org-browse-news ()
+  "Browse the news for the latest major release."
+  (interactive)
+  (browse-url "https://orgmode.org/Changes.html";))
+
 ;;;###autoload
 (defun org-submit-bug-report ()
   "Submit a bug report on Org via mail.
@@ -21705,26 +18726,6 @@ With prefix arg UNCOMPILED, load the uncompiled 
versions."
 
 ;;; Generally useful functions
 
-(defun org-get-at-eol (property n)
-  "Get text property PROPERTY at the end of line less N characters."
-  (get-text-property (- (point-at-eol) n) property))
-
-(defun org-find-text-property-in-string (prop s)
-  "Return the first non-nil value of property PROP in string S."
-  (or (get-text-property 0 prop s)
-      (get-text-property (or (next-single-property-change 0 prop s) 0)
-                        prop s)))
-
-(defun org-display-warning (message)
-  "Display the given MESSAGE as a warning."
-  (display-warning 'org message :warning))
-
-(defun org-eval (form)
-  "Eval FORM and return result."
-  (condition-case error
-      (eval form)
-    (error (format "%%![Error: %s]" error))))
-
 (defun org-in-clocktable-p ()
   "Check if the cursor is in a clocktable."
   (let ((pos (point)) start)
@@ -21742,27 +18743,6 @@ With prefix arg UNCOMPILED, load the uncompiled 
versions."
         (>= (point) (match-beginning 3))
         (<= (point) (match-end 4)))))
 
-(defun org-overlay-display (ovl text &optional face evap)
-  "Make overlay OVL display TEXT with face FACE."
-  (overlay-put ovl 'display text)
-  (if face (overlay-put ovl 'face face))
-  (if evap (overlay-put ovl 'evaporate t)))
-
-(defun org-overlay-before-string (ovl text &optional face evap)
-  "Make overlay OVL display TEXT with face FACE."
-  (if face (org-add-props text nil 'face face))
-  (overlay-put ovl 'before-string text)
-  (if evap (overlay-put ovl 'evaporate t)))
-
-(defun org-find-overlays (prop &optional pos delete)
-  "Find all overlays specifying PROP at POS or point.
-If DELETE is non-nil, delete all those overlays."
-  (let (found)
-    (dolist (ov (overlays-at (or pos (point))) found)
-      (cond ((not (overlay-get ov prop)))
-           (delete (delete-overlay ov))
-           (t (push ov found))))))
-
 (defun org-goto-marker-or-bmk (marker &optional bookmark)
   "Go to MARKER, widen if necessary.  When marker is not live, try BOOKMARK."
   (if (and marker (marker-buffer marker)
@@ -21788,158 +18768,6 @@ If DELETE is non-nil, delete all those overlays."
   (interactive "p")
   (self-insert-command N))
 
-(defun org-shorten-string (s maxlength)
-  "Shorten string S so that it is no longer than MAXLENGTH characters.
-If the string is shorter or has length MAXLENGTH, just return the
-original string.  If it is longer, the functions finds a space in the
-string, breaks this string off at that locations and adds three dots
-as ellipsis.  Including the ellipsis, the string will not be longer
-than MAXLENGTH.  If finding a good breaking point in the string does
-not work, the string is just chopped off in the middle of a word
-if necessary."
-  (if (<= (length s) maxlength)
-      s
-    (let* ((n (max (- maxlength 4) 1))
-          (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ 
]\\|\\'\\)")))
-      (if (string-match re s)
-         (concat (match-string 1 s) "...")
-       (concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
-
-(defun org-get-indentation (&optional line)
-  "Get the indentation of the current line, interpreting tabs.
-When LINE is given, assume it represents a line and compute its indentation."
-  (if line
-      (when (string-match "^ *" (org-remove-tabs line))
-       (match-end 0))
-    (save-excursion
-      (beginning-of-line 1)
-      (skip-chars-forward " \t")
-      (current-column))))
-
-(defun org-get-string-indentation (s)
-  "What indentation has S due to SPACE and TAB at the beginning of the string?"
-  (let ((n -1) (i 0) (w tab-width) c)
-    (catch 'exit
-      (while (< (setq n (1+ n)) (length s))
-       (setq c (aref s n))
-       (cond ((= c ?\ ) (setq i (1+ i)))
-             ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
-             (t (throw 'exit t)))))
-    i))
-
-(defun org-remove-tabs (s &optional width)
-  "Replace tabulators in S with spaces.
-Assumes that s is a single line, starting in column 0."
-  (setq width (or width tab-width))
-  (while (string-match "\t" s)
-    (setq s (replace-match
-            (make-string
-             (- (* width (/ (+ (match-beginning 0) width) width))
-                (match-beginning 0)) ?\ )
-            t t s)))
-  s)
-
-(defun org-fix-indentation (line ind)
-  "Fix indentation in LINE.
-IND is a cons cell with target and minimum indentation.
-If the current indentation in LINE is smaller than the minimum,
-leave it alone.  If it is larger than ind, set it to the target."
-  (let* ((l (org-remove-tabs line))
-        (i (org-get-indentation l))
-        (i1 (car ind)) (i2 (cdr ind)))
-    (when (>= i i2) (setq l (substring line i2)))
-    (if (> i1 0)
-       (concat (make-string i1 ?\ ) l)
-      l)))
-
-(defun org-remove-indentation (code &optional n)
-  "Remove maximum common indentation in string CODE and return it.
-N may optionally be the number of columns to remove.  Return CODE
-as-is if removal failed."
-  (with-temp-buffer
-    (insert code)
-    (if (org-do-remove-indentation n) (buffer-string) code)))
-
-(defun org-do-remove-indentation (&optional n)
-  "Remove the maximum common indentation from the buffer.
-When optional argument N is a positive integer, remove exactly
-that much characters from indentation, if possible.  Return nil
-if it fails."
-  (catch :exit
-    (goto-char (point-min))
-    ;; Find maximum common indentation, if not specified.
-    (let ((n (or n
-                (let ((min-ind (point-max)))
-                  (save-excursion
-                    (while (re-search-forward "^[ \t]*\\S-" nil t)
-                      (let ((ind (1- (current-column))))
-                        (if (zerop ind) (throw :exit nil)
-                          (setq min-ind (min min-ind ind))))))
-                  min-ind))))
-      (if (zerop n) (throw :exit nil)
-       ;; Remove exactly N indentation, but give up if not possible.
-       (while (not (eobp))
-         (let ((ind (progn (skip-chars-forward " \t") (current-column))))
-           (cond ((eolp) (delete-region (line-beginning-position) (point)))
-                 ((< ind n) (throw :exit nil))
-                 (t (indent-line-to (- ind n))))
-           (forward-line)))
-       ;; Signal success.
-       t))))
-
-(defun org-fill-template (template alist)
-  "Find each %key of ALIST in TEMPLATE and replace it."
-  (let ((case-fold-search nil))
-    (dolist (entry (sort (copy-sequence alist)
-                         (lambda (a b) (< (length (car a)) (length (car b))))))
-      (setq template
-           (replace-regexp-in-string
-            (concat "%" (regexp-quote (car entry)))
-            (or (cdr entry) "") template t t)))
-    template))
-
-(defun org-base-buffer (buffer)
-  "Return the base buffer of BUFFER, if it has one.  Else return the buffer."
-  (if (not buffer)
-      buffer
-    (or (buffer-base-buffer buffer)
-       buffer)))
-
-(defun org-wrap (string &optional width lines)
-  "Wrap string to either a number of lines, or a width in characters.
-If WIDTH is non-nil, the string is wrapped to that width, however many lines
-that costs.  If there is a word longer than WIDTH, the text is actually
-wrapped to the length of that word.
-IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
-many lines, whatever width that takes.
-The return value is a list of lines, without newlines at the end."
-  (let* ((words (split-string string))
-        (maxword (apply 'max (mapcar 'org-string-width words)))
-        w ll)
-    (cond (width
-          (org-do-wrap words (max maxword width)))
-         (lines
-          (setq w maxword)
-          (setq ll (org-do-wrap words maxword))
-          (if (<= (length ll) lines)
-              ll
-            (setq ll words)
-            (while (> (length ll) lines)
-              (setq w (1+ w))
-              (setq ll (org-do-wrap words w)))
-            ll))
-         (t (error "Cannot wrap this")))))
-
-(defun org-do-wrap (words width)
-  "Create lines of maximum width WIDTH (in characters) from word list WORDS."
-  (let (lines line)
-    (while words
-      (setq line (pop words))
-      (while (and words (< (+ (length line) (length (car words))) width))
-       (setq line (concat line " " (pop words))))
-      (setq lines (push line lines)))
-    (nreverse lines)))
-
 (defun org-quote-vert (s)
   "Replace \"|\" with \"\\vert\"."
   (while (string-match "|" s)
@@ -21952,8 +18780,8 @@ The return value is a list of lines, without newlines 
at the end."
 
 (defun org-in-src-block-p (&optional inside)
   "Whether point is in a code source block.
-When INSIDE is non-nil, don't consider we are within a src block
-when point is at #+BEGIN_SRC or #+END_SRC."
+When INSIDE is non-nil, don't consider we are within a source
+block when point is at #+BEGIN_SRC or #+END_SRC."
   (let ((case-fold-search t))
     (or (and (eq (get-char-property (point) 'src-block) t))
        (and (not inside)
@@ -21984,8 +18812,6 @@ contexts are:
 :src-block        in a source block
 :link             on a hyperlink
 :keyword          on a keyword: SCHEDULED, DEADLINE, CLOSE, COMMENT.
-:target           on a <<target>>
-:radio-target     on a <<<radio-target>>>
 :latex-fragment   on a LaTeX fragment
 :latex-preview    on a LaTeX fragment with overlaid preview image
 
@@ -22059,12 +18885,6 @@ and :keyword."
       (push (list :keyword
                  (previous-single-property-change p 'face)
                  (next-single-property-change p 'face)) clist))
-     ((org-at-target-p)
-      (push (org-point-in-group p 0 :target) clist)
-      (goto-char (1- (match-beginning 0)))
-      (when (looking-at org-radio-target-regexp)
-       (push (org-point-in-group p 0 :radio-target) clist))
-      (goto-char p))
      ((setq o (cl-some
               (lambda (o)
                 (and (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay)
@@ -22081,28 +18901,6 @@ and :keyword."
     (setq clist (nreverse (delq nil clist)))
     clist))
 
-(defun org-in-regexp (regexp &optional nlines visually)
-  "Check if point is inside a match of REGEXP.
-
-Normally only the current line is checked, but you can include
-NLINES extra lines around point into the search.  If VISUALLY is
-set, require that the cursor is not after the match but really
-on, so that the block visually is on the match.
-
-Return nil or a cons cell (BEG . END) where BEG and END are,
-respectively, the positions at the beginning and the end of the
-match."
-  (catch :exit
-    (let ((pos (point))
-          (eol (line-end-position (if nlines (1+ nlines) 1))))
-      (save-excursion
-       (beginning-of-line (- 1 (or nlines 0)))
-       (while (and (re-search-forward regexp eol t)
-                   (<= (match-beginning 0) pos))
-         (let ((end (match-end 0)))
-           (when (or (> end pos) (and (= end pos) (not visually)))
-             (throw :exit (cons (match-beginning 0) (match-end 0))))))))))
-
 (defun org-between-regexps-p (start-re end-re &optional lim-up lim-down)
   "Non-nil when point is between matches of START-RE and END-RE.
 
@@ -22194,40 +18992,6 @@ for the search purpose."
                (error "Unable to create a link to here"))))
     (org-occur-in-agenda-files (regexp-quote link))))
 
-(defun org-reverse-string (string)
-  "Return the reverse of STRING."
-  (apply 'string (reverse (string-to-list string))))
-
-;; defsubst org-uniquify must be defined before first use
-
-(defun org-uniquify-alist (alist)
-  "Merge elements of ALIST with the same key.
-
-For example, in this alist:
-
-\(org-uniquify-alist \\='((a 1) (b 2) (a 3)))
-  => \\='((a 1 3) (b 2))
-
-merge (a 1) and (a 3) into (a 1 3).
-
-The function returns the new ALIST."
-  (let (rtn)
-    (dolist (e alist rtn)
-      (let (n)
-       (if (not (assoc (car e) rtn))
-           (push e rtn)
-         (setq n (cons (car e) (append (cdr (assoc (car e) rtn)) (cdr e))))
-         (setq rtn (assq-delete-all (car e) rtn))
-         (push n rtn))))))
-
-(defun org-delete-all (elts list)
-  "Remove all elements in ELTS from LIST.
-Comparison is done with `equal'.  It is a destructive operation
-that may remove elements by altering the list structure."
-  (while elts
-    (setq list (delete (pop elts) list)))
-  list)
-
 (defun org-back-over-empty-lines ()
   "Move backwards over whitespace, to the beginning of the first empty line.
 Returns the number of empty lines passed."
@@ -22240,78 +19004,6 @@ Returns the number of empty lines passed."
     (goto-char (min (point) pos))
     (count-lines (point) pos)))
 
-(defun org-skip-whitespace ()
-  (skip-chars-forward " \t\n\r"))
-
-(defun org-point-in-group (point group &optional context)
-  "Check if POINT is in match-group GROUP.
-If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
-match.  If the match group does not exist or point is not inside it,
-return nil."
-  (and (match-beginning group)
-       (>= point (match-beginning group))
-       (<= point (match-end group))
-       (if context
-          (list context (match-beginning group) (match-end group))
-        t)))
-
-(defun org-switch-to-buffer-other-window (&rest args)
-  "Switch to buffer in a second window on the current frame.
-In particular, do not allow pop-up frames.
-Returns the newly created buffer."
-  (org-no-popups
-   (apply 'switch-to-buffer-other-window args)))
-
-(defun org-combine-plists (&rest plists)
-  "Create a single property list from all plists in PLISTS.
-The process starts by copying the first list, and then setting properties
-from the other lists.  Settings in the last list are the most significant
-ones and overrule settings in the other lists."
-  (let ((rtn (copy-sequence (pop plists)))
-       p v ls)
-    (while plists
-      (setq ls (pop plists))
-      (while ls
-       (setq p (pop ls) v (pop ls))
-       (setq rtn (plist-put rtn p v))))
-    rtn))
-
-(defun org-replace-escapes (string table)
-  "Replace %-escapes in STRING with values in TABLE.
-TABLE is an association list with keys like \"%a\" and string values.
-The sequences in STRING may contain normal field width and padding information,
-for example \"%-5s\".  Replacements happen in the sequence given by TABLE,
-so values can contain further %-escapes if they are define later in TABLE."
-  (let ((tbl (copy-alist table))
-       (case-fold-search nil)
-        (pchg 0)
-        re rpl)
-    (dolist (e tbl)
-      (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
-      (when (and (cdr e) (string-match re (cdr e)))
-        (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
-              (safe "SREF"))
-          (add-text-properties 0 3 (list 'sref sref) safe)
-          (setcdr e (replace-match safe t t (cdr e)))))
-      (while (string-match re string)
-        (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
-                          (cdr e)))
-        (setq string (replace-match rpl t t string))))
-    (while (setq pchg (next-property-change pchg string))
-      (let ((sref (get-text-property pchg 'sref string)))
-       (when (and sref (string-match "SREF" string pchg))
-         (setq string (replace-match sref t t string)))))
-    string))
-
-(defun org-find-base-buffer-visiting (file)
-  "Like `find-buffer-visiting' but always return the base buffer and
-not an indirect buffer."
-  (let ((buf (or (get-file-buffer file)
-                (find-buffer-visiting file))))
-    (if buf
-       (or (buffer-base-buffer buf) buf)
-      nil)))
-
 ;;; TODO: Only called once, from ox-odt which should probably use
 ;;; org-export-inline-image-p or something.
 (defun org-file-image-p (file)
@@ -22324,7 +19016,9 @@ not an indirect buffer."
 This works in the calendar and in the agenda, anywhere else it just
 returns the current time.
 If WITH-TIME is non-nil, returns the time of the event at point (in
-the agenda) or the current time of the day."
+the agenda) or the current time of the day; otherwise returns the
+earliest time on the cursor date that Org treats as that date
+(bearing in mind `org-extend-today-until')."
   (let (date day defd tp hod mod)
     (when with-time
       (setq tp (get-text-property (point) 'time))
@@ -22337,13 +19031,13 @@ the agenda) or the current time of the day."
     (cond
      ((eq major-mode 'calendar-mode)
       (setq date (calendar-cursor-to-date)
-           defd (encode-time 0 (or mod 0) (or hod 0)
+           defd (encode-time 0 (or mod 0) (or hod org-extend-today-until)
                              (nth 1 date) (nth 0 date) (nth 2 date))))
      ((eq major-mode 'org-agenda-mode)
       (setq day (get-text-property (point) 'day))
       (when day
        (setq date (calendar-gregorian-from-absolute day)
-             defd (encode-time 0 (or mod 0) (or hod 0)
+             defd (encode-time 0 (or mod 0) (or hod org-extend-today-until)
                                (nth 1 date) (nth 0 date) (nth 2 date))))))
     (or defd (current-time))))
 
@@ -22362,75 +19056,6 @@ hierarchy of headlines by UP levels before marking the 
subtree."
       (call-interactively 'org-mark-element)
     (org-mark-element)))
 
-(defun org-file-newer-than-p (file time)
-  "Non-nil if FILE is newer than TIME.
-FILE is a filename, as a string, TIME is a list of integers, as
-returned by, e.g., `current-time'."
-  (and (file-exists-p file)
-       ;; Only compare times up to whole seconds as some file-systems
-       ;; (e.g. HFS+) do not retain any finer granularity.  As
-       ;; a consequence, make sure we return non-nil when the two
-       ;; times are equal.
-       (not (time-less-p (cl-subseq (file-attribute-modification-time
-                                    (file-attributes file))
-                                   0 2)
-                        (cl-subseq time 0 2)))))
-
-(defun org-compile-file (source process ext &optional err-msg log-buf spec)
-  "Compile a SOURCE file using PROCESS.
-
-PROCESS is either a function or a list of shell commands, as
-strings.  EXT is a file extension, without the leading dot, as
-a string.  It is used to check if the process actually succeeded.
-
-PROCESS must create a file with the same base name and directory
-as SOURCE, but ending with EXT.  The function then returns its
-filename.  Otherwise, it raises an error.  The error message can
-then be refined by providing string ERR-MSG, which is appended to
-the standard message.
-
-If PROCESS is a function, it is called with a single argument:
-the SOURCE file.
-
-If it is a list of commands, each of them is called using
-`shell-command'.  By default, in each command, %b, %f, %F, %o and
-%O are replaced with, respectively, SOURCE base name, name, full
-name, directory and absolute output file name.  It is possible,
-however, to use more place-holders by specifying them in optional
-argument SPEC, as an alist following the pattern
-
-  (CHARACTER . REPLACEMENT-STRING).
-
-When PROCESS is a list of commands, optional argument LOG-BUF can
-be set to a buffer or a buffer name.  `shell-command' then uses
-it for output."
-  (let* ((base-name (file-name-base source))
-        (full-name (file-truename source))
-        (out-dir (or (file-name-directory source) "./"))
-        (output (expand-file-name (concat base-name "." ext) out-dir))
-        (time (current-time))
-        (err-msg (if (stringp err-msg) (concat ".  " err-msg) "")))
-    (save-window-excursion
-      (pcase process
-       ((pred functionp) (funcall process (shell-quote-argument source)))
-       ((pred consp)
-        (let ((log-buf (and log-buf (get-buffer-create log-buf)))
-              (spec (append spec
-                            `((?b . ,(shell-quote-argument base-name))
-                              (?f . ,(shell-quote-argument source))
-                              (?F . ,(shell-quote-argument full-name))
-                              (?o . ,(shell-quote-argument out-dir))
-                              (?O . ,(shell-quote-argument output))))))
-          (dolist (command process)
-            (shell-command (format-spec command spec) log-buf))
-          (when log-buf (with-current-buffer log-buf (compilation-mode)))))
-       (_ (error "No valid command to process %S%s" source err-msg))))
-    ;; Check for process failure.  Output file is expected to be
-    ;; located in the same directory as SOURCE.
-    (unless (org-file-newer-than-p output time)
-      (error (format "File %S wasn't produced%s" output err-msg)))
-    output))
-
 ;;; Indentation
 
 (defvar org-element-greater-elements)
@@ -22454,7 +19079,7 @@ ELEMENT."
         ((item plain-list) (org-list-item-body-column post-affiliated))
         (t
          (goto-char start)
-         (org-get-indentation))))
+         (current-indentation))))
       ((memq type '(headline inlinetask nil))
        (if (org-match-line "[ \t]*$")
           (org--get-expected-indentation element t)
@@ -22487,7 +19112,7 @@ ELEMENT."
                 (setq start (org-element-property :begin previous)))
                (t (goto-char (org-element-property :begin previous))
                   (throw 'exit
-                         (if (bolp) (org-get-indentation)
+                         (if (bolp) (current-indentation)
                            ;; At first paragraph in an item or
                            ;; a footnote definition.
                            (org--get-expected-indentation
@@ -22506,7 +19131,7 @@ ELEMENT."
          ((and (memq type '(footnote-definition plain-list))
                (> (count-lines (point) pos) 2))
           (goto-char start)
-          (org-get-indentation))
+          (current-indentation))
          ;; Line above is the first one of a paragraph at the
          ;; beginning of an item or a footnote definition.  Indent
          ;; like parent.
@@ -22533,9 +19158,9 @@ ELEMENT."
                 (org--get-expected-indentation
                  last (eq (org-element-type last) 'item)))
             (goto-char start)
-            (org-get-indentation)))
+            (current-indentation)))
          ;; In any other case, indent like the current line.
-         (t (org-get-indentation)))))))))
+         (t (current-indentation)))))))))
 
 (defun org--align-node-property ()
   "Align node property at point.
@@ -22564,10 +19189,8 @@ Indentation is done according to the following rules:
        definitions and inline tasks, indent like its first line.
 
     2. If element has a parent, indent like its contents.  More
-       precisely, if parent is an item, indent after the
-       description part, if any, or the bullet (see
-       `org-list-description-max-indent').  Else, indent like
-       parent's first line.
+       precisely, if parent is an item, indent after the bullet.
+       Else, indent like parent's first line.
 
     3. Otherwise, indent relatively to current level, if
        `org-adapt-indentation' is non-nil, or to left margin.
@@ -22596,10 +19219,6 @@ list structure.  Instead, use 
\\<org-mode-map>`\\[org-shiftmetaleft]' or \
 Also align node properties according to `org-property-format'."
   (interactive)
   (cond
-   (orgstruct-is-++
-    (let ((indent-line-function
-          (cl-cadadr (assq 'indent-line-function org-fb-vars))))
-      (indent-according-to-mode)))
    ((org-at-heading-p) 'noindent)
    (t
     (let* ((element (save-excursion (beginning-of-line) 
(org-element-at-point)))
@@ -22675,7 +19294,7 @@ assumed to be significant there."
                       (not
                        (or org-src-preserve-indentation
                            (org-element-property :preserve-indent element)))))
-             (let ((offset (- ind (org-get-indentation))))
+             (let ((offset (- ind (current-indentation))))
                (unless (zerop offset)
                  (indent-rigidly (org-element-property :begin element)
                                  (org-element-property :end element)
@@ -22731,7 +19350,7 @@ assumed to be significant there."
                ;; might break the list as a whole.  On the other
                ;; hand, when at a plain list, indent it as a whole.
                (cond ((eq type 'plain-list)
-                      (let ((offset (- ind (org-get-indentation))))
+                      (let ((offset (- ind (current-indentation))))
                         (unless (zerop offset)
                           (indent-rigidly (org-element-property :begin element)
                                           (org-element-property :end element)
@@ -22849,78 +19468,63 @@ assumed to be significant there."
   ;; parenthesis can end up being parsed as a new list item.
   (looking-at-p "[ \t]*{{{n\\(?:([^\n)]*)\\)?}}}[.)]\\(?:$\\| \\)"))
 
-(declare-function message-in-body-p "message" ())
-(defvar orgtbl-line-start-regexp) ; From org-table.el
 (defun org-adaptive-fill-function ()
   "Compute a fill prefix for the current line.
 Return fill prefix, as a string, or nil if current line isn't
 meant to be filled.  For convenience, if `adaptive-fill-regexp'
 matches in paragraphs or comments, use it."
-  (catch 'exit
-    (when (derived-mode-p 'message-mode)
-      (save-excursion
-       (beginning-of-line)
-       (cond ((not (message-in-body-p)) (throw 'exit nil))
-             ((looking-at-p org-table-line-regexp) (throw 'exit nil))
-             ((looking-at message-cite-prefix-regexp)
-              (throw 'exit (match-string-no-properties 0)))
-             ((looking-at org-outline-regexp)
-              (throw 'exit (make-string (length (match-string 0)) ?\s))))))
-    (org-with-wide-buffer
-     (unless (org-at-heading-p)
-       (let* ((p (line-beginning-position))
-             (element (save-excursion
-                        (beginning-of-line)
-                        (org-element-at-point)))
-             (type (org-element-type element))
-             (post-affiliated (org-element-property :post-affiliated element)))
-        (unless (< p post-affiliated)
-          (cl-case type
-            (comment
+  (org-with-wide-buffer
+   (unless (org-at-heading-p)
+     (let* ((p (line-beginning-position))
+           (element (save-excursion
+                      (beginning-of-line)
+                      (org-element-at-point)))
+           (type (org-element-type element))
+           (post-affiliated (org-element-property :post-affiliated element)))
+       (unless (< p post-affiliated)
+        (cl-case type
+          (comment
+           (save-excursion
+             (beginning-of-line)
+             (looking-at "[ \t]*")
+             (concat (match-string 0) "# ")))
+          (footnote-definition "")
+          ((item plain-list)
+           (make-string (org-list-item-body-column post-affiliated) ?\s))
+          (paragraph
+           ;; Fill prefix is usually the same as the current line,
+           ;; unless the paragraph is at the beginning of an item.
+           (let ((parent (org-element-property :parent element)))
              (save-excursion
                (beginning-of-line)
-               (looking-at "[ \t]*")
-               (concat (match-string 0) "# ")))
-            (footnote-definition "")
-            ((item plain-list)
-             (make-string (org-list-item-body-column post-affiliated) ?\s))
-            (paragraph
-             ;; Fill prefix is usually the same as the current line,
-             ;; unless the paragraph is at the beginning of an item.
-             (let ((parent (org-element-property :parent element)))
-               (save-excursion
-                 (beginning-of-line)
-                 (cond ((eq (org-element-type parent) 'item)
-                        (make-string (org-list-item-body-column
-                                      (org-element-property :begin parent))
-                                     ?\s))
-                       ((and adaptive-fill-regexp
-                             ;; Locally disable
-                             ;; `adaptive-fill-function' to let
-                             ;; `fill-context-prefix' handle
-                             ;; `adaptive-fill-regexp' variable.
-                             (let (adaptive-fill-function)
-                               (fill-context-prefix
-                                post-affiliated
-                                (org-element-property :end element)))))
-                       ((looking-at "[ \t]+") (match-string 0))
-                       (t  "")))))
-            (comment-block
-             ;; Only fill contents if P is within block boundaries.
-             (let* ((cbeg (save-excursion (goto-char post-affiliated)
-                                          (forward-line)
-                                          (point)))
-                    (cend (save-excursion
-                            (goto-char (org-element-property :end element))
-                            (skip-chars-backward " \r\t\n")
-                            (line-beginning-position))))
-               (when (and (>= p cbeg) (< p cend))
-                 (if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
-                     (match-string 0)
-                   "")))))))))))
-
-(declare-function message-goto-body "message" (&optional interactive))
-(defvar message-cite-prefix-regexp)    ; From message.el
+               (cond ((eq (org-element-type parent) 'item)
+                      (make-string (org-list-item-body-column
+                                    (org-element-property :begin parent))
+                                   ?\s))
+                     ((and adaptive-fill-regexp
+                           ;; Locally disable
+                           ;; `adaptive-fill-function' to let
+                           ;; `fill-context-prefix' handle
+                           ;; `adaptive-fill-regexp' variable.
+                           (let (adaptive-fill-function)
+                             (fill-context-prefix
+                              post-affiliated
+                              (org-element-property :end element)))))
+                     ((looking-at "[ \t]+") (match-string 0))
+                     (t  "")))))
+          (comment-block
+           ;; Only fill contents if P is within block boundaries.
+           (let* ((cbeg (save-excursion (goto-char post-affiliated)
+                                        (forward-line)
+                                        (point)))
+                  (cend (save-excursion
+                          (goto-char (org-element-property :end element))
+                          (skip-chars-backward " \r\t\n")
+                          (line-beginning-position))))
+             (when (and (>= p cbeg) (< p cend))
+               (if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
+                   (match-string 0)
+                 ""))))))))))
 
 (defun org-fill-element (&optional justify)
   "Fill element at point, when applicable.
@@ -22944,7 +19548,7 @@ a footnote definition, try to fill the first paragraph 
within."
       ;; First check if point is in a blank line at the beginning of
       ;; the buffer.  In that case, ignore filling.
       (cl-case (org-element-type element)
-       ;; Use major mode filling function is src blocks.
+       ;; Use major mode filling function is source blocks.
        (src-block (org-babel-do-key-sequence-in-edit-buffer (kbd "M-q")))
        ;; Align Org tables, leave table.el tables as-is.
        (table-row (org-table-align) t)
@@ -22962,15 +19566,6 @@ a footnote definition, try to fill the first paragraph 
within."
                         (org-element-property :contents-end element))))
           ;; Do nothing if point is at an affiliated keyword.
           (if (< (line-end-position) beg) t
-            (when (derived-mode-p 'message-mode)
-              ;; In `message-mode', do not fill following citation
-              ;; in current paragraph nor text before message body.
-              (let ((body-start (save-excursion (message-goto-body))))
-                (when body-start (setq beg (max body-start beg))))
-              (when (save-excursion
-                      (re-search-forward
-                       (concat "^" message-cite-prefix-regexp) end t))
-                (setq end (match-beginning 0))))
             ;; Fill paragraph, taking line breaks into account.
             (save-excursion
               (goto-char beg)
@@ -23063,34 +19658,28 @@ fill each of the elements in the active region, 
instead of just
 filling the current element."
   (interactive (progn
                 (barf-if-buffer-read-only)
-                (list (if current-prefix-arg 'full) t)))
-  (cond
-   ((and (derived-mode-p 'message-mode)
-        (or (not (message-in-body-p))
-            (save-excursion (move-beginning-of-line 1)
-                            (looking-at message-cite-prefix-regexp))))
-    ;; First ensure filling is correct in message-mode.
-    (let ((fill-paragraph-function
-          (cl-cadadr (assq 'fill-paragraph-function org-fb-vars)))
-         (fill-prefix (cl-cadadr (assq 'fill-prefix org-fb-vars)))
-         (paragraph-start (cl-cadadr (assq 'paragraph-start org-fb-vars)))
-         (paragraph-separate
-          (cl-cadadr (assq 'paragraph-separate org-fb-vars))))
-      (fill-paragraph nil)))
-   ((and region transient-mark-mode mark-active
-        (not (eq (region-beginning) (region-end))))
-    (let ((origin (point-marker))
-         (start (region-beginning)))
-      (unwind-protect
-         (progn
-           (goto-char (region-end))
-           (while (> (point) start)
-             (org-backward-paragraph)
-             (org-fill-element justify)))
-       (goto-char origin)
-       (set-marker origin nil))))
-   (t (org-fill-element justify))))
-(org-remap org-mode-map 'fill-paragraph 'org-fill-paragraph)
+                (list (when current-prefix-arg 'full) t)))
+  (let ((hash (and (not (buffer-modified-p))
+                  (org-buffer-hash))))
+    (cond
+     ((and region transient-mark-mode mark-active
+          (not (eq (region-beginning) (region-end))))
+      (let ((origin (point-marker))
+           (start (region-beginning)))
+       (unwind-protect
+           (progn
+             (goto-char (region-end))
+             (while (> (point) start)
+               (org-backward-paragraph)
+               (org-fill-element justify)))
+         (goto-char origin)
+         (set-marker origin nil))))
+     (t (org-fill-element justify)))
+    ;; If we didn't change anything in the buffer (and the buffer was
+    ;; previously unmodified), then flip the modification status back
+    ;; to "unchanged".
+    (when (and hash (equal hash (org-buffer-hash)))
+      (set-buffer-modified-p nil))))
 
 (defun org-auto-fill-function ()
   "Auto-fill function."
@@ -23204,7 +19793,7 @@ region only contains such lines."
               (catch 'zerop
                 (while (< (point) end)
                   (unless (looking-at-p "[ \t]*$")
-                    (let ((ind (org-get-indentation)))
+                    (let ((ind (current-indentation)))
                       (setq min-ind (min min-ind ind))
                       (when (zerop ind) (throw 'zerop t))))
                   (forward-line)))))
@@ -23238,7 +19827,69 @@ region only contains such lines."
                 (forward-line)))))))
       (set-marker end nil))))
 
+
+;;; Blocks
+
+(defun org-block-map (function &optional start end)
+  "Call FUNCTION at the head of all source blocks in the current buffer.
+Optional arguments START and END can be used to limit the range."
+  (let ((start (or start (point-min)))
+        (end (or end (point-max))))
+    (save-excursion
+      (goto-char start)
+      (while (and (< (point) end) (re-search-forward org-block-regexp end t))
+       (save-excursion
+         (save-match-data
+            (goto-char (match-beginning 0))
+            (funcall function)))))))
+
+(defun org-next-block (arg &optional backward block-regexp)
+  "Jump to the next block.
+
+With a prefix argument ARG, jump forward ARG many blocks.
+
+When BACKWARD is non-nil, jump to the previous block.
+
+When BLOCK-REGEXP is non-nil, use this regexp to find blocks.
+Match data is set according to this regexp when the function
+returns.
+
+Return point at beginning of the opening line of found block.
+Throw an error if no block is found."
+  (interactive "p")
+  (let ((re (or block-regexp "^[ \t]*#\\+BEGIN"))
+       (case-fold-search t)
+       (search-fn (if backward #'re-search-backward #'re-search-forward))
+       (count (or arg 1))
+       (origin (point))
+       last-element)
+    (if backward (beginning-of-line) (end-of-line))
+    (while (and (> count 0) (funcall search-fn re nil t))
+      (let ((element (save-excursion
+                      (goto-char (match-beginning 0))
+                      (save-match-data (org-element-at-point)))))
+       (when (and (memq (org-element-type element)
+                        '(center-block comment-block dynamic-block
+                                       example-block export-block quote-block
+                                       special-block src-block verse-block))
+                  (<= (match-beginning 0)
+                      (org-element-property :post-affiliated element)))
+         (setq last-element element)
+         (cl-decf count))))
+    (if (= count 0)
+       (prog1 (goto-char (org-element-property :post-affiliated last-element))
+         (save-match-data (org-show-context)))
+      (goto-char origin)
+      (user-error "No %s code blocks" (if backward "previous" "further")))))
+
+(defun org-previous-block (arg &optional block-regexp)
+  "Jump to the previous block.
+With a prefix argument ARG, jump backward ARG many source blocks.
+When BLOCK-REGEXP is non-nil, use this regexp to find blocks."
+  (interactive "p")
+  (org-next-block arg t block-regexp))
 
+
 ;;; Comments
 
 ;; Org comments syntax is quite complex.  It requires the entire line
@@ -23363,21 +20014,54 @@ strictly within a source block, use appropriate 
comment syntax."
                (forward-line)))))))))
 
 (defun org-comment-dwim (_arg)
-  "Call `comment-dwim' within a source edit buffer if needed."
+  "Call the comment command you mean.
+Call `org-toggle-comment' if on a heading, otherwise call
+`comment-dwim', within a source edit buffer if needed."
   (interactive "*P")
-  (if (org-in-src-block-p)
-      (org-babel-do-in-edit-buffer (call-interactively 'comment-dwim))
-    (call-interactively 'comment-dwim)))
+  (cond ((org-at-heading-p)
+        (call-interactively #'org-toggle-comment))
+       ((org-in-src-block-p)
+        (org-babel-do-in-edit-buffer (call-interactively #'comment-dwim)))
+       (t (call-interactively #'comment-dwim))))
 
 
 ;;; Timestamps API
 
-;; This section contains tools to operate on timestamp objects, as
-;; returned by, e.g. `org-element-context'.
+;; This section contains tools to operate on, or create, timestamp
+;; objects, as returned by, e.g. `org-element-context'.
 
-(defun org-timestamp--to-internal-time (timestamp &optional end)
-  "Encode TIMESTAMP object into Emacs internal time.
-Use end of date range or time range when END is non-nil."
+(defun org-timestamp-from-string (s)
+  "Convert Org timestamp S, as a string, into a timestamp object.
+Return nil if S is not a valid timestamp string."
+  (when (org-string-nw-p s)
+    (with-temp-buffer
+      (save-excursion (insert s))
+      (org-element-timestamp-parser))))
+
+(defun org-timestamp-from-time (time &optional with-time inactive)
+  "Convert a time value into a timestamp object.
+
+TIME is an Emacs internal time representation, as returned, e.g.,
+by `current-time'.
+
+When optional argument WITH-TIME is non-nil, return a timestamp
+object with a time part, i.e., with hours and minutes.
+
+Return an inactive timestamp if INACTIVE is non-nil.  Otherwise,
+return an active timestamp."
+  (pcase-let ((`(,_ ,minute ,hour ,day ,month ,year . ,_) (decode-time time)))
+    (org-element-create 'timestamp
+                       (list :type (if inactive 'inactive 'active)
+                             :year-start year
+                             :month-start month
+                             :day-start day
+                             :hour-start (and with-time hour)
+                             :minute-start (and with-time minute)))))
+
+(defun org-timestamp-to-time (timestamp &optional end)
+  "Convert TIMESTAMP object into an Emacs internal time value.
+Use end of date range or time range when END is non-nil.
+Otherwise, use its start."
   (apply #'encode-time 0
         (mapcar
          (lambda (prop) (or (org-element-property prop timestamp) 0))
@@ -23398,11 +20082,10 @@ FORMAT is a format specifier to be passed to
 When optional argument END is non-nil, use end of date-range or
 time-range, if possible.
 
-When optional argument UTC is non-nil, time will be expressed as
+When optional argument UTC is non-nil, time is be expressed as
 Universal Time."
-  (format-time-string
-   format (org-timestamp--to-internal-time timestamp end)
-   (and utc t)))
+  (format-time-string format (org-timestamp-to-time timestamp end)
+                     (and utc t)))
 
 (defun org-timestamp-split-range (timestamp &optional end)
   "Extract a TIMESTAMP object from a date or time range.
@@ -23459,9 +20142,7 @@ it has a `diary' type."
                    (org-timestamp-format timestamp fmt t))
          (org-timestamp-format timestamp fmt (eq boundary 'end)))))))
 
-
-
-;;; Other stuff.
+;;; Other stuff
 
 (defvar reftex-docstruct-symbol)
 (defvar org--rds)
@@ -23498,9 +20179,13 @@ package ox-bibtex by Taru Karttunen."
 (defun org-beginning-of-line (&optional n)
   "Go to the beginning of the current visible line.
 
-If this is a headline, and `org-special-ctrl-a/e' is set, ignore
-tags on the first attempt, and only move to after the tags when
-the cursor is already beyond the end of the headline.
+If this is a headline, and `org-special-ctrl-a/e' is not nil or
+symbol `reversed', on the first attempt move to where the
+headline text starts, and only move to beginning of line when the
+cursor is already before the start of the text of the headline.
+
+If `org-special-ctrl-a/e' is symbol `reversed' then go to the
+start of the text on the second attempt.
 
 With argument N not nil or 1, move forward N - 1 lines first."
   (interactive "^p")
@@ -23557,9 +20242,13 @@ With argument N not nil or 1, move forward N - 1 lines 
first."
 (defun org-end-of-line (&optional n)
   "Go to the end of the line, but before ellipsis, if any.
 
-If this is a headline, and `org-special-ctrl-a/e' is set, ignore
-tags on the first attempt, and only move to after the tags when
-the cursor is already beyond the end of the headline.
+If this is a headline, and `org-special-ctrl-a/e' is not nil or
+symbol `reversed', ignore tags on the first attempt, and only
+move to after the tags when the cursor is already beyond the end
+of the headline.
+
+If `org-special-ctrl-a/e' is symbol `reversed' then ignore tags
+on the second attempt.
 
 With argument N not nil or 1, move forward N - 1 lines first."
   (interactive "^p")
@@ -23613,9 +20302,6 @@ With argument N not nil or 1, move forward N - 1 lines 
first."
          (end-of-line))))
      (t (end-of-line)))))
 
-(define-key org-mode-map "\C-a" 'org-beginning-of-line)
-(define-key org-mode-map "\C-e" 'org-end-of-line)
-
 (defun org-backward-sentence (&optional _arg)
   "Go to beginning of sentence, or beginning of table field.
 This will call `backward-sentence' or `org-table-beginning-of-field',
@@ -23666,9 +20352,6 @@ depending on context."
          (let ((sentence-end (concat (sentence-end) "\\|^\\*+ .*$")))
            (call-interactively #'forward-sentence)))))))
 
-(define-key org-mode-map "\M-a" 'org-backward-sentence)
-(define-key org-mode-map "\M-e" 'org-forward-sentence)
-
 (defun org-kill-line (&optional _arg)
   "Kill line, to tags or end of line."
   (interactive)
@@ -23676,19 +20359,25 @@ depending on context."
    ((or (not org-special-ctrl-k)
        (bolp)
        (not (org-at-heading-p)))
-    (when (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
+    (when (and (get-char-property (line-end-position) 'invisible)
               org-ctrl-k-protect-subtree
               (or (eq org-ctrl-k-protect-subtree 'error)
                   (not (y-or-n-p "Kill hidden subtree along with headline? 
"))))
-      (user-error "C-k aborted as it would kill a hidden subtree"))
+      (user-error
+       (substitute-command-keys
+       "`\\[org-kill-line]' aborted as it would kill a hidden subtree")))
     (call-interactively
      (if (bound-and-true-p visual-line-mode) 'kill-visual-line 'kill-line)))
-   ((looking-at ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$")
-    (kill-region (point) (match-beginning 1))
-    (org-set-tags nil t))
-   (t (kill-region (point) (point-at-eol)))))
-
-(define-key org-mode-map "\C-k" 'org-kill-line)
+   ((org-match-line org-tag-line-re)
+    (let ((end (save-excursion
+                (goto-char (match-beginning 1))
+                (skip-chars-backward " \t")
+                (point))))
+      (if (<= end (point))             ;on tags part
+         (kill-region (point) (line-end-position))
+       (kill-region (point) end)))
+    (org-align-tags))
+   (t (kill-region (point) (line-end-position)))))
 
 (defun org-yank (&optional arg)
   "Yank.  If the kill is a subtree, treat it specially.
@@ -23757,7 +20446,7 @@ interactive command with similar behavior."
             (or (looking-at org-outline-regexp)
                 (re-search-forward org-outline-regexp-bol end t))
             (while (and (< (point) end) (looking-at org-outline-regexp))
-              (outline-hide-subtree)
+              (org-flag-subtree t)
               (org-cycle-show-empty-lines 'folded)
               (condition-case nil
                   (outline-forward-same-level 1)
@@ -23792,25 +20481,6 @@ interactive command with similar behavior."
                (and (bolp) (looking-at-p org-outline-regexp)
                     (<= (org-outline-level) level))))))))
 
-(define-key org-mode-map "\C-y" 'org-yank)
-
-(defun org-truely-invisible-p ()
-  "Check if point is at a character currently not visible.
-This version does not only check the character property, but also
-`visible-mode'."
-  (unless (bound-and-true-p visible-mode)
-    (org-invisible-p)))
-
-(defun org-invisible-p2 ()
-  "Check if point is at a character currently not visible.
-
-If the point is at EOL (and not at the beginning of a buffer too),
-move it back by one char before doing this check."
-  (save-excursion
-    (when (and (eolp) (not (bobp)))
-      (backward-char 1))
-    (org-invisible-p)))
-
 (defun org-back-to-heading (&optional invisible-ok)
   "Call `outline-back-to-heading', but provide a better error message."
   (condition-case nil
@@ -23820,11 +20490,13 @@ move it back by one char before doing this check."
 
 (defun org-before-first-heading-p ()
   "Before first heading?"
-  (save-excursion
-    (end-of-line)
-    (null (re-search-backward org-outline-regexp-bol nil t))))
+  (org-with-limited-levels
+   (save-excursion
+     (end-of-line)
+     (null (re-search-backward org-outline-regexp-bol nil t)))))
 
-(defun org-at-heading-p (&optional ignored)
+(defun org-at-heading-p (&optional _)
+  "Non-nil when on a headline."
   (outline-on-heading-p t))
 
 (defun org-in-commented-heading-p (&optional no-inheritance)
@@ -23843,20 +20515,20 @@ unless optional argument NO-INHERITANCE is non-nil."
     (save-excursion (and (org-up-heading-safe) 
(org-in-commented-heading-p))))))
 
 (defun org-at-comment-p nil
-  "Is cursor in a commented line?"
+  "Return t if cursor is in a commented line."
   (save-excursion
     (save-match-data
       (beginning-of-line)
       (looking-at "^[ \t]*# "))))
 
 (defun org-at-drawer-p nil
-  "Is cursor at a drawer keyword?"
+  "Return t if cursor is at a drawer keyword."
   (save-excursion
     (move-beginning-of-line 1)
     (looking-at org-drawer-regexp)))
 
 (defun org-at-block-p nil
-  "Is cursor at a block keyword?"
+  "Return t if cursor is at a block keyword."
   (save-excursion
     (move-beginning-of-line 1)
     (looking-at org-block-regexp)))
@@ -23876,12 +20548,6 @@ empty."
 (defun org-at-heading-or-item-p ()
   (or (org-at-heading-p) (org-at-item-p)))
 
-(defun org-at-target-p ()
-  (or (org-in-regexp org-radio-target-regexp)
-      (org-in-regexp org-target-regexp)))
-;; Compatibility alias with Org versions < 7.8.03
-(defalias 'org-on-target-p 'org-at-target-p)
-
 (defun org-up-heading-all (arg)
   "Move to the heading line of which the present line is a subheading.
 This function considers both visible and invisible heading lines.
@@ -23967,15 +20633,13 @@ When ENTRY is non-nil, show the entire entry."
   (save-excursion
     (org-back-to-heading t)
     ;; Check if we should show the entire entry
-    (if entry
-       (progn
-         (org-show-entry)
-         (save-excursion
-           (and (outline-next-heading)
-                (org-flag-heading nil))))
-      (outline-flag-region (max (point-min) (1- (point)))
-                          (save-excursion (outline-end-of-heading) (point))
-                          flag))))
+    (if (not entry)
+       (org-flag-region
+        (line-end-position 0) (line-end-position) flag 'outline)
+      (org-show-entry)
+      (save-excursion
+       (and (outline-next-heading)
+            (org-flag-heading nil))))))
 
 (defun org-get-next-sibling ()
   "Move to next heading of the same level, and return point.
@@ -24112,52 +20776,6 @@ respect customization of `org-odd-levels-only'."
   (org-with-limited-levels
    (outline-previous-visible-heading arg)))
 
-(defun org-next-block (arg &optional backward block-regexp)
-  "Jump to the next block.
-
-With a prefix argument ARG, jump forward ARG many blocks.
-
-When BACKWARD is non-nil, jump to the previous block.
-
-When BLOCK-REGEXP is non-nil, use this regexp to find blocks.
-Match data is set according to this regexp when the function
-returns.
-
-Return point at beginning of the opening line of found block.
-Throw an error if no block is found."
-  (interactive "p")
-  (let ((re (or block-regexp "^[ \t]*#\\+BEGIN"))
-       (case-fold-search t)
-       (search-fn (if backward #'re-search-backward #'re-search-forward))
-       (count (or arg 1))
-       (origin (point))
-       last-element)
-    (if backward (beginning-of-line) (end-of-line))
-    (while (and (> count 0) (funcall search-fn re nil t))
-      (let ((element (save-excursion
-                      (goto-char (match-beginning 0))
-                      (save-match-data (org-element-at-point)))))
-       (when (and (memq (org-element-type element)
-                        '(center-block comment-block dynamic-block
-                                       example-block export-block quote-block
-                                       special-block src-block verse-block))
-                  (<= (match-beginning 0)
-                      (org-element-property :post-affiliated element)))
-         (setq last-element element)
-         (cl-decf count))))
-    (if (= count 0)
-       (prog1 (goto-char (org-element-property :post-affiliated last-element))
-         (save-match-data (org-show-context)))
-      (goto-char origin)
-      (user-error "No %s code blocks" (if backward "previous" "further")))))
-
-(defun org-previous-block (arg &optional block-regexp)
-  "Jump to the previous block.
-With a prefix argument ARG, jump backward ARG many source blocks.
-When BLOCK-REGEXP is non-nil, use this regexp to find blocks."
-  (interactive "p")
-  (org-next-block arg t block-regexp))
-
 (defun org-forward-paragraph ()
   "Move forward to beginning of next paragraph or equivalent.
 
@@ -24543,72 +21161,6 @@ modified."
                      (org-do-remove-indentation))))))))
     (funcall unindent-tree (org-element-contents parse-tree))))
 
-(defun org-show-children (&optional level)
-  "Show all direct subheadings of this heading.
-Prefix arg LEVEL is how many levels below the current level
-should be shown.  Default is enough to cause the following
-heading to appear."
-  (interactive "p")
-  ;; If `orgstruct-mode' is active, use the slower version.
-  (if orgstruct-mode (call-interactively #'outline-show-children)
-    (save-excursion
-      (org-back-to-heading t)
-      (let* ((current-level (funcall outline-level))
-            (max-level (org-get-valid-level
-                        current-level
-                        (if level (prefix-numeric-value level) 1)))
-            (end (save-excursion (org-end-of-subtree t t)))
-            (regexp-fmt "^\\*\\{%d,%s\\}\\(?: \\|$\\)")
-            (past-first-child nil)
-            ;; Make sure to skip inlinetasks.
-            (re (format regexp-fmt
-                        current-level
-                        (cond
-                         ((not (featurep 'org-inlinetask)) "")
-                         (org-odd-levels-only (- (* 2 org-inlinetask-min-level)
-                                                 3))
-                         (t (1- org-inlinetask-min-level))))))
-       ;; Display parent heading.
-       (outline-flag-region (line-end-position 0) (line-end-position) nil)
-       (forward-line)
-       ;; Display children.  First child may be deeper than expected
-       ;; MAX-LEVEL.  Since we want to display it anyway, adjust
-       ;; MAX-LEVEL accordingly.
-       (while (re-search-forward re end t)
-         (unless past-first-child
-           (setq re (format regexp-fmt
-                            current-level
-                            (max (funcall outline-level) max-level)))
-           (setq past-first-child t))
-         (outline-flag-region
-          (line-end-position 0) (line-end-position) nil))))))
-
-(defun org-show-subtree ()
-  "Show everything after this heading at deeper levels."
-  (interactive)
-  (outline-flag-region
-   (point)
-   (save-excursion
-     (org-end-of-subtree t t))
-   nil))
-
-(defun org-show-entry ()
-  "Show the body directly following this heading.
-Show the heading too, if it is currently invisible."
-  (interactive)
-  (save-excursion
-    (ignore-errors
-      (org-back-to-heading t)
-      (outline-flag-region
-       (max (point-min) (1- (point)))
-       (save-excursion
-        (if (re-search-forward
-             (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
-            (match-beginning 1)
-          (point-max)))
-       nil)
-      (org-cycle-hide-drawers 'children))))
-
 (defun org-make-options-regexp (kwds &optional extra)
   "Make a regular expression for keyword lines.
 KWDS is a list of keywords, as strings.  Optional argument EXTRA,
@@ -24618,285 +21170,61 @@ when non-nil, is a regexp matching keywords names."
          (and extra (concat (and kwds "\\|") extra))
          "\\):[ \t]*\\(.*\\)"))
 
-;;;; Integration with and fixes for other packages
-
-;;; Imenu support
+
+;;; Conveniently switch to Info nodes
 
-(defvar-local org-imenu-markers nil
-  "All markers currently used by Imenu.")
+(defun org-info-find-node (&optional nodename)
+  "Find Info documentation NODENAME or Org documentation according context.
+Started from `gnus-info-find-node'."
+  (interactive)
+  (Info-goto-node
+   (or nodename
+       (let ((default-org-info-node "(org) Top"))
+         (cond
+          ((eq 'org-agenda-mode major-mode) "(org) Agenda Views")
+          ((eq 'org-mode major-mode)
+           (let* ((context (org-element-at-point))
+                  (element-info-nodes ; compare to `org-element-all-elements'.
+                   `((babel-call . "(org) Evaluating Code Blocks")
+                     (center-block . "(org) Paragraphs")
+                     (clock . ,default-org-info-node)
+                     (comment . "(org) Comment Lines")
+                     (comment-block . "(org) Comment Lines")
+                     (diary-sexp . ,default-org-info-node)
+                     (drawer . "(org) Drawers")
+                     (dynamic-block . "(org) Dynamic Blocks")
+                     (example-block . "(org) Literal Examples")
+                     (export-block . "(org) ASCII/Latin-1/UTF-8 export")
+                     (fixed-width . ,default-org-info-node)
+                     (footnote-definition . "(org) Creating Footnotes")
+                     (headline . "(org) Document Structure")
+                     (horizontal-rule . "(org) Built-in Table Editor")
+                     (inlinetask . ,default-org-info-node)
+                     (item . "(org) Plain Lists")
+                     (keyword . "(org) Per-file keywords")
+                     (latex-environment . "(org) LaTeX Export")
+                     (node-property . "(org) Properties and Columns")
+                     (paragraph . "(org) Paragraphs")
+                     (plain-list . "(org) Plain Lists")
+                     (planning . "(org) Deadlines and Scheduling")
+                     (property-drawer . "(org) Properties and Columns")
+                     (quote-block . "(org) Paragraphs")
+                     (section . ,default-org-info-node)
+                     (special-block . ,default-org-info-node)
+                     (src-block . "(org) Working with Source Code")
+                     (table . "(org) Tables")
+                     (table-row . "(org) Tables")
+                     (verse-block . "(org) Paragraphs"))))
+             (or (cdr (assoc (car context) element-info-nodes))
+                 default-org-info-node)))
+          (t default-org-info-node))))))
 
-(defun org-imenu-new-marker (&optional pos)
-  "Return a new marker for use by Imenu, and remember the marker."
-  (let ((m (make-marker)))
-    (move-marker m (or pos (point)))
-    (push m org-imenu-markers)
-    m))
+
+;;; Finish up
 
-(defun org-imenu-get-tree ()
-  "Produce the index for Imenu."
-  (dolist (x org-imenu-markers) (move-marker x nil))
-  (setq org-imenu-markers nil)
-  (let* ((case-fold-search nil)
-        (n org-imenu-depth)
-        (re (concat "^" (org-get-limited-outline-regexp)))
-        (subs (make-vector (1+ n) nil))
-        (last-level 0)
-        m level head0 head)
-    (org-with-wide-buffer
-     (goto-char (point-max))
-     (while (re-search-backward re nil t)
-       (setq level (org-reduced-level (funcall outline-level)))
-       (when (and (<= level n)
-                 (looking-at org-complex-heading-regexp)
-                 (setq head0 (match-string-no-properties 4)))
-        (setq head (org-link-display-format head0)
-              m (org-imenu-new-marker))
-        (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
-        (if (>= level last-level)
-            (push (cons head m) (aref subs level))
-          (push (cons head (aref subs (1+ level))) (aref subs level))
-          (cl-loop for i from (1+ level) to n do (aset subs i nil)))
-        (setq last-level level))))
-    (aref subs 1)))
-
-(eval-after-load "imenu"
-  '(progn
-     (add-hook 'imenu-after-jump-hook
-              (lambda ()
-                (when (derived-mode-p 'org-mode)
-                  (org-show-context 'org-goto))))))
-
-(defun org-link-display-format (s)
-  "Replace links in string S with their description.
-If there is no description, use the link target."
-  (save-match-data
-    (replace-regexp-in-string
-     org-bracket-link-analytic-regexp
-     (lambda (m)
-       (if (match-end 5) (match-string 5 m)
-        (concat (match-string 1 m) (match-string 3 m))))
-     s nil t)))
-
-(defun org-toggle-link-display ()
-  "Toggle the literal or descriptive display of links."
-  (interactive)
-  (if org-descriptive-links
-      (progn (org-remove-from-invisibility-spec '(org-link))
-            (org-restart-font-lock)
-            (setq org-descriptive-links nil))
-    (progn (add-to-invisibility-spec '(org-link))
-          (org-restart-font-lock)
-          (setq org-descriptive-links t))))
-
-;; Speedbar support
-
-(defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
-  "Overlay marking the agenda restriction line in speedbar.")
-(overlay-put org-speedbar-restriction-lock-overlay
-            'face 'org-agenda-restriction-lock)
-(overlay-put org-speedbar-restriction-lock-overlay
-            'help-echo "Agendas are currently limited to this item.")
-(delete-overlay org-speedbar-restriction-lock-overlay)
-
-(defun org-speedbar-set-agenda-restriction ()
-  "Restrict future agenda commands to the location at point in speedbar.
-To get rid of the restriction, use `\\[org-agenda-remove-restriction-lock]'."
-  (interactive)
-  (require 'org-agenda)
-  (let (p m tp np dir txt)
-    (cond
-     ((setq p (text-property-any (point-at-bol) (point-at-eol)
-                                'org-imenu t))
-      (setq m (get-text-property p 'org-imenu-marker))
-      (with-current-buffer (marker-buffer m)
-       (goto-char m)
-       (org-agenda-set-restriction-lock 'subtree)))
-     ((setq p (text-property-any (point-at-bol) (point-at-eol)
-                                'speedbar-function 'speedbar-find-file))
-      (setq tp (previous-single-property-change
-               (1+ p) 'speedbar-function)
-           np (next-single-property-change
-               tp 'speedbar-function)
-           dir (speedbar-line-directory)
-           txt (buffer-substring-no-properties (or tp (point-min))
-                                               (or np (point-max))))
-      (with-current-buffer (find-file-noselect
-                           (let ((default-directory dir))
-                             (expand-file-name txt)))
-       (unless (derived-mode-p 'org-mode)
-         (user-error "Cannot restrict to non-Org mode file"))
-       (org-agenda-set-restriction-lock 'file)))
-     (t (user-error "Don't know how to restrict Org mode agenda")))
-    (move-overlay org-speedbar-restriction-lock-overlay
-                 (point-at-bol) (point-at-eol))
-    (setq current-prefix-arg nil)
-    (org-agenda-maybe-redo)))
-
-(defvar speedbar-file-key-map)
-(declare-function speedbar-add-supported-extension "speedbar" (extension))
-(eval-after-load "speedbar"
-  '(progn
-     (speedbar-add-supported-extension ".org")
-     (define-key speedbar-file-key-map "<" 
'org-speedbar-set-agenda-restriction)
-     (define-key speedbar-file-key-map "\C-c\C-x<" 
'org-speedbar-set-agenda-restriction)
-     (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
-     (define-key speedbar-file-key-map "\C-c\C-x>" 
'org-agenda-remove-restriction-lock)
-     (add-hook 'speedbar-visiting-tag-hook
-              (lambda () (and (derived-mode-p 'org-mode) (org-show-context 
'org-goto))))))
-
-;;; Fixes and Hacks for problems with other packages
-
-(defun org--flyspell-object-check-p (element)
-  "Non-nil when Flyspell can check object at point.
-ELEMENT is the element at point."
-  (let ((object (save-excursion
-                 (when (looking-at-p "\\>") (backward-char))
-                 (org-element-context element))))
-    (cl-case (org-element-type object)
-      ;; Prevent checks in links due to keybinding conflict with
-      ;; Flyspell.
-      ((code entity export-snippet inline-babel-call
-            inline-src-block line-break latex-fragment link macro
-            statistics-cookie target timestamp verbatim)
-       nil)
-      (footnote-reference
-       ;; Only in inline footnotes, within the definition.
-       (and (eq (org-element-property :type object) 'inline)
-           (< (save-excursion
-                (goto-char (org-element-property :begin object))
-                (search-forward ":" nil t 2))
-              (point))))
-      (otherwise t))))
-
-(defun org-mode-flyspell-verify ()
-  "Function used for `flyspell-generic-check-word-predicate'."
-  (if (org-at-heading-p)
-      ;; At a headline or an inlinetask, check title only.  This is
-      ;; faster than relying on `org-element-at-point'.
-      (and (save-excursion (beginning-of-line)
-                          (and (let ((case-fold-search t))
-                                 (not (looking-at-p "\\*+ END[ \t]*$")))
-                               (let ((case-fold-search nil))
-                                 (looking-at org-complex-heading-regexp))))
-          (match-beginning 4)
-          (>= (point) (match-beginning 4))
-          (or (not (match-beginning 5))
-              (< (point) (match-beginning 5))))
-    (let* ((element (org-element-at-point))
-          (post-affiliated (org-element-property :post-affiliated element)))
-      (cond
-       ;; Ignore checks in all affiliated keywords but captions.
-       ((< (point) post-affiliated)
-       (and (save-excursion
-              (beginning-of-line)
-              (let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
-            (> (point) (match-end 0))
-            (org--flyspell-object-check-p element)))
-       ;; Ignore checks in LOGBOOK (or equivalent) drawer.
-       ((let ((log (org-log-into-drawer)))
-         (and log
-              (let ((drawer (org-element-lineage element '(drawer))))
-                (and drawer
-                     (eq (compare-strings
-                          log nil nil
-                          (org-element-property :drawer-name drawer) nil nil t)
-                         t)))))
-       nil)
-       (t
-       (cl-case (org-element-type element)
-         ((comment quote-section) t)
-         (comment-block
-          ;; Allow checks between block markers, not on them.
-          (and (> (line-beginning-position) post-affiliated)
-               (save-excursion
-                 (end-of-line)
-                 (skip-chars-forward " \r\t\n")
-                 (< (point) (org-element-property :end element)))))
-         ;; Arbitrary list of keywords where checks are meaningful.
-         ;; Make sure point is on the value part of the element.
-         (keyword
-          (and (member (org-element-property :key element)
-                       '("DESCRIPTION" "TITLE"))
-               (save-excursion
-                 (search-backward ":" (line-beginning-position) t))))
-         ;; Check is globally allowed in paragraphs verse blocks and
-         ;; table rows (after affiliated keywords) but some objects
-         ;; must not be affected.
-         ((paragraph table-row verse-block)
-          (let ((cbeg (org-element-property :contents-begin element))
-                (cend (org-element-property :contents-end element)))
-            (and cbeg (>= (point) cbeg) (< (point) cend)
-                 (org--flyspell-object-check-p element))))))))))
-(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
-
-(defun org-remove-flyspell-overlays-in (beg end)
-  "Remove flyspell overlays in region."
-  (and (bound-and-true-p flyspell-mode)
-       (fboundp 'flyspell-delete-region-overlays)
-       (flyspell-delete-region-overlays beg end)))
-
-(defvar flyspell-delayed-commands)
-(eval-after-load "flyspell"
-  '(add-to-list 'flyspell-delayed-commands 'org-self-insert-command))
-
-;; Make `bookmark-jump' shows the jump location if it was hidden.
-(eval-after-load "bookmark"
-  '(if (boundp 'bookmark-after-jump-hook)
-       ;; We can use the hook
-       (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
-     ;; Hook not available, use advice
-     (defadvice bookmark-jump (after org-make-visible activate)
-       "Make the position visible."
-       (org-bookmark-jump-unhide))))
-
-;; Make sure saveplace shows the location if it was hidden
-(eval-after-load "saveplace"
-  '(defadvice save-place-find-file-hook (after org-make-visible activate)
-     "Make the position visible."
-     (org-bookmark-jump-unhide)))
-
-;; Make sure ecb shows the location if it was hidden
-(eval-after-load "ecb"
-  '(defadvice ecb-method-clicked (after esf/org-show-context activate)
-     "Make hierarchy visible when jumping into location from ECB tree buffer."
-     (when (derived-mode-p 'org-mode)
-       (org-show-context))))
-
-(defun org-bookmark-jump-unhide ()
-  "Unhide the current position, to show the bookmark location."
-  (and (derived-mode-p 'org-mode)
-       (or (org-invisible-p)
-          (save-excursion (goto-char (max (point-min) (1- (point))))
-                          (org-invisible-p)))
-       (org-show-context 'bookmark-jump)))
-
-(defun org-mark-jump-unhide ()
-  "Make the point visible with `org-show-context' after jumping to the mark."
-  (when (and (derived-mode-p 'org-mode)
-            (org-invisible-p))
-    (org-show-context 'mark-goto)))
-
-(eval-after-load "simple"
-  '(defadvice pop-to-mark-command (after org-make-visible activate)
-     "Make the point visible with `org-show-context'."
-     (org-mark-jump-unhide)))
-
-(eval-after-load "simple"
-  '(defadvice exchange-point-and-mark (after org-make-visible activate)
-     "Make the point visible with `org-show-context'."
-     (org-mark-jump-unhide)))
-
-(eval-after-load "simple"
-  '(defadvice pop-global-mark (after org-make-visible activate)
-     "Make the point visible with `org-show-context'."
-     (org-mark-jump-unhide)))
-
-;; Make session.el ignore our circular variable
-(defvar session-globals-exclude)
-(eval-after-load "session"
-  '(add-to-list 'session-globals-exclude 'org-mark-ring))
-
-;;;; Finish up
+(add-hook 'org-mode-hook     ;remove overlays when changing major mode
+         (lambda () (add-hook 'change-major-mode-hook
+                              'org-show-all 'append 'local)))
 
 (provide 'org)
 
diff --git a/lisp/org/ox-ascii.el b/lisp/org/ox-ascii.el
index 7c9920f..6e6c17c 100644
--- a/lisp/org/ox-ascii.el
+++ b/lisp/org/ox-ascii.el
@@ -632,7 +632,7 @@ Return value is a symbol among `left', `center', `right' and
     (or justification 'left)))
 
 (defun org-ascii--build-title
-  (element info text-width &optional underline notags toc)
+    (element info text-width &optional underline notags toc)
   "Format ELEMENT title and return it.
 
 ELEMENT is either an `headline' or `inlinetask' element.  INFO is
@@ -651,13 +651,12 @@ possible.  It doesn't apply to `inlinetask' elements."
   (let* ((headlinep (eq (org-element-type element) 'headline))
         (numbers
          ;; Numbering is specific to headlines.
-         (and headlinep (org-export-numbered-headline-p element info)
-              ;; All tests passed: build numbering string.
-              (concat
-               (mapconcat
-                'number-to-string
-                (org-export-get-headline-number element info) ".")
-               " ")))
+         (and headlinep
+              (org-export-numbered-headline-p element info)
+              (let ((numbering (org-export-get-headline-number element info)))
+                (if toc (format "%d. " (org-last numbering))
+                  (concat (mapconcat #'number-to-string numbering ".")
+                          " ")))))
         (text
          (org-trim
           (org-export-data
@@ -672,8 +671,7 @@ possible.  It doesn't apply to `inlinetask' elements."
                    (plist-get info :with-tags)
                    (let ((tag-list (org-export-get-tags element info)))
                      (and tag-list
-                          (format ":%s:"
-                                  (mapconcat 'identity tag-list ":"))))))
+                          (org-make-tag-string tag-list)))))
         (priority
          (and (plist-get info :with-priority)
               (let ((char (org-element-property :priority element)))
@@ -733,7 +731,7 @@ caption keyword."
                 (org-export-data caption info))
         (org-ascii--current-text-width element info) info)))))
 
-(defun org-ascii--build-toc (info &optional n keyword local)
+(defun org-ascii--build-toc (info &optional n keyword scope)
   "Return a table of contents.
 
 INFO is a plist used as a communication channel.
@@ -744,10 +742,10 @@ depth of the table.
 Optional argument KEYWORD specifies the TOC keyword, if any, from
 which the table of contents generation has been initiated.
 
-When optional argument LOCAL is non-nil, build a table of
-contents according to the current headline."
+When optional argument SCOPE is non-nil, build a table of
+contents according to the specified scope."
   (concat
-   (unless local
+   (unless scope
      (let ((title (org-ascii--translate "Table of Contents" info)))
        (concat title "\n"
               (make-string
@@ -769,7 +767,7 @@ contents according to the current headline."
            (or (not (plist-get info :with-tags))
                (eq (plist-get info :with-tags) 'not-in-toc))
            'toc))))
-      (org-export-collect-headlines info n (and local keyword)) "\n"))))
+      (org-export-collect-headlines info n scope) "\n"))))
 
 (defun org-ascii--list-listings (keyword info)
   "Return a list of listings.
@@ -960,7 +958,7 @@ channel."
        (t
         (concat
          (org-ascii--fill-string
-          (format "[%s] %s" anchor (org-element-property :raw-link link))
+          (format "[%s] <%s>" anchor (org-element-property :raw-link link))
           width info)
          "\n\n")))))
    links ""))
@@ -1518,8 +1516,13 @@ information."
          ((string-match-p "\\<headlines\\>" value)
           (let ((depth (and (string-match "\\<[0-9]+\\>" value)
                             (string-to-number (match-string 0 value))))
-                (localp (string-match-p "\\<local\\>" value)))
-            (org-ascii--build-toc info depth keyword localp)))
+                (scope
+                 (cond
+                  ((string-match ":target +\\(\".+?\"\\|\\S-+\\)" value) ;link
+                   (org-export-resolve-link
+                    (org-strip-quotes (match-string 1 value)) info))
+                  ((string-match-p "\\<local\\>" value) keyword)))) ;local
+            (org-ascii--build-toc info depth keyword scope)))
          ((string-match-p "\\<tables\\>" value)
           (org-ascii--list-tables keyword info))
          ((string-match-p "\\<listings\\>" value)
@@ -1602,11 +1605,13 @@ INFO is a plist holding contextual information."
          ;; Don't know what to do.  Signal it.
          (_ "???"))))
      (t
-      (let ((raw-link (org-element-property :raw-link link)))
-       (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
+      (let ((raw-link (concat (org-element-property :type link)
+                             ":"
+                             (org-element-property :path link))))
+       (if (not (org-string-nw-p desc)) (format "<%s>" raw-link)
          (concat (format "[%s]" desc)
                  (and (not (plist-get info :ascii-links-to-notes))
-                      (format " (%s)" raw-link)))))))))
+                      (format " (<%s>)" raw-link)))))))))
 
 
 ;;;; Node Properties
@@ -2067,6 +2072,20 @@ a communication channel."
 ;;; End-user functions
 
 ;;;###autoload
+(defun org-ascii-convert-region-to-ascii ()
+  "Assume region has Org syntax, and convert it to plain ASCII."
+  (interactive)
+  (let ((org-ascii-charset 'ascii))
+    (org-export-replace-region-by 'ascii)))
+
+;;;###autoload
+(defun org-ascii-convert-region-to-utf8 ()
+  "Assume region has Org syntax, and convert it to UTF-8."
+  (interactive)
+  (let ((org-ascii-charset 'utf-8))
+    (org-export-replace-region-by 'ascii)))
+
+;;;###autoload
 (defun org-ascii-export-as-ascii
   (&optional async subtreep visible-only body-only ext-plist)
   "Export current buffer to a text buffer.
diff --git a/lisp/org/ox-beamer.el b/lisp/org/ox-beamer.el
index 77c1b33..0de5e47 100644
--- a/lisp/org/ox-beamer.el
+++ b/lisp/org/ox-beamer.el
@@ -424,9 +424,8 @@ used as a communication channel."
            (let* ((beamer-opt (org-element-property :BEAMER_OPT headline))
                   (options
                    ;; Collect nonempty options from default value and
-                   ;; headline's properties.  Also add a label for
-                   ;; links.
-                   (cl-remove-if-not 'org-string-nw-p
+                   ;; headline's properties.
+                   (cl-remove-if-not #'org-string-nw-p
                     (append
                      (org-split-string
                       (plist-get info :beamer-frame-default-options) ",")
@@ -436,29 +435,31 @@ used as a communication channel."
                            ;; them.
                            (and (string-match "^\\[?\\(.*\\)\\]?$" beamer-opt)
                                 (match-string 1 beamer-opt))
-                           ","))
-                     ;; Provide an automatic label for the frame
-                     ;; unless the user specified one.  Also refrain
-                     ;; from labeling `allowframebreaks' frames; this
-                     ;; is not allowed by beamer.
-                     (unless (and beamer-opt
-                                  (or (string-match "\\(^\\|,\\)label=" 
beamer-opt)
-                                      (string-match "allowframebreaks" 
beamer-opt)))
-                       (list
-                        (let ((label (org-beamer--get-label headline info)))
-                          ;; Labels containing colons need to be
-                          ;; wrapped within braces.
-                          (format (if (string-match-p ":" label)
-                                      "label={%s}"
-                                    "label=%s")
-                                  label))))))))
+                           ",")))))
+                  (fragile
+                   ;; Add "fragile" option if necessary.
+                   (and fragilep
+                        (not (member "fragile" options))
+                        (list "fragile")))
+                  (label
+                   ;; Provide an automatic label for the frame unless
+                   ;; the user specified one.  Also refrain from
+                   ;; labeling `allowframebreaks' frames; this is not
+                   ;; allowed by Beamer.
+                   (and (not (member "allowframebreaks" options))
+                        (not (cl-some (lambda (s) (string-match-p "^label=" s))
+                                      options))
+                        (list
+                         (let ((label (org-beamer--get-label headline info)))
+                           ;; Labels containing colons need to be
+                           ;; wrapped within braces.
+                           (format (if (string-match-p ":" label)
+                                       "label={%s}"
+                                     "label=%s")
+                                   label))))))
              ;; Change options list into a string.
              (org-beamer--normalize-argument
-              (mapconcat
-               'identity
-               (if (or (not fragilep) (member "fragile" options)) options
-                 (cons "fragile" options))
-               ",")
+              (mapconcat #'identity (append label fragile options) ",")
               'option))
            ;; Title.
            (let ((env (org-element-property :BEAMER_ENV headline)))
@@ -644,13 +645,22 @@ as a communication channel."
                contents))
        ;; Case 4: HEADLINE is a note.
        ((member environment '("note" "noteNH"))
-       (format "\\note{%s}"
-               (concat (and (equal environment "note")
-                            (concat
-                             (org-export-data
-                              (org-element-property :title headline) info)
-                             "\n"))
-                       (org-trim contents))))
+        (concat "\\note"
+               ;; Overlay specification.
+               (let ((overlay (org-element-property :BEAMER_ACT headline)))
+                 (when overlay
+                   (org-beamer--normalize-argument
+                    overlay
+                    (if (string-match "\\`\\[.*\\]\\'" overlay)
+                        'defaction 'action))))
+               (format "{%s}"
+                        (concat (and (equal environment "note")
+                                     (concat
+                                      (org-export-data
+                                       (org-element-property :title headline)
+                                      info)
+                                      "\n"))
+                               (org-trim contents)))))
        ;; Case 5: HEADLINE is a frame.
        ((= level frame-level)
        (org-beamer--format-frame headline contents info))
@@ -914,9 +924,9 @@ value."
       (org-back-to-heading t)
       ;; Filter out Beamer-related tags and install environment tag.
       (let ((tags (cl-remove-if (lambda (x) (string-match "^B_" x))
-                                (org-get-tags)))
+                               (org-get-tags nil t)))
            (env-tag (and (org-string-nw-p value) (concat "B_" value))))
-       (org-set-tags-to (if env-tag (cons env-tag tags) tags))
+       (org-set-tags (if env-tag (cons env-tag tags) tags))
        (when env-tag (org-toggle-tag env-tag 'on)))))
    ((equal property "BEAMER_col")
     (org-toggle-tag "BMCOL" (if (org-string-nw-p value) 'on 'off)))))
@@ -1075,12 +1085,12 @@ aid, but the tag does not have any semantic meaning."
         (org-tag-persistent-alist nil)
         (org-use-fast-tag-selection t)
         (org-fast-tag-selection-single-key t))
-    (org-set-tags)
-    (let ((tags (or (ignore-errors (org-get-tags-string)) "")))
+    (org-set-tags-command)
+    (let ((tags (org-get-tags nil t)))
       (cond
        ;; For a column, automatically ask for its width.
        ((eq org-last-tag-selection-key ?|)
-       (if (string-match ":BMCOL:" tags)
+       (if (member "BMCOL" tags)
            (org-set-property "BEAMER_col" (read-string "Column width: "))
          (org-delete-property "BEAMER_col")))
        ;; For an "againframe" section, automatically ask for reference
@@ -1096,8 +1106,12 @@ aid, but the tag does not have any semantic meaning."
           (read-string "Frame reference (*Title, #custom-id, id:...): "))
          (org-set-property "BEAMER_act"
                            (read-string "Overlay specification: "))))
-       ((string-match (concat ":B_\\(" (mapconcat 'car envs "\\|") "\\):") 
tags)
-       (org-entry-put nil "BEAMER_env" (match-string 1 tags)))
+       ((let* ((tags-re (concat "B_" (regexp-opt (mapcar #'car envs) t)))
+              (env (cl-some (lambda (tag)
+                              (and (string-match tags-re tag)
+                                   (match-string 1 tag)))
+                            tags)))
+         (and env (progn (org-entry-put nil "BEAMER_env" env) t))))
        (t (org-entry-delete nil "BEAMER_env"))))))
 
 ;;;###autoload
diff --git a/lisp/org/ox-html.el b/lisp/org/ox-html.el
index 8445f23..83d0fd2 100644
--- a/lisp/org/ox-html.el
+++ b/lisp/org/ox-html.el
@@ -152,6 +152,7 @@
     (:html-metadata-timestamp-format nil nil 
org-html-metadata-timestamp-format)
     (:html-postamble-format nil nil org-html-postamble-format)
     (:html-preamble-format nil nil org-html-preamble-format)
+    (:html-self-link-headlines nil nil org-html-self-link-headlines)
     (:html-table-align-individual-fields
      nil nil org-html-table-align-individual-fields)
     (:html-table-caption-above nil nil org-html-table-caption-above)
@@ -171,6 +172,7 @@
     (:html-table-row-open-tag nil nil org-html-table-row-open-tag)
     (:html-table-row-close-tag nil nil org-html-table-row-close-tag)
     (:html-xml-declaration nil nil org-html-xml-declaration)
+    (:html-wrap-src-lines nil nil org-html-wrap-src-lines)
     (:html-klipsify-src nil nil org-html-klipsify-src)
     (:html-klipse-css nil nil org-html-klipse-css)
     (:html-klipse-js nil nil org-html-klipse-js)
@@ -215,7 +217,7 @@
 (defconst org-html-html5-elements
   '("article" "aside" "audio" "canvas" "details" "figcaption"
     "figure" "footer" "header" "menu" "meter" "nav" "output"
-    "progress" "section" "video")
+    "progress" "section" "summary" "video")
   "New elements in html5.
 
 For blocks that should contain headlines, use the HTML_CONTAINER
@@ -430,6 +432,19 @@ for the JavaScript code in this tag.
   .footdef  { margin-bottom: 1em; }
   .figure { padding: 1em; }
   .figure p { text-align: center; }
+  .equation-container {
+    display: table;
+    text-align: center;
+    width: 100%;
+  }
+  .equation {
+    vertical-align: middle;
+  }
+  .equation-label {
+    display: table-cell;
+    text-align: right;
+    vertical-align: middle;
+  }
   .inlinetask {
     padding: 10px;
     border: 2px solid gray;
@@ -789,6 +804,13 @@ but without \"name\" attribute."
   :package-version '(Org . "8.0")
   :type 'boolean)
 
+(defcustom org-html-self-link-headlines nil
+  "When non-nil, the headlines contain a hyperlink to themselves."
+  :group 'org-export-html
+  :package-version '(Org . "9.3")
+  :type 'boolean
+  :safe #'booleanp)
+
 ;;;; Inlinetasks
 
 (defcustom org-html-format-inlinetask-function
@@ -863,6 +885,7 @@ link to the image."
 
 (defcustom org-html-inline-image-rules
   '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
+    ("attachment" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
     ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
     ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
   "Rules characterizing image files that can be inlined into HTML.
@@ -910,6 +933,15 @@ in all modes you want.  Then, use the command
   :group 'org-export-html
   :type 'string)
 
+(defcustom org-html-wrap-src-lines nil
+  "If non-nil, wrap individual lines of source blocks in \"code\" elements.
+In this case, add line number in attribute \"data-ox-html-linenr\" when line
+numbers are enabled."
+  :group 'org-export-html
+  :package-version '(Org . "9.3")
+  :type 'boolean
+  :safe t)
+
 ;;;; Table
 
 (defcustom org-html-table-default-attributes
@@ -1693,7 +1725,7 @@ object unless a different class is specified with an 
attribute."
 
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
-ELEMENT is either a src block or an example block."
+ELEMENT is either a source or an example block."
   (let* ((code (car (org-export-unravel-code element)))
         (attr (org-export-read-attribute :attr_html element)))
     (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
@@ -1736,8 +1768,8 @@ If you then set `org-html-htmlize-output-type' to `css', 
calls
 to the function `org-html-htmlize-region-for-paste' will
 produce code that uses these same face definitions."
   (interactive)
-  (or (require 'htmlize nil t)
-      (error "Please install htmlize from 
https://github.com/hniksic/emacs-htmlize";))
+  (unless (require 'htmlize nil t)
+    (error "htmlize library missing.  Aborting"))
   (and (get-buffer "*html*") (kill-buffer "*html*"))
   (with-temp-buffer
     (let ((fl (face-list))
@@ -1751,12 +1783,12 @@ produce code that uses these same face definitions."
       (htmlize-region (point-min) (point-max))))
   (pop-to-buffer-same-window "*html*")
   (goto-char (point-min))
-  (if (re-search-forward "<style" nil t)
-      (delete-region (point-min) (match-beginning 0)))
-  (if (re-search-forward "</style>" nil t)
-      (delete-region (1+ (match-end 0)) (point-max)))
+  (when (re-search-forward "<style" nil t)
+    (delete-region (point-min) (match-beginning 0)))
+  (when (re-search-forward "</style>" nil t)
+    (delete-region (1+ (match-end 0)) (point-max)))
   (beginning-of-line 1)
-  (if (looking-at " +") (replace-match ""))
+  (when (looking-at " +") (replace-match ""))
   (goto-char (point-min)))
 
 (defun org-html--make-string (n string)
@@ -1771,33 +1803,38 @@ Replaces invalid characters with \"_\"."
 (defun org-html-footnote-section (info)
   "Format the footnote section.
 INFO is a plist used as a communication channel."
-  (let* ((fn-alist (org-export-collect-footnote-definitions info))
-        (fn-alist
-         (cl-loop for (n _type raw) in fn-alist collect
-                  (cons n (if (eq (org-element-type raw) 'org-data)
-                              (org-trim (org-export-data raw info))
-                            (format "<div class=\"footpara\">%s</div>"
-                                    (org-trim (org-export-data raw info))))))))
-    (when fn-alist
+  (pcase (org-export-collect-footnote-definitions info)
+    (`nil nil)
+    (definitions
       (format
        (plist-get info :html-footnotes-section)
        (org-html--translate "Footnotes" info)
        (format
        "\n%s\n"
        (mapconcat
-        (lambda (fn)
-          (let ((n (car fn)) (def (cdr fn)))
-            (format
-             "<div class=\"footdef\">%s %s</div>\n"
-             (format
-              (plist-get info :html-footnote-format)
-              (org-html--anchor
-               (format "fn.%d" n)
-               n
-               (format " class=\"footnum\" href=\"#fnr.%d\"" n)
-               info))
-             def)))
-        fn-alist
+        (lambda (definition)
+          (pcase definition
+            (`(,n ,_ ,def)
+             ;; `org-export-collect-footnote-definitions' can return
+             ;; two kinds of footnote definitions: inline and blocks.
+             ;; Since this should not make any difference in the HTML
+             ;; output, we wrap the inline definitions within
+             ;; a "footpara" class paragraph.
+             (let ((inline? (not (org-element-map def org-element-all-elements
+                                   #'identity nil t)))
+                   (anchor (org-html--anchor
+                            (format "fn.%d" n)
+                            n
+                            (format " class=\"footnum\" href=\"#fnr.%d\"" n)
+                            info))
+                   (contents (org-trim (org-export-data def info))))
+               (format "<div class=\"footdef\">%s %s</div>\n"
+                       (format (plist-get info :html-footnote-format) anchor)
+                       (format "<div class=\"footpara\">%s</div>"
+                               (if (not inline?) contents
+                                 (format "<p class=\"footpara\">%s</p>"
+                                         contents))))))))
+        definitions
         "\n"))))))
 
 
@@ -1957,44 +1994,42 @@ communication channel."
                       (creator (cdr (assq ?c spec)))
                       (validation-link (cdr (assq ?v spec))))
                   (concat
-                   (when (and (plist-get info :with-date)
-                              (org-string-nw-p date))
-                     (format "<p class=\"date\">%s: %s</p>\n"
-                             (org-html--translate "Date" info)
-                             date))
-                   (when (and (plist-get info :with-author)
-                              (org-string-nw-p author))
-                     (format "<p class=\"author\">%s: %s</p>\n"
-                             (org-html--translate "Author" info)
-                             author))
-                   (when (and (plist-get info :with-email)
-                              (org-string-nw-p email))
-                     (format "<p class=\"email\">%s: %s</p>\n"
-                             (org-html--translate "Email" info)
-                             email))
-                   (when (plist-get info :time-stamp-file)
-                     (format
-                      "<p class=\"date\">%s: %s</p>\n"
-                      (org-html--translate "Created" info)
-                      (format-time-string
-                       (plist-get info :html-metadata-timestamp-format))))
-                   (when (plist-get info :with-creator)
-                     (format "<p class=\"creator\">%s</p>\n" creator))
-                   (format "<p class=\"validation\">%s</p>\n"
-                           validation-link))))
-               (t (format-spec
-                   (or (cadr (assoc-string
-                              (plist-get info :language)
-                              (eval (intern
-                                     (format "org-html-%s-format" type)))
-                              t))
-                       (cadr
-                        (assoc-string
-                         "en"
-                         (eval
-                          (intern (format "org-html-%s-format" type)))
-                         t)))
-                   spec))))))
+                   (and (plist-get info :with-date)
+                        (org-string-nw-p date)
+                        (format "<p class=\"date\">%s: %s</p>\n"
+                                (org-html--translate "Date" info)
+                                date))
+                   (and (plist-get info :with-author)
+                        (org-string-nw-p author)
+                        (format "<p class=\"author\">%s: %s</p>\n"
+                                (org-html--translate "Author" info)
+                                author))
+                   (and (plist-get info :with-email)
+                        (org-string-nw-p email)
+                        (format "<p class=\"email\">%s: %s</p>\n"
+                                (org-html--translate "Email" info)
+                                email))
+                   (and (plist-get info :time-stamp-file)
+                        (format
+                         "<p class=\"date\">%s: %s</p>\n"
+                         (org-html--translate "Created" info)
+                         (format-time-string
+                          (plist-get info :html-metadata-timestamp-format))))
+                   (and (plist-get info :with-creator)
+                        (org-string-nw-p creator)
+                        (format "<p class=\"creator\">%s</p>\n" creator))
+                   (and (org-string-nw-p validation-link)
+                        (format "<p class=\"validation\">%s</p>\n"
+                                validation-link)))))
+               (t
+                (let ((formats (plist-get info (if (eq type 'preamble)
+                                                   :html-preamble-format
+                                                 :html-postamble-format)))
+                      (language (plist-get info :language)))
+                  (format-spec
+                   (cadr (or (assoc-string language formats t)
+                             (assoc-string "en" formats t)))
+                   spec)))))))
        (let ((div (assq type (plist-get info :html-divs))))
          (when (org-string-nw-p section-contents)
            (concat
@@ -2089,12 +2124,12 @@ holding export options."
    ;; Postamble.
    (org-html--build-pre/postamble 'postamble info)
    ;; Possibly use the Klipse library live code blocks.
-   (if (plist-get info :html-klipsify-src)
-       (concat "<script>" (plist-get info :html-klipse-selection-script)
-              "</script><script src=\""
-              org-html-klipse-js
-              "\"></script><link rel=\"stylesheet\" type=\"text/css\" href=\""
-              org-html-klipse-css "\"/>"))
+   (when (plist-get info :html-klipsify-src)
+     (concat "<script>" (plist-get info :html-klipse-selection-script)
+            "</script><script src=\""
+            org-html-klipse-js
+            "\"></script><link rel=\"stylesheet\" type=\"text/css\" href=\""
+            org-html-klipse-css "\"/>"))
    ;; Closing document.
    "</body>\n</html>"))
 
@@ -2160,12 +2195,10 @@ is the language used for CODE, as a string, or nil."
      ;; Plain text explicitly set.
      ((not org-html-htmlize-output-type) (org-html-encode-plain-text code))
      ;; No htmlize library or an inferior version of htmlize.
-     ((not (and (or (require 'htmlize nil t)
-                   (error "Please install htmlize from \
-https://github.com/hniksic/emacs-htmlize";))
-               (fboundp 'htmlize-region-for-paste)))
+     ((not (progn (require 'htmlize nil t)
+                 (fboundp 'htmlize-region-for-paste)))
       ;; Emit a warning.
-      (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
+      (message "Cannot fontify source block (htmlize.el >= 1.34 required)")
       (org-html-encode-plain-text code))
      (t
       ;; Map language
@@ -2208,14 +2241,15 @@ https://github.com/hniksic/emacs-htmlize";))
            (if (and beg end) (substring code beg end) code)))))))))
 
 (defun org-html-do-format-code
-  (code &optional lang refs retain-labels num-start)
+  (code &optional lang refs retain-labels num-start wrap-lines)
   "Format CODE string as source code.
-Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
-respectively, the language of the source code, as a string, an
+Optional arguments LANG, REFS, RETAIN-LABELS, NUM-START, WRAP-LINES
+are, respectively, the language of the source code, as a string, an
 alist between line numbers and references (as returned by
 `org-export-unravel-code'), a boolean specifying if labels should
-appear in the source code, and the number associated to the first
-line of code."
+appear in the source code, the number associated to the first
+line of code, and a boolean specifying if lines of code should be
+wrapped in code elements."
   (let* ((code-lines (split-string code "\n"))
         (code-length (length code-lines))
         (num-fmt
@@ -2233,7 +2267,13 @@ line of code."
                (format "<span class=\"linenr\">%s</span>"
                        (format num-fmt line-num)))
              ;; Transcoded src line.
-             loc
+             (if wrap-lines
+                 (format "<code%s>%s</code>"
+                         (if num-start
+                              (format " data-ox-html-linenr=\"%s\"" line-num)
+                            "")
+                         loc)
+               loc)
              ;; Add label, if needed.
              (when (and ref retain-labels) (format " (%s)" ref))))
        ;; Mark transcoded line as an anchor, if needed.
@@ -2244,18 +2284,20 @@ line of code."
 
 (defun org-html-format-code (element info)
   "Format contents of ELEMENT as source code.
-ELEMENT is either an example block or a src block.  INFO is
-a plist used as a communication channel."
+ELEMENT is either an example or a source block.  INFO is a plist
+used as a communication channel."
   (let* ((lang (org-element-property :language element))
         ;; Extract code and references.
         (code-info (org-export-unravel-code element))
         (code (car code-info))
         (refs (cdr code-info))
-        ;; Does the src block contain labels?
+        ;; Does the source block contain labels?
         (retain-labels (org-element-property :retain-labels element))
         ;; Does it have line numbers?
-        (num-start (org-export-get-loc element info)))
-    (org-html-do-format-code code lang refs retain-labels num-start)))
+        (num-start (org-export-get-loc element info))
+        ;; Should lines be wrapped in code elements?
+        (wrap-lines (plist-get info :html-wrap-src-lines)))
+    (org-html-do-format-code code lang refs retain-labels num-start 
wrap-lines)))
 
 
 ;;; Tables of Contents
@@ -2580,18 +2622,12 @@ holding contextual information."
            (full-text (funcall (plist-get info :html-format-headline-function)
                                todo todo-type priority text tags info))
            (contents (or contents ""))
-          (ids (delq nil
-                      (list (org-element-property :CUSTOM_ID headline)
-                            (org-export-get-reference headline info)
-                            (org-element-property :ID headline))))
-           (preferred-id (car ids))
-           (extra-ids
-           (mapconcat
-            (lambda (id)
-              (org-html--anchor
-               (if (org-uuidgen-p id) (concat "ID-" id) id)
-               nil nil info))
-            (cdr ids) "")))
+          (id (or (org-element-property :CUSTOM_ID headline)
+                  (org-export-get-reference headline info)))
+          (formatted-text
+           (if (plist-get info :html-self-link-headlines)
+               (format "<a href=\"#%s\">%s</a>" id full-text)
+             full-text)))
       (if (org-export-low-level-p headline info)
           ;; This is a deep sub-tree: export it as a list item.
           (let* ((html-type (if numberedp "ol" "ul")))
@@ -2600,15 +2636,16 @@ holding contextual information."
                  (apply #'format "<%s class=\"org-%s\">\n"
                         (make-list 2 html-type)))
             (org-html-format-list-item
-                   contents (if numberedp 'ordered 'unordered)
-                  nil info nil
-                   (concat (org-html--anchor preferred-id nil nil info)
-                           extra-ids
-                           full-text)) "\n"
+             contents (if numberedp 'ordered 'unordered)
+             nil info nil
+             (concat (org-html--anchor id nil nil info) formatted-text)) "\n"
             (and (org-export-last-sibling-p headline info)
                  (format "</%s>\n" html-type))))
        ;; Standard headline.  Export it as a section.
-        (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS 
headline))
+        (let ((extra-class
+              (org-element-property :HTML_CONTAINER_CLASS headline))
+             (headline-class
+              (org-element-property :HTML_HEADLINE_CLASS headline))
               (first-content (car (org-element-contents headline))))
           (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
                   (org-html--container headline info)
@@ -2617,17 +2654,18 @@ holding contextual information."
                   (concat (format "outline-%d" level)
                           (and extra-class " ")
                           extra-class)
-                  (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
+                  (format "\n<h%d id=\"%s\"%s>%s</h%d>\n"
                           level
-                          preferred-id
-                          extra-ids
+                          id
+                         (if (not headline-class) ""
+                           (format " class=\"%s\"" headline-class))
                           (concat
                            (and numberedp
                                 (format
                                  "<span class=\"section-number-%d\">%s</span> "
                                  level
                                  (mapconcat #'number-to-string numbers ".")))
-                           full-text)
+                           formatted-text)
                           level)
                   ;; When there is no section, pretend there is an
                   ;; empty one to get the correct <div
@@ -2795,8 +2833,13 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
         ((string-match "\\<headlines\\>" value)
          (let ((depth (and (string-match "\\<[0-9]+\\>" value)
                            (string-to-number (match-string 0 value))))
-               (localp (string-match-p "\\<local\\>" value)))
-           (org-html-toc depth info (and localp keyword))))
+               (scope
+                (cond
+                 ((string-match ":target +\\(\".+?\"\\|\\S-+\\)" value) ;link
+                  (org-export-resolve-link
+                   (org-strip-quotes (match-string 1 value)) info))
+                 ((string-match-p "\\<local\\>" value) keyword)))) ;local
+           (org-html-toc depth info scope)))
         ((string= "listings" value) (org-html-list-of-listings info))
         ((string= "tables" value) (org-html-list-of-tables info))))))))
 
@@ -2837,26 +2880,73 @@ INFO is a plist containing export properties."
                        "Creating LaTeX Image..." nil processing-type)
       (buffer-string))))
 
+(defun org-html--wrap-latex-environment (contents _ &optional caption label)
+  "Wrap CONTENTS string within appropriate environment for equations.
+When optional arguments CAPTION and LABEL are given, use them for
+caption and \"id\" attribute."
+  (format "\n<div%s class=\"equation-container\">\n%s%s\n</div>"
+          ;; ID.
+          (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
+          ;; Contents.
+          (format "<span class=\"equation\">\n%s\n</span>" contents)
+          ;; Caption.
+          (if (not (org-string-nw-p caption)) ""
+            (format "\n<span class=\"equation-label\">\n%s\n</span>"
+                    caption))))
+
+(defun org-html--math-environment-p (element &optional _)
+  "Non-nil when ELEMENT is a LaTeX math environment.
+Math environments match the regular expression defined in
+`org-latex-math-environments-re'.  This function is meant to be
+used as a predicate for `org-export-get-ordinal' or a value to
+`org-html-standalone-image-predicate'."
+  (string-match-p org-latex-math-environments-re
+                  (org-element-property :value element)))
+
+(defun org-html--unlabel-latex-environment (latex-frag)
+  "Change environment in LATEX-FRAG string to an unnumbered one.
+For instance, change an 'equation' environment to 'equation*'."
+  (replace-regexp-in-string
+   "\\`[ \t]*\\\\begin{\\([^*]+?\\)}"
+   "\\1*"
+   (replace-regexp-in-string "^[ \t]*\\\\end{\\([^*]+?\\)}[ \r\t\n]*\\'"
+                            "\\1*"
+                            latex-frag nil nil 1)
+   nil nil 1))
+
 (defun org-html-latex-environment (latex-environment _contents info)
   "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
   (let ((processing-type (plist-get info :with-latex))
        (latex-frag (org-remove-indentation
                     (org-element-property :value latex-environment)))
-       (attributes (org-export-read-attribute :attr_html latex-environment)))
+        (attributes (org-export-read-attribute :attr_html latex-environment))
+        (label (and (org-element-property :name latex-environment)
+                    (org-export-get-reference latex-environment info)))
+        (caption (number-to-string
+                  (org-export-get-ordinal
+                   latex-environment info nil
+                   #'org-html--math-environment-p))))
     (cond
      ((memq processing-type '(t mathjax))
-      (org-html-format-latex latex-frag 'mathjax info))
+      (org-html-format-latex
+       (if (org-string-nw-p label)
+          (replace-regexp-in-string "\\`.*"
+                                    (format "\\&\n\\\\label{%s}" label)
+                                    latex-frag)
+        latex-frag)
+       'mathjax info))
      ((assq processing-type org-preview-latex-process-alist)
       (let ((formula-link
-            (org-html-format-latex latex-frag processing-type info)))
-       (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
-         ;; Do not provide a caption or a name to be consistent with
-         ;; `mathjax' handling.
-         (org-html--wrap-image
-          (org-html--format-image
-           (match-string 1 formula-link) attributes info) info))))
-     (t latex-frag))))
+             (org-html-format-latex
+              (org-html--unlabel-latex-environment latex-frag)
+              processing-type info)))
+        (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
+          (org-html--wrap-latex-environment
+           (org-html--format-image
+            (match-string 1 formula-link) attributes info)
+           info caption label))))
+     (t (org-html--wrap-latex-environment latex-frag info caption label)))))
 
 ;;;; Latex Fragment
 
@@ -2972,7 +3062,7 @@ INFO is a plist holding contextual information.  See
         (path
          (cond
           ((member type '("http" "https" "ftp" "mailto" "news"))
-           (url-encode-url (org-link-unescape (concat type ":" raw-path))))
+           (url-encode-url (concat type ":" raw-path)))
           ((string= type "file")
            ;; During publishing, turn absolute file names belonging
            ;; to base directory into relative file names.  Otherwise,
@@ -2994,30 +3084,31 @@ INFO is a plist holding contextual information.  See
            ;; relative to a custom-id, a headline title, a name or
            ;; a target.
            (let ((option (org-element-property :search-option link)))
-             (cond ((not option) raw-path)
-                   ;; Since HTML back-end use custom-id value as-is,
-                   ;; resolving is them is trivial.
-                   ((eq (string-to-char option) ?#) (concat raw-path option))
-                   (t
-                    (concat raw-path
-                            "#"
-                            (org-publish-resolve-external-link
-                             option
-                             (org-element-property :path link)))))))
+             (if (not option) raw-path
+               (let ((path (org-element-property :path link)))
+                 (concat raw-path
+                         "#"
+                         (org-publish-resolve-external-link option path t))))))
           (t raw-path)))
-        ;; Extract attributes from parent's paragraph.  HACK: Only do
-        ;; this for the first link in parent (inner image link for
-        ;; inline images).  This is needed as long as attributes
-        ;; cannot be set on a per link basis.
         (attributes-plist
-         (let* ((parent (org-export-get-parent-element link))
-                (link (let ((container (org-export-get-parent link)))
-                        (if (and (eq (org-element-type container) 'link)
-                                 (org-html-inline-image-p link info))
-                            container
-                          link))))
-           (and (eq (org-element-map parent 'link 'identity info t) link)
-                (org-export-read-attribute :attr_html parent))))
+         (org-combine-plists
+          ;; Extract attributes from parent's paragraph.  HACK: Only
+          ;; do this for the first link in parent (inner image link
+          ;; for inline images).  This is needed as long as
+          ;; attributes cannot be set on a per link basis.
+          (let* ((parent (org-export-get-parent-element link))
+                 (link (let ((container (org-export-get-parent link)))
+                         (if (and (eq 'link (org-element-type container))
+                                  (org-html-inline-image-p link info))
+                             container
+                           link))))
+            (and (eq link (org-element-map parent 'link #'identity info t))
+                 (org-export-read-attribute :attr_html parent)))
+          ;; Also add attributes from link itself.  Currently, those
+          ;; need to be added programmatically before `org-html-link'
+          ;; is invoked, for example, by backends building upon HTML
+          ;; export.
+          (org-export-read-attribute :attr_html link)))
         (attributes
          (let ((attr (org-html--make-attribute-string attributes-plist)))
            (if (org-string-nw-p attr) (concat " " attr) ""))))
@@ -3081,23 +3172,37 @@ INFO is a plist holding contextual information.  See
             (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
          ;; Fuzzy link points to a target or an element.
          (_
-          (let* ((ref (org-export-get-reference destination info))
-                 (org-html-standalone-image-predicate
-                  #'org-html--has-caption-p)
-                 (number (cond
-                          (desc nil)
-                          ((org-html-standalone-image-p destination info)
-                           (org-export-get-ordinal
-                            (org-element-map destination 'link
-                              #'identity info t)
-                            info 'link 'org-html-standalone-image-p))
-                          (t (org-export-get-ordinal
-                              destination info nil 'org-html--has-caption-p))))
-                 (desc (cond (desc)
-                             ((not number) "No description for this link")
-                             ((numberp number) (number-to-string number))
-                             (t (mapconcat #'number-to-string number ".")))))
-            (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc))))))
+           (if (and destination
+                    (memq (plist-get info :with-latex) '(mathjax t))
+                    (eq 'latex-environment (org-element-type destination))
+                    (eq 'math (org-latex--environment-type destination)))
+               ;; Caption and labels are introduced within LaTeX
+              ;; environment.  Use "eqref" macro to refer to those in
+              ;; the document.
+               (format "\\eqref{%s}"
+                       (org-export-get-reference destination info))
+             (let* ((ref (org-export-get-reference destination info))
+                    (org-html-standalone-image-predicate
+                     #'org-html--has-caption-p)
+                    (counter-predicate
+                     (if (eq 'latex-environment (org-element-type destination))
+                         #'org-html--math-environment-p
+                       #'org-html--has-caption-p))
+                    (number
+                    (cond
+                     (desc nil)
+                     ((org-html-standalone-image-p destination info)
+                      (org-export-get-ordinal
+                       (org-element-map destination 'link #'identity info t)
+                       info 'link 'org-html-standalone-image-p))
+                     (t (org-export-get-ordinal
+                         destination info nil counter-predicate))))
+                    (desc
+                    (cond (desc)
+                          ((not number) "No description for this link")
+                          ((numberp number) (number-to-string number))
+                          (t (mapconcat #'number-to-string number ".")))))
+               (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc)))))))
      ;; Coderef: replace link with the reference name or the
      ;; equivalent line number.
      ((string= type "coderef")
@@ -3111,18 +3216,18 @@ INFO is a plist holding contextual information.  See
                (format (org-export-get-coderef-format path desc)
                        (org-export-resolve-coderef path info)))))
      ;; External link with a description part.
-     ((and path desc) (format "<a href=\"%s\"%s>%s</a>"
-                             (org-html-encode-plain-text path)
-                             attributes
-                             desc))
+     ((and path desc)
+      (format "<a href=\"%s\"%s>%s</a>"
+             (org-html-encode-plain-text path)
+             attributes
+             desc))
      ;; External link without a description part.
-     (path (let ((path (org-html-encode-plain-text path)))
-            (format "<a href=\"%s\"%s>%s</a>"
-                    path
-                    attributes
-                    (org-link-unescape path))))
+     (path
+      (let ((path (org-html-encode-plain-text path)))
+       (format "<a href=\"%s\"%s>%s</a>" path attributes path)))
      ;; No path, only description.  Try to do something useful.
-     (t (format "<i>%s</i>" desc)))))
+     (t
+      (format "<i>%s</i>" desc)))))
 
 ;;;; Node Property
 
@@ -3665,8 +3770,8 @@ contextual information."
   (with-temp-buffer
     (insert contents)
     (set-auto-mode t)
-    (if (plist-get info :html-indent)
-       (indent-region (point-min) (point-max)))
+    (when (plist-get info :html-indent)
+      (indent-region (point-min) (point-max)))
     (buffer-substring-no-properties (point-min) (point-max))))
 
 
diff --git a/lisp/org/ox-icalendar.el b/lisp/org/ox-icalendar.el
index f66e100..15c572d 100644
--- a/lisp/org/ox-icalendar.el
+++ b/lisp/org/ox-icalendar.el
@@ -33,7 +33,7 @@
 
 (require 'cl-lib)
 (require 'ox-ascii)
-(declare-function org-bbdb-anniv-export-ical "org-bbdb" nil)
+(declare-function org-bbdb-anniv-export-ical "ol-bbdb" nil)
 
 
 
@@ -87,37 +87,66 @@ keyword."
 
 This is a list with possibly several symbols in it.  Valid symbols are:
 
-`event-if-todo'       Deadlines in TODO entries become calendar events.
-`event-if-not-todo'   Deadlines in non-TODO entries become calendar events.
-`todo-due'            Use deadlines in TODO entries as due-dates."
+`event-if-todo'
+
+  Deadlines in TODO entries become calendar events.
+
+`event-if-todo-not-done'
+
+  Deadlines in TODO entries with not-DONE state become events.
+
+`event-if-not-todo'
+
+  Deadlines in non-TODO entries become calendar events.
+
+`todo-due'
+
+  Use deadlines in TODO entries as due-dates."
   :group 'org-export-icalendar
-  :type '(set :greedy t
-             (const :tag "Deadlines in non-TODO entries become events"
-                    event-if-not-todo)
-             (const :tag "Deadline in TODO entries become events"
-                    event-if-todo)
-             (const :tag "Deadlines in TODO entries become due-dates"
-                    todo-due)))
+  :type
+  '(set :greedy t
+       (const :tag "DEADLINE in non-TODO entries become events"
+              event-if-not-todo)
+       (const :tag "DEADLINE in TODO entries become events"
+              event-if-todo)
+       (const :tag "DEADLINE in TODO entries with not-DONE state become events"
+              event-if-todo-not-done)
+       (const :tag "DEADLINE in TODO entries become due-dates"
+              todo-due)))
 
 (defcustom org-icalendar-use-scheduled '(todo-start)
   "Contexts where iCalendar export should use a scheduling time stamp.
 
 This is a list with possibly several symbols in it.  Valid symbols are:
 
-`event-if-todo'       Scheduling time stamps in TODO entries become an event.
-`event-if-not-todo'   Scheduling time stamps in non-TODO entries become an 
event.
-`todo-start'          Scheduling time stamps in TODO entries become start date.
-                      Some calendar applications show TODO entries only after
-                      that date."
+`event-if-todo'
+
+  Scheduling time stamps in TODO entries become an event.
+
+`event-if-todo-not-done'
+
+  Scheduling time stamps in TODO entries with not-DONE state
+  become events.
+
+`event-if-not-todo'
+
+  Scheduling time stamps in non-TODO entries become an event.
+
+`todo-start'
+
+  Scheduling time stamps in TODO entries become start date.  Some
+  calendar applications show TODO entries only after that date."
   :group 'org-export-icalendar
-  :type '(set :greedy t
-             (const :tag
-                    "SCHEDULED timestamps in non-TODO entries become events"
-                    event-if-not-todo)
-             (const :tag "SCHEDULED timestamps in TODO entries become events"
-                    event-if-todo)
-             (const :tag "SCHEDULED in TODO entries become start date"
-                    todo-start)))
+  :type
+  '(set :greedy t
+       (const :tag "SCHEDULED timestamps in non-TODO entries become events"
+              event-if-not-todo)
+       (const :tag "SCHEDULED timestamps in TODO entries become events"
+              event-if-todo)
+       (const :tag "SCHEDULED in TODO entries with not-DONE state become 
events"
+              event-if-todo-not-done)
+       (const :tag "SCHEDULED in TODO entries become start date"
+              todo-start)))
 
 (defcustom org-icalendar-categories '(local-tags category)
   "Items that should be entered into the \"categories\" field.
@@ -317,7 +346,7 @@ A headline is blocked when either
     done first or is a child of a blocked grandparent entry."
   (or
    ;; Check if any child is not done.
-   (org-element-map headline 'headline
+   (org-element-map (org-element-contents headline) 'headline
      (lambda (hl) (eq (org-element-property :todo-type hl) 'todo))
      info 'first-match)
    ;; Check :ORDERED: node property.
@@ -540,6 +569,10 @@ inlinetask within the section."
                   (org-export-get-node-property
                    :LOCATION entry
                    (org-property-inherit-p "LOCATION"))))
+            (class (org-icalendar-cleanup-string
+                    (org-export-get-node-property
+                     :CLASS entry
+                     (org-property-inherit-p "CLASS"))))
             ;; Build description of the entry from associated section
             ;; (headline) or contents (inlinetask).
             (desc
@@ -562,20 +595,28 @@ inlinetask within the section."
          ;; Events: Delegate to `org-icalendar--vevent' to generate
          ;; "VEVENT" component from scheduled, deadline, or any
          ;; timestamp in the entry.
-         (let ((deadline (org-element-property :deadline entry)))
+         (let ((deadline (org-element-property :deadline entry))
+               (use-deadline (plist-get info :icalendar-use-deadline)))
            (and deadline
-                (memq (if todo-type 'event-if-todo 'event-if-not-todo)
-                      org-icalendar-use-deadline)
+                (pcase todo-type
+                  (`todo (or (memq 'event-if-todo-not-done use-deadline)
+                             (memq 'event-if-todo use-deadline)))
+                  (`done (memq 'event-if-todo use-deadline))
+                  (_ (memq 'event-if-not-todo use-deadline)))
                 (org-icalendar--vevent
                  entry deadline (concat "DL-" uid)
-                 (concat "DL: " summary) loc desc cat tz)))
-         (let ((scheduled (org-element-property :scheduled entry)))
+                 (concat "DL: " summary) loc desc cat tz class)))
+         (let ((scheduled (org-element-property :scheduled entry))
+               (use-scheduled (plist-get info :icalendar-use-scheduled)))
            (and scheduled
-                (memq (if todo-type 'event-if-todo 'event-if-not-todo)
-                      org-icalendar-use-scheduled)
+                (pcase todo-type
+                  (`todo (or (memq 'event-if-todo-not-done use-scheduled)
+                             (memq 'event-if-todo use-scheduled)))
+                  (`done (memq 'event-if-todo use-scheduled))
+                  (_ (memq 'event-if-not-todo use-scheduled)))
                 (org-icalendar--vevent
                  entry scheduled (concat "SC-" uid)
-                 (concat "S: " summary) loc desc cat tz)))
+                 (concat "S: " summary) loc desc cat tz class)))
          ;; When collecting plain timestamps from a headline and its
          ;; title, skip inlinetasks since collection will happen once
          ;; ENTRY is one of them.
@@ -593,7 +634,7 @@ inlinetask within the section."
                           ((t) t)))
                   (let ((uid (format "TS%d-%s" (cl-incf counter) uid)))
                     (org-icalendar--vevent
-                     entry ts uid summary loc desc cat tz))))
+                     entry ts uid summary loc desc cat tz class))))
               info nil (and (eq type 'headline) 'inlinetask))
             ""))
          ;; Task: First check if it is appropriate to export it.  If
@@ -607,7 +648,7 @@ inlinetask within the section."
                             (not (org-icalendar-blocked-headline-p
                                   entry info))))
                       ((t) (eq todo-type 'todo))))
-           (org-icalendar--vtodo entry uid summary loc desc cat tz))
+           (org-icalendar--vtodo entry uid summary loc desc cat tz class))
          ;; Diary-sexp: Collect every diary-sexp element within ENTRY
          ;; and its title, and transcode them.  If ENTRY is
          ;; a headline, skip inlinetasks: they will be handled
@@ -638,7 +679,7 @@ inlinetask within the section."
        contents))))
 
 (defun org-icalendar--vevent
-    (entry timestamp uid summary location description categories timezone)
+    (entry timestamp uid summary location description categories timezone 
class)
   "Create a VEVENT component.
 
 ENTRY is either a headline or an inlinetask element.  TIMESTAMP
@@ -648,7 +689,9 @@ summary or subject for the event.  LOCATION defines the 
intended
 venue for the event.  DESCRIPTION provides the complete
 description of the event.  CATEGORIES defines the categories the
 event belongs to.  TIMEZONE specifies a time zone for this event
-only.
+only.  CLASS contains the visibility attribute.  Three of them
+(\"PUBLIC\", \"CONFIDENTIAL\", and \"PRIVATE\") are predefined, others
+should be treated as \"PRIVATE\" if they are unknown to the iCalendar server.
 
 Return VEVENT component as a string."
   (org-icalendar-fold-string
@@ -669,6 +712,7 @@ Return VEVENT component as a string."
                       (org-element-property :repeater-value timestamp)))
             "SUMMARY:" summary "\n"
             (and (org-string-nw-p location) (format "LOCATION:%s\n" location))
+            (and (org-string-nw-p class) (format "CLASS:%s\n" class))
             (and (org-string-nw-p description)
                  (format "DESCRIPTION:%s\n" description))
             "CATEGORIES:" categories "\n"
@@ -677,7 +721,7 @@ Return VEVENT component as a string."
             "END:VEVENT"))))
 
 (defun org-icalendar--vtodo
-  (entry uid summary location description categories timezone)
+  (entry uid summary location description categories timezone class)
   "Create a VTODO component.
 
 ENTRY is either a headline or an inlinetask element.  UID is the
@@ -712,6 +756,7 @@ Return VTODO component as a string."
                          "\n"))
             "SUMMARY:" summary "\n"
             (and (org-string-nw-p location) (format "LOCATION:%s\n" location))
+            (and (org-string-nw-p class) (format "CLASS:%s\n" class))
             (and (org-string-nw-p description)
                  (format "DESCRIPTION:%s\n" description))
             "CATEGORIES:" categories "\n"
@@ -963,7 +1008,7 @@ FILES is a list of files to build the calendar from."
                files "")
               ;; BBDB anniversaries.
               (when (and org-icalendar-include-bbdb-anniversaries
-                         (require 'org-bbdb nil t))
+                         (require 'ol-bbdb nil t))
                 (with-output-to-string (org-bbdb-anniv-export-ical)))))))
          (run-hook-with-args 'org-icalendar-after-save-hook
                              org-icalendar-combined-agenda-file))
diff --git a/lisp/org/ox-latex.el b/lisp/org/ox-latex.el
index 1ec835a..65f40fb 100644
--- a/lisp/org/ox-latex.el
+++ b/lisp/org/ox-latex.el
@@ -127,6 +127,7 @@
     (:latex-format-headline-function nil nil 
org-latex-format-headline-function)
     (:latex-format-inlinetask-function nil nil 
org-latex-format-inlinetask-function)
     (:latex-hyperref-template nil nil org-latex-hyperref-template t)
+    (:latex-image-default-scale nil nil org-latex-image-default-scale)
     (:latex-image-default-height nil nil org-latex-image-default-height)
     (:latex-image-default-option nil nil org-latex-image-default-option)
     (:latex-image-default-width nil nil org-latex-image-default-width)
@@ -159,7 +160,6 @@
 (defconst org-latex-babel-language-alist
   '(("af" . "afrikaans")
     ("bg" . "bulgarian")
-    ("bt-br" . "brazilian")
     ("ca" . "catalan")
     ("cs" . "czech")
     ("cy" . "welsh")
@@ -179,7 +179,7 @@
     ("et" . "estonian")
     ("eu" . "basque")
     ("fi" . "finnish")
-    ("fr" . "frenchb")
+    ("fr" . "french")
     ("fr-ca" . "canadien")
     ("gl" . "galician")
     ("hr" . "croatian")
@@ -195,6 +195,7 @@
     ("no" . "norsk")
     ("pl" . "polish")
     ("pt" . "portuguese")
+    ("pt-br" . "brazilian")
     ("ro" . "romanian")
     ("ru" . "russian")
     ("sa" . "sanskrit")
@@ -211,13 +212,12 @@
 
 (defconst org-latex-polyglossia-language-alist
   '(("am" "amharic")
-    ("ast" "asturian")
     ("ar" "arabic")
-    ("bo" "tibetan")
-    ("bn" "bengali")
+    ("ast" "asturian")
     ("bg" "bulgarian")
+    ("bn" "bengali")
+    ("bo" "tibetan")
     ("br" "breton")
-    ("bt-br" "brazilian")
     ("ca" "catalan")
     ("cop" "coptic")
     ("cs" "czech")
@@ -226,6 +226,7 @@
     ("de" "german" "german")
     ("de-at" "german" "austrian")
     ("de-de" "german" "german")
+    ("dsb" "lsorbian")
     ("dv" "divehi")
     ("el" "greek")
     ("en" "english" "usmax")
@@ -247,40 +248,40 @@
     ("he" "hebrew")
     ("hi" "hindi")
     ("hr" "croatian")
+    ("hsb" "usorbian")
     ("hu" "magyar")
     ("hy" "armenian")
-    ("id" "bahasai")
     ("ia" "interlingua")
+    ("id" "bahasai")
     ("is" "icelandic")
     ("it" "italian")
     ("kn" "kannada")
     ("la" "latin" "modern")
-    ("la-modern" "latin" "modern")
     ("la-classic" "latin" "classic")
     ("la-medieval" "latin" "medieval")
+    ("la-modern" "latin" "modern")
     ("lo" "lao")
     ("lt" "lithuanian")
     ("lv" "latvian")
-    ("mr" "maranthi")
     ("ml" "malayalam")
-    ("nl" "dutch")
+    ("mr" "maranthi")
     ("nb" "norsk")
-    ("nn" "nynorsk")
     ("nko" "nko")
+    ("nl" "dutch")
+    ("nn" "nynorsk")
     ("no" "norsk")
     ("oc" "occitan")
     ("pl" "polish")
     ("pms" "piedmontese")
     ("pt" "portuges")
+    ("pt-br" "brazilian")
     ("rm" "romansh")
     ("ro" "romanian")
     ("ru" "russian")
     ("sa" "sanskrit")
-    ("hsb" "usorbian")
-    ("dsb" "lsorbian")
+    ("se" "samin")
     ("sk" "slovak")
     ("sl" "slovenian")
-    ("se" "samin")
     ("sq" "albanian")
     ("sr" "serbian")
     ("sv" "swedish")
@@ -295,8 +296,6 @@
     ("vi" "vietnamese"))
   "Alist between language code and corresponding Polyglossia option")
 
-
-
 (defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr")
                                          ("qbordermatrix" . "\\cr")
                                          ("kbordermatrix" . "\\\\"))
@@ -708,6 +707,16 @@ This value will not be used if a height is provided."
   :package-version '(Org . "8.0")
   :type 'string)
 
+(defcustom org-latex-image-default-scale ""
+  "Default scale for images.
+This value will not be used if a width or a scale is provided,
+or if the image is wrapped within a \"wrapfigure\" environment.
+Scale overrides width and height."
+  :group 'org-export-latex
+  :package-version '(Org . "9.3")
+  :type 'string
+  :safe #'stringp)
+
 (defcustom org-latex-image-default-height ""
   "Default height for images.
 This value will not be used if a width is provided, or if the
@@ -810,8 +819,9 @@ attributes."
   :type 'boolean
   :safe #'booleanp)
 
-(defcustom org-latex-table-scientific-notation "%s\\,(%s)"
+(defcustom org-latex-table-scientific-notation nil
   "Format string to display numbers in scientific notation.
+
 The format should have \"%s\" twice, for mantissa and exponent
 \(i.e., \"%s\\\\times10^{%s}\").
 
@@ -1026,7 +1036,7 @@ value.  For example,
   (setq org-latex-minted-options
     \\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
 
-will result in src blocks being exported with
+will result in source blocks being exported with
 
 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
 
@@ -1047,12 +1057,13 @@ block-specific options, you may use the following 
syntax:
 (defcustom org-latex-custom-lang-environments nil
   "Alist mapping languages to language-specific LaTeX environments.
 
-It is used during export of src blocks by the listings and minted
-latex packages.  The environment may be a simple string, composed of
-only letters and numbers.  In this case, the string is directly the
-name of the latex environment to use.  The environment may also be
-a format string.  In this case the format string will be directly
-exported.  This format string may contain these elements:
+It is used during export of source blocks by the listings and
+minted LaTeX packages.  The environment may be a simple string,
+composed of only letters and numbers.  In this case, the string
+is directly the name of the LaTeX environment to use.  The
+environment may also be a format string.  In this case the format
+string will be directly exported.  This format string may contain
+these elements:
 
   %s for the formatted source
   %c for the caption
@@ -1074,7 +1085,7 @@ would have the effect that if Org encounters a Python 
source block
 during LaTeX export it will produce
 
   \\begin{pythoncode}
-  <src block body>
+  <source block body>
   \\end{pythoncode}
 
 and if Org encounters an Ocaml source block during LaTeX export it
@@ -1082,7 +1093,7 @@ will produce
 
   \\begin{listing}
   \\begin{minted}[<attr_latex options>]{ocaml}
-  <src block body>
+  <source block body>
   \\end{minted}
   \\caption{<caption>}
   \\label{<label>}
@@ -1221,7 +1232,7 @@ logfiles to remove, set `org-latex-logfiles-extensions'."
     ("Undefined control sequence" . "[undefined control sequence]"))
   "Alist of regular expressions and associated messages for the user.
 The regular expressions are used to find possible warnings in the
-log of a latex-run.  These warnings will be reported after
+log of a LaTeX-run.  These warnings will be reported after
 calling `org-latex-compile'."
   :group 'org-export-latex
   :version "26.1"
@@ -1265,17 +1276,19 @@ Eventually, if FULL is non-nil, wrap label within 
\"\\label{}\"."
          (and (or user-label force)
               (if (and user-label (plist-get info :latex-prefer-user-labels))
                   user-label
-                (concat (cl-case type
-                          (headline "sec:")
-                          (table "tab:")
-                          (latex-environment
+                (concat (pcase type
+                          (`headline "sec:")
+                          (`table "tab:")
+                          (`latex-environment
                            (and (string-match-p
                                  org-latex-math-environments-re
                                  (org-element-property :value datum))
                                 "eq:"))
-                          (paragraph
+                          (`latex-matrices "eq:")
+                          (`paragraph
                            (and (org-element-property :caption datum)
-                                "fig:")))
+                                "fig:"))
+                          (_ nil))
                         (org-export-get-reference datum info))))))
     (cond ((not full) label)
          (label (format "\\label{%s}%s"
@@ -1325,7 +1338,7 @@ For non-floats, see `org-latex--wrap-label'."
                      (t (symbol-name type*)))
                  ""))
              (if short (format "[%s]" (org-export-data short info)) "")
-             label
+             (org-trim label)
              (org-export-data main info))))))
 
 (defun org-latex-guess-inputenc (header)
@@ -1438,26 +1451,21 @@ Return the new header."
 (defun org-latex--remove-packages (pkg-alist info)
   "Remove packages based on the current LaTeX compiler.
 
-If the fourth argument of an element is set in pkg-alist, and it
-is not a member of the LaTeX compiler of the document, the packages
-is removed.  See also `org-latex-compiler'.
+PKG-ALIST is a list of packages, as in `org-latex-packages-alist'
+and `org-latex-default-packages-alist'.  If the fourth argument
+of a package is neither nil nor a member of the LaTeX compiler
+associated to the document, the package is removed.
 
-Return modified pkg-alist."
+Return new list of packages."
   (let ((compiler (or (plist-get info :latex-compiler) "")))
-    (if (member-ignore-case compiler org-latex-compilers)
-       (delq nil
-             (mapcar
-              (lambda (pkg)
-                (unless (and
-                         (listp pkg)
-                         (let ((third (nth 3 pkg)))
-                           (and third
-                                (not (member-ignore-case
-                                      compiler
-                                      (if (listp third) third (list 
third)))))))
-                  pkg))
-              pkg-alist))
-      pkg-alist)))
+    (if (not (member-ignore-case compiler org-latex-compilers)) pkg-alist
+      (cl-remove-if-not
+       (lambda (package)
+        (pcase package
+          (`(,_ ,_ ,_ nil) t)
+          (`(,_ ,_ ,_ ,compilers) (member-ignore-case compiler compilers))
+          (_ t)))
+       pkg-alist))))
 
 (defun org-latex--find-verb-separator (s)
   "Return a character not used in string S.
@@ -1851,7 +1859,7 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
 CONTENTS is nil.  INFO is a plist holding contextual information."
   (org-latex--wrap-label
    fixed-width
-   (format "\\begin{verbatim}\n%s\\end{verbatim}"
+   (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
           (org-remove-indentation
            (org-element-property :value fixed-width)))
    info))
@@ -1877,9 +1885,12 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
                (org-export-get-footnote-definition footnote-reference info)
                info t)))
       ;; Use \footnotemark if reference is within another footnote
-      ;; reference, footnote definition or table cell.
-      ((org-element-lineage footnote-reference
-                           '(footnote-reference footnote-definition 
table-cell))
+      ;; reference, footnote definition, table cell or item's tag.
+      ((or (org-element-lineage footnote-reference
+                               '(footnote-reference footnote-definition
+                                                    table-cell))
+          (eq 'item (org-element-type
+                     (org-export-get-parent-element footnote-reference))))
        "\\footnotemark")
       ;; Otherwise, define it with \footnote command.
       (t
@@ -1890,11 +1901,11 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
                  ;; reference to def.
                  (cond ((not label) "")
                        ((org-element-map (plist-get info :parse-tree) 
'footnote-reference
-                           (lambda (f)
-                             (and (not (eq f footnote-reference))
-                                  (equal (org-element-property :label f) label)
-                                  (org-trim (org-latex--label def info t t))))
-                           info t))
+                          (lambda (f)
+                            (and (not (eq f footnote-reference))
+                                 (equal (org-element-property :label f) label)
+                                 (org-trim (org-latex--label def info t t))))
+                          info t))
                        (t "")))
          ;; Retrieve all footnote references within the footnote and
          ;; add their definition after it, since LaTeX doesn't support
@@ -2131,8 +2142,9 @@ See `org-latex-format-inlinetask-function' for details."
                 (when priority (format "\\framebox{\\#%c} " priority))
                 title
                 (when tags
-                  (format "\\hfill{}\\textsc{:%s:}"
-                          (mapconcat #'org-latex--protect-text tags ":"))))))
+                  (format "\\hfill{}\\textsc{%s}"
+                          (org-make-tag-string
+                           (mapcar #'org-latex--protect-text tags)))))))
     (concat "\\begin{center}\n"
            "\\fbox{\n"
            "\\begin{minipage}[c]{.6\\textwidth}\n"
@@ -2183,12 +2195,22 @@ contextual information."
                     (off "$\\square$")
                     (trans "$\\boxminus$")))
         (tag (let ((tag (org-element-property :tag item)))
-               (and tag (org-export-data tag info)))))
+               (and tag (org-export-data tag info))))
+        ;; If there are footnotes references in tag, be sure to add
+        ;; their definition at the end of the item.  This workaround
+        ;; is necessary since "\footnote{}" command is not supported
+        ;; in tags.
+        (tag-footnotes
+         (or (and tag (org-latex--delayed-footnotes-definitions
+                       (org-element-property :tag item) info))
+             "")))
     (concat counter
            "\\item"
            (cond
-            ((and checkbox tag) (format "[{%s %s}] " checkbox tag))
-            ((or checkbox tag) (format "[{%s}] " (or checkbox tag)))
+            ((and checkbox tag)
+             (format "[{%s %s}] %s" checkbox tag tag-footnotes))
+            ((or checkbox tag)
+             (format "[{%s}] %s" (or checkbox tag) tag-footnotes))
             ;; Without a tag or a check-box, if CONTENTS starts with
             ;; an opening square bracket, add "\relax" to "\item",
             ;; unless the brackets comes from an initial export
@@ -2203,14 +2225,7 @@ contextual information."
                                          'latex)))))))
              "\\relax ")
             (t " "))
-           (and contents (org-trim contents))
-           ;; If there are footnotes references in tag, be sure to
-           ;; add their definition at the end of the item.  This
-           ;; workaround is necessary since "\footnote{}" command is
-           ;; not supported in tags.
-           (and tag
-                (org-latex--delayed-footnotes-definitions
-                 (org-element-property :tag item) info)))))
+           (and contents (org-trim contents)))))
 
 
 ;;;; Keyword
@@ -2370,13 +2385,18 @@ used as a communication channel."
          (if (plist-member attr :center) (plist-get attr :center)
            (plist-get info :latex-images-centered)))
         (comment-include (if (plist-get attr :comment-include) "%" ""))
-        ;; It is possible to specify width and height in the
-        ;; ATTR_LATEX line, and also via default variables.
-        (width (cond ((plist-get attr :width))
+        ;; It is possible to specify scale or width and height in
+        ;; the ATTR_LATEX line, and also via default variables.
+        (scale (cond ((eq float 'wrap) "")
+                     ((plist-get attr :scale))
+                     (t (plist-get info :latex-image-default-scale))))
+        (width (cond ((org-string-nw-p scale) "")
+                     ((plist-get attr :width))
                      ((plist-get attr :height) "")
                      ((eq float 'wrap) "0.48\\textwidth")
                      (t (plist-get info :latex-image-default-width))))
-        (height (cond ((plist-get attr :height))
+        (height (cond ((org-string-nw-p scale) "")
+                      ((plist-get attr :height))
                       ((or (plist-get attr :width)
                            (memq float '(figure wrap))) "")
                       (t (plist-get info :latex-image-default-height))))
@@ -2398,18 +2418,21 @@ used as a communication channel."
                  (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
                          options
                          image-code)))
-         (when (or (org-string-nw-p width) (org-string-nw-p height))
-           (setq image-code (format "\\resizebox{%s}{%s}{%s}"
-                                    (if (org-string-nw-p width) width "!")
-                                    (if (org-string-nw-p height) height "!")
-                                    image-code))))
+         (setq image-code
+               (cond ((org-string-nw-p scale)
+                      (format "\\scalebox{%s}{%s}" scale image-code))
+                     ((or (org-string-nw-p width) (org-string-nw-p height))
+                      (format "\\resizebox{%s}{%s}{%s}"
+                              (if (org-string-nw-p width) width "!")
+                              (if (org-string-nw-p height) height "!")
+                              image-code)))))
       ;; For other images:
-      ;; - add width and height to options.
+      ;; - add scale, or width and height to options.
       ;; - include the image with \includegraphics.
-      (when (org-string-nw-p width)
-       (setq options (concat options ",width=" width)))
-      (when (org-string-nw-p height)
-       (setq options (concat options ",height=" height)))
+      (if (org-string-nw-p scale)
+         (setq options (concat options ",scale=" scale))
+       (when (org-string-nw-p width) (setq options (concat options ",width=" 
width)))
+       (when (org-string-nw-p height) (setq options (concat options ",height=" 
height))))
       (let ((search-option (org-element-property :search-option link)))
         (when (and search-option
                    (equal filetype "pdf")
@@ -2496,8 +2519,10 @@ INFO is a plist holding contextual information.  See
         (path (org-latex--protect-text
                (cond ((member type '("http" "https" "ftp" "mailto" "doi"))
                       (concat type ":" raw-path))
-                     ((string= type "file") (org-export-file-uri raw-path))
-                     (t raw-path)))))
+                     ((string= type "file")
+                      (org-export-file-uri raw-path))
+                     (t
+                      raw-path)))))
     (cond
      ;; Link type is handled by a special function.
      ((org-export-custom-protocol-maybe link desc 'latex))
@@ -2514,9 +2539,10 @@ INFO is a plist holding contextual information.  See
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ((member type '("custom-id" "fuzzy" "id"))
-      (let ((destination (if (string= type "fuzzy")
-                            (org-export-resolve-fuzzy-link link info)
-                          (org-export-resolve-id-link link info))))
+      (let ((destination
+            (if (string= type "fuzzy")
+                (org-export-resolve-fuzzy-link link info 'latex-matrices)
+              (org-export-resolve-id-link link info))))
        (cl-case (org-element-type destination)
          ;; Id link points to an external file.
          (plain-text
@@ -2709,12 +2735,18 @@ it."
                              'latex-matrices)))
            (let* ((caption (and (not (string= mode "inline-math"))
                                 (org-element-property :caption table)))
+                  (name (and (not (string= mode "inline-math"))
+                             (org-element-property :name table)))
                   (matrices
                    (list 'latex-matrices
-                         (list :caption caption
+                         ;; Inherit name from the first table.
+                         (list :name name
+                               ;; FIXME: what syntax for captions?
+                               ;;
+                               ;; :caption caption
                                :markup
                                (cond ((string= mode "inline-math") 'inline)
-                                     (caption 'equation)
+                                     ((or caption name) 'equation)
                                      (t 'math)))))
                   (previous table)
                   (next (org-export-get-next-element table info)))
@@ -2729,6 +2761,8 @@ it."
                                    :attr_latex next :mode)
                                   (plist-get info :latex-default-table-mode))
                               mode))
+               (org-element-put-property table :name nil)
+               (org-element-put-property table :caption nil)
                (org-element-extract-element previous)
                (org-element-adopt-elements matrices previous)
                (setq previous next))
@@ -2738,20 +2772,29 @@ it."
              (org-element-put-property
               matrices :post-blank (org-element-property :post-blank previous))
              (org-element-put-property previous :post-blank 0)
+             (org-element-put-property table :name nil)
+             (org-element-put-property table :caption nil)
              (org-element-extract-element previous)
              (org-element-adopt-elements matrices previous))))))
     info)
   data)
 
-(defun org-latex-matrices (matrices contents _info)
+(defun org-latex-matrices (matrices contents info)
   "Transcode a MATRICES element from Org to LaTeX.
 CONTENTS is a string.  INFO is a plist used as a communication
 channel."
-  (format (cl-case (org-element-property :markup matrices)
-           (inline "\\(%s\\)")
-           (equation "\\begin{equation}\n%s\\end{equation}")
-           (t "\\[\n%s\\]"))
-         contents))
+  (pcase (org-element-property :markup matrices)
+    (`inline (format "\\(%s\\)" contents))
+    (`equation
+     (let ((caption (org-latex--caption/label-string matrices info))
+          (caption-above? (org-latex--caption-above-p matrices info)))
+       (concat "\\begin{equation}\n"
+              (and caption-above? caption)
+              contents
+              (and (not caption-above?) caption)
+              "\\end{equation}")))
+    (_
+     (format "\\[\n%s\\]" contents))))
 
 
 ;;;; Pseudo Object: LaTeX Math Block
@@ -2764,24 +2807,21 @@ channel."
 DATA is a parse tree or a secondary string.  INFO is a plist
 containing export options.  Modify DATA by side-effect and return it."
   (let ((valid-object-p
-        ;; Non-nil when OBJ can be added to the latex math block B.
-        (lambda (obj b)
-          (pcase (org-element-type obj)
-            (`entity (org-element-property :latex-math-p obj))
+        ;; Non-nil when OBJECT can be added to a latex math block.
+        (lambda (object)
+          (pcase (org-element-type object)
+            (`entity (org-element-property :latex-math-p object))
             (`latex-fragment
-             (let ((value (org-element-property :value obj)))
+             (let ((value (org-element-property :value object)))
                (or (string-prefix-p "\\(" value)
-                   (string-match-p "\\`\\$[^$]" value))))
-            ((and type (or `subscript `superscript))
-             (not (memq type (mapcar #'org-element-type
-                                     (org-element-contents b)))))))))
-    (org-element-map data '(entity latex-fragment subscript superscript)
+                   (string-match-p "\\`\\$[^$]" value))))))))
+    (org-element-map data '(entity latex-fragment)
       (lambda (object)
        ;; Skip objects already wrapped.
        (when (and (not (eq (org-element-type
                             (org-element-property :parent object))
                            'latex-math-block))
-                  (funcall valid-object-p object nil))
+                  (funcall valid-object-p object))
          (let ((math-block (list 'latex-math-block nil))
                (next-elements (org-export-get-next-element object info t))
                (last object))
@@ -2793,20 +2833,17 @@ containing export options.  Modify DATA by side-effect 
and return it."
              ;; MATH-BLOCK swallows consecutive math objects.
              (catch 'exit
                (dolist (next next-elements)
-                 (unless (funcall valid-object-p next math-block)
-                   (throw 'exit nil))
+                 (unless (funcall valid-object-p next) (throw 'exit nil))
                  (org-element-extract-element next)
                  (org-element-adopt-elements math-block next)
                  ;; Eschew the case: \beta$x$ -> \(\betax\).
-                 (unless (memq (org-element-type next)
-                               '(subscript superscript))
-                   (org-element-put-property last :post-blank 1))
+                 (org-element-put-property last :post-blank 1)
                  (setq last next)
                  (when (> (or (org-element-property :post-blank next) 0) 0)
                    (throw 'exit nil)))))
            (org-element-put-property
             math-block :post-blank (org-element-property :post-blank last)))))
-      info nil '(subscript superscript latex-math-block) t)
+      info nil '(latex-math-block) t)
     ;; Return updated DATA.
     data))
 
@@ -2883,7 +2920,7 @@ contextual information."
           (listings (plist-get info :latex-listings)))
       (cond
        ;; Case 1.  No source fontification.
-       ((not listings)
+       ((or (not lang) (not listings))
        (let* ((caption-str (org-latex--caption/label-string src-block info))
               (float-env
                (cond ((string= "multicolumn" float)
@@ -2920,21 +2957,23 @@ contextual information."
        ;; Case 3.  Use minted package.
        ((eq listings 'minted)
        (let* ((caption-str (org-latex--caption/label-string src-block info))
+              (placement (or (org-unbracket-string "[" "]" (plist-get 
attributes :placement))
+                             (plist-get info :latex-default-figure-position)))
               (float-env
                (cond
                 ((string= "multicolumn" float)
                  (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
-                         (plist-get info :latex-default-figure-position)
+                         placement
                          (if caption-above-p caption-str "")
                          (if caption-above-p "" caption-str)))
                 (caption
                  (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
-                         (plist-get info :latex-default-figure-position)
+                         placement
                          (if caption-above-p caption-str "")
                          (if caption-above-p "" caption-str)))
                 ((string= "t" float)
                  (concat (format "\\begin{listing}[%s]\n"
-                                 (plist-get info 
:latex-default-figure-position))
+                                 placement)
                          "%s\n\\end{listing}"))
                 (t "%s")))
               (options (plist-get info :latex-minted-options))
@@ -3061,56 +3100,18 @@ holding contextual information."
 
 ;;;; Subscript
 
-(defun org-latex--script-size (object info)
-  "Transcode a subscript or superscript object.
-OBJECT is an Org object.  INFO is a plist used as a communication
-channel."
-  (let ((output ""))
-    (org-element-map (org-element-contents object)
-       (cons 'plain-text org-element-all-objects)
-      (lambda (obj)
-       (cl-case (org-element-type obj)
-         ((entity latex-fragment)
-          (let ((data (org-trim (org-export-data obj info))))
-            (string-match
-             "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
-             data)
-            (setq output
-                  (concat output
-                          (match-string 1 data)
-                          (let ((blank (org-element-property :post-blank obj)))
-                            (and blank (> blank 0) "\\ "))))))
-         (plain-text
-          (setq output
-                (format "%s\\text{%s}" output (org-export-data obj info))))
-         (otherwise
-          (setq output
-                (concat output
-                        (org-export-data obj info)
-                        (let ((blank (org-element-property :post-blank obj)))
-                          (and blank (> blank 0) "\\ ")))))))
-      info nil org-element-recursive-objects)
-    ;; Result.  Do not wrap into curly brackets if OUTPUT is a single
-    ;; character.
-    (concat (if (eq (org-element-type object) 'subscript) "_" "^")
-           (and (> (length output) 1) "{")
-           output
-           (and (> (length output) 1) "}"))))
-
-(defun org-latex-subscript (subscript _contents info)
+(defun org-latex-subscript (_subscript contents _info)
   "Transcode a SUBSCRIPT object from Org to LaTeX.
-CONTENTS is the contents of the object.  INFO is a plist holding
-contextual information."
-  (org-latex--script-size subscript info))
+CONTENTS is the contents of the object."
+  (format "\\textsubscript{%s}" contents))
 
 
 ;;;; Superscript
 
-(defun org-latex-superscript (superscript _contents info)
+(defun org-latex-superscript (_superscript contents _info)
   "Transcode a SUPERSCRIPT object from Org to LaTeX.
-CONTENTS is the contents of the object.  INFO is a plist holding
-contextual information."
-  (org-latex--script-size superscript info))
+CONTENTS is the contents of the object."
+  (format "\\textsuperscript{%s}" contents))
 
 
 ;;;; Table
@@ -3180,6 +3181,56 @@ centered."
          info)
        (apply 'concat (nreverse align)))))
 
+(defun org-latex--decorate-table (table attributes caption above? info)
+  "Decorate TABLE string with caption and float environment.
+
+ATTRIBUTES is the plist containing is LaTeX attributes.  CAPTION
+is its caption, as a string or nil.  It is located above the
+table if ABOVE? is non-nil.  INFO is the plist containing current
+export parameters.
+
+Return new environment, as a string."
+  (let* ((float-environment
+         (let ((float (plist-get attributes :float)))
+           (cond ((and (not float) (plist-member attributes :float)) nil)
+                 ((member float '("sidewaystable" "sideways")) "sidewaystable")
+                 ((equal float "multicolumn") "table*")
+                 ((or float (org-string-nw-p caption)) "table")
+                 (t nil))))
+        (placement
+         (or (plist-get attributes :placement)
+             (format "[%s]" (plist-get info :latex-default-figure-position))))
+        (center? (if (plist-member attributes :center)
+                     (plist-get attributes :center)
+                   (plist-get info :latex-tables-centered)))
+        (fontsize (let ((font (plist-get attributes :font)))
+                    (and font (concat font "\n")))))
+    (concat (cond
+            (float-environment
+             (concat (format "\\begin{%s}%s\n" float-environment placement)
+                     (if above? caption "")
+                     (when center? "\\centering\n")
+                     fontsize))
+            (caption
+             (concat (and center? "\\begin{center}\n" )
+                     (if above? caption "")
+                     (cond ((and fontsize center?) fontsize)
+                           (fontsize (concat "{" fontsize))
+                           (t nil))))
+            (center? (concat "\\begin{center}\n" fontsize))
+            (fontsize (concat "{" fontsize)))
+           table
+           (cond
+            (float-environment
+             (concat (if above? "" (concat "\n" caption))
+                     (format "\n\\end{%s}" float-environment)))
+            (caption
+             (concat (if above? "" (concat "\n" caption))
+                     (and center? "\n\\end{center}")
+                     (and fontsize (not center?) "}")))
+            (center? "\n\\end{center}")
+            (fontsize "}")))))
+
 (defun org-latex--org-table (table contents info)
   "Return appropriate LaTeX code for an Org table.
 
@@ -3189,109 +3240,44 @@ channel.
 
 This function assumes TABLE has `org' as its `:type' property and
 `table' as its `:mode' attribute."
-  (let* ((caption (org-latex--caption/label-string table info))
-        (attr (org-export-read-attribute :attr_latex table))
-        ;; Determine alignment string.
+  (let* ((attr (org-export-read-attribute :attr_latex table))
         (alignment (org-latex--align-string table info))
-        ;; Determine environment for the table: longtable, tabular...
         (table-env (or (plist-get attr :environment)
                        (plist-get info :latex-default-table-environment)))
-        ;; If table is a float, determine environment: table, table*
-        ;; or sidewaystable.
-        (float-env (unless (member table-env '("longtable" "longtabu"))
-                     (let ((float (plist-get attr :float)))
-                       (cond
-                        ((and (not float) (plist-member attr :float)) nil)
-                        ((or (string= float "sidewaystable")
-                             (string= float "sideways")) "sidewaystable")
-                        ((string= float "multicolumn") "table*")
-                        ((or float
-                             (org-element-property :caption table)
-                             (org-string-nw-p (plist-get attr :caption)))
-                         "table")))))
-        ;; Extract others display options.
-        (fontsize (let ((font (plist-get attr :font)))
-                    (and font (concat font "\n"))))
-        ;; "tabular" environment doesn't allow to define a width.
-        (width (and (not (equal table-env "tabular")) (plist-get attr :width)))
-        (spreadp (plist-get attr :spread))
-        (placement
-         (or (plist-get attr :placement)
-             (format "[%s]" (plist-get info :latex-default-figure-position))))
-        (centerp (if (plist-member attr :center) (plist-get attr :center)
-                   (plist-get info :latex-tables-centered)))
-        (caption-above-p (org-latex--caption-above-p table info)))
-    ;; Prepare the final format string for the table.
+        (width
+         (let ((w (plist-get attr :width)))
+           (cond ((not w) "")
+                 ((member table-env '("tabular" "longtable")) "")
+                 ((member table-env '("tabu" "longtabu"))
+                  (format (if (plist-get attr :spread) " spread %s "
+                            " to %s ")
+                          w))
+                 (t (format "{%s}" w)))))
+        (caption (org-latex--caption/label-string table info))
+        (above? (org-latex--caption-above-p table info)))
     (cond
-     ;; Longtable.
-     ((equal "longtable" table-env)
-      (concat (and fontsize (concat "{" fontsize))
-             (format "\\begin{longtable}{%s}\n" alignment)
-             (and caption-above-p
-                  (org-string-nw-p caption)
-                  (concat caption "\\\\\n"))
-             contents
-             (and (not caption-above-p)
-                  (org-string-nw-p caption)
-                  (concat caption "\\\\\n"))
-             "\\end{longtable}\n"
-             (and fontsize "}")))
-     ;; Longtabu
-     ((equal "longtabu" table-env)
-      (concat (and fontsize (concat "{" fontsize))
-             (format "\\begin{longtabu}%s{%s}\n"
-                     (if width
-                         (format " %s %s "
-                                 (if spreadp "spread" "to") width) "")
-                     alignment)
-             (and caption-above-p
-                  (org-string-nw-p caption)
-                  (concat caption "\\\\\n"))
-             contents
-             (and (not caption-above-p)
-                  (org-string-nw-p caption)
-                  (concat caption "\\\\\n"))
-             "\\end{longtabu}\n"
-             (and fontsize "}")))
-     ;; Others.
-     (t (concat (cond
-                (float-env
-                 (concat (format "\\begin{%s}%s\n" float-env placement)
-                         (if caption-above-p caption "")
-                         (when centerp "\\centering\n")
-                         fontsize))
-                ((and (not float-env) caption)
-                 (concat
-                  (and centerp "\\begin{center}\n" )
-                  (if caption-above-p caption "")
-                  (cond ((and fontsize centerp) fontsize)
-                        (fontsize (concat "{" fontsize)))))
-                (centerp (concat "\\begin{center}\n" fontsize))
-                (fontsize (concat "{" fontsize)))
-               (cond ((equal "tabu" table-env)
-                      (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
-                              (if width (format
-                                         (if spreadp " spread %s " " to %s ")
-                                         width) "")
-                              alignment
-                              contents))
-                     (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
-                                table-env
-                                (if width (format "{%s}" width) "")
-                                alignment
-                                contents
-                                table-env)))
-               (cond
-                (float-env
-                 (concat (if caption-above-p "" (concat "\n" caption))
-                         (format "\n\\end{%s}" float-env)))
-                ((and (not float-env) caption)
-                 (concat
-                  (if caption-above-p "" (concat "\n" caption))
-                  (and centerp "\n\\end{center}")
-                  (and fontsize (not centerp) "}")))
-                (centerp "\n\\end{center}")
-                (fontsize "}")))))))
+     ((member table-env '("longtable" "longtabu"))
+      (let ((fontsize (let ((font (plist-get attr :font)))
+                       (and font (concat font "\n")))))
+       (concat (and fontsize (concat "{" fontsize))
+               (format "\\begin{%s}%s{%s}\n" table-env width alignment)
+               (and above?
+                    (org-string-nw-p caption)
+                    (concat caption "\\\\\n"))
+               contents
+               (and (not above?)
+                    (org-string-nw-p caption)
+                    (concat caption "\\\\\n"))
+               (format "\\end{%s}" table-env)
+               (and fontsize "}"))))
+     (t
+      (let ((output (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
+                           table-env
+                           width
+                           alignment
+                           contents
+                           table-env)))
+       (org-latex--decorate-table output attr caption above? info))))))
 
 (defun org-latex--table.el-table (table info)
   "Return appropriate LaTeX code for a table.el table.
@@ -3305,18 +3291,20 @@ property."
   ;; Ensure "*org-export-table*" buffer is empty.
   (with-current-buffer (get-buffer-create "*org-export-table*")
     (erase-buffer))
-  (let ((output (with-temp-buffer
-                 (insert (org-element-property :value table))
-                 (goto-char 1)
-                 (re-search-forward "^[ \t]*|[^|]" nil t)
-                 (table-generate-source 'latex "*org-export-table*")
-                 (with-current-buffer "*org-export-table*"
-                   (org-trim (buffer-string))))))
+  (let ((output
+        (replace-regexp-in-string
+         "^%.*\n" ""                   ;remove comments
+         (with-temp-buffer
+           (save-excursion (insert (org-element-property :value table)))
+           (re-search-forward "^[ \t]*|[^|]" nil t)
+           (table-generate-source 'latex "*org-export-table*")
+           (with-current-buffer "*org-export-table*"
+             (org-trim (buffer-string))))
+         t t)))
     (kill-buffer (get-buffer "*org-export-table*"))
-    ;; Remove left out comments.
-    (while (string-match "^%.*\n" output)
-      (setq output (replace-match "" t t output)))
-    (let ((attr (org-export-read-attribute :attr_latex table)))
+    (let ((attr (org-export-read-attribute :attr_latex table))
+         (caption (org-latex--caption/label-string table info))
+         (above? (org-latex--caption-above-p table info)))
       (when (plist-get attr :rmlines)
        ;; When the "rmlines" attribute is provided, remove all hlines
        ;; but the one separating heading from the table body.
@@ -3325,10 +3313,7 @@ property."
                      (setq pos (string-match "^\\\\hline\n?" output pos)))
            (cl-incf n)
            (unless (= n 2) (setq output (replace-match "" nil nil output))))))
-      (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
-                      (plist-get info :latex-tables-centered))))
-       (if (not centerp) output
-         (format "\\begin{center}\n%s\n\\end{center}" output))))))
+      (org-latex--decorate-table output attr caption above? info))))
 
 (defun org-latex--math-table (table info)
   "Return appropriate LaTeX code for a matrix.
diff --git a/lisp/org/ox-man.el b/lisp/org/ox-man.el
index c0b0f7d..00698fc 100644
--- a/lisp/org/ox-man.el
+++ b/lisp/org/ox-man.el
@@ -424,7 +424,7 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
 CONTENTS is nil.  INFO is a plist holding contextual information."
   (org-man--wrap-label
    fixed-width
-   (format "\\fC\n%s\\fP"
+   (format "\\fC\n%s\n\\fP"
            (org-remove-indentation
             (org-element-property :value fixed-width)))))
 
diff --git a/lisp/org/ox-md.el b/lisp/org/ox-md.el
index fa663db..0a9441a 100644
--- a/lisp/org/ox-md.el
+++ b/lisp/org/ox-md.el
@@ -175,7 +175,7 @@ channel."
            value)))
 
 
-;;;; Example Block, Src Block and export Block
+;;;; Example Block, Src Block and Export Block
 
 (defun org-md-example-block (example-block _contents info)
   "Transcode EXAMPLE-BLOCK element into Markdown format.
@@ -211,8 +211,7 @@ a communication channel."
           (tags (and (plist-get info :with-tags)
                      (let ((tag-list (org-export-get-tags headline info)))
                        (and tag-list
-                            (format "     :%s:"
-                                    (mapconcat 'identity tag-list ":"))))))
+                            (concat "     " (org-make-tag-string tag-list))))))
           (priority
            (and (plist-get info :with-priority)
                 (let ((char (org-element-property :priority headline)))
@@ -364,9 +363,14 @@ channel."
        ((string-match-p "\\<headlines\\>" value)
         (let ((depth (and (string-match "\\<[0-9]+\\>" value)
                           (string-to-number (match-string 0 value))))
-              (local? (string-match-p "\\<local\\>" value)))
+              (scope
+               (cond
+                ((string-match ":target +\\(\".+?\"\\|\\S-+\\)" value) ;link
+                 (org-export-resolve-link
+                  (org-strip-quotes (match-string 1 value)) info))
+                ((string-match-p "\\<local\\>" value) keyword)))) ;local
           (org-remove-indentation
-           (org-md--build-toc info depth keyword local?)))))))
+           (org-md--build-toc info depth keyword scope)))))))
     (_ (org-export-with-backend 'html keyword contents info))))
 
 
@@ -449,7 +453,7 @@ a communication channel."
      (t (let* ((raw-path (org-element-property :path link))
               (path
                (cond
-                ((member type '("http" "https" "ftp" "mailto" "irc"))
+                ((member type '("http" "https" "ftp" "mailto"))
                  (concat type ":" raw-path))
                 ((string= type "file")
                  (org-export-file-uri (funcall link-org-files-as-md raw-path)))
@@ -551,7 +555,7 @@ a communication channel."
 
 ;;;; Template
 
-(defun org-md--build-toc (info &optional n keyword local)
+(defun org-md--build-toc (info &optional n _keyword scope)
   "Return a table of contents.
 
 INFO is a plist used as a communication channel.
@@ -559,13 +563,10 @@ INFO is a plist used as a communication channel.
 Optional argument N, when non-nil, is an integer specifying the
 depth of the table.
 
-Optional argument KEYWORD specifies the TOC keyword, if any, from
-which the table of contents generation has been initiated.
-
-When optional argument LOCAL is non-nil, build a table of
-contents according to the current headline."
+When optional argument SCOPE is non-nil, build a table of
+contents according to the specified element."
   (concat
-   (unless local
+   (unless scope
      (let ((style (plist-get info :md-headline-style))
           (title (org-html--translate "Table of Contents" info)))
        (org-md--headline-title style 1 title nil)))
@@ -575,10 +576,13 @@ contents according to the current headline."
              (make-string
               (* 4 (1- (org-export-get-relative-level headline info)))
               ?\s))
-            (number (format "%d."
-                            (org-last
-                             (org-export-get-headline-number headline info))))
-            (bullet (concat number (make-string (- 4 (length number)) ?\s)))
+            (bullet
+             (if (not (org-export-numbered-headline-p headline info)) "-   "
+               (let ((prefix
+                      (format "%d." (org-last (org-export-get-headline-number
+                                               headline info)))))
+                 (concat prefix (make-string (max 1 (- 4 (length prefix)))
+                                             ?\s)))))
             (title
              (format "[%s](#%s)"
                      (org-export-data-with-backend
@@ -589,12 +593,10 @@ contents according to the current headline."
                          (org-export-get-reference headline info))))
             (tags (and (plist-get info :with-tags)
                        (not (eq 'not-in-toc (plist-get info :with-tags)))
-                       (let ((tags (org-export-get-tags headline info)))
-                         (and tags
-                              (format ":%s:"
-                                      (mapconcat #'identity tags ":")))))))
+                       (org-make-tag-string
+                        (org-export-get-tags headline info)))))
        (concat indentation bullet title tags)))
-    (org-export-collect-headlines info n (and local keyword)) "\n")
+    (org-export-collect-headlines info n scope) "\n")
    "\n"))
 
 (defun org-md--footnote-formatted (footnote info)
diff --git a/lisp/org/ox-odt.el b/lisp/org/ox-odt.el
index 999a2b7..f9c4a93 100644
--- a/lisp/org/ox-odt.el
+++ b/lisp/org/ox-odt.el
@@ -27,8 +27,9 @@
 
 (require 'cl-lib)
 (require 'format-spec)
-(require 'ox)
 (require 'org-compat)
+(require 'org-macs)
+(require 'ox)
 (require 'table nil 'noerror)
 
 ;;; Define Back-End
@@ -147,8 +148,7 @@
 Use this to infer values of `org-odt-styles-dir' and
 `org-odt-schema-dir'.")
 
-(defvar org-odt-data-dir
-  (expand-file-name "../../etc/" org-odt-lib-dir)
+(defvar org-odt-data-dir (expand-file-name "../../etc/" org-odt-lib-dir)
   "Data directory for ODT exporter.
 Use this to infer values of `org-odt-styles-dir' and
 `org-odt-schema-dir'.")
@@ -161,25 +161,17 @@ Use this to infer values of `org-odt-styles-dir' and
   "Regular expressions for special string conversion.")
 
 (defconst org-odt-schema-dir-list
-  (list
-   (and org-odt-data-dir
-       (expand-file-name "./schema/" org-odt-data-dir)) ; bail out
-   (eval-when-compile
-     (and (boundp 'org-odt-data-dir) org-odt-data-dir ; see make install
-         (expand-file-name "./schema/" org-odt-data-dir))))
+  (list (expand-file-name "./schema/" org-odt-data-dir))
   "List of directories to search for OpenDocument schema files.
-Use this list to set the default value of
-`org-odt-schema-dir'.  The entries in this list are
-populated heuristically based on the values of `org-odt-lib-dir'
-and `org-odt-data-dir'.")
+Use this list to set the default value of `org-odt-schema-dir'.
+The entries in this list are populated heuristically based on the
+values of `org-odt-lib-dir' and `org-odt-data-dir'.")
 
 (defconst org-odt-styles-dir-list
   (list
    (and org-odt-data-dir
        (expand-file-name "./styles/" org-odt-data-dir)) ; bail out
-   (eval-when-compile
-     (and (boundp 'org-odt-data-dir) org-odt-data-dir ; see make install
-         (expand-file-name "./styles/" org-odt-data-dir)))
+   (expand-file-name "./styles/" org-odt-data-dir)
    (expand-file-name "../etc/styles/" org-odt-lib-dir) ; git
    (expand-file-name "./etc/styles/" org-odt-lib-dir)  ; elpa
    (expand-file-name "./org/" data-directory)         ; system
@@ -822,7 +814,7 @@ form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME 
TABLE-CELL-OPTIONS).
 TABLE-STYLE-NAME is the style associated with the table through
 \"#+ATTR_ODT: :style TABLE-STYLE-NAME\" line.
 
-TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
+TABLE-TEMPLATE-NAME is a set of - up to 9 - automatic
 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
 below) that is included in `org-odt-content-template-file'.
 
@@ -1357,17 +1349,18 @@ original parsed data.  INFO is a plist holding export 
options."
   ;; Update styles file.
   ;; Copy styles.xml.  Also dump htmlfontify styles, if there is any.
   ;; Write styles file.
-  (let* ((styles-file (plist-get info :odt-styles-file))
-        (styles-file (and (org-string-nw-p styles-file)
-                          (read (org-trim styles-file))))
-        ;; Non-availability of styles.xml is not a critical
-        ;; error. For now, throw an error.
-        (styles-file (or styles-file
-                         (plist-get info :odt-styles-file)
-                         (expand-file-name "OrgOdtStyles.xml"
-                                           org-odt-styles-dir)
-                         (error "org-odt: Missing styles file?"))))
+  (let* ((styles-file
+         (pcase (plist-get info :odt-styles-file)
+           (`nil (expand-file-name "OrgOdtStyles.xml" org-odt-styles-dir))
+           ((and s (pred (string-match-p "\\`(.*)\\'")))
+            (condition-case nil
+                (read s)
+              (error (user-error "Invalid styles file specification: %S" s))))
+           (filename (org-strip-quotes filename)))))
     (cond
+     ;; Non-availability of styles.xml is not a critical error.  For
+     ;; now, throw an error.
+     ((null styles-file) (error "Missing styles file"))
      ((listp styles-file)
       (let ((archive (nth 0 styles-file))
            (members (nth 1 styles-file)))
@@ -1377,7 +1370,7 @@ original parsed data.  INFO is a plist holding export 
options."
            (let* ((image-type (file-name-extension member))
                   (media-type (format "image/%s" image-type)))
              (org-odt-create-manifest-file-entry media-type member))))))
-     ((and (stringp styles-file) (file-exists-p styles-file))
+     ((file-exists-p styles-file)
       (let ((styles-file-type (file-name-extension styles-file)))
        (cond
         ((string= styles-file-type "xml")
@@ -1421,7 +1414,7 @@ original parsed data.  INFO is a plist holding export 
options."
       ;; the resulting odt file.
       (setq-local backup-inhibited t)
 
-      ;; Outline numbering is retained only upto LEVEL.
+      ;; Outline numbering is retained only up to LEVEL.
       ;; To disable outline numbering pass a LEVEL of 0.
 
       (goto-char (point-min))
@@ -1967,10 +1960,12 @@ contextual information."
 CONTENTS holds the contents of the item.  INFO is a plist holding
 contextual information."
   (let* ((plain-list (org-export-get-parent item))
+        (count (org-element-property :counter item))
         (type (org-element-property :type plain-list)))
     (unless (memq type '(ordered unordered descriptive-1 descriptive-2))
       (error "Unknown list type: %S" type))
-    (format "\n<text:list-item>\n%s\n%s"
+    (format "\n<text:list-item%s>\n%s\n%s"
+           (if count (format " text:start-value=\"%s\"" count) "")
            contents
            (if (org-element-map item 'table #'identity info 'first-match)
                "</text:list-header>"
@@ -1996,8 +1991,13 @@ information."
          (let ((depth (or (and (string-match "\\<[0-9]+\\>" value)
                                (string-to-number (match-string 0 value)))
                           (plist-get info :headline-levels)))
-               (localp (string-match-p "\\<local\\>" value)))
-           (org-odt-toc depth info (and localp keyword))))
+               (scope
+                (cond
+                 ((string-match ":target +\\(\".+?\"\\|\\S-+\\)" value) ;link
+                  (org-export-resolve-link
+                   (org-strip-quotes (match-string 1 value)) info))
+                 ((string-match-p "\\<local\\>" value) keyword)))) ;local
+           (org-odt-toc depth info scope)))
         ((string-match-p "tables\\|figures\\|listings" value)
          ;; FIXME
          (ignore))))))))
@@ -3144,7 +3144,7 @@ and prefix with \"OrgSrc\".  For example,
         (code-info (org-export-unravel-code element))
         (code (car code-info))
         (refs (cdr code-info))
-        ;; Does the src block contain labels?
+        ;; Does the source block contain labels?
         (retain-labels (org-element-property :retain-labels element))
         ;; Does it have line numbers?
         (num-start (org-export-get-loc element info)))
@@ -3241,7 +3241,7 @@ styles congruent with the ODF-1.2 specification."
     (when style-spec
       ;; LibreOffice - particularly the Writer - honors neither table
       ;; templates nor custom table-cell styles.  Inorder to retain
-      ;; inter-operability with LibreOffice, only automatic styles are
+      ;; interoperability with LibreOffice, only automatic styles are
       ;; used for styling of table-cells.  The current implementation is
       ;; congruent with ODF-1.2 specification and hence is
       ;; future-compatible.
diff --git a/lisp/org/ox-org.el b/lisp/org/ox-org.el
index ca10287..0e7f977 100644
--- a/lisp/org/ox-org.el
+++ b/lisp/org/ox-org.el
@@ -96,7 +96,7 @@ setting of `org-html-htmlize-output-type' is `css'."
     (table-cell . org-org-identity)
     (table-row . org-org-identity)
     (target . org-org-identity)
-    (timestamp . org-org-identity)
+    (timestamp . org-org-timestamp)
     (underline . org-org-identity)
     (verbatim . org-org-identity)
     (verse-block . org-org-identity))
@@ -206,6 +206,10 @@ as a communication channel."
        (format "#+CREATOR: %s\n" (plist-get info :creator)))
    contents))
 
+(defun org-org-timestamp (timestamp _contents _info)
+  "Transcode a TIMESTAMP object to custom format or back into Org syntax."
+  (org-timestamp-translate timestamp))
+
 (defun org-org-section (section contents info)
   "Transcode SECTION element back into Org syntax.
 CONTENTS is the contents of the section.  INFO is a plist used as
@@ -270,7 +274,7 @@ non-nil."
 ;;;###autoload
 (defun org-org-export-to-org
   (&optional async subtreep visible-only body-only ext-plist)
-  "Export current buffer to an org file.
+  "Export current buffer to an Org file.
 
 If narrowing is active in the current buffer, only export its
 narrowed part.
@@ -303,7 +307,7 @@ Return output file name."
 
 ;;;###autoload
 (defun org-org-publish-to-org (plist filename pub-dir)
-  "Publish an org file to org.
+  "Publish an Org file to Org.
 
 FILENAME is the filename of the Org file to be published.  PLIST
 is the property list for the given project.  PUB-DIR is the
@@ -324,8 +328,7 @@ Return output file name."
           newbuf)
       (with-current-buffer work-buffer
         (org-font-lock-ensure)
-        (outline-show-all)
-        (org-show-block-all)
+        (org-show-all)
         (setq newbuf (htmlize-buffer)))
       (with-current-buffer newbuf
        (when org-org-htmlized-css-url
diff --git a/lisp/org/ox-publish.el b/lisp/org/ox-publish.el
index 3954738..28d063e 100644
--- a/lisp/org/ox-publish.el
+++ b/lisp/org/ox-publish.el
@@ -867,8 +867,7 @@ PROPERTY, i.e. \"behavior\" parameter from 
`org-export-options-alist'."
                    (org-no-properties
                     (org-element-interpret-data parsed-title))
                  (file-name-nondirectory (file-name-sans-extension file)))))
-         (org-publish-cache-set-file-property file :title title)
-         title))))
+         (org-publish-cache-set-file-property file :title title)))))
 
 (defun org-publish-find-date (file project)
   "Find the date of FILE in PROJECT.
@@ -877,20 +876,23 @@ If FILE is an Org file and provides a DATE keyword use 
it.  In
 any other case use the file system's modification time.  Return
 time in `current-time' format."
   (let ((file (org-publish--expand-file-name file project)))
-    (if (file-directory-p file) (file-attribute-modification-time
-                                 (file-attributes file))
-      (let ((date (org-publish-find-property file :date project)))
-       ;; DATE is a secondary string.  If it contains a time-stamp,
-       ;; convert it to internal format.  Otherwise, use FILE
-       ;; modification time.
-       (cond ((let ((ts (and (consp date) (assq 'timestamp date))))
-                (and ts
-                     (let ((value (org-element-interpret-data ts)))
-                       (and (org-string-nw-p value)
-                            (org-time-string-to-time value))))))
-             ((file-exists-p file) (file-attribute-modification-time
-                                     (file-attributes file)))
-             (t (error "No such file: \"%s\"" file)))))))
+    (or (org-publish-cache-get-file-property file :date nil t)
+       (org-publish-cache-set-file-property
+        file :date
+        (if (file-directory-p file)
+            (file-attribute-modification-time (file-attributes file))
+          (let ((date (org-publish-find-property file :date project)))
+            ;; DATE is a secondary string.  If it contains
+            ;; a time-stamp, convert it to internal format.
+            ;; Otherwise, use FILE modification time.
+            (cond ((let ((ts (and (consp date) (assq 'timestamp date))))
+                     (and ts
+                          (let ((value (org-element-interpret-data ts)))
+                            (and (org-string-nw-p value)
+                                 (org-time-string-to-time value))))))
+                  ((file-exists-p file)
+                   (file-attribute-modification-time (file-attributes file)))
+                  (t (error "No such file: \"%s\"" file)))))))))
 
 (defun org-publish-sitemap-default-entry (entry style project)
   "Default format for site map ENTRY, as a string.
@@ -1145,7 +1147,7 @@ This function is meant to be used as a final output 
filter.  See
   ;; Return output unchanged.
   output)
 
-(defun org-publish-resolve-external-link (search file)
+(defun org-publish-resolve-external-link (search file &optional prefer-custom)
   "Return reference for element matching string SEARCH in FILE.
 
 Return value is an internal reference, as a string.
@@ -1153,23 +1155,39 @@ Return value is an internal reference, as a string.
 This function allows resolving external links with a search
 option, e.g.,
 
-  [[file.org::*heading][description]]
-  [[file.org::#custom-id][description]]
-  [[file.org::fuzzy][description]]
+  [[file:file.org::*heading][description]]
+  [[file:file.org::#custom-id][description]]
+  [[file:file.org::fuzzy][description]]
+
+When PREFER-CUSTOM is non-nil, and SEARCH targets a headline in
+FILE, return its custom ID, if any.
 
 It only makes sense to use this if export back-end builds
 references with `org-export-get-reference'."
-  (if (not org-publish-cache)
-      (progn
-       (message "Reference %S in file %S cannot be resolved without publishing"
-                search
-                file)
-       "MissingReference")
+  (cond
+   ((and prefer-custom
+        (if (string-prefix-p "#" search)
+            (substring search 1)
+          (with-current-buffer (find-file-noselect file)
+            (org-with-point-at 1
+              (let ((org-link-search-must-match-exact-headline t))
+                (condition-case err
+                    (org-link-search search nil t)
+                  (error
+                   (signal 'org-link-broken (cdr err)))))
+              (and (org-at-heading-p)
+                   (org-string-nw-p (org-entry-get (point) "CUSTOM_ID"))))))))
+   ((not org-publish-cache)
+    (progn
+      (message "Reference %S in file %S cannot be resolved without publishing"
+              search
+              file)
+      "MissingReference"))
+   (t
     (let* ((filename (file-truename file))
           (crossrefs
            (org-publish-cache-get-file-property filename :crossrefs nil t))
-          (cells
-           (org-export-string-to-search-cell (org-link-unescape search))))
+          (cells (org-export-string-to-search-cell search)))
       (or
        ;; Look for reference associated to search cells triggered by
        ;; LINK.  It can match when targeted file has been published
@@ -1182,7 +1200,7 @@ references with `org-export-get-reference'."
        (let ((new (org-export-new-reference crossrefs)))
         (dolist (cell cells) (push (cons cell new) crossrefs))
         (org-publish-cache-set-file-property filename :crossrefs crossrefs)
-        (org-export-format-reference new))))))
+        (org-export-format-reference new)))))))
 
 (defun org-publish-file-relative-name (filename info)
   "Convert FILENAME to be relative to current project's base directory.
@@ -1283,8 +1301,8 @@ the file including them will be republished as well."
                    (let* ((value (org-element-property :value element))
                           (filename
                            (and (string-match "\\`\\(\".+?\"\\|\\S-+\\)" value)
-                                (let ((m (org-unbracket-string
-                                          "\"" "\"" (match-string 1 value))))
+                                (let ((m (org-strip-quotes
+                                          (match-string 1 value))))
                                   ;; Ignore search suffix.
                                   (if (string-match "::.*?\\'" m)
                                       (substring m 0 (match-beginning 0))
@@ -1296,8 +1314,9 @@ the file including them will be republished as well."
          (unless visiting (kill-buffer buf)))))
     (or (null pstamp)
        (let ((ctime (org-publish-cache-ctime-of-src filename)))
-         (or (< pstamp ctime)
-             (cl-some (lambda (ct) (< ctime ct)) included-files-ctime))))))
+         (or (time-less-p pstamp ctime)
+             (cl-some (lambda (ct) (time-less-p ctime ct))
+                      included-files-ctime))))))
 
 (defun org-publish-cache-set-file-property
   (filename property value &optional project-name)
@@ -1305,7 +1324,7 @@ the file including them will be republished as well."
 Use cache file of PROJECT-NAME.  If the entry does not exist, it
 will be created.  Return VALUE."
   ;; Evtl. load the requested cache file:
-  (if project-name (org-publish-initialize-cache project-name))
+  (when project-name (org-publish-initialize-cache project-name))
   (let ((pl (org-publish-cache-get filename)))
     (if pl (progn (plist-put pl property value) value)
       (org-publish-cache-get-file-property
@@ -1347,8 +1366,8 @@ does not exist."
   (let ((attr (file-attributes
               (expand-file-name (or (file-symlink-p file) file)
                                 (file-name-directory file)))))
-    (if (not attr) (error "No such file: \"%s\"" file)
-      (time-convert (file-attribute-modification-time attr) 'integer))))
+    (if attr (file-attribute-modification-time attr)
+      (error "No such file: %S" file))))
 
 
 (provide 'ox-publish)
diff --git a/lisp/org/ox-texinfo.el b/lisp/org/ox-texinfo.el
index 468fc58..5e74632 100644
--- a/lisp/org/ox-texinfo.el
+++ b/lisp/org/ox-texinfo.el
@@ -147,10 +147,12 @@ If nil it will default to `buffer-file-coding-system'."
 (defcustom org-texinfo-classes
   '(("info"
      "@documentencoding AUTO\n@documentlanguage AUTO"
-     ("@chapter %s" "@unnumbered %s" "@appendix %s")
-     ("@section %s" "@unnumberedsec %s" "@appendixsec %s")
-     ("@subsection %s" "@unnumberedsubsec %s" "@appendixsubsec %s")
-     ("@subsubsection %s" "@unnumberedsubsubsec %s" "@appendixsubsubsec %s")))
+     ("@chapter %s" "@unnumbered %s" "@chapheading %s" "@appendix %s")
+     ("@section %s" "@unnumberedsec %s" "@heading %s" "@appendixsec %s")
+     ("@subsection %s" "@unnumberedsubsec %s" "@subheading %s"
+      "@appendixsubsec %s")
+     ("@subsubsection %s" "@unnumberedsubsubsec %s" "@subsubheading %s"
+      "@appendixsubsubsec %s")))
   "Alist of Texinfo classes and associated header and structure.
 If #+TEXINFO_CLASS is set in the buffer, use its value and the
 associated information.  Here is the structure of a class
@@ -158,8 +160,8 @@ definition:
 
   (class-name
     header-string
-    (numbered-1 unnumbered-1 appendix-1)
-    (numbered-2 unnumbered-2 appendix-2)
+    (numbered-1 unnumbered-1 unnumbered-no-toc-1 appendix-1)
+    (numbered-2 unnumbered-2 unnumbered-no-toc-2 appendix-2)
     ...)
 
 
@@ -193,17 +195,18 @@ following the header string.  For each sectioning level, 
a number
 of strings is specified.  A %s formatter is mandatory in each
 section string and will be replaced by the title of the section."
   :group 'org-export-texinfo
-  :version "26.1"
-  :package-version '(Org . "9.1")
+  :version "27.1"
+  :package-version '(Org . "9.2")
   :type '(repeat
          (list (string :tag "Texinfo class")
                (string :tag "Texinfo header")
                (repeat :tag "Levels" :inline t
                        (choice
                         (list :tag "Heading"
-                              (string :tag "  numbered")
-                              (string :tag "unnumbered")
-                              (string :tag "  appendix")))))))
+                              (string :tag "         numbered")
+                              (string :tag "       unnumbered")
+                              (string :tag "unnumbered-no-toc")
+                              (string :tag "         appendix")))))))
 
 ;;;; Headline
 
@@ -264,7 +267,7 @@ be placed after the end of the title."
   :group 'org-export-texinfo
   :type 'boolean)
 
-(defcustom org-texinfo-table-scientific-notation "%s\\,(%s)"
+(defcustom org-texinfo-table-scientific-notation nil
   "Format string to display numbers in scientific notation.
 
 The format should have \"%s\" twice, for mantissa and exponent
@@ -463,22 +466,40 @@ INFO is a plist used as a communication channel.  See
 
 (defun org-texinfo--get-node (datum info)
   "Return node or anchor associated to DATUM.
-DATUM is an element or object.  INFO is a plist used as
-a communication channel.  The function guarantees the node or
-anchor name is unique."
+DATUM is a headline, a radio-target or a target.  INFO is a plist
+used as a communication channel.  The function guarantees the
+node or anchor name is unique."
   (let ((cache (plist-get info :texinfo-node-cache)))
     (or (cdr (assq datum cache))
        (let* ((salt 0)
               (basename
                (org-texinfo--sanitize-node
-                (if (eq (org-element-type datum) 'headline)
-                    (org-texinfo--sanitize-title
-                     (org-export-get-alt-title datum info) info)
-                  (org-export-get-reference datum info))))
+                (pcase (org-element-type datum)
+                  (`headline
+                   (org-texinfo--sanitize-title
+                    (org-export-get-alt-title datum info) info))
+                  (`radio-target
+                   (org-export-data (org-element-contents datum) info))
+                  (`target
+                   (org-element-property :value datum))
+                  (_
+                   (or (org-element-property :name datum)
+                       (org-export-get-reference datum info))))))
               (name basename))
+         ;; Org exports deeper elements before their parents.  If two
+         ;; node names collide -- e.g., they have the same title --
+         ;; within the same hierarchy, the second one would get the
+         ;; shorter node name.  This is counter-intuitive.
+         ;; Consequently, we ensure that every parent headline get
+         ;; its node beforehand. As a recursive operation, this
+         ;; achieves the desired effect.
+         (let ((parent (org-element-lineage datum '(headline))))
+           (when (and parent (not (assq parent cache)))
+             (org-texinfo--get-node parent info)
+             (setq cache (plist-get info :texinfo-node-cache))))
          ;; Ensure NAME is unique and not reserved node name "Top".
          (while (or (equal name "Top") (rassoc name cache))
-           (setq name (concat basename (format " %d" (cl-incf salt)))))
+           (setq name (concat basename (format " (%d)" (cl-incf salt)))))
          (plist-put info :texinfo-node-cache (cons (cons datum name) cache))
          name))))
 
@@ -500,18 +521,7 @@ periods, commas and colons."
 TITLE is a string or a secondary string.  INFO is the current
 export state, as a plist."
   (org-export-data-with-backend
-   title
-   (org-export-create-backend
-    :parent 'texinfo
-    :transcoders '((footnote-reference . ignore)
-                  (link . (lambda (l c i)
-                            (or c
-                                (org-export-data
-                                 (org-element-property :raw-link l)
-                                 i))))
-                  (radio-target . (lambda (_r c _i) c))
-                  (target . ignore)))
-   info))
+   title (org-export-toc-entry-backend 'texinfo) info))
 
 (defun org-texinfo--sanitize-content (text)
   "Escape special characters in string TEXT.
@@ -526,29 +536,13 @@ float, as a string.  CAPTION and SHORT are, respectively, 
the
 caption and shortcaption used for the float, as secondary
 strings (e.g., returned by `org-export-get-caption')."
   (let* ((backend
-         (org-export-create-backend
-          :parent 'texinfo
-          :transcoders '((link . (lambda (l c i)
-                                   (or c
-                                       (org-export-data
-                                        (org-element-property :raw-link l)
-                                        i))))
-                         (radio-target . (lambda (_r c _i) c))
-                         (target . ignore))))
+         (org-export-toc-entry-backend 'texinfo
+           (cons 'footnote-reference
+                 (lambda (f c i) (org-export-with-backend 'texinfo f c i)))))
         (short-backend
-         (org-export-create-backend
-          :parent 'texinfo
-          :transcoders
-          '((footnote-reference . ignore)
-            (inline-src-block . ignore)
-            (link . (lambda (l c i)
-                      (or c
-                          (org-export-data
-                           (org-element-property :raw-link l)
-                           i))))
-            (radio-target . (lambda (_r c _i) c))
-            (target . ignore)
-            (verbatim . ignore))))
+         (org-export-toc-entry-backend 'texinfo
+           '(inline-src-block . ignore)
+           '(verbatim . ignore)))
         (short-str
          (if (and short caption)
              (format "@shortcaption{%s}\n"
@@ -582,7 +576,7 @@ holding export options."
     (concat
      "\\input texinfo    @c -*- texinfo -*-\n"
      "@c %**start of header\n"
-     (let ((file (or (plist-get info :texinfo-filename)
+     (let ((file (or (org-strip-quotes (plist-get info :texinfo-filename))
                     (let ((f (plist-get info :output-file)))
                       (and f (concat (file-name-sans-extension f) ".info"))))))
        (and file (format "@setfilename %s\n" file)))
@@ -712,7 +706,7 @@ contextual information."
   "Transcode a CENTER-BLOCK element from Org to Texinfo.
 CONTENTS holds the contents of the block.  INFO is a plist used
 as a communication channel."
-  contents)
+  (replace-regexp-in-string "\\(^\\).*?\\S-" "@center " contents nil nil 1))
 
 ;;;; Clock
 
@@ -831,7 +825,7 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
 (defun org-texinfo-fixed-width (fixed-width _contents _info)
   "Transcode a FIXED-WIDTH element from Org to Texinfo.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (format "@example\n%s@end example"
+  (format "@example\n%s\n@end example"
          (org-remove-indentation
           (org-texinfo--sanitize-content
            (org-element-property :value fixed-width)))))
@@ -849,84 +843,81 @@ plist holding contextual information."
 
 ;;;; Headline
 
-(defun org-texinfo--structuring-command (headline info)
-  "Return Texinfo structuring command string for HEADLINE element.
-Return nil if HEADLINE is to be ignored, `plain-list' if it
-should be exported as a plain-list item.  INFO is a plist holding
-contextual information."
-  (cond
-   ((org-element-property :footnote-section-p headline) nil)
-   ((org-not-nil (org-export-get-node-property :COPYING headline t)) nil)
-   ((org-export-low-level-p headline info) 'plain-list)
-   (t
-    (let ((class (plist-get info :texinfo-class)))
-      (pcase (assoc class (plist-get info :texinfo-classes))
-       (`(,_ ,_ . ,sections)
-        (pcase (nth (1- (org-export-get-relative-level headline info))
-                    sections)
-          (`(,numbered ,unnumbered ,appendix)
-           (cond
-            ((org-not-nil (org-export-get-node-property :APPENDIX headline t))
-             appendix)
-            ((org-not-nil (org-export-get-node-property :INDEX headline t))
-             unnumbered)
-            ((org-export-numbered-headline-p headline info) numbered)
-            (t unnumbered)))
-          (`nil 'plain-list)
-          (_ (user-error "Invalid Texinfo class specification: %S" class))))
-       (_ (user-error "Invalid Texinfo class specification: %S" class)))))))
-
 (defun org-texinfo-headline (headline contents info)
   "Transcode a HEADLINE element from Org to Texinfo.
 CONTENTS holds the contents of the headline.  INFO is a plist
 holding contextual information."
-  (let ((section-fmt (org-texinfo--structuring-command headline info)))
-    (when section-fmt
-      (let* ((todo
-             (and (plist-get info :with-todo-keywords)
-                  (let ((todo (org-element-property :todo-keyword headline)))
-                    (and todo (org-export-data todo info)))))
-            (todo-type (and todo (org-element-property :todo-type headline)))
-            (tags (and (plist-get info :with-tags)
-                       (org-export-get-tags headline info)))
-            (priority (and (plist-get info :with-priority)
-                           (org-element-property :priority headline)))
-            (text (org-texinfo--sanitize-title
-                   (org-element-property :title headline) info))
-            (full-text
-             (funcall (plist-get info :texinfo-format-headline-function)
-                      todo todo-type priority text tags))
-            (contents
-             (concat "\n"
-                     (if (org-string-nw-p contents)
-                         (concat "\n" contents)
-                       "")
-                     (let ((index (org-element-property :INDEX headline)))
-                       (and (member index '("cp" "fn" "ky" "pg" "tp" "vr"))
-                            (format "\n@printindex %s\n" index))))))
-       (cond
-        ((eq section-fmt 'plain-list)
-         (let ((numbered? (org-export-numbered-headline-p headline info)))
-           (concat (and (org-export-first-sibling-p headline info)
-                        (format "@%s\n" (if numbered? 'enumerate 'itemize)))
-                   "@item\n" full-text "\n"
-                   contents
-                   (if (org-export-last-sibling-p headline info)
-                       (format "@end %s" (if numbered? 'enumerate 'itemize))
-                     "\n"))))
-        (t
-         (concat (format "@node %s\n" (org-texinfo--get-node headline info))
-                 (format section-fmt full-text)
-                 contents)))))))
+  (cond
+   ((org-element-property :footnote-section-p headline) nil)
+   ((org-not-nil (org-export-get-node-property :COPYING headline t)) nil)
+   (t
+    (let* ((index (let ((i (org-export-get-node-property :INDEX headline t)))
+                   (and (member i '("cp" "fn" "ky" "pg" "tp" "vr")) i)))
+          (numbered? (org-export-numbered-headline-p headline info))
+          (notoc? (org-export-excluded-from-toc-p headline info))
+          (command
+           (and
+            (not (org-export-low-level-p headline info))
+            (let ((class (plist-get info :texinfo-class)))
+              (pcase (assoc class (plist-get info :texinfo-classes))
+                (`(,_ ,_ . ,sections)
+                 (pcase (nth (1- (org-export-get-relative-level headline info))
+                             sections)
+                   (`(,numbered ,unnumbered ,unnumbered-no-toc ,appendix)
+                    (cond
+                     ((org-not-nil
+                       (org-export-get-node-property :APPENDIX headline t))
+                      appendix)
+                     (numbered? numbered)
+                     (index unnumbered)
+                     (notoc? unnumbered-no-toc)
+                     (t unnumbered)))
+                   (`nil nil)
+                   (_ (user-error "Invalid Texinfo class specification: %S"
+                                  class))))
+                (_ (user-error "Unknown Texinfo class: %S" class))))))
+          (todo
+           (and (plist-get info :with-todo-keywords)
+                (let ((todo (org-element-property :todo-keyword headline)))
+                  (and todo (org-export-data todo info)))))
+          (todo-type (and todo (org-element-property :todo-type headline)))
+          (tags (and (plist-get info :with-tags)
+                     (org-export-get-tags headline info)))
+          (priority (and (plist-get info :with-priority)
+                         (org-element-property :priority headline)))
+          (text (org-texinfo--sanitize-title
+                 (org-element-property :title headline) info))
+          (full-text
+           (funcall (plist-get info :texinfo-format-headline-function)
+                    todo todo-type priority text tags))
+          (contents
+           (concat "\n"
+                   (if (org-string-nw-p contents) (concat "\n" contents) "")
+                   (and index (format "\n@printindex %s\n" index)))))
+      (if (not command)
+         (concat (and (org-export-first-sibling-p headline info)
+                      (format "@%s\n" (if numbered? 'enumerate 'itemize)))
+                 "@item\n" full-text "\n"
+                 contents
+                 (if (org-export-last-sibling-p headline info)
+                     (format "@end %s" (if numbered? 'enumerate 'itemize))
+                   "\n"))
+       (concat
+        ;; Even if HEADLINE is using @subheading and al., leave an
+        ;; anchor so cross-references in the Org document still work.
+        (format (if notoc? "@anchor{%s}\n" "@node %s\n")
+                (org-texinfo--get-node headline info))
+        (format command full-text)
+        contents))))))
 
 (defun org-texinfo-format-headline-default-function
   (todo _todo-type priority text tags)
   "Default format function for a headline.
 See `org-texinfo-format-headline-function' for details."
-  (concat (when todo (format "@strong{%s} " todo))
-         (when priority (format "@emph{#%s} " priority))
+  (concat (and todo (format "@strong{%s} " todo))
+         (and priority (format "@emph{#%s} " priority))
          text
-         (when tags (format " :%s:" (mapconcat 'identity tags ":")))))
+         (and tags (concat " " (org-make-tag-string tags)))))
 
 ;;;; Inline Src Block
 
@@ -964,7 +955,7 @@ See `org-texinfo-format-inlinetask-function' for details."
         (concat (when todo (format "@strong{%s} " todo))
                 (when priority (format "#%c " priority))
                 title
-                (when tags (format ":%s:" (mapconcat #'identity tags ":"))))))
+                (when tags (org-make-tag-string tags)))))
     (format "@center %s\n\n%s\n" full-title contents)))
 
 ;;;; Italic
@@ -1262,13 +1253,23 @@ contextual information."
                  (if (string-prefix-p "@" i) i (concat "@" i))))
         (table-type (plist-get attr :table-type))
         (type (org-element-property :type plain-list))
+        (enum
+         (cond ((not (eq type 'ordered)) nil)
+               ((plist-member attr :enum) (plist-get attr :enum))
+               (t
+                ;; Texinfo only supports initial counters, i.e., it
+                ;; cannot change the numbering mid-list.
+                (let ((first-item (car (org-element-contents plain-list))))
+                  (org-element-property :counter first-item)))))
         (list-type (cond
                     ((eq type 'ordered) "enumerate")
                     ((eq type 'unordered) "itemize")
                     ((member table-type '("ftable" "vtable")) table-type)
                     (t "table"))))
     (format "@%s\n%s@end %s"
-           (if (eq type 'descriptive) (concat list-type " " indic) list-type)
+           (cond ((eq type 'descriptive) (concat list-type " " indic))
+                 (enum (format "%s %s" list-type enum))
+                 (t list-type))
            contents
            list-type)))
 
@@ -1298,8 +1299,13 @@ contextual information."
     (when (plist-get info :preserve-breaks)
       (setq output (replace-regexp-in-string
                    "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output)))
-    ;; Return value.
-    output))
+    ;; Reverse sentence ending.  A sentence can end with a capital
+    ;; letter.  Use non-breaking space if it shouldn't.
+    (let ((case-fold-search nil))
+      (replace-regexp-in-string
+       "[A-Z]\\([.?!]\\)\\(?:[])]\\|'\\{1,2\\}\\)?\\(?: \\|$\\)"
+       "@\\1"
+       output nil nil 1))))
 
 ;;;; Planning
 
@@ -1349,11 +1355,12 @@ holding contextual information."
   "Transcode a QUOTE-BLOCK element from Org to Texinfo.
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
-  (let* ((title (org-element-property :name quote-block))
-        (start-quote (concat "@quotation"
-                             (if title
-                                 (format " %s" title)))))
-    (format "%s\n%s@end quotation" start-quote contents)))
+  (let ((tag (org-export-read-attribute :attr_texinfo quote-block :tag))
+       (author (org-export-read-attribute :attr_texinfo quote-block :author)))
+    (format "@quotation%s\n%s%s\n@end quotation"
+           (if tag (concat " " tag) "")
+           contents
+           (if author (concat "\n@author " author) ""))))
 
 ;;;; Radio Target
 
@@ -1372,9 +1379,12 @@ contextual information."
 CONTENTS holds the contents of the section.  INFO is a plist
 holding contextual information."
   (let ((parent (org-export-get-parent-headline section)))
-    (when parent                       ;ignore very first section
+    (when parent   ;first section is handled in `org-texinfo-template'
       (org-trim
-       (concat contents "\n" (org-texinfo-make-menu parent info))))))
+       (concat contents
+              "\n"
+              (and (not (org-export-excluded-from-toc-p parent info))
+                   (org-texinfo-make-menu parent info)))))))
 
 ;;;; Special Block
 
diff --git a/lisp/org/ox.el b/lisp/org/ox.el
index 0ae1e45..5b4134e 100644
--- a/lisp/org/ox.el
+++ b/lisp/org/ox.el
@@ -73,6 +73,7 @@
 
 (require 'cl-lib)
 (require 'ob-exp)
+(require 'ol)
 (require 'org-element)
 (require 'org-macro)
 (require 'tabulated-list)
@@ -1499,7 +1500,7 @@ Assume buffer is in Org mode.  Narrowing, if any, is 
ignored."
                         (cond
                          ;; Options in `org-export-special-keywords'.
                          ((equal key "SETUPFILE")
-                          (let* ((uri (org-unbracket-string "\"" "\"" 
(org-trim val)))
+                          (let* ((uri (org-strip-quotes (org-trim val)))
                                  (uri-is-url (org-file-url-p uri))
                                  (uri (if uri-is-url
                                           uri
@@ -1650,7 +1651,7 @@ an alist where associations are (VARIABLE-NAME VALUE)."
                                      "BIND")
                               (push (read (format "(%s)" val)) alist)
                             ;; Enter setup file.
-                            (let* ((uri (org-unbracket-string "\"" "\"" val))
+                            (let* ((uri (org-strip-quotes val))
                                    (uri-is-url (org-file-url-p uri))
                                    (uri (if uri-is-url
                                             uri
@@ -2007,17 +2008,18 @@ Return a string."
                                  ;; normalized first.
                                  (org-element-normalize-contents
                                   data
-                                  ;; When normalizing contents of the
-                                  ;; first paragraph in an item or
-                                  ;; a footnote definition, ignore
-                                  ;; first line's indentation: there is
-                                  ;; none and it might be misleading.
-                                  (when (eq type 'paragraph)
-                                    (and
-                                     (eq (car (org-element-contents parent))
-                                         data)
-                                     (memq (org-element-type parent)
-                                           '(footnote-definition item)))))))
+                                  ;; When normalizing first paragraph
+                                  ;; of an item or
+                                  ;; a footnote-definition, ignore
+                                  ;; first line's indentation.
+                                  (and
+                                   (eq type 'paragraph)
+                                   (memq (org-element-type parent)
+                                         '(footnote-definition item))
+                                   (eq (car (org-element-contents parent))
+                                       data)
+                                   (eq (org-element-property :pre-blank parent)
+                                       0)))))
                               "")))
                        (broken-link-handler
                         (funcall transcoder data
@@ -2672,10 +2674,7 @@ The function assumes BUFFER's major mode is `org-mode'."
                                    (quote ,val))
                              vars))))))
         ;; Whole buffer contents.
-        (insert
-         ,(org-with-wide-buffer
-           (buffer-substring-no-properties
-            (point-min) (point-max))))
+        (insert ,(org-with-wide-buffer (buffer-string)))
         ;; Narrowing.
         ,(if (org-region-active-p)
              `(narrow-to-region ,(region-beginning) ,(region-end))
@@ -2921,56 +2920,47 @@ returned by the function."
       '(entity bold italic latex-environment latex-fragment strike-through
               subscript superscript underline)
     (lambda (datum)
-      (let ((new
-            (cl-case (org-element-type datum)
-              ;; ... entities...
-              (entity
-               (and (not (plist-get info :with-entities))
-                    (list (concat
-                           (org-export-expand datum nil)
-                           (make-string
-                            (or (org-element-property :post-blank datum) 0)
-                            ?\s)))))
-              ;; ... emphasis...
-              ((bold italic strike-through underline)
-               (and (not (plist-get info :with-emphasize))
-                    (let ((marker (cl-case (org-element-type datum)
-                                    (bold "*")
-                                    (italic "/")
-                                    (strike-through "+")
-                                    (underline "_"))))
-                      (append
-                       (list marker)
-                       (org-element-contents datum)
-                       (list (concat
-                              marker
-                              (make-string
-                               (or (org-element-property :post-blank datum)
-                                   0)
-                               ?\s)))))))
-              ;; ... LaTeX environments and fragments...
-              ((latex-environment latex-fragment)
-               (and (eq (plist-get info :with-latex) 'verbatim)
-                    (list (org-export-expand datum nil))))
-              ;; ... sub/superscripts...
-              ((subscript superscript)
-               (let ((sub/super-p (plist-get info :with-sub-superscript))
-                     (bracketp (org-element-property :use-brackets-p datum)))
-                 (and (or (not sub/super-p)
-                          (and (eq sub/super-p '{}) (not bracketp)))
-                      (append
-                       (list (concat
-                              (if (eq (org-element-type datum) 'subscript)
-                                  "_"
-                                "^")
-                              (and bracketp "{")))
-                       (org-element-contents datum)
-                       (list (concat
-                              (and bracketp "}")
-                              (and (org-element-property :post-blank datum)
-                                   (make-string
-                                    (org-element-property :post-blank datum)
-                                    ?\s)))))))))))
+      (let* ((type (org-element-type datum))
+            (post-blank
+             (pcase (org-element-property :post-blank datum)
+               (`nil nil)
+               (n (make-string n (if (eq type 'latex-environment) ?\n ?\s)))))
+            (new
+             (cl-case type
+               ;; ... entities...
+               (entity
+                (and (not (plist-get info :with-entities))
+                     (list (concat (org-export-expand datum nil)
+                                   post-blank))))
+               ;; ... emphasis...
+               ((bold italic strike-through underline)
+                (and (not (plist-get info :with-emphasize))
+                     (let ((marker (cl-case type
+                                     (bold "*")
+                                     (italic "/")
+                                     (strike-through "+")
+                                     (underline "_"))))
+                       (append
+                        (list marker)
+                        (org-element-contents datum)
+                        (list (concat marker post-blank))))))
+               ;; ... LaTeX environments and fragments...
+               ((latex-environment latex-fragment)
+                (and (eq (plist-get info :with-latex) 'verbatim)
+                     (list (concat (org-export-expand datum nil)
+                                   post-blank))))
+               ;; ... sub/superscripts...
+               ((subscript superscript)
+                (let ((sub/super-p (plist-get info :with-sub-superscript))
+                      (bracketp (org-element-property :use-brackets-p datum)))
+                  (and (or (not sub/super-p)
+                           (and (eq sub/super-p '{}) (not bracketp)))
+                       (append
+                        (list (concat (if (eq type 'subscript) "_" "^")
+                                      (and bracketp "{")))
+                        (org-element-contents datum)
+                        (list (concat (and bracketp "}")
+                                      post-blank)))))))))
        (when new
          ;; Splice NEW at DATUM location in parse tree.
          (dolist (e new (org-element-extract-element datum))
@@ -3042,20 +3032,23 @@ Return code as a string."
         ;; Run first hook with current back-end's name as argument.
         (run-hook-with-args 'org-export-before-processing-hook
                             (org-export-backend-name backend))
-        ;; Include files, delete comments and expand macros.
         (org-export-expand-include-keyword)
         (org-export--delete-comment-trees)
         (org-macro-initialize-templates)
-        (org-macro-replace-all
-         (append org-macro-templates org-export-global-macros)
-         nil parsed-keywords)
-        ;; Refresh buffer properties and radio targets after
-        ;; potentially invasive previous changes.  Likewise, do it
-        ;; again after executing Babel code.
+        (org-macro-replace-all (append org-macro-templates
+                                       org-export-global-macros)
+                               parsed-keywords)
+        ;; Refresh buffer properties and radio targets after previous
+        ;; potentially invasive changes.
         (org-set-regexps-and-options)
         (org-update-radio-target-regexp)
+        ;;  Possibly execute Babel code.  Re-run a macro expansion
+        ;;  specifically for {{{results}}} since inline source blocks
+        ;;  may have generated some more.  Refresh buffer properties
+        ;;  and radio targets another time.
         (when org-export-use-babel
           (org-babel-exp-process-buffer)
+          (org-macro-replace-all '(("results" . "$1")) parsed-keywords)
           (org-set-regexps-and-options)
           (org-update-radio-target-regexp))
         ;; Run last hook with current back-end's name as argument.
@@ -3090,29 +3083,6 @@ Return code as a string."
           (dolist (filter (plist-get info :filter-options))
             (let ((result (funcall filter info backend-name)))
               (when result (setq info result)))))
-        ;; Expand export-specific set of macros: {{{author}}},
-        ;; {{{date(FORMAT)}}}, {{{email}}} and {{{title}}}.  It must
-        ;; be done once regular macros have been expanded, since
-        ;; parsed keywords may contain one of them.
-        (org-macro-replace-all
-         (list
-          (cons "author" (org-element-interpret-data (plist-get info :author)))
-          (cons "date"
-                (let* ((date (plist-get info :date))
-                       (value (or (org-element-interpret-data date) "")))
-                  (if (and (consp date)
-                           (not (cdr date))
-                           (eq (org-element-type (car date)) 'timestamp))
-                      (format "(eval (if (org-string-nw-p \"$1\") %s %S))"
-                              (format "(org-timestamp-format '%S \"$1\")"
-                                      (org-element-copy (car date)))
-                              value)
-                    value)))
-          (cons "email" (org-element-interpret-data (plist-get info :email)))
-          (cons "title" (org-element-interpret-data (plist-get info :title)))
-          (cons "results" "$1"))
-         'finalize
-         parsed-keywords)
         ;; Parse buffer.
         (setq tree (org-element-parse-buffer nil visible-only))
         ;; Prune tree from non-exported elements and transform
@@ -3238,7 +3208,7 @@ locally for the subtree through node properties."
            (org-entry-put
             node "EXPORT_OPTIONS" (mapconcat 'identity items " "))
          (while items
-           (insert "#+OPTIONS:")
+           (insert "#+options:")
            (let ((width 10))
              (while (and items
                          (< (+ width (length (car items)) 1) fill-column))
@@ -3264,7 +3234,7 @@ locally for the subtree through node properties."
        (if subtreep (org-entry-put node (concat "EXPORT_" (car key)) val)
          (insert
           (format "#+%s:%s\n"
-                  (car key)
+                  (downcase (car key))
                   (if (org-string-nw-p val) (format " %s" val) ""))))))))
 
 (defun org-export-expand-include-keyword (&optional included dir footnotes)
@@ -3275,7 +3245,8 @@ avoid infinite recursion.  Optional argument DIR is the 
current
 working directory.  It is used to properly resolve relative
 paths.  Optional argument FOOTNOTES is a hash-table used for
 storing and resolving footnotes.  It is created automatically."
-  (let ((case-fold-search t)
+  (let ((includer-file (buffer-file-name (buffer-base-buffer)))
+       (case-fold-search t)
        (file-prefix (make-hash-table :test #'equal))
        (current-prefix 0)
        (footnotes (or footnotes (make-hash-table :test #'equal)))
@@ -3298,11 +3269,16 @@ storing and resolving footnotes.  It is created 
automatically."
            (beginning-of-line)
            ;; Extract arguments from keyword's value.
            (let* ((value (org-element-property :value element))
-                  (ind (org-get-indentation))
+                  (ind (current-indentation))
                   location
+                  (coding-system-for-read
+                   (or (and (string-match ":coding +\\(\\S-+\\)>" value)
+                            (prog1 (intern (match-string 1 value))
+                              (setq value (replace-match "" nil nil value))))
+                       coding-system-for-read))
                   (file
-                   (and (string-match
-                         "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)" value)
+                   (and (string-match "^\\(\".+?\"\\|\\S-+\\)\\(?:\\s-+\\|$\\)"
+                                      value)
                         (prog1
                             (save-match-data
                               (let ((matched (match-string 1 value)))
@@ -3311,9 +3287,8 @@ storing and resolving footnotes.  It is created 
automatically."
                                   (setq location (match-string 2 matched))
                                   (setq matched
                                         (replace-match "" nil nil matched 1)))
-                                (expand-file-name
-                                 (org-unbracket-string "\"" "\"" matched)
-                                 dir)))
+                                (expand-file-name (org-strip-quotes matched)
+                                                  dir)))
                           (setq value (replace-match "" nil nil value)))))
                   (only-contents
                    (and (string-match ":only-contents *\\([^: \r\t\n]\\S-*\\)?"
@@ -3388,10 +3363,12 @@ storing and resolving footnotes.  It is created 
automatically."
                       (insert
                        (org-export--prepare-file-contents
                         file lines ind minlevel
-                        (or
-                         (gethash file file-prefix)
-                         (puthash file (cl-incf current-prefix) file-prefix))
-                        footnotes)))
+                        (or (gethash file file-prefix)
+                            (puthash file
+                                     (cl-incf current-prefix)
+                                     file-prefix))
+                        footnotes
+                        includer-file)))
                     (org-export-expand-include-keyword
                      (cons (list file lines) included)
                      (file-name-directory file)
@@ -3468,8 +3445,34 @@ Return a string of lines to be included in the format 
expected by
                       (while (< (point) end) (cl-incf counter) (forward-line))
                       counter))))))))
 
+(defun org-export--update-included-link (file-dir includer-dir)
+  "Update relative file name of link at point, if possible.
+
+FILE-DIR is the directory of the file being included.
+INCLUDER-DIR is the directory of the file where the inclusion is
+going to happen.
+
+Move point after the link."
+  (let* ((link (org-element-link-parser))
+        (path (org-element-property :path link)))
+    (if (or (not (string= "file" (org-element-property :type link)))
+           (file-remote-p path)
+           (file-name-absolute-p path))
+       (goto-char (org-element-property :end link))
+      (let ((new-path (file-relative-name (expand-file-name path file-dir)
+                                         includer-dir))
+           (new-link (org-element-copy link))
+           (contents (and (org-element-property :contents-begin link)
+                          (buffer-substring
+                           (org-element-property :contents-begin link)
+                           (org-element-property :contents-end link)))))
+       (org-element-put-property new-link :path new-path)
+       (delete-region (org-element-property :begin link)
+                      (org-element-property :end link))
+       (insert (org-element-link-interpreter new-link contents))))))
+
 (defun org-export--prepare-file-contents
-    (file &optional lines ind minlevel id footnotes)
+    (file &optional lines ind minlevel id footnotes includer)
   "Prepare contents of FILE for inclusion and return it as a string.
 
 When optional argument LINES is a string specifying a range of
@@ -3491,7 +3494,10 @@ This is useful to avoid conflicts when more than one Org 
file
 with footnotes is included in a document.
 
 Optional argument FOOTNOTES is a hash-table to store footnotes in
-the included document."
+the included document.
+
+Optional argument INCLUDER is the file name where the inclusion
+is to happen."
   (with-temp-buffer
     (insert-file-contents file)
     (when lines
@@ -3507,6 +3513,42 @@ the included document."
                    (forward-line (1- lend))
                    (point))))
        (narrow-to-region beg end)))
+    ;; Adapt all file links within the included document that contain
+    ;; relative paths in order to make these paths relative to the
+    ;; base document, or absolute.
+    (when includer
+      (let ((file-dir (file-name-directory file))
+           (includer-dir (file-name-directory includer)))
+       (unless (file-equal-p file-dir includer-dir)
+         (goto-char (point-min))
+         (unless (eq major-mode 'org-mode)
+           (let ((org-inhibit-startup t)) (org-mode))) ;set regexps
+         (let ((regexp (concat org-link-plain-re "\\|" org-link-angle-re)))
+           (while (re-search-forward org-link-any-re nil t)
+             (let ((link (save-excursion
+                           (forward-char -1)
+                           (save-match-data (org-element-context)))))
+               (when (eq 'link (org-element-type link))
+                 ;; Look for file links within link's description.
+                 ;; Org doesn't support such construct, but
+                 ;; `org-export-insert-image-links' may activate
+                 ;; them.
+                 (let ((contents-begin
+                        (org-element-property :contents-begin link))
+                       (begin (org-element-property :begin link)))
+                   (when contents-begin
+                     (save-excursion
+                       (goto-char (org-element-property :contents-end link))
+                       (while (re-search-backward regexp contents-begin t)
+                         (save-match-data
+                           (org-export--update-included-link
+                            file-dir includer-dir))
+                         (goto-char (match-beginning 0)))))
+                   ;; Update current link, if necessary.
+                   (when (string= "file" (org-element-property :type link))
+                     (goto-char begin)
+                     (org-export--update-included-link
+                      file-dir includer-dir))))))))))
     ;; Remove blank lines at beginning and end of contents.  The logic
     ;; behind that removal is that blank lines around include keyword
     ;; override blank lines in included file.
@@ -3665,18 +3707,24 @@ will become the empty string."
                (cdr (nreverse (cons (funcall prepare-value s) result))))))))
     (if property (plist-get attributes property) attributes)))
 
-(defun org-export-get-caption (element &optional shortp)
+(defun org-export-get-caption (element &optional short)
   "Return caption from ELEMENT as a secondary string.
 
-When optional argument SHORTP is non-nil, return short caption,
-as a secondary string, instead.
+When optional argument SHORT is non-nil, return short caption, as
+a secondary string, instead.
 
 Caption lines are separated by a white space."
-  (let ((full-caption (org-element-property :caption element)) caption)
-    (dolist (line full-caption (cdr caption))
-      (let ((cap (funcall (if shortp 'cdr 'car) line)))
-       (when cap
-         (setq caption (nconc (list " ") (copy-sequence cap) caption)))))))
+  (let ((full-caption (org-element-property :caption element))
+       (get (if short #'cdr #'car))
+       caption)
+    (dolist (line full-caption)
+      (pcase (funcall get line)
+       (`nil nil)
+       (c
+        (setq caption
+              (nconc (list " ")
+                     (copy-sequence c) caption)))))
+    (cdr caption)))
 
 
 ;;;; For Derived Back-ends
@@ -4010,19 +4058,19 @@ inherited from parent headlines and FILETAGS keywords."
        ;; Add FILETAGS keywords and return results.
        (org-uniquify (append (plist-get info :filetags) current-tag-list))))))
 
-(defun org-export-get-node-property (property blob &optional inherited)
-  "Return node PROPERTY value for BLOB.
+(defun org-export-get-node-property (property datum &optional inherited)
+  "Return node PROPERTY value for DATUM.
 
-PROPERTY is an upcase symbol (i.e. `:COOKIE_DATA').  BLOB is an
+PROPERTY is an upcase symbol (e.g., `:COOKIE_DATA').  DATUM is an
 element or object.
 
 If optional argument INHERITED is non-nil, the value can be
 inherited from a parent headline.
 
 Return value is a string or nil."
-  (let ((headline (if (eq (org-element-type blob) 'headline) blob
-                   (org-export-get-parent-headline blob))))
-    (if (not inherited) (org-element-property property blob)
+  (let ((headline (if (eq (org-element-type datum) 'headline) datum
+                   (org-export-get-parent-headline datum))))
+    (if (not inherited) (org-element-property property datum)
       (let ((parent headline))
        (catch 'found
          (while parent
@@ -4120,6 +4168,9 @@ meant to be translated with `org-export-data' or alike."
 ;; specified id or custom-id in parse tree, the path to the external
 ;; file with the id.
 ;;
+;; `org-export-resolve-link' searches for the destination of a link
+;; within the parsed tree and returns the element.
+;;
 ;; `org-export-resolve-coderef' associates a reference to a line
 ;; number in the element it belongs, or returns the reference itself
 ;; when the element isn't numbered.
@@ -4150,7 +4201,7 @@ The function ignores links with an implicit type (e.g.,
       (let ((protocol (org-link-get-parameter type :export)))
        (and (functionp protocol)
             (funcall protocol
-                     (org-link-unescape (org-element-property :path link))
+                     (org-element-property :path link)
                      desc
                      backend))))))
 
@@ -4207,8 +4258,8 @@ structure of RULES.
 
 Return modified DATA."
   (let ((link-re (format "\\`\\(?:%s\\|%s\\)\\'"
-                        org-plain-link-re
-                        org-angle-link-re))
+                        org-link-plain-re
+                        org-link-angle-re))
        (case-fold-search t))
     (org-element-map data 'link
       (lambda (l)
@@ -4314,7 +4365,7 @@ as returned by `org-export-search-cells'."
   (let ((targets (org-export-search-cells datum)))
     (and targets (cl-some (lambda (cell) (member cell targets)) cells))))
 
-(defun org-export-resolve-fuzzy-link (link info)
+(defun org-export-resolve-fuzzy-link (link info &rest pseudo-types)
   "Return LINK destination.
 
 INFO is a plist holding contextual information.
@@ -4331,10 +4382,14 @@ Return value can be an object or an element:
 
 - Otherwise, throw an error.
 
+PSEUDO-TYPES are pseudo-elements types, i.e., elements defined
+specifically in an export back-end, that could have a name
+affiliated keyword.
+
 Assume LINK type is \"fuzzy\".  White spaces are not
 significant."
   (let* ((search-cells (org-export-string-to-search-cell
-                       (org-link-unescape (org-element-property :path link))))
+                       (org-element-property :path link)))
         (link-cache (or (plist-get info :resolve-fuzzy-link-cache)
                         (let ((table (make-hash-table :test #'eq)))
                           (plist-put info :resolve-fuzzy-link-cache table)
@@ -4343,7 +4398,7 @@ significant."
     (if (not (eq cached 'not-found)) cached
       (let ((matches
             (org-element-map (plist-get info :parse-tree)
-                (cons 'target org-element-all-elements)
+                (append pseudo-types '(target) org-element-all-elements)
               (lambda (datum)
                 (and (org-export-match-search-cell-p datum search-cells)
                      datum)))))
@@ -4402,11 +4457,36 @@ has type \"radio\"."
             radio))
       info 'first-match)))
 
+(defun org-export-resolve-link (link info)
+  "Return LINK destination.
+
+LINK is a string or a link object.
+
+INFO is a plist holding contextual information.
+
+Return value can be an object or an element:
+
+- If LINK path matches an ID or a custom ID, return the headline.
+
+- If LINK path matches a fuzzy link, return its destination.
+
+- Otherwise, throw an error."
+  ;; Convert string links to link objects.
+  (when (stringp link)
+    (setq link (with-temp-buffer
+                (save-excursion
+                  (insert (org-link-make-string link)))
+                (org-element-link-parser))))
+  (pcase (org-element-property :type link)
+    ((or "custom-id" "id") (org-export-resolve-id-link link info))
+    ("fuzzy" (org-export-resolve-fuzzy-link link info))
+    (_ (signal 'org-link-broken (list (org-element-property :path link))))))
+
 (defun org-export-file-uri (filename)
   "Return file URI associated to FILENAME."
   (cond ((string-prefix-p "//" filename) (concat "file:" filename))
        ((not (file-name-absolute-p filename)) filename)
-       ((org-file-remote-p filename) (concat "file:/" filename))
+       ((file-remote-p filename) (concat "file:/" filename))
        (t
         (let ((fullname (expand-file-name filename)))
           (concat (if (string-prefix-p "/" fullname) "file://" "file:///")
@@ -4449,9 +4529,19 @@ REFERENCE is a number representing a reference, as 
returned by
 DATUM is either an element or an object.  INFO is the current
 export state, as a plist.
 
-This function checks `:crossrefs' property in INFO for search
-cells matching DATUM before creating a new reference.  Returned
-reference consists of alphanumeric characters only."
+References for the current document are stored in
+`:internal-references' property.  Its value is an alist with
+associations of the following types:
+
+  (REFERENCE . DATUM) and (SEARCH-CELL . ID)
+
+REFERENCE is the reference string to be used for object or
+element DATUM.  SEARCH-CELL is a search cell, as returned by
+`org-export-search-cells'.  ID is a number or a string uniquely
+identifying DATUM within the document.
+
+This function also checks `:crossrefs' property for search cells
+matching DATUM before creating a new reference."
   (let ((cache (plist-get info :internal-references)))
     (or (car (rassq datum cache))
        (let* ((crossrefs (plist-get info :crossrefs))
@@ -4861,26 +4951,32 @@ same column as TABLE-CELL, or nil."
                      (plist-put info :table-cell-width-cache table)
                      table)))
         (width-vector (or (gethash table cache)
-                          (puthash table (make-vector columns 'empty) cache)))
-        (value (aref width-vector column)))
-    (if (not (eq value 'empty)) value
-      (let (cookie-width)
-       (dolist (row (org-element-contents table)
-                    (aset width-vector column cookie-width))
-         (when (org-export-table-row-is-special-p row info)
-           ;; In a special row, try to find a width cookie at COLUMN.
-           (let* ((value (org-element-contents
-                          (elt (org-element-contents row) column)))
-                  (cookie (car value)))
-             ;; The following checks avoid expanding unnecessarily
-             ;; the cell with `org-export-data'.
-             (when (and value
-                        (not (cdr value))
-                        (stringp cookie)
-                        (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" cookie)
-                        (match-string 1 cookie))
-               (setq cookie-width
-                     (string-to-number (match-string 1 cookie)))))))))))
+                          (puthash table (make-vector columns 'empty) cache))))
+    ;; Table rows may not have the same number of cells.  Extend
+    ;; WIDTH-VECTOR appropriately if we encounter a row larger than
+    ;; expected.
+    (when (>= column (length width-vector))
+      (setq width-vector
+           (vconcat width-vector
+                    (make-list (- (1+ column) (length width-vector))
+                               'empty)))
+      (puthash table width-vector cache))
+    (pcase (aref width-vector column)
+      (`empty
+       (catch 'found
+        (dolist (row (org-element-contents table))
+          (when (org-export-table-row-is-special-p row info)
+            ;; In a special row, try to find a width cookie at
+            ;; COLUMN.  The following checks avoid expanding
+            ;; unnecessarily the cell with `org-export-data'.
+            (pcase (org-element-contents
+                    (elt (org-element-contents row) column))
+              (`(,(and (pred stringp) cookie))
+               (when (string-match "\\`<[lrc]?\\([0-9]+\\)>\\'" cookie)
+                 (let ((w (string-to-number (match-string 1 cookie))))
+                   (throw 'found (aset width-vector column w))))))))
+        (aset width-vector column nil)))
+      (value value))))
 
 (defun org-export-table-cell-alignment (table-cell info)
   "Return TABLE-CELL contents alignment.
@@ -4905,6 +5001,15 @@ Possible values are `left', `right' and `center'."
                      table)))
         (align-vector (or (gethash table cache)
                           (puthash table (make-vector columns nil) cache))))
+    ;; Table rows may not have the same number of cells.  Extend
+    ;; ALIGN-VECTOR appropriately if we encounter a row larger than
+    ;; expected.
+    (when (>= column (length align-vector))
+      (setq align-vector
+           (vconcat align-vector
+                    (make-list (- (1+ column) (length align-vector))
+                               nil)))
+      (puthash table align-vector cache))
     (or (aref align-vector column)
        (let ((number-cells 0)
              (total-cells 0)
@@ -5231,10 +5336,12 @@ Footnote sections are ignored."
                     (+ (org-export-get-relative-level scope info) n))
                   limit))))
     (org-element-map (org-element-contents scope) 'headline
-      (lambda (headline)
-       (unless (org-element-property :footnote-section-p headline)
-         (let ((level (org-export-get-relative-level headline info)))
-           (and (<= level n) headline))))
+      (lambda (h)
+       (and (not (org-element-property :footnote-section-p h))
+            (not (equal "notoc"
+                        (org-export-get-node-property :UNNUMBERED h t)))
+            (>= n (org-export-get-relative-level h info))
+            h))
       info)))
 
 (defun org-export-collect-elements (type info &optional predicate)
@@ -5280,13 +5387,27 @@ Return a list of elements recognized as figures."
   (org-export-collect-elements 'paragraph info predicate))
 
 (defun org-export-collect-listings (info)
-  "Build a list of src blocks.
+  "Build a list of source blocks.
 
 INFO is a plist used as a communication channel.
 
-Return a list of src-block elements with a caption."
+Return a list of `src-block' elements with a caption."
   (org-export-collect-elements 'src-block info))
 
+(defun org-export-excluded-from-toc-p (headline info)
+  "Non-nil if HEADLINE should be excluded from tables of contents.
+
+INFO is a plist used as a communication channel.
+
+Note that such headlines are already excluded from
+`org-export-collect-headlines'.  Therefore, this function is not
+necessary if you only need to list headlines in the table of
+contents.  However, it is useful if some additional processing is
+required on headlines excluded from table of contents."
+  (or (org-element-property :footnote-section-p headline)
+      (org-export-low-level-p headline info)
+      (equal "notoc" (org-export-get-node-property :UNNUMBERED headline t))))
+
 (defun org-export-toc-entry-backend (parent &rest transcoders)
   "Return an export back-end appropriate for table of contents entries.
 
@@ -5707,6 +5828,7 @@ them."
      ("ja" :default "前ページからの続き")
      ("nl" :default "Vervolg van vorige pagina")
      ("pt" :default "Continuação da página anterior")
+     ("pt_BR" :html "Continua&ccedil;&atilde;o da p&aacute;gina anterior" 
:ascii "Continuacao da pagina anterior" :default "Continuação da página 
anterior")
      ("ru" :html 
"(&#1055;&#1088;&#1086;&#1076;&#1086;&#1083;&#1078;&#1077;&#1085;&#1080;&#1077;)"
       :utf-8 "(Продолжение)")
      ("sl" :default "Nadaljevanje s prejšnje strani"))
@@ -5720,11 +5842,13 @@ them."
      ("ja" :default "次ページに続く")
      ("nl" :default "Vervolg op volgende pagina")
      ("pt" :default "Continua na página seguinte")
+     ("pt_BR" :html "Continua na pr&oacute;xima p&aacute;gina" :ascii 
"Continua na proxima pagina" :default "Continua na próxima página")
      ("ru" :html 
"(&#1055;&#1088;&#1086;&#1076;&#1086;&#1083;&#1078;&#1077;&#1085;&#1080;&#1077; 
&#1089;&#1083;&#1077;&#1076;&#1091;&#1077;&#1090;)"
       :utf-8 "(Продолжение следует)")
      ("sl" :default "Nadaljevanje na naslednji strani"))
     ("Created"
      ("cs" :default "Vytvořeno")
+     ("pt_BR" :default "Criado em")
      ("sl" :default "Ustvarjeno"))
     ("Date"
      ("ar" :default "بتاريخ")
@@ -5779,6 +5903,7 @@ them."
      ("es" :default "Figura")
      ("et" :default "Joonis")
      ("is" :default "Mynd")
+     ("it" :default "Figura")
      ("ja" :default "図" :html "&#22259;")
      ("no" :default "Illustrasjon")
      ("nb" :default "Illustrasjon")
@@ -5796,6 +5921,7 @@ them."
      ("et" :default "Joonis %d:")
      ("fr" :default "Figure %d :" :html "Figure&nbsp;%d&nbsp;:")
      ("is" :default "Mynd %d")
+     ("it" :default "Figura %d:")
      ("ja" :default "図%d: " :html "&#22259;%d: ")
      ("no" :default "Illustrasjon %d")
      ("nb" :default "Illustrasjon %d")
@@ -5844,6 +5970,7 @@ them."
      ("ja" :default "ソースコード目次")
      ("no" :default "Dataprogrammer")
      ("nb" :default "Dataprogrammer")
+     ("pt_BR" :html "&Iacute;ndice de Listagens" :default "Índice de 
Listagens" :ascii "Indice de Listagens")
      ("ru" :html "&#1057;&#1087;&#1080;&#1089;&#1086;&#1082; 
&#1088;&#1072;&#1089;&#1087;&#1077;&#1095;&#1072;&#1090;&#1086;&#1082;"
       :utf-8 "Список распечаток")
      ("sl" :default "Seznam programskih izpisov")
@@ -5857,11 +5984,12 @@ them."
      ("et" :default "Tabelite nimekiri")
      ("fr" :default "Liste des tableaux")
      ("is" :default "Töfluskrá" :html "T&ouml;fluskr&aacute;")
+     ("it" :default "Indice delle tabelle")
      ("ja" :default "表目次")
      ("no" :default "Tabeller")
      ("nb" :default "Tabeller")
      ("nn" :default "Tabeller")
-     ("pt_BR" :default "Índice de Tabelas" :ascii "Indice de Tabelas")
+     ("pt_BR" :html "&Iacute;ndice de Tabelas" :default "Índice de Tabelas" 
:ascii "Indice de Tabelas")
      ("ru" :html "&#1057;&#1087;&#1080;&#1089;&#1086;&#1082; 
&#1090;&#1072;&#1073;&#1083;&#1080;&#1094;"
       :utf-8 "Список таблиц")
      ("sl" :default "Seznam tabel")
@@ -5875,6 +6003,7 @@ them."
      ("es" :default "Listado de programa")
      ("et" :default "Loend")
      ("fr" :default "Programme" :html "Programme")
+     ("it" :default "Listato")
      ("ja" :default "ソースコード")
      ("no" :default "Dataprogram")
      ("nb" :default "Dataprogram")
@@ -5891,10 +6020,11 @@ them."
      ("es" :default "Listado de programa %d")
      ("et" :default "Loend %d")
      ("fr" :default "Programme %d :" :html "Programme&nbsp;%d&nbsp;:")
+     ("it" :default "Listato %d :")
      ("ja" :default "ソースコード%d:")
      ("no" :default "Dataprogram %d")
      ("nb" :default "Dataprogram %d")
-     ("pt_BR" :default "Listagem %d")
+     ("pt_BR" :default "Listagem %d:")
      ("ru" :html 
"&#1056;&#1072;&#1089;&#1087;&#1077;&#1095;&#1072;&#1090;&#1082;&#1072; %d.:"
       :utf-8 "Распечатка %d.:")
      ("sl" :default "Izpis programa %d")
@@ -5902,19 +6032,24 @@ them."
     ("References"
      ("ar" :default "المراجع")
      ("cs" :default "Reference")
-     ("fr" :ascii "References" :default "Références")
      ("de" :default "Quellen")
      ("es" :default "Referencias")
+     ("fr" :ascii "References" :default "Références")
+     ("it" :default "Riferimenti")
+     ("pt_BR" :html "Refer&ecirc;ncias" :default "Referências" :ascii 
"Referencias")
      ("sl" :default "Reference"))
     ("See figure %s"
      ("cs" :default "Viz obrázek %s")
      ("fr" :default "cf. figure %s"
       :html "cf.&nbsp;figure&nbsp;%s" :latex "cf.~figure~%s")
+     ("it" :default "Vedi figura %s")
+     ("pt_BR" :default "Veja a figura %s")
      ("sl" :default "Glej sliko %s"))
     ("See listing %s"
      ("cs" :default "Viz program %s")
      ("fr" :default "cf. programme %s"
       :html "cf.&nbsp;programme&nbsp;%s" :latex "cf.~programme~%s")
+     ("pt_BR" :default "Veja a listagem %s")
      ("sl" :default "Glej izpis programa %s"))
     ("See section %s"
      ("ar" :default "انظر قسم %s")
@@ -5924,6 +6059,7 @@ them."
      ("es" :ascii "Vea seccion %s" :html "Vea secci&oacute;n %s" :default "Vea 
sección %s")
      ("et" :html "Vaata peat&#252;kki %s" :utf-8 "Vaata peatükki %s")
      ("fr" :default "cf. section %s")
+     ("it" :default "Vedi sezione %s")
      ("ja" :default "セクション %s を参照")
      ("pt_BR" :html "Veja a se&ccedil;&atilde;o %s" :default "Veja a seção %s"
       :ascii "Veja a secao %s")
@@ -5935,6 +6071,8 @@ them."
      ("cs" :default "Viz tabulka %s")
      ("fr" :default "cf. tableau %s"
       :html "cf.&nbsp;tableau&nbsp;%s" :latex "cf.~tableau~%s")
+     ("it" :default "Vedi tabella %s")
+     ("pt_BR" :default "Veja a tabela %s")
      ("sl" :default "Glej tabelo %s"))
     ("Table"
      ("ar" :default "جدول")
@@ -5944,6 +6082,7 @@ them."
      ("et" :default "Tabel")
      ("fr" :default "Tableau")
      ("is" :default "Tafla")
+     ("it" :default "Tabella")
      ("ja" :default "表" :html "&#34920;")
      ("pt_BR" :default "Tabela")
      ("ru" :html "&#1058;&#1072;&#1073;&#1083;&#1080;&#1094;&#1072;"
@@ -5958,11 +6097,12 @@ them."
      ("et" :default "Tabel %d")
      ("fr" :default "Tableau %d :")
      ("is" :default "Tafla %d")
+     ("it" :default "Tabella %d:")
      ("ja" :default "表%d:" :html "&#34920;%d:")
      ("no" :default "Tabell %d")
      ("nb" :default "Tabell %d")
      ("nn" :default "Tabell %d")
-     ("pt_BR" :default "Tabela %d")
+     ("pt_BR" :default "Tabela %d:")
      ("ru" :html "&#1058;&#1072;&#1073;&#1083;&#1080;&#1094;&#1072; %d.:"
       :utf-8 "Таблица %d.:")
      ("sl" :default "Tabela %d")
@@ -6003,9 +6143,9 @@ them."
      ("es" :default "Referencia desconocida")
      ("et" :default "Tundmatu viide")
      ("fr" :ascii "Destination inconnue" :default "Référence inconnue")
+     ("it" :default "Riferimento sconosciuto")
      ("ja" :default "不明な参照先")
-     ("pt_BR" :default "Referência desconhecida"
-      :ascii "Referencia desconhecida")
+     ("pt_BR" :html "Refer&ecirc;ncia desconhecida" :default "Referência 
desconhecida" :ascii "Referencia desconhecida")
      ("ru" :html 
"&#1053;&#1077;&#1080;&#1079;&#1074;&#1077;&#1089;&#1090;&#1085;&#1072;&#1103; 
&#1089;&#1089;&#1099;&#1083;&#1082;&#1072;"
       :utf-8 "Неизвестная ссылка")
      ("sl" :default "Neznana referenca")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]