changeset 83531:a387c138b28e

Merged from emacs@sv.gnu.org Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-305 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-306 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-307 Update from CVS: lispref/display.texi (Forcing Redisplay): Fix typo. * emacs@sv.gnu.org/emacs--devo--0--patch-308 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-309 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-310 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-311 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-312 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-313 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-314 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-315 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-316 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-317 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-318 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-319 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-320 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-321 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-322 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-323 lisp/play/cookie1.el (cookie): Work properly when there's only one entry * emacs@sv.gnu.org/emacs--devo--0--patch-324 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-325 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-326 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-327 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-328 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-329 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-330 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-105 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-106 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-107 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-108 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-109 Clean up merge mistakes * emacs@sv.gnu.org/gnus--rel--5.10--patch-110 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-571
author Karoly Lorentey <lorentey@elte.hu>
date Tue, 27 Jun 2006 15:06:36 +0000
parents 46b1096093f5 (current diff) 5b1bf37e044d (diff)
children b19aaf4ab0ee
files ChangeLog admin/FOR-RELEASE etc/TODO lisp/ChangeLog lisp/bindings.el lisp/cus-start.el lisp/ediff-wind.el lisp/emulation/viper-util.el lisp/files.el lisp/mh-e/ChangeLog lisp/mh-e/mh-e.el lisp/net/rcirc.el lisp/progmodes/gdb-ui.el lisp/simple.el lisp/term/mac-win.el lisp/term/xterm.el lisp/vc.el lispref/ChangeLog man/ChangeLog man/emacs.texi man/frames.texi man/info.texi man/mh-e.texi src/.gdbinit src/callproc.c src/dispextern.h src/dispnew.c src/fileio.c src/lread.c src/macfns.c src/macterm.c src/window.c src/xdisp.c src/xfns.c src/xterm.c src/xterm.h
diffstat 99 files changed, 4787 insertions(+), 1691 deletions(-) [+]
line wrap: on
line diff
--- a/AUTHORS	Mon Jun 12 07:27:12 2006 +0000
+++ b/AUTHORS	Tue Jun 27 15:06:36 2006 +0000
@@ -20,7 +20,7 @@
 
 Agustin Martin: changed flyspell.el ispell.el
 
-Aidan Kehoe: changed mm-util.el erc.el
+Aidan Kehoe: changed lread.c mm-util.el erc.el objects.texi
 
 Ake Stenhoff: wrote imenu.el
 and changed cc-mode.el perl-mode.el
@@ -112,9 +112,9 @@
 Andreas Schwab: changed Makefile.in files.el lisp.h xdisp.c alloc.c
   configure.in fns.c coding.c dired.el editfns.c info.el eval.c fileio.c
   print.c simple.el buffer.c minibuf.c xterm.c emacs.c keyboard.c
-  process.c and 442 other files
-
-Andreas Seltenreich: changed nnweb.el gnus-art.el url-http.el
+  process.c and 443 other files
+
+Andreas Seltenreich: changed nnweb.el gnus-art.el gnus-ml.el url-http.el
 
 Andrew Choi: wrote mac-win.el
 and changed macterm.c mac.c macfns.c INSTALL macmenu.c darwin.h macterm.h
@@ -209,9 +209,8 @@
   mh-scan.el mh-seq.el mh-show.el mh-utils.el mh-xface.el
 and changed mh-customize.el mh-index.el MH-E-NEWS mh-alias.el Makefile
   mh-identity.el mh-pick.el README mh-speed.el mh-init.el mh-junk.el
-  mh-acros.el mh-e.texi mh-gnus.el mh-unit.el mh-inc.el
-  mh-xemacs-compat.el mh-print.el mh-search.el Makefile.in image.el
-  and 89 other files
+  mh-e.texi mh-acros.el mh-gnus.el mh-unit.el mh-inc.el mh-search.el
+  mh-xemacs-compat.el mh-print.el Makefile.in image.el and 89 other files
 
 Bjorn Solberg: changed nnimap.el
 
@@ -305,9 +304,9 @@
   url-file.el url-handlers.el url-http.el url-nfs.el
 
 Chong Yidong: changed custom.el cus-edit.el display.texi longlines.el
-  files.texi text.texi FOR-RELEASE custom.texi files.el simple.el
-  cus-theme.el wid-edit.el xterm.c frames.texi info.el mouse.el anti.texi
-  dired.texi image.c keymaps.texi misc.texi and 112 other files
+  files.el files.texi text.texi FOR-RELEASE custom.texi simple.el
+  cus-theme.el wid-edit.el xterm.c frames.texi info.el mouse.el xfns.c
+  anti.texi dired.texi image.c keymaps.texi and 115 other files
 
 Chris Hanson: changed xscheme.el scheme.el xterm.c hpux.h x11term.c
   hp9000s300.h keyboard.c process.c texinfmt.el emacsclient.c sort.el
@@ -374,8 +373,8 @@
 
 Damon Anton Permezel: wrote hanoi.el (public domain)
 
-Dan Christensen: changed nnfolder.el gnus-art.el gnus-group.el
-  gnus-score.el gnus-sum.el nnmail.el
+Dan Christensen: changed gnus-sum.el nnfolder.el gnus-art.el
+  gnus-group.el gnus-score.el nnmail.el
 
 Dan Nicolaescu: wrote iris-ansi.el romanian.el
 and changed term.el hideshow.el xterm.el isearch.el icon.el cus-edit.el
@@ -383,7 +382,7 @@
   vhdl-mode.el bindings.el compile.el dabbrev.el grep.el ibuffer.el
   imenu.el outline.el replace.el and 153 other files
 
-Daniel Brockman: changed cus-start.el format-spec.el ibuffer.el
+Daniel Brockman: changed cus-start.el format-spec.el ibuffer.el rcirc.el
 
 Daniel Laliberte: wrote cl-specs.el cust-print.el edebug.el hideif.el
   isearch.el
@@ -415,8 +414,6 @@
 
 Darrin B. Jewell: changed etags.c lisp.h
 
-Dave Edmondson: changed message.el
-
 Dave Lambert: changed sol2-5.h xfns.c xterm.c xterm.h
 
 Dave Love: wrote autoarg.el autoconf.el benchmark.el cfengine.el
@@ -601,10 +598,10 @@
 Eli Tziperman: wrote rmail-spam-filter.el
 
 Eli Zaretskii: wrote codepage.el rxvt.el tty-colors.el
-and changed msdos.c Makefile.in files.el info.el makefile.w32-in fileio.c
+and changed msdos.c Makefile.in files.el makefile.w32-in info.el fileio.c
   startup.el mainmake.v2 config.bat menu-bar.el pc-win.el simple.el
   internal.el msdos.h xfaces.c rmail.el dosfns.c frame.c faces.el emacs.c
-  frame.el and 501 other files
+  frame.el and 503 other files
 
 Emanuele Giaquinta: changed rxvt.el configure.in etags.c frame.el
   sh-script.el text.texi
@@ -701,7 +698,7 @@
   erc-button.el erc-goodies.el erc-nets.el erc-ring.el Makefile
   erc-pcomplete.el erc-backend.el erc-ibuffer.el erc-match.el
   erc-nickserv.el erc-page.el erc-speedbar.el keymaps.texi message.el
-  os.texi saveplace.el
+  os.texi saveplace.el xterm.c xterm.h
 
 Francois Felix Ingrand: changed gnus-salt.el
 
@@ -936,6 +933,8 @@
 
 Jack Twilley: changed message.el
 
+Jacob Morzinski: changed mh-comp.el
+
 Jacques Duthen: changed ps-print.el
 
 Jaeyoun Chung: changed hangul3.el hanja3.el gnus-mule.el hangul.el
@@ -1241,7 +1240,8 @@
   and 37 other files
 
 Karl Chen: changed files.el align.el cc-vars.el gnus-art.el help-mode.el
-  jka-cmpr-hook.el perl-mode.el python.el tex-mode.el vc-svn.el
+  jka-cmpr-hook.el make-mode.el perl-mode.el python.el tex-mode.el
+  vc-svn.el
 
 Karl Eichwalder: changed Makefile.in add-log.el bookmark.el dired-aux.el
   dired.el info.el menu-bar.el midnight.el po.el
@@ -1266,9 +1266,9 @@
 
 Katsumi Yamaoka: wrote canlock.el
 and changed gnus-art.el message.el gnus-sum.el gnus.texi mm-decode.el
-  mm-view.el gnus-util.el gnus-msg.el gnus.el lpath.el mm-util.el
+  mm-view.el gnus-util.el gnus-msg.el gnus.el mm-util.el lpath.el
   gnus-start.el gnus-group.el mm-uu.el dgnushack.el gnus-agent.el nntp.el
-  mml.el nnrss.el rfc2047.el spam.el and 68 other files
+  mml.el nnrss.el rfc2047.el rfc2231.el and 69 other files
 
 Kaveh R. Ghazi: changed delta88k.h xterm.c
 
@@ -1342,17 +1342,17 @@
 
 Kevin Ryde: wrote info-xref.el
 and changed info-look.el info.el gnus-art.el gnus-sum.el mailcap.el
-  text.texi MORE.STUFF cc-align.el compile.texi display.texi em-alias.el
-  em-dirs.el em-hist.el em-unix.el emacs-lisp-intro.texi ffap.el
-  frames.texi glossary.texi gnus.texi makeinfo.el mule.el
-  and 10 other files
-
-Kim F. Storm: wrote bindat.el cua-base.el cua-gmrk.el cua-rect.el ido.el
-  keypad.el kmacro.el
+  text.texi MORE.STUFF cc-align.el cmdargs.texi compile.texi display.texi
+  em-alias.el em-dirs.el em-hist.el em-unix.el emacs-lisp-intro.texi
+  ffap.el frames.texi glossary.texi gnus.texi makeinfo.el
+  and 12 other files
+
+Kim F. Storm: wrote animage.el bindat.el cua-base.el cua-gmrk.el
+  cua-rect.el ido.el keypad.el kmacro.el
 and changed xdisp.c dispextern.h simple.el xterm.c process.c window.c
-  keyboard.c w32term.c subr.el fringe.c lisp.h macterm.c dispnew.c
-  alloc.c xfaces.c fns.c xterm.h display.texi info.el xfns.c Makefile.in
-  and 219 other files
+  keyboard.c w32term.c subr.el fringe.c dispnew.c lisp.h macterm.c
+  alloc.c xfaces.c display.texi fns.c xterm.h info.el xfns.c .gdbinit
+  and 221 other files
 
 Kim-Minh Kaplan: changed gnus-picon.el gnus-sum.el gnus-start.el
   gnus-win.el gnus-xmas.el gnus.texi message.el nndraft.el nnml.el
@@ -1563,6 +1563,8 @@
 
 Martin Buchholz: changed etags.c
 
+Martin J. Reed: changed ldap.el
+
 Martin Kretzschmar: changed gnus-spec.el
 
 Martin Larose: changed message.el
@@ -1573,8 +1575,8 @@
 Martin Neitzel: changed sc.el
 
 Martin Rudalics: changed cus-edit.el wid-edit.el font-lock.el syntax.c
-  custom.el files.el find-func.el hideif.el info.el insdel.c lisp-mode.el
-  midnight.el mouse.el mwheel.el re-builder.el widget.el
+  custom.el fileio.c files.el find-func.el hideif.el info.el insdel.c
+  lisp-mode.el midnight.el mouse.el mwheel.el re-builder.el widget.el
 
 Martin Stjernholm: wrote cc-bytecomp.el
 and changed cc-engine.el cc-cmds.el cc-langs.el cc-defs.el cc-mode.el
@@ -1645,7 +1647,7 @@
 Michael D. Ernst: wrote reposition.el
 and changed dired-x.el uniquify.el ispell.el bibtex.el rmail.el dired.el
   simple.el dired-aux.el gud.el rmailsum.el bytecomp.el compare-w.el
-  fill.el shadow.el texnfo-upd.el vc.el allout.el comint.el complete.el
+  complete.el fill.el shadow.el texnfo-upd.el vc.el allout.el comint.el
   cust-print.el edebug.el and 29 other files
 
 Michael D. Prange: wrote fortran.el
@@ -1705,8 +1707,8 @@
 
 Michal Jankowski: changed insdel.c keyboard.c
 
-Micha,Ak(Bl Cadilhac: changed dispnew.c ispell.el make-mode.el print.c
-  process.c
+Micha,Ak(Bl Cadilhac: changed ispell.el dispnew.c make-mode.el pong.el
+  print.c process.c
 
 Michelangelo Grigni: wrote ffap.el
 and changed gnus-score.el
@@ -1741,7 +1743,7 @@
 and changed comint.el faces.el simple.el editfns.c xfaces.c info.el
   xdisp.c minibuf.c wid-edit.el xterm.c subr.el window.el cus-edit.el
   diff-mode.el dispextern.h xfns.c help.el lisp.h quick-install-emacs
-  textprop.c menu-bar.el and 239 other files
+  textprop.c menu-bar.el and 240 other files
 
 Miyashita Hisashi: changed ccl.c coding.c coding.h mule-cmds.el
   mule-conf.el mule.el pop3.el
@@ -1987,8 +1989,8 @@
 and changed ffap.el
 
 Ralf Angeli: wrote scroll-lock.el
-and changed comint.el flow-fill.el gnus-art.el killing.texi mm-view.el
-  smtpmail.el tex-mode.el window.c
+and changed tex-mode.el comint.el flow-fill.el gnus-art.el killing.texi
+  mm-view.el smtpmail.el window.c
 
 Ralf Fassel: changed dabbrev.el files.el fill.el iso-acc.el tar-mode.el
 
@@ -2012,8 +2014,8 @@
 and changed message.el gnus-art.el gnus.texi gnus-sum.el gnus.el
   gnus-group.el mml.el gnus-faq.texi gnus-score.el gnus-start.el
   gnus-util.el gnus-msg.el message.texi gnus-agent.el files.el mm-util.el
-  spam-report.el nnweb.el spam.el deuglify.el mm-decode.el
-  and 151 other files
+  spam-report.el nnweb.el spam.el FOR-RELEASE deuglify.el
+  and 152 other files
 
 Remek Trzaska: changed gnus-ems.el
 
@@ -2069,7 +2071,7 @@
 Robert Fenk: changed desktop.el
 
 Robert J. Chassell: wrote makeinfo.el texinfo.el texnfo-upd.el
-and changed texinfmt.el emacs.tex page-ext.el info.el loaddefs.el
+and changed texinfmt.el page-ext.el emacs.tex info.el loaddefs.el
   texinfo-update.el INSTALL case-table.el cl.texinfo
   emacs-lisp-intro.texi history.el informat.el latin-1.el latin-2.el
   latin-3.el latin-4.el page.el tex-mode.el texinfo.tex texinfo.texinfo
@@ -2101,10 +2103,10 @@
 and changed files.el find-file.el
 
 Romain Francoise: changed faq.texi ibuf-ext.el dired-x.el message.el
-  puresize.h replace.el compile.el files.texi gnus-fun.el help-fns.el
-  rcirc.el subr.el FOR-RELEASE Makefile.in antlr-mode.el bookmark.el
-  buffer.c comint.el diary-lib.el dired.el doclicense.texi
-  and 92 other files
+  puresize.h replace.el compile.el files.texi gnus-fun.el gnus.texi
+  help-fns.el rcirc.el subr.el FOR-RELEASE Makefile.in antlr-mode.el
+  bookmark.el buffer.c comint.el diary-lib.el dired.el
+  and 107 other files
 
 Roman Belenov: changed which-func.el
 
@@ -2231,7 +2233,7 @@
 Stefan Monnier: wrote bibtex.el cvs-status.el diff-mode.el log-edit.el
   log-view.el pcvs-defs.el pcvs-info.el pcvs-parse.el pcvs-util.el
   reveal.el smerge-mode.el
-and changed vc.el font-lock.el newcomment.el pcvs.el subr.el lisp.h
+and changed vc.el font-lock.el pcvs.el newcomment.el subr.el lisp.h
   keyboard.c tex-mode.el keymap.c alloc.c fill.el easy-mmode.el simple.el
   compile.el info.el regex.c files.el syntax.c vc-hooks.el xdisp.c
   vc-cvs.el and 497 other files
@@ -2334,10 +2336,10 @@
 Theodore Jump: changed w32-win.el w32faces.c
 
 Thien-Thi Nguyen: wrote hideshow.el make-mms-derivative.el
-and changed ewoc.el info.el processes.texi zone.el Makefile.in fileio.c
-  scheme.el vc.el dcl-mode.el display.texi lisp-mode.el pcvs.el sysdep.c
-  MORE.STUFF TUTORIAL.it TUTORIAL.ja bindat.el diary-lib.el diff-mode.el
-  dired.el ebuff-menu.el and 114 other files
+and changed ewoc.el info.el processes.texi zone.el Makefile.in vc.el
+  fileio.c scheme.el dcl-mode.el display.texi files.el lisp-mode.el
+  pcvs.el sysdep.c MORE.STUFF TUTORIAL.it TUTORIAL.ja bindat.el
+  diary-lib.el diff-mode.el dired.el and 115 other files
 
 Thierry Emery: changed kinsoku.el timezone.el url-http.el wid-edit.el
 
@@ -2497,7 +2499,8 @@
 Wim Nieuwenhuizen: changed TUTORIAL.nl
 
 Wlodzimierz Bzyl: wrote ogonek.el
-and changed latin-pre.el refcard-pl.ps refcard-pl.tex survival.tex
+and changed latin-pre.el pl-refcard.ps pl-refcard.tex refcard-pl.ps
+  refcard-pl.tex survival.tex
 
 Wolfgang Glas: changed unexsgi.c
 
@@ -2520,7 +2523,7 @@
 
 Yamamoto Mitsuharu: changed macterm.c macfns.c mac-win.el mac.c macterm.h
   macgui.h image.c macmenu.c macselect.c keyboard.c xdisp.c makefile.MPW
-  emacs.c xfaces.c config.h darwin.h macos.texi Makefile.in dispextern.h
+  emacs.c macos.texi xfaces.c config.h darwin.h Makefile.in dispextern.h
   w32term.c Info.plist and 55 other files
 
 Yann Dirson: changed imenu.el
@@ -2529,6 +2532,8 @@
 
 Yoshiki Hayashi: changed texinfmt.el nnheader.el
 
+Yoshinori Koseki: changed fontset.el
+
 Yutaka Niibe: changed indent.c xdisp.c configure.in Makefile.in dispnew.c
   sysdep.c config.in dired.el emacs.c fill.el fns.c gmalloc.c gnu-linux.h
   indent.h process.c simple.el term.c window.c
@@ -2539,6 +2544,8 @@
 
 Zoran Milojevic: changed avoid.el
 
+,AI(Bric Jacoboni: changed fr-refcard.tex
+
 Local Variables:
 coding: iso-2022-7bit
 End:
--- a/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,11 @@
+2006-06-25  Kim F. Storm  <storm@cua.dk>
+
+	* AUTHORS: Regenerate.
+
+2006-06-24  Eli Zaretskii  <eliz@gnu.org>
+
+	* INSTALL: Mention www.nongnu.org pages that list free Unicode fonts.
+
 2006-06-05  Kim F. Storm  <storm@cua.dk>
 
 	* AUTHORS: Regenerate.
@@ -19,7 +27,7 @@
 
 2006-04-01  Eli Zaretskii  <eliz@gnu.org>
 
-	* configure: Regenerated.
+	* configure: Regenerate.
 
 2006-04-01  Emanuele Giaquinta  <emanuele.giaquinta@gmail.com>  (tiny change)
 
@@ -46,7 +54,7 @@
 
 2006-02-14  Eli Zaretskii  <eliz@gnu.org>
 
-	* configure: Regenerated.
+	* configure: Regenerate.
 
 2006-02-14  Richard M. Stallman  <rms@gnu.org>
 
@@ -55,7 +63,7 @@
 2006-01-31  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
 
 	* configure.in: Require GTK 2.4 or newer.
-	* configure: Regenerate
+	* configure: Regenerate.
 
 2006-01-29  Michael Olson  <mwolson@gnu.org>
 
@@ -92,7 +100,7 @@
 
 2005-12-25  Giorgos Keramidas  <keramida@ceid.upatras.gr>  (tiny change)
 
-	* configure.in: use amdx86-64 for freebsd on x86_64.
+	* configure.in: Use amdx86-64 for freebsd on x86_64.
 
 2005-11-22  Romain Francoise  <romain@orebokech.com>
 
--- a/INSTALL	Mon Jun 12 07:27:12 2006 +0000
+++ b/INSTALL	Tue Jun 27 15:06:36 2006 +0000
@@ -153,8 +153,8 @@
 
 * Extra fonts
 
-At first, Emacs does not include fonts and does not install them.  You
-must do this yourself.
+The Emacs distribution does not include fonts and does not install
+them.  You must do that yourself.
 
 To take proper advantage of Emacs 21's mule-unicode charsets, you need
 a suitable font.  For `Unicode' (ISO 10646) fonts for X, see
@@ -179,6 +179,10 @@
 Unicode characters are available from <URL:ftp://ftp.x.org/contrib/fonts/>
 and <URL:ftp://ftp.xfree86.org/pub/mirror/X.Org/contrib/fonts/>.
 
+Finally, the Web pages <URL:http://www.nongnu.org/freefont/index.html>
+and <URL:http://www.nongnu.org/freefont/resources.html> list a large
+number of free Unicode fonts.
+
 * GNU/Linux development packages
 
 Many GNU/Linux systems do not come with development packages by
--- a/admin/FOR-RELEASE	Mon Jun 12 07:27:12 2006 +0000
+++ b/admin/FOR-RELEASE	Tue Jun 27 15:06:36 2006 +0000
@@ -39,8 +39,11 @@
 
 * BUGS
 
-** We need a way a Lisp file encoded in iso-2022 can assure
-reliable decoding regardless of user options.
+** text_property_stickiness can be called with a POS value that is before BEGV.
+
+text_property_stickiness is called from get_pos_property,
+which is called from find_field, which is called from
+various user-level functions in editfns.c.
 
 ** JD Smith's 17 Apr 2006 bug report that CVS operations
 get mysterious unreproducible failures.
@@ -149,7 +152,7 @@
 etc/TUTORIAL             rms
 etc/TUTORIAL.bg          Ognyan Kulev <ogi@fmi.uni-sofia.bg>
 etc/TUTORIAL.cn
-etc/TUTORIAL.cs          Pavel Janík <Pavel@Janik.cz>
+etc/TUTORIAL.cs          Pavel Janík <Pavel@Janik.cz>
 etc/TUTORIAL.de          Werner LEMBERG <wl@gnu.org>
 etc/TUTORIAL.es          Marcelo Toledo
 etc/TUTORIAL.fr          ttn
@@ -161,7 +164,7 @@
 etc/TUTORIAL.pt_BR       Marcelo Toledo
 etc/TUTORIAL.ro
 etc/TUTORIAL.ru          Alex Ott <alexott@gmail.com>
-etc/TUTORIAL.sk          Pavel Janík <Pavel@Janik.cz>
+etc/TUTORIAL.sk          Pavel Janík <Pavel@Janik.cz>
 etc/TUTORIAL.sl          Primoz PETERLIN <primoz.peterlin@biofiz.mf.uni-lj.si>
 etc/TUTORIAL.sv          Mats Lidell <matsl@contactor.se>
 etc/TUTORIAL.th          Virach Sornlertlamvanich <virach@tcllab.org>
--- a/etc/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,38 @@
+2006-06-24  Nick Roberts  <nickrob@snap.net.nz>
+
+	* NEWS: Remove duplicate entries.
+
+2006-06-23  Carsten Dominik  <dominik@science.uva.nl>
+
+	* orgcard.tex (section{LaTeX and cdlatex-mode}): New section.
+
+2006-06-23  Kim F. Storm  <storm@cua.dk>
+
+	* DEBUG: Mention `pv variable' to print value of Lisp variables.
+	Mention `xpr' and fix example to use it.  Add section describing
+	commands such as `pit' that are useful for debugging redisplay
+	related problems.
+
+2006-06-22  Kim F. Storm  <storm@cua.dk>
+
+	* HELLO (Local Variables): Move to end of file.
+
+2006-06-20  Bill Wohler  <wohler@newt.com>
+
+	Release MH-E version 8.0.1.
+
+	* NEWS, MH-E-NEWS: Update for MH-E release 8.0.1.
+
+2006-06-19  Carsten Dominik  <dominik@science.uva.nl>
+
+	* orgcard.tex (section{Clocking Time}): Add new clocking
+	commands.
+	(section{Structure Editing}): Add global archiving command.
+
+2006-06-14  Thien-Thi Nguyen  <ttn@gnu.org>
+
+	* yow.lines: Delete existing data; add a new entry.
+
 2006-06-09  W$,1 b(Bodek Bzyl  <matwb@univ.gda.pl>
 
 	* pl-refcard.ps: Regenerate.
--- a/etc/DEBUG	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/DEBUG	Tue Jun 27 15:06:36 2006 +0000
@@ -20,6 +20,8 @@
 ** When you debug Emacs with GDB, you should start it in the directory
 where the executable was made.  That directory has a .gdbinit file
 that defines various "user-defined" commands for debugging Emacs.
+(These commands are described below under "Examining Lisp object
+values" and "Debugging Emacs Redisplay problems".)
 
 ** When you are trying to analyze failed assertions, it will be
 essential to compile Emacs either completely without optimizations or
@@ -84,7 +86,9 @@
 
 You can also use `pp value' to print the emacs value directly.
 
-Note: It is not a good idea to try `pr' or `pp' if you know that Emacs
+To see the current value of a Lisp Variable, use `pv variable'.
+
+Note: It is not a good idea to try `pr', `pp', or `pv' if you know that Emacs
 is in deep trouble: its stack smashed (e.g., if it encountered SIGSEGV
 due to stack overflow), or crucial data structures, such as `obarray',
 corrupted, etc.  In such cases, the Emacs subroutine called by `pr'
@@ -97,10 +101,17 @@
 use `pr'.  Instead, use `s' to step out of the system call.  Then
 Emacs will be between instructions and capable of handling `pr'.
 
-If you can't use `pr' command, for whatever reason, you can fall back
-on lower-level commands.  Use the `xtype' command to print out the
-data type of the last data value.  Once you know the data type, use
-the command that corresponds to that type.  Here are these commands:
+If you can't use `pr' command, for whatever reason, you can use the
+`xpr' command to print out the data type and value of the last data
+value, For example:
+
+    p it->object
+    xpr
+
+You may also analyze data values using lower-level commands.  Use the
+`xtype' command to print out the data type of the last data value.
+Once you know the data type, use the command that corresponds to that
+type.  Here are these commands:
 
     xint xptr xwindow xmarker xoverlay xmiscfree xintfwd xboolfwd xobjfwd
     xbufobjfwd xkbobjfwd xbuflocal xbuffer xsymbol xstring xvector xframe
@@ -132,11 +143,11 @@
 
     (gdb) p frame
     $1 = 139854428
-    (gdb) xtype
+    (gdb) xpr
     Lisp_Vectorlike
     PVEC_FRAME
-    (gdb) xframe
     $2 = (struct frame *) 0x8560258
+    "emacs@localhost"
     (gdb) p *$
     $3 = {
       size = 1073742931,
@@ -144,13 +155,12 @@
       name = 140615219,
       [...]
     }
-    (gdb) p $3->name
-    $4 = 140615219
+
+Now we can use `pr' to print the frame parameters:
 
-Now we can use `pr' to print the name of the frame:
+    (gdb) pp $->param_alist
+    ((background-mode . light) (display-type . color) [...])
 
-    (gdb) pr
-    "emacs@steenrod.math.nwu.edu"
 
 The Emacs C code heavily uses macros defined in lisp.h.  So suppose
 we want the address of the l-value expression near the bottom of
@@ -245,15 +255,32 @@
 
    xsymbol
 
+** Debugging Emacs Redisplay problems
+
+The src/.gdbinit file defines many useful commands for dumping redisplay
+related data structures in a terse and user-friendly format:
+
+ `ppt' prints value of PT, narrowing, and gap in current buffer.
+ `pit' dumps the current display iterator `it'.
+ `pwin' dumps the current window 'win'.
+ `prow' dumps the current glyph_row `row'.
+ `pg' dumps the current glyph `glyph'.
+ `pgi' dumps the next glyph.
+ `pgrow' dumps all glyphs in current glyph_row `row'.
+ `pcursor' dumps current output_cursor.
+
+The above commands also exist in a version with an `x' suffix which
+takes an object of the relevant type as argument.
+
 ** Using GDB in Emacs
 
 Debugging with GDB in Emacs offers some advantages over the command line (See
 the GDB Graphical Interface node of the Emacs manual).  There are also some
 features available just for debugging Emacs:
 
-1) The command gud-pp isavailable on the tool bar (the `pp' icon) and allows
-   the user to print the s-expression of the variable at point, in the GUD
-   buffer.
+1) The command gud-pp is available on the tool bar (the `pp' icon) and
+   allows the user to print the s-expression of the variable at point,
+   in the GUD buffer.
 
 2) Pressing `p' on a component of a watch expression that is a lisp object
    in the speedbar prints its s-expression in the GUD buffer.
--- a/etc/HELLO	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/HELLO	Tue Jun 27 15:06:36 2006 +0000
@@ -64,10 +64,6 @@
 Russian ($,1(`(c(a(a(Z(X(Y(B)	$,1(7(T(`(P(R(a(b(R(c(Y(b(U(B!
 Maltese (il-Malti)	Bon$,1 A(Bu, Sa$,1 G G(Ba
 
-;;; Local Variables:
-;;; tab-width: 32
-;;; End:
-
 
 
 Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006
@@ -88,3 +84,8 @@
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+;;; Local Variables:
+;;; tab-width: 32
+;;; End:
--- a/etc/MH-E-NEWS	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/MH-E-NEWS	Tue Jun 27 15:06:36 2006 +0000
@@ -6,6 +6,35 @@
 are permitted in any medium without royalty provided the copyright
 notice and this notice are preserved.
 
+* Changes in MH-E 8.0.1
+
+Version 8.0.1 works around a couple of bugs in GNU mailutils, spost,
+and Windows. MH-E now requires the use of version 1.0 of mailutils due
+to a bug in the folder command.
+
+** Bug Fixes in MH-E 8.0.1
+
+*** Infinite Loop When Searching (mailutils)
+
+The GNU mailutils folder command displays output when a folder doesn't
+exist. MH-E didn't expect this and responded with an infinite loop
+during searches. While this bug has since been fixed in mailutils,
+MH-E has been modified to work anyway (closes SF #1499712).
+
+*** spost Doesn't Have -msgid or -mime Flags
+
+The post replacement spost does not support the -msgid or -mime flags.
+A new variable `mh-send-uses-spost-flag' was added to control the use
+of these flags (closes SF #1486726).
+
+*** <2> in Search Folders Illegal in Windows
+
+The <2> suffix to the search folder names contain illegal filename
+characters in Windows. These cause searches to fail on Windows. This
+has been fixed by changing the suffix to -2 (closes SF #1507002).
+
+
+
 * Changes in MH-E 8.0
 
 Version 8.0 supports GNU mailutils, S/MIME, picons, which-func-mode,
--- a/etc/NEWS	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/NEWS	Tue Jun 27 15:06:36 2006 +0000
@@ -379,10 +379,6 @@
 ** The default for the paper size (variable ps-paper-type) is taken
 from the locale.
 
-** The command `list-faces-display' now accepts a prefix arg.
-When passed, the function prompts for a regular expression and lists
-only faces matching this regexp.
-
 ** Mark command changes:
 
 +++
@@ -775,6 +771,14 @@
 ** Redisplay changes:
 
 +++
+*** Preemptive redisplay now adapts to current load and bandwidth.
+
+To avoid preempting redisplay on fast computers, networks, and displays,
+the arrival of new input is now performed at regular intervals during
+redisplay.  The new variable `redisplay-preemption-period' specifies
+the period; the default is to check for input every 0.1 seconds.
+
++++
 *** The mode line position information now comes before the major mode.
 When the file is maintained under version control, that information
 appears between the position information and the major mode.
@@ -1935,6 +1939,7 @@
 instead and point will be kept vertically fixed relative to window
 boundaries during scrolling.
 
++++
 ** The file t-mouse.el is now part of Emacs and provides access to mouse
 events from the console.  It still requires gpm to work but has been updated
 for Emacs 22. In particular, the mode-line is now position sensitive.
@@ -3143,7 +3148,7 @@
 ---
 ** MH-E changes.
 
-Upgraded to MH-E version 8.0.  There have been major changes since
+Upgraded to MH-E version 8.0.1.  There have been major changes since
 version 5.0.2; see MH-E-NEWS for details.
 
 ** Calendar changes:
@@ -4720,12 +4725,6 @@
 header line.
 
 +++
-*** New function `window-body-height'.
-
-This is like `window-height' but does not count the mode line
-or the header line.
-
-+++
 *** You can now make a window as short as one line.
 
 A window that is just one line tall does not display either a mode
@@ -4875,6 +4874,10 @@
 *** `sit-for' can now be called with args (SECONDS &optional NODISP).
 
 +++
+*** `sit-for' called with a negative SECONDS value now forces an
+immediate redisplay even if input is pending.
+
++++
 *** New function `force-window-update' can initiate a full redisplay of
 one or all windows.  Normally, this is not needed as changes in window
 contents are detected automatically.  However, certain implicit
--- a/etc/TODO	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/TODO	Tue Jun 27 15:06:36 2006 +0000
@@ -305,6 +305,8 @@
 
 ** Check what hooks would help Emacspeak -- see the defadvising in W3.
 
+** Add definitions for symbol properties, for documentation purposes.
+
 ** Add horizontal scroll bars.
 
 ** Provide an optional feature which computes a scroll bar slider's
--- a/etc/orgcard.tex	Mon Jun 12 07:27:12 2006 +0000
+++ b/etc/orgcard.tex	Tue Jun 27 15:06:36 2006 +0000
@@ -1,5 +1,5 @@
 % Reference Card for Org Mode
-\def\orgversionnumber{4.37}
+\def\orgversionnumber{4.39}
 \def\year{2006}
 %
 %**start of header
@@ -288,10 +288,8 @@
 
 \section{Motion}
 
-\key{next heading}{C-c C-n}
-\key{previous heading}{C-c C-p}
-\key{next heading, same level}{C-c C-f}
-\key{previous heading, same level}{C-c C-b}
+\key{next/previous heading}{C-c C-n/p}
+\key{next/previous heading, same level}{C-c C-f/b}
 \key{backward to higher level heading}{C-c C-u}
 \key{jump to another place in document}{C-c C-j}
 \key{previous/next plain list item}{S-UP/DOWN$^3$}
@@ -306,13 +304,18 @@
 \key{promote current subtree up one level}{M-S-LEFT}
 \key{demote current subtree down one level}{M-S-RIGHT}
 
-\key{move subtree/list item up}{M-S-UP}
-\key{move subtree/list item down}{M-S-DOWN}
+\key{move subtree/list item up/down}{M-S-UP/DOWN}
 \key{kill subtree}{C-c C-x C-w}
 \key{copy subtree}{C-c C-x M-w}
 \key{yank subtree}{C-c C-x C-y}
+\key{narrow buffer to current subtree}{C-x n s}
 
-\key{archive subtree}{C-c \$}
+\section{Archiving}
+
+\key{toggle ARCHIVE tag}{C-c C-x C-a}
+\metax{mark fully dine children}{C-u C-c C-x C-a}
+\key{move subtree to achive file}{C-c \$}
+\key{move all fully done children}{C-u C-c \$}
 To set archive location for current file, add a line like$^2$:
 \vskip -1mm
 \beginexample%
@@ -329,18 +332,8 @@
 %\key{agenda for the week}{C-c a$^1$}
 %\key{agenda for date at cursor}{C-c C-o}
 
-\section{Tags}
-
-\key{set tags for current heading}{C-c C-c}
-\key{realign tags in all headings}{C-u C-c C-c}
-\key{create sparse tree with matching tags}{C-c \\}
-\key{globally (agenda) match tags at cursor}{C-c C-o}
-
 \section{Tables}
 
-%Org-mode has its own built-in intuitive table editor with unique
-%capabilities.
-
 {\bf Creating a table}
 
 %\metax{insert a new Org-mode table}{M-x org-table-create}
@@ -466,6 +459,39 @@
 %\key{\kbd{vm://myself@some.where.org/folder\#id}}{\rm VM remote}
 
 
+\section{Remember-mode Integration}
+
+See the manual for how to make remember.el use Org-mode links and
+files.  The note-finishing command \kbd{C-c C-c} will first prompt for
+an org file. In the file, find a location with:
+
+\key{rotate subtree visibility}{TAB}
+\key{next heading}{DOWN}
+\key{previous heading}{UP}
+
+Insert the note with one of the following: 
+
+\key{as sublevel of heading at cursor}{RET}
+\key{right here (cursor not on heading)}{RET}
+\key{before current heading}{LEFT}
+\key{after current heading}{RIGHT}
+\key{shortcut to end of buffer (cursor at buf-start)}{RET}
+\key{Abort}{q}
+
+\section{Completion}
+
+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}
+
+
+\newcolumn
+\title{Org-Mode Reference Card (2/2)}
+
+\centerline{(for version \orgversionnumber)}
+
 \section{TODO Items}
 
 \key{rotate the state of the current item}{C-c C-t}
@@ -480,6 +506,13 @@
 \key{\kbd{\#+SEQ_TODO: TODO TRY BLUFF DONE}}{\rm todo workflow}
 \key{\kbd{\#+TYP_TODO: Phil home work DONE}}{\rm todo types}
 
+\section{Tags}
+
+\key{set tags for current heading}{C-c C-c}
+\key{realign tags in all headings}{C-u C-c C-c}
+\key{create sparse tree with matching tags}{C-c \\}
+\key{globally (agenda) match tags at cursor}{C-c C-o}
+
 \section{Timestamps}
 
 \key{prompt for date and insert timestamp}{C-c .}
@@ -502,18 +535,26 @@
 %\key{... forward/backward one month}{M-S-LEFT/RIGT}
 
 
-\newcolumn
-\title{Org-Mode Reference Card (2/2)}
-
-\centerline{(for version \orgversionnumber)}
-
 \section{Clocking Time}
 
 \key{start clock on current item}{C-c C-x C-i}
 \key{stop clock on current item}{C-c C-x C-o}
 \key{cancel current clock}{C-c C-x C-x}
+
 \key{display total subtree times}{C-c C-x C-d}
 \key{remove displayed times}{C-c C-c}
+\key{insert/update table with clock report}{C-c C-x C-r}
+
+\section{Dynamic Blocks}
+
+\key{update dynamic block at point}{C-c C-x C-u}
+\metax{update all dynamic blocks}{C-u C-c C-x C-u}
+
+\section{LaTeX and cdlatex-mode}
+
+\key{preview LaTeX fragment}{C-c C-x C-l}
+\key{Expand abbreviation (cdlatex-mode)}{TAB}
+\key{Insert/modify math symbol (cdlatex-mode)}{` / '}
 
 \section{Agenda Views}
 
@@ -565,6 +606,7 @@
 \key{change state of current TODO item}{t}
 \key{show tags of current headline}{T}
 \key{set tags for current headline}{:}
+\key{toggle ARCHIVE tag}{a}
 \key{set priority of current item}{p}
 \key{raise/lower priority of current item}{S-UP/DOWN$^3$}
 \key{display weighted priority of current item}{P}
@@ -577,7 +619,6 @@
 \key{Stop the clock (clock-out)}{O}
 \key{Cancel current clock}{X}
 
-\newcolumn
 
 {\bf Calendar commands}
 
@@ -593,6 +634,13 @@
 \key{quit agenda, remove agenda buffer}{q}
 \key{exit agenda, remove all agenda buffers}{x}
 
+\section{Calendar and Diary Integration}
+
+To include entries from the Emacs diary in your Org-mode agenda:
+\beginexample%
+(setq org-agenda-include-diary t)
+\endexample
+
 \section{Exporting and Publishing}
 
 Exporting creates files with extensions {\it .txt\/} and {\it .html\/}
@@ -629,18 +677,19 @@
 \key{language code for html}{\#+LANGUAGE:}
 \key{free text description of file}{\#+TEXT:}
 \key{... which can carry over multiple lines}{\#+TEXT:}
-\key{settings for the export process - see below}{\#+OPTIONS:}
+%\key{settings for the export process - see below}{\#+OPTIONS:}
+\key{settings for the export process}{\#+OPTIONS:}
 
-\key{set number of headline levels for export}{H:2}
-\key{turn on/off section numbers}{num:t}
-\key{turn on/off table of contents}{toc:t}
-\key{turn on/off linebreak preservation}{\\n:nil}
-\key{turn on/off quoted html tags}{@:t}
-\key{turn on/off fixed width sections}{::t}
-\key{turn on/off tables}{|:t}
-\key{turn on/off \TeX\ syntax for sub/super-scripts}{\^{}:t}
-\key{turn on/off emphasised text}{*:nil}
-\key{turn on/off \TeX\ macros}{TeX:t}
+%\key{set number of headline levels for export}{H:2}
+%\key{turn on/off section numbers}{num:t}
+%\key{turn on/off table of contents}{toc:t}
+%\key{turn on/off linebreak preservation}{\\n:nil}
+%\key{turn on/off quoted html tags}{@:t}
+%\key{turn on/off fixed width sections}{::t}
+%\key{turn on/off tables}{|:t}
+%\key{turn on/off \TeX\ syntax for sub/super-scripts}{\^{}:t}
+%\key{turn on/off emphasised text}{*:nil}
+%\key{turn on/off \TeX\ macros}{TeX:t}
 
 {\bf Comments: Text not being exported}
 
@@ -651,53 +700,20 @@
 
 \key{toggle COMMENT keyword on entry}{C-c ;}
 
-\section{Completion}
 
-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}
-
-\section{Calendar and Diary Integration}
-
-To include entries from the Emacs diary in your Org-mode agenda:
-\beginexample%
-(setq org-agenda-include-diary t)
-\endexample
-
-\section{Remember-mode Integration}
-
-See the manual for how to make remember.el use Org-mode links and
-files.  The note-finishing command \kbd{C-c C-c} will first prompt for
-an org file. In the file, find a location with:
+%\section{CUA and pc-select compatibility}%
 
-\key{rotate subtree visibility}{TAB}
-\key{next heading}{DOWN}
-\key{previous heading}{UP}
-
-Insert the note with one of the following: 
-
-\key{as sublevel of heading at cursor}{RET}
-\key{right here (cursor not on heading)}{RET}
-\key{before current heading}{LEFT}
-\key{after current heading}{RIGHT}
-\key{shortcut to end of buffer (cursor at buf-start)}{RET}
-\key{Abort}{q}
-
-\section{CUA and pc-select compatibility}
-
-Configure the variable {\tt org-CUA-compatibility} to make Org-mode
-avoid the \kbd{S-<cursor>} bindings used by these modes.  When set,
-Org-mode will change the following keybindings (also in the agenda
-buffer, but not during date selection). See note mark four$^3$
-throughout the reference card.
-%\vskip-mm
-\beginexample
-S-UP    $\to$ M-p             S-DOWN  $\to$ M-n
-S-LEFT  $\to$ M--             S-RIGHT $\to$ M-+
-S-RET   $\to$ C-S-RET
-\endexample
+%Configure the variable {\tt org-CUA-compatibility} to make Org-mode
+%avoid the \kbd{S-<cursor>} bindings used by these modes.  When set,
+%Org-mode will change the following keybindings (also in the agenda
+%buffer, but not during date selection). See note mark four$^3$
+%throughout the reference card.
+%%\vskip-mm
+%\beginexample
+%S-UP    $\to$ M-p             S-DOWN  $\to$ M-n
+%S-LEFT  $\to$ M--             S-RIGHT $\to$ M-+
+%S-RET   $\to$ C-S-RET
+%\endexample
 
 \section{Notes}
 $^1$ This is only a suggestion for a binding of this command.  Choose
Binary file etc/yow.lines has changed
--- a/lisp/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,10 +1,285 @@
+2006-06-25  Michael Albinus  <michael.albinus@gmx.de>
+
+	* net/rcompile.el (remote-compile): Replace ange-ftp based
+	implementation by Tramp functions.  Based on a patch published by
+	Marc Abramowitz <msabramo@gmail.com>.
+
+	* net/tramp.el (tramp-unload-tramp): Provide a doc string.
+
+2006-06-24  Yoshinori Koseki  <kose@meadowy.org>
+
+	* international/fontset.el (setup-default-fontset): Fix a typo in
+	the "Oriya-Akruti" registry name.
+
+2006-06-23  Lars Hansen <larsh@soem.dk>
+
+	* desktop.el (desktop-full-file-name): New function.
+	(desktop-kill, desktop-save, desktop-remove, desktop-read)
+	(desktop-revert): Use it.
+	(desktop-clear, desktop-save, desktop-remove): Add autoload cookie.
+	(desktop-after-read-hook): Add option list-buffers.
+	(desktop-locals-to-save): Add tab-width.
+	(desktop-save-mode, desktop-no-desktop-file-hook, desktop-save-hook):
+	Fix docstring.
+
+2006-06-23  Carsten Dominik  <dominik@science.uva.nl>
+
+	* textmodes/org.el (org-cdlatex-mode-map)
+	(org-cdlatex-texmathp-advice-is-done): New variables.
+	(org-cdlatex-mode): New minor mode.
+	(org-inside-LaTeX-fragment-p, org-try-cdlatex-tab): New functions.
+	(org-cdlatex-underscore-caret, org-cdlatex-math-modify): New commands.
+	(org-export-with-archived-trees): New option.
+	(org-open-file): Removed the call to `convert-standard-filename'.
+	(org-archive-tag, org-agenda-skip-archived-trees)
+	(org-cycle-open-archived-trees)
+	(org-sparse-tree-open-archived-trees): New options.
+	(org-cycle-hide-archived-subtrees, org-hide-archived-subtrees)
+	(org-toggle-tag, org-prepare-agenda-buffers, org-agenda-skip): New
+	functions.
+	(org-agenda-toggle-archive-tag, org-toggle-archive-tag): New commands.
+	(org-agenda-mode-map): Add binding of `org-agenda-toggle-archive-tag'.
+	(org-mode-map): Add binding for `org-toggle-archive-tag'.
+	(org-timeline, org-agenda-list, org-todo-list, org-tags-view):
+	Call `org-prepare-agenda-buffers'.
+	(org-occur, org-scan-tags): Call `org-hide-archived-subtrees'.
+	(org-file-apps, org-file-apps-defaults-gnu)
+	(org-file-apps-defaults-macosx, org-file-apps-defaults-windowsnt):
+	Handle remote files by forcing them to be opened in Emacs.
+
+2006-06-23  Andre Spiegel  <spiegel@gnu.org>
+
+	* vc.el (vc-diff-knows-L): New variable.
+	(vc-diff-internal): Use it to handle "diff" programs that don't
+	understand -L.  This works automatically, no user action is necessary.
+
+2006-06-23  Daniel Brockman  <daniel@brockman.se>
+
+	* net/rcirc.el (rcirc-default-user-full-name): Default to
+	`rcirc-default-user-name' instead of `rcirc-user-name' (which no
+	longer exists).
+	(rcirc-process-list): Check `buffer-live-p' before attempting to
+	switch to a buffer.
+
+2006-06-23  Ryan Yeske  <rcyeske@gmail.com>
+
+	* net/rcirc.el (rcirc-mode): Fix initialization of coding systems
+	based on rcirc-coding-system-alist.
+
+2006-06-23  Martin Rudalics  <rudalics@gmx.at>
+
+	* cus-edit.el (customize-apropos): A better error message.
+	(top level) <debug-ignored-errors>: Extend and update the list of
+	ignored error messages.
+
+2006-06-23  Michael Ernst  <mernst@alum.mit.edu>
+
+	* complete.el (PC-do-completion): Retain capitalization of user
+	input, when possible, even if completion-ignore-case is set.
+
+2006-06-23  Eli Zaretskii  <eliz@gnu.org>
+
+	* generic-x.el (bat-generic-mode): Support .cmd files.
+
+	* dos-w32.el (top level): Use find-file-not-found-functions
+	instead of the obsolete find-file-not-found-hooks.
+
+2006-06-22  Kim F. Storm  <storm@cua.dk>
+
+	* progmodes/grep.el (grep-mode-font-lock-keywords): Correct regexps
+	to recognize mode name containing submodes, such as Grep/lw.
+
+2006-06-21  Kim F. Storm  <storm@cua.dk>
+
+	* simple.el (line-move-1): Check for move-end-of-line instead of
+	end-of-line when setting temporary-goal-column.
+
+2006-06-21  Miles Bader  <miles@gnu.org>
+
+	* play/cookie1.el (cookie): Work properly when there's only one entry.
+
+2006-06-21  Nick Roberts  <nickrob@snap.net.nz>
+
+	* progmodes/gdb-ui.el (gdb-exited): Ensure overlay arrow gets killed.
+	(gdb-frame-handler): Generalize frame regexp for templates.
+
+2006-06-20  Glenn Morris  <rgm@gnu.org>
+
+	* calendar/appt.el (appt-display-format): Default value must be
+	one of the customize options.
+
+2006-06-20  Dan Nicolaescu  <dann@ics.uci.edu>
+
+	* term/xterm.el (terminal-init-xterm): Update key availability info.
+	Bind C-return.
+
+	* term.el (term-delete-lines, term-insert-lines): Clarify comments.
+
+2006-06-20  Chong Yidong  <cyd@stupidchicken.com>
+
+	* files.el (hack-local-variables): Run `hack-local-variables-hook'
+	whether or not a local variables list is defined.
+
+	* msb.el (msb): Move `sit-for' hack here to handle both
+	"mouse-down and drag" and "mouse-up and select" situations.
+	(mouse-select-buffer): Move `sit-for' hack to `msb'.
+
+2006-06-20  Kenichi Handa  <handa@m17n.org>
+
+	* international/characters.el (word-combining-categories):
+	Add entries for 2-byte Han characters.
+
+2006-06-19  Richard Stallman  <rms@gnu.org>
+
+	* bindings.el (mode-line-format): Save some mode line space.
+
+	* files.el (find-file-noselect): Improve the question wording.
+	(basic-save-buffer-2): Mask UMASK against 666.
+
+	* mouse.el (mouse-drag-vertical-line-rightward-window): New function.
+	(mouse-drag-vertical-line): Call it.
+
+	* cus-edit.el (customize-option, customize-option-other-window):
+	Error if SYMBOL is nil.
+
+2006-06-19  Carsten Dominik  <dominik@science.uva.nl>
+
+	* textmodes/org.el: Require noutline, also on XEmacs.
+	(org-end-of-subtree): Return point.
+	(org-dblock-start-re, org-dblock-end-re): New constants.
+	(org-create-dblock, org-prepare-dblock, org-map-dblocks)
+	(org-dblock-update, org-update-dblock, org-beginning-of-dblock)
+	(org-update-all-dblocks, org-find-dblock): New functions.
+	(org-collect-clock-time-entries): New function.
+	(org-html-handle-time-stamps): Never export CLOCK timeranges.
+	(org-fixup-indentation): Modified to deadl correctly with lines
+	starting with TAB.  Only one argument DIFF now.
+	(org-demote, org-promote): Call `org-fixup-indentation' with just
+	one argument, DIFF.
+	(org-mode): Don't mark buffer as modified when aligning tables.
+	(org-clock-sum): Don't mark buffer modified when adding time sum
+	properties.
+	(org-export-as-html): Added support for a link validation function.
+	(org-archive-all-done): New function.
+	(org-archive-subtree): New prefix argument.  When set, archive all
+	done subtrees in this buffer.
+	(org-remove-clock-overlays)
+	(org-remove-occur-highlights): Use `org-inhibit-highlight-removal'.
+	(org-inhibit-highlight-removal): New variable, for dynamic scoping.
+	(org-put-clock-overlay): Don't swallow last headline character
+	when displaying overlay.
+	(org-store-link): Link to `image-mode' with just the file name.
+
+2006-06-18  Michael Kifer  <kifer@cs.stonybrook.edu>
+
+	* viper-cmd.el (viper-special-read-and-insert-char):
+	Use read-key-sequence.
+	(viper-after-change-undo-hook): Misc enhancements.
+	(viper-after-change-undo-hook): New hook.
+	(viper-undo): Use viper-after-change-undo-hook.
+	(viper-add-newline-at-eob-if-necessary): Widen before making changes.
+	(viper-next-line-at-bol): If point is on a widget or a button, simulate
+	clicking on that widget/button.
+
+	* viper.el (viper-mode): Allow a separate cursor color in Emacs	state.
+
+	* ediff-diff (ediff-test-patch-utility): Catch errors.
+	(ediff-actual-diff-options, ediff-actual-diff3-options): New variables.
+	(ediff-set-actual-diff-options): New function.
+	(ediff-reset-diff-options, ediff-toggle-ignore-case):
+	Use ediff-set-actual-diff-options.
+	(ediff-extract-diffs): Catch errors.
+	(ediff-whitespace): Add non-breakable space.
+	(ediff-same-file-contents): Catch errors.
+
+	* ediff-mult.el (ediff-collect-custom-diffs):
+	Save coding-system-for-read.
+
+	* ediff-vers.el (ediff-keep-tmp-versions): New variable.
+	(ediff-vc-internal, ediff-vc-merge-internal):
+	Use ediff-delete-version-file.
+	(ediff-delete-version-file): New function.
+
+	* ediff-wind.el (ediff-control-frame-parameters): Set frame fringes.
+
+	* ediff.el (ediff-directories, ediff-directory-revisions)
+	(ediff-merge-directories, ediff-merge-directories-with-ancestor)
+	(ediff-directories-internal, ediff-merge-directory-revisions)
+	(ediff-merge-directory-revisions-with-ancestor)
+	(ediff-directories3): Use read-directory-name.
+
+2006-06-18  Ralf Angeli  <angeli@caeruleus.net>
+
+	* textmodes/tex-mode.el (tex-font-lock-match-suscript): Remove
+	superfluous part of regexp for brace matching which is handled by
+	`scan-lists' call.
+
+2006-06-16  Richard Stallman  <rms@gnu.org>
+
+	* obsolete/options.el (list-options): Put "obsolete" msg in buffer.
+
+	* files.el (basic-save-buffer-2): For a new precious file,
+	use the default modes in the return value.
+
+	* facemenu.el (facemenu-color-alist): Doc fix.
+
+	* cus-edit.el (custom-guess-name-alist): Recognize `-flag'.
+
+2006-06-16  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* cus-start.el (all): Add mac-ts-script-language-on-focus.
+
+	* term/mac-win.el (mac-text-encoding-ascii): New constant.
+	(mac-utxt-to-string): Use it.
+	(mac-ts-update-active-input-area): Use mac-ae-number.
+
+2006-06-15  Dan Nicolaescu  <dann@ics.uci.edu>
+
+	* term.el (term-handle-scroll, term-delete-lines)
+	(term-insert-lines): Fix off by one errors.
+
+2006-06-15  Katsumi Yamaoka  <yamaoka@jpl.org>  (tiny change)
+
+	* net/tramp.el (tramp-touch): Use UTC to express time.
+
+2006-06-15  Chong Yidong  <cyd@stupidchicken.com>
+
+	* mail/sendmail.el (mail-send): Search explicitly for
+	mail-header-separator when checking for corrupted header lines.
+
+2006-06-15  Nick Roberts  <nickrob@snap.net.nz>
+
+	* progmodes/gdb-ui.el (gdb-same-frame): New option.
+	(gud-old-arrow, gdb-frame-begin, gdb-printing): New variables.
+	(gdb-init-1): Initialise them.
+	(gdb-starting): Reset gdb-printing
+	(gdb-starting): Save value of gud-overlay-arrow-position.
+	(gdb-frame-begin): Set gdb-frame-begin, gdb-printing.
+	(gdb-stopped): Don't look for source if calling procedure e.g "p a ()".
+	Use gdb-*-gdb-buffer conditionally on gdb-same-frame.
+	(gdb-frame-gdb-buffer): Keep menu bar, tool bar for GUD buffer.
+
+2006-06-14  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* pcvs.el (cvs-retrieve-revision): Use decode-coding-inserted-region.
+
+2006-06-13  Martin J. Reed  <mjreed@essex.ac.uk>  (tiny change)
+
+	* net/ldap.el (ldap-ldapsearch-args): Default to SASL search.
+	(ldap-search-internal): Keep error messages, and a regexp fix.
+
+2006-06-12  Thien-Thi Nguyen  <ttn@gnu.org>
+
+	* files.el (hack-local-variables-confirm):
+	Display string value using its printed representation.
+
 2006-06-11  Chong Yidong  <cyd@stupidchicken.com>
 
 	* server.el (server-edit): No-op if no server buffers exist.
 
 2006-06-11  Robert J. Chassell  <bob@rattlesnake.com>
 
-	* textmodes/page-ext.el (pages-directory-for-addresses): 
+	* textmodes/page-ext.el (pages-directory-for-addresses):
 	Including `pages-directory-address-mode' in the function results
 	in the message "Buffer in which pages were found is deleted".
 
@@ -82,8 +357,7 @@
 
 2006-06-06  Jesper Harder  <harder@phys.au.dk>
 
-	* ediff-diff.el (ediff-test-utility): Protect against
-	file-error.
+	* ediff-diff.el (ediff-test-utility): Protect against file-error.
 
 2006-06-06  Chong Yidong  <cyd@stupidchicken.com>
 
@@ -115,7 +389,7 @@
 	cookies but no other non-empty fields.
 	(org-set-tags): Allow groups of mutually exclusive tags.
 	(org-cmp-time): Sort 24:21 before items without time.
-	(org-get-time-of-day): Fixed the interpretation of 12pm and 12am.
+	(org-get-time-of-day): Fix the interpretation of 12pm and 12am.
 	(org-open-at-point): Require double colon also for numbers.
 
 2006-06-06  Kim F. Storm  <storm@cua.dk>
@@ -155,8 +429,8 @@
 
 2006-06-05  Kenichi Handa  <handa@m17n.org>
 
-	* international/mule.el (find-auto-coding): Handle
-	enable-character-translation in file header.
+	* international/mule.el (find-auto-coding):
+	Handle enable-character-translation in file header.
 
 2006-06-04  Kim F. Storm  <storm@cua.dk>
 
@@ -225,8 +499,8 @@
 	as well as `coding'.
 	(hack-local-variables): Likewise.
 
-	* international/mule.el (enable-character-translation): Put
-	permanent-local and safe-local-variable properties.
+	* international/mule.el (enable-character-translation):
+	Put permanent-local and safe-local-variable properties.
 	(find-auto-coding): Handle char-trans: tag.
 
 2006-06-02  Juri Linkov  <juri@jurta.org>
--- a/lisp/bindings.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/bindings.el	Tue Jun 27 15:06:36 2006 +0000
@@ -308,8 +308,7 @@
      'mode-line-buffer-identification
      (propertize "   " 'help-echo help-echo)
      'mode-line-position
-     '(vc-mode vc-mode)
-     (propertize "   " 'help-echo help-echo)
+     `(vc-mode ("" vc-mode ,(propertize "   " 'help-echo help-echo)))
      'mode-line-modes
      `(which-func-mode ("" which-func-format ,dashes))
      `(global-mode-string (,dashes global-mode-string))
--- a/lisp/calendar/appt.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/calendar/appt.el	Tue Jun 27 15:06:36 2006 +0000
@@ -136,7 +136,9 @@
   :type '(choice
           (const :tag "Separate window" window)
           (const :tag "Echo-area" echo)
-          (const :tag "No visible display" nil))
+          (const :tag "No visible display" nil)
+          (const :tag "Backwards compatibility setting - choose another value"
+                 ignore))
   :group 'appt
   :version "22.1")
 
--- a/lisp/complete.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/complete.el	Tue Jun 27 15:06:36 2006 +0000
@@ -196,7 +196,7 @@
 For example, M-x p-c-m expands to M-x partial-completion-mode since no other
 command begins with that sequence of characters, and
 \\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no
-other file in that directory begin with that sequence of characters.
+other file in that directory begins with that sequence of characters.
 
 Unless `PC-disable-includes' is non-nil, the `<...>' sequence is interpreted
 specially in \\[find-file].  For example,
@@ -358,13 +358,36 @@
 The function takes no arguments, and typically looks at the value
 of `minibuffer-completion-table' and the minibuffer contents.")
 
+;; Returns the sequence of non-delimiter characters that follow regexp in string.
+(defun PC-chunk-after (string regexp)
+  (if (not (string-match regexp string))
+      (let ((message (format "String %s didn't match regexp %s" string regexp)))
+	(message message)
+	(error message)))
+  (let ((result (substring string (match-end 0))))
+    ;; result may contain multiple chunks
+    (if (string-match PC-delim-regex result)
+	(setq result (substring result 0 (match-beginning 0))))
+    result))
+
+(defun test-completion-ignore-case (str table pred)
+  "Like `test-completion', but ignores case when possible."
+  ;; Binding completion-ignore-case to nil ensures, for compatibility with
+  ;; standard completion, that the return value is exactly one of the
+  ;; possibilities.  Do this binding only if pred is nil, out of paranoia;
+  ;; perhaps it is safe even if pred is non-nil.
+  (if pred
+      (test-completion str table pred)
+    (let ((completion-ignore-case nil))
+      (test-completion str table pred))))
+
 (defun PC-do-completion (&optional mode beg end)
   (or beg (setq beg (minibuffer-prompt-end)))
   (or end (setq end (point-max)))
   (let* ((table minibuffer-completion-table)
 	 (pred minibuffer-completion-predicate)
 	 (filename (funcall PC-completion-as-file-name-predicate))
-	 (dirname nil)
+	 (dirname nil)		; non-nil only if a filename is being completed
 	 (dirlength 0)
 	 (str (buffer-substring beg end))
 	 (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str)))
@@ -379,7 +402,7 @@
 
     ;; Check if buffer contents can already be considered complete
     (if (and (eq mode 'exit)
-	     (test-completion str table pred))
+	     (test-completion-ignore-case str table pred))
 	'complete
 
       ;; Do substitutions in directory names
@@ -598,35 +621,38 @@
 
 	    ;; Check if next few letters are the same in all cases
 	    (if (and (not (eq mode 'help))
-		     (setq prefix (try-completion "" (mapcar 'list poss))))
+		     (setq prefix (try-completion (PC-chunk-after basestr skip) (mapcar 'list poss))))
 		(let ((first t) i)
+		  ;; Retain capitalization of user input even if
+		  ;; completion-ignore-case is set.
 		  (if (eq mode 'word)
 		      (setq prefix (PC-chop-word prefix basestr)))
 		  (goto-char (+ beg (length dirname)))
 		  (while (and (progn
-				(setq i 0)
+				(setq i 0) ; index into prefix string
 				(while (< i (length prefix))
 				  (if (and (< (point) end)
-					   (eq (aref prefix i)
-					       (following-char)))
+					   (eq (downcase (aref prefix i))
+					       (downcase (following-char))))
+				      ;; same char (modulo case); no action
 				      (forward-char 1)
 				    (if (and (< (point) end)
-					     (or (and (looking-at " ")
+					     (and (looking-at " ")
 						      (memq (aref prefix i)
-							    PC-delims-list))
-						 (eq (downcase (aref prefix i))
-						     (downcase
-						      (following-char)))))
+							PC-delims-list)))
+					;; replace " " by the actual delimiter
 					(progn
 					  (delete-char 1)
-					  (setq end (1- end)))
+					  (insert (substring prefix i (1+ i))))
+				      ;; insert a new character
+				      (progn
 				      (and filename (looking-at "\\*")
 					   (progn
 					     (delete-char 1)
 					     (setq end (1- end))))
-				      (setq improved t))
+					(setq improved t)
 				    (insert (substring prefix i (1+ i)))
-				    (setq end (1+ end)))
+					(setq end (1+ end)))))
 				  (setq i (1+ i)))
 				(or pt (setq pt (point)))
 				(looking-at PC-delim-regex))
@@ -634,7 +660,12 @@
 						 (regexp-quote prefix)
 						 PC-ndelims-regex)
 				    prefix (try-completion
-					    ""
+					    (PC-chunk-after
+					     ;; not basestr, because that does
+					     ;; not reflect insertions
+					     (buffer-substring
+					      (+ beg (length dirname)) end)
+					     skip)
 					    (mapcar
 					     (function
 					      (lambda (x)
@@ -666,7 +697,7 @@
 
 		  ;; We changed it... enough to be complete?
 		  (and (eq mode 'exit)
-		       (test-completion (field-string) table pred))
+		       (test-completion-ignore-case (field-string) table pred))
 
 		;; If totally ambiguous, display a list of completions
 		(if (or (eq completion-auto-help t)
@@ -950,11 +981,10 @@
   (if (string-match "<\\([^\"<>]*\\)>?\\'" (ad-get-arg 0))
       (let* ((string (ad-get-arg 0))
              (action (ad-get-arg 2))
-             (name (match-string 1 string))
+             (name (substring string (match-beginning 1) (match-end 1)))
 	     (str2 (substring string (match-beginning 0)))
 	     (completion-table
-	      (mapcar (lambda (x)
-			(format (if (string-match "/\\'" x) "<%s" "<%s>") x))
+	      (mapcar (lambda (x) (format "<%s>" x))
 		      (PC-include-file-all-completions
 		       name (PC-include-file-path)))))
         (setq ad-return-value
--- a/lisp/cus-edit.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/cus-edit.el	Tue Jun 27 15:06:36 2006 +0000
@@ -587,6 +587,7 @@
 
 (defcustom custom-guess-name-alist
   '(("-p\\'" boolean)
+    ("-flag\\'" boolean)
     ("-hook\\'" hook)
     ("-face\\'" face)
     ("-file\\'" file)
@@ -1054,6 +1055,8 @@
 (defun customize-option (symbol)
   "Customize SYMBOL, which must be a user option variable."
   (interactive (custom-variable-prompt))
+  (unless symbol
+    (error "No variable specified"))
   (let ((basevar (indirect-variable symbol)))
     (custom-buffer-create (list (list basevar 'custom-variable))
 			  (format "*Customize Option: %s*"
@@ -1069,6 +1072,8 @@
   "Customize SYMBOL, which must be a user option variable.
 Show the buffer in another window, but don't select it."
   (interactive (custom-variable-prompt))
+  (unless symbol
+    (error "No variable specified"))
   (let ((basevar (indirect-variable symbol)))
     (custom-buffer-create-other-window
      (list (list basevar 'custom-variable))
@@ -1361,10 +1366,10 @@
 				      (get symbol 'variable-documentation))))
 		    (push (list symbol 'custom-variable) found)))))
     (if (not found)
-	(error "No matches")
-      (custom-buffer-create (custom-sort-items found t
-					       custom-buffer-order-groups)
-			    "*Customize Apropos*"))))
+	(error "No customizable items matching %s" regexp)
+      (custom-buffer-create
+       (custom-sort-items found t custom-buffer-order-groups)
+       "*Customize Apropos*"))))
 
 ;;;###autoload
 (defun customize-apropos-options (regexp &optional arg)
@@ -4515,9 +4520,18 @@
 
 (put 'custom-mode 'mode-class 'special)
 
-(add-to-list
- 'debug-ignored-errors
- "^No user options have changed defaults in recent Emacs versions$")
+(dolist (regexp
+	 '("^No user option defaults have been changed since Emacs "
+	   "^Invalid face:? "
+	   "^No \\(?:customized\\|rogue\\|saved\\) user options"
+	   "^No customizable items matching "
+	   "^There are unset changes"
+	   "^Cannot set hidden variable"
+	   "^No \\(?:saved\\|backup\\) value for "
+	   "^No standard setting known for "
+	   "^No standard setting for this face"
+	   "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
+  (add-to-list 'debug-ignored-errors regexp))
 
 ;;; The End.
 
--- a/lisp/cus-start.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/cus-start.el	Tue Jun 27 15:06:36 2006 +0000
@@ -222,6 +222,13 @@
 	     (mac-pass-command-to-system mac boolean "22.1")
 	     (mac-pass-control-to-system mac boolean "22.1")
 	     (mac-allow-anti-aliasing mac boolean "22.1")
+	     (mac-ts-script-language-on-focus mac
+					      (choice (const :tag "System default behavior" nil)
+						      (const :tag "Restore to script/language used in the last focus frame" t)
+						      (cons :tag "Specify script/language"
+							    (integer :tag "Script code")
+							    (integer :tag "Language code")))
+					      "22.1")
 
 ;; This is not good news because it will use the wrong
 ;; version-specific directories when you upgrade.  We need
--- a/lisp/desktop.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/desktop.el	Tue Jun 27 15:06:36 2006 +0000
@@ -153,8 +153,9 @@
 (define-minor-mode desktop-save-mode
   "Toggle desktop saving mode.
 With numeric ARG, turn desktop saving on if ARG is positive, off
-otherwise.  See variable `desktop-save' for a description of when the
-desktop is saved."
+otherwise.  If desktop saving is turned on, the state of Emacs is
+saved from one session to another.  See variable `desktop-save'
+and function `desktop-read' for details."
   :global t
   :group 'desktop)
 
@@ -175,7 +176,8 @@
 The desktop is never saved when `desktop-save-mode' is nil.
 The variables `desktop-dirname' and `desktop-base-file-name'
 determine where the desktop is saved."
-  :type '(choice
+  :type
+  '(choice
     (const :tag "Always save" t)
     (const :tag "Always ask" ask)
     (const :tag "Ask if desktop file is new, else do save" ask-if-new)
@@ -212,6 +214,7 @@
 
 (defcustom desktop-no-desktop-file-hook nil
   "Normal hook run when `desktop-read' can't find a desktop file.
+Run in the directory in which the desktop file was sought.
 May be used to show a dired buffer."
   :type 'hook
   :group 'desktop
@@ -222,11 +225,14 @@
 May be used to show a buffer list."
   :type 'hook
   :group 'desktop
+  :options '(list-buffers)
   :version "22.1")
 
 (defcustom desktop-save-hook nil
   "Normal hook run before the desktop is saved in a desktop file.
-This is useful for truncating history lists, for example."
+Run with the desktop buffer current with only the header present.
+May be used to add to the desktop code or to truncate history lists,
+for example."
   :type 'hook
   :group 'desktop)
 
@@ -282,6 +288,7 @@
     size-indication-mode
     buffer-file-coding-system
     indent-tabs-mode
+    tab-width
     indicate-buffer-boundaries
     indicate-empty-lines
     show-trailing-whitespace)
@@ -475,6 +482,11 @@
 (defvar desktop-dirname nil
   "The directory in which the desktop file should be saved.")
 
+(defun desktop-full-file-name (&optional dirname)
+  "Return the full name of the desktop file in DIRNAME.
+DIRNAME omitted or nil means use `desktop-dirname'."
+  (expand-file-name desktop-base-file-name (or dirname desktop-dirname)))
+
 (defconst desktop-header
 ";; --------------------------------------------------------------------------
 ;; Desktop File for Emacs
@@ -492,6 +504,7 @@
 	(setcdr here nil))))
 
 ;; ----------------------------------------------------------------------------
+;;;###autoload
 (defun desktop-clear ()
   "Empty the Desktop.
 This kills all buffers except for internal ones and those with names matched by
@@ -528,29 +541,26 @@
   "If `desktop-save-mode' is non-nil, do what `desktop-save' says to do.
 If the desktop should be saved and `desktop-dirname'
 is nil, ask the user where to save the desktop."
-  (when
-    (and
-      desktop-save-mode
-      (let ((exists (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname))))
-        (or
-          (eq desktop-save t)
-          (and exists (memq desktop-save '(ask-if-new if-exists)))
-          (and
-            (or
-              (memq desktop-save '(ask ask-if-new))
-              (and exists (eq desktop-save 'ask-if-exists)))
-            (y-or-n-p "Save desktop? ")))))
+  (when (and desktop-save-mode
+             (let ((exists (file-exists-p (desktop-full-file-name))))
+               (or (eq desktop-save t)
+                   (and exists (memq desktop-save '(ask-if-new if-exists)))
+                   (and
+                    (or (memq desktop-save '(ask ask-if-new))
+                        (and exists (eq desktop-save 'ask-if-exists)))
+                    (y-or-n-p "Save desktop? ")))))
     (unless desktop-dirname
       (setq desktop-dirname
-        (file-name-as-directory
-          (expand-file-name
-            (call-interactively
-              (lambda (dir) (interactive "DDirectory for desktop file: ") dir))))))
+            (file-name-as-directory
+             (expand-file-name
+              (call-interactively
+               (lambda (dir)
+                 (interactive "DDirectory for desktop file: ") dir))))))
     (condition-case err
-      (desktop-save desktop-dirname)
+        (desktop-save desktop-dirname)
       (file-error
-        (unless (yes-or-no-p "Error while saving the desktop.  Ignore? ")
-          (signal (car err) (cdr err)))))))
+       (unless (yes-or-no-p "Error while saving the desktop.  Ignore? ")
+         (signal (car err) (cdr err)))))))
 
 ;; ----------------------------------------------------------------------------
 (defun desktop-list* (&rest args)
@@ -715,6 +725,7 @@
     (t (expand-file-name filename))))
 
 ;; ----------------------------------------------------------------------------
+;;;###autoload
 (defun desktop-save (dirname)
   "Save the desktop in a desktop file.
 Parameter DIRNAME specifies where to save the desktop file.
@@ -723,7 +734,7 @@
   (run-hooks 'desktop-save-hook)
   (setq dirname (file-name-as-directory (expand-file-name dirname)))
   (save-excursion
-    (let ((filename (expand-file-name desktop-base-file-name dirname))
+    (let ((filename (desktop-full-file-name dirname))
           (info
             (mapcar
               #'(lambda (b)
@@ -802,12 +813,13 @@
   (setq desktop-dirname dirname))
 
 ;; ----------------------------------------------------------------------------
+;;;###autoload
 (defun desktop-remove ()
   "Delete desktop file in `desktop-dirname'.
 This function also sets `desktop-dirname' to nil."
   (interactive)
   (when desktop-dirname
-    (let ((filename (expand-file-name desktop-base-file-name desktop-dirname)))
+    (let ((filename (desktop-full-file-name)))
       (setq desktop-dirname nil)
       (when (file-exists-p filename)
         (delete-file filename)))))
@@ -830,32 +842,30 @@
   (interactive)
   (unless noninteractive
     (setq desktop-dirname
-      (file-name-as-directory
-        (expand-file-name
-          (or
-            ;; If DIRNAME is specified, use it.
-            (and (< 0 (length dirname)) dirname)
-            ;; Otherwise search desktop file in desktop-path.
-            (let ((dirs desktop-path))
-              (while
-                (and
-                  dirs
-                  (not
-                    (file-exists-p (expand-file-name desktop-base-file-name (car dirs)))))
-                (setq dirs (cdr dirs)))
-              (and dirs (car dirs)))
-            ;; If not found and `desktop-path' is non-nil, use its first element.
-            (and desktop-path (car desktop-path))
-            ;; Default: Home directory.
-            "~"))))
-    (if (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname))
+          (file-name-as-directory
+           (expand-file-name
+            (or
+             ;; If DIRNAME is specified, use it.
+             (and (< 0 (length dirname)) dirname)
+             ;; Otherwise search desktop file in desktop-path.
+             (let ((dirs desktop-path))
+               (while (and dirs
+                           (not (file-exists-p
+                                 (desktop-full-file-name (car dirs)))))
+                 (setq dirs (cdr dirs)))
+               (and dirs (car dirs)))
+             ;; If not found and `desktop-path' is non-nil, use its first element.
+             (and desktop-path (car desktop-path))
+             ;; Default: Home directory.
+             "~"))))
+    (if (file-exists-p (desktop-full-file-name))
       ;; Desktop file found, process it.
       (let ((desktop-first-buffer nil)
             (desktop-buffer-ok-count 0)
             (desktop-buffer-fail-count 0))
         (setq desktop-lazy-timer nil)
         ;; Evaluate desktop buffer.
-        (load (expand-file-name desktop-base-file-name desktop-dirname) t t t)
+        (load (desktop-full-file-name) t t t)
         ;; `desktop-create-buffer' puts buffers at end of the buffer list.
         ;; We want buffers existing prior to evaluating the desktop (and not reused)
         ;; to be placed at the end of the buffer list, so we move them here.
@@ -925,7 +935,7 @@
   (interactive)
   (unless desktop-dirname
     (error "Unknown desktop directory"))
-  (unless (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname))
+  (unless (file-exists-p (desktop-full-file-name))
     (error "No desktop file found"))
   (desktop-clear)
   (desktop-read desktop-dirname))
--- a/lisp/dos-w32.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/dos-w32.el	Tue Jun 27 15:06:36 2006 +0000
@@ -186,7 +186,7 @@
       (setq buffer-file-type (eq buffer-file-coding-system 'no-conversion)))))
 
 ;;; To set the default coding system on new files.
-(add-hook 'find-file-not-found-hooks
+(add-hook 'find-file-not-found-functions
 	  'find-file-not-found-set-buffer-file-coding-system)
 
 ;;; To accomodate filesystems that do not require CR/LF translation.
--- a/lisp/ediff-diff.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/ediff-diff.el	Tue Jun 27 15:06:36 2006 +0000
@@ -65,10 +65,11 @@
 ;; The following functions needed for setting diff/diff3 options
 ;; test if diff supports the --binary option
 (defsubst ediff-test-utility (diff-util option &optional files)
-  (condition-case ()
+  (condition-case nil
       (eq 0 (apply 'call-process
 		   (append (list diff-util nil nil nil option) files)))
-    (file-error nil)))
+    (error (format "Cannot execute program %S." diff-util)))
+  )
 
 (defun ediff-diff-mandatory-option (diff-util)
   (let ((file (if (boundp 'null-device) null-device "/dev/null")))
@@ -77,13 +78,17 @@
 	   ((and (string= diff-util ediff-diff-program)
 		 (ediff-test-utility
 		  ediff-diff-program "--binary" (list file file)))
-	    "--binary")
+	    "--binary ")
 	   ((and (string= diff-util ediff-diff3-program)
 		 (ediff-test-utility
 		  ediff-diff3-program "--binary" (list file file file)))
-	    "--binary")
+	    "--binary ")
 	   (t ""))))
 
+
+;; must be before ediff-reset-diff-options to avoid compiler errors
+(fset 'ediff-set-actual-diff-options '(lambda () nil))
+
 ;; make sure that mandatory options are added even if the user changes
 ;; ediff-diff-options or ediff-diff3-options in the customization widget
 (defun ediff-reset-diff-options (symb val)
@@ -91,12 +96,9 @@
 	  (if (eq symb 'ediff-diff-options)
 	      ediff-diff-program
 	    ediff-diff3-program))
-	 (mandatory-option (ediff-diff-mandatory-option diff-program))
-	 (spacer (if (string-equal mandatory-option "") "" " ")))
-    (set symb
-	 (if (string-match mandatory-option val)
-	     val
-	   (concat mandatory-option spacer val)))
+	 (mandatory-option (ediff-diff-mandatory-option diff-program)))
+    (set symb (concat mandatory-option val))
+    (ediff-set-actual-diff-options)
     ))
 
 
@@ -155,7 +157,7 @@
   :group 'ediff-diff)
 
 ;; the actual options used in comparison
-(ediff-defvar-local ediff-actual-diff-options "" "")
+(ediff-defvar-local ediff-actual-diff-options ediff-diff-options "")
 
 (defcustom ediff-custom-diff-program ediff-diff-program
   "*Program to use for generating custom diff output for saving it in a file.
@@ -178,7 +180,7 @@
   :group 'ediff-diff)
 
 ;; the actual options used in comparison
-(ediff-defvar-local ediff-actual-diff3-options "" "")
+(ediff-defvar-local ediff-actual-diff3-options ediff-diff3-options "")
 
 (defcustom ediff-diff3-ok-lines-regexp
   "^\\([1-3]:\\|====\\|  \\|.*Warning *:\\|.*No newline\\|.*missing newline\\|^\C-m$\\)"
@@ -1272,7 +1274,9 @@
 		;; Similarly for Windows-*
 		;; In DOS, must synchronize because DOS doesn't have
 		;; asynchronous processes.
-		(apply 'call-process program nil buffer nil args)
+		(condition-case nil
+		    (apply 'call-process program nil buffer nil args)
+		  (error (format "Cannot execute program %S." program)))
 	      ;; On other systems, do it asynchronously.
 	      (setq proc (get-buffer-process buffer))
 	      (if proc (kill-process proc))
@@ -1328,7 +1332,8 @@
 Used for splitting difference regions into individual words.")
 (make-variable-buffer-local 'ediff-forward-word-function)
 
-(defvar ediff-whitespace " \n\t\f"
+;; \240 is unicode symbol for nonbreakable whitespace
+(defvar ediff-whitespace " \n\t\f\r\240"
   "*Characters constituting white space.
 These characters are ignored when differing regions are split into words.")
 (make-variable-buffer-local 'ediff-whitespace)
@@ -1442,11 +1447,13 @@
   "Return t if files F1 and F2 have identical contents."
   (if (and (not (file-directory-p f1))
            (not (file-directory-p f2)))
-      (let ((res
-	     (apply 'call-process ediff-cmp-program nil nil nil
-		    (append ediff-cmp-options (list f1 f2)))))
-	(and (numberp res) (eq res 0))))
-  )
+      (condition-case nil
+	  (let ((res
+		 (apply 'call-process ediff-cmp-program nil nil nil
+			(append ediff-cmp-options (list f1 f2)))))
+	    (and (numberp res) (eq res 0)))
+	(error (format "Cannot execute program %S." ediff-cmp-program)))
+    ))
 
 
 (defun ediff-same-contents (d1 d2 &optional filter-re)
@@ -1521,21 +1528,30 @@
       (setq file-list-list (cdr file-list-list)))
     (reverse result)))
 
+
+(defun ediff-set-actual-diff-options ()
+  (if ediff-ignore-case
+      (setq ediff-actual-diff-options 
+	    (concat ediff-diff-options " " ediff-ignore-case-option)
+	    ediff-actual-diff3-options
+	    (concat ediff-diff3-options " " ediff-ignore-case-option3))
+    (setq ediff-actual-diff-options ediff-diff-options
+	  ediff-actual-diff3-options ediff-diff3-options)
+    )
+  (setq-default ediff-actual-diff-options ediff-actual-diff-options
+		ediff-actual-diff3-options ediff-actual-diff3-options)
+  )
+
+
 ;; Ignore case handling - some ideas from drew.adams@@oracle.com
 (defun ediff-toggle-ignore-case ()
   (interactive)
   (ediff-barf-if-not-control-buffer)
   (setq ediff-ignore-case (not ediff-ignore-case))
-  (cond (ediff-ignore-case
-	 (setq ediff-actual-diff-options
-	       (concat ediff-diff-options " " ediff-ignore-case-option)
-	       ediff-actual-diff3-options
-	       (concat ediff-diff3-options " " ediff-ignore-case-option3))
-	 (message "Ignoring regions that differ only in case"))
-	(t
-	 (setq ediff-actual-diff-options ediff-diff-options
-	       ediff-actual-diff3-options ediff-diff3-options)
-	 (message "Ignoring case differences turned OFF")))
+  (ediff-set-actual-diff-options)
+  (if ediff-ignore-case
+      (message "Ignoring regions that differ only in case")
+    (message "Ignoring case differences turned OFF"))
   (cond (ediff-merge-job
 	 (message "Ignoring letter case is too dangerous in merge jobs"))
 	((and ediff-diff3-job (string= ediff-ignore-case-option3 ""))
--- a/lisp/ediff-mult.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/ediff-mult.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1656,22 +1656,26 @@
 multifile patches.  For `ediff-directory-revisions', we insist that
 all marked sessions must be active."
   (interactive)
-  (or (ediff-buffer-live-p ediff-meta-diff-buffer)
-      (setq ediff-meta-diff-buffer
-	    (get-buffer-create
-	     (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
-  (ediff-with-current-buffer ediff-meta-diff-buffer
-    (setq buffer-read-only nil)
-    (erase-buffer))
-  (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
-      ;; did something
-      (progn
-	(display-buffer ediff-meta-diff-buffer 'not-this-window)
-	(ediff-with-current-buffer ediff-meta-diff-buffer
-	  (set-buffer-modified-p nil)
-	  (setq buffer-read-only t)))
-    (beep)
-    (message "No marked sessions found")))
+  (let ((coding-system-for-read ediff-coding-system-for-read))
+    (or (ediff-buffer-live-p ediff-meta-diff-buffer)
+	(setq ediff-meta-diff-buffer
+	      (get-buffer-create
+	       (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
+    (ediff-with-current-buffer ediff-meta-diff-buffer
+			       (setq buffer-read-only nil)
+			       (erase-buffer))
+    (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
+	;; did something
+	(progn
+	  (display-buffer ediff-meta-diff-buffer 'not-this-window)
+	  (ediff-with-current-buffer ediff-meta-diff-buffer
+				     (set-buffer-modified-p nil)
+				     (setq buffer-read-only t))
+	  (if (fboundp 'diff-mode)
+	      (with-current-buffer ediff-meta-diff-buffer
+		(diff-mode))))
+      (beep)
+      (message "No marked sessions found"))))
 
 (defun ediff-meta-show-patch ()
   "Show the multi-file patch associated with this group session."
--- a/lisp/ediff-vers.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/ediff-vers.el	Tue Jun 27 15:06:36 2006 +0000
@@ -52,6 +52,13 @@
 	 )))
 ;; end pacifier
 
+(defcustom ediff-keep-tmp-versions nil
+  "*If t, do not delete temporary previous versions for the files on which
+comparison or merge operations are being performed."
+  :type 'boolean
+  :group 'ediff-vers
+  )
+
 ;; VC.el support
 
 (defun ediff-vc-latest-version (file)
@@ -87,8 +94,8 @@
 	      file2 (buffer-file-name)))
       (setq startup-hooks
 	    (cons `(lambda ()
-		     (delete-file ,file1)
-		     (or ,(string= rev2 "") (delete-file ,file2)))
+		     (ediff-delete-version-file ,file1)
+		     (or ,(string= rev2 "") (ediff-delete-version-file ,file2)))
 		  startup-hooks)))
     (ediff-buffers
      rev1buf rev2buf
@@ -199,12 +206,12 @@
       (setq startup-hooks
 	    (cons
 	     `(lambda ()
-		(delete-file ,(buffer-file-name buf1))
+		(ediff-delete-version-file ,(buffer-file-name buf1))
 		(or ,(string= rev2 "")
-		    (delete-file ,(buffer-file-name buf2)))
+		    (ediff-delete-version-file ,(buffer-file-name buf2)))
 		(or ,(string= ancestor-rev "")
 		    ,(not ancestor-rev)
-		    (delete-file ,(buffer-file-name ancestor-buf)))
+		    (ediff-delete-version-file ,(buffer-file-name ancestor-buf)))
 		)
 	     startup-hooks)))
     (if ancestor-rev
@@ -305,8 +312,13 @@
 	      (find-file-noselect (cvs-fileinfo->full-name fileinfo)))
 	    nil ; startup-hooks
 	    'ediff-revisions)))
-    (if (stringp tmp-file) (delete-file tmp-file))
-    (if (stringp ancestor-file) (delete-file ancestor-file))))
+    (if (stringp tmp-file) (ediff-delete-version-file tmp-file))
+    (if (stringp ancestor-file) (ediff-delete-version-file ancestor-file))))
+
+
+;; delete version file on exit unless ediff-keep-tmp-versions is true
+(defun ediff-delete-version-file (file)
+  (or ediff-keep-tmp-versions (delete-file file)))
 
 
 (provide 'ediff-vers)
--- a/lisp/ediff-wind.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/ediff-wind.el	Tue Jun 27 15:06:36 2006 +0000
@@ -159,6 +159,8 @@
    '(scrollbar-height . 0)        ; XEmacs only
    '(menu-bar-lines . 0)          ; Emacs only
    '(tool-bar-lines . 0)          ; Emacs 21+ only
+   '(left-fringe    . 0)
+   '(right-fringe   . 0)
    ;; don't lower but auto-raise
    '(auto-lower . nil)
    '(auto-raise . t)
--- a/lisp/ediff.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/ediff.el	Tue Jun 27 15:06:36 2006 +0000
@@ -500,12 +500,13 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 f)
-     (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
-	   (ediff-read-file-name "Directory B to compare:"
-				 (if ediff-use-last-dir
-				     ediff-last-dir-B
-				   (ediff-strip-last-dir f))
-				 nil)
+     (list (setq f (read-directory-name
+		    "Directory A to compare:" dir-A nil 'must-match))
+	   (read-directory-name "Directory B to compare:"
+			   (if ediff-use-last-dir
+			       ediff-last-dir-B
+			     (ediff-strip-last-dir f))
+			   nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -532,8 +533,8 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 )
-     (list (ediff-read-file-name
-	    "Directory to compare with revision:" dir-A nil)
+     (list (read-directory-name
+	    "Directory to compare with revision:" dir-A nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -561,17 +562,17 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 f)
-     (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil))
-	   (setq f (ediff-read-file-name "Directory B to compare:"
-					 (if ediff-use-last-dir
-					     ediff-last-dir-B
-					   (ediff-strip-last-dir f))
-					 nil))
-	   (ediff-read-file-name "Directory C to compare:"
-				 (if ediff-use-last-dir
-				     ediff-last-dir-C
-				   (ediff-strip-last-dir f))
-				 nil)
+     (list (setq f (read-directory-name "Directory A to compare:" dir-A nil))
+	   (setq f (read-directory-name "Directory B to compare:"
+				   (if ediff-use-last-dir
+				       ediff-last-dir-B
+				     (ediff-strip-last-dir f))
+				   nil 'must-match))
+	   (read-directory-name "Directory C to compare:"
+			   (if ediff-use-last-dir
+			       ediff-last-dir-C
+			     (ediff-strip-last-dir f))
+			   nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -597,12 +598,13 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 f)
-     (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
-	   (ediff-read-file-name "Directory B to merge:"
-				 (if ediff-use-last-dir
-				     ediff-last-dir-B
-				   (ediff-strip-last-dir f))
-				 nil)
+     (list (setq f (read-directory-name "Directory A to merge:"
+					dir-A nil 'must-match))
+	   (read-directory-name "Directory B to merge:"
+			   (if ediff-use-last-dir
+			       ediff-last-dir-B
+			     (ediff-strip-last-dir f))
+			   nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -633,17 +635,17 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 f)
-     (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil))
-	   (setq f (ediff-read-file-name "Directory B to merge:"
+     (list (setq f (read-directory-name "Directory A to merge:" dir-A nil))
+	   (setq f (read-directory-name "Directory B to merge:"
 				 (if ediff-use-last-dir
 				     ediff-last-dir-B
 				   (ediff-strip-last-dir f))
-				 nil))
-	   (ediff-read-file-name "Ancestor directory:"
+				 nil 'must-match))
+	   (read-directory-name "Ancestor directory:"
 				 (if ediff-use-last-dir
 				     ediff-last-dir-C
 				   (ediff-strip-last-dir f))
-				 nil)
+				 nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -669,8 +671,8 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 )
-     (list (ediff-read-file-name
-	    "Directory to merge with revisions:" dir-A nil)
+     (list (read-directory-name
+	    "Directory to merge with revisions:" dir-A nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -699,8 +701,9 @@
    (let ((dir-A (ediff-get-default-directory-name))
 	 (default-regexp (eval ediff-default-filtering-regexp))
 	 )
-     (list (ediff-read-file-name
-	    "Directory to merge with revisions and ancestors:" dir-A nil)
+     (list (read-directory-name
+	    "Directory to merge with revisions and ancestors:"
+	    dir-A nil 'must-match)
 	   (read-string
 	    (if (stringp default-regexp)
 		(format "Filter through regular expression (default %s): "
@@ -733,11 +736,6 @@
 (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname
 					&optional startup-hooks
 					merge-autostore-dir)
-  ;; ediff-read-file-name is set to attach a previously entered file name if
-  ;; the currently entered file is a directory.  This code takes care of that.
-  (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))
-	dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2)))
-
   (if (stringp dir3)
       (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3))))
 
@@ -763,7 +761,7 @@
 	     (ediff-merge-metajob jobname)
 	     (not merge-autostore-dir))
 	(setq merge-autostore-dir
-	      (read-file-name "Save merged files in directory: "
+	      (read-directory-name "Save merged files in directory: "
 			      (if ediff-use-last-dir
 					ediff-last-merge-autostore-dir
 				      (ediff-strip-last-dir dir1))
@@ -823,7 +821,7 @@
 	     (ediff-merge-metajob jobname)
 	     (not merge-autostore-dir))
 	(setq merge-autostore-dir
-	      (read-file-name "Save merged files in directory: "
+	      (read-directory-name "Save merged files in directory: "
 			      (if ediff-use-last-dir
 				  ediff-last-merge-autostore-dir
 				(ediff-strip-last-dir dir1))
--- a/lisp/emulation/viper-cmd.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/emulation/viper-cmd.el	Tue Jun 27 15:06:36 2006 +0000
@@ -887,12 +887,15 @@
 		   (setq ch (aref (read-key-sequence nil) 0)))
 	       (insert ch))
 	      (t
-	       (setq ch (read-char-exclusive))
+	       ;;(setq ch (read-char-exclusive))
+	       (setq ch (aref (read-key-sequence nil) 0))
 	       ;; replace ^M with the newline
 	       (if (eq ch ?\C-m) (setq ch ?\n))
 	       ;; Make sure ^V and ^Q work as quotation chars
 	       (if (memq ch '(?\C-v ?\C-q))
-		   (setq ch (read-char-exclusive)))
+		   ;;(setq ch (read-char-exclusive))
+		   (setq ch (aref (read-key-sequence nil) 0))
+		 )
 	       (insert ch))
 	      )
 	(setq last-command-event
@@ -1730,20 +1733,34 @@
 
 ;; undoing
 
+;; hook used inside undo
+(defvar viper-undo-functions nil)
+
+;; Runs viper-before-change-functions inside before-change-functions
+(defun viper-undo-sentinel (beg end length)
+  (run-hook-with-args 'viper-undo-functions beg end length))
+
+(add-hook 'after-change-functions 'viper-undo-sentinel)
+
+;; Hook used in viper-undo
+(defun viper-after-change-undo-hook (beg end len)
+  (setq undo-beg-posn beg
+	undo-end-posn (or end beg))
+  ;; some other hooks may be changing various text properties in
+  ;; the buffer in response to 'undo'; so remove this hook to avoid
+  ;; its repeated invocation
+  (remove-hook 'viper-undo-functions 'viper-after-change-undo-hook 'local))
+
 (defun viper-undo ()
   "Undo previous change."
   (interactive)
   (message "undo!")
   (let ((modified (buffer-modified-p))
         (before-undo-pt (point-marker))
-	(after-change-functions after-change-functions)
 	undo-beg-posn undo-end-posn)
 
-    ;; no need to remove this hook, since this var has scope inside a let.
-    (add-hook 'after-change-functions
-	      '(lambda (beg end len)
-		 (setq undo-beg-posn beg
-		       undo-end-posn (or end beg))))
+    ;; the viper-after-change-undo-hook removes itself after the 1st invocation
+    (add-hook 'viper-undo-functions 'viper-after-change-undo-hook nil 'local)
 
     (undo-start)
     (undo-more 2)
@@ -1765,7 +1782,8 @@
 	    (goto-char undo-beg-posn)))
       (push-mark before-undo-pt t))
     (if (and (eolp) (not (bolp))) (backward-char 1))
-    (if (not modified) (set-buffer-modified-p t)))
+    ;;(if (not modified) (set-buffer-modified-p t))
+    )
   (setq this-command 'viper-undo))
 
 ;; Continue undoing previous changes.
@@ -1813,7 +1831,7 @@
 	    (setq viper-undo-needs-adjustment t)))))
 
 
-
+;;; Viper's destructive Command ring utilities
 
 (defun viper-display-current-destructive-command ()
   (let ((text (nth 4 viper-d-com))
@@ -1927,12 +1945,15 @@
       (end-of-line)
       ;; make sure all lines end with newline, unless in the minibuffer or
       ;; when requested otherwise (require-final-newline is nil)
-      (if (and (eobp)
-	       (not (bolp))
-	       require-final-newline
-	       (not (viper-is-in-minibuffer))
-	       (not buffer-read-only))
-	  (insert "\n"))))
+      (save-restriction
+	(widen)
+	(if (and (eobp)
+		 (not (bolp))
+		 require-final-newline
+		 (not (viper-is-in-minibuffer))
+		 (not buffer-read-only))
+	    (insert "\n")))
+      ))
 
 (defun viper-yank-defun ()
   (mark-defun)
@@ -3045,19 +3066,34 @@
     (setq this-command 'next-line)
     (if com (viper-execute-com 'viper-next-line val com))))
 
+
 (defun viper-next-line-at-bol (arg)
-  "Next line at beginning of line."
+  "Next line at beginning of line.
+If point is on a widget or a button, simulate clicking on that widget/button."
   (interactive "P")
-  (viper-leave-region-active)
-  (save-excursion
-    (end-of-line)
-    (if (eobp) (error "Last line in buffer")))
-  (let ((val (viper-p-val arg))
-	(com (viper-getCom arg)))
-    (if com (viper-move-marker-locally 'viper-com-point (point)))
-    (forward-line val)
-    (back-to-indentation)
-    (if com (viper-execute-com 'viper-next-line-at-bol val com))))
+  (let* ((field (get-char-property (point) 'field))
+	 (button (get-char-property (point) 'button))
+	 (doc (get-char-property (point) 'widget-doc))
+	 (widget (or field button doc)))
+    (if (and widget
+             (if (symbolp widget)
+                 (get widget 'widget-type)
+               (and (consp widget)
+                    (get (widget-type widget) 'widget-type))))
+        (widget-button-press (point))
+      (if (button-at (point))
+          (push-button)
+	;; not a widget or a button
+        (viper-leave-region-active)
+        (save-excursion
+          (end-of-line)
+          (if (eobp) (error "Last line in buffer")))
+        (let ((val (viper-p-val arg))
+              (com (viper-getCom arg)))
+          (if com (viper-move-marker-locally 'viper-com-point (point)))
+          (forward-line val)
+          (back-to-indentation)
+          (if com (viper-execute-com 'viper-next-line-at-bol val com)))))))
 
 
 (defun viper-previous-line (arg)
--- a/lisp/emulation/viper-util.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/emulation/viper-util.el	Tue Jun 27 15:06:36 2006 +0000
@@ -139,8 +139,8 @@
 
 (defsubst viper-get-cursor-color ()
   (viper-cond-compile-for-xemacs-or-emacs
-   ;; xemacs
-   (color-instance-name (frame-property (selected-frame) 'cursor-color))
+   (color-instance-name
+    (frame-property (selected-frame) 'cursor-color)) ; xemacs
    (cdr (assoc 'cursor-color (frame-parameters))) ; emacs
    ))
 
--- a/lisp/emulation/viper.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/emulation/viper.el	Tue Jun 27 15:06:36 2006 +0000
@@ -534,6 +534,10 @@
 (defun viper-mode ()
   "Turn on Viper emulation of Vi in Emacs. See Info node `(viper)Viper'."
   (interactive)
+  (if (null viper-vi-state-cursor-color)
+      (modify-frame-parameters
+	(selected-frame)
+	(list (cons 'viper-vi-state-cursor-color (viper-get-cursor-color)))))
   (if (not noninteractive)
       (progn
 	;; if the user requested viper-mode explicitly
@@ -545,8 +549,6 @@
 	(if viper-first-time ; Important check.  Prevents mix-up of startup
 	    (progn	     ; and expert-level msgs when viper-mode recurses
 	      (setq viper-first-time nil)
-	      (setq viper-vi-state-cursor-color
-		    (viper-get-cursor-color))
 	      (if (not viper-inhibit-startup-message)
 		  (save-window-excursion
 		    (setq viper-inhibit-startup-message t)
--- a/lisp/facemenu.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/facemenu.el	Tue Jun 27 15:06:36 2006 +0000
@@ -308,9 +308,8 @@
 ;;; Internal Variables
 
 (defvar facemenu-color-alist nil
-  ;; Don't initialize here; that doesn't work if preloaded.
   "Alist of colors, used for completion.
-If null, `facemenu-read-color' will set it.")
+If this is nil, then the value of (defined-colors) is used.")
 
 (defun facemenu-update ()
   "Add or update the \"Face\" menu in the menu bar.
--- a/lisp/files.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/files.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1514,23 +1514,53 @@
 			   ;; hexl-mode.
 			   (not (eq major-mode 'hexl-mode)))
 		  (if (buffer-modified-p)
-		      (if (y-or-n-p (if rawfile
-					"Save file and revisit literally? "
-				      "Save file and revisit non-literally? "))
+		      (if (y-or-n-p
+			   (format 
+			    (if rawfile
+				"The file %s is already visited normally,
+and you have edited the buffer.  Now you have asked to visit it literally,
+meaning no coding system handling, format conversion, or local variables.
+Emacs can only visit a file in one way at a time.
+
+Do you want to save the file, and visit it literally instead? "
+				"The file %s is already visited literally,
+meaning no coding system handling, format conversion, or local variables.
+You have edited the buffer.  Now you have asked to visit the file normally,
+but Emacs can only visit a file in one way at a time.
+
+Do you want to save the file, and visit it normally instead? ")
+			    (file-name-nondirectory filename)))
 			  (progn
 			    (save-buffer)
 			    (find-file-noselect-1 buf filename nowarn
 						  rawfile truename number))
-			(if (y-or-n-p (if rawfile
-					  "Discard your edits and revisit file literally? "
-					"Discard your edits and revisit file non-literally? "))
+			(if (y-or-n-p
+			     (format 
+			      (if rawfile
+				  "\
+Do you want to discard your changes, and visit the file literally now? "
+				"\
+Do you want to discard your changes, and visit the file normally now? ")))
 			    (find-file-noselect-1 buf filename nowarn
 						  rawfile truename number)
 			  (error (if rawfile "File already visited non-literally"
 				   "File already visited literally"))))
-		    (if (y-or-n-p (if rawfile
-				      "Revisit file literally? "
-				    "Revisit file non-literally? "))
+		    (if (y-or-n-p 
+			 (format 
+			  (if rawfile
+			      "The file %s is already visited normally.
+You have asked to visit it literally,
+meaning no coding system decoding, format conversion, or local variables.
+But Emacs can only visit a file in one way at a time.
+
+Do you want to revisit the file literally now? "
+			    "The file %s is already visited literally,
+meaning no coding system decoding, format conversion, or local variables.
+You have asked to visit it normally,
+but Emacs can only visit a file in one way at a time.
+
+Do you want to revisit the file normally now? ")
+			  (file-name-nondirectory filename)))
 			(find-file-noselect-1 buf filename nowarn
 					      rawfile truename number)
 		      (error (if rawfile "File already visited non-literally"
@@ -1577,7 +1607,7 @@
 	     (kill-buffer buf)
 	     (signal 'file-error (list "File is not readable"
 				       filename)))
-	   ;; Run find-file-not-found-hooks until one returns non-nil.
+	   ;; Run find-file-not-found-functions until one returns non-nil.
 	   (or (run-hook-with-args-until-success 'find-file-not-found-functions)
 	       ;; If they fail too, set error.
 	       (setq error t)))))
@@ -2407,7 +2437,11 @@
 		   (insert "    ")))
 	    (princ (car elt) buf)
 	    (insert " : ")
-	    (princ (cdr elt) buf)
+            (if (stringp (cdr elt))
+                ;; Make strings with embedded whitespace easier to read.
+                (let ((print-escape-newlines t))
+                  (prin1 (cdr elt) buf))
+              (princ (cdr elt) buf))
 	    (insert "\n"))
 	  (setq prompt
 		(format "Please type %s%s: "
@@ -2632,8 +2666,8 @@
 		      (hack-local-variables-confirm
 		       result unsafe-vars risky-vars))
 		  (dolist (elt result)
-		    (hack-one-local-variable (car elt) (cdr elt))))))
-	  (run-hooks 'hack-local-variables-hook))))))
+		    (hack-one-local-variable (car elt) (cdr elt)))))))
+	(run-hooks 'hack-local-variables-hook)))))
 
 (defun safe-local-variable-p (sym val)
   "Non-nil if SYM is safe as a file-local variable with value VAL.
@@ -3627,8 +3661,10 @@
 		(set-visited-file-modtime old-modtime)))
 	    ;; Since we have created an entirely new file,
 	    ;; make sure it gets the right permission bits set.
-	    (setq setmodes (or setmodes (cons (file-modes buffer-file-name)
-					      buffer-file-name)))
+	    (setq setmodes (or setmodes
+ 			       (cons (or (file-modes buffer-file-name)
+					 (logand ?\666 umask))
+				     buffer-file-name)))
 	    ;; We succeeded in writing the temp file,
 	    ;; so rename it.
 	    (rename-file tempname buffer-file-name t))
--- a/lisp/generic-x.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/generic-x.el	Tue Jun 27 15:06:36 2006 +0000
@@ -512,10 +512,11 @@
        (1 font-lock-builtin-face)
        (2 font-lock-variable-name-face t t))))
   '("\\.[bB][aA][tT]\\'"
+    "\\.[cC][mM][dD]\\'"
     "\\`[cC][oO][nN][fF][iI][gG]\\."
     "\\`[aA][uU][tT][oO][eE][xX][eE][cC]\\.")
   '(generic-bat-mode-setup-function)
-  "Generic mode for MS-Windows BAT files.")
+  "Generic mode for MS-Windows batch files.")
 
 (defvar bat-generic-mode-syntax-table nil
   "Syntax table in use in `bat-generic-mode' buffers.")
--- a/lisp/gnus/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/gnus/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,22 @@
+2006-06-20  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* rfc2231.el (rfc2231-parse-string): Allow `*'s in parameter values.
+
+2006-06-19  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* message.el (message-syntax-checks): Doc fix.
+
+2006-06-16  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* message.el (message-syntax-checks): Doc fix.
+	(message-send-mail): Add check for continuation headers.
+	(message-check-news-header-syntax): Fix regexp used to check for
+	continuation headers.
+
+2006-06-14  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* gnus-art.el (gnus-display-mime): Make sure body ends with newline.
+
 2006-06-06  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 	* mm-util.el (mm-mime-mule-charset-alist): Use unicode-precedence-list
--- a/lisp/gnus/gnus-art.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/gnus/gnus-art.el	Tue Jun 27 15:06:36 2006 +0000
@@ -4927,7 +4927,11 @@
 	      (article-goto-body)
 	      (narrow-to-region (point-min) (point))
 	      (gnus-article-save-original-date
-	       (gnus-treat-article 'head)))))))))
+	       (gnus-treat-article 'head)))))))
+    ;; Cope with broken MIME messages.
+    (goto-char (point-max))
+    (unless (bolp)
+      (insert "\n"))))
 
 (defcustom gnus-mime-display-multipart-as-mixed nil
   "Display \"multipart\" parts as  \"multipart/mixed\".
--- a/lisp/gnus/message.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/gnus/message.el	Tue Jun 27 15:06:36 2006 +0000
@@ -190,14 +190,13 @@
 
 Don't touch this variable unless you really know what you're doing.
 
-Checks include `subject-cmsg', `multiple-headers', `sendsys',
-`message-id', `from', `long-lines', `control-chars', `size',
-`new-text', `quoting-style', `redirected-followup', `signature',
-`approved', `sender', `empty', `empty-headers', `message-id', `from',
-`subject', `shorten-followup-to', `existing-newsgroups',
-`buffer-file-name', `unchanged', `newsgroups', `reply-to',
-`continuation-headers', `long-header-lines', `invisible-text' and
-`illegible-text'."
+Checks include `approved', `continuation-headers', `control-chars',
+`empty', `existing-newsgroups', `from', `illegible-text',
+`invisible-text', `long-header-lines', `long-lines', `message-id',
+`multiple-headers', `new-text', `newsgroups', `quoting-style',
+`repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
+`shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
+and `valid-newsgroups'."
   :group 'message-news
   :type '(repeat sexp))			; Fixme: improve this
 
@@ -3769,6 +3768,16 @@
       (let ((message-deletable-headers
 	     (if news nil message-deletable-headers)))
 	(message-generate-headers headers))
+      ;; Check continuation headers.
+      (message-check 'continuation-headers
+	(goto-char (point-min))
+	(while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
+	  (goto-char (match-beginning 0))
+	  (if (y-or-n-p "Fix continuation lines? ")
+	      (insert " ")
+	    (forward-line 1)
+	    (unless (y-or-n-p "Send anyway? ")
+	      (error "Failed to send the message")))))
       ;; Let the user do all of the above.
       (run-hooks 'message-header-hook))
     (unwind-protect
@@ -4326,11 +4335,11 @@
    (message-check 'continuation-headers
      (goto-char (point-min))
      (let ((do-posting t))
-       (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
+       (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
+	 (goto-char (match-beginning 0))
 	 (if (y-or-n-p "Fix continuation lines? ")
-	     (progn
-	       (goto-char (match-beginning 0))
-	       (insert " "))
+	     (insert " ")
+	   (forward-line 1)
 	   (unless (y-or-n-p "Send anyway? ")
 	     (setq do-posting nil))))
        do-posting))
--- a/lisp/gnus/rfc2231.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/gnus/rfc2231.el	Tue Jun 27 15:06:36 2006 +0000
@@ -176,14 +176,14 @@
 			  (buffer-substring
 			   (point)
 			   (progn
-			     (forward-sexp)
-			     ;; We might not have reached at the end of
-			     ;; the value because of non-ascii chars,
-			     ;; so we should jump over them if any.
-			     (while (and (not (eobp))
-					 (> (char-after) ?\177))
+			     ;; Jump over asterisk, non-ASCII
+			     ;; and non-boundary characters.
+			     (while (and c
+					 (or (eq c ?*)
+					     (> c ?\177)
+					     (not (eq (char-syntax c) ? ))))
 			       (forward-char 1)
-			       (forward-sexp))
+			       (setq c (char-after)))
 			     (point)))))
 		   (t
 		    (error "Invalid header: %s" string)))
--- a/lisp/international/characters.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/international/characters.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1258,7 +1258,10 @@
 ;;; Setting word boundary.
 
 (setq word-combining-categories
-      '((?l . ?l)))
+      '((?l . ?l)
+	(?C . ?C)
+	(?C . ?H)
+	(?C . ?K)))
 
 (setq word-separating-categories	;  (2-byte character sets)
       '((?A . ?K)			; Alpha numeric - Katakana
--- a/lisp/international/fontset.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/international/fontset.el	Tue Jun 27 15:06:36 2006 +0000
@@ -130,7 +130,7 @@
 	     (,(indian-font-char-range 'akruti:guj)
 	      . (nil . "Gujarati-Akruti"))
 	     (,(indian-font-char-range 'akruti:ori)
-	      . (nil . "Oriay-Akruti"))
+	      . (nil . "Oriya-Akruti"))
 	     (,(indian-font-char-range 'akruti:tml)
 	      . (nil . "Tamil-Akruti"))
 	     (,(indian-font-char-range 'akruti:tlg)
--- a/lisp/mail/sendmail.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/mail/sendmail.el	Tue Jun 27 15:06:36 2006 +0000
@@ -863,11 +863,14 @@
 		(error "Message contains non-ASCII characters"))))
 	;; Complain about any invalid line.
 	(goto-char (point-min))
-	(while (< (point) (mail-header-end))
-	  (unless (looking-at "[ \t]\\|.*:\\|$")
-	    (push-mark opoint)
-	    (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
-	  (forward-line 1))
+	(re-search-forward (regexp-quote mail-header-separator) (point-max) t)
+	(let ((header-end (or (match-beginning 0) (point-max))))
+	  (goto-char (point-min))
+	  (while (< (point) header-end)
+	    (unless (looking-at "[ \t]\\|.*:\\|$")
+	      (push-mark opoint)
+	      (error "Invalid header line (maybe a continuation line lacks initial whitespace)"))
+	    (forward-line 1)))
 	(goto-char opoint)
 	(run-hooks 'mail-send-hook)
 	(message "Sending...")
--- a/lisp/mh-e/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/mh-e/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,28 @@
+2006-06-20  Bill Wohler  <wohler@newt.com>
+
+	Release MH-E version 8.0.1.
+
+	* mh-e.el (Version, mh-version): Update for release 8.0.1.
+
+2006-06-15  Bill Wohler  <wohler@newt.com>
+
+	* mh-search.el (mh-index-new-folder): Use -2 suffix instead of <2>
+	suffix for folder names, as <> are illegal filenakme characters on
+	Windows	(closes SF #1507002).
+	
+2006-06-05  Jacob Morzinski  <morzinski@MIT.EDU>  (tiny change)
+
+	* mh-comp.el (mh-send-uses-spost): New variable.
+	(mh-send-letter): Do not use -msgid and -mime if
+	mh-send-uses-spost is t (closes SF #1486726).
+
+2006-06-02  Bill Wohler  <wohler@newt.com>
+	
+	(mh-folder-exists-p): Change test from an empty buffer, to one
+	that contains the actual folder, since GNU mailutils' folder
+	command displays output if the folder doesn't exist (closes SF
+	#1499712).
+
 2006-05-06  Bill Wohler  <wohler@newt.com>
 
 	Release MH-E version 8.0.
--- a/lisp/mh-e/mh-comp.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/mh-e/mh-comp.el	Tue Jun 27 15:06:36 2006 +0000
@@ -53,6 +53,15 @@
   "Name of the MH send program.
 Some sites need to change this because of a name conflict.")
 
+(defvar mh-send-uses-spost-flag nil
+  "Non-nil means \"send\" uses \"spost\" to submit messages.
+
+If the value of \"postproc:\" is \"spost\", you may need to set
+this variable to t to tell MH-E to avoid using features of
+\"post\" that are not supported by \"spost\". You'll know that
+you'll need to do this if sending mail fails with an error of
+\"spost: -msgid unknown\".")
+
 (defvar mh-redist-background nil
   "If non-nil redist will be done in background like send.
 This allows transaction log to be visible if -watch, -verbose or
@@ -267,16 +276,18 @@
                (and (boundp 'default-buffer-file-coding-system )
                     default-buffer-file-coding-system)
                'iso-latin-1))))
-    ;; Adding a Message-ID field looks good, makes it easier to search for
-    ;; message in your +outbox, and best of all doesn't break threading for
-    ;; the recipient if you reply to a message in your +outbox.
-    (setq mh-send-args (concat "-msgid " mh-send-args))
-    ;; The default BCC encapsulation will make a MIME message unreadable.
-    ;; With nmh use the -mime arg to prevent this.
-    (if (and (mh-variant-p 'nmh)
-             (mh-goto-header-field "Bcc:")
-             (mh-goto-header-field "Content-Type:"))
-        (setq mh-send-args (concat "-mime " mh-send-args)))
+    ;; Older versions of spost do not support -msgid and -mime.
+    (unless mh-send-uses-spost-flag
+      ;; Adding a Message-ID field looks good, makes it easier to search for
+      ;; message in your +outbox, and best of all doesn't break threading for
+      ;; the recipient if you reply to a message in your +outbox.
+      (setq mh-send-args (concat "-msgid " mh-send-args))
+      ;; The default BCC encapsulation will make a MIME message unreadable.
+      ;; With nmh use the -mime arg to prevent this.
+      (if (and (mh-variant-p 'nmh)
+               (mh-goto-header-field "Bcc:")
+               (mh-goto-header-field "Content-Type:"))
+          (setq mh-send-args (concat "-mime " mh-send-args))))
     (cond (arg
            (pop-to-buffer mh-mail-delivery-buffer)
            (erase-buffer)
--- a/lisp/mh-e/mh-e.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/mh-e/mh-e.el	Tue Jun 27 15:06:36 2006 +0000
@@ -6,7 +6,7 @@
 
 ;; Author: Bill Wohler <wohler@newt.com>
 ;; Maintainer: Bill Wohler <wohler@newt.com>
-;; Version: 8.0
+;; Version: 8.0.1
 ;; Keywords: mail
 
 ;; This file is part of GNU Emacs.
@@ -133,7 +133,7 @@
 ;; Try to keep variables local to a single file. Provide accessors if
 ;; variables are shared. Use this section as a last resort.
 
-(defconst mh-version "8.0" "Version number of MH-E.")
+(defconst mh-version "8.0.1" "Version number of MH-E.")
 
 ;; Variants
 
--- a/lisp/mh-e/mh-search.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/mh-e/mh-search.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1537,7 +1537,7 @@
 SEARCH-REGEXP then it is reused.
 
 Otherwise if the folder NAME was generated from a different
-search then check if NAME<2> can be used. Otherwise try NAME<3>.
+search then check if NAME-2 can be used. Otherwise try NAME-3.
 This is repeated till we find a new folder name.
 
 If the folder returned doesn't exist then it is created."
@@ -1545,7 +1545,7 @@
     (error "The argument should be a valid MH folder name"))
   (let ((chosen-name
          (loop for i from 1
-               for candidate = (if (equal i 1) name (format "%s<%s>" name i))
+               for candidate = (if (equal i 1) name (format "%s-%s" name i))
                when (or (not (mh-folder-exists-p candidate))
                         (equal (mh-index-folder-search-regexp candidate)
                                search-regexp))
--- a/lisp/mouse.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/mouse.el	Tue Jun 27 15:06:36 2006 +0000
@@ -529,6 +529,24 @@
       (mouse-drag-mode-line-1 start-event nil))))
 
 
+(defun mouse-drag-vertical-line-rightward-window (window)
+  "Return a window that is immediately to the right of WINDOW, or nil."
+  (let ((bottom (nth 3 (window-inside-edges window)))
+	(left (nth 0 (window-inside-edges window)))
+	best best-right
+	(try (previous-window window)))
+    (while (not (eq try window))
+      (let ((try-top (nth 1 (window-inside-edges try)))
+	    (try-bottom (nth 3 (window-inside-edges try)))
+	    (try-right (nth 2 (window-inside-edges try))))
+	(if (and (< try-top bottom)
+		 (>= try-bottom bottom)
+		 (< try-right left)
+		 (or (null best-right) (> try-right best-right)))
+	    (setq best-right try-right best try)))
+      (setq try (previous-window try)))
+    best))
+
 (defun mouse-drag-vertical-line (start-event)
   "Change the width of a window by dragging on the vertical line."
   (interactive "e")
@@ -594,7 +612,8 @@
 			;; adjust the window on the left.
 			(if (eq which-side 'right)
 			    (selected-window)
-			  (previous-window))))
+			  (mouse-drag-vertical-line-rightward-window
+			   (selected-window)))))
 		   (setq x (- (car (cdr mouse))
 			      (if (eq which-side 'right) 0 2))
 			 edges (window-edges window)
--- a/lisp/msb.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/msb.el	Tue Jun 27 15:06:36 2006 +0000
@@ -473,18 +473,21 @@
 See the function `mouse-select-buffer' and the variable
 `msb-menu-cond' for more information about how the menus are split."
   (interactive "e")
-  ;; If EVENT is a down-event, read and discard the
-  ;; corresponding up-event.
-  (and (eventp event)
-       (memq 'down (event-modifiers event))
-       (read-event))
   (let ((old-window (selected-window))
-	(window (posn-window (event-start event))))
+	(window (posn-window (event-start event)))
+	early-release)
     (unless (framep window) (select-window window))
+    ;; This `sit-for' magically makes the menu stay up if the mouse
+    ;; button is released within 0.1 second.
+    (setq early-release (not (sit-for 0.1 t)))
     (let ((buffer (mouse-select-buffer event)))
       (if buffer
 	  (switch-to-buffer buffer)
-	(select-window old-window))))
+	(select-window old-window)))
+    ;; If the above `sit-for' was interrupted by a mouse-up, avoid
+    ;; generating a drag event.
+    (if (and early-release (memq 'down (event-modifiers last-input-event)))
+	(discard-input)))
   nil)
 
 ;;;
@@ -995,9 +998,6 @@
 	;; adjust position
 	(setq posX (- posX (funcall msb-horizontal-shift-function))
 	      position (list (list posX posY) posWind))))
-    ;; This `sit-for' magically makes the menu stay up if the mouse
-    ;; button is released within 0.1 second.
-    (sit-for 0 100)
     ;; Popup the menu
     (setq choice (x-popup-menu position msb--last-buffer-menu))
     (cond
--- a/lisp/net/ldap.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/net/ldap.el	Tue Jun 27 15:06:36 2006 +0000
@@ -154,7 +154,7 @@
   :type '(string :tag "`ldapsearch' Program")
   :group 'ldap)
 
-(defcustom ldap-ldapsearch-args '("-LL" "-tt" "-x")
+(defcustom ldap-ldapsearch-args '("-LL" "-tt")
   "*A list of additional arguments to pass to `ldapsearch'."
   :type '(repeat :tag "`ldapsearch' Arguments"
 		 (string :tag "Argument"))
@@ -555,7 +555,7 @@
 	  (setq arglist (nconc arglist (list (format "-z%s" sizelimit)))))
       (eval `(call-process ldap-ldapsearch-prog
 			   nil
-			   `(,buf nil)
+			   buf
 			   nil
 			   ,@arglist
 			   ,@ldap-ldapsearch-args
@@ -580,7 +580,7 @@
 					       (end-of-line)
 					       (point))))
 	  (forward-line 1)
-	  (while (looking-at "^\\(\\w*\\)\\(;\\w*\\)?[=:\t ]+\\(<[\t ]*file://\\)?\\(.*\\)$")
+	  (while (looking-at "^\\(\\w*\\)\\(;\\w*\\)?[=:\t ]+\\(<[\t ]*file://\\)\\(.*\\)$")
 	    (setq name (match-string 1)
 		  value (match-string 4))
             ;; Need to handle file:///D:/... as generated by OpenLDAP
--- a/lisp/net/rcirc.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/net/rcirc.el	Tue Jun 27 15:06:36 2006 +0000
@@ -74,7 +74,7 @@
   :group 'rcirc)
 
 (defcustom rcirc-default-user-full-name (if (string= (user-full-name) "")
-					    rcirc-user-name
+					    rcirc-default-user-name
 					  (user-full-name))
   "The full name sent to the server when connecting."
   :type 'string
@@ -469,7 +469,7 @@
   "Return a list of rcirc processes."
   (let (ps)
     (mapc (lambda (p)
-            (when (process-buffer p)
+            (when (buffer-live-p (process-buffer p))
               (with-rcirc-process-buffer p
                 (when (eq major-mode 'rcirc-mode)
                   (setq ps (cons p ps))))))
@@ -719,8 +719,8 @@
 	  (serv (if (consp (car i)) (cdar i) "")))
       (when (and (string-match chan (or target ""))
 		 (string-match serv (rcirc-server-name process)))
-	(setq rcirc-decode-coding-system (if (consp (cdr i)) (cadr i) i)
-	      rcirc-encode-coding-system (if (consp (cdr i)) (cddr i) i)))))
+	(setq rcirc-decode-coding-system (if (consp (cdr i)) (cadr i) (cdr i))
+	      rcirc-encode-coding-system (if (consp (cdr i)) (cddr i) (cdr i))))))
 
   ;; setup the prompt and markers
   (make-local-variable 'rcirc-prompt-start-marker)
--- a/lisp/net/rcompile.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/net/rcompile.el	Tue Jun 27 15:06:36 2006 +0000
@@ -115,17 +115,25 @@
 
 ;;;; entry point
 
+;; We use the Tramp internal functions `with-parsed-tramp-file-name'
+;; and `tramp-make-tramp-file-name'.  Better would be, if there are
+;; functions to provide user, host and localname of a remote filename,
+;; independent of Tramp's implementation.  The function calls are
+;; wrapped by `funcall' in order to pacify the byte compiler.
+;; ange-ftp check removed, because it is handled also by Tramp.
 ;;;###autoload
 (defun remote-compile (host user command)
   "Compile the current buffer's directory on HOST.  Log in as USER.
 See \\[compile]."
   (interactive
-   (let ((parsed (or (and (featurep 'ange-ftp)
-                          (ange-ftp-ftp-name default-directory))))
-         host user command prompt)
+   (let ((parsed (and (featurep 'tramp)
+		      (file-remote-p default-directory)))
+         host user command prompt l l-host l-user)
      (if parsed
-         (setq host (nth 0 parsed)
-               user (nth 1 parsed))
+	 (funcall (symbol-function 'with-parsed-tramp-file-name)
+		  default-directory l
+		  (setq host l-host
+			user l-user))
        (setq prompt (if (stringp remote-compile-host)
                         (format "Compile on host (default %s): "
                                 remote-compile-host)
@@ -155,8 +163,9 @@
          (setq remote-compile-user user))
         ((null remote-compile-user)
          (setq remote-compile-user (user-login-name))))
-  (let* ((parsed (and (featurep 'ange-ftp)
-                      (ange-ftp-ftp-name default-directory)))
+  (let* (localname ;; Pacify byte-compiler.
+	 (parsed (and (featurep 'tramp)
+		      (file-remote-p default-directory)))
          (compile-command
           (format "%s %s -l %s \"(%scd %s; %s)\""
 		  remote-shell-program
@@ -165,16 +174,25 @@
                   (if remote-compile-run-before
                       (concat remote-compile-run-before "; ")
                     "")
-                  (if parsed (nth 2 parsed) default-directory)
+		  (if parsed
+		      (funcall (symbol-function 'with-parsed-tramp-file-name)
+			       default-directory nil localname)
+		    "")
                   compile-command)))
     (setq remote-compile-host host)
     (save-some-buffers nil nil)
     (compilation-start compile-command)
     ;; Set comint-file-name-prefix in the compilation buffer so
-    ;; compilation-parse-errors will find referenced files by ange-ftp.
+    ;; compilation-parse-errors will find referenced files by Tramp.
     (with-current-buffer compilation-last-buffer
-      (set (make-local-variable 'comint-file-name-prefix)
-	   (concat "/" host ":")))))
+      (when (featurep 'tramp)
+	(set (make-local-variable 'comint-file-name-prefix)
+	     (funcall (symbol-function 'tramp-make-tramp-file-name)
+	      nil ;; multi-method.  To be removed with Tramp 2.1.
+	      nil
+	      remote-compile-user
+	      remote-compile-host
+	      ""))))))
 
 ;;; arch-tag: 2866a132-ece4-4ce9-9f91-ec147f803f73
 ;;; rcompile.el ends here
--- a/lisp/net/tramp.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/net/tramp.el	Tue Jun 27 15:06:36 2006 +0000
@@ -5017,15 +5017,16 @@
 (defun tramp-touch (file time)
   "Set the last-modified timestamp of the given file.
 TIME is an Emacs internal time value as returned by `current-time'."
-  (let ((touch-time (format-time-string "%Y%m%d%H%M.%S" time)))
+  (let ((touch-time (format-time-string "%Y%m%d%H%M.%S" time t)))
     (if (tramp-tramp-file-p file)
 	(with-parsed-tramp-file-name file nil
 	  (let ((buf (tramp-get-buffer multi-method method user host)))
 	    (unless (zerop (tramp-send-command-and-check
 			    multi-method method user host
-			    (format "touch -t %s %s"
+			    (format "TZ=UTC; export TZ; touch -t %s %s"
 				    touch-time
-				    localname)))
+				    localname)
+			    t))
 	      (pop-to-buffer buf)
 	      (error "tramp-touch: touch failed, see buffer `%s' for details"
 		     buf))))
@@ -7590,6 +7591,7 @@
 ;; - Cleanup autoloads
 ;;;###autoload
 (defun tramp-unload-tramp ()
+  "Discard Tramp from loading remote files."
   (interactive)
   ;; When Tramp is not loaded yet, its autoloads are still active.
   (tramp-unload-file-name-handlers)
--- a/lisp/obsolete/options.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/obsolete/options.el	Tue Jun 27 15:06:36 2006 +0000
@@ -41,6 +41,8 @@
   (interactive)
   (with-output-to-temp-buffer "*List Options*"
     (let (vars)
+      (princ "This facility is obsolete; we recommend using M-x customize instead.")
+
       (mapatoms (function (lambda (sym)
 			    (if (user-variable-p sym)
 				(setq vars (cons sym vars))))))
--- a/lisp/pcvs.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/pcvs.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1723,16 +1723,22 @@
 	  (message "Retrieving revision %s..." rev)
 	  ;; Discard stderr output to work around the CVS+SSH+libc
 	  ;; problem when stdout and stderr are the same.
-	  (let ((res (apply 'call-process cvs-program nil '(t nil) nil
-			    "-q" "update" "-p"
-			    ;; If `rev' is HEAD, don't pass it at all:
-			    ;; the default behavior is to get the head
-			    ;; of the current branch whereas "-r HEAD"
-			    ;; stupidly gives you the head of the trunk.
-			    (append (unless (equal rev "HEAD") (list "-r" rev))
-				    (list file)))))
+	  (let ((res
+                 (let ((coding-system-for-read 'binary))
+                   (apply 'call-process cvs-program nil '(t nil) nil
+                          "-q" "update" "-p"
+                          ;; If `rev' is HEAD, don't pass it at all:
+                          ;; the default behavior is to get the head
+                          ;; of the current branch whereas "-r HEAD"
+                          ;; stupidly gives you the head of the trunk.
+                          (append (unless (equal rev "HEAD") (list "-r" rev))
+                                  (list file))))))
 	    (when (and res (not (and (equal 0 res))))
 	      (error "Something went wrong retrieving revision %s: %s" rev res))
+            ;; Figure out the encoding used and decode the byte-sequence
+            ;; into a sequence of chars.
+            (decode-coding-inserted-region
+             (point-min) (point-max) file t nil nil t)
 	    (set-buffer-modified-p nil)
 	    (let ((buffer-file-name (expand-file-name file)))
 	      (after-find-file))
--- a/lisp/play/cookie1.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/play/cookie1.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1,6 +1,6 @@
 ;;; cookie1.el --- retrieve random phrases from fortune cookie files
 
-;; Copyright (C) 1993, 2002, 2003, 2004, 2005,
+;; Copyright (C) 1993, 2002, 2003, 2004, 2005, 2006,
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
@@ -75,7 +75,7 @@
 of load, ENDMSG at the end."
   (let ((cookie-vector (cookie-snarf phrase-file startmsg endmsg)))
     (shuffle-vector cookie-vector)
-    (aref cookie-vector 1)))
+    (aref cookie-vector 0)))
 
 ;;;###autoload
 (defun cookie-insert (phrase-file &optional count startmsg endmsg)
--- a/lisp/progmodes/gdb-ui.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/progmodes/gdb-ui.el	Tue Jun 27 15:06:36 2006 +0000
@@ -76,6 +76,9 @@
 ;; 3) M-x gdb doesn't work with "run" command in .gdbinit, use M-x gdba instead.
 ;; 4) M-x gdb doesn't work if the corefile is specified in the command in the
 ;;    minibuffer, use M-x gdba instead (or specify the core in the GUD buffer).
+;; 5) If you wish to call procedures from your program in GDB
+;;    e.g "call myproc ()", "p mysquare (5)" then use level 2 annotations
+;;    "gdb --annotate=2 myprog" to keep source buffer/selected frame fixed.
 
 ;;; Problems with watch expressions, GDB/MI:
 ;; 1) They go out of scope when the inferior is re-run.
@@ -110,6 +113,7 @@
 where STATUS is nil (unchanged), `changed' or `out-of-scope', FP the frame
 address for root variables.")
 (defvar gdb-main-file nil "Source file from which program execution begins.")
+(defvar gud-old-arrow nil)
 (defvar gdb-overlay-arrow-position nil)
 (defvar gdb-server-prefix nil)
 (defvar gdb-flush-pending-output nil)
@@ -126,6 +130,9 @@
 (defvar gdb-inferior-status nil)
 (defvar gdb-continuation nil)
 (defvar gdb-look-up-stack nil)
+(defvar gdb-frame-begin nil
+  "Non-nil when GDB generates frame-begin annotation.")
+(defvar gdb-printing t)
 
 (defvar gdb-buffer-type nil
   "One of the symbols bound in `gdb-buffer-rules'.")
@@ -543,7 +550,10 @@
 	gdb-source-window nil
 	gdb-inferior-status nil
 	gdb-continuation nil
-	gdb-look-up-stack nil)
+	gdb-look-up-stack nil
+        gdb-frame-begin nil
+	gdb-printing t
+	gud-old-arrow nil)
 
   (setq gdb-buffer-type 'gdba)
 
@@ -1270,6 +1280,7 @@
 This says that I/O for the subprocess is now the program being debugged,
 not GDB."
   (setq gdb-active-process t)
+  (setq gdb-printing t)
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'user)
@@ -1278,6 +1289,7 @@
 	(setq gdb-inferior-status "running")
 	(gdb-force-mode-line-update gdb-inferior-status)
 	(gdb-remove-text-properties)
+	(setq gud-old-arrow gud-overlay-arrow-position)
 	(setq gud-overlay-arrow-position nil)
 	(setq gdb-overlay-arrow-position nil)
 	(if gdb-use-separate-io-buffer
@@ -1313,6 +1325,7 @@
   (setq gdb-active-process nil)
   (setq gud-overlay-arrow-position nil)
   (setq gdb-overlay-arrow-position nil)
+  (setq gud-old-arrow nil)
   (setq gdb-inferior-status "exited")
   (gdb-force-mode-line-update gdb-inferior-status)
   (gdb-stopping ignored))
@@ -1321,6 +1334,8 @@
   (setq gdb-signalled t))
 
 (defun gdb-frame-begin (ignored)
+  (setq gdb-frame-begin t)
+  (setq gdb-printing nil)
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'inferior)
@@ -1331,25 +1346,33 @@
       (gdb-resync)
       (error "Unexpected frame-begin annotation (%S)" sink)))))
 
+(defcustom gdb-same-frame focus-follows-mouse
+  "Non-nil means pop up GUD buffer in same frame."
+  :group 'gud
+  :type 'boolean
+  :version "22.1")
+
 (defun gdb-stopped (ignored)
   "An annotation handler for `stopped'.
 It is just like `gdb-stopping', except that if we already set the output
 sink to `user' in `gdb-stopping', that is fine."
   (setq gud-running nil)
   (unless (or gud-overlay-arrow-position gud-last-frame)
+    (if (and gdb-frame-begin gdb-printing)
+	(setq gud-overlay-arrow-position gud-old-arrow)
     ;;Pop up GUD buffer to display current frame when it doesn't have source
     ;;information i.e id not compiled with -g as with libc routines generally.
-    (let ((special-display-regexps (append special-display-regexps '(".*")))
-	  (special-display-frame-alist gdb-frame-parameters)
-	  (same-window-regexps nil))
-      (display-buffer gud-comint-buffer))
+    (if gdb-same-frame
+	(gdb-display-gdb-buffer)
+      (gdb-frame-gdb-buffer))
     ;;Try to find source further up stack e.g after signal.
     (setq gdb-look-up-stack
-	  (if (gdb-get-buffer 'gdb-stack-buffer) 'keep
+	  (if (gdb-get-buffer 'gdb-stack-buffer)
+	      'keep
 	    (progn
 	      (gdb-get-buffer-create 'gdb-stack-buffer)
 	      (gdb-invalidate-frames)
-	      'delete))))
+	      'delete)))))
   (unless (member gdb-inferior-status '("exited" "signal"))
     (setq gdb-inferior-status "stopped")
     (gdb-force-mode-line-update gdb-inferior-status))
@@ -2757,7 +2780,9 @@
   "Display GUD buffer in a new frame."
   (interactive)
   (let ((special-display-regexps (append special-display-regexps '(".*")))
-	(special-display-frame-alist gdb-frame-parameters)
+	(special-display-frame-alist
+	 (remove '(menu-bar-lines) (remove '(tool-bar-lines)
+					   gdb-frame-parameters)))
 	(same-window-regexps nil))
     (display-buffer gud-comint-buffer)))
 
@@ -3193,8 +3218,8 @@
     (setq gdb-frame-number (match-string 1))
     (setq gdb-frame-address (match-string 2)))
   (goto-char (point-min))
-  (when (re-search-forward ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(\\S-+?\\)\
-\\(?: (\\(\\S-+?\\):[0-9]+?)\\)*;? "
+  (when (re-search-forward ".*=\\s-+0x0*\\(\\S-*\\)\\s-+in\\s-+\\(.*?\\)\
+\\(?: (\\(\\S-+?\\):[0-9]+?)\\)*; "
      nil t)
     (setq gdb-selected-frame (match-string 2))
     (if (gdb-get-buffer 'gdb-locals-buffer)
--- a/lisp/progmodes/grep.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/progmodes/grep.el	Tue Jun 27 15:06:36 2006 +0000
@@ -282,13 +282,13 @@
      (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$"
       1 grep-error-face)
      ;; remove match from grep-regexp-alist before fontifying
-     ("^Grep started.*"
+     ("^Grep[/a-zA-z]* started.*"
       (0 '(face nil message nil help-echo nil mouse-face nil) t))
-     ("^Grep finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*"
+     ("^Grep[/a-zA-z]* finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*"
       (0 '(face nil message nil help-echo nil mouse-face nil) t)
       (1 compilation-info-face nil t)
       (2 compilation-warning-face nil t))
-     ("^Grep \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
+     ("^Grep[/a-zA-z]* \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
       (0 '(face nil message nil help-echo nil mouse-face nil) t)
       (1 grep-error-face)
       (2 grep-error-face nil t))
--- a/lisp/simple.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/simple.el	Tue Jun 27 15:06:36 2006 +0000
@@ -3521,7 +3521,7 @@
 		    (if (and track-eol (eolp)
 			     ;; Don't count beg of empty line as end of line
 			     ;; unless we just did explicit end-of-line.
-			     (or (not (bolp)) (eq last-command 'end-of-line)))
+			     (or (not (bolp)) (eq last-command 'move-end-of-line)))
 			9999
 		      (current-column))))
 
--- a/lisp/term.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/term.el	Tue Jun 27 15:06:36 2006 +0000
@@ -3613,7 +3613,7 @@
 		   (progn
 		     ;; Delete scroll-needed lines at term-scroll-end,
 		     ;; then insert scroll-needed lines.
-		     (term-vertical-motion (1- term-scroll-end))
+		     (term-vertical-motion term-scroll-end)
 		     (end-of-line)
 		     (setq save-top (point))
 		     (term-vertical-motion scroll-needed)
@@ -3767,11 +3767,15 @@
 	(save-current-column term-current-column)
 	(save-start-line-column term-start-line-column)
 	(save-current-row (term-current-row)))
-    (when (>= (+ save-current-row lines) term-scroll-end)
-	(setq lines (- lines (- (+ save-current-row lines) term-scroll-end))))
+    ;; The number of inserted lines shouldn't exceed the scroll region end.
+    ;; The `term-scroll-end' line is part of the scrolling region, so
+    ;; we need to go one line past it in order to ensure correct
+    ;; scrolling.
+    (when (> (+ save-current-row lines) (1+ term-scroll-end))
+      (setq lines (- lines (- (+ save-current-row lines) (1+ term-scroll-end)))))
     (term-down lines)
     (delete-region start (point))
-    (term-down (- term-scroll-end save-current-row lines))
+    (term-down (- (1+ term-scroll-end) save-current-row lines))
     (term-insert-char ?\n lines)
     (setq term-current-column save-current-column)
     (setq term-start-line-column save-start-line-column)
@@ -3785,6 +3789,9 @@
 	(save-start-line-column term-start-line-column)
 	(save-current-row (term-current-row)))
     ;; Inserting lines should take into account the scroll region.
+    ;; The `term-scroll-end' line is part of the scrolling region, so
+    ;; we need to go one line past it in order to ensure correct
+    ;; scrolling.
     (if (< save-current-row term-scroll-start)
 	;; If point is before scroll start, 
 	(progn 
@@ -3792,9 +3799,9 @@
 	  (term-down (- term-scroll-start save-current-row))
 	  (setq start (point)))
       ;; The number of inserted lines shouldn't exceed the scroll region end.
-      (when (>= (+ save-current-row lines) term-scroll-end)
-	(setq lines (- lines (- (+ save-current-row lines) term-scroll-end))))
-      (term-down (- term-scroll-end save-current-row lines)))
+      (when (> (+ save-current-row lines) (1+ term-scroll-end))
+	(setq lines (- lines (- (+ save-current-row lines)(1+ term-scroll-end)))))
+      (term-down (- (1+ term-scroll-end) save-current-row lines)))
     (setq start-deleted (point))
     (term-down lines)
     (delete-region start-deleted (point))
--- a/lisp/term/mac-win.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/term/mac-win.el	Tue Jun 27 15:06:36 2006 +0000
@@ -1249,6 +1249,9 @@
 
 ;;;; Conversion between common flavors and Lisp string.
 
+(defconst mac-text-encoding-ascii #x600
+  "ASCII text encoding.")
+
 (defconst mac-text-encoding-mac-japanese-basic-variant #x20001
   "MacJapanese text encoding without Apple double-byte extensions.")
 
@@ -1269,7 +1272,7 @@
 	  (if (string-match "[\xa0\xfd-\xff]" str)
 	      (setq str nil)
 	    ;; ASCII-only?
-	    (unless (string-match "\\`[[:ascii:]]*\\'" str)
+	    (unless (mac-code-convert-string data nil mac-text-encoding-ascii)
 	      (subst-char-in-string ?\x5c ?\(J\(B str t)
 	      (subst-char-in-string ?\x80 ?\\ str t)))))
     (or str
@@ -1965,8 +1968,7 @@
 	 (coding (or (cdr (assq (car script-language)
 				mac-script-code-coding-systems))
 		     'mac-roman))
-	 (fix-len (mac-bytes-to-integer
-		   (cdr (mac-ae-parameter ae "tsfx" "long"))))
+	 (fix-len (mac-ae-number ae "tsfx"))
 	 ;; Optional parameters
 	 (hilite-rng (mac-ae-text-range-array ae "tshi"))
 	 (update-rng (mac-ae-text-range-array ae "tsup"))
@@ -2008,15 +2010,15 @@
       (put-text-property 0 (length active-input-string)
 			 'mac-ts-active-input-string t active-input-string)
       (if use-echo-area
-	  (let (msg message-log-max)
-	    (if (and (current-message)
+	  (let ((msg (current-message))
+		message-log-max)
+	    (if (and msg
 		     ;; Don't get confused by previously displayed
 		     ;; `active-input-string'.
 		     (null (get-text-property 0 'mac-ts-active-input-string
-					      (current-message))))
-		(setq msg (propertize (current-message) 'display
-				      (concat (current-message)
-					      active-input-string)))
+					      msg)))
+		(setq msg (propertize msg 'display
+				      (concat msg active-input-string)))
 	      (setq msg active-input-string))
 	    (message "%s" msg)
 	    (overlay-put mac-ts-active-input-overlay 'before-string nil))
--- a/lisp/term/xterm.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/term/xterm.el	Tue Jun 27 15:06:36 2006 +0000
@@ -159,9 +159,10 @@
 (define-key xterm-function-map "\e[4~" [select])
 (define-key xterm-function-map "\e[29~" [print])
 
-;; These keys will be available xterm starting probably from
-;; version 214.
+;; These keys are available in xterm starting from version 214
+;; if the modifyOtherKeys resource is set.
 (define-key xterm-function-map "\e[27;5;9~"  [(control ?\t)])
+(define-key xterm-function-map "\e[27;5;13~" [C-return])
 (define-key xterm-function-map "\e[27;5;44~" [(control ?\,)])
 (define-key xterm-function-map "\e[27;5;46~" [(control ?\.)])
 (define-key xterm-function-map "\e[27;5;47~" [(control ?\/)])
--- a/lisp/textmodes/org.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/textmodes/org.el	Tue Jun 27 15:06:36 2006 +0000
@@ -5,7 +5,7 @@
 ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
-;; Version: 4.36b
+;; Version: 4.39
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -90,6 +90,21 @@
 ;;
 ;; Recent changes
 ;; --------------
+;; Version 4.39
+;;    - Special tag ARCHIVE keeps a subtree closed and away from agenda lists.
+;;    - LaTeX code in Org-mode files can be converted to images for HTML.
+;;    - Bug fixes.
+;;    - CDLaTeX-mode features can be used in Org-mode to help inserting
+;;      LaTeX environment and math.
+;;
+;; Version 4.38
+;;    - noutline.el is now required (important for XEmacs users only).
+;;    - Dynamic blocks.
+;;    - Archiving of all level 1 trees without open TODO items.
+;;    - Clock reports can be inserted into the file in a special section.
+;;    - FAQ removed from the manual, now only on the web.
+;;    - Bug fixes.
+;;
 ;; Version 4.37
 ;;    - Clock-feature for measuring time spent on specific items.
 ;;    - Improved emphasizing allows configuration and stacking.
@@ -170,13 +185,18 @@
 (eval-when-compile
   (require 'cl)
   (require 'calendar))
-(require 'outline)
+;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
+;; the file noutline.el being loaded.
+(if (featurep 'xemacs) (condition-case nil (require 'noutline)))
+;; We require noutline, which might be provided in outline.el
+(require 'outline) (require 'noutline)
+;; Other stuff we need.
 (require 'time-date)
 (require 'easymenu)
 
 ;;; Customization variables
 
-(defvar org-version "4.36b"
+(defvar org-version "4.39"
   "The version number of the file org.el.")
 (defun org-version ()
   (interactive)
@@ -396,7 +416,8 @@
 		 (const :tag "Everywhere except in headlines" t)
 		 ))
 
-(defcustom org-cycle-hook '(org-optimize-window-after-visibility-change)
+(defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
+			    org-optimize-window-after-visibility-change)
   "Hook that is run after `org-cycle' has changed the buffer visibility.
 The function(s) in this hook must accept a single argument which indicates
 the new state that was set by the most recent `org-cycle' command.  The
@@ -524,6 +545,38 @@
   :tag "Org Archive"
   :group 'org-structure)
 
+(defcustom org-archive-tag "ARCHIVE"
+  "The tag that marks a subtree as archived.
+An archived subtree does not open during visibility cycling, and does
+not contribute to the agenda listings."
+  :group 'org-archive
+  :group 'org-keywords
+  :type 'string)
+
+(defcustom org-agenda-skip-archived-trees t
+  "Non-nil means, the agenda will skip any items located in archived trees.
+An archived tree is a tree marked with the tag ARCHIVE."
+  :group 'org-archive
+  :group 'org-agenda-display
+  :type 'boolean)
+
+(defcustom org-cycle-open-archived-trees nil
+  "Non-nil means, `org-cycle' will open archived trees.
+An archived tree is a tree marked with the tag ARCHIVE.
+When nil, archived trees will stay folded.  You can still open them with
+normal outline commands like `show-all', but not with the cycling commands."
+  :group 'org-archive
+  :group 'org-cycle
+  :type 'boolean)
+
+(defcustom org-sparse-tree-open-archived-trees nil
+  "Non-nil means sparse tree construction shows matches in archived trees.
+When nil, matches in these trees are highlighted, but the trees are kept in
+collapsed state."
+  :group 'org-archive
+  :group 'org-sparse-trees
+  :type 'boolean)
+
 (defcustom org-archive-location "%s_archive::"
   "The location where subtrees should be archived.
 This string consists of two parts, separated by a double-colon.
@@ -561,12 +614,12 @@
   :type 'string)
 
 (defcustom org-archive-mark-done t
-  "Non-nil means, mark archived entries as DONE."
+  "Non-nil means, mark entries as DONE when they are moved to the archive file."
   :group 'org-archive
   :type 'boolean)
 
 (defcustom org-archive-stamp-time t
-  "Non-nil means, add a time stamp to archived entries.
+  "Non-nil means, add a time stamp to entries moved to an archive file.
 The time stamp will be added directly after the TODO state keyword in the
 first line, so it is probably best to use this in combinations with
 `org-archive-mark-done'."
@@ -1015,12 +1068,14 @@
 	  (const :tag "no confirmation (dangerous)" nil)))
 
 (defconst org-file-apps-defaults-gnu
-  '((t . mailcap))
+  '((remote . emacs)
+    (t . mailcap))
   "Default file applications on a UNIX or GNU/Linux system.
 See `org-file-apps'.")
 
 (defconst org-file-apps-defaults-macosx
-  '((t        . "open %s")
+  '((remote . emacs)
+    (t        . "open %s")
     ("ps"     . "gv %s")
     ("ps.gz"  . "gv %s")
     ("eps"    . "gv %s")
@@ -1033,11 +1088,13 @@
 See `org-file-apps'.")
 
 (defconst org-file-apps-defaults-windowsnt
-  (list (cons t
-	      (list (if (featurep 'xemacs)
-			'mswindows-shell-execute
-		      'w32-shell-execute)
-		      "open" 'file)))
+  (list 
+   '(remote . emacs)
+   (cons t
+	 (list (if (featurep 'xemacs)
+		   'mswindows-shell-execute
+		 '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'.")
@@ -1059,6 +1116,9 @@
 file identifier are
  \"ext\"         A string identifying an extension
  `directory'   Matches a directory
+ `remote'      Matches a remove file, accessible through tramp or efs.
+               Remote files most likely should be visited through emacs
+               because external applications cannot handle such paths.
  t             Default for all remaining files
 
 Possible values for the command are:
@@ -1077,6 +1137,7 @@
 	  (cons (choice :value ""
 			(string :tag "Extension")
 			(const :tag "Default for unrecognized files" t)
+			(const :tag "Remote file" remote)
 			(const :tag "Links to a directory" directory))
 		(choice :value ""
 			(const :tag "Visit with Emacs" emacs)
@@ -1702,6 +1763,29 @@
 	  (const :tag "All" t)
 	  (number :tag "at most")))
 
+(defgroup org-latex nil
+  "Options for embedding LaTeX code into Org-mode"
+  :tag "Org LaTeX"
+  :group 'org)
+
+(defcustom org-format-latex-options
+  '(:foreground "Black" :background "Transparent" :scale 1.0
+		:matchers ("begin" "$" "$$" "\\(" "\\["))
+  "Options for creating images from LaTeX fragments.
+This is a property list with the following properties:
+:foreground  the foreground color, for example \"Black\".
+:background  the background color, or \"Transparent\".
+:scale       a scaling factor for the size of the images
+:matchers    a list indicating which matchers should be used to
+             find LaTeX fragments.  Valid members of this list are:
+             \"begin\"  find environments
+             \"$\"      find mathc expressions surrounded by $...$
+             \"$$\"     find math expressions surrounded by $$....$$
+             \"\\(\"    find math expressions surrounded by \\(...\\)
+             \"\\[\"    find math expressions surrounded by \\[...\\]"
+  :group 'org-latex
+  :type 'plist)
+
 (defgroup org-export nil
   "Options for exporting org-listings."
   :tag "Org Export"
@@ -1800,6 +1884,19 @@
   :group 'org-export-general
   :type 'boolean)
 
+(defcustom org-export-with-archived-trees 'headline
+  "Whether subtrees with the ARCHIVE tag should be exported.
+This can have three different values
+nil       Do not export, pretend this tree is not present
+t         Do export the entire tree
+headline  Only export the headline, but skip the tree below it."
+  :group 'org-export-general
+  :group 'org-archive
+  :type '(choice
+	  (const :tag "not at all" nil)
+	  (const :tag "headline only" 'headline)
+	  (const :tag "entirely" t)))
+
 (defcustom org-export-with-timestamps t
   "Nil means, do not export time stamps and associated keywords."
   :group 'org-export
@@ -1863,6 +1960,19 @@
 
 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
   :group 'org-export-translation
+  :group 'org-latex
+  :type 'boolean)
+
+(defcustom org-export-with-LaTeX-fragments nil
+  "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
+When set, the exporter will find LaTeX environments if the \\begin line is
+the first non-white thing on a line.  It will also find the math delimiters
+like $a=b$ and \\( a=b \\) for inline math,  $$a=b$$ and \\[ a=b \\] for
+display math.
+
+This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
+  :group 'org-export-translation
+  :group 'org-latex
   :type 'boolean)
 
 (defcustom org-export-with-fixed-width t
@@ -2202,7 +2312,7 @@
              `org-emphasis-alist') will be allowed as pre/post, aiding
              inside-out matching.
 Use customize to modify this, or restart emacs after changing it."
-  :group 'org-fixme
+  :group 'org-font-lock
   :set 'org-set-emph-re
   :type '(list
 	  (sexp    :tag "Allowed chars in pre      ")
@@ -2216,19 +2326,23 @@
   '(("*" bold "<b>" "</b>")
     ("/" italic "<i>" "</i>")
     ("_" underline "<u>" "</u>")
-    ("=" shadow "<code>" "</code>"))
+    ("=" shadow "<code>" "</code>")
+    ("+" (:strike-through t) "<del>" "</del>")
+)
 "Special syntax for emphasised text.
 Text starting and ending with a special character will be emphasized, for
 example *bold*, _underlined_ and /italic/.  This variable sets the marker
 characters, the face to bbe used by font-lock for highlighting in Org-mode
 emacs buffers, and the HTML tags to be used for this.
 Use customize to modify this, or restart emacs after changing it."
-  :group 'org-fixme
+  :group 'org-font-lock
   :set 'org-set-emph-re
   :type '(repeat
 	  (list
 	   (string :tag "Marker character")
-	   (face :tag "Font-lock-face")
+	   (choice
+	    (face :tag "Font-lock-face")
+	    (plist :tag "Face property list"))
 	   (string :tag "HTML start tag")
 	   (string :tag "HTML end tag"))))
 
@@ -2370,6 +2484,19 @@
 This face is only used if `org-fontify-done-headline' is set."
   :group 'org-faces)
 
+(defface org-archived    ; similar to shadow
+  (org-compatible-face
+   '((((class color grayscale) (min-colors 88) (background light))
+      (:foreground "grey50"))
+     (((class color grayscale) (min-colors 88) (background dark))
+      (:foreground "grey70"))
+     (((class color) (min-colors 8) (background light))
+      (:foreground "green"))
+     (((class color) (min-colors 8) (background dark))
+      (:foreground "yellow"))))
+   "Face for headline with the ARCHIVE tag."
+   :group 'org-faces)
+
 (defface org-link
   '((((class color) (background light)) (:foreground "Purple" :underline t))
     (((class color) (background dark)) (:foreground "Cyan" :underline t))
@@ -2608,7 +2735,7 @@
       (and arch (set (make-local-variable 'org-archive-location) arch))
       (and int (set (make-local-variable 'org-todo-interpretation) int))
       (when tags
-	(let (e tg c tgs)
+	(let (e tgs)
 	  (while (setq e (pop tags))
 	    (cond
 	     ((equal e "{") (push '(:startgroup) tgs))
@@ -2690,6 +2817,8 @@
 (defvar org-goto-start-pos) ; dynamically scoped parameter
 (defvar org-time-was-given) ; dynamically scoped parameter
 (defvar org-ts-what) ; dynamically scoped parameter
+(defvar org-current-export-file) ; dynamically scoped parameter
+(defvar org-current-export-dir) ; dynamically scoped parameter
 (defvar mark-active) ; Emacs only, not available in XEmacs.
 (defvar timecnt) ; dynamically scoped parameter
 (defvar levels-open) ; dynamically scoped parameter
@@ -2708,6 +2837,7 @@
 (defvar gnus-group-name) ; from gnus
 (defvar gnus-article-current) ; from gnus
 (defvar w3m-current-url) ; from w3m
+(defvar w3m-current-title) ; from w3m
 (defvar mh-progs) ; from MH-E
 (defvar mh-current-folder) ; from MH-E
 (defvar mh-show-folder-buffer) ; from MH-E
@@ -2823,8 +2953,10 @@
       (insert "    -*- mode: org -*-\n\n"))
 
   (unless org-inhibit-startup
-    (if org-startup-align-all-tables
-	(org-table-map-tables 'org-table-align))
+    (when org-startup-align-all-tables
+      (let ((bmp (buffer-modified-p)))
+	(org-table-map-tables 'org-table-align)
+	(set-buffer-modified-p bmp)))
     (if org-startup-with-deadline-check
 	(call-interactively 'org-check-deadlines)
       (cond
@@ -3177,6 +3309,7 @@
 	   '("^[ \t]*| *\\([#!$*_^]\\) *|" (1 'org-formula t))
 	   (if org-format-transports-properties-p
 	       '("| *\\(<[0-9]+>\\) *" (1 'org-formula t)))
+	   '("^\\*+ \\(.*:ARCHIVE:.*\\)" (1 'org-archived prepend))
 	   )))
     (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
     ;; Now set the full font-lock-keywords
@@ -3253,7 +3386,11 @@
 	    outline-regexp))
 	 (bob-special (and org-cycle-global-at-bob (bobp)
 			   (not (looking-at outline-regexp))))
-	 (org-cycle-hook (if bob-special nil org-cycle-hook))
+	 (org-cycle-hook
+	  (if bob-special
+	      (delq 'org-optimize-window-after-visibility-change
+		    (copy-sequence org-cycle-hook))
+	    org-cycle-hook))
 	 (pos (point)))
 
     (if (or bob-special (equal arg '(4)))
@@ -3271,7 +3408,7 @@
 	      (call-interactively 'org-table-next-field)))))
 
      ((eq arg t) ;; Global cycling
-
+      
       (cond
        ((and (eq last-command this-command)
 	     (eq org-cycle-global-status 'overview))
@@ -3350,6 +3487,9 @@
 
      ;; TAB emulation
      (buffer-read-only (org-back-to-heading))
+
+     ((org-try-cdlatex-tab))
+
      ((if (and (memq org-cycle-emulate-tab '(white whitestart))
 	       (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
 	       (or (and (eq org-cycle-emulate-tab 'white)
@@ -3617,10 +3757,8 @@
 		t)
 	    (error nil)))
     (let* ((bul (match-string 0))
-	   (end (match-end 0))
 	   (eow (save-excursion (beginning-of-line 1) (looking-at "[ \t]*")
 				(match-end 0)))
-	   (eowcol (save-excursion (goto-char eow) (current-column)))
 	   pos)
       (cond
        ((and (org-at-item-p) (<= (point) eow))
@@ -3722,9 +3860,7 @@
     (replace-match up-head nil t)
     ;; Fixup tag positioning
     (and org-auto-align-tags (org-set-tags nil t))
-    (if org-adapt-indentation
-	(org-fixup-indentation (if (> diff 1) "^  " "^ ") ""
-			       (if (> diff 1) "^ ? ?\\S-" "^ ?\\S-")))))
+    (if org-adapt-indentation (org-fixup-indentation (- diff)))))
 
 (defun org-demote ()
   "Demote the current heading lower down the tree.
@@ -3737,8 +3873,7 @@
     (replace-match down-head nil t)
     ;; Fixup tag positioning
     (and org-auto-align-tags (org-set-tags nil t))
-    (if org-adapt-indentation
-	(org-fixup-indentation "^ " (if (> diff 1) "   " "  ") "^\\S-"))))
+    (if org-adapt-indentation (org-fixup-indentation diff))))
 
 (defun org-map-tree (fun)
   "Call FUN for every heading underneath the current one."
@@ -3767,20 +3902,23 @@
 		  (not (eobp)))
 	(funcall fun)))))
 
-;; FIXME: this does not work well with Tabulators.  This has to be re-written entirely.
-(defun org-fixup-indentation (from to prohibit)
-  "Change the indentation in the current entry by re-replacing FROM with TO.
-However, if the regexp PROHIBIT matches at all, don't do anything.
-This is being used to change indentation along with the length of the
-heading marker.  But if there are any lines which are not indented, nothing
-is changed at all."
+(defun org-fixup-indentation (diff)
+  "Change the indentation in the current entry by DIFF
+However, if any line in the current entry has no indentation, or if it
+would end up with no indentation after the change, nothing at all is done."
   (save-excursion
     (let ((end (save-excursion (outline-next-heading)
-			       (point-marker))))
+			       (point-marker)))
+	  (prohibit (if (> diff 0)
+			"^\\S-" 
+		      (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
+	  col)
       (unless (save-excursion (re-search-forward prohibit end t))
-	(while (re-search-forward from end t)
-	  (replace-match to)
-	  (beginning-of-line 2)))
+	(while (re-search-forward "^[ \t]+" end t)
+	  (goto-char (match-end 0))
+	  (setq col (current-column))
+	  (if (< diff 0) (replace-match ""))
+	  (indent-to (+ diff col))))
       (move-marker end nil))))
 
 ;;; Vertical tree motion, cutting and pasting of subtrees
@@ -3984,6 +4122,14 @@
 	      (throw 'exit nil)))
 	t))))
 
+(defun org-narrow-to-subtree ()
+  "Narrow buffer to the current subtree."
+  (interactive)
+  (save-excursion
+    (narrow-to-region
+     (progn (org-back-to-heading) (point))
+     (progn (org-end-of-subtree t) (point)))))
+
 ;;; Plain list items
 
 (defun org-at-item-p ()
@@ -4101,12 +4247,10 @@
   "Move to the beginning of the next item in the current plain list.
 Error if not at a plain list, or if this is the last item in the list."
   (interactive)
-  (let (beg end ind ind1 (pos (point)) txt)
+  (let (ind ind1 (pos (point)))
     (org-beginning-of-item)
-    (setq beg (point))
     (setq ind (org-get-indentation))
     (org-end-of-item)
-    (setq end (point))
     (setq ind1 (org-get-indentation))
     (unless (and (org-at-item-p) (= ind ind1))
       (goto-char pos)
@@ -4116,7 +4260,7 @@
   "Move to the beginning of the previous item in the current plain list.
 Error if not at a plain list, or if this is the last item in the list."
   (interactive)
-  (let (beg end ind ind1 (pos (point)) txt)
+  (let (beg ind (pos (point)))
     (org-beginning-of-item)
     (setq beg (point))
     (setq ind (org-get-indentation))
@@ -4126,7 +4270,7 @@
 	(beginning-of-line 0)
 	(if (looking-at "[ \t]*$")
 	    nil
-	  (if (<= (setq ind1 (org-get-indentation)) ind)
+	  (if (<= (org-get-indentation) ind)
 	      (throw 'exit t)))))
     (condition-case nil
 	(org-beginning-of-item)
@@ -4292,103 +4436,391 @@
 
 ;;; Archiving
 
-(defun org-archive-subtree ()
+(defun org-archive-subtree (&optional find-done)
   "Move the current subtree to the archive.
 The archive can be a certain top-level heading in the current file, or in
 a different file.  The tree will be moved to that location, the subtree
-heading be marked DONE, and the current time will be added."
-  (interactive)
-  ;; Save all relevant TODO keyword-relatex variables
-  (let ((tr-org-todo-line-regexp org-todo-line-regexp) ; keep despite compiler
-	(tr-org-todo-keywords org-todo-keywords)
-	(tr-org-todo-interpretation org-todo-interpretation)
-	(tr-org-done-string org-done-string)
-	(tr-org-todo-regexp org-todo-regexp)
-	(tr-org-todo-line-regexp org-todo-line-regexp)
-	(this-buffer (current-buffer))
-	file heading buffer level newfile-p)
-    (if (string-match "\\(.*\\)::\\(.*\\)" org-archive-location)
+heading be marked DONE, and the current time will be added.
+
+When called with prefix argument FIND-DONE, find whole trees without any
+open TODO items and archive them (after getting confirmation from the user).
+If the cursor is not at a headline when this comand is called, try all level
+1 trees.  If the cursor is on a headline, only try the direct children of
+this heading. "
+  (interactive "P")
+  (if find-done
+      (org-archive-all-done)
+    ;; Save all relevant TODO keyword-relatex variables
+    
+    (let ((tr-org-todo-line-regexp org-todo-line-regexp) ; keep despite compiler
+	  (tr-org-todo-keywords org-todo-keywords)
+	  (tr-org-todo-interpretation org-todo-interpretation)
+	  (tr-org-done-string org-done-string)
+	  (tr-org-todo-regexp org-todo-regexp)
+	  (tr-org-todo-line-regexp org-todo-line-regexp)
+	  (this-buffer (current-buffer))
+	  file heading buffer level newfile-p)
+      (if (string-match "\\(.*\\)::\\(.*\\)" org-archive-location)
+	  (progn
+	    (setq file (format (match-string 1 org-archive-location)
+			       (file-name-nondirectory buffer-file-name))
+		  heading (match-string 2 org-archive-location)))
+	(error "Invalid `org-archive-location'"))
+      (if (> (length file) 0)
+	  (setq newfile-p (not (file-exists-p file))
+		buffer (find-file-noselect file))
+	(setq buffer (current-buffer)))
+      (unless buffer
+	(error "Cannot access file \"%s\"" file))
+      (if (and (> (length heading) 0)
+	       (string-match "^\\*+" heading))
+	  (setq level (match-end 0))
+	(setq heading nil level 0))
+      (save-excursion
+	;; We first only copy, in case something goes wrong
+	;; we need to protect this-command, to avoid kill-region sets it,
+	;; which would lead to duplication of subtrees
+	(let (this-command) (org-copy-subtree))
+	(set-buffer buffer)
+	;; Enforce org-mode for the archive buffer
+	(if (not (eq major-mode 'org-mode))
+	    ;; Force the mode for future visits.
+	    (let ((org-insert-mode-line-in-empty-file t))
+	      (call-interactively 'org-mode)))
+	(when newfile-p
+	  (goto-char (point-max))
+	  (insert (format "\nArchived entries from file %s\n\n"
+			  (buffer-file-name this-buffer))))
+	;; Force the TODO keywords of the original buffer
+	(let ((org-todo-line-regexp tr-org-todo-line-regexp)
+	      (org-todo-keywords tr-org-todo-keywords)
+	      (org-todo-interpretation tr-org-todo-interpretation)
+	      (org-done-string tr-org-done-string)
+	      (org-todo-regexp tr-org-todo-regexp)
+	      (org-todo-line-regexp tr-org-todo-line-regexp))
+	  (goto-char (point-min))
+	  (if heading
+	      (progn
+		(if (re-search-forward
+		     (concat "\\(^\\|\r\\)"
+			     (regexp-quote heading) "[ \t]*\\($\\|\r\\)")
+		     nil t)
+		    (goto-char (match-end 0))
+		  ;; Heading not found, just insert it at the end
+		  (goto-char (point-max))
+		  (or (bolp) (insert "\n"))
+		  (insert "\n" heading "\n")
+		  (end-of-line 0))
+		;; Make the subtree visible
+		(show-subtree)
+		(org-end-of-subtree t)
+		(skip-chars-backward " \t\r\n]")
+		(and (looking-at "[ \t\r\n]*")
+		     (replace-match "\n\n")))
+	    ;; No specific heading, just go to end of file.
+	    (goto-char (point-max)) (insert "\n"))
+	  ;; Paste
+	  (org-paste-subtree (1+ level))
+	  ;; Mark the entry as done, i.e. set to last work in org-todo-keywords
+	  (if org-archive-mark-done
+	      (org-todo (length org-todo-keywords)))
+	  ;; Move cursor to right after the TODO keyword
+	  (when org-archive-stamp-time
+	    (beginning-of-line 1)
+	    (looking-at org-todo-line-regexp)
+	    (goto-char (or (match-end 2) (match-beginning 3)))
+	    (insert "(" (format-time-string (cdr org-time-stamp-formats)
+					    (org-current-time))
+		    ")"))
+	  ;; Save the buffer, if it is not the same buffer.
+	  (if (not (eq this-buffer buffer)) (save-buffer))))
+      ;; Here we are back in the original buffer.  Everything seems to have
+      ;; worked.  So now cut the tree and finish up.
+      (let (this-command) (org-cut-subtree))
+      (if (and (not (eobp)) (looking-at "[ \t]*$")) (kill-line))
+      (message "Subtree archived %s"
+	       (if (eq this-buffer buffer)
+		   (concat "under heading: " heading)
+		 (concat "in file: " (abbreviate-file-name file)))))))
+
+(defun org-archive-all-done (&optional tag)
+  "Archive sublevels of the current tree without open TODO items.
+If the cursor is not on a headline, try all level 1 trees.  If
+it is on a headline, try all direct children.
+When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
+  (let ((re (concat "^\\*+ +" org-not-done-regexp)) re1
+	(rea (concat ".*:" org-archive-tag ":"))
+	(begm (make-marker))
+	(endm (make-marker))
+	(question (if tag "Set ARCHIVE tag (no open TODO items)? "
+		    "Move subtree to archive (no open TODO items)? "))
+	beg end (cntarch 0))
+    (if (org-on-heading-p)
 	(progn
-	  (setq file (format (match-string 1 org-archive-location)
-			     (file-name-nondirectory buffer-file-name))
-		heading (match-string 2 org-archive-location)))
-      (error "Invalid `org-archive-location'"))
-    (if (> (length file) 0)
-	(setq newfile-p (not (file-exists-p file))
-	      buffer (find-file-noselect file))
-      (setq buffer (current-buffer)))
-    (unless buffer
-      (error "Cannot access file \"%s\"" file))
-    (if (and (> (length heading) 0)
-	     (string-match "^\\*+" heading))
-	(setq level (match-end 0))
-      (setq heading nil level 0))
+	  (setq re1 (concat "^" (regexp-quote
+				 (make-string 
+				  (1+ (- (match-end 0) (match-beginning 0)))
+				  ?*))
+			    " "))
+	  (move-marker begm (point))
+	  (move-marker endm (org-end-of-subtree)))
+      (setq re1 "^* ")
+      (move-marker begm (point-min))
+      (move-marker endm (point-max)))
+    (save-excursion
+      (goto-char begm)
+      (while (re-search-forward re1 endm t)
+	      beg (match-beginning 0)
+	      end (save-excursion (org-end-of-subtree t) (point)))
+	(goto-char beg)
+	(if (re-search-forward re end t)
+	    (goto-char end)
+	  (goto-char beg)
+	  (if (and (or (not tag) (not (looking-at rea)))
+		   (y-or-n-p question))
+	      (progn
+		(if tag
+		    (org-toggle-tag org-archive-tag 'on)
+		  (org-archive-subtree))
+		(setq cntarch (1+ cntarch)))
+	    (goto-char end))))
+    (message "%d trees archived" cntarch)))
+
+
+(defun org-cycle-hide-archived-subtrees (state)
+  "Re-hide all archived subtrees after a visibility state change."
+  (when (and (not org-cycle-open-archived-trees)
+             (not (memq state '(overview folded))))
+    (save-excursion
+      (let* ((globalp (memq state '(contents all)))
+             (beg (if globalp (point-min) (point)))
+             (end (if globalp (point-max) (org-end-of-subtree))))
+	(org-hide-archived-subtrees beg end)))))
+
+(defun org-hide-archived-subtrees (beg end)
+  "Re-hide all archived subtrees after a visibility state change."
+  (save-excursion
+    (let* ((re (concat ":" org-archive-tag ":")))
+      (goto-char beg)
+      (while (re-search-forward re end t)
+	(and (org-on-heading-p) (hide-subtree))
+	(org-end-of-subtree)))))
+
+(defun org-toggle-tag (tag &optional onoff)
+  "Toggle the tag TAG for the current line.
+If ONOFF is `on' or `off', don't toggle but set to this state."
+  (unless (org-on-heading-p) (error "Not on headling"))
+  (let (res current)
     (save-excursion
-      ;; We first only copy, in case something goes wrong
-      ;; we need to protect this-command, to avoid kill-region sets it,
-      ;; which would lead to duplication of subtrees
-      (let (this-command) (org-copy-subtree))
-      (set-buffer buffer)
-      ;; Enforce org-mode for the archive buffer
-      (if (not (eq major-mode 'org-mode))
-	  ;; Force the mode for future visits.
-	  (let ((org-insert-mode-line-in-empty-file t))
-	    (call-interactively 'org-mode)))
-      (when newfile-p
-	(goto-char (point-max))
-	(insert (format "\nArchived entries from file %s\n\n"
-			(buffer-file-name this-buffer))))
-      ;; Force the TODO keywords of the original buffer
-      (let ((org-todo-line-regexp tr-org-todo-line-regexp)
-	    (org-todo-keywords tr-org-todo-keywords)
-	    (org-todo-interpretation tr-org-todo-interpretation)
-	    (org-done-string tr-org-done-string)
-	    (org-todo-regexp tr-org-todo-regexp)
-	    (org-todo-line-regexp tr-org-todo-line-regexp))
-	(goto-char (point-min))
-	(if heading
-	    (progn
-	      (if (re-search-forward
-		   (concat "\\(^\\|\r\\)"
-			   (regexp-quote heading) "[ \t]*\\($\\|\r\\)")
-		   nil t)
-		  (goto-char (match-end 0))
-		;; Heading not found, just insert it at the end
-		(goto-char (point-max))
-		(or (bolp) (insert "\n"))
-		(insert "\n" heading "\n")
-		(end-of-line 0))
-	      ;; Make the subtree visible
-	      (show-subtree)
-	      (org-end-of-subtree t)
-	      (skip-chars-backward " \t\r\n]")
-	      (and (looking-at "[ \t\r\n]*")
-		   (replace-match "\n\n")))
-	  ;; No specific heading, just go to end of file.
-	  (goto-char (point-max)) (insert "\n"))
-	;; Paste
-	(org-paste-subtree (1+ level))
-	;; Mark the entry as done, i.e. set to last work in org-todo-keywords
-	(if org-archive-mark-done
-	    (org-todo (length org-todo-keywords)))
-	;; Move cursor to right after the TODO keyword
-	(when org-archive-stamp-time
-	  (beginning-of-line 1)
-	  (looking-at org-todo-line-regexp)
-	  (goto-char (or (match-end 2) (match-beginning 3)))
-	  (insert "(" (format-time-string (cdr org-time-stamp-formats)
-					  (org-current-time))
-		  ")"))
-	;; Save the buffer, if it is not the same buffer.
-	(if (not (eq this-buffer buffer)) (save-buffer))))
-    ;; Here we are back in the original buffer.  Everything seems to have
-    ;; worked.  So now cut the tree and finish up.
-    (let (this-command) (org-cut-subtree))
-    (if (and (not (eobp)) (looking-at "[ \t]*$")) (kill-line))
-    (message "Subtree archived %s"
-	     (if (eq this-buffer buffer)
-		 (concat "under heading: " heading)
-	       (concat "in file: " (abbreviate-file-name file))))))
+      (beginning-of-line)
+      (if (re-search-forward "[ \t]:\\([a-zA-Z0-9_@:]+\\):[ \t]*$"
+			     (point-at-eol) t)
+	  (progn
+	    (setq current (match-string 1))
+	    (replace-match ""))
+	(setq current ""))
+      (setq current (nreverse (org-split-string current ":")))
+      (cond
+       ((eq onoff 'on)
+	(setq res t)
+	(or (member tag current) (push tag current)))
+       ((eq onoff 'off)
+	(or (not (member tag current)) (setq current (delete tag current))))
+       (t (if (member tag current)
+	      (setq current (delete tag current))
+	    (setq res t)
+	    (push tag current))))
+      (end-of-line 1)
+      (when current
+	(insert " :" (mapconcat 'identity (nreverse current) ":") ":"))
+      (org-set-tags nil t))
+    res))
+
+(defun org-toggle-archive-tag (&optional arg)
+  "Toggle the archive tag for the current headline.
+With prefix ARG, check all children of current headline and offer tagging
+the children that do not contain any open TODO items."
+  (interactive "P")
+  (if arg
+      (org-archive-all-done 'tag)
+    (let (set)
+      (save-excursion
+	(org-back-to-heading t)
+	(setq set (org-toggle-tag org-archive-tag))
+	(when set (hide-subtree)))
+      (and set (beginning-of-line 1))
+      (message "Subtree %s" (if set "archived" "unarchived")))))
+
+(defun org-prepare-agenda-buffers (files)
+  "Create buffers for all agenda files, protect archived trees and comments."
+  (let ((pa '(:org-archived t))
+	(pc '(:org-comment t))
+	(pall '(:org-archived t :org-comment t))
+	(rea (concat ":" org-archive-tag ":"))
+	file re)
+    (save-excursion
+      (while (setq file (pop files))
+	(org-check-agenda-file file)
+	(set-buffer (org-get-agenda-file-buffer file))
+	(widen)
+	(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)
+	      (if (org-on-heading-p)
+		  (add-text-properties (point-at-bol) (org-end-of-subtree) pa))))
+	  (goto-char (point-min))
+	  (setq re (concat "^\\*+ +" org-comment-string "\\>"))
+	  (while (re-search-forward re nil t)
+	    (add-text-properties
+	     (match-beginning 0) (org-end-of-subtree) pc)))))))
+
+(defun org-agenda-skip ()
+  "Throw to `:skip' in places that should be skipped."
+  (let ((p (point-at-bol)))
+    (and org-agenda-skip-archived-trees
+	 (get-text-property p :org-archived)
+	 (org-end-of-subtree)
+	 (throw :skip t))
+    (and (get-text-property p :org-comment)
+	 (org-end-of-subtree)
+	 (throw :skip t))
+    (if (equal (char-after p) ?#) (throw :skip t))))
+  
+(defun org-agenda-toggle-archive-tag ()
+  "Toggle the archive tag for the current entry."
+  (interactive)
+  (org-agenda-check-no-diary)
+  (org-agenda-show)   ;;; FIXME This is a stupid hack and should not be needed
+  (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
+                       (org-agenda-error)))
+	 (buffer (marker-buffer hdmarker))
+	 (pos (marker-position hdmarker))
+	 (buffer-read-only nil)
+	 newhead)
+    (with-current-buffer buffer
+      (widen)
+      (goto-char pos)
+      (org-show-hidden-entry)
+      (save-excursion
+	(and (outline-next-heading)
+	     (org-flag-heading nil)))   ; show the next heading
+      (call-interactively 'org-toggle-archive-tag)
+      (end-of-line 1)
+      (setq newhead (org-get-heading)))
+    (org-agenda-change-all-lines newhead hdmarker)
+    (beginning-of-line 1)))
+
+;;; Dynamic blocks
+
+(defun org-find-dblock (name)
+  "Find the first dynamic block with name NAME in the buffer.
+If not found, stay at current position and return nil."
+  (let (pos)
+    (save-excursion
+      (goto-char (point-min))
+      (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
+					nil t)
+		     (match-beginning 0))))
+    (if pos (goto-char pos))
+    pos))
+
+(defconst org-dblock-start-re
+  "^#\\+BEGIN:[ \t]+\\(\\S-+\\)[ \t]+\\(.*\\)"
+  "Matches the startline of a dynamic block, with parameters.")
+
+(defconst org-dblock-end-re "^#\\+END\\([: \t\r\n]\\|$\\)"
+  "Matches the end of a dyhamic block.")
+
+(defun org-create-dblock (plist)
+  "Create a dynamic block section, with parameters taken from PLIST.
+PLIST must containe a :name entry which is used as name of the block."
+  (unless (bolp) (newline))
+  (let ((name (plist-get plist :name)))
+    (insert "#+BEGIN: " name)
+    (while plist
+      (if (eq (car plist) :name)
+	  (setq plist (cddr plist))
+	(insert " " (prin1-to-string (pop plist)))))
+    (insert "\n\n#+END:\n")
+    (beginning-of-line -2)))
+
+(defun org-prepare-dblock ()
+  "Prepare dynamic block for refresh.
+This empties the block, puts the cursor at the insert position and returns
+the property list including an extra property :name with the block name."
+  (unless (looking-at org-dblock-start-re)
+    (error "Not at a dynamic block"))
+  (let* ((begdel (1+ (match-end 0)))
+	 (name (match-string 1))
+	 (params (append (list :name name)
+			 (read (concat "(" (match-string 2) ")")))))
+    (unless (re-search-forward org-dblock-end-re nil t)
+      (error "Dynamic block not terminated"))
+    (delete-region begdel (match-beginning 0))
+    (goto-char begdel)
+    (open-line 1)
+    params))
+
+(defun org-map-dblocks (&optional command)
+  "Apply COMMAND to all dynamic blocks in the current buffer.
+If COMMAND is not given, use `org-update-dblock'."
+  (let ((cmd (or command 'org-update-dblock))
+	pos)
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward org-dblock-start-re nil t)
+	(goto-char (setq pos (match-beginning 0)))
+	(condition-case nil
+	    (funcall cmd)
+	  (error (message "Error during update of dynamic block")))
+	(goto-char pos)
+	(unless (re-search-forward org-dblock-end-re nil t)
+	  (error "Dynamic block not terminated"))))))
+
+(defun org-dblock-update (&optional arg)
+  "User command for updating dynamic blocks.
+Update the dynamic block at point.  With prefix ARG, update all dynamic
+blocks in the buffer."
+  (interactive "P")
+  (if arg
+      (org-update-all-dblocks)
+    (or (looking-at org-dblock-start-re)
+	(org-beginning-of-dblock))
+    (org-update-dblock)))
+
+(defun org-update-dblock ()
+  "Update the dynamic block at point
+This means to empty the block, parse for parameters and then call
+the correct writing function."
+  (let* ((pos (point))
+	 (params (org-prepare-dblock))
+	 (name (plist-get params :name))
+	 (cmd (intern (concat "org-dblock-write:" name))))
+    (funcall cmd params)
+    (goto-char pos)))
+
+(defun org-beginning-of-dblock ()
+  "Find the beginning of the dynamic block at point.
+Error if there is no scuh block at point."
+  (let ((pos (point))
+	beg)
+    (end-of-line 1)
+    (if (and (re-search-backward org-dblock-start-re nil t)
+	     (setq beg (match-beginning 0))
+	     (re-search-forward org-dblock-end-re nil t)
+	     (> (match-end 0) pos))
+	(goto-char beg)
+      (goto-char pos)
+      (error "Not in a dynamic block"))))
+
+(defun org-update-all-dblocks ()
+  "Update all dynamic blocks in the buffer.
+This function can be used in a hook."
+  (when (eq major-mode 'org-mode)
+    (org-map-dblocks 'org-update-dblock)))
+
 
 ;;; Completion
 
@@ -4662,9 +5094,8 @@
      (format-time-string (car org-time-stamp-formats) time))
     (setq what nil))
   (save-excursion
-    (let (beg end col list elt (buffer-invisibility-spec nil) ts)
+    (let (col list elt (buffer-invisibility-spec nil) ts)
       (org-back-to-heading t)
-      (setq beg (point))
       (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
       (goto-char (match-end 1))
       (setq col (current-column))
@@ -4734,6 +5165,8 @@
 	  (org-show-hierarchy-above))))
     (org-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)
     (if (interactive-p)
 	(message "%d match(es) for regexp %s" cnt regexp))
@@ -4777,22 +5210,25 @@
     (overlay-put ovl prop value)))
 
 (defvar org-occur-highlights nil)
+(make-variable-buffer-local 'org-occur-highlights)
 (defun org-highlight-new-match (beg end)
   "Highlight from BEG to END and mark the highlight is an occur headline."
   (let ((ov (org-make-overlay beg end)))
     (org-overlay-put ov 'face 'secondary-selection)
     (push ov org-occur-highlights)))
 
+(defvar org-inhibit-highlight-removal nil)
 (defun org-remove-occur-highlights (&optional beg end noremove)
   "Remove the occur highlights from the buffer.
 BEG and END are ignored.  If NOREMOVE is nil, remove this function
 from the `before-change-functions' in the current buffer."
   (interactive)
-  (mapc 'org-delete-overlay org-occur-highlights)
-  (setq org-occur-highlights nil)
-  (unless noremove
-    (remove-hook 'before-change-functions
-		 'org-remove-occur-highlights 'local)))
+  (unless org-inhibit-highlight-removal
+    (mapc 'org-delete-overlay org-occur-highlights)
+    (setq org-occur-highlights nil)
+    (unless noremove
+      (remove-hook 'before-change-functions
+		   'org-remove-occur-highlights 'local))))
 
 ;;; Priorities
 
@@ -5449,15 +5885,16 @@
   "Sum the times for each subtree.
 Puts the resulting times in minutes as a text property on each headline."
   (interactive)
-  (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t))
-  (let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
+  (let* ((bmp (buffer-modified-p))
+	 (re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
 		     org-clock-string
 		     ".*=>[ \t]*\\([0-9]+\\):\\([0-9]+\\)[ \t]*$"))
 	 (lmax 30)
 	 (ltimes (make-vector lmax 0))
 	 (t1 0)
 	 (level 0)
-	 (lastlevel 0) time)
+	 time)
+    (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t))
     (save-excursion
       (goto-char (point-max))
       (while (re-search-backward re nil t)
@@ -5475,7 +5912,8 @@
 		  (aset ltimes l 0))
 	    (goto-char (match-beginning 0))
 	    (put-text-property (point) (point-at-eol) :org-clock-minutes time))))
-      (setq org-clock-file-total-minutes (aref ltimes 0)))))
+      (setq org-clock-file-total-minutes (aref ltimes 0)))
+    (set-buffer-modified-p bmp)))
 
 (defun org-clock-display (&optional total-only)
   "Show subtree times in the entire buffer.
@@ -5500,6 +5938,8 @@
   (message "Total file time: %d:%02d (%d hours and %d minutes)" h m h m)))
 
 (defvar org-clock-overlays nil)
+(make-variable-buffer-local 'org-clock-overlays)
+
 (defun org-put-clock-overlay (time &optional level)
   "Put an overlays on the current line, displaying TIME.
 If LEVEL is given, prefix time with a corresponding number of stars.
@@ -5510,11 +5950,11 @@
 	 (off 0)
 	 ov tx)
     (move-to-column c)
-    (if (eolp) (setq off 1))
     (unless (eolp) (skip-chars-backward "^ \t"))
     (skip-chars-backward " \t")
-    (setq ov (org-make-overlay (- (point) off) (point-at-eol))
-	  tx (concat (make-string (+ off (max 0 (- c (current-column)))) ?.)
+    (setq ov (org-make-overlay (1- (point)) (point-at-eol))
+	  tx (concat (buffer-substring (1- (point)) (point))
+		     (make-string (+ off (max 0 (- c (current-column)))) ?.)
 		     (org-add-props (format "%s %2d:%02d%s"
 					    (make-string l ?*) h m
 					    (make-string (- 10 l) ?\ ))
@@ -5528,11 +5968,12 @@
 BEG and END are ignored.  If NOREMOVE is nil, remove this function
 from the `before-change-functions' in the current buffer."
   (interactive)
-  (mapc 'org-delete-overlay org-clock-overlays)
-  (setq org-clock-overlays nil)
-  (unless noremove
-    (remove-hook 'before-change-functions
-		 'org-remove-clock-overlays 'local)))
+  (unless org-inhibit-highlight-removal
+    (mapc 'org-delete-overlay org-clock-overlays)
+    (setq org-clock-overlays nil)
+    (unless noremove
+      (remove-hook 'before-change-functions
+		   'org-remove-clock-overlays 'local))))
 
 (defun org-clock-out-if-current ()
   "Clock out if the current entry contains the running clock.
@@ -5557,6 +5998,112 @@
     (when (y-or-n-p "Save changed buffer?")
       (save-buffer))))
 
+(defun org-clock-report ()
+  "Create a table containing a report about clocked time.
+If the buffer contains lines
+#+BEGIN: clocktable :maxlevel 3 :emphasize nil
+
+#+END: clocktable
+then the table will be inserted between these lines, replacing whatever
+is was there before.  If these lines are not in the buffer, the table
+is inserted at point, surrounded by the special lines.
+The BEGIN line can contain parameters.  Allowed are:
+:maxlevel   The maximum level to be included in the table.  Default is 3.
+:emphasize  t/nil, if levell 1 and level 2 should be bold/italic in the table."
+  (interactive)
+  (org-remove-clock-overlays)
+  (unless (org-find-dblock "clocktable")
+    (org-create-dblock  (list :name "clocktable"
+			      :maxlevel 2 :emphasize nil)))
+  (org-update-dblock))
+
+(defun org-dblock-write:clocktable (params)
+  "Write the standard clocktable."
+  (let ((hlchars '((1 . "*") (2 . ?/)))
+	(emph nil)
+	(ins (make-marker))
+	ipos time h m p level hlc hdl maxlevel)
+    (setq maxlevel (or (plist-get params :maxlevel) 3)
+	  emph (plist-get params :emphasize))
+    (move-marker ins (point))
+    (setq ipos (point))
+    (insert-before-markers "Clock summary at [" 
+			   (substring
+			    (format-time-string (cdr org-time-stamp-formats))
+			    1 -1)
+			   "]\n|L|Headline|Time|\n")
+    (org-clock-sum)
+    (setq h (/ org-clock-file-total-minutes 60)
+	  m (- org-clock-file-total-minutes (* 60 h)))
+    (insert-before-markers "|-\n|0|" "*Total file time*| "
+			   (format "*%d:%02d*" h m)
+			   "|\n")
+    (goto-char (point-min))
+    (while (setq p (next-single-property-change (point) :org-clock-minutes))
+      (goto-char p)
+      (when (setq time (get-text-property p :org-clock-minutes))
+	(beginning-of-line 1)
+	(when (and (looking-at "\\(\\*+\\)[ \t]+\\(.*?\\)\\([ \t]+:[0-9a-zA-Z_@:]+:\\)?[ \t]*$")
+		   (setq level (- (match-end 1) (match-beginning 1)))
+		   (<= level maxlevel))
+	  (setq hlc (if emph (or (cdr (assoc level hlchars)) "") "")
+		hdl (match-string 2)
+		h (/ time 60)
+		m (- time (* 60 h)))
+	  (save-excursion
+	    (goto-char ins)
+	    (if (= level 1) (insert-before-markers "|-\n"))
+	    (insert-before-markers
+	     "| " (int-to-string level) "|" hlc hdl hlc " |" 
+	     (make-string (1- level) ?|)
+	     hlc
+	     (format "%d:%02d" h m)
+	     hlc
+	     " |\n")))))
+    (goto-char ins)
+    (backward-delete-char 1)
+    (goto-char ipos)
+    (skip-chars-forward "^|")
+    (org-table-align)))
+
+(defun org-collect-clock-time-entries ()
+  "Return an internal list with clocking information.
+This list has one entry for each CLOCK interval.
+FIXME: describe the elements."
+  (interactive)
+  (let ((re (concat "^[ \t]*" org-clock-string
+		    " *\\[\\(.*?\\)\\]--\\[\\(.*?\\)\\]"))
+	rtn beg end next cont level title total closedp leafp
+	clockpos titlepos h m donep)
+    (save-excursion
+      (org-clock-sum)
+      (goto-char (point-min))
+      (while (re-search-forward re nil t)
+	(setq clockpos (match-beginning 0)
+	      beg (match-string 1) end (match-string 2)
+	      cont (match-end 0))
+	(setq beg (apply 'encode-time (org-parse-time-string beg))
+	      end (apply 'encode-time (org-parse-time-string end)))
+	(org-back-to-heading t)
+	(setq donep (org-entry-is-done-p))
+	(setq titlepos (point)
+	      total (or (get-text-property (1+ (point)) :org-clock-minutes) 0)
+	      h (/ total 60) m (- total (* 60 h))
+	      total (cons h m))
+	(looking-at "\\(\\*+\\) +\\(.*\\)")
+	(setq level (- (match-end 1) (match-beginning 1))
+	      title (org-match-string-no-properties 2))
+	(save-excursion (outline-next-heading) (setq next (point)))
+	(setq closedp (re-search-forward org-closed-time-regexp next t))
+	(goto-char next)
+	(setq leafp (and (looking-at "^\\*+ ")
+			 (<= (- (match-end 0) (point)) level)))
+	(push (list beg end clockpos closedp donep
+		    total title titlepos level leafp)
+	      rtn)
+	(goto-char cont)))
+    (nreverse rtn)))
+
 ;;; Agenda, and Diary Integration
 
 ;;; Define the mode
@@ -5616,6 +6163,7 @@
 (define-key org-agenda-mode-map "o"        'delete-other-windows)
 (define-key org-agenda-mode-map "L"        'org-agenda-recenter)
 (define-key org-agenda-mode-map "t"        'org-agenda-todo)
+(define-key org-agenda-mode-map "a"        'org-agenda-toggle-archive-tag)
 (define-key org-agenda-mode-map ":"        'org-agenda-set-tags)
 (define-key org-agenda-mode-map "."        'org-agenda-goto-today)
 (define-key org-agenda-mode-map "d"        'org-agenda-day-view)
@@ -5983,6 +6531,7 @@
 	 (past t)
 	 args
 	 s e rtn d emptyp)
+    (org-prepare-agenda-buffers org-agenda-files)
     (setq org-agenda-redo-command
 	  (list 'progn
 		(list 'switch-to-buffer-other-window (current-buffer))
@@ -6077,6 +6626,7 @@
 	 (day-numbers (list start))
 	 (inhibit-redisplay t)
 	 s e rtn rtnall file date d start-pos end-pos todayp nd)
+    (org-prepare-agenda-buffers files)
     (setq org-agenda-redo-command
 	  (list 'org-agenda-list (list 'quote include-all) start-day ndays t))
     ;; Make the list of days
@@ -6212,6 +6762,7 @@
 	 '(org-todo-list (or current-prefix-arg last-arg) t))
     (setq files (org-agenda-files)
 	  rtnall nil)
+    (org-prepare-agenda-buffers files)
     (while (setq file (pop files))
       (catch 'nextfile
 	(org-check-agenda-file file)
@@ -6820,8 +7371,11 @@
 	 ee txt)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (when (not (and org-agenda-todo-ignore-scheduled
-		      (save-match-data (looking-at sched-re))))
+      (catch :skip
+	(and org-agenda-todo-ignore-scheduled
+	     (looking-at sched-re)
+	     (throw :skip nil))
+	(org-agenda-skip)
 	(goto-char (match-beginning 1))
 	(setq marker (org-agenda-new-marker (1+ (match-beginning 0)))
 	      category (org-get-category)
@@ -6833,14 +7387,14 @@
 		     (- org-todo-kwd-max-priority -2
 			(length
 			 (member (match-string 2) org-todo-keywords)))
-		   1)))
+		     1)))
 	(org-add-props txt props
 	  'org-marker marker 'org-hd-marker marker
 	  'priority priority 'category category)
-	(push txt ee))
-      (if org-agenda-todo-list-sublevels
-	  (goto-char (match-end 1))
-	(org-end-of-subtree 'invisible)))
+	(push txt ee)
+	(if org-agenda-todo-list-sublevels
+	    (goto-char (match-end 1))
+	  (org-end-of-subtree 'invisible))))
     (nreverse ee)))
 
 (defconst org-agenda-no-heading-message
@@ -6866,50 +7420,51 @@
 	 ee txt timestr tags)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (if (not (save-match-data (org-at-date-range-p)))
-	  (progn
-	    (setq marker (org-agenda-new-marker (match-beginning 0))
-		  category (org-get-category (match-beginning 0))
-		  tmp (buffer-substring (max (point-min)
-					     (- (match-beginning 0)
-						org-ds-keyword-length))
-					(match-beginning 0))
-		  timestr (buffer-substring (match-beginning 0) (point-at-eol))
-		  deadlinep (string-match org-deadline-regexp tmp)
-		  scheduledp (string-match org-scheduled-regexp tmp)
-		  donep (org-entry-is-done-p))
-	    (if (string-match ">" timestr)
-		;; substring should only run to end of time stamp
-		(setq timestr (substring timestr 0 (match-end 0))))
-	    (save-excursion
-	      (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t)
-		  (progn
-		    (goto-char (match-end 1))
-		    (setq hdmarker (org-agenda-new-marker)
-			  tags (org-get-tags-at))
-		    (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
-		    (setq txt (org-format-agenda-item
-			       (format "%s%s"
-				       (if deadlinep  "Deadline:  " "")
-				       (if scheduledp "Scheduled: " ""))
-			       (match-string 1) category tags timestr)))
-		(setq txt org-agenda-no-heading-message))
-	      (setq priority (org-get-priority txt))
-	      (org-add-props txt props
-		'org-marker marker 'org-hd-marker hdmarker)
-	      (if deadlinep
-		  (org-add-props txt nil
-		    'face (if donep 'org-done 'org-warning)
-		    'undone-face 'org-warning 'done-face 'org-done
-		    'category category 'priority (+ 100 priority))
-		(if scheduledp
-		    (org-add-props txt nil
-		      'face 'org-scheduled-today
-		      'undone-face 'org-scheduled-today 'done-face 'org-done
-		      'category category 'priority (+ 99 priority))
-		  (org-add-props txt nil 'priority priority 'category category)))
-	      (push txt ee))
-	    (outline-next-heading))))
+      (catch :skip
+	(and (save-match-data (org-at-date-range-p)) (throw :skip nil))
+	(org-agenda-skip)
+	(setq marker (org-agenda-new-marker (match-beginning 0))
+	      category (org-get-category (match-beginning 0))
+	      tmp (buffer-substring (max (point-min)
+					 (- (match-beginning 0)
+					    org-ds-keyword-length))
+				    (match-beginning 0))
+	      timestr (buffer-substring (match-beginning 0) (point-at-eol))
+	      deadlinep (string-match org-deadline-regexp tmp)
+	      scheduledp (string-match org-scheduled-regexp tmp)
+	      donep (org-entry-is-done-p))
+	(if (string-match ">" timestr)
+	    ;; substring should only run to end of time stamp
+	    (setq timestr (substring timestr 0 (match-end 0))))
+	(save-excursion
+	  (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t)
+	      (progn
+		(goto-char (match-end 1))
+		(setq hdmarker (org-agenda-new-marker)
+		      tags (org-get-tags-at))
+		(looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
+		(setq txt (org-format-agenda-item
+			   (format "%s%s"
+				   (if deadlinep  "Deadline:  " "")
+				   (if scheduledp "Scheduled: " ""))
+			   (match-string 1) category tags timestr)))
+	    (setq txt org-agenda-no-heading-message))
+	  (setq priority (org-get-priority txt))
+	  (org-add-props txt props
+	    'org-marker marker 'org-hd-marker hdmarker)
+	  (if deadlinep
+	      (org-add-props txt nil
+		'face (if donep 'org-done 'org-warning)
+		'undone-face 'org-warning 'done-face 'org-done
+		'category category 'priority (+ 100 priority))
+	    (if scheduledp
+		(org-add-props txt nil
+		  'face 'org-scheduled-today
+		  'undone-face 'org-scheduled-today 'done-face 'org-done
+		  'category category 'priority (+ 99 priority))
+	      (org-add-props txt nil 'priority priority 'category category)))
+	  (push txt ee))
+	(outline-next-heading)))
     (nreverse ee)))
 
 (defun org-agenda-get-closed ()
@@ -6933,35 +7488,35 @@
 	 ee txt timestr)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (if (not (save-match-data (org-at-date-range-p)))
-	  (progn
-	    (setq marker (org-agenda-new-marker (match-beginning 0))
-		  closedp (equal (match-string 1) org-closed-string)
-		  category (org-get-category (match-beginning 0))
-		  timestr (buffer-substring (match-beginning 0) (point-at-eol))
-		  ;; donep (org-entry-is-done-p)
-		  )
-	    (if (string-match "\\]" timestr)
-		;; substring should only run to end of time stamp
-		(setq timestr (substring timestr 0 (match-end 0))))
-	    (save-excursion
-	      (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t)
-		  (progn
-		    (goto-char (match-end 1))
-		    (setq hdmarker (org-agenda-new-marker)
-			  tags (org-get-tags-at))
-		    (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
-		    (setq txt (org-format-agenda-item
-			       (if closedp "Closed:    " "Clocked:   ")
-			       (match-string 1) category tags timestr)))
-		(setq txt org-agenda-no-heading-message))
-	      (setq priority 100000)
-	      (org-add-props txt props
-		'org-marker marker 'org-hd-marker hdmarker 'face 'org-done
-		'priority priority 'category category
-		'undone-face 'org-warning 'done-face 'org-done)
-	      (push txt ee))
-	    (outline-next-heading))))
+      (catch :skip
+	(org-agenda-skip)
+	(setq marker (org-agenda-new-marker (match-beginning 0))
+	      closedp (equal (match-string 1) org-closed-string)
+	      category (org-get-category (match-beginning 0))
+	      timestr (buffer-substring (match-beginning 0) (point-at-eol))
+	      ;; donep (org-entry-is-done-p)
+	      )
+	(if (string-match "\\]" timestr)
+	    ;; substring should only run to end of time stamp
+	    (setq timestr (substring timestr 0 (match-end 0))))
+	(save-excursion
+	  (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t)
+	      (progn
+		(goto-char (match-end 1))
+		(setq hdmarker (org-agenda-new-marker)
+		      tags (org-get-tags-at))
+		(looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
+		(setq txt (org-format-agenda-item
+			   (if closedp "Closed:    " "Clocked:   ")
+			   (match-string 1) category tags timestr)))
+	    (setq txt org-agenda-no-heading-message))
+	  (setq priority 100000)
+	  (org-add-props txt props
+	    'org-marker marker 'org-hd-marker hdmarker 'face 'org-done
+	    'priority priority 'category category
+	    'undone-face 'org-warning 'done-face 'org-done)
+	  (push txt ee))
+	(outline-next-heading)))
     (nreverse ee)))
 
 (defun org-agenda-get-deadlines ()
@@ -6980,41 +7535,43 @@
 	 ee txt head face)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (setq pos (1- (match-beginning 1))
-	    d2 (time-to-days
-		(org-time-string-to-time (match-string 1)))
-	    diff (- d2 d1))
-      ;; When to show a deadline in the calendar:
-      ;; If the expiration is within wdays warning time.
-      ;; Past-due deadlines are only shown on the current date
-      (if (and (< diff wdays) todayp (not (= diff 0)))
-	  (save-excursion
-	    (setq category (org-get-category))
-	    (if (re-search-backward "\\(^\\|\r\\)\\*+[ \t]*" nil t)
-		(progn
-		  (goto-char (match-end 0))
-		  (setq pos1 (match-end 1))
-		  (setq tags (org-get-tags-at pos1))
-		  (setq head (buffer-substring-no-properties
-			      (point)
-			      (progn (skip-chars-forward "^\r\n")
-				     (point))))
-		  (if (string-match org-looking-at-done-regexp head)
-		      (setq txt nil)
-		    (setq txt (org-format-agenda-item
-			       (format "In %3d d.: " diff) head category tags))))
-	      (setq txt org-agenda-no-heading-message))
-	    (when txt
-	      (setq face (cond ((<= diff 0) 'org-warning)
-			       ((<= diff 5) 'org-upcoming-deadline)
-			       (t nil)))
-	      (org-add-props txt props
-		'org-marker (org-agenda-new-marker pos)
-		'org-hd-marker (org-agenda-new-marker pos1)
-		'priority (+ (- 10 diff) (org-get-priority txt))
-		'category category
-		'face face 'undone-face face 'done-face 'org-done)
-	      (push txt ee)))))
+      (catch :skip
+	(org-agenda-skip)
+	(setq pos (1- (match-beginning 1))
+	      d2 (time-to-days
+		  (org-time-string-to-time (match-string 1)))
+	      diff (- d2 d1))
+	;; When to show a deadline in the calendar:
+	;; If the expiration is within wdays warning time.
+	;; Past-due deadlines are only shown on the current date
+	(if (and (< diff wdays) todayp (not (= diff 0)))
+	    (save-excursion
+	      (setq category (org-get-category))
+	      (if (re-search-backward "\\(^\\|\r\\)\\*+[ \t]*" nil t)
+		  (progn
+		    (goto-char (match-end 0))
+		    (setq pos1 (match-end 1))
+		    (setq tags (org-get-tags-at pos1))
+		    (setq head (buffer-substring-no-properties
+				(point)
+				(progn (skip-chars-forward "^\r\n")
+				       (point))))
+		    (if (string-match org-looking-at-done-regexp head)
+			(setq txt nil)
+		      (setq txt (org-format-agenda-item
+				 (format "In %3d d.: " diff) head category tags))))
+		(setq txt org-agenda-no-heading-message))
+	      (when txt
+		(setq face (cond ((<= diff 0) 'org-warning)
+				 ((<= diff 5) 'org-upcoming-deadline)
+				 (t nil)))
+		(org-add-props txt props
+		  'org-marker (org-agenda-new-marker pos)
+		  'org-hd-marker (org-agenda-new-marker pos1)
+		  'priority (+ (- 10 diff) (org-get-priority txt))
+		  'category category
+		  'face face 'undone-face face 'done-face 'org-done)
+		(push txt ee))))))
     ee))
 
 (defun org-agenda-get-scheduled ()
@@ -7035,36 +7592,38 @@
 	 ee txt head)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (setq pos (1- (match-beginning 1))
-	    d2 (time-to-days
-		(org-time-string-to-time (match-string 1)))
-	    diff (- d2 d1))
-      ;; When to show a scheduled item in the calendar:
-      ;; If it is on or past the date.
-      (if (and (< diff 0) todayp)
-	  (save-excursion
-	    (setq category (org-get-category))
-	    (if (re-search-backward "\\(^\\|\r\\)\\*+[ \t]*" nil t)
-		(progn
-		  (goto-char (match-end 0))
-		  (setq pos1 (match-end 1))
-		  (setq tags (org-get-tags-at))
-		  (setq head (buffer-substring-no-properties
-			      (point)
-			      (progn (skip-chars-forward "^\r\n") (point))))
-		  (if (string-match org-looking-at-done-regexp head)
-		      (setq txt nil)
-		    (setq txt (org-format-agenda-item
-			       (format "Sched.%2dx: " (- 1 diff)) head
-			       category tags))))
-	      (setq txt org-agenda-no-heading-message))
-	    (when txt
-	      (org-add-props txt props
-		'org-marker (org-agenda-new-marker pos)
-		'org-hd-marker (org-agenda-new-marker pos1)
-		'priority (+ (- 5 diff) (org-get-priority txt))
-		'category category)
-	      (push txt ee)))))
+      (catch :skip
+	(org-agenda-skip)
+	(setq pos (1- (match-beginning 1))
+	      d2 (time-to-days
+		  (org-time-string-to-time (match-string 1)))
+	      diff (- d2 d1))
+	;; When to show a scheduled item in the calendar:
+	;; If it is on or past the date.
+	(if (and (< diff 0) todayp)
+	    (save-excursion
+	      (setq category (org-get-category))
+	      (if (re-search-backward "\\(^\\|\r\\)\\*+[ \t]*" nil t)
+		  (progn
+		    (goto-char (match-end 0))
+		    (setq pos1 (match-end 1))
+		    (setq tags (org-get-tags-at))
+		    (setq head (buffer-substring-no-properties
+				(point)
+				(progn (skip-chars-forward "^\r\n") (point))))
+		    (if (string-match org-looking-at-done-regexp head)
+			(setq txt nil)
+		      (setq txt (org-format-agenda-item
+				 (format "Sched.%2dx: " (- 1 diff)) head
+				 category tags))))
+		(setq txt org-agenda-no-heading-message))
+	      (when txt
+		(org-add-props txt props
+		  'org-marker (org-agenda-new-marker pos)
+		  'org-hd-marker (org-agenda-new-marker pos1)
+		  'priority (+ (- 5 diff) (org-get-priority txt))
+		  'category category)
+		(push txt ee))))))
     ee))
 
 (defun org-agenda-get-blocks ()
@@ -7081,34 +7640,36 @@
 	 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (setq timestr (match-string 0)
-	    s1 (match-string 1)
-	    s2 (match-string 2)
-	    d1 (time-to-days (org-time-string-to-time s1))
-	    d2 (time-to-days (org-time-string-to-time s2)))
-      (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 marker (org-agenda-new-marker (point)))
-	    (setq category (org-get-category))
-	    (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t)
-		(progn
-		  (setq hdmarker (org-agenda-new-marker (match-end 1)))
-		  (goto-char (match-end 1))
-		  (setq tags (org-get-tags-at))
-		  (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
-		  (setq txt (org-format-agenda-item
-			     (format (if (= d1 d2) "" "(%d/%d): ")
-				     (1+ (- d0 d1)) (1+ (- d2 d1)))
-			     (match-string 1) category tags
-			     (if (= d0 d1) timestr))))
-	      (setq txt org-agenda-no-heading-message))
-	    (org-add-props txt props
-	      'org-marker marker 'org-hd-marker hdmarker
-	      'priority (org-get-priority txt) 'category category)
-	    (push txt ee)))
-      (outline-next-heading))
+      (catch :skip
+	(org-agenda-skip)
+	(setq timestr (match-string 0)
+	      s1 (match-string 1)
+	      s2 (match-string 2)
+	      d1 (time-to-days (org-time-string-to-time s1))
+	      d2 (time-to-days (org-time-string-to-time s2)))
+	(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 marker (org-agenda-new-marker (point)))
+	      (setq category (org-get-category))
+	      (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t)
+		  (progn
+		    (setq hdmarker (org-agenda-new-marker (match-end 1)))
+		    (goto-char (match-end 1))
+		    (setq tags (org-get-tags-at))
+		    (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
+		    (setq txt (org-format-agenda-item
+			       (format (if (= d1 d2) "" "(%d/%d): ")
+				       (1+ (- d0 d1)) (1+ (- d2 d1)))
+			       (match-string 1) category tags
+			       (if (= d0 d1) timestr))))
+		(setq txt org-agenda-no-heading-message))
+	      (org-add-props txt props
+		'org-marker marker 'org-hd-marker hdmarker
+		'priority (org-get-priority txt) 'category category)
+	      (push txt ee)))
+	(outline-next-heading)))
     ;; Sort the entries by expiration date.
     (nreverse ee)))
 
@@ -7709,9 +8270,7 @@
   (org-agenda-check-no-diary)
   (let* ((marker (or (get-text-property (point) 'org-marker)
 		     (org-agenda-error)))
-	 (buffer (marker-buffer marker))
-	 (pos (marker-position marker))
-	 (hdmarker (get-text-property (point) 'org-hd-marker)))
+	 (pos (marker-position marker)))
     (with-current-buffer (marker-buffer marker)
       (widen)
       (goto-char pos)
@@ -7877,53 +8436,59 @@
          lspos
 	 tags tags-list tags-alist (llast 0) rtn level category i txt
 	 todo marker)
-
     (save-excursion
       (goto-char (point-min))
       (when (eq action 'sparse-tree) (org-overview))
       (while (re-search-forward re nil t)
-	(setq todo (if (match-end 1) (match-string 2))
-	      tags (if (match-end 4) (match-string 4)))
-	(goto-char (setq lspos (1+ (match-beginning 0))))
-	(setq level (funcall outline-level)
-	      category (org-get-category))
-	(setq i llast llast level)
-	;; remove tag lists from same and sublevels
-	(while (>= i level)
-	  (when (setq entry (assoc i tags-alist))
-	    (setq tags-alist (delete entry tags-alist)))
-	  (setq i (1- i)))
-	;; add the nex tags
-	(when tags
-	  (setq tags (mapcar 'downcase (org-split-string tags ":"))
-		tags-alist
-		(cons (cons level tags) tags-alist)))
-	;; compile tags for current headline
-	(setq tags-list
-	      (if org-use-tag-inheritance
-		  (apply 'append (mapcar 'cdr tags-alist))
-		tags))
-	(when (and (or (not todo-only) todo)
-		   (eval matcher))
-	  ;; list this headline
-	  (if (eq action 'sparse-tree)
-	      (progn
-		(org-show-hierarchy-above))
-	    (setq txt (org-format-agenda-item
-		       ""
-		       (concat
-			(if org-tags-match-list-sublevels
-			    (make-string (1- level) ?.) "")
-			(org-get-heading))
-		       category tags-list))
-            (goto-char lspos)
-	    (setq marker (org-agenda-new-marker))
-	    (org-add-props txt props
-	      'org-marker marker 'org-hd-marker marker 'category category)
-	    (push txt rtn))
-	  ;; if we are to skip sublevels, jump to end of subtree
-          (point)
-	  (or org-tags-match-list-sublevels (org-end-of-subtree)))))
+	(catch :skip
+	  (and (eq action 'agenda) (org-agenda-skip))
+	  (setq todo (if (match-end 1) (match-string 2))
+		tags (if (match-end 4) (match-string 4)))
+	  (goto-char (setq lspos (1+ (match-beginning 0))))
+	  (setq level (funcall outline-level)
+		category (org-get-category))
+	  (setq i llast llast level)
+	  ;; remove tag lists from same and sublevels
+	  (while (>= i level)
+	    (when (setq entry (assoc i tags-alist))
+	      (setq tags-alist (delete entry tags-alist)))
+	    (setq i (1- i)))
+	  ;; add the nex tags
+	  (when tags
+	    (setq tags (mapcar 'downcase (org-split-string tags ":"))
+		  tags-alist
+		  (cons (cons level tags) tags-alist)))
+	  ;; compile tags for current headline
+	  (setq tags-list
+		(if org-use-tag-inheritance
+		    (apply 'append (mapcar 'cdr tags-alist))
+		  tags))
+	  (when (and (or (not todo-only) todo)
+		     (eval matcher)
+		     (or (not org-agenda-skip-archived-trees)
+			 (not (member org-archive-tag tags-list))))
+	    ;; list this headline
+	    (if (eq action 'sparse-tree)
+		(progn
+		  (org-show-hierarchy-above))
+	      (setq txt (org-format-agenda-item
+			 ""
+			 (concat
+			  (if org-tags-match-list-sublevels
+			      (make-string (1- level) ?.) "")
+			  (org-get-heading))
+			 category tags-list))
+	      (goto-char lspos)
+	      (setq marker (org-agenda-new-marker))
+	      (org-add-props txt props
+		'org-marker marker 'org-hd-marker marker 'category category)
+	      (push txt rtn))
+	    ;; if we are to skip sublevels, jump to end of subtree
+	    (point)
+	    (or org-tags-match-list-sublevels (org-end-of-subtree))))))
+    (when (and (eq action 'sparse-tree)
+	       (not org-sparse-tree-open-archived-trees))
+      (org-hide-archived-subtrees (point-min) (point-max)))
     (nreverse rtn)))
 
 (defun org-tags-sparse-tree (&optional arg match)
@@ -7994,6 +8559,7 @@
 	       (list 'if 'current-prefix-arg nil match) t))
     (setq files (org-agenda-files)
 	  rtnall nil)
+    (org-prepare-agenda-buffers files)
     (while (setq file (pop files))
       (catch 'nextfile
 	(org-check-agenda-file file)
@@ -8084,7 +8650,11 @@
 	(setq hd (match-string 1))
 	(delete-region (match-beginning 0) (match-end 0))
 	(insert-before-markers (org-trim hd) (if empty "" " ")))
-      (unless (equal tags "")
+      (if (equal tags "")
+	  (save-excursion
+	    (beginning-of-line 1)
+	    (and (re-search-forward "[ \t]+$" (point-at-eol) t)
+		 (replace-match "")))
 	(move-to-column (max (current-column)
 			     (if (> org-tags-column 0)
 				 org-tags-column
@@ -8590,7 +9160,7 @@
 (defun org-search-not-link (&rest args)
   "Execute `re-search-forward', but only accept matches that are not a link."
   (catch 'exit
-    (let ((pos (point)) p1)
+    (let (p1)
       (while (apply 're-search-forward args)
 	(setq p1 (point))
 	(if (not (save-match-data
@@ -8990,24 +9560,23 @@
   (setq in-emacs (or in-emacs line search))
   (let* ((file (if (equal path "")
 		   buffer-file-name
-		 (convert-standard-filename (org-expand-file-name path))))
-	 (dirp (file-directory-p file))
+		 path))
+	 (apps (append org-file-apps (org-default-apps)))
+	 (remp (and (assq 'remote apps) (org-file-remote-p file)))
+	 (dirp (if remp nil (file-directory-p file)))
 	 (dfile (downcase file))
 	 (old-buffer (current-buffer))
 	 (old-pos (point))
 	 (old-mode major-mode)
-	 ext cmd apps)
-    (if (and (not (file-exists-p file))
-	     (not org-open-non-existing-files))
-	(error "No such file: %s" file))
+	 ext cmd)
     (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
 	(setq ext (match-string 1 dfile))
       (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
 	  (setq ext (match-string 1 dfile))))
-    (setq apps (append org-file-apps (org-default-apps)))
     (if in-emacs
 	(setq cmd 'emacs)
-      (setq cmd (or (and dirp (cdr (assoc 'directory apps)))
+      (setq cmd (or (and remp (cdr (assoc 'remote apps)))
+		    (and dirp (cdr (assoc 'directory apps)))
 		    (cdr (assoc ext apps))
 		    (cdr (assoc t apps)))))
     (when (eq cmd 'mailcap)
@@ -9018,6 +9587,10 @@
 	(if (stringp command)
 	    (setq cmd command)
 	  (setq cmd 'emacs))))
+    (if (and (not (eq cmd 'emacs)) ; Emacs has not problems with non-ex files
+	     (not (file-exists-p file))
+	     (not org-open-non-existing-files))
+	(error "No such file: %s" file))
     (cond
      ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
       ;; Normalize use of quote, this can vary.
@@ -9028,8 +9601,9 @@
 	(shell-command (concat cmd " &"))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))
-      (unless (equal (file-truename file) (file-truename (or buffer-file-name "")))
-	(funcall (cdr (assq 'file org-link-frame-setup)) file))
+;      (unless (equal (file-truename file) (file-truename (or buffer-file-name "")))
+;	(funcall (cdr (assq 'file org-link-frame-setup)) file))
+      (funcall (cdr (assq 'file org-link-frame-setup)) file)
       (if line (goto-line line)
 	(if search (org-link-search search))))
      ((consp cmd)
@@ -9053,6 +9627,20 @@
   "Replace special path abbreviations and expand the file name."
   (expand-file-name path))
 
+(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.
+
+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 ange-ftp-name-format file))
+         t)
+        (t nil)))
 
 (defvar org-insert-link-history nil
   "Minibuffer history for links inserted with `org-insert-link'.")
@@ -9186,8 +9774,8 @@
       (setq cpltxt (url-view-url t)
 	    link (org-make-link cpltxt)))
      ((eq major-mode 'w3m-mode)
-      (setq cpltxt w3m-current-url
-	    link (org-make-link cpltxt)))
+      (setq cpltxt (or w3m-current-title w3m-current-url)
+	    link (org-make-link w3m-current-url)))
 
      ((setq search (run-hook-with-args-until-success
 		    'org-create-file-search-functions))
@@ -9195,6 +9783,11 @@
 			 "::" search))
       (setq cpltxt (or description link)))
 
+     ((eq major-mode 'image-mode)
+      (setq cpltxt (concat "file:"
+			   (abbreviate-file-name buffer-file-name))
+	    link (org-make-link cpltxt)))      
+
      ((eq major-mode 'org-mode)
       ;; Just link to current headline
       (setq cpltxt (concat "file:"
@@ -9414,7 +10007,9 @@
 completed in the minibuffer (i.e. normally ~/path/to/file).
 
 With two \\[universal-argument] prefixes, enforce an absolute path even if the file
-is in the current directory or below."
+is in the current directory or below.
+With three \\[universal-argument] prefixes, negate the meaning of
+`org-keep-stored-link-after-insertion'."
   (interactive "P")
   (let (link desc entry remove file (pos (point)))
     (cond
@@ -9430,7 +10025,7 @@
       (setq link (read-string "Link: "
 			      (org-link-unescape
 			       (org-match-string-no-properties 1)))))
-     (complete-file
+     ((equal complete-file '(4))
       ;; Completing read for file names.
       (setq file (read-file-name "File: "))
       (let ((pwd (file-name-as-directory (expand-file-name ".")))
@@ -9455,7 +10050,8 @@
 		  org-insert-link-history
 		  (or (car (car org-stored-links)))))
       (setq entry (assoc link org-stored-links))
-      (if (not org-keep-stored-link-after-insertion)
+      (if (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)))
       (setq link (if entry (nth 1 entry) link)
@@ -9908,7 +10504,7 @@
 	 (linepos (+ (if (bolp) 1 0) (count-lines (point-min) (point))))
 	 (colpos (org-table-current-column))
 	 (winstart (window-start))
-	 text lines (new "") lengths l typenums ty fields maxfields i
+	 lines (new "") lengths l typenums ty fields maxfields i
 	 column
 	 (indent "") cnt frac
 	 rfmt hfmt
@@ -9919,7 +10515,7 @@
 		 (make-string sp2 ?\ ) "%%%s%ds" (make-string sp1 ?\ ) "|"))
 	 (hfmt1 (concat
 		 (make-string sp2 ?-) "%s" (make-string sp1 ?-) "+"))
-	 emptystrings xx links narrow fmax fmin f1 len c e)
+	 emptystrings links narrow fmax f1 len c e)
     (untabify beg end)
     (remove-text-properties beg end '(org-cwidth t display t))
     ;; Check if we have links
@@ -12055,9 +12651,11 @@
     (:headline-levels      . org-export-headline-levels)
     (:section-numbers      . org-export-with-section-numbers)
     (:table-of-contents    . org-export-with-toc)
+    (:archived-trees       . org-export-with-archived-trees)
     (:emphasize            . org-export-with-emphasize)
     (:sub-superscript      . org-export-with-sub-superscripts)
     (:TeX-macros           . org-export-with-TeX-macros)
+    (:LaTeX-fragments      . org-export-with-LaTeX-fragments)
     (:fixed-width          . org-export-with-fixed-width)
     (:timestamps           . org-export-with-timestamps)
     (:tables               . org-export-with-tables)
@@ -12088,7 +12686,6 @@
     (goto-char 0)
     (let ((re (org-make-options-regexp
 	       '("TITLE" "AUTHOR" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE")))
-	  (text nil)
 	  p key val text options)
       (while (re-search-forward re nil t)
 	(setq key (org-match-string-no-properties 1)
@@ -12112,7 +12709,8 @@
 		    ("|"     . :tables)
 		    ("^"     . :sub-superscript)
 		    ("*"     . :emphasize)
-		    ("TeX"   . :TeX-macros)))
+		    ("TeX"   . :TeX-macros)
+		    ("LaTeX" . :LaTeX-fragments)))
 	      o)
 	  (while (setq o (pop op))
 	    (if (string-match (concat (regexp-quote (car o))
@@ -12199,7 +12797,8 @@
 \[X] publish... (project will be prompted for)
 \[A] publish all projects")
 	(cmds
-	 '((?v . org-export-visible)
+	 '((?t . org-insert-export-options-template)
+	   (?v . org-export-visible)
 	   (?a . org-export-as-ascii)
 	   (?h . org-export-as-html)
 	   (?b . org-export-as-html-and-open)
@@ -12526,32 +13125,56 @@
 (defun org-cleaned-string-for-export (string &rest parameters)
   "Cleanup a buffer substring so that links can be created safely."
   (interactive)
-  (let* ((cb (current-buffer))
-	 (re-radio (and org-target-link-regexp
+  (let* ((re-radio (and org-target-link-regexp
 			(concat "\\([^<]\\)\\(" org-target-link-regexp "\\)")))
 	 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
 	 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re))
+	 (re-archive (concat ":" org-archive-tag ":"))
 	 rtn)
     (save-excursion
       (set-buffer (get-buffer-create " org-mode-tmp"))
       (erase-buffer)
       (insert string)
-      (org-mode)
+      (let ((org-inhibit-startup t)) (org-mode))
+
+      ;; Get rid of archived trees
+      (when (not (eq org-export-with-archived-trees t))
+	(goto-char (point-min))
+	(while (re-search-forward re-archive nil t)
+	  (if (not (org-on-heading-p))
+	      (org-end-of-subtree t)
+	    (beginning-of-line 1)
+	    (delete-region
+	     (if org-export-with-archived-trees (1+ (point-at-eol)) (point))
+	     (org-end-of-subtree)))))
+
       ;; Find targets in comments and move them out of comments,
       ;; but mark them as targets that should be invisible
       (goto-char (point-min))
       (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t)
 	(replace-match "\\1(INVISIBLE)"))
+
       ;; Find matches for radio targets and turn them into internal links
       (goto-char (point-min))
       (when re-radio
 	(while (re-search-forward re-radio nil t)
 	  (replace-match "\\1[[\\2]]")))
+
       ;; Find all links that contain a newline and put them into a single line
       (goto-char (point-min))
       (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
 	(replace-match "\\1 \\3")
 	(goto-char (match-beginning 0)))
+
+      ;; Convert LaTeX fragments to images
+      (when (memq :LaTeX-fragments parameters)
+	(org-format-latex 
+	 (concat "ltxpng/" (file-name-sans-extension
+			    (file-name-nondirectory
+			     org-current-export-file)))
+	 org-current-export-dir nil "Creating LaTeX image %s"))
+      (message "Expriting...")
+
       ;; Normalize links: Convert angle and plain links into bracket links
       (goto-char (point-min))
       (while (re-search-forward re-plain-link nil t)
@@ -12565,8 +13188,9 @@
 	 (concat
 	  (match-string 1) "[[" (match-string 2) ":" (match-string 3) "]]")
 	 t t))
+
       ;; Find multiline emphasis and put them into single line
-      (when (assq :emph-multiline parameters)
+      (when (memq :emph-multiline parameters)
 	(goto-char (point-min))
 	(while (re-search-forward org-emph-re nil t)
 	  (subst-char-in-region (match-beginning 0) (match-end 0) ?\n ?\  t)
@@ -12671,7 +13295,6 @@
 	 (title       (or (plist-get opt-plist :title)
 			  (file-name-sans-extension
 			   (file-name-nondirectory buffer-file-name))))
-	 (options     nil)
 	 (email       (plist-get opt-plist :email))
 	 (language    (plist-get opt-plist :language))
 	 (text        nil)
@@ -12772,7 +13395,7 @@
     (normal-mode)
     (save-buffer)
     ;; remove display and invisible chars
-    (let (beg end s)
+    (let (beg end)
       (goto-char (point-min))
       (while (setq beg (next-single-property-change (point) 'display))
 	(setq end (next-single-property-change beg 'display))
@@ -12849,22 +13472,27 @@
 (defun org-export-visible (type arg)
   "Create a copy of the visible part of the current buffer, and export it.
 The copy is created in a temporary buffer and removed after use.
-TYPE is the final key (as a string) of the `C-c C-x' key sequence that will
-run the export command - in interactive use, the command prompts for this
-key.  As a special case, if the you type SPC at the prompt, the temporary
+TYPE is the final key (as a string) that also select the export command in
+the `C-c C-e' export dispatcher.
+As a special case, if the you type SPC at the prompt, the temporary
 org-mode file will not be removed but presented to you so that you can
 continue to use it.  The prefix arg ARG is passed through to the exporting
 command."
   (interactive
    (list (progn
 	   (message "Export visible: [a]SCII  [h]tml  [b]rowse HTML  [x]OXO  [ ]keep buffer")
-	   (char-to-string (read-char-exclusive)))
+	   (read-char-exclusive))
 	 current-prefix-arg))
-  (if (not (member type '("a" "\C-a" "b" "\C-b" "h" "x" " ")))
+  (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?x ?\ )))
       (error "Invalid export key"))
-  ;; FIXME: do this more explicit?
-  (let* ((binding (key-binding (concat "\C-c\C-x" type)))
-	 (keepp (equal type " "))
+  (let* ((binding (cdr (assoc type
+			      '((?a . org-export-as-ascii)
+				(?\C-a . org-export-as-ascii)
+				(?b . org-export-as-html-and-open)
+				(?\C-b . org-export-as-html-and-open)
+				(?h . org-export-as-html)
+				(?x . org-export-as-xoxo)))))
+	 (keepp (equal type ?\ ))
 	 (file buffer-file-name)
 	 (buffer (get-buffer-create "*Org Export Visible*"))
 	 s e)
@@ -12925,7 +13553,7 @@
 #+EMAIL:     %s
 #+LANGUAGE:  %s
 #+TEXT:      Some descriptive text to be emitted.  Several lines OK.
-#+OPTIONS:   H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s *:%s TeX:%s
+#+OPTIONS:   H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s *:%s TeX:%s LaTeX:%s
 #+CATEGORY:  %s
 #+SEQ_TODO:  %s
 #+TYP_TODO:  %s
@@ -12944,6 +13572,7 @@
    org-export-with-sub-superscripts
    org-export-with-emphasize
    org-export-with-TeX-macros
+   org-export-with-LaTeX-fragments
    (file-name-nondirectory buffer-file-name)
    (if (equal org-todo-interpretation 'sequence)
        (mapconcat 'identity org-todo-keywords " ")
@@ -13041,6 +13670,7 @@
 EXT-PLIST is a property list with external parameters overriding
 org-mode's default settings, but still inferior to file-local settings."
   (interactive "P")
+  (message "Exporting...")
   (setq-default org-todo-line-regexp org-todo-line-regexp)
   (setq-default org-deadline-line-regexp org-deadline-line-regexp)
   (setq-default org-done-string org-done-string)
@@ -13049,16 +13679,24 @@
 					(org-infile-export-plist)))
 
 	 (style (plist-get opt-plist :style))
+	 (link-validate (plist-get opt-plist :link-validation-function))
+	 valid
 	 (odd org-odd-levels-only)
 	 (region-p (org-region-active-p))
          (region
           (buffer-substring
            (if region-p (region-beginning) (point-min))
            (if region-p (region-end) (point-max))))
+	 ;; The following two are dynamically scoped into other
+	 ;; routines below.
+	 (org-current-export-dir (org-export-directory :html opt-plist))
+	 (org-current-export-file buffer-file-name)
          (all_lines
           (org-skip-comments (org-split-string
 			      (org-cleaned-string-for-export
-			       region :emph-multiline)
+			       region :emph-multiline 
+			       (if (plist-get opt-plist :LaTeX-fragments)
+				   :LaTeX-fragments))
 			      "[\r\n]")))
          (lines (org-export-find-first-heading-line all_lines))
          (level 0) (line "") (origline "") txt todo
@@ -13068,6 +13706,7 @@
 			   (file-name-sans-extension
 			    (file-name-nondirectory buffer-file-name))
 			   ".html"))
+	 (current-dir (file-name-directory buffer-file-name))
          (buffer (find-file-noselect filename))
          (levels-open (make-vector org-level-max nil))
 	 (date (format-time-string "%Y/%m/%d" (current-time)))
@@ -13314,6 +13953,10 @@
 		  (if (string-match "::\\(.*\\)" filename)
 		      (setq search (match-string 1 filename)
 			    filename (replace-match "" t nil filename)))
+		  (setq valid
+			(if (functionp link-validate)
+			    (funcall link-validate filename current-dir)
+			  t))		    
 		  (setq file-is-image-p
 			(string-match (org-image-file-name-regexp) filename))
 		  (setq thefile (if abs-p (expand-file-name filename) filename))
@@ -13339,7 +13982,8 @@
 				       (and org-export-html-inline-images
 					    (not descp))))
 			      (concat "<img src=\"" thefile "\"/>")
-			    (concat "<a href=\"" thefile "\">" desc "</a>")))))
+			    (concat "<a href=\"" thefile "\">" desc "</a>")))
+		(if (not valid) (setq rpl desc))))
 	     ((member type '("bbdb" "vm" "wl" "mhe" "rmail" "gnus" "shell" "info" "elisp"))
 	      (setq rpl (concat "<i>&lt;" type ":"
 				(save-match-data (org-link-unescape path))
@@ -13497,7 +14141,9 @@
       (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
 	(replace-match ""))
       (save-buffer)
-      (goto-char (point-min)))))
+      (goto-char (point-min))
+      (message "Exporting... done"))))
+
 
 (defun org-format-table-html (lines olines)
   "Find out which HTML converter to use and return the HTML code."
@@ -13650,27 +14296,31 @@
 
 (defun org-html-handle-time-stamps (s)
   "Format time stamps in string S, or remove them."
-  (let (r b)
-    (while (string-match org-maybe-keyword-time-regexp s)
-      (or b (setq b (substring s 0 (match-beginning 0))))
-      (if (not org-export-with-timestamps)
-	  (setq r (concat r (substring s 0 (match-beginning 0)))
-		s (substring s (match-end 0)))
-	(setq r (concat
-		 r (substring s 0 (match-beginning 0))
-		 (if (match-end 1)
-		     (format "@<span class=\"timestamp-kwd\">%s @</span>"
-			     (match-string 1 s)))
-		 (format " @<span class=\"timestamp\">%s@</span>"
-			 (substring (match-string 3 s) 1 -1)))
-	      s (substring s (match-end 0)))))
-    ;; Line break of line started and ended with time stamp stuff
-    (if (not r)
-	s
-      (setq r (concat r s))
-      (unless (string-match "\\S-" (concat b s))
-	(setq r (concat r "@<br/>")))
-      r)))
+  (catch 'exit
+    (let (r b)
+      (while (string-match org-maybe-keyword-time-regexp s)
+	;; FIXME: is it good to never export CLOCK, or do we need control?
+	(if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
+	    (throw 'exit ""))
+	(or b (setq b (substring s 0 (match-beginning 0))))
+	(if (not org-export-with-timestamps)
+	    (setq r (concat r (substring s 0 (match-beginning 0)))
+		  s (substring s (match-end 0)))
+	  (setq r (concat
+		   r (substring s 0 (match-beginning 0))
+		   (if (match-end 1)
+		       (format "@<span class=\"timestamp-kwd\">%s @</span>"
+			       (match-string 1 s)))
+		   (format " @<span class=\"timestamp\">%s@</span>"
+			   (substring (match-string 3 s) 1 -1)))
+		s (substring s (match-end 0)))))
+      ;; Line break if line started and ended with time stamp stuff
+      (if (not r)
+	  s
+	(setq r (concat r s))
+	(unless (string-match "\\S-" (concat b s))
+	  (setq r (concat r "@<br/>")))
+	r))))
 
 (defun org-html-protect (s)
   ;; convert & to &amp;, < to &lt; and > to &gt;
@@ -14147,6 +14797,255 @@
     (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
     (concat keyword (format-time-string fmt time))))
 
+;;; LaTeX stuff
+
+(defvar org-cdlatex-mode-map (make-sparse-keymap)
+  "Keymap for the minor `org-cdlatex-mode'.")
+
+(define-key org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
+(define-key org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
+(define-key org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
+(define-key org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
+(define-key org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
+
+(defvar org-cdlatex-texmathp-advice-is-done nil
+  "Flag remembering if we have applied the advice to texmathp already.")
+
+(define-minor-mode org-cdlatex-mode 
+  "Toggle the minor `org-cdlatex-mode'.
+This mode supports entering LaTeX environment and math in LaTeX fragments
+in Org-mode.
+\\{org-cdlatex-mode-map}"
+  nil " CDLtx" nil
+  (when org-cdlatex-mode (require 'cdlatex))
+  (unless org-cdlatex-texmathp-advice-is-done
+    (setq org-cdlatex-texmathp-advice-is-done t)
+    (defadvice texmathp (around org-math-always-on activate)
+      "Always return t in org-mode buffers.
+This is because we want to insert math symbols without dollars even outside
+the LaTeX math segments.
+\\[org-cdlatex-mode-map]"
+      (interactive)
+      (if (or (not (eq major-mode 'org-mode))
+	      (org-inside-LaTeX-fragment-p))
+	  ad-do-it
+	(if (eq this-command 'cdlatex-math-symbol)
+	    (setq ad-return-value t))))))
+
+(defun org-inside-LaTeX-fragment-p ()
+  "Test if point is inside a LaTeX fragment. I.e. after a \\begin, \\(, \\[, $, or $$, withoout the corresponding closing
+sequence appearing also before point."
+  (let ((pos (point))
+	(lim (progn
+	       (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
+	       (point)))
+	dollar-on p1)
+    (goto-char pos)
+    (if (re-search-backward "\\(\\\\begin{\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\)" lim t)
+	(progn
+	  (goto-char pos)
+	  (cond
+	   ((match-beginning 1) (match-beginning 0))
+	   ((match-beginning 2) nil)
+	   (t (while (re-search-backward "\\$" lim t)
+		(setq dollar-on (not dollar-on))
+		(if (= (char-before) ?$) (backward-char 1))
+		(setq p1 (or p1 (point))))
+	      (goto-char pos)
+	      (if dollar-on p1))))
+      (goto-char pos)
+      nil)))
+
+(defun org-try-cdlatex-tab ()
+  "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
+It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
+  - inside a LaTeX fragment, or
+  - after the first word in a line, where an abbreviation expansion could
+    insert a LaTeX environment."
+  ;; FIXME:  This may still need refinement.
+  (when org-cdlatex-mode
+    (cond
+     ((save-excursion
+	(skip-chars-backward "a-zA-Z0-9*")
+	(skip-chars-backward " \t")
+	(bolp))
+      (cdlatex-tab) t)
+     ((org-inside-LaTeX-fragment-p)
+      (cdlatex-tab) t)
+     (t nil))))
+
+(defun org-cdlatex-underscore-caret (&optional arg)
+  "Execute `cdlatex-sub-superscript' in LaTeX fragments.
+Revert to the normal definition outside of these fragments."
+  (interactive "P")
+  (if (org-inside-LaTeX-fragment-p)
+      (call-interactively 'cdlatex-sub-superscript)
+    (let (org-cdlatex-mode)
+      (call-interactively (key-binding (vector last-input-event))))))
+
+(defun org-cdlatex-math-modify (&optional arg)
+  "Execute `cdlatex-math-modify' in LaTeX fragments.
+Revert to the normal definition outside of these fragments."
+  (interactive "P")
+  (if (org-inside-LaTeX-fragment-p)
+      (call-interactively 'cdlatex-math-modify)
+    (let (org-cdlatex-mode)
+      (call-interactively (key-binding (vector last-input-event))))))
+
+(defvar org-latex-fragment-image-overlays nil
+  "List of overlays carrying the images of latex fragments.")
+(make-variable-buffer-local 'org-latex-fragment-image-overlays)
+
+(defun org-remove-latex-fragment-image-overlays ()
+  "Remove all overlays with LaTeX fragment images in current buffer."
+  (mapc 'org-delete-overlay org-latex-fragment-image-overlays)
+  (setq org-latex-fragment-image-overlays nil))
+
+(defun org-preview-latex-fragment (&optional subtree)
+  "Preview the LaTeX fragment at point, or all locally or globally.
+If the cursor is in a LaTeX fragment, create the image and overlay
+it over the source code.  If there is no fragment at point, display
+all fragments in the current text, from one headline to the next.  With
+prefix SUBTREE, display all fragments in the current subtree.  With a 
+double prefix `C-u C-u', or when the cursor is before the first headline,
+display all fragments in the buffer.
+The images can be removed again with \\[org-ctrl-c-ctrl-c]."
+  (interactive "P")
+  (org-remove-latex-fragment-image-overlays)
+  (save-excursion
+    (save-restriction
+      (let (beg end at msg)
+	(cond
+	 ((or (equal subtree '(16))
+	      (not (save-excursion
+		     (re-search-backward (concat "^" outline-regexp) nil t))))
+	  (setq beg (point-min) end (point-max)
+		msg "Creating images for buffer...%s"))
+	 ((equal subtree '(4))
+	  (org-back-to-heading)
+	  (setq beg (point) end (org-end-of-subtree)
+		msg "Creating images for subtree...%s"))
+	 (t
+	  (if (setq at (org-inside-LaTeX-fragment-p))
+	      (goto-char (max (point-min) (- at 2)))
+	    (org-back-to-heading))
+	  (setq beg (point) end (progn (outline-next-heading) (point))
+		msg (if at "Creating image...%s"
+		      "Creating images for entry...%s"))))
+	(message msg "")
+	(narrow-to-region beg end)
+	(org-format-latex
+	 (concat "ltxpng/" (file-name-sans-extension
+			    (file-name-nondirectory
+			     buffer-file-name)))
+	 default-directory 'overlays msg at)
+      (message msg "done.  Use `C-c C-c' to remove images.")))))
+
+(defun org-format-latex (prefix &optional dir overlays msg at)
+  "Replace LaTeX fragments with links to an image, and produce images."
+  (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
+  (let* ((prefixnodir (file-name-nondirectory prefix))
+	 (absprefix (expand-file-name prefix dir))
+	 (todir (file-name-directory absprefix))
+	 (opt org-format-latex-options)
+	 (matchers (plist-get opt :matchers))
+	 (re-list
+	  '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
+	    ("$" "\\([ 	(]\\|^\\)\\(\\(\\([$]\\)\\([^ 	\r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ 	\r\n,.$]\\)\\4\\)\\)\\([ 	.,?;:'\")]\\|$\\)" 2 nil)
+	    ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
+	    ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 t)
+	    ("$$" "\\$\\$[^\000]*?\\$\\$" 0 t)))
+	 (cnt 0) txt link beg end re e oldfiles
+	 m n block linkfile movefile ov)
+    ;; Make sure the directory exists
+    (or (file-directory-p todir) (make-directory todir))
+    ;; Check if there are old images files with this prefix, and remove them
+    (setq oldfiles (directory-files
+		    todir 'full
+		    (concat (regexp-quote prefixnodir) "_[0-9]+\\.png$")))
+    (while oldfiles (delete-file (pop oldfiles)))
+    ;; Check the different regular expressions
+    (while (setq e (pop re-list))
+      (setq m (car e) re (nth 1 e) n (nth 2 e)
+	    block (if (nth 3 e) "\n\n" ""))
+      (when (member m matchers)
+	(goto-char (point-min))
+	(while (re-search-forward re nil t)
+	  (when (or (not at) (equal at (match-beginning n)))
+	    (setq txt (match-string n)
+		  beg (match-beginning n) end (match-end n)
+		  cnt (1+ cnt)
+		  linkfile (format "%s_%04d.png" prefix cnt)
+		  movefile (format "%s_%04d.png" absprefix cnt)
+		  link (concat block "[[file:" linkfile "]]" block))
+	    (if msg (message msg cnt))
+	    (goto-char beg)
+	    (org-create-formula-image
+	     txt movefile opt)
+	    (if overlays
+		(progn
+		  (setq ov (org-make-overlay beg end))
+		  (if (featurep 'xemacs)
+		      (progn
+			(org-overlay-put ov 'invisible t)
+			(org-overlay-put
+			 ov 'end-glyph 
+			 (make-glyph (vector 'png :file movefile))))
+		    (org-overlay-put 
+		     ov 'display 
+		     (list 'image :type 'png :file movefile :ascent 'center)))
+		  (push ov org-latex-fragment-image-overlays)
+		  (goto-char end))
+	      (delete-region beg end)
+	      (insert link))))))))
+    
+;; This function borrows from Ganesh Swami's latex2png.el
+(defun org-create-formula-image (string tofile options)
+  (let* ((tmpdir (if (featurep 'xemacs)
+		     (temp-directory)
+		   temporary-file-directory))
+	 (texfilebase (make-temp-name
+		       (expand-file-name "orgtex" tmpdir)))
+
+;(texfilebase (make-temp-file "orgtex"))
+;	 (dummy (delete-file texfilebase))
+	 (texfile (concat texfilebase ".tex"))
+	 (dvifile (concat texfilebase ".dvi"))
+	 (pngfile (concat texfilebase ".png"))
+	 (scale (number-to-string (* 1000 (or (plist-get options :scale) 1.0))))
+	 (fg (or (plist-get options :foreground) "Black"))
+	 (bg (or (plist-get options :background) "Transparent")))
+    (with-temp-file texfile
+      (insert "\\documentclass{article}
+\\usepackage{fullpage}
+\\usepackage{amssymb}
+\\usepackage[usenames]{color}
+\\usepackage{amsmath}
+\\usepackage{latexsym}
+\\usepackage[mathscr]{eucal}
+\\pagestyle{empty}
+\\begin{document}\n" string "\n\\end{document}\n"))
+    (let ((dir default-directory))
+      (condition-case nil
+	  (progn
+	    (cd tmpdir)
+	    (call-process "latex" nil nil nil texfile))
+	(error nil))
+      (cd dir))
+    (if (not (file-exists-p dvifile))
+	(progn (message "Failed to create dvi file from %s" texfile) nil)
+      (call-process "dvipng" nil nil nil
+		    "-E" "-fg" fg "-bg" bg
+		    "-x" scale "-y" scale "-T" "tight"
+		    "-o" pngfile
+		    dvifile)
+      (if (not (file-exists-p pngfile))
+	  (progn (message "Failed to create png file from %s" texfile) nil)
+	;; Use the requested file name and clean up
+	(copy-file pngfile tofile 'replace)
+	(loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
+	      (delete-file (concat texfilebase e)))
+	pngfile))))
 
 ;;; Key bindings
 
@@ -14212,7 +15111,9 @@
 ;; All the other keys
 
 (define-key org-mode-map "\C-c\C-a" 'show-all)  ; in case allout messed up.
+(define-key org-mode-map "\C-xns" 'org-narrow-to-subtree)
 (define-key org-mode-map "\C-c$"    'org-archive-subtree)
+(define-key org-mode-map "\C-c\C-x\C-a" 'org-toggle-archive-tag)
 (define-key org-mode-map "\C-c\C-j" 'org-goto)
 (define-key org-mode-map "\C-c\C-t" 'org-todo)
 (define-key org-mode-map "\C-c\C-s" 'org-schedule)
@@ -14255,24 +15156,7 @@
 (define-key org-mode-map "\C-c~"          'org-table-create-with-table.el)
 (define-key org-mode-map "\C-c\C-q"       'org-table-wrap-region)
 (define-key org-mode-map "\C-c\C-e"       'org-export)
-;(define-key org-mode-map "\C-c\C-xa"      'org-export-as-ascii)
-;(define-key org-mode-map "\C-c\C-x\C-a"   'org-export-as-ascii)
-;(define-key org-mode-map "\C-c\C-xv"      'org-export-visible)
-;(define-key org-mode-map "\C-c\C-x\C-v"   'org-export-visible)
-;; OPML support is only an option for the future
-;(define-key org-mode-map "\C-c\C-xo"      'org-export-as-opml)
-;(define-key org-mode-map "\C-c\C-x\C-o"   'org-export-as-opml)
-;(define-key org-mode-map "\C-c\C-xi"      'org-export-icalendar-this-file)
-;(define-key org-mode-map "\C-c\C-x\C-i"   'org-export-icalendar-all-agenda-files)
-;(define-key org-mode-map "\C-c\C-xc"      'org-export-icalendar-combine-agenda-files)
-;(define-key org-mode-map "\C-c\C-x\C-c"   'org-export-icalendar-combine-agenda-files)
-;(define-key org-mode-map "\C-c\C-xt"      'org-insert-export-options-template)
 (define-key org-mode-map "\C-c:"          'org-toggle-fixed-width-section)
-;(define-key org-mode-map "\C-c\C-xh"      'org-export-as-html)
-;(define-key org-mode-map "\C-c\C-xx"      'org-export-as-xoxo)
-;(define-key org-mode-map "\C-c\C-x\C-x"   'org-export-as-xoxo)
-;(define-key org-mode-map "\C-c\C-xb"      'org-export-as-html-and-open)
-;(define-key org-mode-map "\C-c\C-x\C-b"   'org-export-as-html-and-open)
 
 (define-key org-mode-map "\C-c\C-x\C-k"   'org-cut-special)
 (define-key org-mode-map "\C-c\C-x\C-w"   'org-cut-special)
@@ -14283,15 +15167,9 @@
 (define-key org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
 (define-key org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
 (define-key org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
-
-;(define-key org-mode-map "\C-c\C-ef"    'org-publish-current-file)
-;(define-key org-mode-map "\C-c\C-ep"    'org-publish-current-project)
-;(define-key org-mode-map "\C-c\C-ec"    'org-publish)
-;(define-key org-mode-map "\C-c\C-ea"    'org-publish-all)
-;(define-key org-mode-map "\C-c\C-e\C-f" 'org-publish-current-file)
-;(define-key org-mode-map "\C-c\C-e\C-p" 'org-publish-current-project)
-;(define-key org-mode-map "\C-c\C-e\C-c" 'org-publish)
-;(define-key org-mode-map "\C-c\C-e\C-a" 'org-publish-all)
+(define-key org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
+(define-key org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
+(define-key org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
 
 (when (featurep 'xemacs)
   (define-key org-mode-map 'button3   'popup-mode-menu))
@@ -14598,12 +15476,12 @@
   (interactive "P")
   (let  ((org-enable-table-editor t))
     (cond
-     (org-clock-overlays 
+     ((or org-clock-overlays org-occur-highlights
+	  org-latex-fragment-image-overlays)
       (org-remove-clock-overlays)
-      (message "Clock overlays removed"))
-     (org-occur-highlights
       (org-remove-occur-highlights)
-      (message "occur highlights removed"))
+      (org-remove-latex-fragment-image-overlays)
+      (message "Temporary highlights/overlays removed from current buffer"))
      ((and (local-variable-p 'org-finish-function (current-buffer))
 	   (fboundp org-finish-function))
       (funcall org-finish-function))
@@ -14753,10 +15631,26 @@
      ["Demote Heading"  org-metaright (not (org-at-table-p))]
      ["Demote Subtree"  org-shiftmetaright (not (org-at-table-p))]
      "--"
-     ["Archive Subtree" org-archive-subtree t]
-     "--"
      ["Convert to odd levels" org-convert-to-odd-levels t]
      ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
+    ("Archive"
+     ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
+     ["Check and Tag Children" (org-toggle-archive-tag (4))
+      :active t :keys "C-u C-c C-x C-a"]
+     ["Sparse trees open ARCHIVE trees"
+      (setq org-sparse-tree-open-archived-trees
+	    (not org-sparse-tree-open-archived-trees))
+      :style toggle :selected org-sparse-tree-open-archived-trees]
+     ["Cycling opens ARCHIVE trees"
+      (setq org-cycle-open-archived-trees (not org-cycle-open-archived-trees))
+      :style toggle :selected org-cycle-open-archived-trees]
+     ["Agenda includes ARCHIVE trees"
+      (setq org-agenda-skip-archived-trees (not org-agenda-skip-archived-trees))
+      :style toggle :selected (not org-agenda-skip-archived-trees)]
+     "--"
+     ["Move Subtree to Archive" org-archive-subtree t]
+     ["Check and Move Children" (org-archive-subtree '(4)) 
+      :active t :keys "C-u C-c $"])
     "--"
     ("TODO Lists"
      ["TODO/DONE/-" org-todo t]
@@ -14785,6 +15679,7 @@
      ["Clock out" org-clock-out t]
      ["Clock cancel" org-clock-cancel t]
      ["Display times" org-clock-display t]
+     ["Create clock table" org-clock-report t]
      "--"
      ["Record DONE time"
       (progn (setq org-log-done (not org-log-done))
@@ -14819,6 +15714,16 @@
 		      (re-search-forward "<[a-z]+:" nil t))])
     "--"
     ["Export/Publish" org-export t]
+    ("LaTeX"
+     ["Org CDLaTeX mode" org-cdlatex-mode :style toggle 
+      :selected org-cdlatex-mode]
+     ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
+     ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
+     ["Modify math symbol" org-cdlatex-math-modify
+      (org-inside-LaTeX-fragment-p)]
+     ["Export LaTeX fragments as images"
+      (setq org-export-with-LaTeX-fragments (not org-export-with-LaTeX-fragments)) 
+      :style toggle :selected org-export-with-LaTeX-fragments])
     "--"
     ("Documentation"
      ["Show Version" org-version t]
@@ -15012,6 +15917,7 @@
   ;; In the paragraph separator we include headlines, because filling
   ;; text in a line directly attached to a headline would otherwise
   ;; fill the headline as well.
+  (set (make-local-variable 'comment-start-skip) "^#+[ \t]*")
   (set (make-local-variable 'paragraph-separate) "\f\\|\\*\\|[ 	]*$\\|[ \t]*[:|]")
   ;; The paragraph starter includes hand-formatted lists.
   (set (make-local-variable 'paragraph-start)
@@ -15284,7 +16190,8 @@
 	  (forward-char -1)
 	  (if (memq (preceding-char) '(?\n ?\^M))
 	      ;; leave blank line before heading
-	      (forward-char -1))))))
+	      (forward-char -1)))))
+  (point))
 
 (defun org-show-subtree ()
   "Show everything after this heading at deeper levels."
@@ -15334,8 +16241,10 @@
 			   (org-invisible-p)))
        (org-show-hierarchy-above)))
 
+;;; Experimental code
+
 ;;; Finish up
-
+	
 (provide 'org)
 
 (run-hooks 'org-load-hook)
--- a/lisp/textmodes/tex-mode.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/textmodes/tex-mode.el	Tue Jun 27 15:06:36 2006 +0000
@@ -597,7 +597,7 @@
 (defun tex-font-lock-match-suscript (limit)
   "Match subscript and superscript patterns up to LIMIT."
   (when (re-search-forward "[_^] *\\([^\n\\{}]\\|\
-\\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|{[^\\{]*}\\|\\({\\)\\)" limit t)
+\\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|\\({\\)\\)" limit t)
     (when (match-end 3)
       (let ((beg (match-beginning 3))
 	    (end (save-restriction
--- a/lisp/vc.el	Mon Jun 12 07:27:12 2006 +0000
+++ b/lisp/vc.el	Tue Jun 27 15:06:36 2006 +0000
@@ -567,6 +567,13 @@
   :group 'vc
   :version "21.1")
 
+(defcustom vc-diff-knows-L nil
+  "*Indicates whether diff understands the -L option.
+The value is either `yes', `no', or nil.  If it is nil, VC tries
+to use -L and sets this variable to remember whether it worked."
+  :type '(choice (const :tag "Work out" nil) (const yes) (const no))
+  :group 'vc)
+
 (defcustom vc-allow-async-revert nil
   "Specifies whether the diff during \\[vc-revert-buffer] may be asynchronous.
 Enabling this option means that you can confirm a revert operation even
@@ -1837,18 +1844,36 @@
                      (vc-version-backup-file file rev2)))
         (coding-system-for-read (vc-coding-system-for-diff file)))
     (if (and file-rev1 file-rev2)
-        (apply 'vc-do-command "*vc-diff*" 1 "diff" nil
-	       (append (vc-switches nil 'diff)
-		       ;; Provide explicit labels like RCS or CVS would do
-		       ;; so diff-mode refers to `file' rather than to
-		       ;; `file-rev1' when trying to find/apply/undo hunks.
-		       (list "-L" (vc-diff-label file file-rev1 rev1)
-			     "-L" (vc-diff-label file file-rev2 rev2)
-			     (file-relative-name file-rev1)
-			     (file-relative-name file-rev2))))
+        (let ((status
+               (if (eq vc-diff-knows-L 'no)
+                   (apply 'vc-do-command "*vc-diff*" 1 "diff"
+                          (append (vc-switches nil 'diff)
+                                  (list (file-relative-name file-rev1)
+                                        (file-relative-name file-rev2))))
+                 (apply 'vc-do-command "*vc-diff*" 2 "diff" nil
+                        (append (vc-switches nil 'diff)
+                                ;; Provide explicit labels like RCS or
+                                ;; CVS would do so diff-mode refers to
+                                ;; `file' rather than to `file-rev1'
+                                ;; when trying to find/apply/undo
+                                ;; hunks.
+                                (list "-L" (vc-diff-label file file-rev1 rev1)
+                                      "-L" (vc-diff-label file file-rev2 rev2)
+                                      (file-relative-name file-rev1)
+                                      (file-relative-name file-rev2)))))))
+          (if (eq status 2)
+              (if (not vc-diff-knows-L)
+                  (setq vc-diff-knows-L 'no
+                        status (apply 'vc-do-command "*vc-diff*" 1 "diff"
+                                      (append 
+                                       (vc-switches nil 'diff)
+                                       (list (file-relative-name file-rev1)
+                                             (file-relative-name file-rev2)))))
+                (error "diff failed"))
+            (if (not vc-diff-knows-L) (setq vc-diff-knows-L 'yes)))
+          status)
       (vc-call diff file rev1 rev2))))
 
-
 (defun vc-switches (backend op)
   (let ((switches
 	 (or (if backend
--- a/lispref/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,50 @@
+2006-06-24  Eli Zaretskii  <eliz@gnu.org>
+
+	* files.texi (Contents of Directories): Document case-insensitive
+	behavior on respective filesystems.
+
+	* objects.texi (Character Type): Document that Emacs signals an
+	error for unsupported Unicode characters specified as \uNNNN.
+
+2006-06-19  Richard Stallman  <rms@gnu.org>
+
+	* processes.texi (Bindat Spec): Clarify previous change.
+
+2006-06-16  Richard Stallman  <rms@gnu.org>
+
+	* tips.texi (Coding Conventions): Better explain conventions
+	for definition constructs.
+
+	* text.texi (Special Properties): String value of `read-only'
+	serves as the error message.
+
+	* objects.texi (Character Type): Clarify prev. change.
+	(Non-ASCII in Strings): Mention \u and \U.
+
+	* commands.texi (Using Interactive): Explain problem of
+	markers, etc., in command-history.
+
+2006-06-14  Kim F. Storm  <storm@cua.dk>
+
+	* commands.texi (Waiting): Negative arg to sit-for forces
+	redisplay even if input is pending.
+
+	* display.texi (Forcing Redisplay): Use (sit-for -1) to force a
+	redisplay.  Remove incorrect example of binding redisplay-dont-pause
+	around (sit-for 0).
+
+2006-06-13  Richard Stallman  <rms@gnu.org>
+
+	* display.texi (Forcing Redisplay): Clarify previous change.
+
+2006-06-13  Romain Francoise  <romain@orebokech.com>
+
+	* display.texi (Forcing Redisplay): Fix typo.
+
+2006-06-13  Kim F. Storm  <storm@cua.dk>
+
+	* display.texi (Forcing Redisplay): Add redisplay-preemption-period.
+
 2006-06-10  Luc Teirlinck  <teirllm@auburn.edu>
 
 	* tips.texi (Coding Conventions): Add `@end itemize'.
--- a/lispref/commands.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/commands.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -233,6 +233,20 @@
  (let ((string (read-string "Foo: " nil 'my-history)))
    (list (region-beginning) (region-end) string)))
 @end smallexample
+
+@strong{Warning:} the argument values should not include any data
+types that can't be printed and then read.  Some facilities save
+@code{command-history} in a file to be read in the subsequent
+sessions; if a command's arguments contain a data type that prints
+using @samp{#<@dots{}>} syntax, those facilities won't work.
+
+There are, however, a few exceptions: it is ok to use a limited set of
+expressions such as @code{(point)}, @code{(mark)},
+@code{(region-beginning)}, and @code{(region-end)}, because Emacs
+recognizes them specially and puts the expression (rather than its
+value) into the command history.  To see whether the expression you
+wrote is one of these exceptions, run the command, then examine
+@code{(car command-history)}.
 @end itemize
 
 @cindex examining the @code{interactive} form
@@ -2532,8 +2546,11 @@
 Some systems support only a whole number of seconds; on these systems,
 @var{seconds} is rounded down.
 
+If @var{seconds} is negative, force a redisplay even if there is
+pending input.  So use @code{(sit-for -1)} to force a redisplay.
+
 The expression @code{(sit-for 0)} is a convenient way to request a
-redisplay, without any delay.  @xref{Forcing Redisplay}.
+redisplay, without any delay, if there is no pending input.  @xref{Forcing Redisplay}.
 
 If @var{nodisp} is non-@code{nil}, then @code{sit-for} does not
 redisplay, but it still returns as soon as input is available (or when
--- a/lispref/display.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/display.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -94,6 +94,20 @@
 is exactly what you want.  However, you can prevent preemption by
 binding @code{redisplay-dont-pause} to a non-@code{nil} value.
 
+@tindex redisplay-preemption-period
+@defvar redisplay-preemption-period
+This variable specifies how many seconds Emacs waits between checks
+for new input during redisplay.  (The default is 0.1 seconds.)  If
+input has arrived when Emacs checks, it pre-empts redisplay and
+processes the available input before trying again to redisplay.
+
+If this variable is @code{nil}, Emacs does not check for input during
+redisplay, and redisplay cannot be preempted by input.
+
+@emph{Note} that this variable is only available if Emacs is built
+with support for sub-second timers.
+@end defvar
+
 @tindex redisplay-dont-pause
 @defvar redisplay-dont-pause
 If this variable is non-@code{nil}, pending input does not
@@ -101,14 +115,10 @@
 regardless of whether input is available.
 @end defvar
 
+@tindex sit-for
   You can request a display update, but only if no input is pending,
 with @code{(sit-for 0)}.  To force a display update even when input is
-pending, do this:
-
-@example
-(let ((redisplay-dont-pause t))
-  (sit-for 0))
-@end example
+pending, use @code{(sit-for -1)}.
 
 @node Truncation
 @section Truncation
--- a/lispref/files.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/files.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -2364,7 +2364,8 @@
 
 If @var{match-regexp} is non-@code{nil}, this function returns only
 those file names that contain a match for that regular expression---the
-other file names are excluded from the list.
+other file names are excluded from the list.  On case-insensitive
+filesystems, the regular expression matching is case-insensitive.
 
 @c Emacs 19 feature
 If @var{nosort} is non-@code{nil}, @code{directory-files} does not sort
--- a/lispref/objects.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/objects.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -438,11 +438,12 @@
 different syntax for specifying characters with code points above
 @code{#xFFFF}; @code{\U00@var{nnnnnn}} represents the character whose
 Unicode code point is @samp{U+@var{nnnnnn}}, if such a character
-is supported by Emacs.
+is supported by Emacs.  If the corresponding character is not
+supported, Emacs signals an error.
 
-  Unlike in some other programming languages, in Emacs Lisp this
-syntax is available for character literals, and (see later) in
-strings, but not elsewhere.
+  This peculiar and inconvenient syntax was adopted for compatibility
+with other programming languages.  Unlike some other languages, Emacs
+Lisp supports this syntax in only character literals and strings.
 
 @cindex @samp{\} in character constant
 @cindex backslash in character constant
@@ -1013,6 +1014,9 @@
 string (even for an @acronym{ASCII} character) forces the string to be
 multibyte.
 
+  You can also specify characters in a string by their numeric values
+in Unicode, using @samp{\u} and @samp{\U} (@pxref{Character Type}).
+
   @xref{Text Representations}, for more information about the two
 text representations.
 
--- a/lispref/processes.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/processes.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -2230,13 +2230,12 @@
 @var{tag} matches unconditionally if it is @code{t}.
 @end itemize
 
-@item repeat @var{count} @var{field-spec}@dots{}
-Process the set of @var{field-spec}s recursively, in order, and loop
-starting from the first one, for @var{count} times overall (looping
-@code{@var{count} @minus{} 1} times).
-@var{count} may be an integer, or a list of one element naming a
-previous field.  For correct operation, each @var{field-spec} must
-include a name.
+@item repeat @var{count} @var{field-specs}@dots{}
+Process the @var{field-specs} recursively, in order, then repeat
+starting from the first one, processing all the specs @var{count}
+times overall.  @var{count} may be an integer, or a list of one
+element that names a previous field.  For correct operation, each spec
+in @var{field-specs} must include a name.
 @end table
 
 @node Bindat Functions
--- a/lispref/text.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/text.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -3098,7 +3098,8 @@
 @kindex read-only @r{(text property)}
 If a character has the property @code{read-only}, then modifying that
 character is not allowed.  Any command that would do so gets an error,
-@code{text-read-only}.
+@code{text-read-only}.  If the property value is a string, that string
+is used as the error message.
 
 Insertion next to a read-only character is an error if inserting
 ordinary text there would inherit the @code{read-only} property due to
--- a/lispref/tips.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/lispref/tips.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -204,11 +204,14 @@
 replacements differs from that of the originals.
 
 @item
-Avoid using macros that define functions and variables with names that
-are constructed.  It is best for maintenance when the name of the
-function or variable being defined is given explicitly in the source
-code, as the second element of the list---as it is when you use
-@code{defun}, @code{defalias}, @code{defvar} and @code{defcustom}.
+Constructs that define a function or variable should be macros,
+not functions, and their names should start with @samp{def}.
+
+@item
+Macros that define a functions or variables should take the name to be
+defined as the first argument.  That will help various tools find the
+definition automatically.  Avoid constructing the names in the macro
+itself, since that would confuse these tools.
 
 @item
 Please keep the names of your Emacs Lisp source files to 13 characters
--- a/man/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,63 @@
+2006-06-25  Nick Roberts  <nickrob@snap.net.nz>
+
+	* frames.texi (XTerm Mouse) Rename to...
+	(Text-Only Mouse): ...this.  Mention t-mouse-mode.
+
+	* emacs.texi (Top): Use new node name.
+
+2006-06-24  Eli Zaretskii  <eliz@gnu.org>
+
+	* emacs.texi (Top): Update the detailed menu according to changes in
+	msdog.texi.
+
+	* msdog.texi (Windows Keyboard): New section.
+	(Windows Mouse): New section.
+	(Windows System Menu): Remove section (text merged with "Windows
+	Keyboard").
+	(Windows Misc): New section.
+
+	* dired.texi (Dired Enter): Refer to msdog.texi for ls-lisp emulation.
+
+	* msdog.texi (ls in Lisp): New section.
+
+	* files.texi (Visiting): Document case-insensitive wildcard matching
+	under find-file-wildcards.
+
+2006-06-23  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.texi (Embedded LaTeX): New chapter.
+	(Archiving): Section rewritten.
+	(Enhancing text): Some parts moved to the new chapter about
+	LaTeX.
+
+2006-06-20  Bill Wohler  <wohler@newt.com>
+
+	Release MH-E manual version 8.0.1.
+
+	* mh-e.texi (VERSION, EDITION, UPDATED, UPDATE-MONTH): Update for
+	release 8.0.1.
+	(Preface): Depend on GNU mailutils 1.0 and higher.
+
+2006-06-19  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* message.texi (News Headers): Update message-syntax-checks section.
+
+2006-06-19  Karl Berry  <karl@gnu.org>
+
+	* info.texi (Advanced): mention C-q, especially with ?.
+
+2006-06-19  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.texi (Publishing links): Document the `:link-validation-function'
+	property.
+	(Extensions and Hacking): New chapter, includes some sections of the
+	"Miscellaneous" chapter.
+
+2006-06-16  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* macos.texi (Mac Input): Add description of mac-function-modifier.
+	Now Unicode keyboard layouts work.
+
 2006-06-10  Carsten Dominik  <dominik@science.uva.nl>
 
 	* org.texi: (Progress logging): New section.
@@ -6,6 +66,11 @@
 
 	* mule.texi (Recognize Coding): Clarify previous change.
 
+2006-06-09  Kenichi Handa  <handa@m17n.org>
+
+	* mule.texi (Recognize Coding): Describe the convention of "CODING!"
+	notation.
+
 2006-06-07  Kevin Ryde  <user42@zip.com.au>
 
 	* mule.texi (Coding Systems): Footnote xref "MS-DOS and MULE" in main
--- a/man/dired.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/dired.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -70,6 +70,10 @@
 options (starting with @samp{--}) whose arguments are specified with
 @samp{=}.
 
+  On MS-Windows and MS-DOS systems, Emacs @emph{emulates} @code{ls};
+see @ref{ls in Lisp}, for options and peculiarities of that emulation.
+
+
 @findex dired-other-window
 @kindex C-x 4 d
 @findex dired-other-frame
--- a/man/ediff.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/ediff.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -1614,6 +1614,9 @@
 ignoring letter case or not. It can be set in @file{.emacs} using
 @code{setq-default}.
 
+When case sensitivity is toggled, all difference
+regions are recomputed.
+
 @node Highlighting Difference Regions, Narrowing, Selective Browsing, Customization
 @section Highlighting Difference Regions
 
@@ -2316,6 +2319,14 @@
 
 Using @code{ediff-cleanup-hook}, one can make Ediff delete the variants
 unconditionally (e.g., by making @code{ediff-janitor} into one of these hooks).
+
+@item ediff-keep-tmp-versions
+@vindex @code{ediff-keep-tmp-versions}
+Default is @code{nil}. If @code{t}, the versions of the files being
+compared or merged using operations such as @code{ediff-revision} or
+@code{ediff-merge-revisions} are not deleted on exit. The normal action is
+to clean up and delete these version files.
+
 @item ediff-grab-mouse
 @vindex @code{ediff-grab-mouse}
 Default is @code{t}.  Normally, Ediff grabs mouse and puts it in its
@@ -2457,6 +2468,7 @@
 (jaffe@@chipmunk.cita.utoronto.ca),
 David Karr (dkarr@@nmo.gtegsc.com),
 Norbert Kiesel (norbert@@i3.informatik.rwth-aachen.de),
+Steffen Kilb (skilb@@gmx.net),
 Leigh L Klotz (klotz@@adoc.xerox.com),
 Fritz Knabe (Fritz.Knabe@@ecrc.de),
 Heinz Knutzen (hk@@informatik.uni-kiel.d400.de),
--- a/man/emacs.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/emacs.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -457,7 +457,7 @@
 * Tooltips::            Showing "tooltips", AKA "balloon help" for active text.
 * Mouse Avoidance::     Moving the mouse pointer out of the way.
 * Non-Window Terminals::  Multiple frames on terminals that show only one.
-* XTerm Mouse::         Using the mouse in an XTerm terminal emulator.
+* Text-Only Mouse::     Using the mouse in text-only terminals.
 
 International Character Set Support
 
@@ -879,9 +879,15 @@
 
 Emacs and Microsoft Windows
 
-* Text and Binary::     Text files on MS-DOS use CRLF to separate lines.
+* Text and Binary::     Text files use CRLF to terminate lines.
+* Windows Files::       File-name conventions on Windows.
+* ls in Lisp::          Emulation of @code{ls} for Dired.
+* Windows HOME::        Where Emacs looks for your @file{.emacs}.
+* Windows Keyboard::    Windows-specific keyboard features.
+* Windows Mouse::       Windows-specific mouse features.
 * Windows Processes::   Running subprocesses on Windows.
-* Windows System Menu:: Controlling what the ALT key does.
+* Windows Printing::    How to specify the printer on MS-Windows.
+* Windows Misc::        Miscellaneous Windows features.
 @end menu
 
 @iftex
--- a/man/faq.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/faq.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -3659,7 +3659,7 @@
 
 For information on Emacs for Windows 95 and NT, read the FAQ produced by
 @email{voelker@@cs.washington.edu, Geoff Voelker} and currently maintained
-by @email{ramprasad_i82@@yahoo.com, Ramprasad B}, available at
+by @email{ramprasad@@gnu.org, Ramprasad B}, available at
 
 @uref{http://www.gnu.org/software/emacs/windows/ntemacs.html}
 
--- a/man/files.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/files.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -289,13 +289,14 @@
 @cindex wildcard characters in file names
 @vindex find-file-wildcards
   If the file name you specify contains shell-style wildcard
-characters, Emacs visits all the files that match it.  Wildcards
-include @samp{?}, @samp{*}, and @samp{[@dots{}]} sequences.  To enter
-the wild card @samp{?} in a file name in the minibuffer, you need to
-type @kbd{C-q ?}.  @xref{Quoted File Names}, for information on how to
-visit a file whose name actually contains wildcard characters.  You
-can disable the wildcard feature by customizing
-@code{find-file-wildcards}.
+characters, Emacs visits all the files that match it.  (On
+case-insensitive filesystems, Emacs matches the wildcards disregarding
+the letter case.)  Wildcards include @samp{?}, @samp{*}, and
+@samp{[@dots{}]} sequences.  To enter the wild card @samp{?} in a file
+name in the minibuffer, you need to type @kbd{C-q ?}.  @xref{Quoted
+File Names}, for information on how to visit a file whose name
+actually contains wildcard characters.  You can disable the wildcard
+feature by customizing @code{find-file-wildcards}.
 
   If you visit a file that the operating system won't let you modify,
 or that is marked read-only, Emacs makes the buffer read-only too, so
--- a/man/frames.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/frames.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -57,7 +57,7 @@
 * Tooltips::            Displaying information at the current mouse position.
 * Mouse Avoidance::     Moving the mouse pointer out of the way.
 * Non-Window Terminals::  Multiple frames on terminals that show only one.
-* XTerm Mouse::         Using the mouse in an XTerm terminal emulator.
+* Text-Only Mouse::     Using the mouse in text-only terminals.
 @end menu
 
 @node Mouse Commands
@@ -1035,21 +1035,26 @@
 to select a frame according to its name.  The name you specify appears
 in the mode line when the frame is selected.
 
-@node XTerm Mouse
+@node Text-Only Mouse
 @section Using a Mouse in Terminal Emulators
-@cindex xterm, mouse support
+@cindex mouse support
 @cindex terminal emulators, mouse support
 
-  Some terminal emulators under X support mouse clicks in the terminal
-window.  In a terminal emulator which is compatible with @code{xterm},
+Some terminal emulators support mouse clicks in the terminal window.
+
+@cindex xterm
+In a terminal emulator which is compatible with @code{xterm},
 you can use @kbd{M-x xterm-mouse-mode} to give Emacs control over
 simple use of the mouse---basically, only non-modified single clicks
 are supported.  The normal @code{xterm} mouse functionality for such
 clicks is still available by holding down the @kbd{SHIFT} key when you
-press the mouse button.
+press the mouse button.  Xterm Mouse mode is a global minor mode
+(@pxref{Minor Modes}).  Repeating the command turns the mode off
+again.
 
-  Xterm Mouse mode is a global minor mode (@pxref{Minor Modes}).
-Repeating the command turns the mode off again.
+In the console on GNU/Linux, you can use @kbd{M-x t-mouse-mode}.  You
+need to have the gpm package installed and running on your system in
+order for this to work.
 
 @ignore
    arch-tag: 7dcf3a31-a43b-45d4-a900-445b10d77e49
--- a/man/info.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/info.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -918,6 +918,15 @@
 specific to it, which are documented in several chapters of @ref{Top,,
 GNU Info, info-stnd, GNU Info}.)
 
+@kindex C-q @r{(Info mode)}
+  One advanced command useful with most of the others described here
+is @kbd{C-q}, which ``quotes'' the next character so that it is
+entered literally (@pxref{Inserting Text,,,emacs,The GNU Emacs
+Manual}).  For example, pressing @kbd{?} ordinarily brings up a list
+of completion possibilities.  If you want to (for example) search for
+an actual @samp{?} character, the simplest way is to insert it using
+@kbd{C-q ?}.  This works the same in Emacs and stand-alone Info.
+
 @menu
 * Search Text::          How to search Info documents.
 * Search Index::         How to search the indices for specific subjects.
--- a/man/macos.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/macos.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -45,16 +45,17 @@
 @vindex mac-control-modifier
 @vindex mac-command-modifier
 @vindex mac-option-modifier
-  On Mac, Emacs can use @key{control}, @key{command}, and @key{option}
-keys as any of Emacs modifier keys except @key{SHIFT} (i.e.,
-@key{ALT}, @key{CTRL}, @key{HYPER}, @key{META}, and @key{SUPER}).  The
-assignment is controlled by the variables @code{mac-control-modifier},
-@code{mac-command-modifier}, and @code{mac-option-modifier}.  The
-value for each of these variables can be one of the following symbols:
-@code{alt}, @code{control}, @code{hyper}, @code{meta}, @code{super},
-and @code{nil} (no particular assignment).  By default, the
-@key{control} key works as @key{CTRL}, and the @key{command} key as
-@key{META}.
+@vindex mac-function-modifier
+  On Mac, Emacs can use @key{control}, @key{command}, @key{option}, and
+laptop @key{function} keys as any of Emacs modifier keys except
+@key{SHIFT} (i.e., @key{ALT}, @key{CTRL}, @key{HYPER}, @key{META}, and
+@key{SUPER}).  The assignment is controlled by the variables
+@code{mac-control-modifier}, @code{mac-command-modifier},
+@code{mac-option-modifier}, and @code{mac-function-modifier}.  The value
+for each of these variables can be one of the following symbols:
+@code{alt}, @code{control}, @code{hyper}, @code{meta}, @code{super}, and
+@code{nil} (no particular assignment).  By default, the @key{control}
+key works as @key{CTRL}, and the @key{command} key as @key{META}.
 
   For the @key{option} key, if @code{mac-option-modifier} is set to
 @code{nil}, which is the default, the key works as the normal
@@ -64,13 +65,9 @@
 
   Emacs recognizes the setting in the Keyboard control panel (Mac OS
 Classic) or the International system preference pane (Mac OS X) and
-supports international and alternative keyboard layouts (e.g., Dvorak)
-if its script is either Roman, Japanese, Traditional Chinese, Korean,
-Cyrillic, Simplified Chinese, or Central European.  Keyboard layouts
-based on Unicode may not work properly.  (Try drag-and-drop if input
-from the Character Palette does not work.)  Selecting one of the layouts
-from the keyboard layout pull-down menu will affect how the keys typed
-on the keyboard are interpreted.
+supports international and alternative keyboard layouts (e.g., Dvorak).
+Selecting one of the layouts from the keyboard layout pull-down menu
+will affect how the keys typed on the keyboard are interpreted.
 
 @vindex mac-pass-command-to-system
 @vindex mac-pass-control-to-system
--- a/man/message.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/message.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -1681,56 +1681,73 @@
 Valid checks are:
 
 @table @code
-@item subject-cmsg
-Check the subject for commands.
-@item sender
-@cindex Sender
-Insert a new @code{Sender} header if the @code{From} header looks odd.
-@item multiple-headers
-Check for the existence of multiple equal headers.
-@item sendsys
-@cindex sendsys
-Check for the existence of version and sendsys commands.
-@item message-id
-Check whether the @code{Message-ID} looks ok.
-@item from
-Check whether the @code{From} header seems nice.
-@item long-lines
-@cindex long lines
-Check for too long lines.
-@item control-chars
-Check for invalid characters.
-@item size
-Check for excessive size.
-@item new-text
-Check whether there is any new text in the messages.
-@item signature
-Check the length of the signature.
 @item approved
 @cindex approved
 Check whether the article has an @code{Approved} header, which is
 something only moderators should include.
+@item continuation-headers
+Check whether there are continuation header lines that don't begin with
+whitespace.
+@item control-chars
+Check for invalid characters.
 @item empty
 Check whether the article is empty.
-@item invisible-text
-Check whether there is any invisible text in the buffer.
-@item empty-headers
-Check whether any of the headers are empty.
 @item existing-newsgroups
 Check whether the newsgroups mentioned in the @code{Newsgroups} and
 @code{Followup-To} headers exist.
-@item valid-newsgroups
-Check whether the @code{Newsgroups} and @code{Followup-to} headers
-are valid syntactically.
+@item from
+Check whether the @code{From} header seems nice.
+@item illegible-text
+Check whether there is any non-printable character in the body.
+@item invisible-text
+Check whether there is any invisible text in the buffer.
+@item long-header-lines
+Check for too long header lines.
+@item long-lines
+@cindex long lines
+Check for too long lines in the body.
+@item message-id
+Check whether the @code{Message-ID} looks syntactically ok.
+@item multiple-headers
+Check for the existence of multiple equal headers.
+@item new-text
+Check whether there is any new text in the messages.
+@item newsgroups
+Check whether the @code{Newsgroups} header exists and is not empty.
+@item quoting-style
+Check whether text follows last quoted portion.
 @item repeated-newsgroups
 Check whether the @code{Newsgroups} and @code{Followup-to} headers
 contains repeated group names.
+@item reply-to
+Check whether the @code{Reply-To} header looks ok.
+@item sender
+@cindex Sender
+Insert a new @code{Sender} header if the @code{From} header looks odd.
+@item sendsys
+@cindex sendsys
+Check for the existence of version and sendsys commands.
+@item shoot
+Check whether the domain part of the @code{Message-ID} header looks ok.
 @item shorten-followup-to
 Check whether to add a @code{Followup-to} header to shorten the number
 of groups to post to.
+@item signature
+Check the length of the signature.
+@item size
+Check for excessive size.
+@item subject
+Check whether the @code{Subject} header exists and is not empty.
+@item subject-cmsg
+Check the subject for commands.
+@item valid-newsgroups
+Check whether the @code{Newsgroups} and @code{Followup-to} headers
+are valid syntactically.
 @end table
 
-All these conditions are checked by default.
+All these conditions are checked by default, except for @code{sender}
+for which the check is disabled by default if
+@code{message-insert-canlock} is non-@code{nil} (@pxref{Canceling News}).
 
 @item message-ignored-news-headers
 @vindex message-ignored-news-headers
--- a/man/mh-e.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/mh-e.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -8,12 +8,12 @@
 @c %**end of header
 
 @c Version of the software and manual.
-@set VERSION 8.0
+@set VERSION 8.0.1
 @c Edition of the manual. It is either empty for the first edition or
 @c has the form ", nth Edition" (without the quotes).
 @set EDITION 
-@set UPDATED 2006-05-06
-@set UPDATE-MONTH May, 2006
+@set UPDATED 2006-06-20
+@set UPDATE-MONTH June, 2006
 
 @c Other variables.
 @set MH-BOOK-HOME http://rand-mh.sourceforge.net/book/mh
@@ -217,7 +217,7 @@
 @value{VERSION} of MH-E will appear in GNU Emacs 22.1. It is supported
 in GNU Emacs 21, as well as XEmacs 21 (except for versions
 21.5.9-21.5.16). It is compatible with MH versions 6.8.4 and higher,
-all versions of nmh, and GNU mailutils 0.4 and higher.}, so you
+all versions of nmh, and GNU mailutils 1.0 and higher.}, so you
 shouldn't have to do anything special to use it. This manual covers
 MH-E version @value{VERSION}. To help you decide which version you
 have, see @ref{Getting Started}.
--- a/man/msdog.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/msdog.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -29,10 +29,13 @@
 @menu
 * Text and Binary::     Text files use CRLF to terminate lines.
 * Windows Files::       File-name conventions on Windows.
+* ls in Lisp::          Emulation of @code{ls} for Dired.
 * Windows HOME::        Where Emacs looks for your @file{.emacs}.
+* Windows Keyboard::    Windows-specific keyboard features.
+* Windows Mouse::       Windows-specific mouse features.
 * Windows Processes::   Running subprocesses on Windows.
 * Windows Printing::    How to specify the printer on MS-Windows.
-* Windows System Menu:: Controlling what the ALT key does.
+* Windows Misc::        Miscellaneous Windows features.
 @ifnottex
 * MS-DOS::              Using Emacs on MS-DOS (otherwise known as @dfn{MS-DOG}).
 @end ifnottex
@@ -167,6 +170,111 @@
   On MS-DOS/MS-Windows, file names are case-insensitive, so Emacs by
 default ignores letter-case in file names during completion.
 
+@vindex w32-get-true-file-attributes
+  If the variable @code{w32-get-true-file-attributes} is
+non-@code{nil} (the default), Emacs tries to determine the accurate
+link counts for files.  This option is only useful on the NT family of
+Windows (2K/XP/2K3), and it considerably slows down Dired and other
+features.
+
+@node ls in Lisp
+@section Emulation of @code{ls} on MS-Windows
+@cindex Dired, and MS-Windows/MS-DOS
+@cindex @code{ls} emulation
+
+  Dired normally uses the external program @code{ls} (or its close
+work-alike) to produce the directory listing displayed in Dired
+buffers (@pxref{Dired}).  However, MS-Windows and MS-DOS systems don't
+come with such a program, although several ports of @sc{gnu} @code{ls}
+are available.  Therefore, Emacs on those systems @emph{emulates}
+@code{ls} in Lisp, by using the @file{ls-lisp.el} package.  While
+@file{ls-lisp.el} provides a reasonably full emulation of @code{ls},
+there are some options and features peculiar to that emulation; they
+are described in this section.
+
+  The @code{ls} emulation supports many of the @code{ls} switches, but
+it doesn't support all of them.  Here's the list of the switches it
+does support: @option{-A}, @option{-a}, @option{-B}, @option{-C},
+@option{-c}, @option{-i}, @option{-G}, @option{-g}, @option{-R},
+@option{-r}, @option{-S}, @option{-s}, @option{-t}, @option{-U},
+@option{-u}, and @option{-X}.  The @option{-F} switch is partially
+supported (it appends the character that classifies the file, but does
+not prevent symlink following).
+
+@vindex ls-lisp-use-insert-directory-program
+  On MS-Windows and MS-DOS, @file{ls-lisp.el} is preloaded when Emacs
+is built, so the Lisp emulation of @code{ls} is always used on those
+platforms.  If you have a ported @code{ls}, setting
+@code{ls-lisp-use-insert-directory-program} to a non-@code{nil} value
+will revert to using an external program named by the variable
+@code{insert-directory-program}.
+
+@vindex ls-lisp-ignore-case
+  By default, @file{ls-lisp.el} uses a case-sensitive sort order for
+the directory listing it produces; this is so the listing looks the
+same as on other platforms.  If you wish that the files be sorted in
+case-insensitive order, set the variable @code{ls-lisp-ignore-case} to
+a non-@code{nil} value.
+
+@vindex ls-lisp-dirs-first
+  By default, files and subdirectories are sorted together, to emulate
+the behavior of @code{ls}.  However, native MS-Windows/MS-DOS file
+managers list the directories before the files; if you want that
+behavior, customize the option @code{ls-lisp-dirs-first} to a
+non-@code{nil} value.
+
+@vindex ls-lisp-verbosity
+  The variable @code{ls-lisp-verbosity} controls the file attributes
+that @file{ls-lisp.el} displays.  The value should be a list that
+contains one or more of the symbols @code{links}, @code{uid}, and
+@code{gid}.  @code{links} means display the count of different file
+names that are associated with (a.k.a.@: @dfn{links to}) the file's
+data.  @code{uid} means display the numerical identifier of the user
+who owns the file.  @code{gid} means display the numerical identifier
+of the file owner's group.  The default value is @code{(links uid gid)}
+i.e.@: all the 3 optional attributes are displayed.
+
+@vindex ls-lisp-emulation
+  The variable @code{ls-lisp-emulation} controls the flavour of the
+@code{ls} emulation by setting the defaults for the 3 options
+described above: @code{ls-lisp-ignore-case},
+@code{ls-lisp-dirs-first}, and @code{ls-lisp-verbosity}.  The value of
+this option can be one of the following symbols:
+
+@table @code
+@item GNU
+@itemx nil
+Emulate @sc{gnu} systems; this is the default.  This sets
+@code{ls-lisp-ignore-case} and @code{ls-lisp-dirs-first} to
+@code{nil}, and @code{ls-lisp-verbosity} to @code{(links uid gid)}.
+@item UNIX
+Emulate Unix systems.  Like @code{GNU}, but sets
+@code{ls-lisp-verbosity} to @code{(links uid)}.
+@item MacOS
+Emulate MacOS.  Sets @code{ls-lisp-ignore-case} to @code{t}, and
+@code{ls-lisp-dirs-first} and @code{ls-lisp-verbosity} to @code{nil}.
+@item MS-Windows
+Emulate MS-Windows.  Sets @code{ls-lisp-ignore-case} and
+@code{ls-lisp-dirs-first} to @code{t}, and @code{ls-lisp-verbosity} to
+@code{(links)} on Windows NT/2K/XP/2K3 and to @code{nil} on Windows 9X.
+Note that the default emulation is @emph{not} @code{MS-Windows}, even
+on Windows, since many users of Emacs on those platforms prefer the
+@sc{gnu} defaults.
+@end table
+
+@noindent
+Any other value of @code{ls-lisp-emulation} means the same as
+@code{GNU}.  Note that this option needs to be set @emph{before}
+@file{ls-lisp.el} is loaded, which means that on MS-Windows and MS-DOS
+you will have to set the value from your @file{.emacs} file and then
+restart Emacs, since @file{ls-lisp.el} is preloaded.
+
+@vindex ls-lisp-support-shell-wildcards
+  The variable @code{ls-lisp-support-shell-wildcards} controls how
+file-name patterns are supported: if it is non-@code{nil} (the
+default), they are treated as shell-style wildcards; otherwise they
+are treated as Emacs regular expressions.
+
 @node Windows HOME
 @section HOME Directory on MS-Windows
 @cindex @code{HOME} directory on MS-Windows
@@ -211,6 +319,132 @@
 @file{_emacs} as a fallback, if such a file exists in the home
 directory, whereas @file{.emacs} does not.
 
+@node Windows Keyboard
+@section Keyboard Usage on MS-Windows
+@cindex keyboard, MS-Windows
+
+  This section describes the Windows-specific features related to
+keyboard input in Emacs.
+
+@kindex F10 @r{(MS-Windows)}
+@cindex menu bar access using keyboard @r{(MS-Windows)}
+  The @key{F10} key on Windows activates the menu bar in a way that
+makes it possible to use the menus without a mouse.  In this mode, the
+arrow keys traverse the menus, @key{RET} selects a highlighted menu
+item, and @key{ESC} closes the menu.
+
+@vindex w32-alt-is-meta
+@cindex @code{Alt} key (MS-Windows)
+  By default, the key labeled @key{Alt} is mapped as the @key{META}
+key.  If you wish it to produce the @code{Alt} modifier instead, set
+the variable @code{w32-alt-is-meta} to a @code{nil} value.
+
+@vindex w32-capslock-is-shiftlock
+  By default, the @key{CapsLock} key only affects normal character
+keys (it converts lower-case characters to their upper-case
+variants).  However, if you set the variable
+@code{w32-capslock-is-shiftlock} to a non-@code{nil} value, the
+@key{CapsLock} key will affect non-character keys as well, as if you
+pressed the @key{Shift} key while typing the non-character key.
+
+@vindex w32-enable-caps-lock
+  If the variable @code{w32-enable-caps-lock} is set to a @code{nil}
+value, the @key{CapsLock} key produces the symbol @code{capslock}
+instead of the shifted version of they keys.  The default value is
+@code{t}.
+
+@vindex w32-enable-num-lock
+@cindex keypad keys (MS-Windows)
+  Similarly, if @code{w32-enable-num-lock} is @code{nil}, the
+@key{NumLock} key will produce the symbol @code{kp-numlock}.  The
+default is @code{t}, which causes @key{NumLock} to work as expected:
+toggle the meaning of the keys on the numeric keypad.
+
+@vindex w32-apps-modifier
+  The variable @code{w32-apps-modifier} controls the effect of the
+@key{Apps} key (usually located between the right @key{Alt} and the
+right @key{Ctrl} keys).  Its value can be one of the symbols
+@code{hyper}, @code{super}, @code{meta}, @code{alt}, @code{control},
+or @code{shift} for the respective modifier, or @code{nil} to appear
+as the key @code{apps}.  The default is @code{nil}.
+
+@vindex w32-lwindow-modifier
+@vindex w32-rwindow-modifier
+@vindex w32-scroll-lock-modifier
+  The variable @code{w32-lwindow-modifier} determines the effect of
+the left Windows key (usually labeled with @key{start} and the Windows
+logo).  If its value is @code{nil} (the default), the key will produce
+the symbol @code{lwindow}.  Setting it to one of the symbols
+@code{hyper}, @code{super}, @code{meta}, @code{alt}, @code{control},
+or @code{shift} will produce the respective modifier.  A similar
+variable @code{w32-rwindow-modifier} controls the effect of the right
+Windows key, and @code{w32-scroll-lock-modifier} does the same for the
+@key{ScrLock} key.  If these variables are set to @code{nil}, the
+right Windows key produces the symbol @code{rwindow} and @key{ScrLock}
+produces the symbol @code{scroll}.
+
+@vindex w32-pass-alt-to-system
+@cindex Windows system menu
+@cindex @code{Alt} key invokes menu (Windows)
+  Emacs compiled as a native Windows application normally turns off
+the Windows feature that tapping the @key{ALT} key invokes the Windows
+menu.  The reason is that the @key{ALT} serves as @key{META} in Emacs.
+When using Emacs, users often press the @key{META} key temporarily and
+then change their minds; if this has the effect of bringing up the
+Windows menu, it alters the meaning of subsequent commands.  Many
+users find this frustrating.
+
+  You can re-enable Windows' default handling of tapping the @key{ALT}
+key by setting @code{w32-pass-alt-to-system} to a non-@code{nil}
+value.
+
+@vindex w32-pass-lwindow-to-system
+@vindex w32-pass-rwindow-to-system
+  The variables @code{w32-pass-lwindow-to-system} and
+@code{w32-pass-rwindow-to-system} determine whether the respective
+keys are passed to Windows or swallowed by Emacs.  If the value is
+@code{nil}, the respective key is silently swallowed by Emacs,
+otherwise it is passed to Windows.  The default is @code{t} for both
+of these variables.  Passing each of these keys to Windows produces
+its normal effect: for example, @kbd{@key{Lwindow}} opens the
+@code{Start} menu, etc.
+
+@vindex w32-recognize-altgr
+@kindex AltGr @r{(MS-Windows)}
+@cindex AltGr key (MS-Windows)
+  The variable @code{w32-recognize-altgr} controls whether the right
+@key{Alt} and left @key{Ctrl} keys are recognized as the @key{AltGr}
+key.  The default is @code{t}, which means these keys produce
+@code{AltGr}; setting them to @code{nil} causes these keys to be
+interpreted normally (as the respective modifiers).
+
+@node Windows Mouse
+@section Mouse Usage on MS-Windows
+@cindex mouse, and MS-Windows
+
+  This section describes the Windows-specific variables related to
+mouse.
+
+@vindex w32-mouse-button-tolerance
+@cindex simulation of middle mouse button
+  The variable @code{w32-mouse-button-tolerance} specifies the
+time interval, in milliseconds, for faking middle mouse button press
+on 2-button mice.  If both mouse buttons are depressed within this
+time interval, Emacs generates a middle mouse button click event
+instead of a double click on one of the buttons.
+
+@vindex w32-pass-extra-mouse-buttons-to-system
+  If the variable @code{w32-pass-extra-mouse-buttons-to-system} is
+non-@code{nil}, Emacs passes the fourth and fifth mouse buttons to
+Windows.
+
+@vindex w32-swap-mouse-buttons
+  The variable @code{w32-swap-mouse-buttons} controls which of the 3
+mouse buttons generates the @kbd{mouse-2} events.  When it is
+@code{nil} (the default), the middle button generates @kbd{mouse-2}
+and the right button generates @kbd{mouse-3} events.  If this variable
+is non-@code{nil}, the roles of these two buttons are reversed.
+
 @node Windows Processes
 @section Subprocesses on Windows 9X/ME and Windows NT/2K/XP
 @cindex subprocesses on MS-Windows
@@ -263,6 +497,14 @@
 @code{Shutdown}.  That usually works, although it may take a few minutes
 to do its job.
 
+@vindex w32-quote-process-args
+  The variable @code{w32-quote-process-args} controls how the process
+arguments are quoted.  If it is non-@code{nil} means they are quoted
+with the @code{"} character.  If the value is a character, that
+character will be used to escape any quote characters that appear;
+otherwise a suitable escape character will be chosen based on the type
+of the program.
+
 @node Windows Printing
 @section Printing and MS-Windows
 
@@ -408,21 +650,33 @@
 (This assumes that Ghostscript is installed in the
 @file{D:/gs6.01} directory.)
 
-@node Windows System Menu
-@section Using the System Menu on Windows
-@cindex @code{Alt} key invokes menu (Windows)
+@node Windows Misc
+@section Miscellaneous Windows-specific features
+
+  This section describes miscellaneous Windows-specific features.
+
+@vindex w32-grab-focus-on-raise
+@cindex frame focus policy, MS-Windows
+  The variable @code{w32-grab-focus-on-raise}, if set to a
+non-@code{nil} value causes a frame to grab focus when it is raised.
+The default is @code{t}, which fits well with the Windows default
+click-to-focus policy.
 
-Emacs compiled as a native Windows application normally turns off the
-Windows feature that tapping the @key{ALT} key invokes the Windows
-menu.  The reason is that the @key{ALT} serves as @key{META} in Emacs.
-When using Emacs, users often press the @key{META} key temporarily and
-then change their minds; if this has the effect of bringing up the
-Windows menu, it alters the meaning of subsequent commands.  Many
-users find this frustrating.
+@vindex w32-list-proportional-fonts
+  The variable @code{w32-list-proportional-fonts} controls whether
+proportional fonts are included in the font selection dialog.  If its
+value is non-@code{nil}, these fonts will be included.  The default is
+@code{nil}.
 
-@vindex w32-pass-alt-to-system
-You can re-enable Windows' default handling of tapping the @key{ALT} key
-by setting @code{w32-pass-alt-to-system} to a non-@code{nil} value.
+@vindex w32-use-visible-system-caret
+@cindex screen reader software, MS-Windows
+  The variable @code{w32-use-visible-system-caret} is a flag that
+determines whether to make the system caret visible.  The default is
+@code{nil}, which means Emacs draws its own cursor to indicate the
+position of point.  A non-@code{nil} value means Emacs will indicate
+point location by the system caret; this facilitates use of screen
+reader software.  When this variable is non-@code{nil}, other
+variables affecting the cursor display have no effect.
 
 @ifnottex
 @include msdog-xtra.texi
--- a/man/org.texi	Mon Jun 12 07:27:12 2006 +0000
+++ b/man/org.texi	Tue Jun 27 15:06:36 2006 +0000
@@ -3,7 +3,7 @@
 @setfilename ../info/org
 @settitle Org Mode Manual
 
-@set VERSION 4.37
+@set VERSION 4.39
 @set DATE June 2006
 
 @dircategory Emacs
@@ -83,9 +83,12 @@
 * Timestamps::                  Assign date and time to items
 * Tags::                        Tagging headlines and matching sets of tags
 * Agenda views::                Collecting information into views
+* Embedded LaTeX::              LaTeX fragments and formulas
 * Exporting::                   Sharing and publishing of notes
 * Publishing::                  Create a web site of linked Org-mode files
 * Miscellaneous::               All the rest which did not fit elsewhere
+* Extensions and Hacking::      It is possible to write add-on code
+* History and Acknowledgments::  How Org-mode came into being 
 * Index::                       The fast road to specific information
 * Key Index::                   Key bindings and where they are described
 
@@ -95,7 +98,7 @@
 Introduction
 
 * Summary::                     Brief summary of what Org-mode does
-* Installation and activation::  How to install Org-mode
+* Installation::                How to install Org-mode
 * Feedback::                    Bug reports, ideas, patches etc.
 
 Document Structure
@@ -109,6 +112,11 @@
 * Sparse trees::                Matches embedded in context
 * Plain lists::                 Editing hand-formatted lists
 
+Archiving
+
+* ARCHIVE tag::                 Marking a tree as inactive
+* Moving subtrees::             Moving a tree to an archive file
+
 Tables
 
 * Built-in table editor::       Simple tables
@@ -162,7 +170,7 @@
 
 Progress Logging
 
-* Closing items::               When was this entry makred DONE?
+* Closing items::               When was this entry marked DONE?
 * Clocking work time::          When exactly did you work on this item?
 
 Tags
@@ -188,6 +196,14 @@
 * Calendar/Diary integration::  Integrating Anniversaries and more
 * Sorting of agenda items::     The order of things
 
+Embedded LaTeX
+
+* Math symbols::                TeX macros for symbols and greek letters
+* Subscripts and Superscripts::  Simple syntax for raising/lowering text
+* LaTeX fragments::             Complex formulas made easy
+* Processing LaTeX fragments::  Previewing LaTeX processing
+* CDLaTeX mode::                Speed up entering of formulas
+
 Exporting
 
 * ASCII export::                Exporting to plain ASCII
@@ -211,7 +227,7 @@
 Configuration
 
 * Project alist::               The central configuration variable
-* File sources and destinations::  From here to there
+* 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 export
@@ -227,21 +243,23 @@
 
 * Completion::                  M-TAB knows what you need
 * Customization::               Adapting Org-mode to your taste
-* Summary of in-buffer settings::  Using special lines to set options
+* 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-mode on a tty
-* FAQ::                         Frequently asked questions
 * Interaction::                 Other Emacs packages
 * Bugs::                        Things which do not work perfectly
-* Acknowledgments::             These people provided feedback and more
 
 Interaction with other packages
 
-* Extensions::                  Third-party extensions for Org-mode
 * Cooperation::                 Packages Org-mode cooperates with
 * Conflicts::                   Packages that lead to conflicts
 
+Extensions, Hooks and Hacking
+
+* Extensions::                  Existing 3rd-part extensions
+* Dynamic blocks::              Automatically filled blocks
+
 @end detailmenu
 @end menu
 
@@ -251,11 +269,11 @@
 
 @menu
 * Summary::                     Brief summary of what Org-mode does
-* Installation and activation::  How to install Org-mode
+* Installation::                How to install Org-mode
 * Feedback::                    Bug reports, ideas, patches etc.
 @end menu
 
-@node Summary, Installation and activation, Introduction, Introduction
+@node Summary, Installation, Introduction, Introduction
 @section Summary
 @cindex summary
 
@@ -296,14 +314,15 @@
 The Org-mode table editor can be integrated into any major mode by
 activating the minor Orgtbl-mode.
 
+@cindex FAQ
 There is a website for Org-mode which provides links to the newest
-version of Org-mode, as well as additional information, screen shots
-and example files.  This page is located at
+version of Org-mode, as well as additional information, frequently asked
+questions (FAQ), links to tutorials etc.  This page is located at
 @uref{http://www.astro.uva.nl/~dominik/Tools/org/}.
 
 @page
 
-@node Installation and activation, Feedback, Summary, Introduction
+@node Installation, Feedback, Summary, Introduction
 @section Installation and Activation
 @cindex installation
 @cindex autoload
@@ -341,6 +360,10 @@
 (require 'org-install)
 @end lisp
 
+If you use Org-mode with XEmacs, you also need to install the file
+@file{noutline.el} from the @file{xemacs} subdirectory of the Org-mode
+distribution.
+
 @cindex org-mode, turning on
 With this setup, all files with extension @samp{.org} will be put into
 Org-mode.  As an alternative, make the first line of a file look like
@@ -354,7 +377,7 @@
 the file's name is.  See also the variable
 @code{org-insert-mode-line-in-empty-file}.
 
-@node Feedback,  , Installation and activation, Introduction
+@node Feedback,  , Installation, Introduction
 @section Feedback
 @cindex feedback
 @cindex bug reports
@@ -614,26 +637,89 @@
 @node Archiving, Sparse trees, Structure editing, Document structure
 @section Archiving
 @cindex archiving
-@cindex filing subtrees
 
 When a project represented by a (sub)tree is finished, you may want
-to move the tree to an archive place, either in the same file under a
-special top-level heading, or even to a different file.
+to move the tree out of the way and to stop it from contributing to the
+agenda.  Org-mode knows two ways of archiving.  You can mark a tree with
+the ARCHIVE tag, or you can move an entire (sub)tree to a different
+location.
+
+@menu
+* ARCHIVE tag::                 Marking a tree as inactive
+* Moving subtrees::             Moving a tree to an archive file
+@end menu
+
+@node ARCHIVE tag, Moving subtrees, Archiving, Archiving
+@subsection The ARCHIVE tag
+@cindex internal archiving
+
+A headline that is marked with the ARCHIVE tag (@pxref{Tags}) stays at
+its location in the outline tree, but behaves in the following way:
+@itemize @minus
+@item
+It does not open when you attempt to do so with a visibility cycling
+command (@pxref{Visibility cycling}).  You can still open it with a
+normal outline command like @code{show-all}.  Or you can modify the
+option @code{org-cycle-open-archived-trees}.
+@item
+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
+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}.
+@item
+Archived trees are not exported (@pxref{Exporting}), only the headline
+is.  Configure the details using the variable
+@code{org-export-with-archived-trees}.
+@end itemize
+
+The following commands allow to set or clear the ARCHIVE tag:
+
+@table @kbd
+@kindex C-c C-x C-a
+@item C-c C-x C-a
+Toggle the ARCHIVE tag for the current headline.  When the tag is set,
+the headline changes to a shadowish face, and the subtree below it is
+hidden.
+@kindex C-u C-c C-x C-a
+@item C-u C-c C-x C-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.
+@end table
+
+@node Moving subtrees,  , ARCHIVE tag, Archiving
+@subsection Moving subtrees
+@cindex external archiving
+
+Once an entire project is finished, you may want to move it to a
+different location, either in the current file, or even in a different
+file, the archive file.
+
 @table @kbd
 @kindex C-c $
-@item @kbd{C-c $}
+@item C-c $
 Archive the subtree starting at the cursor position to the location
 given by @code{org-archive-location}.
+@kindex C-u C-c $
+@item C-u C-c $
+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.
 @end table
 
 @cindex archive locations
-The default archive is a file in the same directory as the current
-file, with the name derived by appending @file{_archive} to the
-current file name.  For information and examples on how to change
-this, see the documentation string of the variable
-@code{org-archive-location}.  If you are also using the Org-mode
-agenda, archiving to a different file is a good way to keep archived
-trees from contributing agenda items.
+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.  For information and examples on how to change this,
+see the documentation string of the variable
+@code{org-archive-location}.
 
 @node Sparse trees, Plain lists, Archiving, Document structure
 @section Sparse trees
@@ -806,6 +892,7 @@
 list at the cursor.
 @end table
 
+
 @node Tables, Hyperlinks, Document structure, Top
 @chapter Tables
 @cindex tables
@@ -1663,8 +1750,7 @@
 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
-and activation}.
+The key binding @kbd{C-c l} is only a suggestion - see @ref{Installation}.
 
 @kindex C-c C-l
 @cindex link completion
@@ -1674,7 +1760,11 @@
 Insert a link.  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.  Through completion,
-all links stored during the current session can be accessed.  The link
+all links stored during the current session can be
+accessed@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 to @kbd{C-c C-l}, or configure the
+option @code{org-keep-stored-link-after-insertion}.}.  The link
 will be inserted into the buffer, along with a descriptive text.  Note
 that you don't have to use this command to insert a link.  Links in
 Org-mode are plain text, and you can type or paste them straight into
@@ -1711,11 +1801,11 @@
 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 time
 stamp, it compiles the agenda for that date.  Furthermore, it will visit
-text files in @samp{file:} links with Emacs and select a suitable
-application for 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.
+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.
 
 @kindex mouse-2
 @kindex mouse-1
@@ -2227,10 +2317,9 @@
 @item Time range with CLOCK keyword
 @cindex CLOCK keyword
 When using the clock to time the work that is being done on specific
-items, time ranges preceeded by the CLOCK keyword are inserted
+items, time ranges preceded by the CLOCK keyword are inserted
 automatically into the file.  The time stamps are enclosed in square
 brackets instead of angular brackets.  @xref{Clocking work time}.
-@c FIXME: Reference needed
 @end table
 
 @node Creating timestamps, Progress logging, Time stamps, Timestamps
@@ -2376,7 +2465,7 @@
 stop working on an aspect of a project.
 
 @menu
-* Closing items::               When was this entry makred DONE?
+* Closing items::               When was this entry marked DONE?
 * Clocking work time::          When exactly did you work on this item?
 @end menu
 
@@ -2405,8 +2494,8 @@
 
 Org-mode allows you to clock the time you spent on specific tasks in a
 project.  When you start working on an item, you can start the clock.
-When you stop working on that tast, or when you makr the task done, the
-clock is stoppend and the corresponding time interval is recorded.  It
+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 of a project.
 
 @table @kbd
@@ -2435,6 +2524,22 @@
 recorded under that heading, including the time of any subheadings. You
 can use visibility cycling to study the tree, but the overlays disappear
 automatically when the buffer is changed.
+@kindex C-c C-x C-r
+@item C-c C-x C-r
+Insert a dynamic block containing a clock report as an org-mode table
+into the current file.
+@example
+#+BEGIN: clocktable :maxlevel 2 :emphasize nil
+
+#+END: clocktable
+@end example
+@noindent
+If such a block already exists, its content is replaced by the new
+table.  The @samp{BEGIN} line can specify options:
+@example
+:maxlevels   @r{Maximum level depth to which times are listed in the table.}
+:emphasize   @r{When @code{t}, emphasize level one and level two items}
+@end example
 @end table
 
 The @kbd{l} key may be used in the timeline (@pxref{Timeline}) and in
@@ -2612,7 +2717,7 @@
 @samp{WORK|LAPTOP&NIGHT} requires that the @samp{:LAPTOP:} lines are
 also tagged @samp{NIGHT}.
 
-@node Agenda views, Exporting, Tags, Top
+@node Agenda views, Embedded LaTeX, Tags, Top
 @chapter Agenda Views
 @cindex agenda views
 
@@ -2693,12 +2798,11 @@
 @cindex custom agenda commands
 @cindex agenda commands, custom
 The views are created through a dispatcher that should be bound to a
-global key, for example @kbd{C-c a} (@pxref{Installation and
-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:
+global key, for example @kbd{C-c a} (@pxref{Installation}).  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}).
@@ -3092,6 +3196,10 @@
 @item :
 Set tags for the current headline.
 
+@kindex a
+@item a
+Toggle the ARCHIVE tag for the current headline.
+
 @kindex ,
 @item ,
 Set the priority for the current item.  Org-mode prompts for the
@@ -3208,7 +3316,200 @@
 
 @end table
 
-@node Exporting, Publishing, Agenda views, Top
+@node Embedded LaTeX, Exporting, Agenda views, Top
+@chapter Embedded LaTeX
+@cindex @TeX{} interpretation
+@cindex La@TeX{} interpretation
+
+Plain ASCII is normally sufficient for almost all note taking.  One
+exception, however, are scientific notes which need to be able to
+contain mathematical symbols and the occasional formula.
+La@TeX{}@footnote{La@TeX{} is a macro system based on Donald E. Knuth's
+@TeX{} system.  Many of the features described here as ``La@TeX{}'' are
+really from @TeX{}, but for simplicity I am blurring this distinction.}
+is widely used to typeset scientific documents. Org-mode supports
+embedding La@TeX{} code into its files, because many academics are used
+to read La@TeX{} source code, and because it can be readily processed
+into images for HTML production.
+
+It is not necessary to mark La@TeX{} macros and code in any special way.
+If you observe a few conventions, Org-mode knows how to find it and what
+to do with it.
+
+@menu
+* Math symbols::                TeX macros for symbols and Greek letters
+* Subscripts and Superscripts::  Simple syntax for raising/lowering text
+* LaTeX fragments::             Complex formulas made easy
+* Processing LaTeX fragments::  Previewing LaTeX processing
+* CDLaTeX mode::                Speed up entering of formulas
+@end menu
+
+@node Math symbols, Subscripts and Superscripts, Embedded LaTeX, Embedded LaTeX
+@section Math symbols
+
+You can use La@TeX{} macros to insert special symbols like @samp{\alpha}
+to indicate the Greek letter, or @samp{\to} to indicate an arrow.
+Completion for these macros is available, just type @samp{\} and maybe a
+few letters, and press @kbd{M-@key{TAB}} to see possible completions.
+Unlike La@TeX{} code, Org-mode allows these macros to be present
+without surrounding math delimiters, for example:
+
+@example
+Angles are written as Greek letters \alpha, \beta and \gamma.
+@end example
+
+During HTML export (@pxref{HTML export}), these symbols are translated
+into the proper syntax for HTML, for the above examples this is
+@samp{&alpha;} and @samp{&rarr;}, respectively.
+
+@node Subscripts and Superscripts, LaTeX fragments, Math symbols, Embedded LaTeX
+@section Subscripts and Superscripts
+
+Just like in La@TeX{}, @samp{^} and @samp{_} are used to indicate super-
+and subscripts.  Again, these can be used without embedding them in
+math-mode delimiters.  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
+The mass if the sun is M_sun = 1.989 x 10^30 kg.  The radius o
+the sun is R_@{sun@} = 6.96 x 10^8 m.
+@end example
+
+To avoid interpretation as raised or lowered text, you can quote
+@samp{^} and @samp{_} with a backslash: @samp{\_} and @samp{\^}.
+
+During HTML export (@pxref{HTML export}), subscript and superscripts
+are surrounded with @code{<sub>} and @code{<sup>} tags, respectively.
+
+@node LaTeX fragments, Processing LaTeX fragments, Subscripts and Superscripts, Embedded LaTeX
+@section LaTeX fragments
+
+With symbols, sub- and superscripts, HTML is pretty much at its end when
+it comes to representing mathematical formulas.  More complex
+expressions need a dedicated formula processor.  To this end, Org-mode
+can contain arbitrary La@TeX{} fragments.  It provides commands to
+preview the typeset result of these fragments, and upon export to HTML,
+all fragments will be converted to images and inlined into the HTML
+document.  For this to work you need to be on a system with a working
+La@TeX{} installation.  You also need the @file{dvipng} program,
+available at @url{http://sourceforge.net/projects/dvipng/}.
+
+La@TeX{} 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.  The only requirement is that the
+@code{\begin} statements appears on a new line, preceded by only
+whitespace.
+@item
+Text within the usual La@TeX{} math delimiters.  Org-mode recognizes
+single @samp{$} characters as math delimiters only if they are directly
+attached to the surrounded text, with no whitespace in between.  For the
+other delimiters, there is no such restriction.
+@end itemize
+
+@noindent For example:
+
+@example
+\begin@{equation@}                          % arbitrary environments,
+x=\sqrt@{b@}                                % even tables, figures
+\end@{equation@}                            % etc
+
+If $a=\sqrt@{b@}$ and \( b=2 \), then the solution must be
+either $$ a=+\sqrt@{2@} $$ or \[ a=-\sqrt@{2@} \].
+@end example
+
+@noindent
+If you need any of the delimiter ASCII sequences for other purposes, you
+can configure the option @code{org-format-latex-options} to deselect the
+ones you do not wish to have interpreted by the La@TeX{} converter.
+
+@node Processing LaTeX fragments, CDLaTeX mode, LaTeX fragments, Embedded LaTeX
+@section Processing LaTeX fragments
+
+La@TeX{} fragments can be processed to produce a preview images of the
+typeset expressions:
+
+@table @kbd
+@kindex C-c C-x C-l
+@item C-c C-x C-l
+Produce a preview image of the La@TeX{} 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.
+@end table
+
+During HTML export (@pxref{HTML export}), all La@TeX{} fragments are
+converted into images and inlined into the document if the following
+setting is active:
+
+@lisp
+(setq org-export-with-LaTeX-fragments t)
+@end lisp
+
+@node CDLaTeX mode,  , Processing LaTeX fragments, Embedded LaTeX
+@section Using CDLaTeX to enter math
+
+CDLaTeX-mode is a minor mode that is normally used in combination with a
+major LaTeX mode like AUCTeX in order to speed-up insertion of
+environments and math templates.  Inside Org-mode, you can make use of
+some of the features of cdlatex-mode by turning on a special minor mode
+with @code{M-x org-cdlatex-mode}.  You can also turn it on for all
+Org-mode 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 cdlatex-mode):
+@itemize @bullet
+@kindex C-c @{
+@item
+Environment templates can be inserted with @kbd{C-c @{}.
+@item
+@kindex @key{TAB}
+The @key{TAB} key will do template expansion if the cursor is inside a
+LaTeX fragment@footnote{Org-mode has a heuristic 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}. 
+@item
+@kindex _
+@kindex ^
+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 backquote @kbd{`} 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 will pop up.
+@item
+@kindex '
+Pressing the normal quote @kbd{'} followed by another character modifies
+the symbol before point with an accent or a font.  If you wait more than
+1.5 seconds after the backquote, a help window will pop up.  Character
+modification will work only inside La@TeX{} fragments, outside the quote
+is normal.
+@end itemize
+
+@node Exporting, Publishing, Embedded LaTeX, Top
 @chapter Exporting
 @cindex exporting
 
@@ -3470,7 +3771,6 @@
 has a number of typing conventions that allow to produce a richly
 formatted output.
 
-
 @itemize @bullet
 
 @cindex hand-formatted lists
@@ -3484,22 +3784,14 @@
 @cindex bold text
 @cindex italic text
 @item
-You can make words @b{*bold*}, @i{/italic/}, and _underlined_
-
-@cindex @TeX{} interpretation
+You can make words @b{*bold*}, @i{/italic/}, _underlined_,
+@code{=code=}, and @samp{+strikethrough+}.
+
+@cindex LaTeX fragments, export
+@cindex TeX macros, export
 @item
-Simple @TeX{}-like math constructs are interpreted:
-
-@cindex completion, of @TeX{} symbols
-@itemize @minus
-@item
-@samp{10^22} and @samp{J_n} are super- and subscripts.  You can quote
-@samp{^} and @samp{_} with a backslash: @samp{\_} and @samp{\^}
-@item
-@samp{\alpha} indicates a Greek letter, @samp{\to} an arrow.  You can
-use completion for these macros, just type @samp{\} and maybe a few
-letters, and press @kbd{M-@key{TAB}} to see possible completions.
-@end itemize
+Many @TeX{} macros and entire La@TeX{} fragments are converted into HTML
+entities or images (@pxref{Embedded LaTeX}).
 
 @cindex tables, export
 @item
@@ -3531,6 +3823,7 @@
 which explains how to set export options with special lines in a
 buffer.
 
+
 @node Export options,  , Enhancing text, Text interpretation
 @subsection Export options
 @cindex options, for export
@@ -3556,7 +3849,7 @@
 #+LANGUAGE:  language for HTML, e.g. @samp{en} (@code{org-export-default-language})
 #+TEXT:      Some descriptive text to be inserted at the beginning.
 #+TEXT:      Several lines may be given.
-#+OPTIONS:   H:2  num:t  toc:t  \n:nil  @:t  ::t  |:t  ^:t  *:nil  TeX:t
+#+OPTIONS:   H:2 num:t toc:t \n:nil @@:t ::t |:t ^:t *:nil TeX:t LaTeX:t
 @end example
 
 @noindent
@@ -3572,6 +3865,7 @@
 @cindex @TeX{}-like syntax for sub- and superscripts
 @cindex emphasized text
 @cindex @TeX{} macros
+@cindex La@TeX{} fragments
 @example
 H:      @r{set the number of headline levels for export}
 num:    @r{turn on/off section-numbers}
@@ -3582,11 +3876,13 @@
 |:      @r{turn on/off tables}
 ^:      @r{turn on/off @TeX{}-like syntax for sub- and superscripts.}
 *:      @r{turn on/off emphasized text (bold, italic, underlined)}
-TeX:    @r{turn on/off @TeX{} macros}
+TeX:    @r{turn on/off simple @TeX{} macros in plain text}
+LaTeX:  @r{turn on/off La@TeX{} fragments}
 @end example
 
 @node Publishing, Miscellaneous, Exporting, Top
 @chapter Publishing
+@cindex publishing
 
 Org-mode includes@footnote{@file{org-publish.el} is not yet part of
 emacs, so if you are using @file{org.el} as it comes with Emacs, you
@@ -3615,7 +3911,7 @@
 
 @menu
 * Project alist::               The central configuration variable
-* File sources and destinations::  From here to there
+* 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 export
@@ -3623,8 +3919,10 @@
 * Project page index::          Publishing a list of project files
 @end menu
 
-@node Project alist, File sources and destinations, Configuration, Configuration
+@node Project alist, Sources and destinations, Configuration, Configuration
 @subsection The variable @code{org-publish-project-alist}
+@cindex org-publish-project-alist
+@cindex projects, for publishing
 
 Org-publish is configured almost entirely through setting the value of
 one variable, called @code{org-publish-project-alist}.
@@ -3649,8 +3947,9 @@
 options. When you publish such a ``meta-project'' all the components
 will also publish.
 
-@node File sources and destinations, Selecting files, Project alist, Configuration
+@node Sources and destinations, Selecting files, Project alist, Configuration
 @subsection Sources and destinations for files
+@cindex directories, for publishing
 
 Most properties are optional, but some should always be set. In
 particular, org-publish needs to know where to look for source files,
@@ -3664,8 +3963,9 @@
 @end multitable
 @noindent
 
-@node Selecting files, Publishing action, File sources and destinations, Configuration
+@node Selecting files, Publishing action, Sources and destinations, Configuration
 @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
@@ -3687,6 +3987,7 @@
 
 @node Publishing action, Publishing options, Selecting files, Configuration
 @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
@@ -3711,6 +4012,7 @@
 
 @node Publishing options, Publishing links, Publishing action, Configuration
 @subsection Options for the HTML exporter
+@cindex options, for publishing
 
 The property list can be used to set many export options for the HTML
 exporter.  In most cases, these properties correspond to user variables
@@ -3723,9 +4025,11 @@
 @item @code{:headline-levels}       @tab @code{org-export-headline-levels}
 @item @code{:section-numbers}       @tab @code{org-export-with-section-numbers}
 @item @code{:table-of-contents}     @tab @code{org-export-with-toc}
+@item @code{:archived-trees}        @tab @code{org-export-with-archived-trees}
 @item @code{:emphasize}             @tab @code{org-export-with-emphasize}
 @item @code{:sub-superscript}       @tab @code{org-export-with-sub-superscripts}
 @item @code{:TeX-macros}            @tab @code{org-export-with-TeX-macros}
+@item @code{:LaTeX-fragments}       @tab @code{org-export-with-LaTeX-fragments}
 @item @code{:fixed-width}           @tab @code{org-export-with-fixed-width}
 @item @code{:timestamps}           .@tab @code{org-export-with-timestamps}
 @item @code{:tags}                 .@tab @code{org-export-with-tags}
@@ -3752,6 +4056,7 @@
 
 @node Publishing links, Project page index, Publishing options, Configuration
 @subsection Links between published files
+@cindex links, publishing
 
 To create a link from one Org-mode file to another, you would use
 something like @samp{[[file:foo.org][The foo]]} or simply
@@ -3765,8 +4070,27 @@
 org-publish to upload the related files, these links will work
 too. @ref{Complex example} for an example of this usage.
 
+Sometime an Org-mode file to be published may contain links that are
+only valid in your production environment, but not in the publishing
+location.  In this case, use the property 
+
+@multitable @columnfractions 0.4 0.6
+@item @code{:link-validation-function}
+@tab Function to validate links
+@end multitable
+
+@noindent
+to define a function for checking link validity.  This function must
+accept two arguments, the file name and a directory relative to which
+the file name is interpreted in the production environment.  If this
+function returns @code{nil}, then the HTML generator will only insert a
+description into the HTML file, but no link.  One option for this
+function is @code{org-publish-validate-link} which checks if the given
+file is part of any project in @code{org-publish-project-alist}.
+
 @node Project page index,  , Publishing links, Configuration
 @subsection Project page index
+@cindex index, of published pages
 
 The following properties may be used to control publishing of an
 index of files or summary page for a given project.
@@ -3891,20 +4215,18 @@
 functions normally only publish changed files. You can override this and
 force publishing of all files by giving a prefix argument. 
 
-@node Miscellaneous, Index, Publishing, Top
+@node Miscellaneous, Extensions and Hacking, Publishing, Top
 @chapter Miscellaneous
 
 @menu
 * Completion::                  M-TAB knows what you need
 * Customization::               Adapting Org-mode to your taste
-* Summary of in-buffer settings::  Using special lines to set options
+* 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-mode on a tty
-* FAQ::                         Frequently asked questions
 * Interaction::                 Other Emacs packages
 * Bugs::                        Things which do not work perfectly
-* Acknowledgments::             These people provided feedback and more
 @end menu
 
 @node Completion, Customization, Miscellaneous, Miscellaneous
@@ -3950,8 +4272,7 @@
 @end itemize
 @end table
 
-
-@node Customization, Summary of in-buffer settings, Completion, Miscellaneous
+@node Customization, In-buffer settings, Completion, Miscellaneous
 @section Customization
 @cindex customization
 @cindex options, for customization
@@ -3963,9 +4284,9 @@
 variables is available with @kbd{M-x org-customize}.  Or select
 @code{Browse Org Group} from the @code{Org->Customization} menu.  Many
 settings can also be activated on a per-file basis, by putting special
-lines into the buffer (@pxref{Summary of in-buffer settings}).
-
-@node Summary of in-buffer settings, The very busy C-c C-c key, Customization, Miscellaneous
+lines into the buffer (@pxref{In-buffer settings}).
+
+@node In-buffer settings, The very busy C-c C-c key, Customization, Miscellaneous
 @section Summary of in-buffer settings
 @cindex in-buffer settings
 @cindex special keywords
@@ -4035,7 +4356,7 @@
 @ref{Export options}.
 @end table
 
-@node The very busy C-c C-c key, Clean view, Summary of in-buffer settings, Miscellaneous
+@node The very busy C-c C-c key, Clean view, In-buffer settings, Miscellaneous
 @section The very busy C-c C-c key
 @kindex C-c C-c
 
@@ -4043,14 +4364,13 @@
 mentioned scattered throughout this manual.  One specific function of
 this key is to add @emph{tags} to a headline (@pxref{Tags}).  In many
 other circumstances it means something like @emph{Hey Org-mode, look
-here and update according to what you see here}.  Here is a summary of what
-this means in different contexts.
+here and update according to what you see here}.  Here is a summary of
+what this means in different contexts.
 
 @itemize @minus
-@c @item
-@c If the cursor is in a headline, prompt for tags and insert them
-@c into the current line, aligned to `org-tags-column'.  When called
-@c with prefix arg, realign all tags in the current buffer.
+@item
+If there are highlichts in the buffer from the creation of a sparse
+tree, or from clock display, remove these highlights.
 @item
 If the cursor is in one of the special @code{#+KEYWORD} lines, this
 triggers scanning the buffer for these lines and updating the
@@ -4180,7 +4500,7 @@
 RET} in that file.  The reverse operation is @kbd{M-x
 org-convert-to-oddeven-levels}.
 
-@node TTY keys, FAQ, Clean view, Miscellaneous
+@node TTY keys, Interaction, Clean view, Miscellaneous
 @section Using org-mode on a tty
 @cindex tty keybindings
 
@@ -4217,251 +4537,19 @@
 @item @kbd{S-@key{down}}    @tab @kbd{C-c C-x @key{down}}  @tab
 @end multitable
 
-@node FAQ, Interaction, TTY keys, Miscellaneous
-@section Frequently asked questions
-@cindex FAQ
-
-@enumerate
-@cindex @code{keymapp nil} error
-@item @b{When I try to use Org-mode, I always get
-@code{(wrong-type-argument keymapp nil)}}.@*
-@cindex allout.el, conflict with
-This is a conflict with an outdated version of the @file{allout.el}.
-See @ref{Conflicts}.
-
-@item @b{Org-mode seems to be a useful default mode for the various
-@file{README} files I have scattered through my directories.  How do I
-turn it on for all @file{README} files?}
-
-@lisp
-(add-to-list 'auto-mode-alist '("README$" . org-mode))
-@end lisp
-
-@item @b{I would like to use editing features of org-mode in other
-modes, is this possible?}@*
-@c
-Not really.  For tables there is @code{orgtbl-mode} which implements the
-table editor as a minor mode.  For other features you need to switch to
-Org-mode temporarily, or prepare text in a different buffer.
-
-@item @b{Can I get the visibility-cycling features in outline-mode and
-outline-minor-mode?}@* 
-@c
-Yes, these functions are written in a way that they are independent of
-the outline setup.  The following setup provides standard Org-mode
-functionality in outline-mode on @key{TAB} and @kbd{S-@key{TAB}}.  For
-outline-minor-mode, we use @kbd{C-@key{TAB}} instead of @key{TAB},
-because @key{TAB} usually has mode-specific tasks.
-@lisp
-(add-hook 'outline-minor-mode-hook
-  (lambda ()
-    (define-key outline-minor-mode-map [(control tab)] 'org-cycle)
-    (define-key outline-minor-mode-map [(shift tab)] 'org-global-cycle)))
-(add-hook 'outline-mode-hook
-  (lambda ()
-    (define-key outline-mode-map [(tab)] 'org-cycle)
-    (define-key outline-mode-map [(shift tab)] 'org-global-cycle)))
-@end lisp
-
-Or check out @file{outline-magic.el}, which does this and also provides
-promotion and demotion functionality.  @file{outline-magic.el} is
-available at @url{http://www.astro.uva.nl/~dominik/Tools/OutlineMagic}.
-
-@item @b{Some of my links stopped working after I upgraded to a version
-4.20 or later.  Why is this, and how can I fix it?}@*
-@c
-These must be links in plain text, containing white space, such as
-@samp{bbdb:Richard Stallman}.  You need to protect these links by
-putting double brackets around them, like @samp{[[bbdb:Richard
-Stallman]]}.
-
-@item @b{I see that Org-mode now creates links using the double bracket
-convention that hides the link part and the brackets, only showing the
-description part.  How can I convert my old links to this new format?}@*
-@c
-Execute once in each Org-mode file: @kbd{M-x org-upgrade-old-links}.
-This replaces angular brackets with the new link format.
-
-@item @b{I don't care if you find the new bracket links great, I am
-attached to the old style using angular brackets and no hiding of the
-link text.  Please give them back to me, don't tell me it is not
-possible!}@*
-@c
-Would I let you down like that?  If you must, you can do this
-
-@lisp
-(setq org-link-style 'plain
-      org-link-format "<%s>")
-@end lisp
-
-@item @b{When I am executing shell/elisp links I always get a 
-confirmation prompt and need to type @kbd{yes @key{RET}}, that's 4 key
-presses!  Can I get rid of this?}@*
-@c
-@cindex shell links, confirmation
-@cindex dangerous commands
-The confirmation is there to protect you from unwantingly execute
-potentially dangerous commands.  For example, imagine a link
-@samp{[[shell:rm -rf ~/*][Google Search]]}.  In an Org-mode buffer, this
-command would look like @samp{Google Search}, but really it would remove
-your home directory.  If you wish, you can make it easier to respond to
-the query by setting @code{org-confirm-shell-link-function} and/or
-@code{org-confirm-elisp-link-function} to @code{y-or-n-p}.  Then a
-single @kbd{y} keypress will be enough to confirm those links.  It is
-also possible to turn off this check entirely, but I do not recommend to
-do this.  Be warned.
-
-@item @b{All these stars are driving me mad, I just find the Emacs
-outlines unreadable. Can't you just put white space and a single star as a
-starter for headlines?}@*
-@c
-See @ref{Clean view}.
-
-@item @b{I would like to have two windows on the same Org-mode
-file, but with different outline visibility.  Is that possible?}@*
-@c
-@cindex @code{make-indirect-buffer}
-@cindex indirect buffers
-In GNU Emacs, you may use @emph{indirect buffers} which do exactly this.
-See the documentation on the command @code{make-indirect-buffer}.  In
-XEmacs, this is currently not possible because of the different outline
-implementation.
-
-@item @b{When I export my TODO list, every TODO item becomes a
-separate section.  How do I enforce these items to be exported as an
-itemized list?}@*
-@c
-If you plan to use ASCII or HTML export, make sure things you want to
-be exported as item lists are level 4 at least, even if that does mean
-there is a level jump.  For example:
-
-@example
-* Todays top priorities
-**** TODO write a letter to xyz
-**** TODO Finish the paper
-**** Pick up kids at the school
-@end example
-
-Alternatively, if you need a specific value for the heading/item
-transition in a particular file, use the @samp{+OPTIONS} line to
-configure the @samp{H} switch.
-
-@example
-+OPTIONS:   H:2; ...
-@end example
-
-@item @b{I would like to export only a subtree of my file to HTML.
-How?}@*
-@c
-@cindex exporting a subtree
-If you want to export a subtree, mark the subtree as region and then
-export.  Marking can be done with @kbd{C-c @@ C-x C-x}, for example.
-
-@item @b{Org-mode takes over the S-cursor keys.  I also want to use
-CUA-mode, is there a way to fix this conflict?}@*
-Yes, see @ref{Conflicts}.
-
-@item @b{One of my table columns has started to fill up with
-@samp{#ERROR}.  What is going on?}@*
-@c
-Org-mode tried to compute the column from other fields using a
-formula stored in the @samp{#+TBLFM:} line just below the table, and
-the evaluation of the formula fails.  Fix the fields used in the
-formula, or fix the formula, or remove it!
-
-@item @b{When I am in the last column of a table and just above a
-horizontal line in the table, pressing TAB creates a new table line
-@i{before} the horizontal line.  How can I quickly move to the line
-@i{below} the horizontal line instead?}@*
-@c
-Press @key{down} (to get on the separator line) and then @key{TAB}.
-Or configure the variable @code{org-table-tab-jumps-over-hlines}.
-
-@item @b{How can I change the indentation of an entire table without
-fixing every line by hand?}@*
-@c
-@cindex indentation, of tables
-The indentation of a table is set by the first line.  So just fix the
-indentation of the first line and realign with @key{TAB}.
-
-@item @b{Is it possible to include entries from org-mode files into my
-emacs diary?}@*
-@c
-Since the org-mode agenda is much more powerful and can contain the
-diary (@pxref{Calendar/Diary integration}), you should think twice
-before deciding to do this.  Integrating Org-mode information into the
-diary is, however, possible.  You need to turn on @emph{fancy diary
-display} by setting in @file{.emacs}:
-
-@lisp
-(add-hook 'diary-display-hook 'fancy-diary-display)
-@end lisp
-
-Then include the following line into your @file{~/diary} file, in
-order to get the entries from all files listed in the variable
-@code{org-agenda-files}:
-
-@example
-&%%(org-diary)
-@end example
-@noindent
-You may also select specific files with
-
-@example
-&%%(org-diary) ~/path/to/some/org-file.org
-&%%(org-diary) ~/path/to/another/org-file.org
-@end example
-
-If you now launch the calendar and press @kbd{d} to display a diary, the
-headlines of entries containing a timestamp, date range, schedule, or
-deadline referring to the selected date will be listed.  Just like
-Org-mode's agenda view, the diary for @emph{today} contains additional
-entries for overdue deadlines and scheduled items.  See also the
-documentation of the @command{org-diary} function.  Under XEmacs, it is
-not possible to jump back from the diary to the org, this works only in
-the agenda buffer.
-
-@end enumerate
-
-
-@node Interaction, Bugs, FAQ, Miscellaneous
+@node Interaction, Bugs, TTY keys, Miscellaneous
 @section Interaction with other packages
 @cindex packages, interaction with other
 Org-mode lives in the world of GNU Emacs and interacts in various ways
 with other code out there.
 
 @menu
-* Extensions::                  Third-party extensions for Org-mode
 * Cooperation::                 Packages Org-mode cooperates with
 * Conflicts::                   Packages that lead to conflicts
 @end menu
 
-@node Extensions, Cooperation, Interaction, Interaction
-@subsection Third-party extensions for Org-mode
-
-The following extensions for Org-mode have been written by other people:
-
-@table @asis
-@cindex @file{org-mouse.el}
-@item @file{org-mouse.el} by Piotr Zielinski
-This package implements extended mouse functionality for Org-mode.  It
-allows you to cycle visibility and to edit the document structure with
-the mouse.  Best of all, it provides a context-sensitive menu on
-@key{mouse-3} that changes depending on the context of a mouse-click.
-@file{org-mouse.el} is freely available at @url{http://www.cl.cam.ac.uk/~pz215/files/org-mouse.el}.
-@cindex @file{org-publish.el}
-@item @file{org-publish.el} by David O'Toole
-This package provides facilities for publishing related sets of Org-mode
-files together with linked files like images as a webpages.  It is
-highly configurable and can be used for other publishing purposes as
-well.  As of Org-mode version 4.30, @file{org-publish.el} is part of
-the Org-mode distribution.  It is not yet part of Emacs, however, due to
-a pending copyright assignment.  In the mean time, @file{org-publish.el}
-can be downloaded from David's site:
-@url{http://dto.freeshell.org/e/org-publish.el}.
-@end table
-
-@node Cooperation, Conflicts, Extensions, Interaction
+
+@node Cooperation, Conflicts, Interaction, Interaction
 @subsection Packages that Org-mode cooperates with
 
 @table @asis
@@ -4487,6 +4575,11 @@
 the function @code{constants-get}, which has to be autoloaded in your
 setup.  See the installation instructions in the file
 @file{constants.el}.
+@item @file{cdlatex.el} by Carsten Dominik
+@cindex @file{cdlatex.el}
+Org-mode can make use of the cdlatex package to efficiently enter
+La@TeX{} fragments into Org-mode files.
+@file{cdlatex.el} is not part of Emacs, find it on the web.
 @item @file{remember.el} by John Wiegley
 @cindex @file{remember.el}
 Org mode cooperates with remember, see @ref{Remember}.
@@ -4538,7 +4631,7 @@
 @end table
 
 
-@node Bugs, Acknowledgments, Interaction, Miscellaneous
+@node Bugs,  , Interaction, Miscellaneous
 @section Bugs
 @cindex bugs
 
@@ -4564,10 +4657,6 @@
 (for example because the application does not exist or refuses to open
 the file), it does so silently.  No error message is displayed.
 @item
-Plain list items should be able to hold a TODO item.  Unfortunately this
-has so many technical problems that I will only consider this change for
-the next major release (5.0).
-@item
 The remote-editing commands in the agenda buffer cannot be undone with
 @code{undo} called from within the agenda buffer.  But you can go to
 the corresponding buffer (using @key{TAB} or @key{RET} and execute
@@ -4577,22 +4666,144 @@
 If a formula uses @emph{calculated} fields further down the row,
 multiple recalculation may be needed to get all fields consistent.
 @item
-Several words in a row may @b{*be made bold*}, but this does not work if
-the string is distributed over two lines.
+A single letter cannot be made bold, for example @samp{*a*}.
 @item
 The exporters work well, but could be made more efficient.
 @end itemize
 
-@node Acknowledgments,  , Bugs, Miscellaneous
-@section Acknowledgments
+
+@node Extensions and Hacking, History and Acknowledgments, Miscellaneous, Top
+@appendix Extensions, Hooks and Hacking
+
+This appendix lists extensions for Org-mode written by other authors.
+It also covers some aspects where users can easily extend the
+functionality of Org-mode.
+
+@menu
+* Extensions::                  Existing 3rd-part extensions
+* Dynamic blocks::              Automatically filled blocks
+@end menu
+
+@node Extensions, Dynamic blocks, Extensions and Hacking, Extensions and Hacking
+@section Third-party extensions for Org-mode
+
+The following extensions for Org-mode have been written by other people:
+
+@table @asis
+@cindex @file{org-mouse.el}
+@item @file{org-mouse.el} by Piotr Zielinski
+This package implements extended mouse functionality for Org-mode.  It
+allows you to cycle visibility and to edit the document structure with
+the mouse.  Best of all, it provides a context-sensitive menu on
+@key{mouse-3} that changes depending on the context of a mouse-click.
+@file{org-mouse.el} is freely available at @url{http://www.cl.cam.ac.uk/~pz215/files/org-mouse.el}.
+@cindex @file{org-publish.el}
+@item @file{org-publish.el} by David O'Toole
+This package provides facilities for publishing related sets of Org-mode
+files together with linked files like images as a webpages.  It is
+highly configurable and can be used for other publishing purposes as
+well.  As of Org-mode version 4.30, @file{org-publish.el} is part of the
+Org-mode distribution.  It is not yet part of Emacs, however, a delay
+caused by the preparations for the 22.1 release.  In the mean time,
+@file{org-publish.el} can be downloaded from David's site:
+@url{http://dto.freeshell.org/e/org-publish.el}.
+@cindex @file{org-blog.el}
+@item @file{org-blog.el} by David O'Toole
+A blogging plug-in for @file{org-publish.el}.
+@url{http://dto.freeshell.org/notebook/OrgMode.html}.
+@cindex @file{org-blogging.el}
+@item @file{org-blogging.el} by  Bastien Guerry
+Publish Org-mode files as
+blogs. @url{http://www.cognition.ens.fr/~guerry/org-blogging.html}.
+@end table
+
+@node Dynamic blocks,  , Extensions, Extensions and Hacking
+@section Dynamic blocks
+
+Org-mode documents can contain @emph{dynamic blocks}.  These are
+specially marked regions that are updates by some user-written
+function.  A good example for such a block is the clock table inserted
+by the command @kbd{C-c C-x C-r} (@pxref{Clocking work time}).
+
+Dynamic block are enclosed by a BEGIN-END structure that assigns a name
+to the block and can also specify parameters for the function producing
+the content of the block.
+
+@example
+#+BEGIN: myblock :parameter1 value1 :parameter2 value2 .....
+
+#+END:
+@end example
+
+Dynamic blocks are updated with the following commands
+
+@table @kbd
+@kindex C-c C-x C-u
+@item C-c C-x C-u
+Update dynamic block at point.
+@kindex C-u C-c C-x C-u
+@item C-u C-c C-x C-u
+Update all dynamic blocks in the current file.
+@end table
+
+Updating a dynamic block means to remove all the text between BEGIN and
+END, parse the BEGIN line for parameters and then call the specific
+writer function for this block to insert the new content.  For a block
+with name @code{myblock}, the writer function is
+@code{org-dblock-write:myblock} with as only parameter a property list
+with the parameters given in the begin line.  Here is a trivial example
+of a block that keeps track of when the block update function was last
+run:
+
+@example
+#+BEGIN: block-update-time :format "on %m/%d/%Y at %H:%M"
+
+#+END:
+@end example
+
+@noindent
+The corresponding block writer function could look like this:
+
+@lisp
+(defun org-dblock-write:date-and-time (params)
+   (let ((fmt (or (plist-get params :format) "%d. %m. %Y")))
+     (insert "Last block update at: "
+	     (format-time-string fmt (current-time)))))
+@end lisp
+
+If you want to make sure that all dynamic blocks are always up-to-date,
+you could add the function @code{org-update-all-dblocks} to a hook, for
+example @code{before-save-hook}.  @code{org-update-all-dblocks} is
+written in a way that is does nothing in buffers that are not in Org-mode.
+
+
+@node History and Acknowledgments, Index, Extensions and Hacking, Top
+@appendix History and Acknowledgments
 @cindex acknowledgments
+@cindex history
 @cindex thanks
 
-Org-mode was created by @value{AUTHOR}, who still maintains it at the
-Org-mode homepage @uref{http://www.astro.uva.nl/~dominik/Tools/org/}.
-The following people (in alphabetic order) have helped the development
-along with ideas, suggestions and patches.  Many thanks to all of you,
-Org-mode would not be what it is without your input.
+The beginnings of Org-mode go back to 2003.  It was borne out of
+frustration over the user interface of the emacs outline-mode.  All I
+wanted was to make working with an outline tree possible without having
+to remember more than 10 commands just for hiding and unhiding parts of
+the outline tree, and to allow to restructure a tree easily.  Visibility
+cycling and structure editing were originally implemented in the package
+@file{outline-magic.el}, but quickly moved to the more general
+@file{org.el}.  TODO entries, basic time stamps, and table support were
+added next, and highlight the two main goals that Org-mode still has
+today:  To create 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, hundreds of emails to me or on
+@code{emacs-orgmode@@gnu.org} have provided a constant stream of bug
+reports, feedback, new ideas, and sometimes even 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-mode.  The list may not
+be complete, if I have forgotten someone, please accept my apologies and
+let me know.
 
 @itemize @bullet
 @item
@@ -4607,8 +4818,9 @@
 @i{Pavel Chalmoviansky} influenced the agenda treatment of items with
 specified time.
 @item
-@i{Gregory Chenov} patched support for lisp forms into table
-calculations and improved XEmacs compatibility.
+@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 to copy some linking code from Planner.
 @item
@@ -4619,6 +4831,10 @@
 @item
 @i{Nic Ferrier} contributed mailcap and XOXO support.
 @item
+@i{Niels Giessen} had the idea to automatically archive DONE trees.
+@item
+@i{Bastien Guerry} provoded extensive feedback.
+@item
 @i{Kai Grossjohann} pointed out key-binding conflicts caused by
 Org-mode.
 @item
@@ -4656,6 +4872,9 @@
 Linking to VM/BBDB/GNUS was inspired by @i{Tom Shannon}'s
 @file{organizer-mode.el}.
 @item
+@i{Daniel Sinder} came up with the idea of internal archiving my locking
+subtrees.
+@item
 @i{David O'Toole} wrote @file{org-publish.el} and drafted the manual
 chapter about publishing.
 @item
@@ -4684,9 +4903,10 @@
 @i{Piotr Zielinski} wrote @file{org-mouse.el} and showed how to follow
 links with mouse-1.
 @end itemize
- 
-@node Index, Key Index, Miscellaneous, Top
-@chapter Index
+
+
+@node Index, Key Index, History and Acknowledgments, Top
+@unnumbered Index
 
 @printindex cp
 
--- a/src/.gdbinit	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/.gdbinit	Tue Jun 27 15:06:36 2006 +0000
@@ -190,12 +190,8 @@
       printf " ch=[%d,%d]", $it->c, $it->len
     end
   else
-    if ($it->what == IT_IMAGE)
-      printf " IMAGE=%d", $it->image_id
-    else
-      printf " "
-      output $it->what
-    end
+    printf " "
+    output $it->what
   end
   if ($it->method != GET_FROM_BUFFER)
     printf " next="
@@ -203,6 +199,12 @@
     if ($it->method == GET_FROM_STRING)
       printf "[%d]", $it->current.string_pos.charpos
     end
+    if ($it->method == GET_FROM_IMAGE)
+      printf "[%d]", $it->image_id
+    end
+    if ($it->method == GET_FROM_COMPOSITION)
+      printf "[%d,%d,%d]", $it->cmp_id, $it->len, $it->cmp_len
+    end
   end
   printf "\n"
   if ($it->region_beg_charpos >= 0)
@@ -215,6 +217,15 @@
   printf " a+d=%d+%d=%d", $it->ascent, $it->descent, $it->ascent+$it->descent
   printf " max=%d+%d=%d", $it->max_ascent, $it->max_descent, $it->max_ascent+$it->max_descent
   printf "\n"
+  set $i = 0
+  while ($i < $it->sp)
+    set $e = $it->stack[$i]
+    printf "stack[%d]: ", $i
+    output $e->method
+    printf "[%d]", $e->position.charpos
+    printf "\n"
+    set $i = $i + 1
+  end
 end
 document pitx
 Pretty print a display iterator.
@@ -372,6 +383,121 @@
 Pretty print window structure w.
 end
 
+define pgx
+  set $g = $arg0
+  if ($g->type == CHAR_GLYPH)
+    if ($g->u.ch >= ' ' && $g->u.ch < 127)
+      printf "CHAR[%c]", $g->u.ch
+    else
+      printf "CHAR[0x%x]", $g->u.ch
+    end
+  end
+  if ($g->type == COMPOSITE_GLYPH)
+    printf "COMP[%d]", $g->u.cmp_id
+  end
+  if ($g->type == IMAGE_GLYPH)
+    printf "IMAGE[%d]", $g->u.img_id
+  end
+  if ($g->type == STRETCH_GLYPH)
+    printf "STRETCH[%d+%d]", $g->u.stretch.height, $g->u.stretch.ascent
+  end
+  xgettype ($g->object)
+  if ($type == Lisp_String)
+    printf " str=%x[%d]", $g->object, $g->charpos
+  else
+    printf " pos=%d", $g->charpos
+  end
+  printf " w=%d a+d=%d+%d", $g->pixel_width, $g->ascent, $g->descent
+  if ($g->face_id != DEFAULT_FACE_ID)
+    printf " face=%d", $g->face_id
+  end
+  if ($g->voffset)
+    printf " vof=%d", $g->voffset
+  end
+  if ($g->multibyte_p)
+    printf " MB"
+  end
+  if ($g->padding_p)
+    printf " PAD"
+  end
+  if ($g->glyph_not_available_p)
+    printf " N/A"
+  end
+  if ($g->overlaps_vertically_p)
+    printf " OVL"
+  end
+  if ($g->left_box_line_p)
+    printf " ["
+  end
+  if ($g->right_box_line_p)
+    printf " ]"
+  end
+  if ($g->slice.x || $g->slice.y || $g->slice.width || $g->slice.height)
+    printf " slice=%d,%d,%d,%d" ,$g->slice.x, $g->slice.y, $g->slice.width, $g->slice.height
+  end
+  printf "\n"
+end
+document pgx
+Pretty print a glyph structure.
+Takes one argument, a pointer to a glyph structure
+end
+
+define pg
+  set $pgidx = 0
+  pgx glyph
+end
+document pg
+Pretty print glyph structure glyph.
+end
+
+define pgi
+  set $pgidx = $arg0
+  pgx (&glyph[$pgidx])
+end
+document pgi
+Pretty print glyph structure glyph[I].
+Takes one argument, a integer I.
+end
+
+define pgn
+  set $pgidx = $pgidx + 1
+  pgx (&glyph[$pgidx])
+end
+document pgn
+Pretty print next glyph structure.
+end
+
+define pgrowx
+  set $row = $arg0
+  set $area = 0
+  set $xofs = $row->x
+  while ($area < 3)
+    set $used = $row->used[$area]
+    if ($used > 0)
+      set $gl0 = $row->glyphs[$area]
+      set $pgidx = 0
+      printf "%s: %d glyphs\n", ($area == 0 ? "LEFT" : $area == 2 ? "RIGHT" : "TEXT"), $used
+      while ($pgidx < $used)
+	printf "%3d %4d: ", $pgidx, $xofs
+	pgx $gl0[$pgidx]
+	set $xofs = $xofs + $gl0[$pgidx]->pixel_width
+	set $pgidx = $pgidx + 1
+      end
+    end
+    set $area = $area + 1
+  end
+end
+document pgrowx
+Pretty print all glyphs in a row structure.
+Takes one argument, a pointer to a row structure.
+end
+
+define pgrow
+  pgrowx row
+end
+document pgrow
+Pretty print all glyphs in row structure row.
+end
 
 define xtype
   xgettype $
--- a/src/ChangeLog	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/ChangeLog	Tue Jun 27 15:06:36 2006 +0000
@@ -1,3 +1,168 @@
+2006-06-25  Kim F. Storm  <storm@cua.dk>
+
+	* s/gnu-linux.h (SIGNALS_VIA_CHARACTERS): Define for Linux kernel
+	version 2.4 and later.
+
+2006-06-24  Chong Yidong  <cyd@stupidchicken.com>
+
+	* xfns.c (Fx_create_frame): Set font parameter directly instead of
+	using x_default_parameter, since x_get_args clears the parm alist.
+
+2006-06-24  Eli Zaretskii  <eliz@gnu.org>
+
+	* dired.c (directory_files_internal) [WINDOWSNT]: Find files
+	case-insensitively.
+
+2006-06-24  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* lread.c (read_escape): When an unknown Unicode code point is
+	encountered as a string or character escape, signal an error.
+
+2006-06-23  Kim F. Storm  <storm@cua.dk>
+
+	* .gdbinit (pitx): Dump iterator stack.
+
+	* xdisp.c (handle_composition_prop): Push iterator on stack.
+	(set_iterator_to_next): Pop iterator at end of composition.
+
+2006-06-23  Martin Rudalics  <rudalics@gmx.at>
+
+	* fileio.c (Frename_file) [DOS_NT]: Don't try to move directory to
+	itself on DOS_NT platforms, if the old and new names are identical
+	but for the letter-case.
+
+2006-06-21  Kim F. Storm  <storm@cua.dk>
+
+	* dispextern.h (struct it): Add `position' member to iterator stack.
+	Rename `pos' member to `current'.  Rearrange and add comments.
+
+	* xdisp.c (handle_stop): Set it->ignore_overlay_strings_at_pos_p
+	if  we get any overlays.
+	(set_cursor_from_row): Don't clobber `end' if we rescan from
+	start_string.
+	(push_it, pop_it): Save it->position.
+
+2006-06-19  Richard Stallman  <rms@gnu.org>
+
+	* window.c (size_window): New arg FIRST_ONLY.  All callers changed.
+	(adjust_window_trailing_edge): Specially compute FIRST_PARALLEL
+	for the case of a top-level window and the following minibuffer.
+	Don't exit because of no `next' when there is a parent.
+	Use the FIRST_ONLY feature when resizing following windows.
+
+	* syntax.c (init_syntax_once): Give most control chars' syntax Spunct.
+
+2006-06-17  Kim F. Storm  <storm@cua.dk>
+
+	* dispnew.c (update_frame): Check for input pending on entry.
+	(update_window, update_frame_1): Break loop if input is detected.
+
+2006-06-16  Francis Litterio  <flitterio@gmail.com>
+
+	* xterm.c (x_check_expected_move, handle_one_xevent)
+	(x_set_offset, x_check_fullscreen): Extensive changes to make
+	frame positioning deterministic under X.
+
+	* xterm.h (x_output): Added members left_before_move and
+	top_before_move.  Removed members expected_left and expected_top.
+
+2006-06-16  Kim F. Storm  <storm@cua.dk>
+
+	* dispextern.h (struct it): Add union to iterator stack to save
+	image, composition, and stretch specific paramters.
+
+	* xdisp.c (next_overlay_string): Fix assert.
+	(push_it, pop_it): Handle composition and stretch specific values.
+	Only handle it->slice in image (for now).
+	(back_to_previous_visible_line_start): Continue search if newline is
+	part of a compisition.  Simplify.
+	(reseat_1): Set it->object to buffer.
+	(set_iterator_to_next): Set it->object to string or buffer, when
+	setting it->method to GET_FROM_STRING or GET_FROM_BUFFER.
+	(next_element_from_composition): Set it->object to buffer if not
+	from string.
+	(set_cursor_from_row): Only save start of string if not already
+	done to handle multiple strings in a row.
+
+	* .gdbinit (pitx): Show composition parameters.
+	(pgx, pg): New commands to print a glyph structure.
+	(pgi, pgn): New commands to print specific/next glyph.
+	(pgrowx, pgrow): New commands to print all glyphs in a row.
+
+2006-06-16  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* macfns.c (Fx_display_mm_height, Fx_display_mm_width)
+	[MAC_OS_X_VERSION_MAX_ALLOWED >= 1030]: Use CGDisplayScreenSize.
+
+	* macterm.c (do_app_resume, do_app_suspend): Remove functions.
+	(mac_tsm_resume, mac_tsm_suspend) [USE_MAC_TSM]: New functions.
+	(mac_handle_window_event, XTread_socket) [USE_MAC_TSM]: Use them.
+	(Vmac_ts_script_language_on_focus) [USE_MAC_TSM]: New variable.
+	(syms_of_macterm) [USE_MAC_TSM]: Defvar it.
+	(saved_ts_language, saved_ts_component) [USE_MAC_TSM]: New variables.
+	(mac_initialize_display_info) [MAC_OSX]: Use Quartz Display
+	Services functions to get size of main display in pixels.
+
+2006-06-14  Chong Yidong  <cyd@stupidchicken.com>
+
+	* xdisp.c (back_to_previous_visible_line_start): Reset
+	it->continuation_lines_width.
+
+2006-06-14  Richard Stallman  <rms@gnu.org>
+
+	* eval.c (Fdefconst): Mark variable as risky.
+
+	* callproc.c (Fcall_process): Doc fix.
+
+	* window.c (adjust_window_trailing_edge): Don't break out of the loop
+	because there's no next window, if there are parallel windows.
+	Do break out when WINDOW is nil.
+
+2006-06-14  Kim F. Storm  <storm@cua.dk>
+
+	* dispextern.h (IT_STACK_SIZE): New macro specifying size of
+	iterator stack (instead of hardcoded number).  Increase from 2 to
+	4 to make room for propertized overlay strings before and after a
+	display string, image or composition.
+	(struct it): Add image_id and method members to iterator stack.
+
+	* xdisp.c (init_from_display_pos): Don't set it->method and
+	overlay_string_index after pop_it.  Add asserts.
+	(handle_stop): Look for overlay strings around a display string,
+	image, or composition.  Handle properties on those strings.
+	(next_overlay_string): Don't set string, pos or method after pop_it.
+	(get_overlay_strings_1): Split from get_overlay_strings; don't
+	modify it if no overlay strings are found.
+	(get_overlay_strings): Use get_overlay_strings_1.  Always set
+	it->string and it->method.
+	(push_it): Push it->image_id and it->method.  Push it->object
+	instead of it->string if method is GET_FROM_IMAGE.
+	(pop_it): Pop it->image_id and it->method.  Ppo it->object
+	instead of it->string if method is GET_FROM_IMAGE.
+	Reset it->current.string_pos if popped it->string is nil.
+	(reseat_1): Remove comment dated 19 May 2003.  It expressed doubt
+	whether a given change was correct; but the change is correct.
+	Clear it->string_from_display_prop_p.
+	(set_iterator_to_next): Rely on it->method and it->image_id from
+	iterator stack, instead of setting them explicitly after pop_it.
+
+	* dispnew.c (sit_for): Undo 2006-06-01 change.  Instead, a
+	negative time forces redisplay even when input is available.
+	(Fsit_for): Doc fix.
+
+2006-06-13  Kim F. Storm  <storm@cua.dk>
+
+	* dispnew.c: Modify preemptive redisplay to be based on periodic
+	checks for input.
+	(PERIODIC_PREEMPTION_CHECKING): Define to 1 iff EMACS_HAS_USECS.
+	(Vredisplay_preemption_period): New variable.
+	(syms_of_display): DEFVAR_LISP and initialize it.
+	(preemption_period, preemption_next_check): New variables.
+	(update_frame, update_single_window): Initialize them based on
+	Vredisplay_preemption_period if !force_p.
+	(update_window, update_frame_1): Use them to determine when to
+	check for input.
+
 2006-06-03  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* lread.c (read_escape): Provide a Unicode character escape
--- a/src/callproc.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/callproc.c	Tue Jun 27 15:06:36 2006 +0000
@@ -206,6 +206,10 @@
 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
 Remaining arguments are strings passed as command arguments to PROGRAM.
 
+If executable PROGRAM can't be found as an executable, `call-process'
+signals a Lisp error.  `call-process' reports errors in execution of
+the program only through its return and output.
+
 If BUFFER is 0, `call-process' returns immediately with value nil.
 Otherwise it waits for PROGRAM to terminate
 and returns a numeric exit status or a signal description string.
--- a/src/dired.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/dired.c	Tue Jun 27 15:06:36 2006 +0000
@@ -175,9 +175,15 @@
 #ifdef VMS
       bufp = compile_pattern (match, 0,
 			      buffer_defaults.downcase_table, 0, 1);
-#else
+#else  /* !VMS */
+# ifdef WINDOWSNT
+      /* Windows users want case-insensitive wildcards.  */
+      bufp = compile_pattern (match, 0,
+			      buffer_defaults.case_canon_table, 0, 1);
+# else	/* !WINDOWSNT */
       bufp = compile_pattern (match, 0, Qnil, 0, 1);
-#endif
+# endif	 /* !WINDOWSNT */
+#endif	 /* !VMS */
     }
 
   /* Note: ENCODE_FILE and DECODE_FILE can GC because they can run
--- a/src/dispextern.h	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/dispextern.h	Tue Jun 27 15:06:36 2006 +0000
@@ -1814,6 +1814,8 @@
   NUM_IT_METHODS
 };
 
+#define IT_STACK_SIZE 4
+
 struct it
 {
   /* The window in which we iterate over current_buffer (or a string).  */
@@ -1922,22 +1924,47 @@
      from what we previously had.  */
   struct iterator_stack_entry
   {
+    Lisp_Object string;
+    int string_nchars;
+    int end_charpos;
     int stop_charpos;
     int face_id;
-    Lisp_Object string;
-    struct display_pos pos;
-    int end_charpos;
-    int string_nchars;
+
+    /* Save values specific to a given method.  */
+    union {
+      /* method == GET_FROM_IMAGE */
+      struct {
+	Lisp_Object object;
+	struct it_slice slice;
+	int image_id;
+      } image;
+      /* method == GET_FROM_COMPOSITION */
+      struct {
+	Lisp_Object object;
+	int c, len;
+	int cmp_id, cmp_len;
+      } comp;
+      /* method == GET_FROM_STRETCH */
+      struct {
+	Lisp_Object object;
+      } stretch;
+    } u;
+
+    /* current text and display positions.  */
+    struct text_pos position;
+    struct display_pos current;
     enum glyph_row_area area;
+    enum it_method method;
     unsigned multibyte_p : 1;
     unsigned string_from_display_prop_p : 1;
     unsigned display_ellipsis_p : 1;
-    struct it_slice slice;
+
+    /* properties from display property that are reset by another display property. */
     Lisp_Object space_width;
+    Lisp_Object font_height;
     short voffset;
-    Lisp_Object font_height;
   }
-  stack[2];
+  stack[IT_STACK_SIZE];
 
   /* Stack pointer.  */
   int sp;
--- a/src/dispnew.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/dispnew.c	Tue Jun 27 15:06:36 2006 +0000
@@ -192,6 +192,28 @@
 
 int redisplay_dont_pause;
 
+/* Define PERIODIC_PREEMPTION_CHECKING to 1, if micro-second timers
+   are supported, so we can check for input during redisplay at
+   regular intervals.  */
+#ifdef EMACS_HAS_USECS
+#define PERIODIC_PREEMPTION_CHECKING 1
+#else
+#define PERIODIC_PREEMPTION_CHECKING 0
+#endif
+
+#if PERIODIC_PREEMPTION_CHECKING
+
+/* If a number (float), check for user input every N seconds.  */
+
+Lisp_Object Vredisplay_preemption_period;
+
+/* Redisplay preemption timers.  */
+
+static EMACS_TIME preemption_period;
+static EMACS_TIME preemption_next_check;
+
+#endif
+
 /* Nonzero upon entry to redisplay means do not assume anything about
    current contents of actual terminal frame; clear and redraw it.  */
 
@@ -3814,6 +3836,28 @@
   int paused_p;
   struct window *root_window = XWINDOW (f->root_window);
 
+#if PERIODIC_PREEMPTION_CHECKING
+  if (!force_p && NUMBERP (Vredisplay_preemption_period))
+    {
+      EMACS_TIME tm;
+      double p = XFLOATINT (Vredisplay_preemption_period);
+      int sec, usec;
+
+      if (detect_input_pending_ignore_squeezables ())
+	{
+	  paused_p = 1;
+	  goto do_pause;
+	}
+
+      sec = (int) p;
+      usec = (p - sec) * 1000000;
+
+      EMACS_GET_TIME (tm);
+      EMACS_SET_SECS_USECS (preemption_period, sec, usec);
+      EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
+    }
+#endif
+
   if (FRAME_WINDOW_P (f))
     {
       /* We are working on window matrix basis.  All windows whose
@@ -3895,6 +3939,7 @@
 #endif
     }
 
+ do_pause:
   /* Reset flags indicating that a window should be updated.  */
   set_window_update_flags (root_window, 0);
 
@@ -3949,6 +3994,22 @@
       /* Record that this is not a frame-based redisplay.  */
       set_frame_matrix_frame (NULL);
 
+#if PERIODIC_PREEMPTION_CHECKING
+      if (!force_p && NUMBERP (Vredisplay_preemption_period))
+	{
+	  EMACS_TIME tm;
+	  double p = XFLOATINT (Vredisplay_preemption_period);
+	  int sec, usec;
+
+	  sec = (int) p;
+	  usec = (p - sec) * 1000000;
+
+	  EMACS_GET_TIME (tm);
+	  EMACS_SET_SECS_USECS (preemption_period, sec, usec);
+	  EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
+	}
+#endif
+
       /* Update W.  */
       update_begin (f);
       update_window (w, force_p);
@@ -4108,7 +4169,9 @@
 {
   struct glyph_matrix *desired_matrix = w->desired_matrix;
   int paused_p;
+#if !PERIODIC_PREEMPTION_CHECKING
   int preempt_count = baud_rate / 2400 + 1;
+#endif
   extern int input_pending;
   extern Lisp_Object do_mouse_tracking;
   struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
@@ -4120,8 +4183,13 @@
   /* Check pending input the first time so that we can quickly return.  */
   if (redisplay_dont_pause)
     force_p = 1;
-  else
+#if PERIODIC_PREEMPTION_CHECKING
+  else if (NILP (Vredisplay_preemption_period))
+    force_p = 1;
+#else
+  else if (!force_p)
     detect_input_pending_ignore_squeezables ();
+#endif
 
   /* If forced to complete the update, or if no input is pending, do
      the update.  */
@@ -4193,9 +4261,23 @@
 	       detect_input_pending.  If it's done too often,
 	       scrolling large windows with repeated scroll-up
 	       commands will too quickly pause redisplay.  */
+#if PERIODIC_PREEMPTION_CHECKING
+	    if (!force_p)
+	      {
+		EMACS_TIME tm, dif;
+		EMACS_GET_TIME (tm);
+		EMACS_SUB_TIME (dif, preemption_next_check, tm);
+		if (EMACS_TIME_NEG_P (dif))
+		  {
+		    EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
+		    if (detect_input_pending_ignore_squeezables ())
+		      break;
+		  }
+	      }
+#else
 	    if (!force_p && ++n_updated % preempt_count == 0)
 	      detect_input_pending_ignore_squeezables ();
-
+#endif
 	    changed_p |= update_window_line (w, vpos,
 					     &mouse_face_overwritten_p);
 
@@ -5151,11 +5233,16 @@
 
   if (redisplay_dont_pause)
     force_p = 1;
+#if PERIODIC_PREEMPTION_CHECKING
+  else if (NILP (Vredisplay_preemption_period))
+    force_p = 1;
+#else
   else if (!force_p && detect_input_pending_ignore_squeezables ())
     {
       pause = 1;
       goto do_pause;
     }
+#endif
 
   /* If we cannot insert/delete lines, it's no use trying it.  */
   if (!FRAME_LINE_INS_DEL_OK (f))
@@ -5206,8 +5293,23 @@
 		}
 	    }
 
-	  if ((i - 1) % preempt_count == 0)
+#if PERIODIC_PREEMPTION_CHECKING
+	  if (!force_p)
+	    {
+	      EMACS_TIME tm, dif;
+	      EMACS_GET_TIME (tm);
+	      EMACS_SUB_TIME (dif, preemption_next_check, tm);
+	      if (EMACS_TIME_NEG_P (dif))
+		{
+		  EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
+		  if (detect_input_pending_ignore_squeezables ())
+		    break;
+		}
+	    }
+#else
+	  if (!force_p && (i - 1) % preempt_count == 0)
 	    detect_input_pending_ignore_squeezables ();
+#endif
 
 	  update_frame_line (f, i);
 	}
@@ -6434,15 +6536,22 @@
 sit_for (sec, usec, reading, display, initial_display)
      int sec, usec, reading, display, initial_display;
 {
+  int preempt = (sec >= 0) || (sec == 0 && usec >= 0);
+
   swallow_events (display);
 
-  if ((detect_input_pending_run_timers (display)
-       && !redisplay_dont_pause)
+  if ((detect_input_pending_run_timers (display) && preempt)
       || !NILP (Vexecuting_kbd_macro))
     return Qnil;
 
   if (initial_display)
-    redisplay_preserve_echo_area (2);
+    {
+      int count = SPECPDL_INDEX ();
+      if (!preempt)
+	specbind (Qredisplay_dont_pause, Qt);
+      redisplay_preserve_echo_area (2);
+      unbind_to (count, Qnil);
+    }
 
   if (sec == 0 && usec == 0)
     return Qt;
@@ -6468,8 +6577,7 @@
 if input is available before it starts.
 Value is t if waited the full time with no input arriving.
 
-Redisplay will occur even when input is available if you bind
-`redisplay-dont-pause' to a non-nil value.
+Redisplay will occur even when input is available if SECONDS is negative.
 
 An obsolete but still supported form is
 \(sit-for SECONDS &optional MILLISECONDS NODISP)
@@ -7000,7 +7108,14 @@
 	       doc: /* *Non-nil means update isn't paused when input is detected.  */);
   redisplay_dont_pause = 0;
 
-  /* Initialize `window-system', unless init_display already decided it.  */
+#if PERIODIC_PREEMPTION_CHECKING
+  DEFVAR_LISP ("redisplay-preemption-period", &Vredisplay_preemption_period,
+	       doc: /* *The period in seconds between checking for input during redisplay.
+If input is detected, redisplay is pre-empted, and the input is processed.
+If nil, never pre-empt redisplay.  */);
+  Vredisplay_preemption_period = make_float (0.10);
+#endif
+
 #ifdef CANNOT_DUMP
   if (noninteractive)
 #endif
--- a/src/eval.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/eval.c	Tue Jun 27 15:06:36 2006 +0000
@@ -195,9 +195,10 @@
 
 Lisp_Object Vmacro_declaration_function;
 
+extern Lisp_Object Qrisky_local_variable;
 
 static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
-
+
 void
 init_eval_once ()
 {
@@ -895,6 +896,7 @@
 	tem = Fpurecopy (tem);
       Fput (sym, Qvariable_documentation, tem);
     }
+  Fput (sym, Qrisky_local_variable, Qt);
   LOADHIST_ATTACH (sym);
   return sym;
 }
--- a/src/fileio.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/fileio.c	Tue Jun 27 15:06:36 2006 +0000
@@ -2752,7 +2752,13 @@
   CHECK_STRING (newname);
   file = Fexpand_file_name (file, Qnil);
 
-  if (!NILP (Ffile_directory_p (newname)))
+  if ((!NILP (Ffile_directory_p (newname)))
+#ifdef DOS_NT
+      /* If the file names are identical but for the case,
+	 don't attempt to move directory to itself. */
+      && (NILP (Fstring_equal (Fdowncase (file), Fdowncase (newname))))
+#endif
+      )
     newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
   else
     newname = Fexpand_file_name (newname, Qnil);
--- a/src/lread.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/lread.c	Tue Jun 27 15:06:36 2006 +0000
@@ -1949,7 +1949,7 @@
 	while (++count <= unicode_hex_count)
 	  {
 	    c = READCHAR;
-	    /* isdigit(), isalpha() may be locale-specific, which we don't
+	    /* isdigit and isalpha may be locale-specific, which we don't
 	       want. */
 	    if      (c >= '0' && c <= '9')  i = (i << 4) + (c - '0');
 	    else if (c >= 'a' && c <= 'f')  i = (i << 4) + (c - 'a') + 10;
@@ -1962,21 +1962,16 @@
 	  }
 
 	GCPRO1 (readcharfun);
-	lisp_char = call2(intern("decode-char"), intern("ucs"),
-			  make_number(i));
+	lisp_char = call2 (intern ("decode-char"), intern ("ucs"),
+			  make_number (i));
 	UNGCPRO;
 
-	if (EQ(Qnil, lisp_char))
+	if (NILP (lisp_char))
 	  {
-	    /* This is ugly and horrible and trashes the user's data.  */
-	    XSETFASTINT (i, MAKE_CHAR (charset_katakana_jisx0201,
-				       34 + 128, 46 + 128));
-            return i;
+	    error ("Unsupported Unicode code point: U+%x", (unsigned)i);
 	  }
-	else
-	  {
-	    return XFASTINT (lisp_char);
-	  }
+
+	return XFASTINT (lisp_char);
       }
 
     default:
--- a/src/macfns.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/macfns.c	Tue Jun 27 15:06:36 2006 +0000
@@ -3070,11 +3070,20 @@
      (display)
      Lisp_Object display;
 {
-  /* MAC_TODO: this is an approximation, and only of the main display */
-
   struct mac_display_info *dpyinfo = check_x_display_info (display);
-
+  /* Only of the main display.  */
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+  CGSize size;
+
+  BLOCK_INPUT;
+  size = CGDisplayScreenSize (kCGDirectMainDisplay);
+  UNBLOCK_INPUT;
+
+  return make_number ((int) (size.height + .5f));
+#else
+  /* This is an approximation.  */
   return make_number ((int) (dpyinfo->height * 25.4 / dpyinfo->resy));
+#endif
 }
 
 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
@@ -3085,11 +3094,20 @@
      (display)
      Lisp_Object display;
 {
-  /* MAC_TODO: this is an approximation, and only of the main display */
-
   struct mac_display_info *dpyinfo = check_x_display_info (display);
-
+  /* Only of the main display.  */
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+  CGSize size;
+
+  BLOCK_INPUT;
+  size = CGDisplayScreenSize (kCGDirectMainDisplay);
+  UNBLOCK_INPUT;
+
+  return make_number ((int) (size.width + .5f));
+#else
+  /* This is an approximation.  */
   return make_number ((int) (dpyinfo->width * 25.4 / dpyinfo->resx));
+#endif
 }
 
 DEFUN ("x-display-backing-store", Fx_display_backing_store,
--- a/src/macterm.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/macterm.c	Tue Jun 27 15:06:36 2006 +0000
@@ -8512,6 +8512,9 @@
 static Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event;
 static Lisp_Object Vmac_ts_active_input_overlay;
 extern Lisp_Object Qbefore_string;
+static Lisp_Object Vmac_ts_script_language_on_focus;
+static ScriptLanguageRecord saved_ts_language;
+static Component saved_ts_component;
 #endif
 #endif
 extern int mac_ready_for_apple_events;
@@ -8861,22 +8864,84 @@
   return 0;
 }
 
-static void
-do_app_resume ()
-{
 #if USE_MAC_TSM
-  ActivateTSMDocument (tsm_document_id);
-#endif
-}
-
-static void
-do_app_suspend ()
-{
-#if USE_MAC_TSM
-  DeactivateTSMDocument (tsm_document_id);
-#endif
-}
-
+static OSStatus
+mac_tsm_resume ()
+{
+  OSStatus err;
+  ScriptLanguageRecord slrec, *slptr = NULL;
+
+  err = ActivateTSMDocument (tsm_document_id);
+
+  if (err == noErr)
+    {
+      if (EQ (Vmac_ts_script_language_on_focus, Qt))
+	slptr = &saved_ts_language;
+      else if (CONSP (Vmac_ts_script_language_on_focus)
+	       && INTEGERP (XCAR (Vmac_ts_script_language_on_focus))
+	       && INTEGERP (XCDR (Vmac_ts_script_language_on_focus)))
+	{
+	  slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus));
+	  slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus));
+	  slptr = &slrec;
+	}
+    }
+
+  if (slptr)
+    {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+      err = SetDefaultInputMethodOfClass (saved_ts_component, slptr,
+					  kKeyboardInputMethodClass);
+#else
+      err = SetDefaultInputMethod (saved_ts_component, slptr);
+#endif
+      if (err == noErr)
+	err = SetTextServiceLanguage (slptr);
+
+      /* Seems to be needed on Mac OS X 10.2.  */
+      if (err == noErr)
+	KeyScript (slptr->fScript | smKeyForceKeyScriptMask);
+    }
+
+  return err;
+}
+
+static OSStatus
+mac_tsm_suspend ()
+{
+  OSStatus err;
+  ScriptLanguageRecord slrec, *slptr = NULL;
+
+  if (EQ (Vmac_ts_script_language_on_focus, Qt))
+    {
+      err = GetTextServiceLanguage (&saved_ts_language);
+      if (err == noErr)
+	slptr = &saved_ts_language;
+    }
+  else if (CONSP (Vmac_ts_script_language_on_focus)
+	   && INTEGERP (XCAR (Vmac_ts_script_language_on_focus))
+	   && INTEGERP (XCDR (Vmac_ts_script_language_on_focus)))
+    {
+      slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus));
+      slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus));
+      slptr = &slrec;
+    }
+
+  if (slptr)
+    {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+      GetDefaultInputMethodOfClass (&saved_ts_component, slptr,
+				    kKeyboardInputMethodClass);
+#else
+      GetDefaultInputMethod (&saved_ts_component, slptr);
+#endif
+    }
+
+  err = DeactivateTSMDocument (tsm_document_id);
+
+  return err;
+}
+#endif
 
 static void
 do_apple_menu (SInt16 menu_item)
@@ -9330,12 +9395,12 @@
 #if USE_MAC_TSM
     case kEventWindowFocusAcquired:
       result = CallNextEventHandler (next_handler, event);
-      err = ActivateTSMDocument (tsm_document_id);
+      err = mac_tsm_resume ();
       return err == noErr ? noErr : result;
 
     case kEventWindowFocusRelinquish:
       result = CallNextEventHandler (next_handler, event);
-      err = DeactivateTSMDocument (tsm_document_id);
+      err = mac_tsm_suspend ();
       return err == noErr ? noErr : result;
 #endif
     }
@@ -10394,10 +10459,12 @@
 	  switch ((er.message >> 24) & 0x000000FF)
 	    {
 	    case suspendResumeMessage:
-	      if ((er.message & resumeFlag) == 1)
-		do_app_resume ();
+#if USE_MAC_TSM
+	      if (er.message & resumeFlag)
+		mac_tsm_resume ();
 	      else
-		do_app_suspend ();
+		mac_tsm_suspend ();
+#endif
 	      break;
 
 	    case mouseMovedMessage:
@@ -10960,7 +11027,6 @@
 mac_initialize_display_info ()
 {
   struct mac_display_info *dpyinfo = &one_mac_display_info;
-  GDHandle main_device_handle;
 
   bzero (dpyinfo, sizeof (*dpyinfo));
 
@@ -10976,37 +11042,29 @@
   strcpy (dpyinfo->mac_id_name, "Mac Display");
 #endif
 
-  main_device_handle = LMGetMainDevice();
-
   dpyinfo->reference_count = 0;
   dpyinfo->resx = 72.0;
   dpyinfo->resy = 72.0;
-  dpyinfo->color_p = TestDeviceAttribute (main_device_handle, gdDevType);
 #ifdef MAC_OSX
   /* HasDepth returns true if it is possible to have a 32 bit display,
-     but this may not be what is actually used.  Mac OSX can do better.
-     CGMainDisplayID is only available on OSX 10.2 and higher, but the
-     header for CGGetActiveDisplayList says that the first display returned
-     is the active one, so we use that.  */
+     but this may not be what is actually used.  Mac OSX can do better.  */
+  dpyinfo->color_p = 1;
+  dpyinfo->n_planes = CGDisplayBitsPerPixel (kCGDirectMainDisplay);
+  dpyinfo->height = CGDisplayPixelsHigh (kCGDirectMainDisplay);
+  dpyinfo->width = CGDisplayPixelsWide (kCGDirectMainDisplay);
+#else
   {
-    CGDirectDisplayID disp_id[1];
-    CGDisplayCount disp_count;
-    CGDisplayErr error_code;
-
-    error_code = CGGetActiveDisplayList (1, disp_id, &disp_count);
-    if (error_code != 0)
-      error ("No display found, CGGetActiveDisplayList error %d", error_code);
-
-    dpyinfo->n_planes = CGDisplayBitsPerPixel (disp_id[0]);
+    GDHandle main_device_handle = LMGetMainDevice();
+
+    dpyinfo->color_p = TestDeviceAttribute (main_device_handle, gdDevType);
+    for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1)
+      if (HasDepth (main_device_handle, dpyinfo->n_planes,
+		    gdDevType, dpyinfo->color_p))
+	break;
+    dpyinfo->height = (**main_device_handle).gdRect.bottom;
+    dpyinfo->width = (**main_device_handle).gdRect.right;
   }
-#else
-  for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1)
-    if (HasDepth (main_device_handle, dpyinfo->n_planes,
-		  gdDevType, dpyinfo->color_p))
-      break;
-#endif
-  dpyinfo->height = (**main_device_handle).gdRect.bottom;
-  dpyinfo->width = (**main_device_handle).gdRect.right;
+#endif
   dpyinfo->grabbed = 0;
   dpyinfo->root_window = NULL;
   dpyinfo->image_cache = make_image_cache ();
@@ -11558,6 +11616,15 @@
   DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay,
     doc: /* Overlay used to display Mac TSM active input area.  */);
   Vmac_ts_active_input_overlay = Qnil;
+
+  DEFVAR_LISP ("mac-ts-script-language-on-focus", &Vmac_ts_script_language_on_focus,
+    doc: /* *How to change Mac TSM script/language when a frame gets focus.
+If the value is t, the input script and language are restored to those
+used in the last focus frame.  If the value is a pair of integers, the
+input script and language codes, which are defined in the Script
+Manager, are set to its car and cdr parts, respectively.  Otherwise,
+Emacs doesn't set them and thus follows the system default behavior.  */);
+  Vmac_ts_script_language_on_focus = Qnil;
 #endif
 }
 
--- a/src/s/gnu-linux.h	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/s/gnu-linux.h	Tue Jun 27 15:06:36 2006 +0000
@@ -52,6 +52,9 @@
 #if LINUX_VERSION_CODE >= 0x20000
 #define LINUX_MAP_SHARED_DOES_WORK
 #endif /* LINUX_VERSION_CODE >= 0x20000 */
+#if LINUX_VERSION_CODE >= 0x20400
+#define LINUX_SIGNALS_VIA_CHARACTERS_DOES_WORK
+#endif /* LINUX_VERSION_CODE >= 0x20400 */
 #endif /* HAVE_LINUX_VERSION_H */
 #endif /* emacs */
 #endif /* NOT_C_CODE */
@@ -247,9 +250,9 @@
 #define C_DEBUG_SWITCH
 #endif
 
-/* Let's try this out, just in case.
-   Nah.  Rik Faith <faith@cs.unc.edu> says it doesn't work well.  */
-/* #define SIGNALS_VIA_CHARACTERS */
+#ifdef LINUX_SIGNALS_VIA_CHARACTERS_DOES_WORK
+#define SIGNALS_VIA_CHARACTERS
+#endif
 
 /* Rob Malouf <malouf@csli.stanford.edu> says:
    SYSV IPC is standard a standard part of Linux since version 0.99pl10,
--- a/src/syntax.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/syntax.c	Tue Jun 27 15:06:36 2006 +0000
@@ -3122,6 +3122,20 @@
 
   Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp);
 
+  /* Control characters should not be whitespace.  */
+  temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct];
+  for (i = 0; i <= ' ' - 1; i++)
+    SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);
+  SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 0177, temp);
+
+  /* Except that a few really are whitespace.  */
+  temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace];
+  SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ' ', temp);
+  SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\t', temp);
+  SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\n', temp);
+  SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 015, temp);
+  SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 014, temp);
+
   temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword];
   for (i = 'a'; i <= 'z'; i++)
     SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);
--- a/src/window.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/window.c	Tue Jun 27 15:06:36 2006 +0000
@@ -65,7 +65,7 @@
 static void window_scroll_line_based P_ ((Lisp_Object, int, int, int));
 static int window_min_size_1 P_ ((struct window *, int));
 static int window_min_size P_ ((struct window *, int, int, int *));
-static void size_window P_ ((Lisp_Object, int, int, int));
+static void size_window P_ ((Lisp_Object, int, int, int, int, int));
 static int freeze_window_start P_ ((struct window *, void *));
 static int window_fixed_size_p P_ ((struct window *, int, int));
 static void enlarge_window P_ ((Lisp_Object, int, int));
@@ -2828,17 +2828,23 @@
 
 /* Set WINDOW's height or width to SIZE.  WIDTH_P non-zero means set
    WINDOW's width.  Resize WINDOW's children, if any, so that they
-   keep their proportionate size relative to WINDOW.  Propagate
-   WINDOW's top or left edge position to children.  Delete windows
-   that become too small unless NODELETE_P is non-zero.
+   keep their proportionate size relative to WINDOW.
+
+   If FIRST_ONLY is 1, change only the first of WINDOW's children when
+   they are in series.  If LAST_ONLY is 1, change only the last of
+   WINDOW's children when they are in series.
+
+   Propagate WINDOW's top or left edge position to children.  Delete
+   windows that become too small unless NODELETE_P is non-zero.
 
    If NODELETE_P is 2, that means we do delete windows that are
    too small, even if they were too small before!  */
 
 static void
-size_window (window, size, width_p, nodelete_p)
+size_window (window, size, width_p, nodelete_p, first_only, last_only)
      Lisp_Object window;
      int size, width_p, nodelete_p;
+     int first_only, last_only;
 {
   struct window *w = XWINDOW (window);
   struct window *c;
@@ -2913,6 +2919,7 @@
 
   if (!NILP (*sideward))
     {
+      /* We have a chain of parallel siblings whose size should all change.  */
       for (child = *sideward; !NILP (child); child = c->next)
 	{
 	  c = XWINDOW (child);
@@ -2920,8 +2927,44 @@
 	    c->left_col = w->left_col;
 	  else
 	    c->top_line = w->top_line;
-	  size_window (child, size, width_p, nodelete_p);
+	  size_window (child, size, width_p, nodelete_p,
+		       first_only, last_only);
+	}
+    }
+  else if (!NILP (*forward) && last_only)
+    {
+      /* Change the last in a series of siblings.  */
+      Lisp_Object last_child;
+      int child_size;
+
+      for (child = *forward; !NILP (child); child = c->next)
+	{
+	  c = XWINDOW (child);
+	  last_child = child;
 	}
+
+      child_size = XINT (width_p ? c->total_cols : c->total_lines);
+      size_window (last_child,
+		   size - old_size + child_size,
+		   width_p, nodelete_p, first_only, last_only);
+    }
+  else if (!NILP (*forward) && first_only)
+    {
+      /* Change the first in a series of siblings.  */
+      int child_size;
+
+      child = *forward;
+      c = XWINDOW (child);
+
+      if (width_p)
+	c->left_col = w->left_col;
+      else
+	c->top_line = w->top_line;
+
+      child_size = XINT (width_p ? c->total_cols : c->total_lines);
+      size_window (child,
+		   size - old_size + child_size,
+		   width_p, nodelete_p, first_only, last_only);
     }
   else if (!NILP (*forward))
     {
@@ -2930,7 +2973,7 @@
       int last_pos, first_pos, nchildren, total;
       int *new_sizes = NULL;
 
-      /* Determine the fixed-size portion of the this window, and the
+      /* Determine the fixed-size portion of this window, and the
 	 number of child windows.  */
       fixed_size = nchildren = nfixed = total = 0;
       for (child = *forward; !NILP (child); child = c->next, ++nchildren)
@@ -2993,7 +3036,7 @@
 	  /* Set new height.  Note that size_window also propagates
 	     edge positions to children, so it's not a no-op if we
 	     didn't change the child's size.  */
-	  size_window (child, new_size, width_p, 1);
+	  size_window (child, new_size, width_p, 1, first_only, last_only);
 
 	  /* Remember the bottom/right edge position of this child; it
 	     will be used to set the top/left edge of the next child.  */
@@ -3012,7 +3055,7 @@
 	    int child_size;
 	    c = XWINDOW (child);
 	    child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
-	    size_window (child, child_size, width_p, 2);
+	    size_window (child, child_size, width_p, 2, first_only, last_only);
 	  }
     }
 }
@@ -3028,7 +3071,7 @@
      int height;
      int nodelete;
 {
-  size_window (window, height, 0, nodelete);
+  size_window (window, height, 0, nodelete, 0, 0);
 }
 
 
@@ -3043,7 +3086,7 @@
      int width;
      int nodelete;
 {
-  size_window (window, width, 1, nodelete);
+  size_window (window, width, 1, nodelete, 0, 0);
 }
 
 /* Change window heights in windows rooted in WINDOW by N lines.  */
@@ -4281,21 +4324,31 @@
     {
       Lisp_Object first_parallel = Qnil;
 
+      if (NILP (window))
+	{
+	  /* This happens if WINDOW on the previous iteration was
+	     at top level of the window tree.  */
+	  Fset_window_configuration (old_config);
+	  error ("Specified window edge is fixed");
+	}
+
       p = XWINDOW (window);
       parent = p->parent;
 
-      if (NILP (XWINDOW (window)->next))
-	{
-	  Fset_window_configuration (old_config);
-	  error ("No other window following this one");
-	}
-
       /* See if this level has windows in parallel in the specified
 	 direction.  If so, set FIRST_PARALLEL to the first one.  */
       if (horiz_flag)
 	{
 	  if (! NILP (parent) && !NILP (XWINDOW (parent)->vchild))
 	    first_parallel = XWINDOW (parent)->vchild;
+	  else if (NILP (parent) && !NILP (p->next))
+	    {
+	      /* Handle the vertical chain of main window and minibuffer
+		 which has no parent.  */
+	      first_parallel = window;
+	      while (! NILP (XWINDOW (first_parallel)->prev))
+		first_parallel = XWINDOW (first_parallel)->prev;
+	    }
 	}
       else
 	{
@@ -4303,6 +4356,16 @@
 	    first_parallel = XWINDOW (parent)->hchild;
 	}
 
+      /* If this level's succession is in the desired dimension,
+	 and this window is the last one, and there is no higher level,
+	 its trailing edge is fixed.  */
+      if (NILP (XWINDOW (window)->next) && NILP (first_parallel)
+	  && NILP (parent))
+	{
+	  Fset_window_configuration (old_config);
+	  error ("Specified window edge is fixed");
+	}
+
       /* Don't make this window too small.  */
       if (XINT (CURSIZE (window)) + delta
 	  < (horiz_flag ? window_min_width : window_min_height))
@@ -4326,7 +4389,7 @@
 	 we will fail and report an error, above.)  */
       if (NILP (first_parallel))
 	{
-	  if (!NILP (XWINDOW (window)->next))
+	  if (!NILP (p->next))
 	    {
               /* This may happen for the minibuffer.  In that case
                  the window_deletion_count check below does not work.  */
@@ -4339,7 +4402,7 @@
 	      XSETINT (CURBEG (p->next),
 		       XINT (CURBEG (p->next)) + delta);
 	      size_window (p->next, XINT (CURSIZE (p->next)) - delta,
-			   horiz_flag, 0);
+			   horiz_flag, 0, 1, 0);
 	      break;
 	    }
 	}
@@ -4351,7 +4414,7 @@
 	     child = XWINDOW (child)->next)
 	  if (! EQ (child, window))
 	    size_window (child, XINT (CURSIZE (child)) + delta,
-			 horiz_flag, 0);
+			 horiz_flag, 0, 0, 1);
 
       window = parent;
     }
--- a/src/xdisp.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/xdisp.c	Tue Jun 27 15:06:36 2006 +0000
@@ -903,6 +903,7 @@
 static void compute_line_metrics P_ ((struct it *));
 static void run_redisplay_end_trigger_hook P_ ((struct it *));
 static int get_overlay_strings P_ ((struct it *, int));
+static int get_overlay_strings_1 P_ ((struct it *, int, int));
 static void next_overlay_string P_ ((struct it *));
 static void reseat P_ ((struct it *, struct text_pos, int));
 static void reseat_1 P_ ((struct it *, struct text_pos, int));
@@ -2896,8 +2897,8 @@
 	 also ``processed'' overlay strings at ZV.  */
       while (it->sp)
 	pop_it (it);
-      it->current.overlay_string_index = -1;
-      it->method = GET_FROM_BUFFER;
+      xassert (it->current.overlay_string_index == -1);
+      xassert (it->method == GET_FROM_BUFFER);
       if (CHARPOS (pos->pos) == ZV)
 	it->overlay_strings_at_end_processed_p = 1;
     }
@@ -3008,7 +3009,19 @@
 	  if (handled == HANDLED_RECOMPUTE_PROPS)
 	    break;
 	  else if (handled == HANDLED_RETURN)
-	    return;
+	    {
+	      /* We still want to show before and after strings from
+		 overlays even if the actual buffer text is replaced.  */
+	      if (!handle_overlay_change_p || it->sp > 1)
+		return;
+	      if (!get_overlay_strings_1 (it, 0, 0))
+		return;
+	      it->ignore_overlay_strings_at_pos_p = 1;
+	      it->string_from_display_prop_p = 0;
+	      handle_overlay_change_p = 0;
+	      handled = HANDLED_RECOMPUTE_PROPS;
+	      break;
+	    }
 	  else if (handled == HANDLED_OVERLAY_STRING_CONSUMED)
 	    handle_overlay_change_p = 0;
 	}
@@ -4460,6 +4473,8 @@
 		}
 	      return HANDLED_RECOMPUTE_PROPS;
 	    }
+
+	  push_it (it);
 	  it->method = GET_FROM_COMPOSITION;
 	  it->cmp_id = id;
 	  it->cmp_len = COMPOSITION_LENGTH (prop);
@@ -4529,13 +4544,14 @@
       int display_ellipsis_p = it->stack[it->sp - 1].display_ellipsis_p;
 
       pop_it (it);
-      xassert (it->stop_charpos >= BEGV
-	       && it->stop_charpos <= it->end_charpos);
-      it->string = Qnil;
+      xassert (it->sp > 0
+	       || it->method == GET_FROM_COMPOSITION
+	       || (NILP (it->string)
+		   && it->method == GET_FROM_BUFFER
+		   && it->stop_charpos >= BEGV
+		   && it->stop_charpos <= it->end_charpos));
       it->current.overlay_string_index = -1;
-      SET_TEXT_POS (it->current.string_pos, -1, -1);
       it->n_overlay_strings = 0;
-      it->method = GET_FROM_BUFFER;
 
       /* If we're at the end of the buffer, record that we have
 	 processed the overlay strings there already, so that
@@ -4791,7 +4807,7 @@
    least one overlay string was found.  */
 
 static int
-get_overlay_strings (it, charpos)
+get_overlay_strings_1 (it, charpos, compute_stop_p)
      struct it *it;
      int charpos;
 {
@@ -4813,12 +4829,13 @@
       /* Make sure we know settings in current_buffer, so that we can
 	 restore meaningful values when we're done with the overlay
 	 strings.  */
-      compute_stop_pos (it);
+      if (compute_stop_p)
+	compute_stop_pos (it);
       xassert (it->face_id >= 0);
 
       /* Save IT's settings.  They are restored after all overlay
 	 strings have been processed.  */
-      xassert (it->sp == 0);
+      xassert (!compute_stop_p || it->sp == 0);
       push_it (it);
 
       /* Set up IT to deliver display elements from the first overlay
@@ -4830,13 +4847,22 @@
       it->end_charpos = SCHARS (it->string);
       it->multibyte_p = STRING_MULTIBYTE (it->string);
       it->method = GET_FROM_STRING;
-    }
-  else
-    {
-      it->string = Qnil;
-      it->current.overlay_string_index = -1;
-      it->method = GET_FROM_BUFFER;
-    }
+      return 1;
+    }
+
+  it->current.overlay_string_index = -1;
+  return 0;
+}
+
+static int
+get_overlay_strings (it, charpos)
+     struct it *it;
+     int charpos;
+{
+  it->string = Qnil;
+  it->method = GET_FROM_BUFFER;
+
+  (void) get_overlay_strings_1 (it, charpos, 1);
 
   CHECK_IT (it);
 
@@ -4861,19 +4887,38 @@
 {
   struct iterator_stack_entry *p;
 
-  xassert (it->sp < 2);
+  xassert (it->sp < IT_STACK_SIZE);
   p = it->stack + it->sp;
 
   p->stop_charpos = it->stop_charpos;
   xassert (it->face_id >= 0);
   p->face_id = it->face_id;
   p->string = it->string;
-  p->pos = it->current;
+  p->method = it->method;
+  switch (p->method)
+    {
+    case GET_FROM_IMAGE:
+      p->u.image.object = it->object;
+      p->u.image.image_id = it->image_id;
+      p->u.image.slice = it->slice;
+      break;
+    case GET_FROM_COMPOSITION:
+      p->u.comp.object = it->object;
+      p->u.comp.c = it->c;
+      p->u.comp.len = it->len;
+      p->u.comp.cmp_id = it->cmp_id;
+      p->u.comp.cmp_len = it->cmp_len;
+      break;
+    case GET_FROM_STRETCH:
+      p->u.stretch.object = it->object;
+      break;
+    }
+  p->position = it->position;
+  p->current = it->current;
   p->end_charpos = it->end_charpos;
   p->string_nchars = it->string_nchars;
   p->area = it->area;
   p->multibyte_p = it->multibyte_p;
-  p->slice = it->slice;
   p->space_width = it->space_width;
   p->font_height = it->font_height;
   p->voffset = it->voffset;
@@ -4900,13 +4945,34 @@
   p = it->stack + it->sp;
   it->stop_charpos = p->stop_charpos;
   it->face_id = p->face_id;
+  it->current = p->current;
+  it->position = p->position;
   it->string = p->string;
-  it->current = p->pos;
+  if (NILP (it->string))
+    SET_TEXT_POS (it->current.string_pos, -1, -1);
+  it->method = p->method;
+  switch (it->method)
+    {
+    case GET_FROM_IMAGE:
+      it->image_id = p->u.image.image_id;
+      it->object = p->u.image.object;
+      it->slice = p->u.image.slice;
+      break;
+    case GET_FROM_COMPOSITION:
+      it->object = p->u.comp.object;
+      it->c = p->u.comp.c;
+      it->len = p->u.comp.len;
+      it->cmp_id = p->u.comp.cmp_id;
+      it->cmp_len = p->u.comp.cmp_len;
+      break;
+    case GET_FROM_STRETCH:
+      it->object = p->u.comp.object;
+      break;
+    }
   it->end_charpos = p->end_charpos;
   it->string_nchars = p->string_nchars;
   it->area = p->area;
   it->multibyte_p = p->multibyte_p;
-  it->slice = p->slice;
   it->space_width = p->space_width;
   it->font_height = p->font_height;
   it->voffset = p->voffset;
@@ -5038,6 +5104,7 @@
   while (IT_CHARPOS (*it) > BEGV)
     {
       back_to_previous_line_start (it);
+
       if (IT_CHARPOS (*it) <= BEGV)
 	break;
 
@@ -5057,36 +5124,46 @@
 	  continue;
       }
 
-      /* If newline has a display property that replaces the newline with something
-	 else (image or text), find start of overlay or interval and continue search
-	 from that point.  */
-      if (IT_CHARPOS (*it) > BEGV)
-	{
-	  struct it it2 = *it;
-	  int pos;
-	  int beg, end;
-	  Lisp_Object val, overlay;
-
-	  pos = --IT_CHARPOS (it2);
-	  --IT_BYTEPOS (it2);
-	  it2.sp = 0;
-	  if (handle_display_prop (&it2) == HANDLED_RETURN
-	      && !NILP (val = get_char_property_and_overlay
-			(make_number (pos), Qdisplay, Qnil, &overlay))
-	      && (OVERLAYP (overlay)
-		  ? (beg = OVERLAY_POSITION (OVERLAY_START (overlay)))
-		  : get_property_and_range (pos, Qdisplay, &val, &beg, &end, Qnil)))
-	    {
-	      if (beg < BEGV)
-		beg = BEGV;
-	      IT_CHARPOS (*it) = beg;
-	      IT_BYTEPOS (*it) = buf_charpos_to_bytepos (current_buffer, beg);
-	      continue;
-	    }
-	}
-
-      break;
-    }
+      if (IT_CHARPOS (*it) <= BEGV)
+	break;
+
+      {
+	struct it it2;
+	int pos;
+	int beg, end;
+	Lisp_Object val, overlay;
+
+	/* If newline is part of a composition, continue from start of composition */
+	if (find_composition (IT_CHARPOS (*it), -1, &beg, &end, &val, Qnil)
+	    && beg < IT_CHARPOS (*it))
+	  goto replaced;
+
+	/* If newline is replaced by a display property, find start of overlay
+	   or interval and continue search from that point.  */
+	it2 = *it;
+	pos = --IT_CHARPOS (it2);
+	--IT_BYTEPOS (it2);
+	it2.sp = 0;
+	if (handle_display_prop (&it2) == HANDLED_RETURN
+	    && !NILP (val = get_char_property_and_overlay
+		      (make_number (pos), Qdisplay, Qnil, &overlay))
+	    && (OVERLAYP (overlay)
+		? (beg = OVERLAY_POSITION (OVERLAY_START (overlay)))
+		: get_property_and_range (pos, Qdisplay, &val, &beg, &end, Qnil)))
+	  goto replaced;
+
+	/* Newline is not replaced by anything -- so we are done.  */
+	break;
+
+      replaced:
+	if (beg < BEGV)
+	  beg = BEGV;
+	IT_CHARPOS (*it) = beg;
+	IT_BYTEPOS (*it) = buf_charpos_to_bytepos (current_buffer, beg);
+      }
+    }
+
+  it->continuation_lines_width = 0;
 
   xassert (IT_CHARPOS (*it) >= BEGV);
   xassert (IT_CHARPOS (*it) == BEGV
@@ -5219,15 +5296,11 @@
   IT_STRING_BYTEPOS (*it) = -1;
   it->string = Qnil;
   it->method = GET_FROM_BUFFER;
-  /* RMS: I added this to fix a bug in move_it_vertically_backward
-     where it->area continued to relate to the starting point
-     for the backward motion.  Bug report from
-     Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
-     However, I am not sure whether reseat still does the right thing
-     in general after this change.  */
+  it->object = it->w->buffer;
   it->area = TEXT_AREA;
   it->multibyte_p = !NILP (current_buffer->enable_multibyte_characters);
   it->sp = 0;
+  it->string_from_display_prop_p = 0;
   it->face_before_selective_p = 0;
 
   if (set_stop_p)
@@ -5706,18 +5779,20 @@
 
     case GET_FROM_COMPOSITION:
       xassert (it->cmp_id >= 0 && it->cmp_id < n_compositions);
-      if (STRINGP (it->string))
+      xassert (it->sp > 0);
+      pop_it (it);
+      if (it->method == GET_FROM_STRING)
 	{
 	  IT_STRING_BYTEPOS (*it) += it->len;
 	  IT_STRING_CHARPOS (*it) += it->cmp_len;
-	  it->method = GET_FROM_STRING;
+	  it->object = it->string;
 	  goto consider_string_end;
 	}
-      else
+      else if (it->method == GET_FROM_BUFFER)
 	{
 	  IT_BYTEPOS (*it) += it->len;
 	  IT_CHARPOS (*it) += it->cmp_len;
-	  it->method = GET_FROM_BUFFER;
+	  it->object = it->w->buffer;
 	}
       break;
 
@@ -5747,7 +5822,10 @@
 	  else if (STRINGP (it->string))
 	    it->method = GET_FROM_STRING;
 	  else
-	    it->method = GET_FROM_BUFFER;
+	    {
+	      it->method = GET_FROM_BUFFER;
+	      it->object = it->w->buffer;
+	    }
 
 	  it->dpvec = NULL;
 	  it->current.dpvec_index = -1;
@@ -5795,9 +5873,8 @@
 	      && it->sp > 0)
 	    {
 	      pop_it (it);
-	      if (STRINGP (it->string))
+	      if (it->method == GET_FROM_STRING)
 		goto consider_string_end;
-	      it->method = GET_FROM_BUFFER;
 	    }
 	}
       break;
@@ -5809,13 +5886,8 @@
          if the `display' property takes up the whole string.  */
       xassert (it->sp > 0);
       pop_it (it);
-      it->image_id = 0;
-      if (STRINGP (it->string))
-	{
-	  it->method = GET_FROM_STRING;
-	  goto consider_string_end;
-	}
-      it->method = GET_FROM_BUFFER;
+      if (it->method == GET_FROM_STRING)
+	goto consider_string_end;
       break;
 
     default:
@@ -6038,6 +6110,7 @@
 	 setting face_before_selective_p.  */
       it->saved_face_id = it->face_id;
       it->method = GET_FROM_BUFFER;
+      it->object = it->w->buffer;
       reseat_at_next_visible_line_start (it, 1);
       it->face_before_selective_p = 1;
     }
@@ -6226,6 +6299,8 @@
 		  : it->current.pos);
   if (STRINGP (it->string))
     it->object = it->string;
+  else
+    it->object = it->w->buffer;
   return 1;
 }
 
@@ -11687,9 +11762,12 @@
 	}
       else
 	{
-	  string_before_pos = last_pos;
-	  string_start = glyph;
-	  string_start_x = x;
+	  if (string_start == NULL)
+	    {
+	      string_before_pos = last_pos;
+	      string_start = glyph;
+	      string_start_x = x;
+	    }
 	  /* Skip all glyphs from string.  */
 	  do
 	    {
@@ -11747,25 +11825,25 @@
 	 glyph on point by scanning from string_start again.  */
       Lisp_Object limit;
       Lisp_Object string;
+      struct glyph *stop = glyph;
       int pos;
 
       limit = make_number (pt_old + 1);
-      end = glyph;
       glyph = string_start;
       x = string_start_x;
       string = glyph->object;
       pos = string_buffer_position (w, string, string_before_pos);
       /* If STRING is from overlay, LAST_POS == 0.  We skip such glyphs
 	 because we always put cursor after overlay strings.  */
-      while (pos == 0 && glyph < end)
+      while (pos == 0 && glyph < stop)
 	{
 	  string = glyph->object;
-	  SKIP_GLYPHS (glyph, end, x, EQ (glyph->object, string));
-	  if (glyph < end)
+	  SKIP_GLYPHS (glyph, stop, x, EQ (glyph->object, string));
+	  if (glyph < stop)
 	    pos = string_buffer_position (w, glyph->object, string_before_pos);
 	}
 
-      while (glyph < end)
+      while (glyph < stop)
 	{
 	  pos = XINT (Fnext_single_char_property_change
 		      (make_number (pos), Qdisplay, Qnil, limit));
@@ -11773,13 +11851,13 @@
 	    break;
 	  /* Skip glyphs from the same string.  */
 	  string = glyph->object;
-	  SKIP_GLYPHS (glyph, end, x, EQ (glyph->object, string));
+	  SKIP_GLYPHS (glyph, stop, x, EQ (glyph->object, string));
 	  /* Skip glyphs from an overlay.  */
-	  while (glyph < end
+	  while (glyph < stop
 		 && ! string_buffer_position (w, glyph->object, pos))
 	    {
 	      string = glyph->object;
-	      SKIP_GLYPHS (glyph, end, x, EQ (glyph->object, string));
+	      SKIP_GLYPHS (glyph, stop, x, EQ (glyph->object, string));
 	    }
 	}
 
--- a/src/xfns.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/xfns.c	Tue Jun 27 15:06:36 2006 +0000
@@ -3207,8 +3207,7 @@
     if (! STRINGP (font))
       font = build_string ("fixed");
 
-    x_default_parameter (f, parms, Qfont, font,
-			 "font", "Font", RES_TYPE_STRING);
+    x_set_frame_parameters (f, Fcons (Fcons (Qfont, font), Qnil));
   }
 
 #ifdef USE_LUCID
--- a/src/xterm.c	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/xterm.c	Tue Jun 27 15:06:36 2006 +0000
@@ -359,7 +359,8 @@
 					    Lisp_Object *, Lisp_Object *,
 					    unsigned long *));
 static void x_check_fullscreen P_ ((struct frame *));
-static void x_check_expected_move P_ ((struct frame *));
+static void x_check_expected_move P_ ((struct frame *, int, int));
+static void x_sync_with_move P_ ((struct frame *, int, int, int));
 static int handle_one_xevent P_ ((struct x_display_info *, XEvent *,
 				  int *, struct input_event *));
 static SIGTYPE x_connection_closed P_ ((Display *, char *));
@@ -6686,11 +6687,8 @@
               && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f)))
 #endif
             {
-	      /* What we have now is the position of Emacs's own window.
-		 Convert that to the position of the window manager window.  */
 	      x_real_positions (f, &f->left_pos, &f->top_pos);
 
-	      x_check_expected_move (f);
 	      if (f->want_fullscreen & FULLSCREEN_WAIT)
 		f->want_fullscreen &= ~(FULLSCREEN_WAIT|FULLSCREEN_BOTH);
             }
@@ -8260,8 +8258,11 @@
 {
   int modified_top, modified_left;
 
-  if (change_gravity > 0)
-    {
+  if (change_gravity != 0)
+    {
+      FRAME_X_OUTPUT (f)->left_before_move = f->left_pos;
+      FRAME_X_OUTPUT (f)->top_before_move = f->top_pos;
+
       f->top_pos = yoff;
       f->left_pos = xoff;
       f->size_hint_flags &= ~ (XNegative | YNegative);
@@ -8279,7 +8280,7 @@
   modified_left = f->left_pos;
   modified_top = f->top_pos;
 
-  if (FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_A)
+  if (change_gravity != 0 && FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_A)
     {
       /* Some WMs (twm, wmaker at least) has an offset that is smaller
          than the WM decorations.  So we use the calculated offset instead
@@ -8291,13 +8292,26 @@
   XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
                modified_left, modified_top);
 
-  if (FRAME_VISIBLE_P (f)
-      && FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_UNKNOWN)
-    {
-      FRAME_X_OUTPUT (f)->check_expected_move = 1;
-      FRAME_X_OUTPUT (f)->expected_top = f->top_pos;
-      FRAME_X_OUTPUT (f)->expected_left = f->left_pos;
-    }
+  x_sync_with_move (f, f->left_pos, f->top_pos,
+                    FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_UNKNOWN
+                    ? 1 : 0);
+
+  /* change_gravity is non-zero when this function is called from Lisp to
+     programmatically move a frame.  In that case, we call
+     x_check_expected_move to discover if we have a "Type A" or "Type B"
+     window manager, and, for a "Type A" window manager, adjust the position
+     of the frame.
+
+     We call x_check_expected_move if a programmatic move occurred, and
+     either the window manager type (A/B) is unknown or it is Type A but we
+     need to compute the top/left offset adjustment for this frame.  */
+
+  if (change_gravity != 0 &&
+      (FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_UNKNOWN
+       || (FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_A
+           && (FRAME_X_OUTPUT (f)->move_offset_left == 0
+               && FRAME_X_OUTPUT (f)->move_offset_top == 0))))
+    x_check_expected_move (f, modified_left, modified_top);
 
   UNBLOCK_INPUT;
 }
@@ -8332,37 +8346,96 @@
     }
 }
 
-/* If frame parameters are set after the frame is mapped, we need to move
-   the window.
-   Some window managers moves the window to the right position, some
-   moves the outer window manager window to the specified position.
-   Here we check that we are in the right spot.  If not, make a second
-   move, assuming we are dealing with the second kind of window manager. */
+/* This function is called by x_set_offset to determine whether the window
+   manager interfered with the positioning of the frame.  Type A window
+   managers position the surrounding window manager decorations a small
+   amount above and left of the user-supplied position.  Type B window
+   managers position the surrounding window manager decorations at the
+   user-specified position.  If we detect a Type A window manager, we
+   compensate by moving the window right and down by the proper amount.  */
+
 static void
-x_check_expected_move (f)
+x_check_expected_move (f, expected_left, expected_top)
      struct frame *f;
-{
-  if (FRAME_X_OUTPUT (f)->check_expected_move)
-  {
-    int expect_top = FRAME_X_OUTPUT (f)->expected_top;
-    int expect_left = FRAME_X_OUTPUT (f)->expected_left;
-
-    if (expect_top != f->top_pos || expect_left != f->left_pos)
+     int expected_left;
+     int expected_top;
+{
+  int count = 0, current_left = 0, current_top = 0;
+
+  /* x_real_positions returns the left and top offsets of the outermost
+     window manager window around the frame.  */
+
+  x_real_positions (f, &current_left, &current_top);
+
+  if (current_left != expected_left || current_top != expected_top)
       {
+      /* It's a "Type A" window manager. */
+
+      int adjusted_left;
+      int adjusted_top;
+
         FRAME_X_DISPLAY_INFO (f)->wm_type = X_WMTYPE_A;
-        FRAME_X_OUTPUT (f)->move_offset_left = expect_left - f->left_pos;
-        FRAME_X_OUTPUT (f)->move_offset_top = expect_top - f->top_pos;
-
-        f->left_pos = expect_left;
-        f->top_pos = expect_top;
-        x_set_offset (f, expect_left, expect_top, 0);
+      FRAME_X_OUTPUT (f)->move_offset_left = expected_left - current_left;
+      FRAME_X_OUTPUT (f)->move_offset_top = expected_top - current_top;
+
+      /* Now fix the mispositioned frame's location. */
+
+      adjusted_left = expected_left + FRAME_X_OUTPUT (f)->move_offset_left;
+      adjusted_top = expected_top + FRAME_X_OUTPUT (f)->move_offset_top;
+
+      XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                   adjusted_left, adjusted_top);
+
+      x_sync_with_move (f, expected_left, expected_top, 0);
       }
-    else if (FRAME_X_DISPLAY_INFO (f)->wm_type == X_WMTYPE_UNKNOWN)
+  else
+    /* It's a "Type B" window manager.  We don't have to adjust the
+       frame's position. */
+
       FRAME_X_DISPLAY_INFO (f)->wm_type = X_WMTYPE_B;
-
-    /* Just do this once */
-    FRAME_X_OUTPUT (f)->check_expected_move = 0;
+}
+
+
+/* Wait for XGetGeometry to return up-to-date position information for a
+   recently-moved frame.  Call this immediately after calling XMoveWindow.
+   If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
+   frame has been moved to, so we use a fuzzy position comparison instead
+   of an exact comparison.  */
+
+static void
+x_sync_with_move (f, left, top, fuzzy)
+    struct frame *f;
+    int left, top, fuzzy;
+{
+  int count = 0;
+
+  while (count++ < 50)
+    {
+      int current_left = 0, current_top = 0;
+
+      /* In theory, this call to XSync only needs to happen once, but in
+         practice, it doesn't seem to work, hence the need for the surrounding
+         loop.  */
+
+      XSync (FRAME_X_DISPLAY (f), False);
+      x_real_positions (f, &current_left, &current_top);
+
+      if (fuzzy)
+        {
+          /* The left fuzz-factor is 10 pixels.  The top fuzz-factor is 40
+             pixels.  */
+
+          if (abs (current_left - left) <= 10 && abs (current_top - top) <= 40)
+            return;
   }
+      else if (current_left == left && current_top == top)
+        return;
+    }
+
+  /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
+     will then return up-to-date position info. */
+
+  wait_reading_process_output (0, 500000, 0, 0, Qnil, NULL, 0);
 }
 
 
--- a/src/xterm.h	Mon Jun 12 07:27:12 2006 +0000
+++ b/src/xterm.h	Tue Jun 27 15:06:36 2006 +0000
@@ -639,18 +639,14 @@
      FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
   int focus_state;
 
-  /* The latest move we made to FRAME_OUTER_WINDOW.  Saved so we can
-     compensate for type A WMs (see wm_type in dpyinfo above).  */
-  int expected_top;
-  int expected_left;
-
   /* The offset we need to add to compensate for type A WMs.  */
   int move_offset_top;
   int move_offset_left;
 
-  /* Nonzero if we have made a move and needs to check if the WM placed us
-     at the right position.  */
-  int check_expected_move;
+  /* The frame's left/top offsets before we call XMoveWindow.  See
+     x_check_expected_move.  */
+  int left_before_move;
+  int top_before_move;
 };
 
 #define No_Cursor (None)