emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/lisp/textmodes/org.el


From: Carsten Dominik
Subject: [Emacs-diffs] Changes to emacs/lisp/textmodes/org.el
Date: Fri, 29 Apr 2005 04:40:22 -0400

Index: emacs/lisp/textmodes/org.el
diff -c emacs/lisp/textmodes/org.el:1.14 emacs/lisp/textmodes/org.el:1.15
*** emacs/lisp/textmodes/org.el:1.14    Sat Apr 16 14:50:10 2005
--- emacs/lisp/textmodes/org.el Fri Apr 29 08:40:22 2005
***************
*** 5,11 ****
  ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
  ;; Keywords: outlines, hypermedia, calendar
  ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
! ;; Version: 3.06
  ;;
  ;; This file is part of GNU Emacs.
  ;;
--- 5,11 ----
  ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
  ;; Keywords: outlines, hypermedia, calendar
  ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
! ;; Version: 3.08
  ;;
  ;; This file is part of GNU Emacs.
  ;;
***************
*** 79,84 ****
--- 79,94 ----
  ;;
  ;; Changes:
  ;; -------
+ ;; Version 3.08
+ ;;    - "|" no longer allowed as part of a link, to allow links in tables.
+ ;;    - The prefix of items in the agenda buffer can be configured.
+ ;;    - Cleanup.
+ ;;
+ ;; Version 3.07
+ ;;    - Some folding incinsistencies removed.
+ ;;    - BBDB links to company-only entries.
+ ;;    - Bug fixes and global cleanup.
+ ;;
  ;; Version 3.06
  ;;    - M-S-RET inserts a new TODO heading.
  ;;    - New startup option `content'.
***************
*** 131,144 ****
  
  ;;; Code:
  
! (eval-when-compile (require 'cl))
  (require 'outline)
  (require 'time-date)
  (require 'easymenu)
  
  ;;; Customization variables
  
! (defvar org-version "3.06"
    "The version number of the file org.el.")
  (defun org-version ()
    (interactive)
--- 141,154 ----
  
  ;;; Code:
  
! (eval-when-compile (require 'cl) (require 'calendar))
  (require 'outline)
  (require 'time-date)
  (require 'easymenu)
  
  ;;; Customization variables
  
! (defvar org-version "3.08"
    "The version number of the file org.el.")
  (defun org-version ()
    (interactive)
***************
*** 194,201 ****
  the following lines anywhere in the buffer:
  
     #+STARTUP: dlcheck
!    #+STARTUP: nodlcheck
! "
    :group 'org-startup
    :type 'boolean)
  
--- 204,210 ----
  the following lines anywhere in the buffer:
  
     #+STARTUP: dlcheck
!    #+STARTUP: nodlcheck"
    :group 'org-startup
    :type 'boolean)
  
***************
*** 215,222 ****
    :group 'org)
  
  (defcustom org-todo-keywords '("TODO" "DONE")
!   "List of TODO entry keywords.\\<org-mode-map>
! By default, this is '(\"TODO\" \"DONE\").  The last entry in the list is
  considered to mean that the entry is \"done\".  All the other mean that
  action is required, and will make the entry show up in todo lists, diaries
  etc.
--- 224,231 ----
    :group 'org)
  
  (defcustom org-todo-keywords '("TODO" "DONE")
!   "List of TODO entry keywords.
! \\<org-mode-map>By default, this is '(\"TODO\" \"DONE\").  The last entry in 
the list is
  considered to mean that the entry is \"done\".  All the other mean that
  action is required, and will make the entry show up in todo lists, diaries
  etc.
***************
*** 228,235 ****
    :type '(repeat (string :tag "Keyword")))
  
  (defcustom org-todo-interpretation 'sequence
!   "Controls how TODO keywords are interpreted.\\<org-mode-map>
! Possible values are `sequence' and `type'.
  This variable is only relevant if `org-todo-keywords' contains more than two
  states.  There are two ways how these keywords can be used:
  
--- 237,244 ----
    :type '(repeat (string :tag "Keyword")))
  
  (defcustom org-todo-interpretation 'sequence
!   "Controls how TODO keywords are interpreted.
! \\<org-mode-map>Possible values are `sequence' and `type'.
  This variable is only relevant if `org-todo-keywords' contains more than two
  states.  There are two ways how these keywords can be used:
  
***************
*** 256,262 ****
  RELAXED will not be changed REMIND, but directly to DONE.
  
  You can create a large number of types.  To initially select a
! type, it is then best to use C-u \\[org-todo] in order to specify the
  type with completion.  Of course, you can also type the keyword
  directly into the buffer.  M-TAB completes TODO keywords at the
  beginning of a headline."
--- 265,271 ----
  RELAXED will not be changed REMIND, but directly to DONE.
  
  You can create a large number of types.  To initially select a
! type, it is then best to use \\[universal-argument] \\[org-todo] in order to 
specify the
  type with completion.  Of course, you can also type the keyword
  directly into the buffer.  M-TAB completes TODO keywords at the
  beginning of a headline."
***************
*** 304,310 ****
  (defcustom org-after-todo-state-change-hook nil
    "Hook which is run after the state of a TODO item was changed.
  The new state (a string with a todo keyword, or nil) is available in the
! lisp variable `state'."
    :group 'org-keywords
    :type 'hook)
  
