changeset 83478:856efda75a1b

Merged from emacs@sv.gnu.org Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-111 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-112 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-113 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-114 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-115 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-518
author Karoly Lorentey <lorentey@elte.hu>
date Thu, 23 Feb 2006 03:17:52 +0000
parents 3a9507e5aa39 (current diff) 3f5044e40e3e (diff)
children b0c0309b2727
files lisp/ChangeLog lisp/files.el lisp/isearch.el lisp/mh-e/ChangeLog lisp/progmodes/gdb-ui.el man/ChangeLog src/fringe.c src/indent.c src/macterm.c src/window.c
diffstat 37 files changed, 1096 insertions(+), 404 deletions(-) [+]
line wrap: on
line diff
--- a/etc/ChangeLog	Thu Feb 23 02:59:27 2006 +0000
+++ b/etc/ChangeLog	Thu Feb 23 03:17:52 2006 +0000
@@ -1,3 +1,8 @@
+2006-02-22  Carsten Dominik  <dominik@science.uva.nl>
+
+	* orgcard.tex: (section{Links}): Rewritten to cover the modified
+	link system.
+
 2006-02-18  Bill Wohler  <wohler@newt.com>
 
 	Release MH-E version 7.92.
--- a/etc/orgcard.tex	Thu Feb 23 02:59:27 2006 +0000
+++ b/etc/orgcard.tex	Thu Feb 23 03:17:52 2006 +0000
@@ -1,11 +1,11 @@
-% Reference Card for Org Mode 4.04
+% Reference Card for Org Mode 4.05
 %
 %**start of header
 \newcount\columnsperpage
 
 % This file can be printed with 1, 2, or 3 columns per page (see below).
 % At the moment this card works quite nicely in 3 column format and
-% currently takes 2 full pages.  It is thus suited to producing one
+% currently takes 2 full pages.  It is thus suited to producing one 
 % double-side page when printed.
 
 % There are a couple of tweaks in the format of this card which make it work
@@ -18,8 +18,7 @@
 
 \columnsperpage=3
 
-% Copyright (C) 2005, 2006 Free Software Foundation, Inc.
-% Copyright (c) 2004 Philip Rooke
+% Copyright (c) 2004 Philip Rooke, 2005, 2006 Free Software Foundation
 
 % GNU Emacs is free software; you can redistribute it and/or modify
 % it under the terms of the GNU General Public License as published by
@@ -59,7 +58,7 @@
 % Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
 % for their many good ideas.
 
