Browse Source

Apply patches by James TD Smith.

Carsten Dominik 17 years ago
parent
commit
d2d495df4f
8 changed files with 297 additions and 151 deletions
  1. 8 0
      ChangeLog
  2. 113 71
      ORGWEBPAGE/Changes.org
  3. 15 11
      doc/org.texi
  4. 5 5
      lisp/org-agenda.el
  5. 2 1
      lisp/org-clock.el
  6. 32 10
      lisp/org-remember.el
  7. 73 39
      lisp/org-table.el
  8. 49 14
      lisp/org.el

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-04-10  Carsten Dominik  <dominik@science.uva.nl>
+
+	* lisp/org-clock.el (org-dblock-write:clocktable): Fixed bug with
+	total time calculation.
+
+2008-04-09  Carsten Dominik  <dominik@science.uva.nl>
+
+	* lisp/org.el (org-make-link-description-function): New option.
 
 2008-04-09  Bastien Guerry  <bzg@altern.org>
 

+ 113 - 71
ORGWEBPAGE/Changes.org

@@ -9,28 +9,43 @@
 
 ** Details
 
-*** Faces
+*** The Org distribution has a new structure
 
-    There are now special faces for the date lines in the
-    agenda/timeline buffers, and another special face for days
-    that fall on a weekend: `org-agenda-date' and
-    `org-agenda-date-weekend'.
+    In the distribution files, the lisp files are now located in
+    a subdirectory "lisp", and the documentation files are
+    located in a subdirectory "doc".  If you are running Org
+    directly from the unpacked distribtuion archive (zip or tar
+    file), you need to modify your settings for load-path
+    accordingly.
+
+*** Loading modules
+
+    Org-mode has now a system for loading modules by simply
+    configuring an option that lists all the modules you want to
+    use.  Customize the variable `org-modules'.  That variable
+    lists modules that are part of the Org-mode core (and in this
+    way part of Emacs), as well as contributed packages that will
+    only be available when you have installed them properly (most
+    likely by downloading the distribution and adding
+    /path/to/orgdir/contrib/lisp to your load path.
 
-*** New archiving mechanism: The Attic Sibling
+*** New archiving mechanism: The Archive Sibling
 
     There is a new method to archive entries in the current file:
-    By moving it to a sibling called the Attic Sibling.  That
-    sibling has the heading "Attic" and also carries the ARCHIVE
+    By moving it to a sibling called the /Archive Sibling/.  That
+    sibling has the heading "Archive" and also carries the ARCHIVE
     tag.  It seems to me that this is a great way to do archiving
     inside a project, to get parts of the project out of the way
-    and to wait with archiving the entire project until it is
-    truly done.  The key binding for the is "C-c C-x A", and
-    from the agenda buffer you can simply use "A".
+    and to wait with true archiving (moving to another file)
+    until the entire project done.  The key binding for the is
+    "C-c C-x A", and from the agenda buffer you can simply use
+    "A".
 
-    Thanks to Ilya Shlyakhter for this brilliant idea.
+    Thanks to Ilya Shlyakhter for this rather clever idea.
 
 *** Support for Sebastian Rose's Javasript org-info.js.
-    This fascinating program allows and Org file (exported to
+
+    This fascinating program allows an Org file (exported to
     HTML) to be viewed different ways.  There is an Info-like
     interface where you can jump through the sections of the
     document with the `n' and `p' keys (and others).  And there
@@ -55,15 +70,6 @@
     For details see the documentation provided by Sebastian Rose
     together with org-info.js.
 
-*** The Org distribution has a new structure
-
-    In the distribution files, the lisp files are now located in
-    a subdirectory "lisp", and the documentation files are
-    located in a subdirectory "doc".  If you are running Org
-    directly from the unpacked distribtuion archive (zip or tar
-    file), you need to modify your settings for load-path
-    accordingly.
-
 *** Improvements to clocktable
 
     - The clocktable is now much more flexible and user friendly
@@ -99,35 +105,15 @@
       total time for each file will now also be listed.  This was
       a request from Bernt Hansen.
 