--- 313,319 ----
  (defcustom org-after-todo-state-change-hook nil
    "Hook which is run after the state of a TODO item was changed.
  The new state (a string with a todo keyword, or nil) is available in the
! Lisp variable `state'."
    :group 'org-keywords
    :type 'hook)
  
***************
*** 313,319 ****
    "Do TODO items have priorities?")
  (make-variable-buffer-local 'org-todo-kwd-priority-p)
  (defvar org-todo-kwd-max-priority nil
!   "Maximum priority of TODO items")
  (make-variable-buffer-local 'org-todo-kwd-max-priority)
  (defvar org-ds-keyword-length 12
    "Maximum length of the Deadline and SCHEDULED keywords.")
--- 322,328 ----
    "Do TODO items have priorities?")
  (make-variable-buffer-local 'org-todo-kwd-priority-p)
  (defvar org-todo-kwd-max-priority nil
!   "Maximum priority of TODO items.")
  (make-variable-buffer-local 'org-todo-kwd-max-priority)
  (defvar org-ds-keyword-length 12
    "Maximum length of the Deadline and SCHEDULED keywords.")
***************
*** 352,357 ****
--- 361,375 ----
    "Matches the SCHEDULED keyword together with a time stamp.")
  (make-variable-buffer-local 'org-scheduled-time-regexp)
  
+ (defvar org-category nil
+   "Variable used by org files to set a category for agenda display.
+ Such files should use a file variable to set it, for example
+ 
+    -*- mode: org; org-category: \"ELisp\"
+ 
+ If the file does not specify a category, the file's base name
+ is used instead.")
+ 
  (defun org-set-regexps-and-options ()
    "Precompute regular expressions for current buffer."
    (when (eq major-mode 'org-mode)
***************
*** 359,366 ****
                 '("CATEGORY" "SEQ_TODO" "PRI_TODO" "TYP_TODO" "STARTUP")))
            (splitre "[ \t]+")
            kwds int key value cat)
!       (save-restriction
!         (save-excursion
            (widen)
            (goto-char (point-min))
            (while (re-search-forward re nil t)
--- 377,384 ----
                 '("CATEGORY" "SEQ_TODO" "PRI_TODO" "TYP_TODO" "STARTUP")))
            (splitre "[ \t]+")
            kwds int key value cat)
!       (save-excursion
!         (save-restriction
            (widen)
            (goto-char (point-min))
            (while (re-search-forward re nil t)
***************
*** 383,389 ****
                (let ((opts (org-split-string value splitre))
                      (set '(("fold" org-startup-folded t)
                             ("nofold" org-startup-folded nil)
!                            ("content" org-startup-folded 'content)
                             ("dlcheck" org-startup-with-deadline-check t)
                             ("nodlcheck" org-startup-with-deadline-check nil)))
                      l var val)
--- 401,407 ----
                (let ((opts (org-split-string value splitre))
                      (set '(("fold" org-startup-folded t)
                             ("nofold" org-startup-folded nil)
!                            ("content" org-startup-folded content)
                             ("dlcheck" org-startup-with-deadline-check t)
                             ("nodlcheck" org-startup-with-deadline-check nil)))
                      l var val)
***************
*** 515,522 ****
    :type 'boolean)
  
  (defcustom org-agenda-include-diary nil
!   "Non-nil means, when preparing the agenda, also get the
! entries from the emacs calendars diary."
    :group 'org-agenda
    :type 'boolean)
  
--- 533,539 ----
    :type 'boolean)
  
  (defcustom org-agenda-include-diary nil
!   "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
    :group 'org-agenda
    :type 'boolean)
  
***************
*** 566,571 ****
--- 583,625 ----
             (const priority-up)
             (const priority-down))))
  
+ (defcustom org-agenda-prefix-format "  %-12:c% s"
+   "Format specification for the prefix of items in the agenda buffer.
+ This format works similar to a printf format, with the following meaning:
+ 
+   %c   the category of the item, \"Diary\" for entries from the diary, or
+        as given by the CATEGORY keyword or derived from the file name.
+   %t   the time-of-day specification if one applies to the entry, in the
+        format HH:MM
+   %s   Scheduling/Deadline information, a short string
+ 
+ In addition to the normal printf field modifiers like field width and
+ padding instructions, in this format you can also add an additional
+ punctuation or whitespace character just before the final format letter.
+ This character will be appended to the field value if the value is not
+ empty.  For example, the format \"%-12:c\" leads to \"Diary:    \" if
+ the category is \"Diary\".  If the category were be empty, no additional
+ colon would be interted.
+ 
+ Including `%t' in the format string leads to a double time specification
+ because the headline/diary item will contain the time specification as
+ well.  However, using `%t' in the format will result in a canonical 24
+ hour time specification at a consistent position in the prefix, while the
+ time specification in the headline/diary item may be at any position and in
+ various formats.
+ Example:
+   (setq org-agenda-prefix-format \"  %-12:c% t% s\")"
+   :type 'string
+   :group 'org-agenda)
+ 
+ (defcustom org-timeline-prefix-format "  % s"
+   "Like `org-agenda-prefix-format', but for the timeline of a single file."
+   :type 'string
+   :group 'org-agenda)
+ 
+ (defvar org-prefix-format-compiled nil
+   "The compiled version of `org-???-prefix-format'.")
+ 
  (defcustom org-sort-agenda-notime-is-late t
    "Non-nil means, items without time are considered late.
  This is only relevant for sorting.  When t, items which have no explicit
***************
*** 574,588 ****
    :group 'org-agenda
    :type 'boolean)
  
- (defvar org-category nil
-   "Variable used by org files to set a category for agenda display.
- Such files should use a file variable to set it, for example
- 
-    -*- mode: org; org-category: \"ELisp\"
- 
- If the file does not specify a category, the file's base name
- is used instead.")
- 
  (defgroup org-structure nil
    "Options concerning structure editing in Org-mode."
    :tag "Org Structure"
--- 628,633 ----
***************
*** 647,653 ****
  
  (defcustom org-allow-space-in-links t
    "Non-nil means, file names in links may contain space characters.
! When nil, it becomes possible to put several links into a line."
    :group 'org-link
    :type 'boolean)
  
--- 692,701 ----
  
  (defcustom org-allow-space-in-links t
    "Non-nil means, file names in links may contain space characters.
! 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 varable requires a re-launch of Emacs of become effective."
    :group 'org-link
    :type 'boolean)
  
***************
*** 667,673 ****
  location to an internal list. These links accumulate during a session.
  The command `org-insert-link' can be used to insert links into any
  Org-mode file (offering completion for all stored links).  When this
! option is nil, every link which has been inserted once using `C-c C-l'
  will be removed from the list, to make completing the unused links
  more efficient."
    :group 'org-link
--- 715,721 ----
  location to an internal list. These links accumulate during a session.
  The command `org-insert-link' can be used to insert links into any
  Org-mode file (offering completion for all stored links).  When this
! option is nil, every link which has been inserted once using 
\\[org-insert-link]
  will be removed from the list, to make completing the unused links
  more efficient."
    :group 'org-link
***************
*** 682,696 ****
  this link in another window or frame.  This variable can be used to
  set this up for the different types of links.
  For VM, use any of
!     vm-visit-folder
!     vm-visit-folder-other-frame
  For Gnus, use any of
!     gnus
!     gnus-other-frame
  For FILE, use any of
!     find-file
!     find-file-other-window
!     find-file-other-frame
  For the calendar, use the variable `calendar-setup'.
  For BBDB, it is currently only possible to display the matches in
  another window."
--- 730,744 ----
  this link in another window or frame.  This variable can be used to
  set this up for the different types of links.
  For VM, use any of
!     `vm-visit-folder'
!     `vm-visit-folder-other-frame'
  For Gnus, use any of
!     `gnus'
!     `gnus-other-frame'
  For FILE, use any of
!     `find-file'
!     `find-file-other-window'
!     `find-file-other-frame'
  For the calendar, use the variable `calendar-setup'.
  For BBDB, it is currently only possible to display the matches in
  another window."
***************
*** 792,801 ****
  and the corresponding command.  Possible values for the command are:
   `emacs'     The file will be visited by the current Emacs process.
   `default'   Use the default application for this file type.
!  string      A command to be executed by a shell. %s will be replaced
               by the path to the file.
!  sexp        A lisp form which will be evaluated.  The file path will
!              be available in the lisp variable `file'.
  For more examples, see the system specific constants
  `org-file-apps-defaults-macosx'
  `org-file-apps-defaults-windowsnt'
--- 840,849 ----
  and the corresponding command.  Possible values for the command are:
   `emacs'     The file will be visited by the current Emacs process.
   `default'   Use the default application for this file type.
!  string      A command to be executed by a shell; %s will be replaced
               by the path to the file.
!  sexp        A Lisp form which will be evaluated.  The file path will
!              be available in the Lisp variable `file'.
  For more examples, see the system specific constants
  `org-file-apps-defaults-macosx'
  `org-file-apps-defaults-windowsnt'
***************
*** 1076,1082 ****
    :type 'boolean)
  
  (defcustom org-export-with-tables t
!   "Non-nil means, lines starting with \"|\" define a table
  For example:
  
    | Name        | Address  | Birthday  |
--- 1124,1130 ----
    :type 'boolean)
  
  (defcustom org-export-with-tables t
!   "If non-nil, lines starting with \"|\" define a table
  For example:
  
    | Name        | Address  | Birthday  |
***************
*** 1150,1156 ****
    :type 'boolean)
  
  (defcustom org-export-html-with-timestamp nil
!   "Non-nil means,  write `org-export-html-html-helper-timestamp'
  into the exported html text.  Otherwise, the buffer will just be saved
  to a file."
    :group 'org-export
--- 1198,1204 ----
    :type 'boolean)
  
  (defcustom org-export-html-with-timestamp nil
!   "If non-nil, write `org-export-html-html-helper-timestamp'
  into the exported html text.  Otherwise, the buffer will just be saved
  to a file."
    :group 'org-export
***************
*** 1348,1353 ****
--- 1396,1402 ----
    (defvar org-cursor-color)
    (defvar org-time-was-given)
    (defvar org-ts-what)
+   (defvar mark-active)
    (defvar timecnt)
    (defvar levels-open)
    (defvar title)
***************
*** 1383,1388 ****
--- 1432,1448 ----
  (defvar org-struct-menu)
  (defvar org-org-menu)
  
+ ;; We use a before-change function to check if a table might need
+ ;; an update.
+ (defvar org-table-may-need-update t
+   "Indicates of a table might need an update.
+ This variable is set by `org-before-change-function'. `org-table-align'
+ sets it back to nil.")
+ 
+ (defvar org-mode-hook nil)
+ (defvar org-inhibit-startup nil)        ; Dynamically-scoped param.
+ 
+ 
  ;;;###autoload
  (defun org-mode (&optional arg)
    "Outline-based notes management and organizer, alias 
***************
*** 1437,1450 ****
          (goto-char (point-min))
          (insert "    -*- mode: org -*-\n\n")))
    (run-hooks 'org-mode-hook)
!   (unless (boundp 'org-inhibit-startup)
      (if org-startup-with-deadline-check
          (call-interactively 'org-check-deadlines)
        (cond
         ((eq org-startup-folded t)
!         (org-cycle))
!        ((eq org-startup-folded 'contents)
!         (org-cycle) (org-cycle))))))
  
  ;;; Font-Lock stuff
  
--- 1497,1511 ----
          (goto-char (point-min))
          (insert "    -*- mode: org -*-\n\n")))
    (run-hooks 'org-mode-hook)
!   (unless org-inhibit-startup
      (if org-startup-with-deadline-check
          (call-interactively 'org-check-deadlines)
        (cond
         ((eq org-startup-folded t)
!         (org-cycle '(4)))
!        ((eq org-startup-folded 'content)
!         (let ((this-command 'org-cycle) (last-command 'org-cycle))
!           (org-cycle '(4)) (org-cycle '(4))))))))
  
  ;;; Font-Lock stuff
  
***************
*** 1456,1465 ****
  
  (require 'font-lock)
  
  (defconst org-link-regexp
    (if org-allow-space-in-links
!       
"\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|rmail\\|gnus\\|shell\\):\\([^\t\n\r]+[^
 \t\n\r]\\)"
!     
"\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|rmail\\|gnus\\|shell\\):\\([^
 \t\n\r]+\\)"
      )
    "Regular expression for matching links.")
  (defconst org-ts-lengths
--- 1517,1529 ----
  
  (require 'font-lock)
  
+ (defconst org-non-link-chars "\t\n\r|")
  (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 "]\\)")
!     (concat
!      
"\\(https?\\|ftp\\|mailto\\|file\\|news\\|bbdb\\|vm\\|wl\\|rmail\\|gnus\\|shell\\):\\([^
 " org-non-link-chars "]+\\)")
      )
    "Regular expression for matching links.")
  (defconst org-ts-lengths
***************
*** 1502,1507 ****
--- 1566,1573 ----
      (org-back-to-heading t)
      (- (match-end 0) (match-beginning 0))))
  
+ (defvar org-font-lock-keywords nil)
+ 
  (defun org-set-font-lock-defaults ()
    (let ((org-font-lock-extra-keywords
           (list
***************
*** 1550,1562 ****
           '(org-font-lock-keywords t nil nil backward-paragraph))
      (kill-local-variable 'font-lock-keywords) nil))
      
- (defvar org-font-lock-keywords nil)
- 
  (defun org-unfontify-region (beg end &optional maybe_loudly)
    "Remove fontification and activation overlays from links."
    (font-lock-default-unfontify-region beg end)
!   (let* ((modified (buffer-modified-p)) ;; FIXME: Why did I add this???
!          (buffer-undo-list t)
           (inhibit-read-only t) (inhibit-point-motion-hooks t)
           (inhibit-modification-hooks t)
           deactivate-mark buffer-file-name buffer-file-truename)
--- 1616,1625 ----
           '(org-font-lock-keywords t nil nil backward-paragraph))
      (kill-local-variable 'font-lock-keywords) nil))
      
  (defun org-unfontify-region (beg end &optional maybe_loudly)
    "Remove fontification and activation overlays from links."
    (font-lock-default-unfontify-region beg end)
!   (let* ((buffer-undo-list t)
           (inhibit-read-only t) (inhibit-point-motion-hooks t)
           (inhibit-modification-hooks t)
           deactivate-mark buffer-file-name buffer-file-truename)
***************
*** 1651,1665 ****
      (save-excursion
        (org-back-to-heading)
        (outline-up-heading arg)
!       (show-subtree)))
  
     ((save-excursion (beginning-of-line 1) (looking-at outline-regexp))
      ;; At a heading: rotate between three different views
      (org-back-to-heading)
!     (let ((goal-column 0) beg eoh eol eos nxh)
        ;; First, some boundaries
        (save-excursion
!       (org-back-to-heading)  (setq beg (point))
        (save-excursion
          (beginning-of-line 2)
          (while (and (not (eobp))   ;; this is like `next-line'
--- 1714,1728 ----
      (save-excursion
        (org-back-to-heading)
        (outline-up-heading arg)
!       (org-show-subtree)))
  
     ((save-excursion (beginning-of-line 1) (looking-at outline-regexp))
      ;; At a heading: rotate between three different views
      (org-back-to-heading)
!     (let ((goal-column 0) eoh eol eos)
        ;; First, some boundaries
        (save-excursion
!       (org-back-to-heading)
        (save-excursion
          (beginning-of-line 2)
          (while (and (not (eobp))   ;; this is like `next-line'
***************
*** 1667,1673 ****
            (beginning-of-line 2)) (setq eol (point)))
        (outline-end-of-heading)   (setq eoh (point))
        (outline-end-of-subtree)   (setq eos (point))
!         (outline-next-heading)     (setq nxh (point)))
        ;; Find out what to do next and set `this-command'
        (cond
         ((= eos eoh)
--- 1730,1736 ----
            (beginning-of-line 2)) (setq eol (point)))
        (outline-end-of-heading)   (setq eoh (point))
        (outline-end-of-subtree)   (setq eos (point))
!         (outline-next-heading))
        ;; Find out what to do next and set `this-command'
        (cond
         ((= eos eoh)
***************
*** 1676,1682 ****
          (setq org-cycle-subtree-status nil))
         ((>= eol eos)
        ;; Entire subtree is hidden in one line: open it
!       (show-entry)
        (show-children)
        (message "CHILDREN")
        (setq org-cycle-subtree-status 'children)
--- 1739,1745 ----
          (setq org-cycle-subtree-status nil))
         ((>= eol eos)
        ;; Entire subtree is hidden in one line: open it
!       (org-show-entry)
        (show-children)
        (message "CHILDREN")
        (setq org-cycle-subtree-status 'children)
***************
*** 1684,1690 ****
         ((and (eq last-command this-command)
             (eq org-cycle-subtree-status 'children))
        ;; We just showed the children, now show everything.
!       (show-subtree)
        (message "SUBTREE")
        (setq org-cycle-subtree-status 'subtree)
          (run-hook-with-args 'org-cycle-hook 'subtree))
--- 1747,1753 ----
         ((and (eq last-command this-command)
             (eq org-cycle-subtree-status 'children))
        ;; We just showed the children, now show everything.
!       (org-show-subtree)
        (message "SUBTREE")
        (setq org-cycle-subtree-status 'subtree)
          (run-hook-with-args 'org-cycle-hook 'subtree))
***************
*** 1733,1741 ****
    "Move cursor to the first headline and recenter the headline.
  Optional argument N means, put the headline into the Nth line of the window."
    (goto-char (point-min))
!   (re-search-forward (concat "^" outline-regexp))
!   (beginning-of-line)
!   (recenter (prefix-numeric-value N)))
  
  (defvar org-goto-window-configuration nil)
  (defvar org-goto-marker nil)
--- 1796,1804 ----
    "Move cursor to the first headline and recenter the headline.
  Optional argument N means, put the headline into the Nth line of the window."
    (goto-char (point-min))
!   (when (re-search-forward (concat "^" outline-regexp) nil t)
!     (beginning-of-line)
!     (recenter (prefix-numeric-value N))))
  
  (defvar org-goto-window-configuration nil)
  (defvar org-goto-marker nil)
***************
*** 1836,1844 ****
          current-prefix-arg arg)
    (throw 'exit nil))
  
! (defun org-goto-left (&optional arg)
    "Finish org-goto by going to the new location."
!   (interactive "P")
    (if (org-on-heading-p)
        (progn
          (beginning-of-line 1)
--- 1899,1907 ----
          current-prefix-arg arg)
    (throw 'exit nil))
  
! (defun org-goto-left ()
    "Finish org-goto by going to the new location."
!   (interactive)
    (if (org-on-heading-p)
        (progn
          (beginning-of-line 1)
***************
*** 1847,1855 ****
          (throw 'exit nil))
      (error "Not on a heading")))
  
! (defun org-goto-right (&optional arg)
    "Finish org-goto by going to the new location."
!   (interactive "P")
    (if (org-on-heading-p)
        (progn
          (outline-end-of-subtree)
--- 1910,1918 ----
          (throw 'exit nil))
      (error "Not on a heading")))
  
! (defun org-goto-right ()
    "Finish org-goto by going to the new location."
!   (interactive)
    (if (org-on-heading-p)
        (progn
          (outline-end-of-subtree)
***************
*** 1870,1878 ****
  (defvar org-ignore-region nil
    "To temporarily disable the active region.")
  
! (defun org-insert-heading (&optional arg)
    "Insert a new heading with same depth at point."
!   (interactive "P")
    (let* ((head (save-excursion
                 (condition-case nil
                     (org-back-to-heading)
--- 1933,1941 ----
  (defvar org-ignore-region nil
    "To temporarily disable the active region.")
  
! (defun org-insert-heading ()
    "Insert a new heading with same depth at point."
!   (interactive)
    (let* ((head (save-excursion
                 (condition-case nil
                     (org-back-to-heading)
***************
*** 1903,1936 ****
        (insert (car org-todo-keywords) " ")
      (insert (match-string 2) " ")))
  
! (defun org-promote-subtree (&optional arg)
    "Promote the entire subtree.
  See also `org-promote'."
!   (interactive "P")
!   (org-map-tree 'org-promote))
  
! (defun org-demote-subtree (&optional arg)
    "Demote the entire subtree.  See `org-demote'.
  See also `org-promote'."
!   (interactive "P")
!   (org-map-tree 'org-demote))
  
! (defun org-do-promote (&optional arg)
    "Promote the current heading higher up the tree.
! If the region is active in transient-mark-mode, promote all headings
  in the region."
!   (interactive "P")
    (save-excursion
      (if (org-region-active-p)
          (org-map-region 'org-promote (region-beginning) (region-end))
        (org-promote)))
    (org-fix-position-after-promote))
  
! (defun org-do-demote (&optional arg)
    "Demote the current heading lower down the tree.
! If the region is active in transient-mark-mode, demote all headings
  in the region."
!   (interactive "P")
    (save-excursion
      (if (org-region-active-p)
          (org-map-region 'org-demote (region-beginning) (region-end))
--- 1966,2001 ----
        (insert (car org-todo-keywords) " ")
      (insert (match-string 2) " ")))
  
! (defun org-promote-subtree ()
    "Promote the entire subtree.
  See also `org-promote'."
!   (interactive)
!   (save-excursion
!     (org-map-tree 'org-promote)))
  
! (defun org-demote-subtree ()
    "Demote the entire subtree.  See `org-demote'.
  See also `org-promote'."
!   (interactive)
!   (save-excursion
!     (org-map-tree 'org-demote)))
  
! (defun org-do-promote ()
    "Promote the current heading higher up the tree.
! If the region is active in t`ransient-mark-mode', promote all headings
  in the region."
!   (interactive)
    (save-excursion
      (if (org-region-active-p)
          (org-map-region 'org-promote (region-beginning) (region-end))
        (org-promote)))
    (org-fix-position-after-promote))
  
! (defun org-do-demote ()
    "Demote the current heading lower down the tree.
! If the region is active in `transient-mark-mode', demote all headings
  in the region."
!   (interactive)
    (save-excursion
      (if (org-region-active-p)
          (org-map-region 'org-demote (region-beginning) (region-end))
***************
*** 1945,1951 ****
  
  (defun org-promote ()
    "Promote the current heading higher up the tree.
! If the region is active in transient-mark-mode, promote all headings
  in the region."
    (org-back-to-heading t)
    (let* ((level (save-match-data (funcall outline-level)))
--- 2010,2016 ----
  
  (defun org-promote ()
    "Promote the current heading higher up the tree.
! If the region is active in `transient-mark-mode', promote all headings
  in the region."
    (org-back-to-heading t)
    (let* ((level (save-match-data (funcall outline-level)))
***************
*** 1957,1963 ****
  
  (defun org-demote ()
    "Demote the current heading lower down the tree.
! If the region is active in transient-mark-mode, demote all headings
  in the region."
    (org-back-to-heading t)
    (let* ((level (save-match-data (funcall outline-level)))
--- 2022,2028 ----
  
  (defun org-demote ()
    "Demote the current heading lower down the tree.
! If the region is active in `transient-mark-mode', demote all headings
  in the region."
    (org-back-to-heading t)
    (let* ((level (save-match-data (funcall outline-level)))
***************
*** 2066,2082 ****
    "Was the last copied subtree folded?
  This is used to fold the tree back after pasting.")
  
! (defun org-cut-subtree (&optional arg)
    "Cut the current subtree into the clipboard.
  This is a short-hand for marking the subtree and then cutting it."
!   (interactive "p")
!   (org-copy-subtree arg 'cut))
  
! (defun org-copy-subtree (&optional arg cut)
    "Cut the current subtree into the clipboard.
  This is a short-hand for marking the subtree and then copying it.
  If CUT is non nil, actually cut the subtree."
!   (interactive "p")
    (let (beg end folded)
      (org-back-to-heading)
      (setq beg (point))
--- 2131,2147 ----
    "Was the last copied subtree folded?
  This is used to fold the tree back after pasting.")
  
! (defun org-cut-subtree ()
    "Cut the current subtree into the clipboard.
  This is a short-hand for marking the subtree and then cutting it."
!   (interactive)
!   (org-copy-subtree 'cut))
  
! (defun org-copy-subtree (&optional cut)
    "Cut the current subtree into the clipboard.
  This is a short-hand for marking the subtree and then copying it.
  If CUT is non nil, actually cut the subtree."
!   (interactive)
    (let (beg end folded)
      (org-back-to-heading)
      (setq beg (point))
***************
*** 2338,2344 ****
    ;; Fixup cursor location if close to the keyword
    (if (and (outline-on-heading-p)
             (not (bolp))
!            (save-excursion (goto-char (point-at-bol))
                             (looking-at org-todo-line-regexp))
             (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
        (progn
--- 2403,2409 ----
    ;; Fixup cursor location if close to the keyword
    (if (and (outline-on-heading-p)
             (not (bolp))
!            (save-excursion (beginning-of-line 1)
                             (looking-at org-todo-line-regexp))
             (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
        (progn
***************
*** 2681,2687 ****
  A deadline is considered due if it happens within `org-deadline-warning-days'
  days from today's date.  If the deadline appears in an entry marked DONE,
  it is not shown.  The prefix arg NDAYS can be used to test that many
! days.  If the prefix is a raw C-u prefix, all deadlines are shown."
    (interactive "P")
    (let* ((org-warn-days
            (cond
--- 2746,2752 ----
  A deadline is considered due if it happens within `org-deadline-warning-days'
  days from today's date.  If the deadline appears in an entry marked DONE,
  it is not shown.  The prefix arg NDAYS can be used to test that many
! days.  If the prefix is a raw \\[universal-argument] prefix, all deadlines 
are shown."
    (interactive "P")
    (let* ((org-warn-days
            (cond
***************
*** 2718,2723 ****
--- 2783,2789 ----
          (error "Not at a time-stamp range, and none found in current line.")))
    (let* ((ts1 (match-string 1))
           (ts2 (match-string 2))
+          (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
           (match-end (match-end 0))
           (time1 (org-time-string-to-time ts1))
           (time2 (org-time-string-to-time ts2))
***************
*** 2725,2741 ****
           (t2 (time-to-seconds time2))
           (diff (abs (- t2 t1)))
           (negative (< (- t2 t1) 0))
!          (ys (floor (* 365 24 60 60)))
           (ds (* 24 60 60))
           (hs (* 60 60))
           (fy "%dy %dd %02d:%02d")
           (fd "%dd %02d:%02d")
           (fh "%02d:%02d")
           y d h m align)
!     (setq y (floor (/ diff ys))  diff (mod diff ys)
!           d (floor (/ diff ds))  diff (mod diff ds)
!           h (floor (/ diff hs))  diff (mod diff hs)
!           m (floor (/ diff 60)))
      (if (not to-buffer)
          (message (org-make-tdiff-string y d h m))
        (when (org-at-table-p)
--- 2791,2817 ----
           (t2 (time-to-seconds time2))
           (diff (abs (- t2 t1)))
           (negative (< (- t2 t1) 0))
!          ;; (ys (floor (* 365 24 60 60)))
           (ds (* 24 60 60))
           (hs (* 60 60))
           (fy "%dy %dd %02d:%02d")
+          (fy1 "%dy %dd")
           (fd "%dd %02d:%02d")
+          (fd1 "%dd")
           (fh "%02d:%02d")
           y d h m align)
!     ;; FIXME:  Should I re-introduce years, make year refer to same date?
!     ;; This would be the only useful way to have years, actually.
!     (if havetime
!         (setq ; y (floor (/ diff ys))  diff (mod diff ys)
!          y 0
!          d (floor (/ diff ds))  diff (mod diff ds)
!          h (floor (/ diff hs))  diff (mod diff hs)
!          m (floor (/ diff 60)))
!       (setq ; y (floor (/ diff ys))  diff (mod diff ys)
!        y 0
!        d (floor (+ (/ diff ds) 0.5))
!        h 0 m 0))
      (if (not to-buffer)
          (message (org-make-tdiff-string y d h m))
        (when (org-at-table-p)
***************
*** 2746,2753 ****
             "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
            (replace-match ""))
        (if negative (insert " -"))
!       (if (> y 0) (insert " " (format fy y d h m))
!         (if (> d 0) (insert " " (format fd d h m))
            (insert " " (format fh h m))))
        (if align (org-table-align))
        (message "Time difference inserted"))))
--- 2822,2829 ----
             "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
            (replace-match ""))
        (if negative (insert " -"))
!       (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
!         (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
            (insert " " (format fh h m))))
        (if align (org-table-align))
        (message "Time difference inserted"))))
***************
*** 2770,2776 ****
  
  (defun org-parse-time-string (s)
    "Parse the standard Org-mode time string.
! This should be a lot faster than the normal parse-time-string."
    (if (string-match org-ts-regexp1 s)
        (list 0
              (string-to-number (or (match-string 8 s) "0"))
--- 2846,2852 ----
  
  (defun org-parse-time-string (s)
    "Parse the standard Org-mode time string.
! This should be a lot faster than the normal `parse-time-string'."
    (if (string-match org-ts-regexp1 s)
        (list 0
              (string-to-number (or (match-string 8 s) "0"))
***************
*** 2927,2933 ****
  ;;; Define the mode
  
  (defvar org-agenda-mode-map (make-sparse-keymap)
!   "Keymap for org-agenda-mode.")
  
  (defvar org-agenda-menu)
  (defvar org-agenda-follow-mode nil)
--- 3003,3009 ----
  ;;; Define the mode
  
  (defvar org-agenda-mode-map (make-sparse-keymap)
!   "Keymap for `org-agenda-mode'.")
  
  (defvar org-agenda-menu)
  (defvar org-agenda-follow-mode nil)
***************
*** 2949,2954 ****
--- 3025,3031 ----
    (easy-menu-add org-agenda-menu)
    (if org-startup-truncated (setq truncate-lines t))
    (add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
+   (add-hook 'pre-command-hook 'org-unhighlight nil 'local)
    (setq org-agenda-follow-mode nil)
    (easy-menu-change 
     '("Agenda") "Agenda Files"
***************
*** 2968,2974 ****
  (define-key org-agenda-mode-map "l" 'org-agenda-recenter)
  (define-key org-agenda-mode-map "t" 'org-agenda-todo)
  (define-key org-agenda-mode-map "." 'org-agenda-goto-today)
! (define-key org-agenda-mode-map "w" 'org-agenda-week-view)
  (define-key org-agenda-mode-map [(shift right)] 'org-agenda-date-later)
  (define-key org-agenda-mode-map [(shift left)] 'org-agenda-date-earlier)
  
--- 3045,3051 ----
  (define-key org-agenda-mode-map "l" 'org-agenda-recenter)
  (define-key org-agenda-mode-map "t" 'org-agenda-todo)
  (define-key org-agenda-mode-map "." 'org-agenda-goto-today)
! (define-key org-agenda-mode-map "w" 'org-agenda-toggle-week-view)
  (define-key org-agenda-mode-map [(shift right)] 'org-agenda-date-later)
  (define-key org-agenda-mode-map [(shift left)] 'org-agenda-date-earlier)
  
***************
*** 3043,3049 ****
      ["Next Dates" org-agenda-later (local-variable-p 'starting-day)]
      ["Previous Dates" org-agenda-earlier (local-variable-p 'starting-day)]
      "--"
!     ["Week/Day View" org-agenda-week-view (local-variable-p 'starting-day)]
      ["Include Diary" org-agenda-toggle-diary
       :style toggle :selected org-agenda-include-diary :active t]
      "--"
--- 3120,3127 ----
      ["Next Dates" org-agenda-later (local-variable-p 'starting-day)]
      ["Previous Dates" org-agenda-earlier (local-variable-p 'starting-day)]
      "--"
!     ["Week/Day View" org-agenda-toggle-week-view
!      (local-variable-p 'starting-day)]
      ["Include Diary" org-agenda-toggle-diary
       :style toggle :selected org-agenda-include-diary :active t]
      "--"
***************
*** 3060,3066 ****
      ))
  
  (defvar org-agenda-markers nil
!   "List of all currently active markers created by org-agenda")
  (defvar org-agenda-last-marker-time (time-to-seconds (current-time))
    "Creation time of the last agenda marker.")
  
--- 3138,3144 ----
      ))
  
  (defvar org-agenda-markers nil
!   "List of all currently active markers created by `org-agenda'.")
  (defvar org-agenda-last-marker-time (time-to-seconds (current-time))
    "Creation time of the last agenda marker.")
  
***************
*** 3074,3080 ****
      m))
  
  (defun org-agenda-maybe-reset-markers (&optional force)
!   "Reset markers created by org-agenda.  But only if they are old enough."
    (if (or force
            (> (- (time-to-seconds (current-time))
                  org-agenda-last-marker-time)
--- 3152,3158 ----
      m))
  
  (defun org-agenda-maybe-reset-markers (&optional force)
!   "Reset markers created by `org-agenda'.  But only if they are old enough."
    (if (or force
            (> (- (time-to-seconds (current-time))
                  org-agenda-last-marker-time)
***************
*** 3106,3126 ****
        (when (and (buffer-modified-p buf)
                   file
                   (y-or-n-p (format "Save file %s? " file)))
!         (save-excursion
!           (set-buffer buf) (save-buffer)))
        (kill-buffer buf))))
  
  (defun org-timeline (&optional include-all)
    "Show a time-sorted view of the entries in the current org file.
  Only entries with a time stamp of today or later will be listed.  With
! one C-u prefix argument, past entries will also be listed.
! With two C-u prefixes, all unfinished TODO items will also be shown,
  under the current date.
  If the buffer contains an active region, only check the region for
  dates."
    (interactive "P")
    (require 'calendar)
    (org-agenda-maybe-reset-markers 'force)
    (let* ((dopast include-all)
           (dotodo (equal include-all '(16)))
           (entry (buffer-file-name))
--- 3184,3206 ----
        (when (and (buffer-modified-p buf)
                   file
                   (y-or-n-p (format "Save file %s? " file)))
!         (with-current-buffer buf (save-buffer)))
        (kill-buffer buf))))
  
+ (defvar org-respect-restriction nil)    ; Dynamically-scoped param.
+ 
  (defun org-timeline (&optional include-all)
    "Show a time-sorted view of the entries in the current org file.
  Only entries with a time stamp of today or later will be listed.  With
! one \\[universal-argument] prefix argument, past entries will also be listed.
! With two \\[universal-argument] prefixes, all unfinished TODO items will also 
be shown,
  under the current date.
  If the buffer contains an active region, only check the region for
  dates."
    (interactive "P")
    (require 'calendar)
    (org-agenda-maybe-reset-markers 'force)
+   (org-compile-prefix-format org-timeline-prefix-format)
    (let* ((dopast include-all)
           (dotodo (equal include-all '(16)))
           (entry (buffer-file-name))
***************
*** 3135,3141 ****
           (today (time-to-days (current-time)))
           (org-respect-restriction t)
           (past t)
!          s e rtn d pos)
      (setq org-agenda-redo-command 
            (list 'progn
                  (list 'switch-to-buffer-other-window (current-buffer))
--- 3215,3221 ----
           (today (time-to-days (current-time)))
           (org-respect-restriction t)
           (past t)
!          s e rtn d)
      (setq org-agenda-redo-command 
            (list 'progn
                  (list 'switch-to-buffer-other-window (current-buffer))
***************
*** 3188,3200 ****
    "Produce a weekly view from all files in variable `org-agenda-files'.
  The view will be for the current week, but from the overview buffer you
  will be able to go to other weeks.
! With one C-u prefix argument INCLUDE-ALL, all unfinished TODO items will
  also be shown, under the current date.
  START-DAY defaults to TODAY, or to the most recent match for the weekday
  given in `org-agenda-start-on-weekday'.
  NDAYS defaults to `org-agenda-ndays'."
    (interactive "P")
    (org-agenda-maybe-reset-markers 'force)
    (require 'calendar)
    (let* ((org-agenda-start-on-weekday
            (if (or (equal ndays 1)
--- 3268,3281 ----
    "Produce a weekly view from all files in variable `org-agenda-files'.
  The view will be for the current week, but from the overview buffer you
  will be able to go to other weeks.
! With one \\[universal-argument] prefix argument INCLUDE-ALL, all unfinished 
TODO items will
  also be shown, under the current date.
  START-DAY defaults to TODAY, or to the most recent match for the weekday
  given in `org-agenda-start-on-weekday'.
  NDAYS defaults to `org-agenda-ndays'."
    (interactive "P")
    (org-agenda-maybe-reset-markers 'force)
+   (org-compile-prefix-format org-agenda-prefix-format)
    (require 'calendar)
    (let* ((org-agenda-start-on-weekday
            (if (or (equal ndays 1)
***************
*** 3306,3336 ****
          (throw 'nextfile t))
         (t (error "Abort"))))))
  
! (defun org-agenda-quit (arg)
    "Exit agenda by removing the window or the buffer."
!   (interactive "P")
    (let ((buf (current-buffer)))
      (if (not (one-window-p)) (delete-window))
      (kill-buffer buf)
      (org-agenda-maybe-reset-markers 'force)))
  
! (defun org-agenda-exit (arg)
    "Exit agenda by removing the window or the buffer.
  Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  Org-mode buffers visited directly by the user will not be touched."
!   (interactive "P")
    (org-release-buffers org-agenda-new-buffers)
    (setq org-agenda-new-buffers nil)
!   (org-agenda-quit arg))
  
! (defun org-agenda-redo (&optional arg)
!   "Rebuild Agenda"
!   (interactive "P")
    (eval org-agenda-redo-command))
  
! (defun org-agenda-goto-today (arg)
    "Go to today."
!   (interactive "P")
    (if (boundp 'starting-day)
        (let ((cmd (car org-agenda-redo-command))
              (iall (nth 1 org-agenda-redo-command))
--- 3387,3417 ----
          (throw 'nextfile t))
         (t (error "Abort"))))))
  
! (defun org-agenda-quit ()
    "Exit agenda by removing the window or the buffer."
!   (interactive)
    (let ((buf (current-buffer)))
      (if (not (one-window-p)) (delete-window))
      (kill-buffer buf)
      (org-agenda-maybe-reset-markers 'force)))
  
! (defun org-agenda-exit ()
    "Exit agenda by removing the window or the buffer.
  Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  Org-mode buffers visited directly by the user will not be touched."
!   (interactive)
    (org-release-buffers org-agenda-new-buffers)
    (setq org-agenda-new-buffers nil)
!   (org-agenda-quit))
  
! (defun org-agenda-redo ()
!   "Rebuild Agenda."
!   (interactive)
    (eval org-agenda-redo-command))
  
! (defun org-agenda-goto-today ()
    "Go to today."
!   (interactive)
    (if (boundp 'starting-day)
        (let ((cmd (car org-agenda-redo-command))
              (iall (nth 1 org-agenda-redo-command))
***************
*** 3357,3373 ****
    (org-agenda (if (boundp 'include-all-loc) include-all-loc nil)
                (- starting-day (* arg org-agenda-ndays))))
  
! (defun org-agenda-day-view (arg)
!   "Switch agenda to single day view."
!   (interactive "P")
!   (unless (boundp 'starting-day)
!     (error "Not allowed"))
!   (setq org-agenda-ndays 1)
!   (org-agenda include-all-loc starting-day 1))
! 
! (defun org-agenda-week-view (arg)
!   "Switch agenda to week view."
!   (interactive "P")
    (unless (boundp 'starting-day)
      (error "Not allowed"))
    (setq org-agenda-ndays
--- 3438,3446 ----
    (org-agenda (if (boundp 'include-all-loc) include-all-loc nil)
                (- starting-day (* arg org-agenda-ndays))))
  
! (defun org-agenda-toggle-week-view ()
!   "Toggle weekly/daily view for aagenda."
!   (interactive)
    (unless (boundp 'starting-day)
      (error "Not allowed"))
    (setq org-agenda-ndays
***************
*** 3397,3402 ****
--- 3470,3490 ----
    (if (not (re-search-backward "^\\S-" nil t arg))
        (error "No previous date before this line in this buffer.")))
  
+ ;; Initialize the highlight
+ (defvar org-hl (funcall (if org-xemacs-p 'make-extent 'make-overlay) 1 1))
+ (funcall (if org-xemacs-p 'set-extent-property 'overlay-put) org-hl
+          'face 'highlight)
+ 
+ (defun org-highlight (begin end &optional buffer)
+   "Highlight a region with overlay."
+   (funcall (if org-xemacs-p 'set-extent-endpoints 'move-overlay)
+            org-hl begin end (or buffer (current-buffer))))
+ 
+ (defun org-unhighlight ()
+   "Detach overlay INDEX."
+   (funcall (if org-xemacs-p 'detach-extent 'delete-overlay) org-hl))
+ 
+ 
  (defun org-agenda-follow-mode ()
    "Toggle follow mode in an agenda buffer."
    (interactive)
***************
*** 3430,3450 ****
             (get-text-property (point) 'org-marker))
        (org-agenda-show)))
  
  (defun org-get-entries-from-diary (date)
!   "Get the (emacs calendar) diary entries for DATE."
    (let* ((fancy-diary-buffer "*temporary-fancy-diary-buffer*")
           (diary-display-hook '(fancy-diary-display))
           (list-diary-entries-hook 
            (cons 'org-diary-default-entry list-diary-entries-hook))
!          entries
!          (disable-org-diary t))
      (save-excursion
        (save-window-excursion
          (list-diary-entries date 1)))
      (if (not (get-buffer fancy-diary-buffer))
          (setq entries nil)
!       (save-excursion
!         (switch-to-buffer fancy-diary-buffer)
          (setq buffer-read-only nil)
          (if (= (point-max) 1)
              ;; No entries
--- 3518,3539 ----
             (get-text-property (point) 'org-marker))
        (org-agenda-show)))
  
+ (defvar org-disable-diary nil)          ;Dynamically-scoped param.
+ 
  (defun org-get-entries-from-diary (date)
!   "Get the (Emacs Calendar) diary entries for DATE."
    (let* ((fancy-diary-buffer "*temporary-fancy-diary-buffer*")
           (diary-display-hook '(fancy-diary-display))
           (list-diary-entries-hook 
            (cons 'org-diary-default-entry list-diary-entries-hook))
!          entries tod tods
!          (org-disable-diary t))
      (save-excursion
        (save-window-excursion
          (list-diary-entries date 1)))
      (if (not (get-buffer fancy-diary-buffer))
          (setq entries nil)
!       (with-current-buffer fancy-diary-buffer
          (setq buffer-read-only nil)
          (if (= (point-max) 1)
              ;; No entries
***************
*** 3452,3462 ****
            ;; Omit the date and other unnecessary stuff
            (org-agenda-cleanup-fancy-diary)
            ;; Add prefix to each line and extend the text properties
-           (goto-char (point-min))
-           (while (and (re-search-forward "^" nil t) (not (eobp)))
-             (replace-match "  Diary:     ")
-             (add-text-properties (point-at-bol) (point)
-                                  (text-properties-at (point))))
            (if (= (point-max) 1)
                (setq entries nil)
              (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
--- 3541,3546 ----
***************
*** 3467,3497 ****
        (setq entries 
              (mapcar 
               (lambda (x)
!                (if (string-match "\\<\\([012][0-9]\\):\\([0-6][0-9]\\)" x)
!                    (add-text-properties
!                     1 (length x)
!                     (list 'time-of-day
!                           (+ (* 100 (string-to-number
!                                      (match-string 1 x)))
!                              (string-to-number (match-string 2 x))))
!                     x))
                 x)
               entries)))))
  
  (defun org-agenda-cleanup-fancy-diary ()
    "Remove unwanted stuff in buffer created by fancy-diary-display.
  This gets rid of the date, the underline under the date, and
! the dummy entry installed by org-mode to ensure non-empty diary for each
! date."
    (goto-char (point-min))
    (if (looking-at ".*?:[ \t]*")
        (progn
          (replace-match "")
          (re-search-forward "\n=+$" nil t)
          (replace-match "")
!         (while (re-search-backward "^ +" nil t) (replace-match "")))
      (re-search-forward "\n=+$" nil t)
      (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
    (if (re-search-forward "^Org-mode dummy\n?" nil t)
        (replace-match "")))
  
--- 3551,3583 ----
        (setq entries 
              (mapcar 
               (lambda (x)
!                (setq x (org-format-agenda-item "" x "Diary"))
!                ;; Extend the text properties to the beginning of the line
!                (add-text-properties 
!                 0 (length x)
!                 (text-properties-at (1- (length x)) x)
!                 x)
                 x)
               entries)))))
  
  (defun org-agenda-cleanup-fancy-diary ()
    "Remove unwanted stuff in buffer created by fancy-diary-display.
  This gets rid of the date, the underline under the date, and
! the dummy entry installed by `org-mode' to ensure non-empty diary for each
! date.  Itt also removes lines that contain only whitespace."
    (goto-char (point-min))
    (if (looking-at ".*?:[ \t]*")
        (progn
          (replace-match "")
          (re-search-forward "\n=+$" nil t)
          (replace-match "")
!         (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
      (re-search-forward "\n=+$" nil t)
      (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
+   (goto-char (point-min))
+   (while (re-search-forward "^ +\n" nil t)
+     (replace-match ""))
+   (goto-char (point-min))
    (if (re-search-forward "^Org-mode dummy\n?" nil t)
        (replace-match "")))
  
***************
*** 3501,3507 ****
  (eval-after-load "diary-lib"
    '(defadvice add-to-diary-list (before org-mark-diary-entry activate)
       "Make the position visible."
!      (if (and (boundp 'disable-org-diary)  ;; called from org-agenda
                (stringp string)
                (buffer-file-name))
           (add-text-properties
--- 3587,3593 ----
  (eval-after-load "diary-lib"
    '(defadvice add-to-diary-list (before org-mark-diary-entry activate)
       "Make the position visible."
!      (if (and org-disable-diary  ;; called from org-agenda
                (stringp string)
                (buffer-file-name))
           (add-text-properties
***************
*** 3606,3612 ****
  
  ;;;###autoload
  (defun org-diary (&rest args)
!   "Returns diary information from org-files.
  This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  It accesses org files and extracts information from those files to be
  listed in the diary.  The function accepts arguments specifying what
--- 3692,3698 ----
  
  ;;;###autoload
  (defun org-diary (&rest args)
!   "Return diary information from org-files.
  This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  It accesses org files and extracts information from those files to be
  listed in the diary.  The function accepts arguments specifying what
***************
*** 3649,3654 ****
--- 3735,3741 ----
  by the caller, because this is how the calendar works.  Don't use this
  function from a program - use `org-agenda-get-day-entries' instead." 
    (org-agenda-maybe-reset-markers)
+   (org-compile-agenda-prefix-format org-agenda-prefix-format)
    (setq args (or args '(:deadline :scheduled :timestamp)))
    (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
                      (list entry)
***************
*** 3656,3669 ****
           file rtn results)
      ;; If this is called during org-agenda, don't return any entries to
      ;; the calendar.  Org Agenda will list these entries itself.
!     (if (boundp 'disable-org-diary) (setq files nil))
      (while (setq file (pop files))
        (setq rtn (apply 'org-agenda-get-day-entries file date args))
        (setq results (append results rtn)))
      (concat (org-finalize-agenda-entries results) "\n")))
  
  (defun org-agenda-get-day-entries (file date &rest args)
!   "Does the work for `org-diary' and `org-agenda'
  FILE is the path to a file to be checked for entries.  DATE is date like
  the one returned by `calendar-current-date'.  ARGS are symbols indicating
  which kind of entries should be extracted.  For details about these, see
--- 3743,3756 ----
           file rtn results)
      ;; If this is called during org-agenda, don't return any entries to
      ;; the calendar.  Org Agenda will list these entries itself.
!     (if org-disable-diary (setq files nil))
      (while (setq file (pop files))
        (setq rtn (apply 'org-agenda-get-day-entries file date args))
        (setq results (append results rtn)))
      (concat (org-finalize-agenda-entries results) "\n")))
  
  (defun org-agenda-get-day-entries (file date &rest args)
!   "Does the work for `org-diary' and `org-agenda'.
  FILE is the path to a file to be checked for entries.  DATE is date like
  the one returned by `calendar-current-date'.  ARGS are symbols indicating
  which kind of entries should be extracted.  For details about these, see
***************
*** 3672,3697 ****
    (let* ((org-startup-with-deadline-check nil)
           (org-startup-folded nil)
           (buffer (if (file-exists-p file)
- ;                     (find-file-noselect file)
                       (org-get-agenda-file-buffer file)
                     (error "No such file %s" file)))
-          (respect-narrow-p (boundp 'org-respect-restriction))
           arg results rtn)
      (if (not buffer)
          ;; If file does not exist, make sure an error message ends up in diary
          (format "ORG-AGENDA-ERROR: No such org-file %s" file)
!       (save-excursion
!         (set-buffer buffer)
          (let ((case-fold-search nil))
            (save-excursion
              (save-restriction
!               (if respect-narrow-p
                    (if (org-region-active-p)
                        ;; Respect a region to restrict search
                        (narrow-to-region (region-beginning) (region-end)))
                  ;; If we work for the calendar or many files, 
                  ;; get rid of any restriction
                  (widen))
                (while (setq arg (pop args))
                  (cond
                   ((and (eq arg :todo)
--- 3759,3784 ----
    (let* ((org-startup-with-deadline-check nil)
           (org-startup-folded nil)
           (buffer (if (file-exists-p file)
                       (org-get-agenda-file-buffer file)
                     (error "No such file %s" file)))
           arg results rtn)
      (if (not buffer)
          ;; If file does not exist, make sure an error message ends up in diary
          (format "ORG-AGENDA-ERROR: No such org-file %s" file)
!       (with-current-buffer buffer
!         (unless (eq major-mode 'org-mode)
!           (error "Agenda file %s is not in `org-mode'" file))
          (let ((case-fold-search nil))
            (save-excursion
              (save-restriction
!               (if org-respect-restriction
                    (if (org-region-active-p)
                        ;; Respect a region to restrict search
                        (narrow-to-region (region-beginning) (region-end)))
                  ;; If we work for the calendar or many files, 
                  ;; get rid of any restriction
                  (widen))
+               ;; The way we repeatedly append to `results' makes it O(n^2) :-(
                (while (setq arg (pop args))
                  (cond
                   ((and (eq arg :todo)
***************
*** 3748,3754 ****
           (regexp (concat "[\n\r]\\*+ *\\(" org-not-done-regexp
                           "[^\n\r]*\\)"))
           marker priority
!          ee txt pl)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
        (goto-char (match-beginning 1))
--- 3835,3841 ----
           (regexp (concat "[\n\r]\\*+ *\\(" org-not-done-regexp
                           "[^\n\r]*\\)"))
           marker priority
!          ee txt)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
        (goto-char (match-beginning 1))
***************
*** 3855,3861 ****
           (todayp (equal date (calendar-current-date))) ; DATE bound by 
calendar
           (d1 (calendar-absolute-from-gregorian date))  ; DATE bound by 
calendar
           d2 diff pos pos1
!          ee txt head hdmarker)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
        (setq pos (1- (match-beginning 1))
--- 3942,3948 ----
           (todayp (equal date (calendar-current-date))) ; DATE bound by 
calendar
           (d1 (calendar-absolute-from-gregorian date))  ; DATE bound by 
calendar
           d2 diff pos pos1
!          ee txt head)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
        (setq pos (1- (match-beginning 1))
***************
*** 3913,3919 ****
           (regexp org-scheduled-time-regexp)
           (todayp (equal date (calendar-current-date))) ; DATE bound by 
calendar
           (d1 (calendar-absolute-from-gregorian date))  ; DATE bound by 
calendar
!          d2 diff marker hdmarker pos pos1
           ee txt head)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
--- 4000,4006 ----
           (regexp org-scheduled-time-regexp)
           (todayp (equal date (calendar-current-date))) ; DATE bound by 
calendar
           (d1 (calendar-absolute-from-gregorian date))  ; DATE bound by 
calendar
!          d2 diff pos pos1
           ee txt head)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
***************
*** 3990,4027 ****
      ;; Sort the entries by expiration date.
      (nreverse ee)))
  
! 
! (defun org-format-agenda-item (prefix txt)
    "Format TXT to be inserted into the agenda buffer.
  In particular, this indents the line and adds a category."
!   (let ((cat (or org-category
!                  (file-name-sans-extension
!                   (file-name-nondirectory (buffer-file-name)))))
!         time rtn)
!     (if (symbolp cat) (setq cat (symbol-name cat)))
!     (setq rtn (format "  %-10s %s%s" (concat cat ":") prefix txt))
!     (add-text-properties 
!      0 2 (list 'category (downcase cat)
!                'prefix-length (- (length rtn) (length txt))
!                'time-of-day (org-get-time-of-day rtn))
       rtn)
      rtn))
    
! ;; FIXME:  Should this be restricted to beginning of string?
  (defun org-get-time-of-day (s)
!   "Check string S for a time of day."
    (save-match-data
!   (when (and 
!          (string-match
!           "\\<\\([012][0-9]\\)\\(:\\([0-6][0-9]\\)\\)?\\([AaPp][Mm]\\)?\\>" s)
!          (or (match-beginning 2) (match-beginning 4)))
!     (+ (* 100 (+ (string-to-number (match-string 1 s))
!                  (if (and (match-beginning 4)
!                           (equal (downcase (match-string 4 s)) "pm"))
!                      12 0)))
!        (if (match-beginning 3)
!            (string-to-number (match-string 3 s))
!          0)))))
  
  (defun org-finalize-agenda-entries (list)
    "Sort and concatenate the agenda items."
--- 4077,4142 ----
      ;; Sort the entries by expiration date.
      (nreverse ee)))
  
! (defun org-format-agenda-item (prefix txt &optional category)
    "Format TXT to be inserted into the agenda buffer.
  In particular, this indents the line and adds a category."
!   (let* ((category (or category
!                        org-category
!                        (file-name-sans-extension
!                         (file-name-nondirectory (buffer-file-name)))))
!          (extra prefix)
!          (time-of-day (org-get-time-of-day txt))
!          (t1 (if time-of-day (concat "0" (int-to-string time-of-day)) "0000"))
!          (time (if time-of-day
!                    (concat (substring t1 -4 -2)
!                            ":" (substring t1 -2))
!                  ""))
!          rtn)
!     (if (symbolp category) (setq category (symbol-name category)))
!     (setq rtn (concat (eval org-prefix-format-compiled) txt))
!     (add-text-properties
!      0 (length rtn) (list 'category (downcase category)
!                           'prefix-length (- (length rtn) (length txt))
!                           'time-of-day time-of-day)
       rtn)
      rtn))
    
! (defun org-compile-prefix-format (format)
!   "Compile the prefix format into a Lisp form that can be evaluated.
! The resulting form is returned and stored in the variable
! `org-prefix-format-compiled'."
!   (let ((start 0) varform vars (s format) c)
!     (while (string-match "%\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cts]\\)"
!                          s start)
!       (setq var (cdr (assoc (match-string 3 s)
!                             '(("c" . category) ("t" . time) ("s" . extra))))
!             c (match-string 2 s)
!             start (1+ (match-beginning 0)))
!       (if (= (length c) 1)
!           (setq varform `(if (equal "" ,var) "" (concat ,var ,c)))
!         (setq varform var))
!       (setq s (replace-match "%\\1s" t nil s))
!       (push varform vars))
!     (setq vars (nreverse vars))
!     (setq org-prefix-format-compiled `(format ,s ,@vars))))
! 
  (defun org-get-time-of-day (s)
!   "Check string S for a time of day.
! If found, return it as a military time number between 0 and 2400.
! If not found, return nil."
    (save-match-data
!     (when (or
!            (string-match
!             "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\>" 
s)
!            (string-match
!             "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\>" 
s))
!       (+ (* 100 (+ (string-to-number (match-string 1 s))
!                    (if (and (match-beginning 4)
!                             (equal (downcase (match-string 4 s)) "pm"))
!                        12 0)))
!          (if (match-beginning 3)
!              (string-to-number (match-string 3 s))
!            0)))))
  
  (defun org-finalize-agenda-entries (list)
    "Sort and concatenate the agenda items."
***************
*** 4073,4079 ****
    (let* ((pri (get-text-property (point-at-bol) 'priority)))
      (message "Priority is %d" (if pri pri -1000))))
  
! (defun org-agenda-goto ()
    "Go to the Org-mode file which contains the item at point."
    (interactive)
    (let* ((marker (or (get-text-property (point) 'org-marker) 
--- 4188,4194 ----
    (let* ((pri (get-text-property (point-at-bol) 'priority)))
      (message "Priority is %d" (if pri pri -1000))))
  
! (defun org-agenda-goto (&optional highlight)
    "Go to the Org-mode file which contains the item at point."
    (interactive)
    (let* ((marker (or (get-text-property (point) 'org-marker) 
***************
*** 4087,4093 ****
        (org-show-hidden-entry)
        (save-excursion
          (and (outline-next-heading)
!              (org-flag-heading nil))))))  ; show the next heading
  
  (defun org-agenda-switch-to ()
    "Go to the Org-mode file which contains the item at point."
--- 4202,4209 ----
        (org-show-hidden-entry)
        (save-excursion
          (and (outline-next-heading)
!              (org-flag-heading nil)))) ; show the next heading
!     (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  
  (defun org-agenda-switch-to ()
    "Go to the Org-mode file which contains the item at point."
***************
*** 4116,4129 ****
    "Display the Org-mode file which contains the item at point."
    (interactive)
    (let ((win (selected-window)))
!     (org-agenda-goto)
      (select-window win)))
  
  (defun org-agenda-recenter (arg)
    "Display the Org-mode file which contains the item at point and recenter."
    (interactive "P")
    (let ((win (selected-window)))
!     (org-agenda-goto)
      (recenter arg)
      (select-window win)))
  
--- 4232,4245 ----
    "Display the Org-mode file which contains the item at point."
    (interactive)
    (let ((win (selected-window)))
!     (org-agenda-goto t)
      (select-window win)))
  
  (defun org-agenda-recenter (arg)
    "Display the Org-mode file which contains the item at point and recenter."
    (interactive "P")
    (let ((win (selected-window)))
!     (org-agenda-goto t)
      (recenter arg)
      (select-window win)))
  
***************
*** 4159,4166 ****
           (hdmarker (get-text-property (point) 'org-hd-marker))
           (buffer-read-only nil)
           newhead)
!     (save-excursion
!       (set-buffer buffer)
        (widen)
        (goto-char pos)
        (org-show-hidden-entry)
--- 4275,4281 ----
           (hdmarker (get-text-property (point) 'org-hd-marker))
           (buffer-read-only nil)
           newhead)
!     (with-current-buffer buffer
        (widen)
        (goto-char pos)
        (org-show-hidden-entry)
***************
*** 4225,4242 ****
  the same tree node, and the headline of the tree node in the Org-mode file."
    (interactive)
    (org-agenda-check-no-diary)
!   (let* ((props (text-properties-at (point)))
!          (col (current-column))
!          (marker (or (get-text-property (point) 'org-marker)
                       (org-agenda-error)))
-          (pl (get-text-property (point-at-bol) 'prefix-length))
           (buffer (marker-buffer marker))
           (pos (marker-position marker))
           (hdmarker (get-text-property (point) 'org-hd-marker))
           (buffer-read-only nil)
           newhead)
!     (save-excursion
!       (set-buffer buffer)
        (widen)
        (goto-char pos)
        (org-show-hidden-entry)
--- 4340,4353 ----
  the same tree node, and the headline of the tree node in the Org-mode file."
    (interactive)
    (org-agenda-check-no-diary)
!   (let* ((marker (or (get-text-property (point) 'org-marker)
                       (org-agenda-error)))
           (buffer (marker-buffer marker))
           (pos (marker-position marker))
           (hdmarker (get-text-property (point) 'org-hd-marker))
           (buffer-read-only nil)
           newhead)
!     (with-current-buffer buffer
        (widen)
        (goto-char pos)
        (org-show-hidden-entry)
***************
*** 4271,4290 ****
    (org-agenda-date-later (- arg) what))
  
  (defun org-agenda-date-prompt (arg)
!   "Change the date of this item.  Date is prompted for, with default today."
!   (interactive "p")
    (org-agenda-check-no-diary)
    (let* ((marker (or (get-text-property (point) 'org-marker)
                       (org-agenda-error)))
           (buffer (marker-buffer marker))
           (pos (marker-position marker)))
!     (save-excursion
!       (set-buffer buffer)
        (widen)
        (goto-char pos)
        (if (not (org-at-timestamp-p))
            (error "Cannot find time stamp"))
!       (org-time-stamp nil)
        (message "Time stamp changed to %s" org-last-changed-timestamp))))
  
  (defun org-get-heading ()
--- 4382,4402 ----
    (org-agenda-date-later (- arg) what))
  
  (defun org-agenda-date-prompt (arg)
!   "Change the date of this item.  Date is prompted for, with default today.
! The prefix ARG is passed to the `org-time-stamp' command and can therefore
! be used to request time specification in the time stamp."
!   (interactive "P")
    (org-agenda-check-no-diary)
    (let* ((marker (or (get-text-property (point) 'org-marker)
                       (org-agenda-error)))
           (buffer (marker-buffer marker))
           (pos (marker-position marker)))
!     (with-current-buffer buffer
        (widen)
        (goto-char pos)
        (if (not (org-at-timestamp-p))
            (error "Cannot find time stamp"))
!       (org-time-stamp arg)
        (message "Time stamp changed to %s" org-last-changed-timestamp))))
  
  (defun org-get-heading ()
***************
*** 4295,4304 ****
          (match-string 1)
        "")))
  
! (defun org-agenda-diary-entry (arg)
    "Make a diary entry, like the `i' command from the calendar.
  All the standard commands work: block, weekly etc"
!   (interactive "P")
    (require 'diary-lib)
    (let* ((char (progn 
                   (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early 
[a]nniversary [b]lock [c]yclic")
--- 4407,4416 ----
          (match-string 1)
        "")))
  
! (defun org-agenda-diary-entry ()
    "Make a diary entry, like the `i' command from the calendar.
  All the standard commands work: block, weekly etc"
!   (interactive)
    (require 'diary-lib)
    (let* ((char (progn 
                   (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early 
[a]nniversary [b]lock [c]yclic")
***************
*** 4344,4350 ****
      (error "Don't know which date to use for calendar command"))
    (let* ((oldf (symbol-function 'calendar-cursor-to-date))
           (point (point))
-          (mark (or (mark t) (point)))
           (date (calendar-gregorian-from-absolute
                  (get-text-property point 'day)))
           (displayed-day (extract-calendar-day date))
--- 4456,4461 ----
***************
*** 4527,4537 ****
  (defun org-follow-bbdb-link (name)
    "Follow a BBDB link to NAME."
    (require 'bbdb)
!   ;; First try an exact match
!   (bbdb-name (concat "\\`" name "\\'") nil)
!   (if (= 0 (buffer-size (get-buffer "*BBDB*")))
!       ;; No exact match - try partial match
!       (bbdb-name name nil)))
  
  (defun org-follow-gnus-link (&optional group article)
    "Follow a Gnus link to GROUP and ARTICLE."
--- 4638,4662 ----
  (defun org-follow-bbdb-link (name)
    "Follow a BBDB link to NAME."
    (require 'bbdb)
!   (let ((inhibit-redisplay t))
!     (catch 'exit
!       ;; Exact match on name
!       (bbdb-name (concat "\\`" name "\\'") nil)
!       (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
!       ;; Exact match on name
!       (bbdb-company (concat "\\`" name "\\'") nil)
!       (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
!       ;; Partial match on name
!       (bbdb-name name nil)
!       (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
!       ;; Partial match on company
!       (bbdb-company name nil)
!       (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
!       ;; General match including network address and notes
!       (bbdb name nil)
!       (when (= 0 (buffer-size (get-buffer "*BBDB*")))
!         (delete-window (get-buffer-window "*BBDB*"))
!         (error "No matching BBDB record")))))
  
  (defun org-follow-gnus-link (&optional group article)
    "Follow a Gnus link to GROUP and ARTICLE."
***************
*** 4545,4551 ****
                  (gnus-summary-insert-cached-articles)
                  (gnus-summary-goto-article article nil 'force))
              (message "Message could not be found.")))))
- ;;  (if article (gnus-summary-goto-article article nil 'force)))
  
  (defun org-follow-vm-link (&optional folder article readonly)
    "Follow a VM link to FOLDER and ARTICLE."
--- 4670,4675 ----
***************
*** 4681,4688 ****
  
       ((eq major-mode 'bbdb-mode)
        (setq link (concat "bbdb:"
!                          (bbdb-record-name (bbdb-current-record)))))
! 
       ((eq major-mode 'calendar-mode)
        (let ((cd (calendar-cursor-to-date)))
          (setq link
--- 4805,4813 ----
  
       ((eq major-mode 'bbdb-mode)
        (setq link (concat "bbdb:"
!                          (or (bbdb-record-name (bbdb-current-record))
!                              (bbdb-record-company (bbdb-current-record))))))
!      
       ((eq major-mode 'calendar-mode)
        (let ((cd (calendar-cursor-to-date)))
          (setq link
***************
*** 4702,4708 ****
                (folder (buffer-file-name))
                (subject (vm-su-subject message))
                (author (vm-su-full-name message))
-               (address (vm-su-from message))
                (message-id (vm-su-message-id message)))
           (setq folder (abbreviate-file-name folder))
           (if (string-match (concat "^" (regexp-quote vm-folder-directory))
--- 4827,4832 ----
***************
*** 4747,4755 ****
                                 group))
            (setq link (concat "gnus:" group)))))
  
!      ((or (eq major-mode 'gnus-summary-mode)
!           (eq major-mode 'gnus-article-mode))
!       (gnus-article-show-summary)
        (gnus-summary-beginning-of-article)
        (let* ((group (car gnus-article-current))
               (article (cdr gnus-article-current))
--- 4871,4878 ----
                                 group))
            (setq link (concat "gnus:" group)))))
  
!      ((memq major-mode '(gnus-summary-mode gnus-article-mode))
!       (and (eq major-mode 'gnus-article-mode) (gnus-article-show-summary))
        (gnus-summary-beginning-of-article)
        (let* ((group (car gnus-article-current))
               (article (cdr gnus-article-current))
***************
*** 4825,4832 ****
  
  
  (defun org-fixup-message-id-for-http (s)
!   "Replace special characters in a message id, so that it can be used
! in an http query."
    (while (string-match "<" s)
      (setq s (replace-match "%3C" t t s)))
    (while (string-match ">" s)
--- 4948,4954 ----
  
  
  (defun org-fixup-message-id-for-http (s)
!   "Replace special characters in a message id, so it can be used in an http 
query."
    (while (string-match "<" s)
      (setq s (replace-match "%3C" t t s)))
    (while (string-match ">" s)
***************
*** 4843,4855 ****
  press RET at the prompt), the link defaults to the most recently
  stored link.
  
! With a C-u prefix, prompts for a file to link to.  The file name can be
  selected using completion.  The path to the file will be relative to
  the current directory if the file is in the current directory or a
  subdirectory.  Otherwise, the link will be the absolute path as
  completed in the minibuffer (i.e. normally ~/path/to/file).
  
! With two C-u prefixes, enforce an absolute path even if the file
  is in the current directory or below."
    (interactive "P")
    (let ((link (if complete-file
--- 4965,4977 ----
  press RET at the prompt), the link defaults to the most recently
  stored link.
  
! With a \\[universal-argument] prefix, prompts for a file to link to.  The 
file name can be
  selected using completion.  The path to the file will be relative to
  the current directory if the file is in the current directory or a
  subdirectory.  Otherwise, the link will be the absolute path as
  completed in the minibuffer (i.e. normally ~/path/to/file).
  
! With two \\[universal-argument] prefixes, enforce an absolute path even if 
the file
  is in the current directory or below."
    (interactive "P")
    (let ((link (if complete-file
***************
*** 4970,4980 ****
        ;; Find the file
        (if (not visiting)
            (find-file-noselect file))
!       (save-excursion
!         (set-buffer (get-file-buffer file))
          (setq reversed (org-notes-order-reversed-p))
!         (save-restriction
!           (save-excursion
              (widen)
              ;; Ask the User for a location
              (setq spos (if fastp 1 (org-get-location
--- 5092,5101 ----
        ;; Find the file
        (if (not visiting)
            (find-file-noselect file))
!       (with-current-buffer (get-file-buffer file)
          (setq reversed (org-notes-order-reversed-p))
!         (save-excursion
!           (save-restriction
              (widen)
              ;; Ask the User for a location
              (setq spos (if fastp 1 (org-get-location
***************
*** 5038,5049 ****
  ;; Emacs package.  We call the former org-type tables, and the latter
  ;; table.el-type tables.
  
- ;; We use a before-change function to check if a table might need
- ;; an update.
- (defvar org-table-may-need-update t
-   "Indicates of a table might need an update.
- This variable is set by `org-before-change-function'. `org-table-align'
- sets it back to nil.")
  
  (defun org-before-change-function (beg end)
    "Every change indicates that a table might need an update."
--- 5159,5164 ----
***************
*** 5058,5064 ****
  (defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]"
    "Detects a table-type table hline.")
  (defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)"
!   "Detects an org-type or table-type table")
  (defconst org-table-border-regexp "^[ \t]*[^| \t]"
    "Searching from within a table (any type) this finds the first line
  outside the table.")
--- 5173,5179 ----
  (defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]"
    "Detects a table-type table hline.")
  (defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)"
!   "Detects an org-type or table-type table.")
  (defconst org-table-border-regexp "^[ \t]*[^| \t]"
    "Searching from within a table (any type) this finds the first line
  outside the table.")
***************
*** 5210,5218 ****
  This is being used to correctly align a single field after TAB or RET.")
  
  
! (defun org-table-align (&optional arg)
    "Align the table at point by aligning all vertical bars."
!   (interactive "P")
    (let* (
           ;; Limits of table
           (beg (org-table-begin))
--- 5325,5333 ----
  This is being used to correctly align a single field after TAB or RET.")
  
  
! (defun org-table-align ()
    "Align the table at point by aligning all vertical bars."
!   (interactive)
    (let* (
           ;; Limits of table
           (beg (org-table-begin))
***************
*** 5366,5375 ****
            (setq org-table-may-need-update t))
          (goto-char pos))))))
  
! (defun org-table-next-field (&optional arg)
    "Go to the next field in the current table.
  Before doing so, re-align the table if necessary."
!   (interactive "P")
    (if (and org-table-automatic-realign
             org-table-may-need-update)
        (org-table-align))
--- 5481,5490 ----
            (setq org-table-may-need-update t))
          (goto-char pos))))))
  
! (defun org-table-next-field ()
    "Go to the next field in the current table.
  Before doing so, re-align the table if necessary."
!   (interactive)
    (if (and org-table-automatic-realign
             org-table-may-need-update)
        (org-table-align))
***************
*** 5388,5397 ****
      (error
       (org-table-insert-row 'below))))
  
! (defun org-table-previous-field (&optional arg)
    "Go to the previous field in the table.
  Before doing so, re-align the table if necessary."
!   (interactive "P")
    (if (and org-table-automatic-realign
             org-table-may-need-update)
        (org-table-align))
--- 5503,5512 ----
      (error
       (org-table-insert-row 'below))))
  
! (defun org-table-previous-field ()
    "Go to the previous field in the table.
  Before doing so, re-align the table if necessary."
!   (interactive)
    (if (and org-table-automatic-realign
             org-table-may-need-update)
        (org-table-align))
***************
*** 5404,5413 ****
    (if (looking-at "| ?")
        (goto-char (match-end 0))))
  
! (defun org-table-next-row (&optional arg)
    "Go to the next row (same column) in the current table.
  Before doing so, re-align the table if necessary."
!   (interactive "P")
    (if (or (looking-at "[ \t]*$")
            (save-excursion (skip-chars-backward " \t") (bolp)))
        (newline)
--- 5519,5528 ----
    (if (looking-at "| ?")
        (goto-char (match-end 0))))
  
! (defun org-table-next-row ()
    "Go to the next row (same column) in the current table.
  Before doing so, re-align the table if necessary."
!   (interactive)
    (if (or (looking-at "[ \t]*$")
            (save-excursion (skip-chars-backward " \t") (bolp)))
        (newline)
***************
*** 5470,5475 ****
--- 5585,5593 ----
            (looking-at "[ \t]*$"))
        (error "Not in table data field")))
  
+ (defvar org-table-clip nil
+   "Clipboard for table regions")
+ 
  (defun org-table-blank-field ()
    "Blank the current table field or active region."
    (interactive)
***************
*** 5497,5503 ****
    (backward-char 1)
    (if (looking-at "|[^|\r\n]*")
        (let* ((pos (match-beginning 0))
-              (len (length (match-string 0)))
               (val (buffer-substring (1+ pos) (match-end 0))))
          (if replace
              (replace-match (concat "|" replace)))
--- 5615,5620 ----
***************
*** 5591,5599 ****
          (looking-at org-table-hline-regexp))
      nil))
  
! (defun org-table-insert-column (&optional arg)
    "Insert a new column into the table."
!   (interactive "P")
    (if (not (org-at-table-p))
        (error "Not at a table"))
    (org-table-find-dataline)
--- 5708,5716 ----
          (looking-at org-table-hline-regexp))
      nil))
  
! (defun org-table-insert-column ()
    "Insert a new column into the table."
!   (interactive)
    (if (not (org-at-table-p))
        (error "Not at a table"))
    (org-table-find-dataline)
***************
*** 5634,5642 ****
          (error
           "Please position cursor in a data line for column operations")))))
  
! (defun org-table-delete-column (&optional arg)
    "Delete a column into the table."
!   (interactive "P")
    (if (not (org-at-table-p))
        (error "Not at a table"))
    (org-table-find-dataline)
--- 5751,5759 ----
          (error
           "Please position cursor in a data line for column operations")))))
  
! (defun org-table-delete-column ()
    "Delete a column into the table."
!   (interactive)
    (if (not (org-at-table-p))
        (error "Not at a table"))
    (org-table-find-dataline)
***************
*** 5777,5785 ****
      (beginning-of-line 0)
      (move-to-column col)))
  
! (defun org-table-kill-row (&optional arg)
    "Delete the current row or horizontal line from the table."
!   (interactive "P")
    (if (not (org-at-table-p))
        (error "Not at a table"))
    (let ((col (current-column)))
--- 5894,5902 ----
      (beginning-of-line 0)
      (move-to-column col)))
  
! (defun org-table-kill-row ()
    "Delete the current row or horizontal line from the table."
!   (interactive)
    (if (not (org-at-table-p))
        (error "Not at a table"))
    (let ((col (current-column)))
***************
*** 5788,5801 ****
      (move-to-column col)))
  
  
! (defun org-table-cut-region (&optional arg)
    "Copy region in table to the clipboard and blank all relevant fields."
!   (interactive "P")
    (org-table-copy-region 'cut))
  
- (defvar org-table-clip nil
-   "Clipboard for table regions")
- 
  (defun org-table-copy-region (&optional cut)
    "Copy rectangular region in table to clipboard.
  A special clipboard is used which can only be accessed
--- 5905,5915 ----
      (move-to-column col)))
  
  
! (defun org-table-cut-region ()
    "Copy region in table to the clipboard and blank all relevant fields."
!   (interactive)
    (org-table-copy-region 'cut))
  
  (defun org-table-copy-region (&optional cut)
    "Copy rectangular region in table to clipboard.
  A special clipboard is used which can only be accessed
***************
*** 5832,5851 ****
      (setq org-table-clip (nreverse region))
      (if cut (org-table-align))))
    
! (defun org-table-paste-rectangle (&optional arg)
    "Paste a rectangular region into a table.
  The upper right corner ends up in the current field.  All involved fields
  will be overwritten.  If the rectangle does not fit into the present table,
  the table is enlarged as needed.  The process ignores horizontal separator
  lines."
!   (interactive "P")
    (unless (and org-table-clip (listp org-table-clip))
      (error "First cut/copy a region to paste!"))
    (org-table-check-inside-data-field)
    (let* ((clip org-table-clip)
           (line (count-lines (point-min) (point)))
           (col (org-table-current-column))
-          (l line)
           (org-enable-table-editor t)
           (org-table-automatic-realign nil)
           c cols field)
--- 5946,5964 ----
      (setq org-table-clip (nreverse region))
      (if cut (org-table-align))))
    
! (defun org-table-paste-rectangle ()
    "Paste a rectangular region into a table.
  The upper right corner ends up in the current field.  All involved fields
  will be overwritten.  If the rectangle does not fit into the present table,
  the table is enlarged as needed.  The process ignores horizontal separator
  lines."
!   (interactive)
    (unless (and org-table-clip (listp org-table-clip))
      (error "First cut/copy a region to paste!"))
    (org-table-check-inside-data-field)
    (let* ((clip org-table-clip)
           (line (count-lines (point-min) (point)))
           (col (org-table-current-column))
           (org-enable-table-editor t)
           (org-table-automatic-realign nil)
           c cols field)
***************
*** 5864,5870 ****
      (org-table-align)))
  
  (defun org-table-convert ()
!   "Convert from org-mode table to table.el and back.
  Obviously, this only works within limits.  When an Org-mode table is
  converted to table.el, all horizontal separator lines get lost, because
  table.el uses these as cell boundaries and has no notion of horizontal lines.
--- 5977,5983 ----
      (org-table-align)))
  
  (defun org-table-convert ()
!   "Convert from `org-mode' table to table.el and back.
  Obviously, this only works within limits.  When an Org-mode table is
  converted to table.el, all horizontal separator lines get lost, because
  table.el uses these as cell boundaries and has no notion of horizontal lines.
***************
*** 5915,5921 ****
  If there is an active region, and both point and mark are in the same column,
  the text in the column is wrapped to minimum width for the given number of
  lines.  Generally, this makes the table more compact.  A prefix ARG may be
! used to change the number of desired lines.  For example, `C-2 C-c C-q'
  formats the selected text to two lines.  If the region was longer than 2
  lines, the remaining lines remain empty.  A negative prefix argument reduces
  the current number of lines by that amount.  The wrapped text is pasted back
--- 6028,6034 ----
  If there is an active region, and both point and mark are in the same column,
  the text in the column is wrapped to minimum width for the given number of
  lines.  Generally, this makes the table more compact.  A prefix ARG may be
! used to change the number of desired lines.  For example, `C-2 
\\[org-table-wrap]'
  formats the selected text to two lines.  If the region was longer than 2
  lines, the remaining lines remain empty.  A negative prefix argument reduces
  the current number of lines by that amount.  The wrapped text is pasted back
***************
*** 5984,5991 ****
  The return value is a list of lines, without newlines at the end."
    (let* ((words (org-split-string string "[ \t\n]+"))
           (maxword (apply 'max (mapcar 'length words)))
-          (black (apply '+ (mapcar 'length words)))
-          (total (+ black (length words)))
           w ll)
      (cond (width
             (org-do-wrap words (max maxword width)))
--- 6097,6102 ----
***************
*** 6003,6009 ****
             
  
  (defun org-do-wrap (words width)
!   "Creates lines of maximum width WIDTH (in characters) from word list WORDS."
    (let (lines line)
      (while words
        (setq line (pop words))
--- 6114,6120 ----
             
  
  (defun org-do-wrap (words width)
!   "Create lines of maximum width WIDTH (in characters) from word list WORDS."
    (let (lines line)
      (while words
        (setq line (pop words))
***************
*** 6222,6231 ****
    $;%.1f              Reformat current cell to 1 digit after dec.point
    ($3-32)*5/9         degrees F -> C conversion
  
! When called with a raw C-u prefix, the formula is applied to the current
  field, and to the same same column in all following rows, until reaching a
  horizontal line or the end of the table.  When the command is called with a
! numeric prefix argument (like M-3 or C-7 or C-u 24), the formula is applied
  to the current row, and to the following n-1 rows (but not beyond a
  separator line)."
    (interactive "P")
--- 6333,6342 ----
    $;%.1f              Reformat current cell to 1 digit after dec.point
    ($3-32)*5/9         degrees F -> C conversion
  
! When called with a raw \\[universal-argument] prefix, the formula is applied 
to the current
  field, and to the same same column in all following rows, until reaching a
  horizontal line or the end of the table.  When the command is called with a
! numeric prefix argument (like M-3 or C-7 or \\[universal-argument] 24), the 
formula is applied
  to the current row, and to the following n-1 rows (but not beyond a
  separator line)."
    (interactive "P")
***************
*** 6297,6303 ****
  ;; modified self-insert.
  
  (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
!   "Non-nil means, use the optimized table editor version for orgtbl-mode.
  In the optimized version, the table editor takes over all simple keys that
  normally just insert a character.  In tables, the characters are inserted
  in a way to minimize disturbing the table structure (i.e. in overwrite mode
--- 6408,6414 ----
  ;; modified self-insert.
  
  (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized)
!   "Non-nil means, use the optimized table editor version for `orgtbl-mode'.
  In the optimized version, the table editor takes over all simple keys that
  normally just insert a character.  In tables, the characters are inserted
  in a way to minimize disturbing the table structure (i.e. in overwrite mode
***************
*** 6311,6331 ****
    :type 'boolean)
  
  (defvar orgtbl-mode nil
!   "Variable controlling orgtbl-mode, a minor mode enabling the org-mode
  table editor in arbitrary modes.")
  (make-variable-buffer-local 'orgtbl-mode)
  
  (defvar orgtbl-mode-map (make-sparse-keymap)
!   "Keymap for orgtbl-mode.")
  
  ;;;###autoload
  (defun turn-on-orgtbl ()
!   "Unconditionally turn on orgtbl-mode."
    (orgtbl-mode 1))
  
  ;;;###autoload
  (defun orgtbl-mode (&optional arg)
!   "The org-mode table editor as a minor mode for use in other modes." 
    (interactive) 
    (setq orgtbl-mode
          (if arg (> (prefix-numeric-value arg) 0) (not orgtbl-mode)))
--- 6422,6442 ----
    :type 'boolean)
  
  (defvar orgtbl-mode nil
!   "Variable controlling `orgtbl-mode', a minor mode enabling the `org-mode'
  table editor in arbitrary modes.")
  (make-variable-buffer-local 'orgtbl-mode)
  
  (defvar orgtbl-mode-map (make-sparse-keymap)
!   "Keymap for `orgtbl-mode'.")
  
  ;;;###autoload
  (defun turn-on-orgtbl ()
!   "Unconditionally turn on `orgtbl-mode'."
    (orgtbl-mode 1))
  
  ;;;###autoload
  (defun orgtbl-mode (&optional arg)
!   "The `org-mode' table editor as a minor mode for use in other modes." 
    (interactive) 
    (setq orgtbl-mode
          (if arg (> (prefix-numeric-value arg) 0) (not orgtbl-mode)))
***************
*** 6435,6447 ****
    (define-key org-mode-map "|" 'self-insert-command))
  
  (defun orgtbl-tab ()
!   "Justification and field motion for orgtbl-mode."
    (interactive)
    (org-table-justify-field-maybe)
    (org-table-next-field))
  
  (defun orgtbl-ret ()
!   "Justification and field motion for orgtbl-mode."
    (interactive)
    (org-table-justify-field-maybe)
    (org-table-next-row))
--- 6546,6558 ----
    (define-key org-mode-map "|" 'self-insert-command))
  
  (defun orgtbl-tab ()
!   "Justification and field motion for `orgtbl-mode'."
    (interactive)
    (org-table-justify-field-maybe)
    (org-table-next-field))
  
  (defun orgtbl-ret ()
!   "Justification and field motion for `orgtbl-mode'."
    (interactive)
    (org-table-justify-field-maybe)
    (org-table-next-row))
***************
*** 6454,6460 ****
    (if (and (org-at-table-p)
             (eq N 1)
             (looking-at "[^|\n]*  +|"))
!       (let (org-table-may-need-update (pos (point)))
          (goto-char (1- (match-end 0)))
          (delete-backward-char 1)
          (goto-char (match-beginning 0))
--- 6565,6571 ----
    (if (and (org-at-table-p)
             (eq N 1)
             (looking-at "[^|\n]*  +|"))
!       (let (org-table-may-need-update)
          (goto-char (1- (match-end 0)))
          (delete-backward-char 1)
          (goto-char (match-beginning 0))
***************
*** 6869,6874 ****
--- 6980,6987 ----
  It is supplemented by a number of commonly used TeX macros with appropriate
  translations.")
  
+ (defvar org-last-level nil) ; dynamically scoped variable
+ 
  (defun org-export-as-ascii (arg)
    "Export the outline as a pretty ASCII file.
  If there is an active region, export only the region.
***************
*** 6898,6907 ****
         (email       user-mail-address)
           (language    org-export-default-language)
         (text        nil)
-          (last-level  1)
           (todo nil)
           (lang-words nil))
  
      (org-init-section-numbers)
  
      (find-file-noselect filename)
--- 7011,7020 ----
         (email       user-mail-address)
           (language    org-export-default-language)
         (text        nil)
           (todo nil)
           (lang-words nil))
  
+     (setq org-last-level 1)
      (org-init-section-numbers)
  
      (find-file-noselect filename)
***************
*** 6962,6968 ****
                                 (insert
                                    (make-string (* (1- level) 4) ?\ )
                                  (format (if todo "%s (*)\n" "%s\n") txt))
!                                (setq last-level level))
                             ))))
                  lines)))
  
--- 7075,7081 ----
                                 (insert
                                    (make-string (* (1- level) 4) ?\ )
                                  (format (if todo "%s (*)\n" "%s\n") txt))
!                                (setq org-last-level level))
                             ))))
                  lines)))
  
***************
*** 7030,7040 ****
            (setq title (concat (org-section-number level) " " title)))
        (insert title "\n" (make-string (string-width title) char) "\n"))))
  
! (defun org-export-copy-visible (&optional arg)
    "Copy the visible part of the buffer to another buffer, for printing.
  Also removes the first line of the buffer if it specifies a mode,
  and all options lines."
!   (interactive "P")
    (let* ((filename (concat (file-name-sans-extension (buffer-file-name))
                             ".txt"))
           (buffer (find-file-noselect filename))
--- 7143,7153 ----
            (setq title (concat (org-section-number level) " " title)))
        (insert title "\n" (make-string (string-width title) char) "\n"))))
  
! (defun org-export-copy-visible ()
    "Copy the visible part of the buffer to another buffer, for printing.
  Also removes the first line of the buffer if it specifies a mode,
  and all options lines."
!   (interactive)
    (let* ((filename (concat (file-name-sans-extension (buffer-file-name))
                             ".txt"))
           (buffer (find-file-noselect filename))
***************
*** 7044,7051 ****
                    "TITLE" "AUTHOR" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"))
                 (if org-noutline-p "\\(\n\\|$\\)" "")))
           s e)
!     (save-excursion
!       (set-buffer buffer)
        (erase-buffer)
        (text-mode))
      (save-excursion
--- 7157,7163 ----
                    "TITLE" "AUTHOR" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"))
                 (if org-noutline-p "\\(\n\\|$\\)" "")))
           s e)
!     (with-current-buffer buffer
        (erase-buffer)
        (text-mode))
      (save-excursion
***************
*** 7174,7180 ****
    (org-open-file (buffer-file-name)))
  
  (defun org-export-as-html-batch ()
!   "Call org-export-as-html, may be used in batch processing as
  emacs         --batch
        --load=$HOME/lib/emacs/org.el
        --eval \"(setq org-export-headline-levels 2)\"
--- 7286,7292 ----
    (org-open-file (buffer-file-name)))
  
  (defun org-export-as-html-batch ()
!   "Call `org-export-as-html', may be used in batch processing as
  emacs         --batch
        --load=$HOME/lib/emacs/org.el
        --eval \"(setq org-export-headline-levels 2)\"
***************
*** 7199,7205 ****
            (org-skip-comments (org-split-string region "[\r\n]")))
           (lines (org-export-find-first-heading-line all_lines))
           (level 0) (line "") (origline "") txt todo
-        (last-level 1)
           (umax nil)
           (filename (concat (file-name-sans-extension (buffer-file-name))
                             ".html"))
--- 7311,7316 ----
***************
*** 7220,7225 ****
--- 7331,7337 ----
         )
      (message "Exporting...")
  
+     (setq org-last-level 1)
      (org-init-section-numbers)
  
      ;; Search for the export key lines
***************
*** 7284,7298 ****
                               (if (<= level umax)
                                   (progn
                                     (setq head-count (+ head-count 1))
!                                    (if (> level last-level)
                                         (progn
!                                          (setq cnt (- level last-level))
                                           (while (>= (setq cnt (1- cnt)) 0)
                                             (insert "<ul>"))
                                           (insert "\n")))
!                                    (if (< level last-level)
                                         (progn
!                                          (setq cnt (- last-level level))
                                           (while (>= (setq cnt (1- cnt)) 0)
                                             (insert "</ul>"))
                                           (insert "\n")))
--- 7396,7410 ----
                               (if (<= level umax)
                                   (progn
                                     (setq head-count (+ head-count 1))
!                                    (if (> level org-last-level)
                                         (progn
!                                          (setq cnt (- level org-last-level))
                                           (while (>= (setq cnt (1- cnt)) 0)
                                             (insert "<ul>"))
                                           (insert "\n")))
!                                    (if (< level org-last-level)
                                         (progn
!                                          (setq cnt (- org-last-level level))
                                           (while (>= (setq cnt (1- cnt)) 0)
                                             (insert "</ul>"))
                                           (insert "\n")))
***************
*** 7302,7312 ****
                                           "<li><a href=\"#sec-%d\"><span 
style='color:red'>%s</span></a></li>\n"
                                         "<li><a 
href=\"#sec-%d\">%s</a></li>\n")
                                       head-count txt))
!                                    (setq last-level level))
                                 ))))
                      lines)
!             (while (> last-level 0)
!               (setq last-level (1- last-level))
                (insert "</ul>\n"))
              ))
        (setq head-count 0)
--- 7414,7424 ----
                                           "<li><a href=\"#sec-%d\"><span 
style='color:red'>%s</span></a></li>\n"
                                         "<li><a 
href=\"#sec-%d\">%s</a></li>\n")
                                       head-count txt))
!                                    (setq org-last-level level))
                                 ))))
                      lines)
!             (while (> org-last-level 0)
!               (setq org-last-level (1- org-last-level))
                (insert "</ul>\n"))
              ))
        (setq head-count 0)
***************
*** 7537,7553 ****
  This has the advantage that cell- or row-spanning is allowed.
  But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
    (require 'table)
!   (save-excursion
!     (set-buffer (get-buffer-create " org-tmp1 "))
      (erase-buffer)
      (insert (mapconcat 'identity lines "\n"))
      (goto-char (point-min))
      (if (not (re-search-forward "|[^+]" nil t))
          (error "Error processing table."))
      (table-recognize-table)
!     (save-excursion
!       (set-buffer (get-buffer-create " org-tmp2 "))
!       (erase-buffer))
      (table-generate-source 'html " org-tmp2 ")
      (set-buffer " org-tmp2 ")
      (buffer-substring (point-min) (point-max))))
--- 7649,7662 ----
  This has the advantage that cell- or row-spanning is allowed.
  But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
    (require 'table)
!   (with-current-buffer (get-buffer-create " org-tmp1 ")
      (erase-buffer)
      (insert (mapconcat 'identity lines "\n"))
      (goto-char (point-min))
      (if (not (re-search-forward "|[^+]" nil t))
          (error "Error processing table."))
      (table-recognize-table)
!     (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
      (table-generate-source 'html " org-tmp2 ")
      (set-buffer " org-tmp2 ")
      (buffer-substring (point-min) (point-max))))
***************
*** 7711,7717 ****
                          level head-count title level))
        (insert (format "\n<H%d>%s</H%d>\n" level title level))))))
  
! (defun org-html-level-close (level)
    "Terminate one level in HTML export."
    (insert "</ul>"))
  
--- 7820,7826 ----
                          level head-count title level))
        (insert (format "\n<H%d>%s</H%d>\n" level title level))))))
  
! (defun org-html-level-close (&rest args)
    "Terminate one level in HTML export."
    (insert "</ul>"))
  
***************
*** 7800,7805 ****
--- 7909,7915 ----
  (define-key org-mode-map "\C-c/"    'org-occur)   ; Minor-mode reserved
  (define-key org-mode-map "\C-c\C-m" 'org-insert-heading)
  (define-key org-mode-map "\M-\C-m"  'org-insert-heading)
+ (define-key org-mode-map [(meta shift return)] 'org-insert-todo-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\C-z" 'org-time-stamp)  ; Alternative binding
***************
*** 7811,7818 ****
  (define-key org-mode-map "\C-c["    'org-add-file)
  (define-key org-mode-map "\C-c]"    'org-remove-file)
  (define-key org-mode-map "\C-c\C-r"       'org-timeline)
- ;(define-key org-mode-map [(shift up)]     'org-timestamp-up)
- ;(define-key org-mode-map [(shift down)]   'org-timestamp-down)
  (define-key org-mode-map [(shift up)]     'org-shiftup)
  (define-key org-mode-map [(shift down)]   'org-shiftdown)
  (define-key org-mode-map [(shift left)]   'org-timestamp-down-day)
--- 7921,7926 ----
***************
*** 7864,7870 ****
    (if (and (org-table-p)
             (eq N 1)
             (looking-at "[^|\n]*  +|"))
!       (let (org-table-may-need-update (pos (point)))
          (goto-char (1- (match-end 0)))
          (delete-backward-char 1)
          (goto-char (match-beginning 0))
--- 7972,7978 ----
    (if (and (org-table-p)
             (eq N 1)
             (looking-at "[^|\n]*  +|"))
!       (let (org-table-may-need-update)
          (goto-char (1- (match-end 0)))
          (delete-backward-char 1)
          (goto-char (match-beginning 0))
***************
*** 7935,7959 ****
     ((org-at-table-p) (org-table-previous-field))
     (t (org-cycle '(4)))))
  
! (defun org-shiftmetaleft (&optional arg)
    "Call `org-promote-subtree' or `org-table-delete-column'."
!   (interactive "P")
    (cond
!    ((org-at-table-p) (org-table-delete-column arg))
!    ((org-on-heading-p) (org-promote-subtree arg))
     (t (org-shiftcursor-error))))
! (defun org-shiftmetaright (&optional arg)
    "Call `org-demote-subtree' or `org-table-insert-column'."
!   (interactive "P")
    (cond
!    ((org-at-table-p) (org-table-insert-column arg))
!    ((org-on-heading-p) (org-demote-subtree arg))
     (t (org-shiftcursor-error))))
  (defun org-shiftmetaup (&optional arg)
    "Call `org-move-subtree-up' or `org-table-kill-row'."
    (interactive "P")
    (cond
!    ((org-at-table-p) (org-table-kill-row arg))
     ((org-on-heading-p) (org-move-subtree-up arg))
     (t (org-shiftcursor-error))))
  (defun org-shiftmetadown (&optional arg)
--- 8043,8069 ----
     ((org-at-table-p) (org-table-previous-field))
     (t (org-cycle '(4)))))
  
! (defun org-shiftmetaleft ()
    "Call `org-promote-subtree' or `org-table-delete-column'."
!   (interactive)
    (cond
!    ((org-at-table-p) (org-table-delete-column))
!    ((org-on-heading-p) (org-promote-subtree))
     (t (org-shiftcursor-error))))
! 
! (defun org-shiftmetaright ()
    "Call `org-demote-subtree' or `org-table-insert-column'."
!   (interactive)
    (cond
!    ((org-at-table-p) (org-table-insert-column))
!    ((org-on-heading-p) (org-demote-subtree))
     (t (org-shiftcursor-error))))
+ 
  (defun org-shiftmetaup (&optional arg)
    "Call `org-move-subtree-up' or `org-table-kill-row'."
    (interactive "P")
    (cond
!    ((org-at-table-p) (org-table-kill-row))
     ((org-on-heading-p) (org-move-subtree-up arg))
     (t (org-shiftcursor-error))))
  (defun org-shiftmetadown (&optional arg)
***************
*** 7969,7983 ****
    (interactive "P")
    (cond
     ((org-at-table-p) (org-table-move-column 'left))
!    ((or (org-on-heading-p) (org-region-active-p)) (org-do-promote arg))
     (t (backward-word (prefix-numeric-value arg)))))
  (defun org-metaright (&optional arg)
    "Call `org-do-demote' or `org-table-move-column' to right."
    (interactive "P")
    (cond
     ((org-at-table-p) (org-table-move-column nil))
!    ((or (org-on-heading-p) (org-region-active-p)) (org-do-demote arg))
     (t (forward-word (prefix-numeric-value arg)))))
  (defun org-metaup (&optional arg)
    "Call `org-move-subtree-up' or `org-table-move-row' up."
    (interactive "P")
--- 8079,8095 ----
    (interactive "P")
    (cond
     ((org-at-table-p) (org-table-move-column 'left))
!    ((or (org-on-heading-p) (org-region-active-p)) (org-do-promote))
     (t (backward-word (prefix-numeric-value arg)))))
+ 
  (defun org-metaright (&optional arg)
    "Call `org-do-demote' or `org-table-move-column' to right."
    (interactive "P")
    (cond
     ((org-at-table-p) (org-table-move-column nil))
!    ((or (org-on-heading-p) (org-region-active-p)) (org-do-demote))
     (t (forward-word (prefix-numeric-value arg)))))
+ 
  (defun org-metaup (&optional arg)
    "Call `org-move-subtree-up' or `org-table-move-row' up."
    (interactive "P")
***************
*** 7985,7990 ****
--- 8097,8103 ----
     ((org-at-table-p) (org-table-move-row 'up))
     ((org-on-heading-p) (org-move-subtree-up arg))
     (t (org-shiftcursor-error))))
+ 
  (defun org-metadown (&optional arg)
    "Call `org-move-subtree-down' or `org-table-move-row' down."
    (interactive "P")
***************
*** 8007,8031 ****
     ((org-at-timestamp-p) (org-timestamp-down arg))
     (t (org-priority-down))))
  
! (defun org-copy-special (arg)
    "Call either `org-table-copy' or `org-copy-subtree'."
!   (interactive "P")
    (if (org-at-table-p)
!       (org-table-copy-region arg)
!     (org-copy-subtree arg)))
  
! (defun org-cut-special (arg)
!   "Call either `org-table-copy' or `org-copy-subtree'."
!   (interactive "P")
    (if (org-at-table-p)
!       (org-table-cut-region arg)
!     (org-cut-subtree arg)))
  
  (defun org-paste-special (arg)
    "Call either `org-table-paste-rectangle' or `org-paste-subtree'."
    (interactive "P")
    (if (org-at-table-p)
!       (org-table-paste-rectangle arg)
      (org-paste-subtree arg)))
  
  (defun org-ctrl-c-ctrl-c (&optional arg)
--- 8120,8144 ----
     ((org-at-timestamp-p) (org-timestamp-down arg))
     (t (org-priority-down))))
  
! (defun org-copy-special ()
    "Call either `org-table-copy' or `org-copy-subtree'."
!   (interactive)
    (if (org-at-table-p)
!       (org-table-copy-region)
!     (org-copy-subtree)))
  
! (defun org-cut-special ()
!   "Call either `org-table-copy' or `org-cut-subtree'."
!   (interactive)
    (if (org-at-table-p)
!       (org-table-cut-region)
!     (org-cut-subtree)))
  
  (defun org-paste-special (arg)
    "Call either `org-table-paste-rectangle' or `org-paste-subtree'."
    (interactive "P")
    (if (org-at-table-p)
!       (org-table-paste-rectangle)
      (org-paste-subtree arg)))
  
  (defun org-ctrl-c-ctrl-c (&optional arg)
***************
*** 8040,8051 ****
       ((org-at-table.el-p)
        (require 'table)
        (beginning-of-line 1)
!       (re-search-forward "|" (save-excursion (end-of-line 2) (point)))
        (table-recognize-table))
       ((org-at-table-p)
        (org-table-align))
       ((save-excursion (beginning-of-line 1) (looking-at "#\\+[A-Z]+"))
!       (let (org-inhibit-startup) (org-mode)))
       ((org-region-active-p)
        (org-table-convert-region (region-beginning) (region-end) arg))
       ((and (region-beginning) (region-end))
--- 8153,8164 ----
       ((org-at-table.el-p)
        (require 'table)
        (beginning-of-line 1)
!       (re-search-forward "|" (save-excursion (end-of-line 2) (point))) 
;FIXME: line-end-position?
        (table-recognize-table))
       ((org-at-table-p)
        (org-table-align))
       ((save-excursion (beginning-of-line 1) (looking-at "#\\+[A-Z]+"))
!       (let ((org-inhibit-startup t)) (org-mode)))
       ((org-region-active-p)
        (org-table-convert-region (region-beginning) (region-end) arg))
       ((and (region-beginning) (region-end))
***************
*** 8054,8062 ****
          (error "Abort")))
       (t (error "No table at point, and no region to make one.")))))
  
! (defun org-return (&optional arg)
    "Call `org-table-next-row' or `newline'."
!   (interactive "P")
    (cond
     ((org-at-table-p)
      (org-table-justify-field-maybe)
--- 8167,8175 ----
          (error "Abort")))
       (t (error "No table at point, and no region to make one.")))))
  
! (defun org-return ()
    "Call `org-table-next-row' or `newline'."
!   (interactive)
    (cond
     ((org-at-table-p)
      (org-table-justify-field-maybe)
***************
*** 8069,8075 ****
    (cond
     ((org-at-table-p)
      (org-table-wrap-region arg))
!    (t (org-insert-heading arg))))
  
  ;;; Menu entries
  
--- 8182,8188 ----
    (cond
     ((org-at-table-p)
      (org-table-wrap-region arg))
!    (t (org-insert-heading))))
  
  ;;; Menu entries
  
***************
*** 8256,8262 ****
  ;;; Miscellaneous stuff
  
  (defun org-move-line-down (arg)
!   "Move the current line up."
    (interactive "p")
    (let ((col (current-column))
        beg end pos)
--- 8369,8375 ----
  ;;; Miscellaneous stuff
  
  (defun org-move-line-down (arg)
!   "Move the current line down.  With prefix argument, move it past ARG lines."
    (interactive "p")
    (let ((col (current-column))
        beg end pos)
***************
*** 8269,8281 ****
      (move-to-column col)))
  
  (defun org-move-line-up (arg)
!   "Move the current line up."
    (interactive "p")
    (let ((col (current-column))
        beg end pos)
      (beginning-of-line 1) (setq beg (point))
      (beginning-of-line 2) (setq end (point))
!     (beginning-of-line (+ -2 arg))
      (setq pos (move-marker (make-marker) (point)))
      (insert (delete-and-extract-region beg end))
      (goto-char pos)
--- 8382,8394 ----
      (move-to-column col)))
  
  (defun org-move-line-up (arg)
!   "Move the current line up.  With prefix argument, move it past ARG lines."
    (interactive "p")
    (let ((col (current-column))
        beg end pos)
      (beginning-of-line 1) (setq beg (point))
      (beginning-of-line 2) (setq end (point))
!     (beginning-of-line (- arg))
      (setq pos (move-marker (make-marker) (point)))
      (insert (delete-and-extract-region beg end))
      (goto-char pos)
***************
*** 8284,8290 ****
  ;; Functions needed for Emacs/XEmacs region compatibility
  
  (defun org-region-active-p ()
!   "Is transient-mark-mode on and the region active?
  Works on both Emacs and XEmacs."
    (if org-ignore-region
        nil
--- 8397,8403 ----
  ;; Functions needed for Emacs/XEmacs region compatibility
  
  (defun org-region-active-p ()
!   "Is `transient-mark-mode' on and the region active?
  Works on both Emacs and XEmacs."
    (if org-ignore-region
        nil
***************
*** 8403,8409 ****
  This function considers both visible and invisible heading lines.
  With argument, move up ARG levels."
    (if org-noutline-p
!       (outline-up-heading arg t)
      (org-back-to-heading t)
      (looking-at outline-regexp)
      (if (<= (- (match-end 0) (match-beginning 0)) arg)
--- 8516,8524 ----
  This function considers both visible and invisible heading lines.
  With argument, move up ARG levels."
    (if org-noutline-p
!       (if (fboundp 'outline-up-heading-all) 
!           (outline-up-heading-all arg)   ; emacs 21 version of outline.el
!         (outline-up-heading arg t))      ; emacs 22 version of outline.el
      (org-back-to-heading t)
      (looking-at outline-regexp)
      (if (<= (- (match-end 0) (match-beginning 0)) arg)
***************
*** 8422,8428 ****
          (progn
            (org-back-to-heading t)
            (org-flag-heading nil)))
!     (show-entry)))
  
  (defun org-check-occur-regexp (regexp)
    "If REGEXP starts with \"^\", modify it to check for \\r as well.
--- 8537,8543 ----
          (progn
            (org-back-to-heading t)
            (org-flag-heading nil)))
!     (org-show-entry)))
  
  (defun org-check-occur-regexp (regexp)
    "If REGEXP starts with \"^\", modify it to check for \\r as well.
***************
*** 8444,8450 ****
      ;; Check if we should show the entire entry
      (if entry
          (progn
!           (show-entry)
            (save-excursion  ;; FIXME: Is this the fix for points in the   -|
                             ;;        middle of text?                      |
              (and (outline-next-heading)   ;;                              |
--- 8559,8565 ----
      ;; Check if we should show the entire entry
      (if entry
          (progn
!           (org-show-entry)
            (save-excursion  ;; FIXME: Is this the fix for points in the   -|
                             ;;        middle of text?                      |
              (and (outline-next-heading)   ;;                              |
***************
*** 8455,8460 ****
--- 8570,8597 ----
                                 flag
                               (if flag ?\r ?\n))))))
  
+ (defun org-show-subtree ()
+   "Show everything after this heading at deeper levels."
+   (outline-flag-region 
+    (point) 
+    (save-excursion
+      (outline-end-of-subtree) (outline-next-heading) (point))
+    (if org-noutline-p nil ?\n)))
+ 
+ (defun org-show-entry ()
+   "Show the body directly following this heading.
+ Show the heading too, if it is currently invisible."
+   (interactive)
+   (save-excursion
+     (org-back-to-heading t)
+     (outline-flag-region 
+      (1- (point))
+      (save-excursion
+        (re-search-forward (concat "[\r\n]\\(" outline-regexp "\\)") nil 'move)
+        (or (match-beginning 1) (point-max)))
+      (if org-noutline-p nil ?\n))))
+ 
+ 
  (defun org-make-options-regexp (kwds)
    "Make a regular expression for keyword lines."
    (concat




reply via email to

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