diff lisp/org/org-exp.el @ 98644:e1cc41b9282d

2008-10-12 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-edit-fixed-width-region): Exclude final newline from picture area. * org-export-latex.el (org-export-latex-subcontent): Add labels to sections, to make internal links work. (org-export-latex-fontify-headline): Do not remove all text properties, to make sure that target properties survive this process. * org-exp.el (org-export-preprocess-string): Change sequence of modifications, to make sure links are prepared before the LaTeX conversions do happen. * org-attach.el (org-attach-delete-all): Renamed from `org-attch-delete'. Add a security query before deleting the entire directory. New optional argument FORCE can overrule the security query. (org-attach-delete-one): New command. * org-attach.el (org-attach-file-list): Fix bug with directory. * org.el (org-apps-regexp-alist): New function. (org-file-apps): Add auto-mode to the default value. (org-open-file): Use the new structure of org-file-apps. * org-attach.el (org-attach): Support the new keys. (org-attach-method): New option. * org-bbdb.el (org-bbdb-anniversaries): Fix but with 29 Feb/1 March. * org.el (org-remove-uniherited-tags): Fix reverse interpretation of the list value o `org-use-tag-inheritance'. * org-attach.el (org-attach-auto-tag): New option. (org-attach-tag, org-attach-untag): New functions. (org-attach-attach, org-attach-new, org-attach-sync): Call `org-attach-tag'. (org-attach-delete): Call `org-attach-untag'. * org-attach.el: New file. * org-table.el (orgtbl-self-insert-command): Make this work for the keypad as well. * org.el (org-add-log-setup): Limit searc for drawers to entry text, not to subtree. * org-clock.el (org-clock-heading-for-remember): New variable. (org-clock-in): Set `org-clock-heading-for-remember'. 2008-10-12 James TD Smith <ahktenzero@mohorovi.cc> * org-remember.el (org-remember-apply-template): Add new expansions: %k, %K for currently clocked task and a link to the currently clocked task, and %< to file notes in the currently clocked task. 2008-10-12 Carsten Dominik <dominik@science.uva.nl> * org-export-latex.el (org-export-latex-make-header): Also insert the content of the property :latex-header-extra. * org-exp.el (org-infile-export-plist): Put the content of #+LATEX_HEADER: into the property :latex-header-extra. * org-colview.el (org-columns-get-format-and-top-level): Remove resetting the marker. * org-colview-xemacs.el (org-columns-get-format-and-top-level): Remove resetting the marker. * org.el (org-entry-property-inherited-from): Improve docstring. (org-entry-get-with-inheritance): Reset marker before starting the search. * org-exp.el (org-infile-export-plist): Allow multiple STYLE lines. * org.el (org-entry-get-multivalued-property) (org-entry-protect-space, org-entry-restore-space): New functions. (org-file-apps-defaults-macosx): Let postscript files be opened by preview. (org-time-stamp-inactive): Call `org-time-stamp'. (org-time-stamp): New argument `inactive'. Also edit inacive stamps. Convert time stamp type. (org-open-file): Interpret the `default' value for the `command' in `org-file-apps'. * org-id.el (org-id-int-to-b36-one-digit) (org-id-b36-to-int-one-digit, org-id-int-to-b36) (org-id-b36-to-int, org-id-time-to-b36): Modified from b62 to b36. * org-id.el (org-id-reverse-string): New function. (org-id-new): Use `org-id-reverse-string' to make sure the beginning chars of the ID are mutating fast. This allows to use a directory structure to spread things better. (org-id-prefix): Changed default to nil. * org-list.el (org-move-item-down, org-move-item-up): Remember and restore the column of the cursor position. * org-remember.el (org-remember-apply-template): Remove properties from `initial'. * org-wl.el (org-wl-open): Remove useless call to `wl-thread-open-all'. * org-remember.el (org-remember-handler): Fix bug with `bottom' location. * org-bbdb.el (org-bbdb-anniversaries): Require bbdb in `org-bbdb-anniversaries'. * org.el (org-get-next-sibling, org-forward-same-level): New functions, similar to the outline versions, but invisible headings are OK. 2008-10-12 Bastien Guerry <bzg@altern.org> * org.el (org-auto-repeat-maybe): Insert a space between the timestamp's type and the timestamp itself. 2008-10-12 Carsten Dominik <dominik@science.uva.nl> * org-table.el (org-table-sum): Do not format the result with %g, it does rounding when there are too many digits. * org.el (org-map-entries): Protect the keyword-selecting variables. 2008-10-12 Bastien Guerry <bzg@altern.org> * org-agenda.el (org-agenda-to-appt): Make sure the function check against all agenda files. 2008-10-12 Carsten Dominik <dominik@science.uva.nl> * org-list.el: New file, aggregating list functions from org.el and org-export-latex.el. * org.el (org-edit-src-region-extra): New option. * org-agenda.el (org-agenda-to-appt): Fix bug with appointment time before 1am. 2008-10-12 Bastien Guerry <bzg@altern.org> * org-export-latex.el (org-export-latex-keywords-maybe): Bug fix. 2008-10-12 James TA Smith <ahktenzero@mohorovi.cc> * org-plot.el (org-plot/gnuplot): Make tables starting with a hline work correctly. (org-plot/gnuplot-script): Put commas at the end of each script line. * org.el (org-get-refile-targets): Replace links with their descriptions (org-imenu-get-tree): Replace links with their descriptions. * org-remember.el (org-remember-apply-template): Add a new expansion for adding properties to remember items. * org.el (org-add-log-setup): Skip over drawers (properties, clocks etc) when adding notes. * org-agenda.el (org-agenda-get-closed): show durations of clocked items as well as the start and end times. * org-compat.el (org-get-x-clipboard-compat): Add a compat function for fetching the X clipboard on XEmacs and GNU Emacs 21. * org-remember.el (org-get-x-clipboard): Use the compat function to get clipboard values when x-selection-value is unavailable. Use substring-no-properties instead of set-text-properties to remove text properties from the clipboard value. * lisp/org-clock.el (org-update-mode-line): Support limiting the modeline clock string, and display the full todo value in the tooltip. Set a local keymap so mouse-3 on the clock string goes to the currently clocked task. (org-clock-string-limit): Add a custom value for the maximum length of the clock string in the modeline. (org-clock-mode-map): Add a keymap for the modeline string 2008-10-12 Carsten Dominik <dominik@science.uva.nl> * org-compat.el (org-propertize): New function. 2008-10-12 Bastien Guerry <bzg@altern.org> * org-export-latex.el (org-export-latex-tables): protect exported tables from further special chars conversion. (org-export-latex-preprocess): Preserve LaTeX environments. (org-list-parse-list): Parse descriptive lists. (org-list-to-generic, org-list-to-latex, org-list-to-html) (org-list-to-texinfo): Export descriptive lists. (org-quote-chars): Remove. (org-export-latex-keywords-maybe): Use `replace-regexp-in-string'. (org-export-latex-list-beginning-re): Rename to `org-list-beginning-re' (org-list-item-begin): Rename to `org-list-item-beginning' 2008-10-12 Carsten Dominik <dominik@science.uva.nl> * org.el (org-refile): Allow refiling to the last entry in the buffer. (org-get-tags-at): Fix bug when inheritance is turned off. * org.el (org-indent-line-function): No longer check for src regions, this is too much overhead. * org-agenda.el (org-agenda-highlight-todo): Fix bugs with keyword matching. * org.el (org-scan-tags): Make sure that tags matching is not case sensitive. TODO keyword matching is case sensitive, however, to avoid confusion with similar words that are not meant to be keywords. * org.el (org-get-local-tags-at): New function. (org-get-local-tags): New function. * org-exp.el (org-export-get-categories): New function. * org-agenda.el (org-sorting-choice) (org-agenda-sorting-strategy, org-agenda-get-todos) (org-agenda-get-timestamps, org-agenda-get-deadlines) (org-agenda-get-scheduled, org-agenda-get-blocks) (org-entries-lessp): Implement sorting by TODO state. (org-cmp-todo-state): New defsubst. * org-colview.el (org-colview-construct-allowed-dates): New function. (org-columns-next-allowed-value): Use `org-colview-construct-allowed-dates'. * org-colview-xemacs.el (org-colview-construct-allowed-dates): New function. (org-columns-next-allowed-value): Use `org-colview-construct-allowed-dates'. * org.el (org-protect-slash): New function. (org-get-refile-targets): Use `org-protect-slash'. * org-agenda.el (org-global-tags-completion-table): New variable. * org-exp.el (org-export-handle-export-tags): New function. (org-export-preprocess-string): Call `org-export-handle-export-tags'. * org-plot.el: New file. * org-publish.el (org-publish-expand-components): Function removed. (org-publish-expand-projects): Allow components to have components. * org.el (org-indent-line-function): Do not indent in regions that are external source code. (org-yank-and-fold-if-subtree): New function. * org-agenda.el (org-agenda-todayp): New function. (org-agenda-get-deadlines, org-agenda-get-scheduled): Use `org-agenda-todayp'. * org.el (org-insert-heading-respect-content) (org-insert-todo-heading-respect-content): New commands. (org-insert-heading-respect-content): New option. (org-insert-heading): Respect `org-insert-heading-respect-content'. * org-clock.el (org-clock-find-position): Make sure the note after the clock line gets moved into the new clock drawer. * org-id.el (org-id-new): New option. * org-table.el (org-table-copy-down): Avoid overflow during increment. Use prefix argument 0 to temporarily disable the increment. * org-exp.el (org-export-as-html): Do not turn on the major mode if the buffer will be killed anyway. (org-get-current-options): Exclude the #+TEXT field. (org-export-as-html): Make sure text before the first headline is a paragraph. * org-publish.el (org-publish-org-to): Tell the exporter that this buffer will be killed, so it is not necessary to do major mode initialization. * org-archive.el (org-archive-to-archive-sibling): Show empty lines after folding the archive sibling. * org.el (org-log-note-extra): New variable. 2008-10-12 Bastien Guerry <bzg@altern.org> * org.el (org-additional-option-like-keywords): Added keywords for the _QUOTE, _VERSE and _SRC environments. * org-export-latex.el (org-export-latex-preprocess): Fix bug when exporting _QUOTE and _VERSE environments. 2008-10-12 Carsten Dominik <dominik@science.uva.nl> * org-agenda.el (org-agenda-filter-by-tag): New command. * org-exp.el (org-get-current-options): Remove angular brackets from the date entry. * org.el (org-edit-fixed-width-region): New function. (org-edit-fixed-width-region): Also try `org-edit-fixed-width-region'. (org-edit-fixed-width-region-mode): New option. (org-activate-code): Only interprete lines starting with colon plus a space as example lines. * org-remember.el (org-remember-templates): Add nil instead of empty strings to fix the length of remember templates. * org-table.el (org-calc-default-modes): Fix the time format for calc, from 12 hour to 24 hour clock. * org-agenda.el (org-agenda-get-deadlines) (org-agenda-get-scheduled): Avoid `time-of-day' extraction for entries that are pre-warnings of deadlines or reminders. * org.el (org-sort-entries-or-items): Make numeric and alpha comparisons ignore any TODO keyword and priority cookie. * org-remember.el (org-remember-handler): Reinterpretation of the prefix argument. * org-agenda.el (org-agenda-get-scheduled): Use new `org-scheduled' face. * org-faces.el (org-scheduled): New face. * org-wl.el (org-wl-open): Remove incorrect declaration. * org-gnus.el (org-gnus-store-link): Support for :to information in gnus links. * org-exp.el (org-export-as-html): Fixed typo in creator information. (org-export-protect-examples): New parameter indent. Insert extra spaces only when this parameter is specified. (org-export-preprocess-string): Call `org-export-protect-examples' with an indentation parameter when exporting to ASCII. * org-remember.el (org-remember-templates) (org-remember-apply-template): Allow the file component to be a function. * org.el (org-goto-local-search-headings): Renamed from `org-goto-local-search-forward-headings'. Added the possibility to search backwards. * org-export-latex.el (org-export-latex): New customization group. * org-agenda.el (org-write-agenda): Erase buffer for txt export. * org-exp.el (org-html-do-expand): Allow {} to terminate tex macro * org.el (org-buffer-list): Select buffers based on major mode, not on file name. * org-agenda.el (org-agenda-align-tags): Fix bug with malformed face property. * org-colview.el (org-columns-display-here): Use `org-columns-modify-value-for-display-function'. * org-colview-xemacs.el (org-columns-display-here): Use `org-columns-modify-value-for-display-function'. * org.el (org-columns-modify-value-for-display-function): New option. * org-publish.el (org-publish-file): Make sure the directory match for the publishing directory works correctly. * org-agenda.el (org-agenda-execute-calendar-command) (org-agenda-diary-entry): Additional optional argument.
author Carsten Dominik <dominik@science.uva.nl>
date Sun, 12 Oct 2008 06:12:44 +0000
parents 9da424c0c9c9
children 8fa7ef477c04
line wrap: on
line diff
--- a/lisp/org/org-exp.el	Sun Oct 12 04:47:51 2008 +0000
+++ b/lisp/org/org-exp.el	Sun Oct 12 06:12:44 2008 +0000
@@ -5,7 +5,7 @@
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 6.06b
+;; Version: 6.09a
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -64,6 +64,24 @@
   :group 'org-export-general
   :type 'boolean)
 