-*** Clockreport in the daily/weekly arenda
-
-    If you turn on clockreport mode with the "R" key in the
-    agenda, a clock table will be attached to the agenda, showing
-    the clock report for the file scope and time interval of the
-    agenda view.  To turn this on permanently, configure the
-    variable =org-agenda-start-with-clockreport-mode=.  To modify
-    the properties of the table, in particula the =:maxlevel=
-    depth, configure =org-agenda-clockreport-parameter-plist=.
-
-*** Selective tag inheritance
-
-    Inheritance of tags can now be limited to a subset of all
-    tags, using the variable =org-use-tag-inheritance=.  This
-    variable may now be a regular expression or a list to select
-    the inherited tags.  Thanks to Michael Ekstrand for this
-    excellent proposal.
 
-    The regexp option is also implemented for
-    =org-use-property-inheritance=, so that you can now select
-    properties for inheritance my name.
-
-*** Changes to property API
-
-    The INHERIT flag to the function =org-entry-get= can be set
-    to the symbol =selective=.  If this is the case, then the
-    value of the property will be retrieved using inheritance if
-    and only if the setting in =org-use-property-inheritance=
-    selects the property for inheritance.
+    - If you turn on the new clockreport mode with the "R" key in
+      the agenda, a clock table will be attached to the agenda,
+      showing the clock report for the file scope and time
+      interval of the agenda view.  To turn this on permanently,
+      configure the variable
+      =org-agenda-start-with-clockreport-mode=.  To modify the
+      properties of the table, in particula the =:maxlevel=
+      depth, configure =org-agenda-clockreport-parameter-plist=.
 
 *** Support for ISO week dates (ISO 6801)
 
@@ -171,17 +157,6 @@
 
     This was a request by Thomas Baumann.
 
-*** Loading modules
-
-    Org-mode has now a system for loading modules by simply
-    configuring an option that lists all the modules you want to
-    use.  Customize the variable `org-modules'.  That variable
-    lists modules that are part of the Org-mode core (and in this
-    way part of Emacs), as well as contributed packages that will
-    only be available when you have installed them properly (most
-    likely by downloading the distribution and adding
-    CONTRIB/lisp to your load path.
-
 *** Improvements in Search View
     
     - Calling search view with a C-u prefix will make it match
@@ -191,20 +166,87 @@
       during search, so that searching for the word "Nasim" will
       also match in "Nasim's".
 
+*** Changes to property API
+
+    The INHERIT flag to the function =org-entry-get= can be set
+    to the symbol =selective=.  If this is the case, then the
+    value of the property will be retrieved using inheritance if
+    and only if the setting in =org-use-property-inheritance=
+    selects the property for inheritance.
+
 *** Misc
+    
+    - Inheritance of tags can now be limited to a subset of all
+      tags, using the variable =org-use-tag-inheritance=.  This
+      variable may now be a regular expression or a list to
+      select the inherited tags.  Thanks to Michael Ekstrand for
+      this excellent proposal.
+      
+      The regexp option is also implemented for
+      =org-use-property-inheritance=, so that you can now select
+      properties for inheritance my name.
+
+    - There are now special faces for the date lines in the
+      agenda/timeline buffers, and another special face for days
+      that fall on a weekend: `org-agenda-date' and
+      `org-agenda-date-weekend'.
+      
+    - When an entry already has a scheduling or deadline time
+      stamp, calling `C-c C-s' or `C-c C-d', respectively, will
+      now use that old date as the default, and you can can use
+      the "++4d" syntax to invoke shifts relative to that default
+      date.  Simply pressing RET at the prompt will keep the
+      default date, not switch to today.
+      
+      This was an omission in the earlier implementation, spotted
+      by Wanrong Lin.  Thanks!
+      
+    - File names in remember templates can be relative, they will
+      be interpreted relative to =org-directory=.
+      
+    - The handling of the cliboard when inserting into remember
+      templates is now much better, and gives more control on what
+      should be inserted with new %-escapes:
+      
+      - =%c= - Now always insert to head of the kill ring
+      - =%x= - Insert the content of the X clipboard. This is the
+	first non-empty value from the PRIMARY, SECONDARY and
+	CLIPBOARD X clipboards. 
+	
+      - =%^C= - This allows the user to choose between any of the
+	clipboard values available, the kill ring head, and the
+	initial region if set.  
+	
+      - =%^L= - Like =%^C=, but this inserts an org link using the
+	selected value.
+	
+      Thanks to James TD Smith for this patch.
+	
+    - Table export to an internal file can now use a format
+      specification, similar to the formats that are used by
+      orgtbl radio tables.  The default format is in the variable
+      =org-table-export-default-format=.  You can use properties
+      =TABLE_EXPORT_FILE= and =TABLE_EXPORT_FORMAT= to specify the
+      file name to which the export should go, and a local
+      format.  For example:
+     
+      : :PROPERTIES:
+      : :TABLE_EXPORT_FILE: ~/xx.txt
+      : :TABLE_EXPORT_FORMAT: orgtbl-to-generic :splice t :sep "\t"
+      : :END:
+
+      Thanks to James TD Smith for this patch.
+
+    - Entries can be sorted by TODO keyword, and the orde is given
+      by the definition sequence of the TODO keywords in the
+      variable =org-todo-keywords=, or in the =#+TODO= line.  Use
+      the "o" key when sorting with =C-c ^=.
+      
+      Thanks to James TD Smith for this patch.
+
 