-\def\orgversionnumber{4.04}
+\def\orgversionnumber{4.05}
 \def\year{2006}
 
 \def\shortcopyrightnotice{\vskip 1ex plus 2 fill
@@ -89,7 +88,7 @@
 
 \def\ncolumns{\the\columnsperpage}
 
-\message{[\ncolumns\space
+\message{[\ncolumns\space 
   column\if 1\ncolumns\else s\fi\space per page]}
 
 \def\scaledmag#1{ scaled \magstep #1}
@@ -174,7 +173,7 @@
   \def\bye{\par\vfill\supereject
     \if a\abc \else\null\vfill\eject\fi
     \if a\abc \else\null\vfill\eject\fi
-    \end}
+    \end}  
 \fi
 
 % we won't be using math mode much, so redefine some of the characters
@@ -356,18 +355,8 @@
 \key{raise priority of current item}{S-UP$^4$}
 \key{lower priority of current item}{S-DOWN$^4$}
 
-\vskip 1mm
-per-file TODO workflow states: add line(s) like$^3$:
-\vskip -1mm
-\beginexample%
-\#+SEQ_TODO: TODO PROCRASTINATE BLUFF DONE
-\endexample
-\vskip -1mm
-per-file TODO keywords: add line(s) like$^3$:
-\vskip -1mm
-\beginexample%
-\#+TYP_TODO: Phil home work DONE
-\endexample
+\key{\kbd{\#+SEQ_TODO: TODO TRY BLUFF DONE}}{\rm todo workflow}
+\key{\kbd{\#+TYP_TODO: Phil home work DONE}}{\rm todo types}
 
 \section{Timestamps}
 
@@ -398,21 +387,26 @@
 \key{insert a link (TAB completes stored links)}{C-c C-l}
 \key{insert file link with file name completion}{C-u C-c C-l}
 
-\key{open link at point}{C-c C-o}
-\key{open file links in emacs}{C-u C-c C-o}
-\key{open link at point}{mouse-2}
-\key{open file links in emacs}{mouse-3}
+\key{open file links in emacs (\kbd{C-u} : in emacs)}{C-c C-o}
+\key{open link at point (3: in emacs)}{mouse-2/3}
+%\key{open file links in emacs}{mouse-3}
+\key{record a position in mark ring}{C-c \%}
+\key{jump back to last followed link(s)}{C-c \&}
+
+{\bf Internal Links}
 
-{\bf Link types}
+\key{\kbd{<<My Target>>}}{\rm target}
+\key{\kbd{<<<My Target>>>}}{\rm radio target$^3$}
+\key{\kbd{[[*this text]]}}{\rm find headline}
+\metax{\kbd{[[this text]]}}{\rm find target or text in buffer}
 
-\key{\kbd{*CamelCaseWord}}{\rm search headline}
-\key{\kbd{CamelCaseWord}}{\rm search in buffer}
+{\bf External Links}
+
 \key{\kbd{<file:/home/dominik/img/mars.jpg>}}{\rm file, absolute}
 \key{\kbd{<file:papers/last.pdf>}}{\rm file, relative}
-\key{\kbd{<file:~/code/main.c:255>}}{\rm file with line nr.}
-\key{\kbd{<file:projects.org::*CamelCaseWord>}}{\rm search headline}
-\key{\kbd{<file:projects.org::find me>}}{\rm search string}
-\key{\kbd{<file:projects.org::/regexp/>}}{\rm search regexp}
+\key{\kbd{<file:projects.org::*that text>}}{\rm find headline}
+\key{\kbd{<file:projects.org::find me>}}{\rm find tgt/string}
+\key{\kbd{<file:projects.org::/regexp/>}}{\rm regexp search}
 \key{\kbd{<http://www.astro.uva.nl/~dominik>}}{\rm on the web}
 \key{\kbd{<mailto:adent@galaxy.net>}}{\rm EMail address}
 \key{\kbd{<news:comp.emacs>}}{\rm Usenet group}
@@ -420,15 +414,9 @@
 \key{\kbd{<shell:ls *.org>}}{\rm shell command}
 \key{\kbd{<gnus:group>}}{\rm GNUS group}
 \key{\kbd{<gnus:group\#id>}}{\rm GNUS message}
-\key{\kbd{<vm:folder>}}{\rm VM folder}
-\key{\kbd{<vm:folder\#id>}}{\rm VM message}
-% FIXME: would like to get this back in.
+\key{\kbd{<vm|wl|mhe|rmail:folder>}}{\rm Mail folder}
+\key{\kbd{<vm|wl|mhe|rmail:folder\#id>}}{\rm Mail message}
 %\key{\kbd{<vm://myself@some.where.org/folder\#id>}}{\rm VM remote}
-Wanderlust \kbd{<wl:...>} and RMAIL \kbd{<rmail:...>} like VM
-%\key{\kbd{<wl:folder>}}{\rm Wanderlust f.}
-%\key{\kbd{<wl:folder\#id>}}{\rm Wanderlust m.}
-%\key{\kbd{<rmail:folder>}}{\rm RMAIL folder}
-%\key{\kbd{<rmail:folder\#id>}}{\rm RMAIL msg}
 
 \section{Tables}
 
@@ -711,7 +699,7 @@
 \key{next heading}{DOWN}
 \key{previous heading}{UP}
 
-Insert the note with one of the following:
+Insert the note with one of the following: 
 
 \key{as sublevel of heading at cursor}{RET}
 \key{right here (cursor not on heading)}{RET}
@@ -741,8 +729,8 @@
 $^2$ This is only a suggestion for a binding of this command.  Choose
 you own key as shown under INSTALLATION.
 
-$^3$ After changing a \kbd{\#+KEYWORD} line, press \kbd{C-c C-c} with
-the cursor still in a line to make Org-mode notice the change.
+$^3$ After changing a \kbd{\#+KEYWORD} or \kbd{<<<target>>>} line,
+press \kbd{C-c C-c} with the cursor still in the line to update.
 
 $^4$ Keybinding affected by {\tt org-CUA-compatibility}.
 
@@ -753,7 +741,7 @@
 
 % arch-tag: 139f6750-5cfc-49ca-92b5-237fe5795290
 
-%%% Local Variables:
+%%% Local Variables: 
 %%% mode: latex
 %%% TeX-master: t
-%%% End:
+%%% End: 
--- a/lisp/ChangeLog	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/ChangeLog	Thu Feb 23 03:17:52 2006 +0000
@@ -1,3 +1,100 @@
+2006-02-23  Nick Roberts  <nickrob@snap.net.nz>
+
+	* progmodes/gdb-ui.el (gdb-signalled): New variable and function.
+	(gdb-debug-log-ring): Rename from gdb-debug-log and make a ring.
+	(gdb-send, gdb-send-item, gud-gdba-marker-filter): Use it.
+	(gdb-debug-log-length): Customize it's length.
+	(gud-watch, gdb-var-create-handler): Display function::var format
+	but don't use to create variable object.
+	(gdb-var-create-handler): Use message-box in place of message.
+	(gdb-stopped): Call gdb-exited if signalled.
+
+2006-02-22  Carsten Dominik  <dominik@science.uva.nl>
+
+	* textmodes/reftex.el (reftex-locate-file): Removed duplicate
+	function.
+
+	* textmodes/reftex-vars.el: (reftex-try-all-extensions): New
+	option.
+
+	* textmodes/reftex.el: (reftex-locate-file): Search all extensions
+	if `reftex-try-all-extensions' is set.
+
+	* textmodes/org.el: (org-mark-ring-previous, org-mark-ring-set):
+	New commands.
+	(org-mark-ring): New variable.
+	(org-mark-ring-length): New option.
+	(org-open-at-point, org-goto, org-open-file): Push old position
+	onto the mark ring.
+	(org-add-hook): New function.
+	(org-export-table-remove-special-lines): New option.
+	(org-skip-comments, org-format-org-table-html): Respect new option
+	`org-export-table-remove-special-lines'.
+	(org-open-file): Allow special command configuration for directory
+	link.
+	(org-file-apps): Fixed bugs in customize type, added setting for
+	directories.
+	(org-activate-tags, org-format-agenda-item, org-complete)
+	(org-get-tags-at, org-scan-tags, org-make-tags-matcher)
+	(org-get-tags, org-get-buffer-tags, org-open-at-point)
+	(org-link-search, org-make-org-heading-search-string)
+	(org-make-org-heading-camel): Allow @ and 0-9 as tags characters.
+	(org-radio-targets, org-file-link-context-use-camel-case)
+	(org-activate-camels): New options.
+	(org-update-radio-target-regexp, org-all-targets)
+	(org-make-target-link-regexp, org-activate-target-links): New
+	functions.
+	(org-make-org-heading-search-string): New function.
+	(org-store-link, org-insert-link): Use new option
+	`org-file-link-context-use-camel-case'.
+	(org-activate-camels): Use new option `org-activate-camels'.
+	(org-link-regexp): Added mhe prefix.
+	(org-open-at-point,org-store-link): Support for mhe links.
+	(org-mhe-get-message-id, org-mhe-get-message-folder)
+	(org-mhe-get-header,org-follow-mhe-link): New functions.
+	(org-remove-angle-brackets, org-add-angle-brackets): New
+	functions.
+	(org-bracked-link-regexp): New constant.
+	(org-read-date): Fixed bug that was rejecting all typed dates.
+	(org-link-search): Make hierarchy above visible after a match.
+	(org-follow-bbdb-link): Inhibit electric mode for BBDB.
+	(org-store-link): Fixed bug with link creation when cursor is in
+	an empty line.
+	(org-open-at-point): Fixed bug with matching a link.  Fixed buggy
+	argument sequence in call to `org-view-tags'.
+	(org-compile-prefix-format): Set `org-prefix-has-tag'.
+	(org-prefix-has-tag): New variable.
+	(org-format-agenda-item): Remove tags from headline if
+	appropriate.
+	(org-agenda-remove-tags-when-in-prefix): New option.
+
+2006-02-21  Michael Kifer  <kifer@cs.stonybrook.edu>
+	
+	* ediff-diff.el (ediff-setup-diff-regions, ediff-setup-diff-regions3):
+	fix the regular expressions.
+	
+2006-02-21  Richard M. Stallman  <rms@gnu.org>
+
+	* progmodes/sh-script.el (sh-mode): Set shell type based on file name
+	if there's no other specific basis.
+
+	* emacs-lisp/unsafep.el (unsafep): Don't treat &rest or &optional
+	as variables at all.
+	(unsafep-variable): Rename arg; doc fix.
+
+	* abbrevlist.el (list-one-abbrev-table): Add autoload.
+
+	* calendar/appt.el (diary-selective-display): Add defvar.
+
+	* sort.el (sort-columns): Use Posix arg syntax for `sort'.
+
+	* isearch.el (search-whitespace-regexp): Fix custom type.
+
+	* help.el (describe-key-briefly): Compute interactive args
+	in same was as before previous change.
+
+	* files.el (enable-local-variables): Doc fix.
+
 2006-02-21  Kim F. Storm  <storm@cua.dk>
 
 	* fringe.el: Cleanup as file is now pre-loaded.
--- a/lisp/abbrevlist.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/abbrevlist.el	Thu Feb 23 03:17:52 2006 +0000
@@ -28,6 +28,7 @@
 
 ;;; Code:
 
+;;;###autoload
 (defun list-one-abbrev-table (abbrev-table output-buffer)
   "Display alphabetical listing of ABBREV-TABLE in buffer OUTPUT-BUFFER."
   (with-output-to-temp-buffer output-buffer
--- a/lisp/calendar/appt.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/calendar/appt.el	Thu Feb 23 03:17:52 2006 +0000
@@ -78,6 +78,7 @@
 ;; Make sure calendar is loaded when we compile this.
 (require 'calendar)
 
+(defvar diary-selective-display)
 
 ;;;###autoload
 (defcustom appt-issue-message t
--- a/lisp/ediff-diff.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/ediff-diff.el	Thu Feb 23 03:17:52 2006 +0000
@@ -251,7 +251,8 @@
 ;; ediff-setup-diff-regions3, which takes 4 arguments.
 (defun ediff-setup-diff-regions (file-A file-B file-C)
   ;; looking for '-c', '-i', or a 'c', 'i' among clustered non-long options
-  (if (string-match "^-[ci]\\| -[ci]\\|-[^- ]+[ci]" ediff-diff-options)
+  (if (string-match "^-[ci]\\| -[ci]\\|\\(^\\| \\)-[^- ]+[ci]"
+		    ediff-diff-options)
       (error "Options `-c' and `-i' are not allowed in `ediff-diff-options'"))
 
   ;; create, if it doesn't exist
@@ -1215,7 +1216,7 @@
 ;; or it is the ancestor file.
 (defun ediff-setup-diff-regions3 (file-A file-B file-C)
   ;; looking for '-i' or a 'i' among clustered non-long options
-  (if (string-match "^-i\\| -i\\|-[^- ]+i" ediff-diff-options)
+  (if (string-match "^-i\\| -i\\|\\(^\\| \\)-[^- ]+i" ediff-diff-options)
       (error "Option `-i' is not allowed in `ediff-diff3-options'"))
 
   (or (ediff-buffer-live-p ediff-diff-buffer)
--- a/lisp/emacs-lisp/unsafep.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/emacs-lisp/unsafep.el	Thu Feb 23 03:17:52 2006 +0000
@@ -148,10 +148,10 @@
        ((eq fun 'lambda)
 	;;First arg is temporary bindings
 	(mapc #'(lambda (x)
-		  (let ((y (unsafep-variable x t)))
-		    (if y (throw 'unsafep y)))
 		  (or (memq x '(&optional &rest))
-		      (push x unsafep-vars)))
+		      (let ((y (unsafep-variable x t)))
+			(if y (throw 'unsafep y))
+			(push x unsafep-vars))))
 	      (cadr form))
 	(unsafep-progn (cddr form)))
        ((eq fun 'let)
@@ -247,17 +247,16 @@
     (if reason (throw 'unsafep reason))
     sym))
 
-(defun unsafep-variable (sym global-okay)
-  "Return nil if SYM is safe as a let-binding sym
-\(because it already has a temporary binding or is a non-risky buffer-local
-variable), otherwise a reason why it is unsafe.  Failing to be locally bound
-is okay if GLOBAL-OKAY is non-nil."
+(defun unsafep-variable (sym to-bind)
+  "Return nil if SYM is safe to set or bind, or a reason why not.
+If TO-BIND is nil, check whether SYM is safe to set.
+If TO-BIND is t, check whether SYM is safe to bind."
   (cond
    ((not (symbolp sym))
     `(variable ,sym))
    ((risky-local-variable-p sym nil)
     `(risky-local-variable ,sym))
-   ((not (or global-okay
+   ((not (or to-bind
 	     (memq sym unsafep-vars)
 	     (local-variable-p sym)))
     `(global-variable ,sym))))
--- a/lisp/files.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/files.el	Thu Feb 23 03:17:52 2006 +0000
@@ -447,10 +447,11 @@
 The value can be t, nil or something else.
 
 A value of t means file local variables specifications are obeyed
-if all the specified variables are safe.  If any variables are
-not safe, you will be queries before setting them.
-A value of nil means file local variables are ignored.
-Any other value means to always query.
+if all the specified variable values are safe; if any values are
+not safe, Emacs queries you, once, whether to set them all.
+
+A value of nil means always ignore the file local variables.
+Any other value means always query you once whether to set them all.
 
 This variable also controls use of major modes specified in
 a -*- line.
--- a/lisp/help.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/help.el	Thu Feb 23 03:17:52 2006 +0000
@@ -579,12 +579,8 @@
 	   (setq key (read-key-sequence "Describe key (or click or menu item): "))
 	   (list
 	    key
-	    (prefix-numeric-value current-prefix-arg)
-	    ;; If KEY is a down-event, read the corresponding up-event
-	    ;; and use it as the third argument.
-	    (if (and (consp key) (symbolp (car key))
-		     (memq 'down (cdr (get (car key) 'event-symbol-elements))))
-		(read-event))))
+	    (if current-prefix-arg (prefix-numeric-value current-prefix-arg))
+	    1))
        ;; Put yank-menu back as it was, if we changed it.
        (when saved-yank-menu
 	 (setq yank-menu (copy-sequence saved-yank-menu))
--- a/lisp/isearch.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/isearch.el	Thu Feb 23 03:17:52 2006 +0000
@@ -116,8 +116,11 @@
 this, unless it is inside of a regexp construct such as [...] or *, + or ?.
 You might want to use something like \"[ \\t\\r\\n]+\" instead.
 In the Customization buffer, that is `[' followed by a space,
-a tab, a carriage return (control-M), a newline, and `]+'."
-  :type 'regexp
+a tab, a carriage return (control-M), a newline, and `]+'.
+
+When this is nil, each space you type matches literally, against one space."
+  :type '(choice (const :tag "Find Spaces Literally" nil)
+		 regexp)
   :group 'isearch)
 
 (defcustom search-invisible 'open
--- a/lisp/mh-e/ChangeLog	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/mh-e/ChangeLog	Thu Feb 23 03:17:52 2006 +0000
@@ -1,3 +1,8 @@
+2006-02-21  Eric Ding  <ericding@alum.mit.edu>
+
+	* mh-e.el (mh-invisible-header-fields-internal): Added entry
+	"X-Sasl-enc:"
+
 2006-02-20  Eric Ding  <ericding@alum.mit.edu>
 
 	* mh-e.el (mh-invisible-header-fields-internal): Added entries
--- a/lisp/mh-e/mh-e.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/mh-e/mh-e.el	Thu Feb 23 03:17:52 2006 +0000
@@ -2395,7 +2395,8 @@
     "X-SBPass:"                         ; Spam
     "X-SBRule:"                         ; Spam
     "X-SMTP-"
-    "X-Scanned-By"
+    "X-Sasl-enc:"                       ; Apple Mail
+    "X-Scanned-By:"
     "X-Sender:"
     "X-Server-Date:"
     "X-Server-Uuid:"
--- a/lisp/progmodes/gdb-ui.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/progmodes/gdb-ui.el	Thu Feb 23 03:17:52 2006 +0000
@@ -123,6 +123,7 @@
 (defvar gdb-macro-info nil
   "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
 (defvar gdb-buffer-fringe-width nil)
+(defvar gdb-signalled nil)
 
 (defvar gdb-buffer-type nil
   "One of the symbols bound in `gdb-buffer-rules'.")
@@ -258,11 +259,20 @@
   (gdb command-line)
   (gdb-init-1))
 
-(defvar gdb-debug-log nil)
+(defcustom gdb-debug-log-length 128
+  "Length of `gdb-debug-log-ring'."
+  :group 'gud
+  :type 'integer
+  :version "22.1")
+
+(defvar gdb-debug-log-ring (make-ring gdb-debug-log-length)
+  "Ring of commands sent to and replies received from GDB.
+This variable is used to debug GDB-UI.  Just need most recent
+messages and a ring limits the size.")
 
 ;;;###autoload
 (defcustom gdb-enable-debug-log nil
-  "Non-nil means record the process input and output in `gdb-debug-log'."
+  "Non-nil means record the process input and output in `gdb-debug-log-ring'."
   :type 'boolean
   :group 'gud
   :version "22.1")
@@ -390,7 +400,6 @@
     expr))
 
 (defun gdb-init-1 ()
-  (setq gdb-debug-log nil)
   (set (make-local-variable 'gud-minor-mode) 'gdba)
   (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
   ;;
@@ -469,14 +478,15 @@
 	gdb-source-file-list nil
 	gdb-error nil
 	gdb-macro-info nil
-	gdb-buffer-fringe-width (car (window-fringes)))
+	gdb-buffer-fringe-width (car (window-fringes))
+	gdb-debug-log-ring (make-ring gdb-debug-log-length)
+	gdb-signalled nil)
 
   (setq gdb-buffer-type 'gdba)
 
   (if gdb-use-separate-io-buffer (gdb-clear-inferior-io))
 
   ;; Hack to see test for GDB 6.4+ (-stack-info-frame was implemented in 6.4)
-  (setq gdb-version nil)
   (gdb-enqueue-input (list "server interpreter mi -stack-info-frame\n"
 			   'gdb-get-version)))
 
@@ -573,9 +583,6 @@
   (require 'tooltip)
   (save-selected-window
     (let ((expr (tooltip-identifier-from-point (point))))
-      (if (and (string-equal gdb-current-language "c")
-	       gdb-use-colon-colon-notation gdb-selected-frame)
-	  (setq expr (concat gdb-selected-frame "::" expr)))
       (catch 'already-watched
 	(dolist (var gdb-var-list)
 	  (if (string-equal expr (car var)) (throw 'already-watched nil)))
@@ -593,11 +600,15 @@
 (defun gdb-var-create-handler (expr)
   (goto-char (point-min))
   (if (re-search-forward gdb-var-create-regexp nil t)
-      (let ((var (list expr
-		       (match-string 1)
-		       (match-string 2)
-		       (match-string 3)
-		       nil nil)))
+      (let ((var (list
+		  (if (and (string-equal gdb-current-language "c")
+			   gdb-use-colon-colon-notation gdb-selected-frame)
+		      (setq expr (concat gdb-selected-frame "::" expr))
+		    expr)
+		  (match-string 1)
+		  (match-string 2)
+		  (match-string 3)
+		  nil nil)))
 	(push var gdb-var-list)
 	(speedbar 1)
 	(unless (string-equal
@@ -613,7 +624,7 @@
 		       ,(nth 1 var) nil)))))
     (if (search-forward "Undefined command" nil t)
 	(message-box "Watching expressions requires gdb 6.0 onwards")
-      (message "No symbol \"%s\" in current context." expr))))
+      (message-box "No symbol \"%s\" in current context." expr))))
 
 (defun gdb-var-evaluate-expression-handler (varnum changed)
   (goto-char (point-min))
@@ -864,7 +875,7 @@
 	  "*"))
 
 (defun gdb-display-separate-io-buffer ()
-  "Display IO of inferior in a separate window."
+  "Display IO of debugged program in a separate window."
   (interactive)
   (if gdb-use-separate-io-buffer
       (gdb-display-buffer
@@ -963,7 +974,7 @@
   (let ((item (concat string "\n")))
     (if gud-running
       (progn
-	(if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
+	(if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log-ring))
 	(process-send-string proc item))
       (gdb-enqueue-input item))))
 
@@ -986,7 +997,8 @@
 
 (defun gdb-send-item (item)
   (setq gdb-flush-pending-output nil)
-  (if gdb-enable-debug-log (push (cons 'send-item item) gdb-debug-log))
+  (if gdb-enable-debug-log
+      (ring-insert gdb-debug-log-ring (cons 'send-item item)))
   (setq gdb-current-item item)
   (let ((process (get-buffer-process gud-comint-buffer)))
     (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) 'gdba)
@@ -1039,7 +1051,7 @@
     ("source" gdb-source)
     ("starting" gdb-starting)
     ("exited" gdb-exited)
-    ("signalled" gdb-exited)
+    ("signalled" gdb-signalled)
     ("signal" gdb-stopping)
     ("breakpoint" gdb-stopping)
     ("watchpoint" gdb-stopping)
@@ -1156,6 +1168,9 @@
   (setq gdb-overlay-arrow-position nil)
   (gdb-stopping ignored))
 
+(defun gdb-signalled (ignored)
+  (setq gdb-signalled t))
+
 (defun gdb-frame-begin (ignored)
   (let ((sink gdb-output-sink))
     (cond
@@ -1172,7 +1187,6 @@
 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)
-  (setq gdb-active-process t)
   (let ((sink gdb-output-sink))
     (cond
      ((eq sink 'inferior)
@@ -1180,7 +1194,8 @@
      ((eq sink 'user) t)
      (t
       (gdb-resync)
-      (error "Unexpected stopped annotation")))))
+      (error "Unexpected stopped annotation"))))
+  (if gdb-signalled (gdb-exited ignored)))
 
 (defun gdb-error (ignored)
   (setq gdb-error (not gdb-error)))
@@ -1233,7 +1248,8 @@
   "A gud marker filter for gdb.  Handle a burst of output from GDB."
   (if gdb-flush-pending-output
       nil
-    (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
+    (if gdb-enable-debug-log
+	(ring-insert gdb-debug-log-ring (cons 'recv string)))
     ;; Recall the left over gud-marker-acc from last time.
     (setq gud-marker-acc (concat gud-marker-acc string))
     ;; Start accumulating output for the GUD buffer.
--- a/lisp/progmodes/sh-script.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/progmodes/sh-script.el	Thu Feb 23 03:17:52 2006 +0000
@@ -1438,6 +1438,16 @@
 		 ((and buffer-file-name
 		       (string-match "\\.m?spec\\'" buffer-file-name))
 		  "rpm")))))
+    (unless interpreter
+      (setq interpreter
+	    (cond ((string-match "[.]sh\\>" buffer-file-name)
+		   "sh")
+		  ((string-match "[.]bash\\>" buffer-file-name)
+		   "bash")
+		  ((string-match "[.]ksh\\>" buffer-file-name)
+		   "ksh")
+		  ((string-match "[.]csh\\>" buffer-file-name)
+		   "csh"))))
     (sh-set-shell (or interpreter sh-shell-file) nil nil))
   (run-mode-hooks 'sh-mode-hook))
 
--- a/lisp/sort.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/sort.el	Thu Feb 23 03:17:52 2006 +0000
@@ -499,8 +499,9 @@
 	  ;; in the region, since the sort utility would lose the
 	  ;; properties.
 	  (let ((sort-args (list (if reverse "-rt\n" "-t\n")
-				 (concat "+0." (int-to-string col-start))
-				 (concat "-0." (int-to-string col-end)))))
+				 (format "-k1.%d,1.%d"
+					 (1+ col-start)
+					 (1+ col-end)))))
 	    (when sort-fold-case
 	      (push "-f" sort-args))
 	    (apply #'call-process-region beg1 end1 "sort" t t nil sort-args))
--- a/lisp/textmodes/org.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/org.el	Thu Feb 23 03:17:52 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.04
+;; Version: 4.05
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -81,6 +81,17 @@
 ;;
 ;; Changes since version 4.00:
 ;; ---------------------------
+;; Version 4.05
+;;    - Changes to internal link system (thanks to David Wainberg for ideas).
+;;      - in-file links: [[Search String]] instead of <file:::Search String>
+;;      - automatic links to "radio targets".
+;;      - CamelCase not longer active by default, configure org-activate-camels
+;;        if you want to turn it back on.
+;;      - After following a link, `C-c &' jumps back to it.
+;;    - MH-E link support (thanks to Thomas Baumann).
+;;    - Special table lines are no longer exported.
+;;    - Bug fixes and minor improvements.
+;;
 ;; Version 4.04
 ;;    - Cleanup tags display in agenda.
 ;;    - Bug fixes.
@@ -115,7 +126,7 @@
 
 ;;; Customization variables
 
-(defvar org-version "4.04"
+(defvar org-version "4.05"
   "The version number of the file org.el.")
 (defun org-version ()
   (interactive)
@@ -775,7 +786,7 @@
 (defcustom org-level-color-stars-only nil
   "Non-nil means fontify only the stars in each headline.
 When nil, the entire headline is fontified.
-Changing it requires a restart of Emacs to become effective."
+Changing it requires restart of Emacs to become effective."
   :group 'org-structure
   :type 'boolean)
 
@@ -930,6 +941,12 @@
   :group 'org-link
   :type 'boolean)
 
+(defcustom org-mark-ring-length 4
+  "Number of different positions to be recorded in the ring
+Changing this requires a restart of Emacs to work correctly."
+  :group 'org-link
+  :type 'interger)
+
 (defcustom org-link-format "<%s>"
   "Default format for linkes in the buffer.
 This is a format string for printf, %s will be replaced by the link text.
@@ -948,13 +965,27 @@
 When nil, it becomes possible to put several links into a line.
 Note that in tables, a link never extends accross fields, so in a table
 it is always possible to put several links into a line.
-Changing this variable requires a restart of Emacs to become effective."
+Changing this variable requires a restart of Emacs of become effective."
+  :group 'org-link
+  :type 'boolean)
+
+(defcustom org-radio-targets t
+  "Non-nil means activate text matching a link target.
+Radio targets are strings in triple angular brackets, like <<<My Target>>>.
+When this option is set, any occurrence of \"my target\" in normal text
+becomes a link."
+  :group 'org-link
+  :type 'boolean)
+
+(defcustom org-activate-camels nil
+  "Non-nil means, treat words in CamelCase as in-file links.
+Changing this requires restart of Emacs to become effective."
   :group 'org-link
   :type 'boolean)
 
 (defcustom org-context-in-file-links t
   "Non-nil means, file links from `org-store-link' contain context.
-The line number will be added to the file name with :: as separator and
+A search string will be added to the file name with :: as separator and
 used to find the context when the link is activated by the command
 `org-open-at-point'.
 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
@@ -962,6 +993,12 @@
   :group 'org-link
   :type 'boolean)
 
+(defcustom org-file-link-context-use-camel-case nil
+  "Non-nil means, use CamelCase to store a search context in a file link.
+When nil, the search string simply consists of the words of the string."
+  :group 'org-link
+  :type 'boolean)
+
 (defcustom org-keep-stored-link-after-insertion nil
   "Non-nil means, keep link in list for entire session.
 
@@ -1082,13 +1119,15 @@
 `org-file-apps-defaults-gnu'."
   :group 'org-link
   :type '(repeat
-	  (cons (string :tag "Extension")
+	  (cons (choice :value ""
+			(string :tag "Extension")
+			(const :tag "Default for unrecognized files" t)
+			(const :tag "Links to a directory" directory))
 		(choice :value ""
-		 (const :tag "Visit with Emacs" 'emacs)
-		 (const :tag "Use system default" 'default)
-		 (string :tag "Command")
-		 (sexp :tag "Lisp form")))))
-
+			(const :tag "Visit with Emacs" emacs)
+			(const :tag "Use system default" default)
+			(string :tag "Command")
+			(sexp :tag "Lisp form")))))
 
 (defgroup org-remember nil
   "Options concerning interaction with remember.el."
@@ -1508,6 +1547,15 @@
   :group 'org-export
   :type 'boolean)
 
+(defcustom org-export-table-remove-special-lines t
+  "Remove special lines and marking characters in calculating tables.
+This removes the special marking character column from tables that are set
+up for spreadsheet calculations.  It also removes the entire lines
+marked with `!', `_', or `^'.  The lines with `$' are kept, because
+the values of constants may be useful to have."
+  :group 'org-export
+  :type 'boolean)
+
 (defcustom org-export-prefer-native-exporter-for-tables nil
   "Non-nil means, always export tables created with table.el natively.
 Natively means, use the HTML code generator in table.el.
@@ -1923,6 +1971,10 @@
   (defvar gnus-group-name)
   (defvar gnus-article-current)
   (defvar w3m-current-url)
+  (defvar mh-progs)
+  (defvar mh-current-folder)
+  (defvar mh-show-folder-buffer)
+  (defvar mh-index-folder)
   (defvar org-selected-point)
   (defvar calendar-mode-map)
   (defvar remember-save-after-remembering)
@@ -1981,17 +2033,11 @@
        'org-unfontify-region)
   ;; Activate before-change-function
   (set (make-local-variable 'org-table-may-need-update) t)
-  (make-local-hook 'before-change-functions)  ;; needed for XEmacs
-  (add-hook 'before-change-functions 'org-before-change-function nil
-	    'local)
-  ;; FIXME: The following does not work because isearch-mode-end-hook
-  ;; is called *before* the visibility overlays as removed.
-  ;; There should be another hook then for me to be used.
-;;  (make-local-hook 'isearch-mode-end-hook)  ;; needed for XEmacs
-;;  (add-hook 'isearch-mode-end-hook 'org-show-hierarchy-above nil
-;;	    'local)
+  (org-add-hook 'before-change-functions 'org-before-change-function nil
+		'local)
   ;; Paragraphs and auto-filling
   (org-set-autofill-regexps)
+  (org-update-radio-target-regexp)
   ;; Settings for Calc embedded mode
   (set (make-local-variable 'calc-embedded-open-formula) "|\\|\n")
   (set (make-local-variable 'calc-embedded-close-formula) "|\\|\n")
@@ -2053,9 +2099,9 @@
 (defconst org-link-regexp
   (if org-allow-space-in-links
       (concat
-       "\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|rmail\\|gnus\\|shell\\):\\([^" org-non-link-chars "]+[^ " org-non-link-chars "]\\)")
+       "\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|mhe\\|rmail\\|gnus\\|shell\\):\\([^" org-non-link-chars "]+[^ " org-non-link-chars "]\\)")
     (concat
-     "\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|rmail\\|gnus\\|shell\\):\\([^ " org-non-link-chars "]+\\)")
+     "\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|mhe\\|rmail\\|gnus\\|shell\\):\\([^ " org-non-link-chars "]+\\)")
     )
   "Regular expression for matching links.")
 (defconst org-link-maybe-angles-regexp
@@ -2065,6 +2111,10 @@
   (concat "\000" org-link-regexp "\000")
   "Matches a link and optionally surrounding angle brackets.")
 
+(defconst org-bracket-link-regexp
+  "\\[\\[\\([^]]+\\)\\]\\(\\[\\([^]]+\\)\\]\\)?\\]"
+  "Matches a link in double brackets.")
+
 (defconst org-ts-lengths
   (cons (length (format-time-string (car org-time-stamp-formats)))
 	(length (format-time-string (cdr org-time-stamp-formats))))
@@ -2092,6 +2142,15 @@
 				   'keymap org-mouse-map))
 	t)))
 
+(defun org-activate-links2 (limit)
+  "Run through the buffer and add overlays to links."
+  (if (re-search-forward org-bracket-link-regexp limit t)
+      (progn
+	(add-text-properties (match-beginning 0) (match-end 0)
+			     (list 'mouse-face 'highlight
+				   'keymap org-mouse-map))
+	t)))
+
 (defun org-activate-dates (limit)
   "Run through the buffer and add overlays to dates."
   (if (re-search-forward org-tsr-regexp limit t)
@@ -2101,19 +2160,75 @@
 				   'keymap org-mouse-map))
 	t)))
 
+(defvar org-target-link-regexp nil
+  "Regular expression matching radio targets in plain text.")
+(defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
+  "Regular expression matching a link target.")
+(defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
+  "Regular expression matching a link target.")
+
+(defun org-activate-target-links (limit)
+  "Run through the buffer and add overlays to target matches."
+  (when org-radio-targets
+    (let ((case-fold-search t))
+      (if (re-search-forward org-target-link-regexp limit t)
+	  (progn
+	    (add-text-properties (match-beginning 0) (match-end 0)
+				 (list 'mouse-face 'highlight
+				       'keymap org-mouse-map
+				       'org-linked-text t))
+	    t)))))
+
+(defun org-update-radio-target-regexp ()
+  "Find all radio targets in this file and update the regular expression."
+  (interactive)
+  (when org-radio-targets
+    (setq org-target-link-regexp
+	  (org-make-target-link-regexp (org-all-targets 'radio)))
+    (font-lock-mode -1)
+    (font-lock-mode 1)))
+
+(defun org-all-targets (&optional radio)
+  "Return a list of all targets in this file.
+With optional argument RADIO, only find radio targets."
+  (let ((re (if radio org-radio-target-regexp org-target-regexp))
+	rtn)
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward re nil t)
+	(add-to-list 'rtn (downcase (match-string-no-properties 1))))
+      rtn)))
+
+(defun org-make-target-link-regexp (targets)
+  "Make regular expression matching all strings in TARGETS.
+The regular expression finds the targets also if there is a line break
+between words."
+  (concat
+   "\\<\\("
+   (mapconcat
+    (lambda (x)
+      (while (string-match " +" x)
+	(setq x (replace-match "\\s-+" t t x)))
+      x)
+    targets
+    "\\|")
+   "\\)\\>"))
+
 (defvar org-camel-regexp "\\*?\\<[A-Z]+[a-z]+[A-Z][a-zA-Z]*\\>"
   "Matches CamelCase words, possibly with a star before it.")
+
 (defun org-activate-camels (limit)
   "Run through the buffer and add overlays to dates."
-  (if (re-search-forward org-camel-regexp limit t)
-      (progn
-	(add-text-properties (match-beginning 0) (match-end 0)
-			     (list 'mouse-face 'highlight
-				   'keymap org-mouse-map))
-	t)))
+  (if org-activate-camels
+      (if (re-search-forward org-camel-regexp limit t)
+	  (progn
+	    (add-text-properties (match-beginning 0) (match-end 0)
+				 (list 'mouse-face 'highlight
+				       'keymap org-mouse-map))
+	    t))))
 
 (defun org-activate-tags (limit)
-  (if (re-search-forward "[ \t]\\(:[A-Za-z_:]+:\\)[ \r\n]" limit t)
+  (if (re-search-forward "[ \t]\\(:[A-Za-z_@0-9:]+:\\)[ \r\n]" limit t)
       (progn
 	(add-text-properties (match-beginning 1) (match-end 1)
 			     (list 'mouse-face 'highlight
@@ -2138,6 +2253,8 @@
   (let ((org-font-lock-extra-keywords
 	 (list
 	  '(org-activate-links (0 'org-link t))
+	  '(org-activate-links2 (0 'org-link t))
+	  '(org-activate-target-links (0 'org-link t))
 	  '(org-activate-dates (0 'org-link t))
 	  '(org-activate-camels (0 'org-link t))
 	  '(org-activate-tags (1 'org-link t))
@@ -2199,7 +2316,8 @@
 	 (inhibit-read-only t) (inhibit-point-motion-hooks t)
 	 (inhibit-modification-hooks t)
 	 deactivate-mark buffer-file-name buffer-file-truename)
-    (remove-text-properties beg end '(mouse-face nil keymap nil))))
+    (remove-text-properties beg end
+			    '(mouse-face nil keymap nil org-linked-text nil))))
 
 ;;; Visibility cycling
 
@@ -2433,8 +2551,10 @@
 	  (org-get-location (current-buffer) org-goto-help)))
     (if selected-point
 	(progn
+	  (org-mark-ring-push org-goto-start-pos)
 	  (goto-char selected-point)
-	  (if (org-invisible-p) (org-show-hierarchy-above)))
+	  (if (or (org-invisible-p) (org-invisible-p2))
+	      (org-show-hierarchy-above)))
       (error "Quit"))))
 
 (defun org-get-location (buf help)
@@ -3213,7 +3333,7 @@
     (let* ((end (point))
 	   (beg1 (save-excursion
 		   (if (equal (char-before (point)) ?\ ) (backward-char 1))
-		   (skip-chars-backward "a-zA-Z_")
+		   (skip-chars-backward "a-zA-Z_@0-9")
 		   (point)))
 	   (beg (save-excursion
 		  (if (equal (char-before (point)) ?\ ) (backward-char 1))
@@ -3247,7 +3367,11 @@
 		    (save-excursion
 		      (goto-char (point-min))
 		      (while (re-search-forward org-todo-line-regexp nil t)
-			(push (list (org-make-org-heading-camel (match-string 3)))
+			(push (list 
+			       (if org-file-link-context-use-camel-case
+				   (org-make-org-heading-camel (match-string 3) t)
+				 (org-make-org-heading-search-string
+				  (match-string 3) t)))
 			      tbl)))
 		    tbl)
 		   (tag (setq type :tag beg beg1)
@@ -3475,9 +3599,8 @@
 	  (setq cnt (1+ cnt))
 	  (org-highlight-new-match (match-beginning 0) (match-end 0))
 	  (org-show-hierarchy-above))))
-    (make-local-hook 'before-change-functions) ; needed for XEmacs
-    (add-hook 'before-change-functions 'org-remove-occur-highlights
-	      nil 'local)
+    (org-add-hook 'before-change-functions 'org-remove-occur-highlights
+		  nil 'local)
     (run-hooks 'org-occur-hook)
     (if (interactive-p)
 	(message "%d match(es) for regexp %s" cnt regexp))
@@ -3488,7 +3611,8 @@
   (catch 'exit
     (if (org-on-heading-p t)
 	(org-flag-heading nil)    ; only show the heading
-      (and (org-invisible-p) (org-show-hidden-entry)))    ; show entire entry
+      (and (or (org-invisible-p) (org-invisible-p2))
+	   (org-show-hidden-entry)))    ; show entire entry
     (save-excursion
       (and org-show-following-heading
 	   (outline-next-heading)
@@ -3765,7 +3889,8 @@
 		  (progn
 		    (use-local-map map)
 		    (setq ans (read-string prompt "" nil nil))
-		    (setq ans (or ans1 ans2 ans)))
+		    (if (not (string-match "\\S-" ans)) (setq ans nil))
+		    (setq ans (or ans1 ans ans2)))
 		(use-local-map old-map)))))
       ;; Naked prompt only
       (setq ans (read-string prompt "" nil timestr)))
@@ -4133,10 +4258,8 @@
   (use-local-map org-agenda-mode-map)
   (easy-menu-add org-agenda-menu)
   (if org-startup-truncated (setq truncate-lines t))
-  (make-local-hook 'post-command-hook)  ; Needed for XEmacs
-  (add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
-  (make-local-hook 'pre-command-hook)  ; Needed for XEmacs
-  (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
+  (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
+  (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
   (unless org-agenda-keep-modes
     (setq org-agenda-follow-mode nil
 	  org-agenda-show-log nil))
@@ -5285,27 +5408,6 @@
 	     (throw 'exit t)))
       nil)))
 
-(defun org-get-tags-at (&optional pos)
-  "Get a list of all headline targs applicable at POS.
-POS defaults to point.  If tags are inherited, the list contains
-the targets in the same sequence as the headlines appear, i.e.
-the tags of the current headline come last."
-  (interactive)
-  (let (tags)
-    (save-excursion
-      (goto-char (or pos (point)))
-      (save-match-data
-	(org-back-to-heading t)
-	(condition-case nil
-	    (while t
-	      (if (looking-at "[^\r\n]+?:\\([a-zA-Z_:]+\\):[ \t]*\\([\n\r]\\|\\'\\)")
-		  (setq tags (append (org-split-string (match-string 1) ":") tags)))
-	      (or org-use-tag-inheritance (error ""))
-	      (org-up-heading-all 1))
-	  (error nil))))
-    (message "%s" tags)
-    tags))
-
 (defun org-agenda-get-todos ()
   "Return the TODO information for agenda display."
   (let* ((props (list 'face nil
@@ -5726,7 +5828,7 @@
       (when (and (or (eq org-agenda-remove-tags-when-in-prefix t)
 		     (and org-agenda-remove-tags-when-in-prefix
 			  org-prefix-has-tag))
-		 (string-match ":[a-zA-Z_:]+:[ \t]*$" txt))
+		 (string-match ":[a-zA-Z_@0-9:]+:[ \t]*$" txt))
 	(setq txt (replace-match "" t t txt)))
 
       ;; Create the final string
@@ -6076,6 +6178,27 @@
     (org-agenda-change-all-lines newhead hdmarker)
     (beginning-of-line 1)))
 
+(defun org-get-tags-at (&optional pos)
+  "Get a list of all headline targs applicable at POS.
+POS defaults to point.  If tags are inherited, the list contains
+the targets in the same sequence as the headlines appear, i.e.
+the tags of the current headline come last."
+  (interactive)
+  (let (tags)
+    (save-excursion
+      (goto-char (or pos (point)))
+      (save-match-data
+	(org-back-to-heading t)
+	(condition-case nil
+	    (while t
+	      (if (looking-at "[^\r\n]+?:\\([a-zA-Z_@0-9:]+\\):[ \t]*\\([\n\r]\\|\\'\\)")
+		  (setq tags (append (org-split-string (match-string 1) ":") tags)))
+	      (or org-use-tag-inheritance (error ""))
+	      (org-up-heading-all 1))
+	  (error nil))))
+    (message "%s" tags)
+    tags))
+
 (defun org-agenda-set-tags ()
   "Set tags for the current headline."
   (interactive)
@@ -6298,7 +6421,7 @@
 		     (mapconcat 'regexp-quote
 				(nreverse (cdr (reverse org-todo-keywords)))
 				"\\|")
-		     "\\>\\)\\)? *\\(.*?\\)\\(:[A-Za-z_:]+:\\)?[ \t]*[\n\r]"))
+		     "\\>\\)\\)? *\\(.*?\\)\\(:[A-Za-z_@0-9:]+:\\)?[ \t]*[\n\r]"))
 	 (props (list 'face nil
 		      'done-face 'org-done
 		      'undone-face nil
@@ -6386,7 +6509,7 @@
   (let ((match0 match) minus tag mm matcher orterms term orlist)
     (setq orterms (org-split-string match "|"))
     (while (setq term (pop orterms))
-      (while (string-match "^&?\\([-+:]\\)?\\([A-Za-z_]+\\)" term)
+      (while (string-match "^&?\\([-+:]\\)?\\([A-Za-z_@0-9]+\\)" term)
 	(setq minus (and (match-end 1)
 			 (equal (match-string 1 term) "-"))
 	      tag (match-string 2 term)
@@ -6481,7 +6604,7 @@
 	 (re (concat "^" outline-regexp))
 	 (col (current-column))
 	 (current (org-get-tags))
-	 tags hd empty)
+	 tags hd empty invis)
     (if arg
 	(save-excursion
 	  (goto-char (point-min))
@@ -6505,19 +6628,23 @@
       (if (equal current "")
 	  (progn
 	    (end-of-line 1)
-	    (or empty (insert " ")))
+	    (or empty (insert-before-markers " ")))
 	(beginning-of-line 1)
+	(setq invis (org-invisible-p))
 	(looking-at (concat "\\(.*\\)\\(" (regexp-quote current) "\\)[ \t]*"))
 	(setq hd (match-string 1))
 	(delete-region (match-beginning 0) (match-end 0))
-	(insert (org-trim hd) (if empty "" " ")))
+	(insert-before-markers (org-trim hd) (if empty "" " ")))
+      ;; FIXME:  What happens when adding a new tag???  Seems OK!!!
       (unless (equal tags "")
 	(move-to-column (max (current-column)
 			     (if (> org-tags-column 0)
 				 org-tags-column
 			       (- (- org-tags-column) (length tags))))
 			t)
-	(insert tags))
+	(insert-before-markers tags)
+	(if (and (not invis) (org-invisible-p))
+	    (outline-flag-region (point-at-bol) (point) nil)))
       (move-to-column col))))
 
 (defun org-tags-completion-function (string predicate &optional flag)
@@ -6551,7 +6678,7 @@
     (error "Not on a heading"))
   (save-excursion
     (beginning-of-line 1)
-    (if (looking-at ".*[ \t]\\(:[A-Za-z_:]+:\\)[ \t]*\\(\r\\|$\\)")
+    (if (looking-at ".*[ \t]\\(:[A-Za-z_@0-9:]+:\\)[ \t]*\\(\r\\|$\\)")
 	(match-string 1)
       "")))
 
@@ -6560,7 +6687,7 @@
   (let (tags)
     (save-excursion
       (goto-char (point-min))
-      (while (re-search-forward "[ \t]:\\([A-Za-z_:]+\\):[ \t\r\n]" nil t)
+      (while (re-search-forward "[ \t]:\\([A-Za-z_@0-9:]+\\):[ \t\r\n]" nil t)
 	(mapc (lambda (x) (add-to-list 'tags x))
 	      (org-split-string (match-string 1) ":"))))
     (mapcar 'list tags)))
@@ -6591,9 +6718,34 @@
       (org-agenda-list nil (time-to-days (org-time-string-to-time
 					  (substring (match-string 1) 0 10)))
 		       1)
-    (let (type path line search (pos (point)))
+    (let (type path link line search (pos (point)))
       (catch 'match
 	(save-excursion
+	  (skip-chars-forward "^]\n\r")
+	  (when (and (re-search-backward "\\[\\[" nil t)
+		     (looking-at org-bracket-link-regexp)
+		     (<= (match-beginning 0) pos)
+		     (>= (match-end 0) pos))
+	    (setq link (match-string 1))
+	    (while (string-match " *\n *" link)
+	      (setq link (replace-match " " t t link)))
+	    (if (string-match org-link-regexp link)
+		(setq type (match-string 1)
+		      path (match-string 2))
+	      (setq type "thisfile"
+		    path link))
+	    (throw 'match t)))
+
+	(when (get-text-property (point) 'org-linked-text)
+	  (setq type "thisfile"
+		pos (if (get-text-property (1+ (point)) 'org-linked-text)
+			(1+ (point)) (point))
+		path (buffer-substring
+		      (previous-single-property-change pos 'org-linked-text)
+		      (next-single-property-change pos 'org-linked-text)))
+	  (throw 'match t))
+
+	(save-excursion
 	  (skip-chars-backward
 	   (concat (if org-allow-space-in-links "^" "^ ")
 		   org-non-link-chars))
@@ -6606,7 +6758,7 @@
 	    (throw 'match t)))
 	(save-excursion
 	  (skip-chars-backward "^ \t\n\r")
-	  (when (looking-at "\\(:[A-Za-z_:]+\\):[ \t\r\n]")
+	  (when (looking-at "\\(:[A-Za-z_@0-9:]+\\):[ \t\r\n]")
 	    (setq type "tags"
 		  path (match-string 1))
 	    (while (string-match ":" path)
@@ -6614,7 +6766,8 @@
 	    (throw 'match t)))
 	(save-excursion
 	  (skip-chars-backward "a-zA-Z_")
-	  (when (looking-at org-camel-regexp)
+	  (when (and org-activate-camels
+		     (looking-at org-camel-regexp))
 	    (setq type "camel" path (match-string 0))
 	    (if (equal (char-before) ?*)
 		(setq path (concat "*" path))))
@@ -6639,7 +6792,9 @@
 
        ((string= type "tags")
 	(org-tags-view in-emacs path))
-       ((string= type "camel")
+       ((or (string= type "camel")
+	    (string= type "thisfile"))
+	(org-mark-ring-push)
 	(org-link-search
 	 path
 	 (cond ((equal in-emacs '(4)) 'occur)
@@ -6686,6 +6841,14 @@
 		article (match-string 3 path))
 	  (org-follow-wl-link folder article)))
 
+       ((string= type "mhe")
+	(let (folder article)
+	  (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
+	      (error "Error in MHE link"))
+	  (setq folder (match-string 1 path)
+		article (match-string 3 path))
+	  (org-follow-mhe-link folder article)))
+
        ((string= type "rmail")
 	(let (folder article)
 	  (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
@@ -6717,11 +6880,19 @@
 If the current buffer is in `dired-mode', grep will be used to search
 in all files."
   (let ((case-fold-search t)
-	(s0 s)
+	(s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
 	(pos (point))
 	(pre "") (post "")
-	words re0 re1 re2 re3 re4 re5 reall)
-    (cond ((string-match "^/\\(.*\\)/$" s)
+	words re0 re1 re2 re3 re4 re5 reall camel)
+    (cond ((save-excursion
+	     (goto-char (point-min))
+	     (and
+	      (re-search-forward
+	       (concat "<<" (regexp-quote s0) ">>") nil t)
+	      (setq pos (match-beginning 0))))
+	   ;; There is an exact target for this
+	   (goto-char pos))
+	  ((string-match "^/\\(.*\\)/$" s)
 	   ;; A regular expression
 	   (cond
 	    ((eq major-mode 'org-mode)
@@ -6729,17 +6900,22 @@
 	    ;;((eq major-mode 'dired-mode)
 	    ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
 	    (t (org-do-occur (match-string 1 s)))))
-	  ((string-match (concat "^" org-camel-regexp) s)
-	   ;; A camel
-	   (if (equal (string-to-char s) ?*)
-	       (setq pre "^\\*+[ \t]*\\(\\sw+\\)?[ \t]*"
-		     post "[ \t]*$"
-		     s (substring s 1)))
+	  ((or (setq camel (string-match (concat "^" org-camel-regexp "$") s))
+	       t)
+	   ;; A camel or a normal search string
+	   (when (equal (string-to-char s) ?*)
+	     ;; Anchor on headlines, post may include tags.
+	     (setq pre "^\\*+[ \t]*\\(\\sw+\\)?[ \t]*"
+		   post "[ \t]*\\([ \t]+:[a-zA-Z_@0-9:+]:[ \t]*\\)?$"
+		   s (substring s 1)))
 	   (remove-text-properties
 	    0 (length s)
 	    '(face nil mouse-face nil keymap nil fontified nil) s)
 	   ;; Make a series of regular expressions to find a match
-	   (setq words (org-camel-to-words s)
+	   (setq words
+		 (if camel
+		     (org-camel-to-words s)
+		   (org-split-string s "[ \n\r\t]+"))
 		 re0 (concat "<<" (regexp-quote s0) ">>")
 		 re2 (concat "\\<" (mapconcat 'downcase words "[ \t]+") "\\>")
 		 re4 (concat "\\<" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\>")
@@ -6770,7 +6946,8 @@
 	   (goto-char (point-min))
 	   (if (search-forward s nil t)
 	       (goto-char (match-beginning 0))
-	     (error "No match"))))))
+	     (error "No match"))))
+    (and (eq major-mode 'org-mode) (org-show-hierarchy-above))))
 
 (defun org-do-occur (regexp &optional cleanup)
   "Call the Emacs command `occur'.
@@ -6791,6 +6968,47 @@
       (goto-char (point-min))
       (select-window cwin))))
 
+(defvar org-mark-ring nil
+  "Mark ring for positions before jumps in Org-mode.")
+(defvar org-mark-ring-last-goto nil
+  "Last position in the mark ring used to go back.")
+;; Fill and close the ring
+(setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
+(loop for i from 1 to org-mark-ring-length do
+      (push (make-marker) org-mark-ring))
+(setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
+	org-mark-ring)
+
+(defun org-mark-ring-push (&optional pos buffer)
+  "Put the current position or POS into the mark ring and rotate it."
+  (interactive)
+  (setq pos (or pos (point)))
+  (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
+  (move-marker (car org-mark-ring) 
+	       (or pos (point))
+	       (or buffer (current-buffer)))
+  (message
+   (substitute-command-keys
+    "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
+
+(defun org-mark-ring-goto (&optional n)
+  "Jump to the previous position in the mark ring.
+With prefix arg N, jump back that many stored positions.  When
+called several times in succession, walk through the entire ring.
+Org-mode commands jumping to a different position in the current file,
+or to another Org-mode file, automatically push the old position
+onto the ring."
+  (interactive "p")
+  (let (p m)
+    (if (eq last-command this-command)
+	(setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
+      (setq p org-mark-ring))
+    (setq org-mark-ring-last-goto p)
+    (setq m (car p))
+    (switch-to-buffer (marker-buffer m))
+    (goto-char m)
+    (if (or (org-invisible-p) (org-invisible-p2)) (org-show-hierarchy-above))))
+
 (defun org-camel-to-words (s)
   "Split \"CamelCaseWords\" to (\"Camel\" \"Case\" \"Words\")."
   (let ((case-fold-search nil)
@@ -6800,10 +7018,20 @@
       (setq s (substring s (1+ (match-beginning 0)))))
     (nreverse (cons s words))))
 
+(defun org-remove-angle-brackets (s)
+  (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
+  (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
+  s)
+(defun org-add-angle-brackets (s)
+  (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
+  (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
+  s)
+
 (defun org-follow-bbdb-link (name)
   "Follow a BBDB link to NAME."
   (require 'bbdb)
-  (let ((inhibit-redisplay t))
+  (let ((inhibit-redisplay t)
+	(bbdb-electric-p nil))
     (catch 'exit
       ;; Exact match on name
       (bbdb-name (concat "\\`" name "\\'") nil)
@@ -6839,6 +7067,7 @@
 (defun org-follow-vm-link (&optional folder article readonly)
   "Follow a VM link to FOLDER and ARTICLE."
   (require 'vm)
+  (setq article (org-add-angle-brackets article))
   (if (string-match "^//\\([a-zA-Z]+@\\)?\\([^:]+\\):\\(.*\\)" folder)
       ;; ange-ftp or efs or tramp access
       (let ((user (or (match-string 1 folder) (user-login-name)))
@@ -6872,12 +7101,14 @@
 
 (defun org-follow-wl-link (folder article)
   "Follow a Wanderlust link to FOLDER and ARTICLE."
+  (setq article (org-add-angle-brackets article))
   (wl-summary-goto-folder-subr folder 'no-sync t nil t)
-  (if article (wl-summary-jump-to-msg-by-message-id article))
+  (if article (wl-summary-jump-to-msg-by-message-id article ">"))
   (wl-summary-redisplay))
 
 (defun org-follow-rmail-link (folder article)
   "Follow an RMAIL link to FOLDER and ARTICLE."
+  (setq article (org-add-angle-brackets article))
   (let (message-number)
     (save-excursion
       (save-window-excursion
@@ -6898,6 +7129,107 @@
 	  message-number)
       (error "Message not found"))))
 
+;; mh-e integration based on planner-mode
+(defun org-mhe-get-message-real-folder ()
+  "Return the name of the current message real folder, so if you use
+  sequences, it will now work."
+  (save-excursion
+    (let* ((folder
+            (if (equal major-mode 'mh-folder-mode)
+                mh-current-folder
+              ;; Refer to the show buffer
+              mh-show-folder-buffer))
+           (end-index 
+            (if (boundp 'mh-index-folder)
+                (min (length mh-index-folder) (length folder))))
+           )
+      ;; a simple test on mh-index-data does not work, because
+      ;; mh-index-data is always nil in a show buffer.
+      (if (and (boundp 'mh-index-folder)
+               (string= mh-index-folder (substring folder 0 end-index)))
+          (if (equal major-mode 'mh-show-mode)
+              (save-window-excursion
+                (when (buffer-live-p (get-buffer folder))
+                  (progn
+                    (pop-to-buffer folder)
+                    (org-mhe-get-message-folder-from-index)
+                    )
+                  ))
+            (org-mhe-get-message-folder-from-index)
+            )
+        folder
+        )
+      )))
+
+(defun org-mhe-get-message-folder-from-index ()
+  "Returns the name of the message folder in a index folder
+  buffer."
+  (save-excursion
+    (mh-index-previous-folder)
+    (if (not (re-search-forward "^\\(+.*\\)$" nil t))
+        (message "Problem getting folder from index.")
+      (message (match-string 1)))))
+
+(defun org-mhe-get-message-folder ()
+  "Return the name of the current message folder. Be careful if you
+  use sequences."
+  (save-excursion
+    (if (equal major-mode 'mh-folder-mode)
+        mh-current-folder
+      ;; Refer to the show buffer
+      mh-show-folder-buffer)))
+
+(defun org-mhe-get-message-num ()
+  "Return the number of the current message. Be careful if you
+  use sequences."
+  (save-excursion
+    (if (equal major-mode 'mh-folder-mode)
+        (mh-get-msg-num nil)
+      ;; Refer to the show buffer
+      (mh-show-buffer-message-number))))
+
+(defun org-mhe-get-header (header)
+  "Return a header of the message in folder mode. This will create a
+  show buffer for the corresponding message. If you have a more clever
+  idea..."
+  (let* ((folder (org-mhe-get-message-folder))
+         (num (org-mhe-get-message-num))
+         (buffer (get-buffer-create (concat "show-" folder)))
+         (header-field))
+  (with-current-buffer buffer
+    (mh-display-msg num folder)
+    (if (equal major-mode 'mh-folder-mode)
+        (mh-header-display)
+      (mh-show-header-display))
+    (set-buffer buffer)
+    (setq header-field (mh-get-header-field header))
+    (if (equal major-mode 'mh-folder-mode)
+        (mh-show)
+      (mh-show-show))
+    header-field)))
+
+(defun org-follow-mhe-link (folder article)
+  "Follow an MHE link to FOLDER and ARTICLE."
+  (setq article (org-add-angle-brackets article))
+;;  (require 'mh-e)
+  (mh-rmail) ;; mh-e is standard with emacs 22
+  (let* ((show-buf (concat "show-" folder)))
+    (get-buffer-create show-buf)
+    (mh-display-msg
+     (string-to-number
+      (car (split-string 
+	    (with-temp-buffer
+	      (call-process
+	       (expand-file-name "pick" mh-progs)
+	       nil t nil
+	       folder
+	       "--message-id"
+	       article)
+	      (buffer-string))
+	    "\n")))
+     folder)
+    (pop-to-buffer show-buf)))
+
 (defun org-open-file (path &optional in-emacs line search)
   "Open the file at PATH.
 First, this expands any special file name abbreviations.  Then the
@@ -6913,7 +7245,11 @@
   (let* ((file (if (equal path "")
 		   (buffer-file-name)
 		 (convert-standard-filename (org-expand-file-name path))))
+	 (dirp (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))
@@ -6925,7 +7261,8 @@
     (setq apps (append org-file-apps (org-default-apps)))
     (if in-emacs
 	(setq cmd 'emacs)
-      (setq cmd (or (cdr (assoc ext apps))
+      (setq cmd (or (and dirp (cdr (assoc 'directory apps)))
+		    (cdr (assoc ext apps))
 		    (cdr (assoc t apps)))))
     (when (eq cmd 'mailcap)
       (require 'mailcap)
@@ -6948,7 +7285,11 @@
 	(if search (org-link-search search))))
      ((consp cmd)
       (eval cmd))
-     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))))
+     (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
+    (and (eq major-mode 'org-mode) (eq old-mode 'org-mode)
+	 (or (not (equal old-buffer (current-buffer)))
+	     (not (equal old-pos (point))))
+	 (org-mark-ring-push old-pos old-buffer))))
 
 (defun org-default-apps ()
   "Return the default applications for this operating system."
@@ -6979,7 +7320,7 @@
 For links to usenet articles, arg negates `org-usenet-links-prefer-google'.
 For file links, arg negates `org-context-in-file-links'."
   (interactive "P")
-  (let (link cpltxt)
+  (let (link cpltxt txt (pos (point)))
     (cond
 
      ((eq major-mode 'bbdb-mode)
@@ -7009,6 +7350,7 @@
 	      (subject (vm-su-subject message))
 	      (author (vm-su-full-name message))
 	      (message-id (vm-su-message-id message)))
+	 (setq message-id (org-remove-angle-brackets message-id))
 	 (setq folder (abbreviate-file-name folder))
 	 (if (string-match (concat "^" (regexp-quote vm-folder-directory))
 			   folder)
@@ -7026,12 +7368,25 @@
 				 msgnum (wl-summary-buffer-msgdb)))
 	     (author (wl-summary-line-from)) ; FIXME: how to get author name?
 	     (subject "???"))   ; FIXME: How to get subject of email?
+	(setq message-id (org-remove-angle-brackets message-id))
 	(setq cpltxt (concat author  " on: " subject))
 	(setq link (concat cpltxt "\n  "
 			   (org-make-link
 			    "wl:" wl-summary-buffer-folder-name
 			   "#" message-id)))))
 
+     ((or (equal major-mode 'mh-folder-mode)
+	  (equal major-mode 'mh-show-mode))
+      (let ((from-header (org-mhe-get-header "From:"))
+	    (to-header (org-mhe-get-header "To:"))
+	    (subject (org-mhe-get-header "Subject:")))
+	(setq cpltxt (concat from-header " on: " subject))
+	(setq link (concat cpltxt "\n  "
+			   (org-make-link
+			    "mhe:" (org-mhe-get-message-real-folder) "#" 
+			    (org-remove-angle-brackets
+			     (org-mhe-get-header "Message-Id:")))))))
+
      ((eq major-mode 'rmail-mode)
       (save-excursion
 	(save-restriction
@@ -7040,6 +7395,7 @@
 		(message-id (mail-fetch-field "message-id"))
 		(author (mail-fetch-field "from"))
 		(subject (mail-fetch-field "subject")))
+	    (setq message-id (org-remove-angle-brackets message-id))
 	    (setq cpltxt (concat author  " on: " subject))
 	    (setq link (concat cpltxt "\n  "
 			       (org-make-link
@@ -7093,19 +7449,26 @@
 			   (abbreviate-file-name (buffer-file-name))))
       ;; Add a context search string
       (when (org-xor org-context-in-file-links arg)
+	;; Check if we are on a target
 	(if (save-excursion
-	      (skip-chars-backward "a-zA-Z<")
-	      (looking-at (concat "<<\\(" org-camel-regexp "\\)>>")))
+	      (skip-chars-forward "^>\n\r")
+	      (and (re-search-backward "<<" nil t)
+		   (looking-at "<<\\(.*?\\)>>")
+		   (<= (match-beginning 0) pos)
+		   (>= (match-end 0) pos)))
 	    (setq cpltxt (concat cpltxt "::" (match-string 1)))
+	  (setq txt (cond
+		     ((org-on-heading-p) nil)
+		     ((org-region-active-p)
+		      (buffer-substring (region-beginning) (region-end)))
+		     (t (buffer-substring (point-at-bol) (point-at-eol)))))
 	  (setq cpltxt
 		(concat cpltxt "::"
-			(org-make-org-heading-camel
-			 (cond
-			  ((org-on-heading-p) nil)
-			  ((org-region-active-p)
-			   (buffer-substring (region-beginning) (region-end)))
-			  (t (buffer-substring (point-at-bol) (point-at-eol))))
-			 )))))
+			(if org-file-link-context-use-camel-case
+			    (org-make-org-heading-camel txt)
+			  (org-make-org-heading-search-string txt))))))
+      (if (string-match "::\\'" cpltxt)
+	  (setq cpltxt (substring cpltxt 0 -2)))
       (setq link (org-make-link cpltxt)))
 
      ((buffer-file-name)
@@ -7114,19 +7477,21 @@
 			   (abbreviate-file-name (buffer-file-name))))
       ;; Add a context string
       (when (org-xor org-context-in-file-links arg)
+	(setq txt (if (org-region-active-p)
+		      (buffer-substring (region-beginning) (region-end))
+		    (buffer-substring (point-at-bol) (point-at-eol))))
 	(setq cpltxt
 	      (concat cpltxt "::"
-		      (org-make-org-heading-camel
-		       (if (org-region-active-p)
-			   (buffer-substring (region-beginning) (region-end))
-			 (buffer-substring (point-at-bol) (point-at-eol)))))))
+		      (if org-file-link-context-use-camel-case
+			  (org-make-org-heading-camel txt)
+			(org-make-org-heading-search-string txt)))))
       (setq link (org-make-link cpltxt)))
 
      ((interactive-p)
       (error "Cannot link to a buffer which is not visiting a file"))
 
      (t (setq link nil)))
-
+    
     (if (and (interactive-p) link)
 	(progn
 	  (setq org-stored-links
@@ -7134,14 +7499,37 @@
 	  (message "Stored: %s" (or cpltxt link)))
       link)))
 
-(defun org-make-org-heading-camel (&optional string)
+(defun org-make-org-heading-search-string (&optional string heading)
+  "Make search string for S or current headline."
+  (interactive)
+  (let ((s (or string (org-get-heading))))
+    (unless (and string (not heading))
+      ;; We are using a headline, clean up garbage in there.
+      (if (string-match org-todo-regexp s)
+	  (setq s (replace-match "" t t s)))
+      (if (string-match ":[a-zA-Z_@0-9:]+:[ \t]*$" s)
+	  (setq s (replace-match "" t t s)))
+      (setq s (org-trim s))
+      (if (string-match (concat "^\\(" org-quote-string "\\|"
+				org-comment-string "\\)") s)
+	  (setq s (replace-match "" t t s)))
+      (while (string-match org-ts-regexp s)
+	(setq s (replace-match "" t t s))))
+    (while (string-match "[^a-zA-Z_0-9 \t]+" s)
+      (setq s (replace-match " " t t s)))
+    (or string (setq s (concat "*" s)))  ; Add * for headlines
+    (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
+
+(defun org-make-org-heading-camel (&optional string heading)
   "Make a CamelCase string for S or the current headline."
   (interactive)
   (let ((s (or string (org-get-heading))))
-    (unless string
+    (unless (and string (not heading))
       ;; We are using a headline, clean up garbage in there.
       (if (string-match org-todo-regexp s)
 	  (setq s (replace-match "" t t s)))
+      (if (string-match ":[a-zA-Z_@0-9:]+:[ \t]*$" s)
+	  (setq s (replace-match "" t t s)))
       (setq s (org-trim s))
       (if (string-match (concat "^\\(" org-quote-string "\\|"
 				org-comment-string "\\)") s)
@@ -7157,6 +7545,12 @@
   "Concatenate STRINGS, format resulting string with `org-link-format'."
   (format org-link-format (apply 'concat strings)))
 
+(defun org-make-link2 (link &optional description)
+  "Make a link with brackets."
+  (concat "[[" link "]"
+	  (if description (concat "[" description "]") "")
+	  "]"))
+
 (defun org-xor (a b)
   "Exclusive or."
   (if a (not b) b))
@@ -7245,15 +7639,18 @@
 	(let* ((path (match-string 1 link))
 	       (case-fold-search nil)
 	       (search (match-string 2 link)))
-	    (when (save-match-data
-		    (equal (file-truename (buffer-file-name))
-			   (file-truename path)))
-	      (if (save-match-data
-		    (string-match (concat "^" org-camel-regexp "$") search))
-		  (setq link (replace-match search t t link)
-			matched t)
-		(setq link (replace-match (concat "<file:::" search ">")
-					  t t link))))))
+	  (when (save-match-data
+		  (equal (file-truename (buffer-file-name))
+			 (file-truename path)))
+	    ;; We are linking to this same file
+	    (if (and org-file-link-context-use-camel-case
+		     (save-match-data
+		       (string-match (concat "^" org-camel-regexp "$") search)))
+		(setq link (replace-match search t t link)
+		      matched t)
+	      (setq link (replace-match (concat "[[" search "]]")
+					t t link)
+		    matched t)))))
       (let ((lines (org-split-string link "\n")))
 	(insert (car lines))
 	(setq matched (or matched (string-match org-link-regexp (car lines))))
@@ -9467,9 +9864,8 @@
 	    (and c (setq minor-mode-map-alist
 			 (cons c (delq c minor-mode-map-alist)))))
 	  (set (make-local-variable (quote org-table-may-need-update)) t)
-	  (make-local-hook (quote before-change-functions)) ; needed for XEmacs
-	  (add-hook 'before-change-functions 'org-before-change-function
-		    nil 'local)
+	  (org-add-hook 'before-change-functions 'org-before-change-function
+			nil 'local)
 	  (set (make-local-variable 'org-old-auto-fill-inhibit-regexp)
 	       auto-fill-inhibit-regexp)
 	  (set (make-local-variable 'auto-fill-inhibit-regexp)
@@ -9734,6 +10130,10 @@
        ((string-match "^#" line)
 	;; an ordinary comment line
 	)
+       ((and org-export-table-remove-special-lines
+	     (string-match "^[ \t]*| *[!_^] *|" line))
+	;; a special table line that should be removed
+	)
        (t (setq rtn (cons line rtn)))))
     (nreverse rtn)))
 
@@ -10587,7 +10987,7 @@
 			      (concat "<a href=\"" thefile "\">\\1:\\2</a>"))
 			    nil nil line))))
 
-	     ((member type '("bbdb" "vm" "wl" "rmail" "gnus" "shell"))
+	     ((member type '("bbdb" "vm" "wl" "mhe" "rmail" "gnus" "shell"))
 	      (setq line (replace-match
 			  "<i>&lt;\\1:\\2&gt;</i>" nil nil line)))))
 
@@ -10727,6 +11127,29 @@
   (setq lines (nreverse lines))
   (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
   (setq lines (nreverse lines))
+  (when org-export-table-remove-special-lines
+    ;; Check if the table has a marking column.  If yes remove the
+    ;; column and the special lines
+    (let* ((special
+	    (not
+	     (memq nil
+		   (mapcar
+		    (lambda (x)
+		      (or (string-match "^[ \t]*|-" x)
+			  (string-match "^[ \t]*| *\\([#!$*_^ ]\\) *|" x)))
+		    lines)))))
+      (if special
+	  (setq lines
+		(delq nil
+		      (mapcar
+		       (lambda (x)
+			 (if (string-match "^[ \t]*| *[!_^] *|" x)
+			     nil ; ignore this line
+			   (and (or (string-match "^[ \t]*|-+\\+" x)
+				    (string-match "^[ \t]*|[^|]*|" x))
+				(replace-match "|" t t x))))
+		       lines))))))
+  
   (let ((head (and org-export-highlight-first-table-line
 		   (delq nil (mapcar
 			      (lambda (x) (string-match "^[ \t]*|-" x))
@@ -11210,10 +11633,10 @@
 
 ;; - Bindings in Org-mode map are currently
 ;;   0123456789abcdefghijklmnopqrstuvwxyz!?@#$%^&-+*/=()_{}[]:;"|,.<>~`'\t  the alphabet
-;;             abcd fgh j lmnopqrstuvwxyz!? #$   -+*/=     [] ; |,.<>~  \t  necessary bindings
+;;             abcd fgh j lmnopqrstuvwxyz!? #$ ^ -+*/=     [] ; |,.<>~ '\t  necessary bindings
 ;;                 e                                                        (?) useful from outline-mode
 ;;                     i k                 @                                expendable from outline-mode
-;;   0123456789                               %^&     ()_{}    "      `'    free
+;;   0123456789                               % &     ()_{}    "      `     free
 
 ;; Make `C-c C-x' a prefix key
 (define-key org-mode-map "\C-c\C-x" (make-sparse-keymap))
@@ -11281,6 +11704,8 @@
 (define-key org-mode-map "\M-\C-m"  'org-insert-heading)
 (define-key org-mode-map "\C-c\C-l" 'org-insert-link)
 (define-key org-mode-map "\C-c\C-o" 'org-open-at-point)
+(define-key org-mode-map "\C-c%"    'org-mark-ring-push)
+(define-key org-mode-map "\C-c&"    'org-mark-ring-goto)
 (define-key org-mode-map "\C-c\C-z" 'org-time-stamp)  ; Alternative binding
 (define-key org-mode-map "\C-c."    'org-time-stamp)  ; Minor-mode reserved
 (define-key org-mode-map "\C-c!"    'org-time-stamp-inactive) ; Minor-mode r.
@@ -11594,6 +12019,7 @@
   (interactive "P")
   (let  ((org-enable-table-editor t))
     (cond
+     ((org-on-target-p) (org-update-radio-target-regexp))
      ((org-on-heading-p) (org-set-tags arg))
      ((org-at-table.el-p)
       (require 'table)
@@ -11935,6 +12361,11 @@
 
 ;; Functions needed for Emacs/XEmacs region compatibility
 
+(defun org-add-hook (hook function &optional append local)
+  "Add-hook, compatible with both Emacsen."
+  (if (and local org-xemacs-p) (make-local-hook hook)) ;; Needed for XEmacs
+  (add-hook hook function append local))
+
 (defun org-region-active-p ()
   "Is `transient-mark-mode' on and the region active?
 Works on both Emacs and XEmacs."
@@ -12030,6 +12461,19 @@
       (skip-chars-backward "^\r\n")
       (equal (char-before) ?\r))))
 
+(defun org-invisible-p2 ()
+  "Check if point is at a character currently not visible."
+  (save-excursion
+    (if org-noutline-p
+	(progn
+	  (if (and (eolp) (not (bobp))) (backward-char 1))
+	  ;; Early versions of noutline don't have `outline-invisible-p'.
+	  (if (fboundp 'outline-invisible-p)
+	      (outline-invisible-p)
+	    (get-char-property (point) 'invisible)))
+      (skip-chars-backward "^\r\n")
+      (equal (char-before) ?\r))))
+
 (defun org-back-to-heading (&optional invisible-ok)
   "Move to previous heading line, or beg of this line if it's a heading.
 Only visible heading lines are considered, unless INVISIBLE-OK is non-nil."
@@ -12058,6 +12502,16 @@
 	       (bobp)
 	       (equal (char-before) ?\n))))))
 
+(defun org-on-target-p ()
+  (let ((pos (point)))
+    (save-excursion
+      (skip-chars-forward "<")
+      (and (re-search-backward "<<" nil t)
+	   (or (looking-at org-target-regexp)
+	       (looking-at org-radio-target-regexp))
+	   (<= (match-beginning 0) pos)
+	   (>= (match-end 0) pos)))))
+
 (defun org-up-heading-all (arg)
   "Move to the heading line of which the present line is a subheading.
 This function considers both visible and invisible heading lines.
@@ -12195,4 +12649,3 @@
 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
 ;;; org.el ends here
 
-
--- a/lisp/textmodes/reftex-auc.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-auc.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-cite.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-cite.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-dcr.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-dcr.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 ;;
 
 ;; This file is part of GNU Emacs.
@@ -33,7 +33,7 @@
 (require 'reftex)
 ;;;
 
-(defun reftex-view-crossref (&optional arg auto-how)
+(defun reftex-view-crossref (&optional arg auto-how fail-quietly)
   "View cross reference of macro at point.  Point must be on the KEY
 argument.  When at at `\\ref' macro, show corresponding `\\label'
 definition, also in external documents (`xr').  When on a label, show
@@ -56,52 +56,53 @@
          dw)
 
     (if (or (null macro) (reftex-in-comment))
-        (error "Not on a crossref macro argument"))
-
-    (setq reftex-call-back-to-this-buffer (current-buffer))
+	(or fail-quietly
+	    (error "Not on a crossref macro argument"))
 
-    (cond
-     ((string-match "\\`\\\\cite\\|cite\\*?\\'\\|bibentry" macro)
-      ;; A citation macro: search for bibitems or BibTeX entries
-      (setq dw (reftex-view-cr-cite arg key auto-how)))
-     ((string-match "\\`\\\\ref\\|ref\\(range\\)?\\*?\\'" macro)
-      ;; A reference macro: search for labels
-      (setq dw (reftex-view-cr-ref arg key auto-how)))
-     (auto-how nil)  ;; No further action for automatic display (speed)
-     ((or (equal macro "\\label")
-          (member macro reftex-macros-with-labels))
-      ;; A label macro: search for reference macros
-      (reftex-access-scan-info arg)
-      (setq dw (reftex-view-regexp-match
-                (format reftex-find-reference-format (regexp-quote key))
-                4 nil nil)))
-     ((equal macro "\\bibitem")
-      ;; A bibitem macro: search for citations
-      (reftex-access-scan-info arg)
-      (setq dw (reftex-view-regexp-match
-                (format reftex-find-citation-regexp-format (regexp-quote key))
-                4 nil nil)))
-     ((member macro reftex-macros-with-index)
-      (reftex-access-scan-info arg)
-      (setq dw (reftex-view-regexp-match
-                (format reftex-find-index-entry-regexp-format
-                        (regexp-quote key))
-                3 nil nil)))
-     (t 
-      (reftex-access-scan-info arg)
-      (catch 'exit
-        (let ((list reftex-view-crossref-extra)
-              entry mre action group)
-          (while (setq entry (pop list))
-            (setq mre (car entry)
-                  action (nth 1 entry)
-                  group (nth 2 entry))
-            (when (string-match mre macro)
-              (setq dw (reftex-view-regexp-match 
-                        (format action key) group nil nil))
-              (throw 'exit t))))
-        (error "Not on a crossref macro argument"))))
-    (if (and (eq arg 2) (windowp dw)) (select-window dw))))
+      (setq reftex-call-back-to-this-buffer (current-buffer))
+      
+      (cond
+       ((string-match "\\`\\\\cite\\|cite\\*?\\'\\|bibentry" macro)
+	;; A citation macro: search for bibitems or BibTeX entries
+	(setq dw (reftex-view-cr-cite arg key auto-how)))
+       ((string-match "\\`\\\\ref\\|ref\\(range\\)?\\*?\\'" macro)
+	;; A reference macro: search for labels
+	(setq dw (reftex-view-cr-ref arg key auto-how)))
+       (auto-how nil)  ;; No further action for automatic display (speed)
+       ((or (equal macro "\\label")
+	    (member macro reftex-macros-with-labels))
+	;; A label macro: search for reference macros
+	(reftex-access-scan-info arg)
+	(setq dw (reftex-view-regexp-match
+		  (format reftex-find-reference-format (regexp-quote key))
+		  4 nil nil)))
+       ((equal macro "\\bibitem")
+	;; A bibitem macro: search for citations
+	(reftex-access-scan-info arg)
+	(setq dw (reftex-view-regexp-match
+		  (format reftex-find-citation-regexp-format (regexp-quote key))
+		  4 nil nil)))
+       ((member macro reftex-macros-with-index)
+	(reftex-access-scan-info arg)
+	(setq dw (reftex-view-regexp-match
+		  (format reftex-find-index-entry-regexp-format
+			  (regexp-quote key))
+		  3 nil nil)))
+       (t 
+	(reftex-access-scan-info arg)
+	(catch 'exit
+	  (let ((list reftex-view-crossref-extra)
+		entry mre action group)
+	    (while (setq entry (pop list))
+	      (setq mre (car entry)
+		    action (nth 1 entry)
+		    group (nth 2 entry))
+	      (when (string-match mre macro)
+		(setq dw (reftex-view-regexp-match 
+			  (format action key) group nil nil))
+		(throw 'exit t))))
+	  (error "Not on a crossref macro argument"))))
+      (if (and (eq arg 2) (windowp dw)) (select-window dw)))))
      
 (defun reftex-view-cr-cite (arg key how)
   ;; View crossreference of a ref cite.  HOW can have the values 
@@ -243,7 +244,7 @@
        (not (memq last-command '(reftex-view-crossref
                                  reftex-mouse-view-crossref)))
        ;; Quick precheck if this might be a relevant spot
-       ;; FIXME: Can fail with backslash in comment
+       ;; `reftex-view-crossref' will do a more thorough check.
        (save-excursion  
          (search-backward "\\" nil t)
          (looking-at "\\\\[a-zA-Z]*\\(cite\\|ref\\|bibentry\\)"))
@@ -252,9 +253,9 @@
            (let ((current-prefix-arg nil))
              (cond
               ((eq reftex-auto-view-crossref t)
-               (reftex-view-crossref -1 'echo))
+               (reftex-view-crossref -1 'echo 'quiet))
               ((eq reftex-auto-view-crossref 'window)
-               (reftex-view-crossref -1 'tmp-window))
+               (reftex-view-crossref -1 'tmp-window 'quiet))
               (t nil)))
          (error nil))))
 
@@ -267,7 +268,8 @@
   ;; Display crossref info in echo area.
   (cond
    ((null docstruct)
-    (message "%s" (substitute-command-keys (format reftex-no-info-message "ref"))))
+    (message "%s" 
+	     (substitute-command-keys (format reftex-no-info-message "ref"))))
    ((null entry)
     (message "ref: unknown label: %s" label))
    (t
@@ -301,7 +303,7 @@
                (if (and files (= (length all-files) (length files)))
                    (message "cite: no such database entry: %s" key)
                  (message "%s" (substitute-command-keys 
-                           (format reftex-no-info-message "cite"))))
+				(format reftex-no-info-message "cite"))))
                nil)))
       (when entry
         (if item
--- a/lisp/textmodes/reftex-global.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-global.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-index.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-index.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-parse.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-parse.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 ;;
 
 ;; This file is part of GNU Emacs.
--- a/lisp/textmodes/reftex-ref.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-ref.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-sel.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-sel.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-toc.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-toc.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
--- a/lisp/textmodes/reftex-vars.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex-vars.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 
 ;; This file is part of GNU Emacs.
 
@@ -1555,6 +1555,18 @@
   :type '(repeat (cons (string :tag "File type")
                        (repeat (string :tag "Extension")))))
 
+(defcustom reftex-try-all-extensions nil
+  "Non-nil means, try all extensions listed in `reftex-file-extensions'.
+When searching for a file, LaTeX uses only the default extension.  However,
+if you are working with a noweb system that produces the .tex files from
+some other file, and you want RefTeX to scan the web file instead of the
+tex file, you need to set this option.  You also need to make the noweb
+extension the default extension, i.e. the first in the list in
+`reftex-file-extensions'.
+Note that if you are using external file finders, this option has no effect."
+  :group 'reftex-finding-files
+  :type 'boolean)
+
 (defcustom reftex-search-unrecursed-path-first t
   "*Non-nil means, search all specified directories before trying recursion.
 Thus, in a path \".//:/tex/\", search first \"./\", then \"/tex/\" and then
--- a/lisp/textmodes/reftex.el	Thu Feb 23 02:59:27 2006 +0000
+++ b/lisp/textmodes/reftex.el	Thu Feb 23 03:17:52 2006 +0000
@@ -3,7 +3,7 @@
 ;;   2006 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: VERSIONTAG
+;; Version: 4.31
 ;; Keywords: tex
 
 ;; This file is part of GNU Emacs.
@@ -301,7 +301,7 @@
 ;;; Define the formal stuff for a minor mode named RefTeX.
 ;;;
 
-(defconst reftex-version "RefTeX version VERSIONTAG"
+(defconst reftex-version "RefTeX version 4.31"
   "Version string for RefTeX.")
 
 (defvar reftex-mode nil
@@ -1437,14 +1437,17 @@
                          "\\)\\'"))
          (files (if (string-match ext-re file)
                     (cons file nil)
-                  (cons (concat file def-ext) file)))
-         path old-path file1)
+		  (if reftex-try-all-extensions
+		      (append (mapcar (lambda (x) (concat file x))
+				      extensions)
+			      (list file))
+		    (list (concat file def-ext) file))))
+         path old-path file1 f fs)
     (cond
      ((file-name-absolute-p file)
-      (setq file1 
-            (or 
-             (and (car files) (file-regular-p (car files)) (car files))
-             (and (cdr files) (file-regular-p (cdr files)) (cdr files)))))
+      (while (setq f (pop files))
+	(if (file-regular-p f)
+	    (setq file1 f files nil))))
      ((and reftex-use-external-file-finders
            (assoc type reftex-external-file-finders))
       (setq file1 (reftex-find-file-externally file type master-dir)))
@@ -1452,16 +1455,13 @@
       (while (and (null file1) rec-values)
         (setq path (reftex-access-search-path
                     type (pop rec-values) master-dir file))
-        (if (or (null old-path)
-                (not (eq old-path path)))
-            (setq old-path path
-                  path (cons master-dir path)
-                  file1 (or (and (car files)
-                                 (reftex-find-file-on-path 
-                                  (car files) path master-dir))
-                            (and (cdr files)
-                                 (reftex-find-file-on-path 
-                                  (cdr files) path master-dir))))))))
+	(setq fs files)
+	(while (and (null file1) (setq f (pop fs)))
+	  (when (or (null old-path)
+		    (not (eq old-path path)))
+	    (setq old-path path
+		  path (cons master-dir path))
+	    (setq file1 (reftex-find-file-on-path f path master-dir)))))))
     (cond (file1 file1)
           (die (error "No such file: %s" file) nil)
           (t (message "No such file: %s (ignored)" file) nil))))
--- a/man/ChangeLog	Thu Feb 23 02:59:27 2006 +0000
+++ b/man/ChangeLog	Thu Feb 23 03:17:52 2006 +0000
@@ -1,3 +1,10 @@
+2006-02-22  Carsten Dominik  <dominik@science.uva.nl>
+
+	* reftex.texi: Version number and date change only.
+
+	* org.texi: (Internal Links): Rewritten to cover the modified
+	linking system.
+
 2006-02-21  Nick Roberts  <nickrob@snap.net.nz>
 
 	* building.texi (Watch Expressions): Update and describe
--- a/man/org.texi	Thu Feb 23 02:59:27 2006 +0000
+++ b/man/org.texi	Thu Feb 23 03:17:52 2006 +0000
@@ -4,8 +4,8 @@
 @setfilename ../info/org
 @settitle Org Mode Manual
 
-@set VERSION 4.04
-@set DATE January 2006
+@set VERSION 4.05
+@set DATE February 2006
 
 @dircategory Emacs
 @direntry
@@ -35,7 +35,7 @@
 @copying
 This manual is for Org-mode (version @value{VERSION}).
 
-Copyright @copyright{} 2004, 2005, 2006 Free Software Foundation, Inc.
+Copyright @copyright{} 2004, 2005, 2006 Free Software Foundation
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -126,12 +126,17 @@
 
 Hyperlinks
 
-* Internal Links::              CamelCaseWords as internal links
+* Internal Links::              Links to other places in the current file
 * External Links::              URL-like links to the world
 * Managing links::              Creating, inserting and following
 * Search Options::              Linking to a specific location
 * Remember::                    Org-trees store quick notes
 
+Internal Links
+
+* Radio targets::               Make targets trigger links in plain text.
+* CamelCase links::             Activating CamelCase words as links
+
 TODO items
 
 * TODO basics::                 Marking and displaying TODO entries
@@ -155,12 +160,12 @@
 * Agenda files::                Files being searched for agenda information
 * Agenda dispatcher::           Keyboard access to agenda views
 * Weekly/Daily Agenda::         The calendar page with current tasks
-* Global TODO list::            All infinished action items
+* Global TODO list::            All unfinished action items
 * Matching headline tags::      Structured information with fine-tuned search
 * Timeline::                    Time-sorted view for single file
 * Agenda commands::             Remote editing of org trees
 
-Weekly/Daily Agenda
+The weekly/daily agenda
 
 * Categories::                  Not all tasks are equal
 * Time-of-day specifications::  How the agenda knows the time
@@ -1314,7 +1319,8 @@
 
 Complex ASCII tables with automatic line wrapping, column- and
 row-spanning, and alignment can be created using the Emacs table
-package by Takaaki Ota (@uref{http://sourceforge.net/projects/table}).
+package by Takaaki Ota (@uref{http://sourceforge.net/projects/table},
+and also part of Emacs 22).
 When @key{TAB} or @kbd{C-c C-c} is pressed in such a table, Org-mode
 will call @command{table-recognize-table} and move the cursor into the
 table.  Inside a table, the keymap of Org-mode is inactive.  In order
@@ -1343,7 +1349,7 @@
 links to other files, Usenet articles, emails and much more.
 
 @menu
-* Internal Links::              CamelCaseWords as internal links
+* Internal Links::              Links to other places in the current file
 * External Links::              URL-like links to the world
 * Managing links::              Creating, inserting and following
 * Search Options::              Linking to a specific location
@@ -1356,44 +1362,73 @@
 @cindex links, internal
 @cindex CamelCase links
 
-Similar to Wiki implementations, Org-mode interprets words spelled in
-CamelCase (i.e. mixed case with at least one capital letter following
-on a small letter inside the word) as links.  While in Wiki these
-links usually point to another file, in Org-mode they point to a
-target in the current file.  Targets are CamelCased words in double
-angular brackets, and may be located anywhere, also in a comment line.
-For example
+Strings inside double brackets like @samp{[[My Target]]} are links
+that lead to a text search in the current file.  The link can be
+followed with @kbd{C-c C-o} or with a mouse click (@pxref{Managing
+links}).  The preferred match for such a link is a dedicated target:
+The same string in double angular brackets.  Targets may be located
+anywhere, often it is convenient to put them into a comment line, for
+example
 @example
-# <<MyTarget>>
+# <<My Target>>
 @end example
 
-Each occurrence of @samp{MyTarget} in the file is an active link that
-can be followed with @kbd{C-c C-o} or with a mouse click
-(@pxref{Managing links}).  If no dedicated target exists, org-mode will
-search for the words in the link separated by white space, in the
-above example for @samp{my target}.  If the link starts with a star
-like @samp{*MyTarget}, the search is restricted to headlines.
-Org-mode will first try an exact match of a full headline, but then
-move on to more and more lenient searches.  The link @samp{*MyTargets}
-will find any of the following
+If no dedicated target exists, Org-mode will search for the words in
+the link, in the above example for @samp{my target}.  Links starting
+with a star like @samp{*My Target} restrict the search to headlines.
+When searching, Org-mode will first try an exact match, but then move
+on to more and more lenient searches.  For example, the link
+@samp{[[*My Targets]]} will find any of the following
 @example
 ** My targets
 ** TODO my targets are bright
 ** my 20 targets are
 @end example
+It is therefore often not necessary to set a dedicated target.  To
+insert a link targeting a headline, in-buffer completion can be used.
+Just type a star followed by a few optional letters into the buffer
+and press @kbd{M-@key{TAB}}.  All headlines in the current buffer will
+be offered as completions.  @xref{Managing links}, for more commands
+creating links.
+
+Following a link pushes a mark onto Org-mode's own mark ring.  You can
+return to the previous position with @kbd{C-c &}.  Using this command
+several times in direct succession goes back to positions recorded
+earlier.
+
+@menu
+* Radio targets::               Make targets trigger links in plain text.
+* CamelCase links::             Activating CamelCase words as links
+@end menu
+
+@node Radio targets, CamelCase links, Internal Links, Internal Links
+@subsection Radio targets
+
+You can configure Org-mode to link any occurrences of certain target
+names in normal text.  So without explicitly creating a link, the text
+connects to the target radioing its position.  Radio targets are
+enclosed by triple angular brackets.  For example, a target
+@samp{<<<My Target>>>} causes each occurrence of @samp{my target} in
+normal text to become activated as a link.  The Org-mode file is
+scanned automatically for radio targets only when the file is first
+loaded into Emacs.  To update the target list during editing, press
+@kbd{C-c C-c} with the cursor on or at a target.
+
+@node CamelCase links,  , Radio targets, Internal Links
+@subsection CamelCase words as links
 @cindex completion, of CamelCase links
 @cindex CamelCase links, completion of
-It is therefore often not even necessary to set a dedicated target.
-The link will automatically find a target.  If you want to see what
-lines in the current buffer are matched by a given CamelCase link,
-open the link with @kbd{C-u C-c C-o}.  Even if there are several
-matches, org-mode will usually find the right one since it tries
-targets and exact matches first.  To insert links targeting a
-headline, in-buffer completion can be used.  Just type a star followed
-by a few optional letters into the buffer and press @kbd{M-@key{TAB}}.
-CamelCased versions of all headlines in the current buffer will be
-offered as completions.  @xref{Managing links}, for more commands
-creating links.
+
+As an alternative to @samp{[[...]]} links, Org-mode also supports
+CamelCase words as links.  This feature is not turned on by default
+because of the occasional inconsistencies this system suffers from.
+To activate CamelCase words as links, and to make headline completion
+offer CamelCase version of headlines, the following customization is
+needed:
+@lisp
+(setq org-activate-camels t
+      org-file-link-context-use-camel-case t)
+@end lisp
 
 @node External Links, Managing links, Internal Links, Hyperlinks
 @section External Links
@@ -1407,6 +1442,7 @@
 @cindex VM links
 @cindex RMAIL links
 @cindex WANDERLUST links
+@cindex MH-E links
 @cindex USENET links
 @cindex SHELL links
 
@@ -1426,6 +1462,8 @@
 <vm://myself@@some.where.org/folder#id>     @r{VM on remote machine}
 <wl:folder>                                @r{WANDERLUST folder link}
 <wl:folder#id>                             @r{WANDERLUST message link}
+<mhe:folder>                               @r{MH-E folder link}
+<mhe:folder#id>                            @r{MH-E message link}
 <rmail:folder>                             @r{RMAIL folder link}
 <rmail:folder#id>                          @r{RMAIL message link}
 <gnus:group>                               @r{GNUS group link}
@@ -1458,7 +1496,7 @@
 the current article/entry.  For W3 and W3M buffer, the link goes to
 the current URL.  For Org-mode files, the current headline is
 targeted.  For any other files, the link will point to the file, with
-a CamelCase (@pxref{Search Options}) search string pointing to the
+a search string (@pxref{Search Options}) pointing to the
 contents of the current line.  If there is an active region, the
 selected words will form the basis of the search string.  The key
 binding @kbd{C-c l} is only a suggestion - see @ref{Installation and
@@ -1510,6 +1548,20 @@
 @kindex mouse-3
 @item mouse-3
 Like @kbd{mouse-2}, but force file links to be opened with Emacs.
+
+@cindex mark ring
+@kindex C-c %
+@item C-c %
+Push the current position onto the mark ring, to be able to return
+easily. Commands following an internal link do this automatically.
+
+@cindex links, returning to
+@kindex C-c &
+@item C-c &
+Jump back to a recorded position.  A position is recorded by the
+commands following internal links, and by @kbd{C-c %}.  Using this
+command several times in direct succession moves through a ring of
+previously recorded positions.
 @end table
 
 
@@ -1525,8 +1577,8 @@
 For example:
 @example
 <file:~/code/main.c::255>
-<file:~/xx.org::MyTarget>
-<file:~/xx.org::find me>
+<file:~/xx.org::My Target>
+<file:~/xx.org::*My Target>
 <file:~/xx.org::/regexp/>
 @end example
 @noindent Here is what these options do.
@@ -1534,12 +1586,12 @@
 @table @code
 @item 255
 Jump to line 255.
-@item MyGoal
-Search for a link target with name MyGoal, or do a text search for
-@samp{my target}, similar to the CamelCase search in internal links,
-see @ref{Internal Links}.
-@item find me
-Do a normal text search for the text @samp{find me}.
+@item My Target
+Search for a link target @samp{<<My Target>>}, or do a text search for
+@samp{my target}, similar to the search in internal links, see
+@ref{Internal Links}.
+@item *My Target
+In an Org-mode file, restrict search to headlines.
 @item /regexp/
 Do a regular expression search for @code{regexp}.  This uses the Emacs
 command @code{occur} to list all matches in a separate window.  If the
@@ -1549,10 +1601,10 @@
 @c @code{grep} will be used to search all files in the directory.
 @end table
 
-To use the search options also for a search in the current file, a
-file link with an empty file name can be used.  For example,
-@code{<file:::find me>} does a search for @samp{find me} in the
-current file.
+As a degenerate case, a file link with an empty file name can be used
+to search the current file.  For example, @code{<file:::find me>} does
+a search for @samp{find me} in the current file, just like
+@samp{[[find me]]} would.
 
 @node Remember,  , Search Options, Hyperlinks
 @section Remember
@@ -3248,6 +3300,8 @@
 
 @itemize @bullet
 @item
+Thomas Baumann contributed the code for links to the MH-E email system.
+@item
 Pavel Chalmoviansky reported bugs and suggested improvements
 related to the agenda treatment of items with specified time.
 @item
@@ -3267,7 +3321,7 @@
 Tim O'Callaghan suggested in-file links, search options for
 general file links, and TAGS.
 @item
-Oliver Oppitz made useful suggestions.
+Oliver Oppitz suggested multi-state TODO items.
 @item
 Pete Phillips helped the development of the TAGS feature with beta
 testing and suggestions.
@@ -3289,8 +3343,8 @@
 Juergen Vollmer contributed code generating the table of contents
 in HTML output, and other export improvements.
 @item
-David Wainberg suggested to implement an archiving mechanism and helped
-testing.
+David Wainberg suggested the archiving mechanism and shaped the
+internal link system with many suggestions and ideas.
 @item
 Scheduling TODO items was inspired by John Wiegley's @file{planner.el}.
 @item
--- a/man/reftex.texi	Thu Feb 23 02:59:27 2006 +0000
+++ b/man/reftex.texi	Thu Feb 23 03:17:52 2006 +0000
@@ -7,9 +7,9 @@
 @syncodeindex fn cp
 
 @c Version and Contact Info
-@set VERSION 4.30
-@set EDITION 4.30
-@set DATE September 2005
+@set VERSION 4.31
+@set EDITION 4.31
+@set DATE February 2006
 @set AUCTEXSITE @uref{http://www.nongnu.org/auctex/,AUCTeX distribution site}
 @set MAINTAINERSITE @uref{http://www.astro.uva.nl/~dominik/Tools/,maintainers webpage}
 @set MAINTAINER Carsten Dominik
@@ -25,8 +25,7 @@
 This is edition @value{EDITION} of the @b{Ref@TeX{}} User Manual for
 @b{Ref@TeX{}} @value{VERSION}
 
-Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005,
-   2006 Free Software Foundation, Inc.
+Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
--- a/src/ChangeLog	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/ChangeLog	Thu Feb 23 03:17:52 2006 +0000
@@ -1,3 +1,35 @@
+2006-02-22  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* window.c (Fwindow_list): Check `window' before doing XWINDOW.
+	The default `window' should not be "on a different frame".
+
+2006-02-22  Kim F. Storm  <storm@cua.dk>
+
+	* indent.c (Fvertical_motion): Only try to move back if we can.
+
+2006-02-22  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+	* macgui.h (struct _XGC) [!MAC_OSX || !USE_ATSUI]: New member
+	n_clip_rects.
+
+	* macmenu.c (digest_single_submenu): Apply 2006-02-19 change for
+	xmenu.c.
+
+	* macterm.c (GC_CLIP_REGION): Remove macro.
+	(mac_begin_clip, mac_end_clip): Take arg GC instead of REGION.
+	All uses changed.  Don't do clipping if n_clip_rects is zero.
+	(mac_set_clip_rectangles): Use xassert instead of abort.
+	Set n_clip_rects.  Don't make clip_region empty when number of
+	clipping rectangles is zero.
+	(mac_reset_clip_rectangles): Set n_clip_rects directly instead of
+	calling mac_set_clip_rectangles.
+	(x_set_toolkit_scroll_bar_thumb): Temporarily hide scroll bar to
+	avoid multiple redraws.
+
+2006-02-22  Kim F. Storm  <storm@cua.dk>
+
+	* fringe.c (draw_fringe_bitmap): Fix overlay-arrow display.
+
 2006-02-21  Kim F. Storm  <storm@cua.dk>
 
 	* fringe.c (syms_of_fringe) <fringe-bitmaps>: Doc fix.
@@ -18,8 +50,8 @@
 	BG_WIDTH.  All uses changed.  Draw background if BG_WIDTH is not zero.
 	(mac_draw_image_string, mac_draw_image_string_16): New arg BG_WIDTH.
 	[USE_CG_TEXT_DRAWING] (mac_draw_image_string_cg): Rename from
-	mac_draw_string_cg.  New arg BG_WIDTH.  All uses changed.  Draw
-	background if BG_WIDTH is not zero.  Use float constants as
+	mac_draw_string_cg.  New arg BG_WIDTH.  All uses changed.
+	Draw background if BG_WIDTH is not zero.  Use float constants as
 	divisors instead of double.  Use alloca instead of xmalloc/xfree.
 	(x_draw_glyph_string_background, x_draw_glyph_string_foreground)
 	[!MAC_OS8 || USE_ATSUI]: Background may be drawn using
@@ -30,6 +62,11 @@
 	(mac_set_clip_rectangles): When resetting clip region, make it
 	empty instead of disposing of it.
 
+2006-02-20  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* keymap.c (store_in_keymap): Change `def' arg to not be `register'.
+	Seems to trigger a bug in gcc-amd64 4.0.2 20051125 (Red Hat 4.0.2-8).
+
 2006-02-20  Kim F. Storm  <storm@cua.dk>
 
 	* Makefile.in: Add fringe.elc to WINDOW_SUPPORT.
@@ -55,10 +92,10 @@
 	(left_curly_arrow_bits): Rename from continuation_bits.
 	(right_curly_arrow_bits): Rename from continued_bits.
 	(left_triangle_bits): Rename from ov_bits.
-	(right_triangle_bits): Added.
+	(right_triangle_bits): Add.
 	(filled_rectangle_bits): Rename from filled_box_cursor_bits.
 	(hollow_rectangle_bits): Rename from hollow_box_cursor_bits.
-	(filled_square_bits): Added.
+	(filled_square_bits): Add.
 	(vertical_bar_bits): Rename from bar_cursor_bits.
 	(horizontal_bar_bits): Rename from hbar_cursor_bits.
 	(empty_line_bits): Rename from zv_bits.
--- a/src/fringe.c	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/fringe.c	Thu Feb 23 03:17:52 2006 +0000
@@ -869,7 +869,7 @@
   if (left_p && row->overlay_arrow_bitmap != NO_FRINGE_BITMAP)
     draw_fringe_bitmap_1 (w, row, 1, 1,
 			  (row->overlay_arrow_bitmap < 0
-			   ? get_logical_cursor_bitmap (w, Qoverlay_arrow)
+			   ? get_logical_fringe_bitmap (w, Qoverlay_arrow, 0, 0)
 			   : row->overlay_arrow_bitmap));
 }
 
--- a/src/indent.c	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/indent.c	Thu Feb 23 03:17:52 2006 +0000
@@ -2109,7 +2109,8 @@
       it.vpos = 0;
       /* Do this even if LINES is 0, so that we move back
 	 to the beginning of the current line as we ought.  */
-      move_it_by_lines (&it, XINT (lines), 0);
+      if (XINT (lines) >= 0 || IT_CHARPOS (it) > 0)
+	move_it_by_lines (&it, XINT (lines), 0);
 
       SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
     }
--- a/src/macgui.h	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/macgui.h	Thu Feb 23 03:17:52 2006 +0000
@@ -217,13 +217,13 @@
   RGBColor back_color;
 
 #define MAX_CLIP_RECTS 2
-  /* QuickDraw clipping region.  */
+  /* Number of clipping rectangles.  */
+  int n_clip_rects;
+
+  /* QuickDraw clipping region.  Ignored if n_clip_rects == 0.  */
   RgnHandle clip_region;
 
 #if defined (MAC_OSX) && USE_ATSUI
-  /* Number of clipping rectangles used in Quartz 2D drawing.  */
-  int n_clip_rects;
-
   /* Clipping rectangles used in Quartz 2D drawing.  The y-coordinate
      is in QuickDraw's.  */
   CGRect clip_rects[MAX_CLIP_RECTS];
--- a/src/macmenu.c	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/macmenu.c	Thu Feb 23 03:17:52 2006 +0000
@@ -1257,8 +1257,11 @@
 	      wv->enabled = 1;
 	      wv->button_type = BUTTON_TYPE_NONE;
 	      wv->help = Qnil;
+	      save_wv = wv;
 	    }
-	  save_wv = wv;
+	  else
+	    save_wv = first_wv;
+
 	  prev_wv = 0;
 	  i += MENU_ITEMS_PANE_LENGTH;
 	}
--- a/src/macterm.c	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/macterm.c	Thu Feb 23 03:17:52 2006 +0000
@@ -267,14 +267,13 @@
 #define GC_FORE_COLOR(gc)	(&(gc)->fore_color)
 #define GC_BACK_COLOR(gc)	(&(gc)->back_color)
 #define GC_FONT(gc)		((gc)->xgcv.font)
-#define GC_CLIP_REGION(gc)	((gc)->clip_region)
 #define FRAME_NORMAL_GC(f)	((f)->output_data.mac->normal_gc)
 
 static RgnHandle saved_port_clip_region = NULL;
 
 static void
-mac_begin_clip (region)
-     RgnHandle region;
+mac_begin_clip (gc)
+     GC gc;
 {
   static RgnHandle new_region = NULL;
 
@@ -283,19 +282,19 @@
   if (new_region == NULL)
     new_region = NewRgn ();
 
-  if (region && !EmptyRgn (region))
+  if (gc->n_clip_rects)
     {
       GetClip (saved_port_clip_region);
-      SectRgn (saved_port_clip_region, region, new_region);
+      SectRgn (saved_port_clip_region, gc->clip_region, new_region);
       SetClip (new_region);
     }
 }
 
 static void
-mac_end_clip (region)
-     RgnHandle region;
-{
-  if (region && !EmptyRgn (region))
+mac_end_clip (gc)
+     GC gc;
+{
+  if (gc->n_clip_rects)
     SetClip (saved_port_clip_region);
 }
 
@@ -323,10 +322,10 @@
 
   RGBForeColor (GC_FORE_COLOR (gc));
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   MoveTo (x1, y1);
   LineTo (x2, y2);
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 }
 
 void
@@ -367,9 +366,9 @@
   RGBBackColor (GC_BACK_COLOR (gc));
   SetRect (&r, x, y, x + width, y + height);
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   EraseRect (&r);
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 
   RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
 }
@@ -432,7 +431,7 @@
   RGBBackColor (GC_BACK_COLOR (gc));
   SetRect (&r, x, y, x + width, y + height);
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
 #if TARGET_API_MAC_CARBON
   {
     CGrafPtr port;
@@ -447,7 +446,7 @@
   CopyBits (&bitmap, &(FRAME_MAC_WINDOW (f)->portBits), &(bitmap.bounds), &r,
 	    overlay_p ? srcOr : srcCopy, 0);
 #endif /* not TARGET_API_MAC_CARBON */
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 
   RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
 }
@@ -579,9 +578,9 @@
   RGBForeColor (GC_FORE_COLOR (gc));
   SetRect (&r, x, y, x + width, y + height);
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   PaintRect (&r); /* using foreground color of gc */
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 }
 
 
@@ -601,9 +600,9 @@
   RGBForeColor (GC_FORE_COLOR (gc));
   SetRect (&r, x, y, x + width + 1, y + height + 1);
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   FrameRect (&r); /* using foreground color of gc */
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 }
 
 
@@ -718,7 +717,7 @@
       if (!mac_use_core_graphics)
 	{
 #endif
-	  mac_begin_clip (GC_CLIP_REGION (gc));
+	  mac_begin_clip (gc);
 	  RGBForeColor (GC_FORE_COLOR (gc));
 	  if (bg_width)
 	    {
@@ -734,7 +733,7 @@
 	  ATSUDrawText (text_layout,
 			kATSUFromTextBeginning, kATSUToTextEnd,
 			kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
-	  mac_end_clip (GC_CLIP_REGION (gc));
+	  mac_end_clip (gc);
 #ifdef MAC_OSX
 	}
       else
@@ -807,7 +806,7 @@
       if (mac_use_core_graphics)
 	savedFlags = SwapQDTextFlags (kQDUseCGTextRendering);
 #endif
-      mac_begin_clip (GC_CLIP_REGION (gc));
+      mac_begin_clip (gc);
       RGBForeColor (GC_FORE_COLOR (gc));
 #ifdef MAC_OS8
       if (bg_width)
@@ -843,7 +842,7 @@
       DrawText (buf, 0, nchars * bytes_per_char);
       if (bg_width)
 	RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
-      mac_end_clip (GC_CLIP_REGION (gc));
+      mac_end_clip (gc);
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
       if (mac_use_core_graphics)
@@ -1185,7 +1184,7 @@
   ForeColor (blackColor);
   BackColor (whiteColor);
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   LockPixels (GetGWorldPixMap (src));
 #if TARGET_API_MAC_CARBON
   {
@@ -1203,7 +1202,7 @@
 	    &src_r, &dest_r, srcCopy, 0);
 #endif /* not TARGET_API_MAC_CARBON */
   UnlockPixels (GetGWorldPixMap (src));
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 
   RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
 }
@@ -1229,7 +1228,7 @@
   ForeColor (blackColor);
   BackColor (whiteColor);
 
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   LockPixels (GetGWorldPixMap (src));
   LockPixels (GetGWorldPixMap (mask));
 #if TARGET_API_MAC_CARBON
@@ -1249,7 +1248,7 @@
 #endif /* not TARGET_API_MAC_CARBON */
   UnlockPixels (GetGWorldPixMap (mask));
   UnlockPixels (GetGWorldPixMap (src));
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 
   RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
 }
@@ -1287,9 +1286,9 @@
      color mapping in CopyBits.  Otherwise, it will be slow.  */
   ForeColor (blackColor);
   BackColor (whiteColor);
-  mac_begin_clip (GC_CLIP_REGION (gc));
+  mac_begin_clip (gc);
   CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0);
-  mac_end_clip (GC_CLIP_REGION (gc));
+  mac_end_clip (gc);
 
   RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
 #endif /* not TARGET_API_MAC_CARBON */
@@ -1425,14 +1424,10 @@
 {
   int i;
 
-  if (n < 0 || n > MAX_CLIP_RECTS)
-    abort ();
-  if (n == 0)
-    {
-      if (gc->clip_region)
-	SetEmptyRgn (gc->clip_region);
-    }
-  else
+  xassert (n >= 0 && n <= MAX_CLIP_RECTS);
+
+  gc->n_clip_rects = n;
+  if (n > 0)
     {
       if (gc->clip_region == NULL)
 	gc->clip_region = NewRgn ();
@@ -1450,8 +1445,6 @@
 	}
     }
 #if defined (MAC_OSX) && USE_ATSUI
-  gc->n_clip_rects = n;
-
   for (i = 0; i < n; i++)
     {
       Rect *rect = rectangles + i;
@@ -1471,7 +1464,7 @@
      Display *display;
      GC gc;
 {
-  mac_set_clip_rectangles (display, gc, NULL, 0);
+  gc->n_clip_rects = 0;
 }
 
 
@@ -4536,8 +4529,7 @@
      int portion, position, whole;
 {
   ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar);
-
-  int value, viewsize, maximum;
+  int value, viewsize, maximum, visible_p;
 
   if (whole == 0 || XINT (bar->track_height) == 0)
     value = 0, viewsize = 1, maximum = 0;
@@ -4550,11 +4542,17 @@
 
   BLOCK_INPUT;
 
+  /* Temporarily hide the scroll bar to avoid multiple redraws.  */
+  visible_p = IsControlVisible (ch);
+  SetControlVisibility (ch, false, false);
+
   SetControl32BitMinimum (ch, 0);
   SetControl32BitMaximum (ch, maximum);
   SetControl32BitValue (ch, value);
   SetControlViewSize (ch, viewsize);
 
+  SetControlVisibility (ch, visible_p, true);
+
   UNBLOCK_INPUT;
 }
 
--- a/src/window.c	Thu Feb 23 02:59:27 2006 +0000
+++ b/src/window.c	Thu Feb 23 03:17:52 2006 +0000
@@ -1863,7 +1863,8 @@
      Lisp_Object frame, minibuf, window;
 {
   if (NILP (window))
-    window = selected_window;
+    window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
+  CHECK_WINDOW (window);
   if (NILP (frame))
     frame = selected_frame;