+
+(defcustom org-export-select-tags '("export")
+  "Tags that select a tree for export.
+If any such tag is found in a buffer, all trees that do not carry one
+of these tags will be deleted before export.
+Inside trees that are selected like this, you can still deselect a
+subtree by tagging it with one of the `org-export-excude-tags'."
+  :group 'org-export-general
+  :type '(repeat (string :tag "Tag")))
+
+(defcustom org-export-exclude-tags '("noexport")
+  "Tags that exclude a tree from export.
+All trees carrying any of these tags will be excluded from export.
+This is without contition, so even subtrees inside that carry one of the
+`org-export-select-tags' will be removed."
+  :group 'org-export-general
+  :type '(repeat (string :tag "Tag")))
+
 (defcustom org-export-with-special-strings t
   "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
 When this option is turned on, these strings will be exported as:
@@ -494,6 +512,13 @@
   table { border-collapse: collapse; }
   td, th { vertical-align: top; }
   dt { font-weight: bold; }
+
+  .org-info-js_info-navigation { border-style:none; }
+  #org-info-js_console-label { font-size:10px; font-weight:bold;
+                               white-space:nowrap; }
+  .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
+                                 font-weight:bold; }
+
 </style>"
   "The default style specification for exported HTML files.
 Please use the variables `org-export-html-style' and
@@ -540,6 +565,7 @@
 ;;;###autoload
 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
 
+
 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
   "Format for typesetting the document title in HTML export."
   :group 'org-export-html
@@ -687,6 +713,22 @@
 	      (const :tag "SCHEDULED in TODO entries become start date"
 		     todo-start)))
 
+(defcustom org-icalendar-categories '(local-tags category)
+  "Items that should be entered into the categories field.
+This is a list of symbols, the following are valid:
+
+category    The Org-mode category of the current file or tree
+todo-state  The todo state, if any
+local-tags  The tags, defined in the current line
+all-tags    All tags, including inherited ones."
+  :group 'org-export-icalendar
+  :type '(repeat
+	  (choice
+	   (const :tag "The file or tree category" category)
+	   (const :tag "The TODO state" todo-state)
+	   (const :tag "Tags defined in current line" local-tags)
+	   (const :tag "All tags, including inherited ones" all-tags))))
+
 (defcustom org-icalendar-include-todo nil
   "Non-nil means, export to iCalendar files should also cover TODO items."
   :group 'org-export-icalendar
@@ -733,9 +775,9 @@
 (defconst org-level-max 20)
 
 (defvar org-export-html-preamble nil
-  "Preamble, to be inserted just after <body>.  Set by publishing functions.")
+  "Preamble, to be inserted just before <body>.  Set by publishing functions.")
 (defvar org-export-html-postamble nil
-  "Preamble, to be inserted just before </body>.  Set by publishing functions.")
+  "Preamble, to be inserted just after </body>.  Set by publishing functions.")
 (defvar org-export-html-auto-preamble t
   "Should default preamble be inserted?  Set by publishing functions.")
 (defvar org-export-html-auto-postamble t
@@ -785,7 +827,9 @@
     (:auto-preamble        . org-export-html-auto-preamble)
     (:auto-postamble       . org-export-html-auto-postamble)
     (:author               . user-full-name)
-    (:email                . user-mail-address)))
+    (:email                . user-mail-address)
+    (:select-tags          . org-export-select-tags)
+    (:exclude-tags         . org-export-exclude-tags)))
 
 (defun org-default-export-plist ()
   "Return the property list with default settings for the export variables."
@@ -821,9 +865,11 @@
       (let ((re (org-make-options-regexp
 		 (append
 		  '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
-		    "LINK_UP" "LINK_HOME" "SETUPFILE")
+		    "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
+		    "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
 		  (mapcar 'car org-export-inbuffer-options-extra))))
-	    p key val text options js-up js-main js-css js-opt a pr
+	    p key val text options js-up js-main js-css js-opt a pr style
+	    latex-header
 	    ext-setup-or-nil setup-contents (start 0))
 	(while (or (and ext-setup-or-nil
 			(string-match re ext-setup-or-nil start)
@@ -841,6 +887,10 @@
 	   ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
 	   ((string-equal key "DATE") (setq p (plist-put p :date val)))
 	   ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
+	   ((string-equal key "STYLE")
+	    (setq style (concat style "\n" val)))
+	   ((string-equal key "LATEX_HEADER")
+	    (setq latex-header (concat latex-header "\n" val)))
 	   ((string-equal key "TEXT")
 	    (setq text (if text (concat text "\n" val) val)))
 	   ((string-equal key "OPTIONS")
@@ -849,6 +899,10 @@
 	    (setq p (plist-put p :link-up val)))
 	   ((string-equal key "LINK_HOME")
 	    (setq p (plist-put p :link-home val)))
+	   ((string-equal key "EXPORT_SELECT_TAGS")
+	    (setq p (plist-put p :select-tags (org-split-string val))))
+	   ((string-equal key "EXPORT_EXCLUDE_TAGS")
+	    (setq p (plist-put p :exclude-tags (org-split-string val))))
 	   ((equal key "SETUPFILE")
 	    (setq setup-contents (org-file-contents
 				  (expand-file-name
@@ -862,6 +916,9 @@
 			    "\n" setup-contents "\n"
 			    (substring ext-setup-or-nil start)))))))
 	(setq p (plist-put p :text text))
+	(when style (setq p (plist-put p :style-extra style)))
+	(when latex-header
+	  (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
 	(when options
 	  (setq p (org-export-add-options-to-plist p options)))
 	p))))
@@ -1345,9 +1402,13 @@
       (setq case-fold-search t)
       (untabify (point-min) (point-max))
       
-      ;; Handle incude files
+      ;; Handle include files
       (org-export-handle-include-files)
       
+      ;; Get rid of excluded trees
+      (org-export-handle-export-tags (plist-get parameters :select-tags)
+				     (plist-get parameters :exclude-tags))
+
       ;; Handle source code snippets
       (org-export-replace-src-segments)
       
@@ -1377,7 +1438,7 @@
       (setq target-alist (org-export-handle-invisible-targets target-alist))
 
       ;; Protect examples
-      (org-export-protect-examples)
+      (org-export-protect-examples (if asciip 'indent nil))
 
       ;; Protect backend specific stuff, throw away the others.
       (org-export-select-backend-specific-text
@@ -1395,6 +1456,26 @@
       ;; Remove comment environment and comment subtrees
       (org-export-remove-comment-blocks-and-subtrees)
 
+
+      ;; Find matches for radio targets and turn them into internal links
+      (org-export-mark-radio-links)
+
+      ;; Find all links that contain a newline and put them into a single line
+      (org-export-concatenate-multiline-links)
+
+      ;; Normalize links: Convert angle and plain links into bracket links
+      ;; and expand link abbreviations
+      (org-export-normalize-links)
+
+      ;; Find all internal links.  If they have a fuzzy match (i.e. not
+      ;; a *dedicated* target match, let the link  point to the
+      ;; corresponding section.
+      (org-export-target-internal-links target-alist)
+
+      ;; Find multiline emphasis and put them into single line
+      (when (plist-get parameters :emph-multiline)
+	(org-export-concatenate-multiline-emphasis))
+
       ;; Remove special table lines
       (when org-export-table-remove-special-lines
 	(org-export-remove-special-table-lines))
@@ -1415,24 +1496,6 @@
       ;; Remove or replace comments
       (org-export-handle-comments (plist-get parameters :comments))
 
-      ;; Find matches for radio targets and turn them into internal links
-      (org-export-mark-radio-links)
-
-      ;; Find all links that contain a newline and put them into a single line
-      (org-export-concatenate-multiline-links)
-
-      ;; Normalize links: Convert angle and plain links into bracket links
-      ;; and expand link abbreviations
-      (org-export-normalize-links)
-
-      ;; Find all internal links.  If they have a fuzzy match (i.e. not
-      ;; a *dedicated* target match, let the link  point to the
-      ;; corresponding section.
-      (org-export-target-internal-links target-alist)
-
-      ;; Find multiline emphasis and put them into single line
-      (when (plist-get parameters :emph-multiline)
-	(org-export-concatenate-multiline-emphasis))
 
       (setq rtn (buffer-string)))
     (kill-buffer " org-mode-tmp")
@@ -1545,6 +1608,60 @@
       (while (re-search-forward re nil t)
 	(replace-match "")))))
 
+(defun org-export-handle-export-tags (select-tags exclude-tags)
+  "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
+Both arguments are lists of tags.
+If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
+will be removed.
+After that, all subtrees that are marked by EXCLUDE-TAGS will be
+removed as well."
+  (remove-text-properties (point-min) (point-max) '(:org-delete t))
+  (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
+					   select-tags "\\|")
+			 "\\):"))
+	 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
+					   exclude-tags "\\|")
+			"\\):"))
+	 beg end cont)
+    (goto-char (point-min))
+    (when (and select-tags
+	       (re-search-forward
+		(concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
+      ;; At least one tree is marked for export, this means
+      ;; all the unmarked stuff needs to go.
+      ;; Dig out the trees that should be exported
+      (goto-char (point-min))
+      (outline-next-heading)
+      (setq beg (point))
+      (put-text-property beg (point-max) :org-delete t)
+      (while (re-search-forward re-sel nil t)
+	(when (org-on-heading-p)
+	  (org-back-to-heading)
+	  (remove-text-properties
+	   (max (1- (point)) (point-min))
+	   (setq cont (save-excursion (org-end-of-subtree t t)))
+	   '(:org-delete t))
+	  (while (and (org-up-heading-safe)
+		      (get-text-property (point) :org-delete))
+	    (remove-text-properties (max (1- (point)) (point-min))
+				    (point-at-eol) '(:org-delete t)))
+	  (goto-char cont))))
+    ;; Remove the trees explicitly marked for noexport
+    (when exclude-tags
+      (goto-char (point-min))
+      (while (re-search-forward re-excl nil t)
+	(when (org-at-heading-p)
+	  (org-back-to-heading t)
+	  (setq beg (point))
+	  (org-end-of-subtree t)
+	  (delete-region beg (point)))))
+    ;; Remove everything that is now still marked for deletion
+    (goto-char (point-min))
+    (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
+      (setq end (or (next-single-property-change beg :org-delete)
+		    (point-max)))
+      (delete-region beg end))))
+
 (defun org-export-remove-archived-trees (export-archived-trees)
   "Remove archived trees.
 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
@@ -1582,13 +1699,13 @@
 			 '(org-protected t))
     (goto-char (1+ (match-end 4)))))
 
-(defun org-export-protect-examples ()
+(defun org-export-protect-examples (&optional indent)
   "Protect code that should be exported as monospaced examples."
   (goto-char (point-min))
   (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t)
     (goto-char (match-end 0))
     (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
-      (insert ":  ")
+      (insert (if indent ":  " ":"))
       (beginning-of-line 2)))
   (goto-char (point-min))
   (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
@@ -1763,7 +1880,9 @@
   (let ((inhibit-read-only t))
     (save-excursion
       (goto-char (point-min))
-      (let ((end (save-excursion (outline-next-heading) (point))))
+      (let ((end (if (looking-at org-outline-regexp)
+		     (point)
+		   (save-excursion (outline-next-heading) (point)))))
 	(when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
 	  ;; Mark the line so that it will not be exported as normal text.
 	  (org-unmodified
@@ -2104,6 +2223,8 @@
 		  (plist-get opt-plist :skip-before-1st-heading)
 		  :drawers (plist-get opt-plist :drawers)
 		  :verbatim-multiline t
+		  :select-tags (plist-get opt-plist :select-tags)
+		  :exclude-tags (plist-get opt-plist :exclude-tags)
 		  :archived-trees
 		  (plist-get opt-plist :archived-trees)
 		  :add-text (plist-get opt-plist :text))
@@ -2463,9 +2584,10 @@
 #+EMAIL:     %s
 #+DATE:      %s
 #+LANGUAGE:  %s
-#+TEXT:      Some descriptive text to be emitted.  Several lines OK.
 #+OPTIONS:   H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s tags:%s
 %s
+#+EXPORT_SELECT_TAGS: %s
+#+EXPORT_EXCUDE_TAGS: %s
 #+LINK_UP:   %s
 #+LINK_HOME: %s
 #+CATEGORY:  %s
@@ -2480,7 +2602,7 @@
 #+LINK:      %s
 "
    (buffer-name) (user-full-name) user-mail-address
-   (format-time-string (car org-time-stamp-formats))
+   (format-time-string (substring (car org-time-stamp-formats) 1 -1))
    org-export-default-language
    org-export-headline-levels
    org-export-with-section-numbers
@@ -2499,6 +2621,8 @@
    org-export-with-drawers
    org-export-with-tags
    (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
+   (mapconcat 'identity org-export-select-tags " ")
+   (mapconcat 'identity org-export-exclude-tags " ")
    org-export-html-link-up
    org-export-html-link-home
    (file-name-nondirectory buffer-file-name)
@@ -2769,6 +2893,8 @@
 	    :drawers (plist-get opt-plist :drawers)
 	    :archived-trees
 	    (plist-get opt-plist :archived-trees)
+	    :select-tags (plist-get opt-plist :select-tags)
+	    :exclude-tags (plist-get opt-plist :exclude-tags)
 	    :add-text
 	    (plist-get opt-plist :text)
 	    :LaTeX-fragments
@@ -2930,6 +3056,8 @@
       (setq head-count 0)
       (org-init-section-numbers)
 
+      (org-open-par)
+
       (while (setq line (pop lines) origline line)
 	(catch 'nextline
 
@@ -2994,11 +3122,11 @@
 	    (throw 'nextline nil))
 	  (when inverse
 	    (let ((i (org-get-string-indentation line)))
-              (if (> i 0)
-                  (setq line (concat (mapconcat 'identity
-                                                (make-list (* 2 i) "\\nbsp") "")
-                                     " " (org-trim line))))
-              (setq line (concat line " \\\\"))))
+	      (if (> i 0)
+		  (setq line (concat (mapconcat 'identity
+						(make-list (* 2 i) "\\nbsp") "")
+				     " " (org-trim line))))
+	      (setq line (concat line " \\\\"))))
 
 	  ;; make targets to anchors
 	  (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
@@ -3306,7 +3434,7 @@
       (org-html-level-start 1 nil umax
 			    (and org-export-with-toc (<= level umax))
 			    head-count)
-      ;; the </div> to lose the last text-... div.
+      ;; the </div> to close the last text-... div.
       (insert "</div>\n")
 
       (unless body-only
@@ -3329,7 +3457,7 @@
 		    (nth 2 lang-words) ": "
 		    date "</p>\n"))
 	  (when org-export-creator-info
-	    (insert (format "<p>HTML generated by org-mode %s in emacs %s<\p>\n"
+	    (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
 			    org-version emacs-major-version)))
 	  (insert "</div>"))
 
@@ -3338,8 +3466,9 @@
 	(insert (or (plist-get opt-plist :postamble) ""))
 	(insert "</body>\n</html>\n"))
 
-      (normal-mode)
-      (if (eq major-mode default-major-mode) (html-mode))
+      (unless (plist-get opt-plist :buffer-will-be-killed)
+	(normal-mode)
+	(if (eq major-mode default-major-mode) (html-mode)))
 
       ;; insert the table of contents
       (goto-char (point-min))
@@ -3789,7 +3918,8 @@
       (setq s (org-export-html-convert-sub-super s)))
   (if org-export-with-TeX-macros
       (let ((start 0) wd ass)
-	(while (setq start (string-match "\\\\\\([a-zA-Z]+\\)" s start))
+	(while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
+					 s start))
 	  (if (get-text-property (match-beginning 0) 'org-protected s)
 	      (setq start (match-end 0))
 	    (setq wd (match-string 1 s))
@@ -4074,7 +4204,7 @@
 	      "DTSTART"))
 	hd ts ts2 state status (inc t) pos b sexp rrule
 	scheduledp deadlinep todo prefix due start
-	tmp pri category entry location summary desc uid
+	tmp pri categories entry location summary desc uid
 	(sexp-buffer (get-buffer-create "*ical-tmp*")))
     (org-refresh-category-properties)
     (save-excursion
@@ -4105,7 +4235,7 @@
 		uid (if org-icalendar-store-UID
 			(org-id-get-create)
 		      (or (org-id-get) (org-id-new)))
-		category (org-get-category)
+		categories (org-export-get-categories)
 		deadlinep nil scheduledp nil)
 	  (if (looking-at re2)
 	      (progn
@@ -4177,7 +4307,7 @@
 			       (concat "\nDESCRIPTION: " desc) "")
 			   (if (and location (string-match "\\S-" location))
 			       (concat "\nLOCATION: " location) "")
-			   category)))))
+			   categories)))))
       (when (and org-icalendar-include-sexps
 		 (condition-case nil (require 'icalendar) (error nil))
 		 (fboundp 'icalendar-export-region))
@@ -4228,6 +4358,7 @@
 			     (org-entry-get nil "DEADLINE"))
 		    start (and (member 'todo-start org-icalendar-use-scheduled)
 			     (org-entry-get nil "SCHEDULED"))
+		    categories (org-export-get-categories)
 		    uid (if org-icalendar-store-UID
 			    (org-id-get-create)
 			  (or (org-id-get) (org-id-new))))
@@ -4263,9 +4394,24 @@
 			     (if (and desc (string-match "\\S-" desc))
 				 (concat "\nDESCRIPTION: " desc) "")
 			     (if due (concat "\n" due) "")
-			     category
+			     categories
 			     pri status)))))))))
 
+(defun org-export-get-categories ()
+  "Get categories according to `org-icalendar-categories'."
+  (let ((cs org-icalendar-categories) c rtn tmp)
+    (while (setq c (pop cs))
+      (cond
+       ((eq c 'category) (push (org-get-category) rtn))
+       ((eq c 'todo-state)
+	(setq tmp (org-get-todo-state))
+	(and tmp (push tmp rtn)))
+       ((eq c 'local-tags)
+	(setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
+       ((eq c 'all-tags)
+	(setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
+    (mapconcat 'identity (nreverse rtn) ",")))
+
 (defun org-icalendar-cleanup-string (s &optional is-body maxlength)
   "Take out stuff and quote what needs to be quoted.
 When IS-BODY is non-nil, assume that this is the body of an item, clean up