-   - When an entry already has a scheduling or deadline time
-     stamp, calling `C-c C-s' or `C-c C-d', respectively, will
-     now use that old date as the default, and you can can use
-     the "++4d" syntax to invoke shifts relative to that default
-     date.  Simply pressing RET at the prompt will keep the
-     default date, not switch to today.
 
-     This was an omission in the earlier implementation, spotted
-     by Wanrong Lin.  Thanks!
 
-   - File names in remember templates can be relative, they will
-     be interpreted relative to =org-directory=.
 
 * Version 5.23
 

+ 15 - 11
doc/org.texi

@@ -897,14 +897,15 @@ headline marker like @samp{****}.
 Refile entry to a different location.  @xref{Refiling notes}.
 @kindex C-c ^
 @item C-c ^
-Sort same-level entries.  When there is an active region, all entries in
-the region will be sorted.  Otherwise the children of the current
-headline are sorted.  The command prompts for the sorting method, which
-can be alphabetically, numerically, by time (using the first time stamp
-in each entry), by priority, and each of these in reverse order.  You
-can also supply your own function to extract the sorting key.  With a
-@kbd{C-u} prefix, sorting will be case-sensitive.  With two @kbd{C-u
-C-u} prefixes, duplicate entries will also be removed.
+Sort same-level entries.  When there is an active region, all entries in the
+region will be sorted.  Otherwise the children of the current headline are
+sorted.  The command prompts for the sorting method, which can be
+alphabetically, numerically, by time (using the first time stamp in each
+entry), by priority, or by TODO keyword (in the sequence the keywords have
+been defined in the setup).  Reverse sorting is possible as well.  You can
+also supply your own function to extract the sorting key.  With a @kbd{C-u}
+prefix, sorting will be case-sensitive.  With two @kbd{C-u C-u} prefixes,
+duplicate entries will also be removed.
 @kindex C-c *
 @item C-c *
 Turn a normal line or plain list item into a headline (so that it
@@ -4705,7 +4706,10 @@ insertion of content:
 %A          @r{like @code{%a}, but prompt for the description part}
 %i          @r{initial content, the region when remember is called with C-u.}
             @r{The entire text will be indented like @code{%i} itself.}
-%c          @r{Content of the clipboard, or current kill ring head.}
+%c          @r{Current kill ring head.}
+%x          @r{Content of the X clipboard.}
+%^C         @r{Interactive selection of which kill or clip to use.}
+%^L         @r{Like @code{%^C}, but insert as link.}
 %^g         @r{prompt for tags, with completion on tags in target file.}
 %^G         @r{prompt for tags, with completion all tags in all agenda files.}
 %:keyword   @r{specific information for certain link types, see below}
@@ -5613,7 +5617,7 @@ Toggle the ARCHIVE tag for the current headline.
 @c
 @kindex A
 @item A
-Move the subtree correspoding to the current entry to its @emph{Attic
+Move the subtree correspoding to the current entry to its @emph{Archive
 Sibling}.
 @c
 @kindex $
@@ -8926,7 +8930,7 @@ other things.
 Linking to VM/BBDB/Gnus was inspired by @i{Tom Shannon}'s
 @file{organizer-mode.el}.
 @item
-@i{Ilya Shlyakhter} proposed the Attic Sibling.
+@i{Ilya Shlyakhter} proposed the Archive Sibling.
 @item
 @i{Daniel Sinder} came up with the idea of internal archiving by locking
 subtrees.

+ 5 - 5
lisp/org-agenda.el

@@ -1007,7 +1007,7 @@ The following commands are available:
 (org-defkey org-agenda-mode-map "\C-c$"    'org-agenda-archive)
 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
 (org-defkey org-agenda-mode-map "$"        'org-agenda-archive)
-(org-defkey org-agenda-mode-map "A"        'org-agenda-archive-to-attic-sibling)
+(org-defkey org-agenda-mode-map "A"        'org-agenda-archive-to-archive-sibling)
 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
 (org-defkey org-agenda-mode-map " "        'org-agenda-show)
 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
@@ -1114,7 +1114,7 @@ The following commands are available:
     ["Cycle TODO" org-agenda-todo t]
     ("Archive"
      ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
-     ["Move to attic sibling" org-agenda-archive-to-attic-sibling t]
+     ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
      ["Archive subtree" org-agenda-archive t])
     ["Delete subtree" org-agenda-kill t]
     ["Add note" org-agenda-add-note t]
@@ -4307,8 +4307,8 @@ Point is in the buffer where the item originated.")
 	      (org-archive-subtree))
 	  (error "Archiving works only in Org-mode files"))))))
 
-(defun org-agenda-archive-to-attic-sibling ()
-  "Move the entry to the attic sibling."
+(defun org-agenda-archive-to-archive-sibling ()
+  "Move the entry to the archive sibling."
   (interactive)
   (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
   (let* ((marker (or (get-text-property (point) 'org-marker)
@@ -4322,7 +4322,7 @@ Point is in the buffer where the item originated.")
 	      (goto-char pos)
 	      (org-remove-subtree-entries-from-agenda)
 	      (org-back-to-heading t)
-	      (org-archive-to-attic-sibling))
+	      (org-archive-to-archive-sibling))
 	  (error "Archiving works only in Org-mode files"))))))
 
 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)

+ 2 - 1
lisp/org-clock.el

@@ -578,7 +578,7 @@ the currently selected interval size."
   (catch 'exit
     (let* ((hlchars '((1 . "*") (2 . "/")))
 	   (ins (make-marker))
-	   (total-time 0)
+	   (total-time nil)
 	   (scope (plist-get params :scope))
 	   (tostring (plist-get  params :tostring))
 	   (multifile (plist-get  params :multifile))
@@ -592,6 +592,7 @@ the currently selected interval size."
 	   (link (plist-get params :link))
 	   ipos time p level hlc hdl
 	   cc beg end pos tbl tbl1 range-text)
+      (setq org-clock-file-total-minutes nil)
       (when step
 	(org-clocktable-steps params)
 	(throw 'exit nil))

+ 32 - 10
lisp/org-remember.el

@@ -275,8 +275,13 @@ RET at beg-of-buf -> Append to file as level 2 headline
 			 char0))))))
       (cddr (assoc char templates)))))
 
-(defvar x-last-selected-text)
-(defvar x-last-selected-text-primary)
+(defun org-get-x-clipboard (value)
+  "Get the value of the x clibboard, in a way that also works with XEmacs."
+  (if (eq window-system 'x)
+      (let ((x (if org-xemacs-p
+		   (org-no-warnings (get-selection-no-error value))
+		 (x-selection-value value))))
+	(and (> (length x) 0) (set-text-properties 0 (length x) nil x) x))))
 
 ;;;###autoload
 (defun org-remember-apply-template (&optional use-char skip-interactive)
@@ -292,12 +297,10 @@ to be run from that hook to function properly."
 		       (nth 1 entry)
 		     org-default-notes-file))
 	     (headline (nth 2 entry))
-	     (v-c (or (and (eq window-system 'x)
-			   (fboundp 'x-cut-buffer-or-selection-value)
-			   (x-cut-buffer-or-selection-value))
-		      (org-bound-and-true-p x-last-selected-text)
-		      (org-bound-and-true-p x-last-selected-text-primary)
-		      (and (> (length kill-ring) 0) (current-kill 0))))
+	     (v-c (and (> (length kill-ring) 0) (current-kill 0)))
+	     (v-x (or (org-get-x-clipboard 'PRIMARY)
+		      (org-get-x-clipboard 'CLIPBOARD)
+		      (org-get-x-clipboard 'SECONDARY)))
 	     (v-t (format-time-string (car org-time-stamp-formats) (org-current-time)))
 	     (v-T (format-time-string (cdr org-time-stamp-formats) (org-current-time)))
 	     (v-u (concat "[" (substring v-t 1 -1) "]"))
@@ -307,6 +310,11 @@ to be run from that hook to function properly."
 	     (v-a (if (and (boundp 'annotation) annotation)
 		      (if (equal annotation "[[]]") "" annotation)
 		    ""))
+	     (clipboards (remove nil (list v-i
+					   (org-get-x-clipboard 'PRIMARY)
+					   (org-get-x-clipboard 'CLIPBOARD)
+					   (org-get-x-clipboard 'SECONDARY)
+					   v-c)))
 	     (v-A (if (and v-a
 			   (string-match "\\[\\(\\[.*?\\]\\)\\(\\[.*?\\]\\)?\\]" v-a))
 		      (replace-match "[\\1[%^{Link description}]]" nil nil v-a)
@@ -337,7 +345,7 @@ to be run from that hook to function properly."
 		  (or (cdr org-remember-previous-location) "???"))))
 	(insert tpl) (goto-char (point-min))
 	;; Simple %-escapes
-	(while (re-search-forward "%\\([tTuUaiAc]\\)" nil t)
+	(while (re-search-forward "%\\([tTuUaiAcx]\\)" nil t)
 	  (when (and initial (equal (match-string 0) "%i"))
 	    (save-match-data
 	      (let* ((lead (buffer-substring
@@ -391,7 +399,7 @@ to be run from that hook to function properly."
 	    (org-set-local 'org-remember-default-headline headline))
 	;; Interactive template entries
 	(goto-char (point-min))
-	(while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGuUtT]\\)?" nil t)
+	(while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGuUtTCL]\\)?" nil t)
 	  (setq char (if (match-end 3) (match-string 3))
 		prompt (if (match-end 2) (match-string 2)))
 	  (goto-char (match-beginning 0))
@@ -422,6 +430,20 @@ to be run from that hook to function properly."
 		(or (equal (char-before) ?:) (insert ":"))
 		(insert ins)
 		(or (equal (char-after) ?:) (insert ":")))))
+	   ((equal char "C")
+	    (cond ((= (length clipboards) 1) (insert (car clipboards)))
+		  ((> (length clipboards) 1)
+		   (insert (read-string "Clipboard/kill value: "
+					(car clipboards) '(clipboards . 1)
+					(car clipboards))))))
+	   ((equal char "L")
+	    (cond ((= (length clipboards) 1)
+		   (org-insert-link 0 (car clipboards)))
+		  ((> (length clipboards) 1)
+		   (org-insert-link 0 (read-string "Clipboard/kill value: "
+						   (car clipboards)
+						   '(clipboards . 1)
+						   (car clipboards))))))
 	   (char
 	    (setq org-time-was-given (equal (upcase char) char))
 	    (setq time (org-read-date (equal (upcase char) "U") t nil

+ 73 - 39
lisp/org-table.el

@@ -41,6 +41,8 @@
   (require 'cl))
 (require 'org)
 
+(declare-function org-table-clean-before-export "org-exp" (lines))
+(declare-function org-format-org-table-html "org-exp" (lines &optional splice))
 (defvar orgtbl-mode) ; defined below
 (defvar orgtbl-mode-menu) ; defined when orgtbl mode get initialized
 
@@ -244,17 +246,19 @@ Automatically means, when TAB or RET or C-c C-c are pressed in the line."
   :group 'org-table-calculation
   :type 'boolean)
 
+(defgroup org-table-import-export nil
+  "Options concerning table import and export in Org-mode."
+  :tag "Org Table Import Export"
+  :group 'org-table)
 
-
-
-
-
-
-
-
-
-
-
+(defcustom org-table-export-default-format
+  "orgtbl-to-generic :splice t :sep \"\t\""
+  "Default export parameters for org-table-export. These can be
+  overridden on for a specific table by setting the
+  TABLE_EXPORT_FORMAT parameter. See orgtbl-export for the
+  different export transforms and available parameters."
+  :group 'org-table-import-export
+  :type 'string)
 
 (defconst org-table-auto-recalculate-regexp "^[ \t]*| *# *\\(|\\|$\\)"
   "Detects a table line marked for automatic recalculation.")
@@ -422,41 +426,73 @@ are found, lines will be split on whitespace into fields."
     (insert-file-contents file)
     (org-table-convert-region beg (+ (point) (- (point-max) pm)) arg)))
 
-(defun org-table-export ()
+
+(defvar org-table-last-alignment)
+(defvar org-table-last-column-widths)
+(defun org-table-export (&optional file format)
   "Export table as a tab-separated file.
-Such a file can be imported into a spreadsheet program like Excel."
+Such a file can be imported into a spreadsheet program like Excel.
+FILE can be the output file name.  If not given, it will be taken from
+a TABLE_EXPORT_FILE property in the current entry or higher up in the
+hierarchy, or the user will be prompted for a file name.
+FORMAT can be an export format, of the same kind as it used when
+orgtbl-mode sends a table in a different format.  The default format can
+be found in the variable `org-table-export-default-format', but the function
+first checks if there is an export format specified in a TABLE_EXPORT_FORMAT
+property, locally or anywhere up in the hierarchy."
   (interactive)
+  (org-table-align) ;; make sure we have everything we need
   (let* ((beg (org-table-begin))
 	 (end (org-table-end))
-	 (table (buffer-substring beg end))
-	 (file (read-file-name "Export table to: "))
+	 (txt (buffer-substring-no-properties beg end))
+	 (file (or file (org-entry-get beg "TABLE_EXPORT_FILE" t)
+		   (read-file-name "Export table to: ")))
+	 (format (or (org-entry-get beg "TABLE_EXPORT_FORMAT" t)
+		     org-table-export-default-format))
 	 buf)
     (unless (or (not (file-exists-p file))
 		(y-or-n-p (format "Overwrite file %s? " file)))
       (error "Abort"))
-    (with-current-buffer (find-file-noselect file)
-      (setq buf (current-buffer))
-      (erase-buffer)
-      (fundamental-mode)
-      (insert table)
-      (goto-char (point-min))
-      (while (re-search-forward "^[ \t]*|[ \t]*" nil t)
-	(replace-match "" t t)
-	(end-of-line 1))
-      (goto-char (point-min))
-      (while (re-search-forward "[ \t]*|[ \t]*$" nil t)
-	(replace-match "" t t)
-	(goto-char (min (1+ (point)) (point-max))))
-      (goto-char (point-min))
-      (while (re-search-forward "^-[-+]*$" nil t)
-	(replace-match "")
-	(if (looking-at "\n")
-	    (delete-char 1)))
-      (goto-char (point-min))
-      (while (re-search-forward "[ \t]*|[ \t]*" nil t)
-	(replace-match "\t" t t))
-      (save-buffer))
-    (kill-buffer buf)))
+    (message format)
+    
+    (if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format)
+	(let* ((transform (intern (match-string 1 format)))
+	       (params (if (match-end 2)
+			   (read (concat "(" (match-string 2 format) ")"))))
+	       (skip (plist-get params :skip))
+	       (skipcols (plist-get params :skipcols))
+	       (lines (nthcdr (or skip 0) (org-split-string txt "[ \t]*\n[ \t]*")))
+	       (lines (org-table-clean-before-export lines))
+	       (i0 (if org-table-clean-did-remove-column 2 1))
+	       (table (mapcar
+		       (lambda (x)
+			 (if (string-match org-table-hline-regexp x)
+			     'hline
+			   (org-remove-by-index
+			    (org-split-string (org-trim x) "\\s-*|\\s-*")
+			    skipcols i0)))
+		       lines))
+	       (fun (if (= i0 2) 'cdr 'identity))
+	       (org-table-last-alignment
+		(org-remove-by-index (funcall fun org-table-last-alignment)
+				     skipcols i0))
+	       (org-table-last-column-widths
+		(org-remove-by-index (funcall fun org-table-last-column-widths)
+				     skipcols i0)))
+	  
+	  (unless (fboundp transform)
+	    (error "No such transformation function %s" transform))
+	  (setq txt (funcall transform table params))
+	  
+	  (with-current-buffer (find-file-noselect file)
+	    (setq buf (current-buffer))
+	    (erase-buffer)
+	    (fundamental-mode)
+	    (insert txt "\n")
+	    (save-buffer))
+	  (kill-buffer buf)
+	  (message "Export done."))
+      (error "TABLE_EXPORT_FORMAT invalid"))))
 
 (defvar org-table-aligned-begin-marker (make-marker)
   "Marker at the beginning of the table last aligned.
@@ -3431,8 +3467,6 @@ overwritten, and the table is not marked as requiring realignment."
 (defvar orgtbl-exp-regexp "^\\([-+]?[0-9][0-9.]*\\)[eE]\\([-+]?[0-9]+\\)$"
   "Regular expression matching exponentials as produced by calc.")
 
-(declare-function org-table-clean-before-export "org-exp" (lines))
-(declare-function org-format-org-table-html "org-exp" (lines &optional splice))
 (defun orgtbl-export (table target)
   (require 'org-exp)
   (let ((func (intern (concat "orgtbl-to-" (symbol-name target))))

+ 49 - 14
lisp/org.el

@@ -876,6 +876,15 @@ Changing this variable requires a restart of Emacs to become effective."
 	      (const :tag "Tags" tag)
 	      (const :tag "Timestamps" date)))
 
+(defcustom org-make-link-description-function nil
+  "Function to use to generate link descriptions from links. If
+nil the link location will be used. This function must take two
+parameters; the first is the link and the second the description
+org-insert-link has generated, and should return the description
+to use."
+  :group 'org-link
+  :type 'function)
+
 (defgroup org-link-store nil
   "Options concerning storing links in Org-mode."
   :tag "Org Store Link"
@@ -2467,7 +2476,7 @@ collapsed state."
 	(org-end-of-subtree t)))))
 
 (org-autoload "org-archive"
-  '(org-archive-subtree org-archive-to-attic-sibling org-toggle-archive-tag))
+  '(org-archive-subtree org-archive-to-archive-sibling org-toggle-archive-tag))
 
 ;; Autoload Column View Code
 
@@ -4875,7 +4884,7 @@ WITH-CASE, the sorting considers case as well."
       (message
        (if plain-list-p
 	   "Sort %s: [a]lpha [n]umeric [t]ime [f]unc  A/N/T/F means reversed:"
-	 "Sort %s: [a]lpha [n]umeric [t]ime [p]riority p[r]operty [f]unc  A/N/T/P/F means reversed:")
+	 "Sort %s: [a]lpha [n]umeric [t]ime [p]riority p[r]operty todo[o]rder [f]unc  A/N/T/P/O/F means reversed:")
        what)
       (setq sorting-type (read-char-exclusive))
 
@@ -4966,6 +4975,10 @@ WITH-CASE, the sorting considers case as well."
 		 org-default-priority))
 	      ((= dcst ?r)
 	       (or (org-entry-get nil property) ""))
+	      ((= dcst ?o)
+	       (if (looking-at org-complex-heading-regexp)
+		   (- 9999 (length (member (match-string 2)
+					   org-todo-keywords-1)))))
 	      ((= dcst ?f)
 	       (if getkey-func
 		   (progn
@@ -6353,7 +6366,7 @@ This command can be called in any mode to insert a link in Org-mode syntax."
   (org-load-modules-maybe)
   (org-run-like-in-org-mode 'org-insert-link))
 
-(defun org-insert-link (&optional complete-file)
+(defun org-insert-link (&optional complete-file link-location)
   "Insert a link.  At the prompt, enter the link.
 
 Completion can be used to select a link previously stored with
@@ -6368,16 +6381,22 @@ be displayed in the buffer instead of the link.
 If there is already a link at point, this command will allow you to edit link
 and description parts.
 
-With a \\[universal-argument] prefix, prompts for a file to link to.  The file name can be
-selected using completion.  The path to the file will be relative to
-the current directory if the file is in the current directory or a
-subdirectory.  Otherwise, the link will be the absolute path as
-completed in the minibuffer (i.e. normally ~/path/to/file).
+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. With three \\[universal-argument] prefixes, negate the meaning
+of `org-keep-stored-link-after-insertion'.
+
+If `org-make-link-description-function' is non-nil, this function will be
+called with the link target, and the result will be the default
+link description.
 
-With two \\[universal-argument] prefixes, enforce an absolute path even if the file
-is in the current directory or below.
-With three \\[universal-argument] prefixes, negate the meaning of
-`org-keep-stored-link-after-insertion'."
+If the LINK-LOCATION parameter is non-nil, this value will be
+used as the link location instead of reading one interactively."
   (interactive "P")
   (let* ((wcf (current-window-configuration))
 	 (region (if (org-region-active-p)
@@ -6385,8 +6404,10 @@ With three \\[universal-argument] prefixes, negate the meaning of
 	 (remove (and region (list (region-beginning) (region-end))))
 	 (desc region)
 	 tmphist ; byte-compile incorrectly complains about this
-	 link entry file)
+	 (link link-location)
+	 entry file)
     (cond
+     (link-location) ; specified by arg, just use it.
      ((org-in-regexp org-bracket-link-regexp 1)
       ;; We do have a link at point, and we are going to edit it.
       (setq remove (list (match-beginning 0) (match-end 0)))
@@ -6498,6 +6519,9 @@ With three \\[universal-argument] prefixes, negate the meaning of
 	(if (equal desc origpath)
 	    (setq desc path))))
 
+    (if org-make-link-description-function
+	(setq desc (funcall org-make-link-description-function link desc)))
+
     (setq desc (read-string "Description: " desc))
     (unless (string-match "\\S-" desc) (setq desc nil))
     (if remove (apply 'delete-region remove))
@@ -11545,7 +11569,7 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-toggle-archive-tag)
 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
-(org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-attic-sibling)
+(org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
@@ -12460,14 +12484,25 @@ With optional NODE, go directly to that node."
 
 ;;;; Documentation
 
+(defun org-require-autoloaded-modules ()
+  (interactive)
+  (mapc 'require
+	'(org-agenda org-archive org-clock org-colview
+		     org-exp org-export-latex org-publish
+		     org-remember org-table)))
+
 (defun org-customize ()
   "Call the customize function with org as argument."
   (interactive)
+  (org-load-modules-maybe)
+  (org-require-autoloaded-modules)
   (customize-browse 'org))
 
 (defun org-create-customize-menu ()
   "Create a full customization menu for Org-mode, insert it into the menu."
   (interactive)
+  (org-load-modules-maybe)
+  (org-require-autoloaded-modules)
   (if (fboundp 'customize-menu-create)
       (progn
 	(easy-menu-change