changeset 69454:d60237bf3ccc

(org-link-search): Avoid self-matching of links, allow target text to be distributed over several lines. (org-search-not-link): New function. (org-set-regexps-and-options, org-get-current-options): New startup options. (org-export-as-html): Take odd-level setting from local variable. (org-fontify-emphasized-text): New option. (org-set-font-lock-defaults): Include emphasized text. (org-follow-mhe-link): Allow folder-only links, fix folder name. (org-font-lock): Customize group renamed from `org-faces'.
author Carsten Dominik <dominik@science.uva.nl>
date Mon, 13 Mar 2006 07:08:15 +0000
parents 91b04387dd58
children 1ad059d669d5
files lisp/textmodes/org.el
diffstat 1 files changed, 193 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/org.el	Mon Mar 13 01:45:16 2006 +0000
+++ b/lisp/textmodes/org.el	Mon Mar 13 07:08:15 2006 +0000
@@ -5,7 +5,7 @@
 ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
-;; Version: 4.08
+;; Version: 4.09
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -81,8 +81,14 @@
 ;;
 ;; Changes since version 4.00:
 ;; ---------------------------
+;; Version 4.09
+;;    - Bug fixes.
+;;    - Small improvements to font-lock support.
+;;    - MHE support finalized.
+;;
 ;; Version 4.08
-;;
+;;    - Bug fixes.
+;;    - Improved MHE support
 ;;
 ;; Version 4.07
 ;;    - Bug fixes.
@@ -139,7 +145,7 @@
 
 ;;; Customization variables
 
-(defvar org-version "4.08"
+(defvar org-version "4.09"
   "The version number of the file org.el.")
 (defun org-version ()
   (interactive)
@@ -796,31 +802,15 @@
   :group 'org-structure
   :type 'hook)
 
-(defcustom org-level-color-stars-only nil
-  "Non-nil means fontify only the stars in each headline.
-When nil, the entire headline is fontified.
-Changing it requires restart of `font-lock-mode' to become effective."
-  :group 'org-structure
-  :type 'boolean)
-
-(defcustom org-hide-leading-stars nil
-  "Non-nil means, hide the first N-1 stars in a headline.
-This works by using the face `org-hide' for these stars.  This
-face is white for a light background, and black for a dark
-background.  You may have to customize the face `org-hide' to
-make this work.
-Changing it requires restart of `font-lock-mode' to become effective."
-  :group 'org-structure
-  :type 'boolean)
-
 (defcustom org-odd-levels-only nil
   "Non-nil means, skip even levels and only use odd levels for the outline.
 This has the effect that two stars are being added/taken away in
 promotion/demotion commands.  It also influences how levels are
 handled by the exporters.
 Changing it requires restart of `font-lock-mode' to become effective
-for fontification." 
+for fontification also in regions already fontified." 
   :group 'org-structure
+  :group 'org-font-lock
   :type 'boolean)
 
 (defcustom org-adapt-indentation t
@@ -1710,11 +1700,44 @@
   :group 'org-export
   :type 'string)
 
-(defgroup org-faces nil
-  "Faces for highlighting in Org-mode."
-  :tag "Org Faces"
+(defgroup org-font-lock nil
+  "Faces and settings for highlighting in Org-mode."
+  :tag "Org Font Lock"
   :group 'org)
 
+(defcustom org-level-color-stars-only nil
+  "Non-nil means fontify only the stars in each headline.
+When nil, the entire headline is fontified.
+Changing it requires restart of `font-lock-mode' to become effective
+also in regions already fontified."
+  :group 'org-font-lock
+  :type 'boolean)
+
+(defcustom org-hide-leading-stars nil
+  "Non-nil means, hide the first N-1 stars in a headline.
+This works by using the face `org-hide' for these stars.  This
+face is white for a light background, and black for a dark
+background.  You may have to customize the face `org-hide' to
+make this work.
+Changing it requires restart of `font-lock-mode' to become effective
+also in regions already fontified."
+  :group 'org-font-lock
+  :type 'boolean)
+
+(defcustom org-fontify-done-headline nil
+  "Non-nil means, change the face of a headline if it is marked DONE.
+Normally, only the TODO/DONE keyword indicates the state of a headline.
+When this is non-nil, the headline after the keyword is set to the
+`org-headline-done' as an additional indication."
+  :group 'org-font-lock
+  :type 'boolean)
+
+(defcustom org-fontify-emphasized-text t
+  "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
+Changing this variable requires a restart of Emacs to take effect."
+  :group 'org-font-lock
+  :type 'boolean)
+
 (defface org-hide
   '((((type tty) (class color)) (:foreground "blue" :weight bold))
     (((class color) (background light)) (:foreground "white"))
@@ -1723,7 +1746,7 @@
 ;    (((class color) (background dark)) (:foreground "grey10"))
     (t (:inverse-video nil)))
   "Face used for level 1 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-1 ;; font-lock-function-name-face
   '((((type tty) (class color)) (:foreground "blue" :weight bold))
@@ -1731,7 +1754,7 @@
     (((class color) (background dark)) (:foreground "LightSkyBlue"))
     (t (:inverse-video t :bold t)))
   "Face used for level 1 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-2 ;; font-lock-variable-name-face
   '((((type tty) (class color)) (:foreground "yellow" :weight light))
@@ -1739,7 +1762,7 @@
     (((class color) (background dark)) (:foreground "LightGoldenrod"))
     (t (:bold t :italic t)))
   "Face used for level 2 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-3 ;; font-lock-keyword-face
   '((((type tty) (class color)) (:foreground "cyan" :weight bold))
@@ -1747,7 +1770,7 @@
     (((class color) (background dark)) (:foreground "Cyan"))
     (t (:bold t)))
   "Face used for level 3 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-4   ;; font-lock-comment-face
   '((((type tty pc) (class color) (background light)) (:foreground "red"))
@@ -1756,7 +1779,7 @@
     (((class color) (background dark)) (:foreground "chocolate1"))
     (t (:bold t :italic t)))
   "Face used for level 4 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-5 ;; font-lock-type-face
   '((((type tty) (class color)) (:foreground "green"))
@@ -1764,7 +1787,7 @@
     (((class color) (background dark)) (:foreground "PaleGreen"))
     (t (:bold t :underline t)))
   "Face used for level 5 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-6 ;; font-lock-constant-face
   '((((type tty) (class color)) (:foreground "magenta"))
@@ -1772,7 +1795,7 @@
     (((class color) (background dark)) (:foreground "Aquamarine"))
     (t (:bold t :underline t)))
   "Face used for level 6 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-7 ;; font-lock-builtin-face
   '((((type tty) (class color)) (:foreground "blue" :weight light))
@@ -1780,7 +1803,7 @@
     (((class color) (background dark)) (:foreground "LightSteelBlue"))
     (t (:bold t)))
   "Face used for level 7 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-level-8 ;; font-lock-string-face
   '((((type tty) (class color)) (:foreground "green"))
@@ -1788,7 +1811,7 @@
     (((class color) (background dark)) (:foreground "LightSalmon"))
     (t (:italic t)))
   "Face used for level 8 headlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-special-keyword ;; font-lock-string-face
   '((((type tty) (class color)) (:foreground "green"))
@@ -1796,7 +1819,7 @@
     (((class color) (background dark)) (:foreground "LightSalmon"))
     (t (:italic t)))
   "Face used for special keywords."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-warning ;; font-lock-warning-face
   '((((type tty) (class color)) (:foreground "red"))
@@ -1805,15 +1828,7 @@
 ;    (((class color) (background dark)) (:foreground "Pink" :bold t))
     (t (:inverse-video t :bold t)))
   "Face for deadlines and TODO keywords."
-  :group 'org-faces)
-
-(defcustom org-fontify-done-headline nil
-  "Non-nil means, change the face of a headline if it is marked DONE.
-Normally, only the TODO/DONE keyword indicates the state of a headline.
-When this is non-nil, the headline after the keyword is set to the
-`org-headline-done' as an additional indication."
-  :group 'org-faces
-  :type 'boolean)
+  :group 'org-font-lock)
 
 (defface org-headline-done ;; font-lock-string-face
   '((((type tty) (class color)) (:foreground "green"))
@@ -1822,7 +1837,7 @@
     (t (:italic t)))
   "Face used to indicate that a headline is DONE.  See also the variable
 `org-fontify-done-headline'."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 ;; Inheritance does not yet work for xemacs. So we just copy...
 
@@ -1832,7 +1847,7 @@
     (((class color) (background dark)) (:foreground "LightSkyBlue"))
     (t (:inverse-video t :bold t)))
   "Face for upcoming deadlines."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-scheduled-today
   '((((type tty) (class color)) (:foreground "green"))
@@ -1840,7 +1855,7 @@
     (((class color) (background dark)) (:foreground "PaleGreen"))
     (t (:bold t :underline t)))
   "Face for items scheduled for a certain day."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-scheduled-previously
   '((((type tty pc) (class color) (background light)) (:foreground "red"))
@@ -1849,7 +1864,7 @@
     (((class color) (background dark)) (:foreground "chocolate1"))
     (t (:bold t :italic t)))
   "Face for items scheduled previously, and not yet done."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-formula
   '((((type tty pc) (class color) (background light)) (:foreground "red"))
@@ -1858,7 +1873,7 @@
     (((class color) (background dark)) (:foreground "chocolate1"))
     (t (:bold t :italic t)))
   "Face for formulas."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-link
   '((((type tty) (class color)) (:foreground "cyan" :weight bold))
@@ -1866,15 +1881,15 @@
     (((class color) (background dark)) (:foreground "Cyan"))
     (t (:bold t)))
   "Face for links."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-tag
   '((((type tty) (class color)) (:foreground "cyan" :weight bold))
     (((class color) (background light)) (:foreground "Purple" :weight bold))
     (((class color) (background dark)) (:foreground "Cyan" :weight bold))
     (t (:bold t)))
-  "Face for links."
-  :group 'org-faces)
+  "Face for tags."
+  :group 'org-font-lock)
 
 (defface org-done ;; font-lock-type-face
   '((((type tty) (class color)) (:foreground "green"))
@@ -1882,7 +1897,7 @@
     (((class color) (background dark)) (:foreground "PaleGreen" :bold t))
     (t (:bold t :underline t)))
   "Face used for DONE."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-table ;; font-lock-function-name-face
   '((((type tty) (class color)) (:foreground "blue" :weight bold))
@@ -1890,7 +1905,7 @@
     (((class color) (background dark)) (:foreground "LightSkyBlue"))
     (t (:inverse-video t :bold t)))
   "Face used for tables."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defface org-time-grid ;; font-lock-variable-name-face
   '((((type tty) (class color)) (:foreground "yellow" :weight light))
@@ -1898,7 +1913,7 @@
     (((class color) (background dark)) (:foreground "LightGoldenrod"))
     (t (:bold t :italic t)))
   "Face used for time grids."
-  :group 'org-faces)
+  :group 'org-font-lock)
 
 (defvar org-level-faces
   '(org-level-1 org-level-2 org-level-3 org-level-4
@@ -1939,6 +1954,10 @@
 		    (set '(("fold" org-startup-folded t)
 			   ("nofold" org-startup-folded nil)
 			   ("content" org-startup-folded content)
+			   ("hidestars" org-hide-leading-stars t)
+			   ("showstars" org-hide-leading-stars nil)
+			   ("odd" org-odd-levels-only t)
+			   ("oddeven" org-odd-levels-only nil)
 			   ("dlcheck" org-startup-with-deadline-check t)
 			   ("nodlcheck" org-startup-with-deadline-check nil)))
 		    l var val)
@@ -2307,44 +2326,45 @@
 (defvar org-font-lock-keywords nil)
 
 (defun org-set-font-lock-defaults ()
-  (let ((org-font-lock-extra-keywords
-	 (list
-	  '("^\\(\\**\\)\\(\\*\\)\\(.*\\)" (1 (org-get-level-face 1))
-	    (2 (org-get-level-face 2)) (3 (org-get-level-face 3)))
-	  '(org-activate-links (0 'org-link t))
-	  '(org-activate-links2 (0 'org-link t))
-	  '(org-activate-target-links (0 'org-link t))
-	  '(org-activate-dates (0 'org-link t))
-	  '(org-activate-camels (0 'org-link t))
-	  '(org-activate-tags (1 'org-tag t))
-	  (list (concat "^\\*+[ \t]*" org-not-done-regexp)
-		'(1 'org-warning t))
-	  (list (concat "\\[#[A-Z]\\]") '(0 'org-special-keyword t))
-	  (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
-	  (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
-	  (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
-	  ;; '("\\(\\s-\\|^\\)\\(\\*\\([a-zA-Z]+\\)\\*\\)\\([^a-zA-Z*]\\|$\\)"
-	  ;; (3 'bold))
-	  ;; '("\\(\\s-\\|^\\)\\(/\\([a-zA-Z]+\\)/\\)\\([^a-zA-Z*]\\|$\\)"
-	  ;; (3 'italic))
-	  ;; '("\\(\\s-\\|^\\)\\(_\\([a-zA-Z]+\\)_\\)\\([^a-zA-Z*]\\|$\\)"
-	  ;; (3 'underline))
-	  (list (concat "^\\*+[ \t]*\\<\\(" org-comment-string
-			"\\|" org-quote-string "\\)\\>")
-		'(1 'org-special-keyword t))
-	  '("^#.*" (0 'font-lock-comment-face t))
-	  (if org-fontify-done-headline
-	      (list (concat "^[*]+ +\\<\\(" org-done-string "\\)\\(.*\\)\\>")
-		    '(1 'org-done t) '(2 'org-headline-done t))
-	    (list (concat "^[*]+ +\\<\\(" org-done-string "\\)\\>")
-		  '(1 'org-done t)))
-	  '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
-	    (1 'org-table t))
-	  '("^[ \t]*\\(:.*\\)" (1 'org-table t))
-	  '("| *\\(:?=[^|\n]*\\)" (1 'org-formula t))
-	  '("^[ \t]*| *\\([#!$*_^]\\) *|" (1 'org-formula t))
-	  )))
-
+  (let* ((em org-fontify-emphasized-text)
+	 (org-font-lock-extra-keywords
+	  (list
+	   '("^\\(\\**\\)\\(\\*\\)\\(.*\\)" (1 (org-get-level-face 1))
+	     (2 (org-get-level-face 2)) (3 (org-get-level-face 3)))
+	   '(org-activate-links (0 'org-link t))
+	   '(org-activate-links2 (0 'org-link t))
+	   '(org-activate-target-links (0 'org-link t))
+	   '(org-activate-dates (0 'org-link t))
+	   '(org-activate-camels (0 'org-link t))
+	   '(org-activate-tags (1 'org-tag t))
+	   (list (concat "^\\*+[ \t]*" org-not-done-regexp)
+		 '(1 'org-warning t))
+	   (list (concat "\\[#[A-Z]\\]") '(0 'org-special-keyword t))
+	   (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
+	   (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
+	   (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
+;	   (if em '("\\(\\s-\\|^\\)\\(\\*\\([a-zA-Z]+\\)\\*\\)\\([^a-zA-Z*]\\|$\\)" (3 'bold)))
+;	   (if em '("\\(\\s-\\|^\\)\\(/\\([a-zA-Z]+\\)/\\)\\([^a-zA-Z*]\\|$\\)" (3 'italic)))
+;	   (if em '("\\(\\s-\\|^\\)\\(_\\([a-zA-Z]+\\)_\\)\\([^a-zA-Z*]\\|$\\)" (3 'underline)))
+	   (if em '("\\*[a-zA-Z]+\\*" 0 'bold))
+	   (if em '("/*[a-zA-Z]+/" 0 'italic))
+	   (if em '("_[a-zA-Z]+_" 0 'underline))
+	   (list (concat "^\\*+[ \t]*\\<\\(" org-comment-string
+			 "\\|" org-quote-string "\\)\\>")
+		 '(1 'org-special-keyword t))
+	   '("^#.*" (0 'font-lock-comment-face t))
+	   (if org-fontify-done-headline
+	       (list (concat "^[*]+ +\\<\\(" org-done-string "\\)\\(.*\\)\\>")
+		     '(1 'org-done t) '(2 'org-headline-done t))
+	     (list (concat "^[*]+ +\\<\\(" org-done-string "\\)\\>")
+		   '(1 'org-done t)))
+	   '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
+	     (1 'org-table t))
+	   '("^[ \t]*\\(:.*\\)" (1 'org-table t))
+	   '("| *\\(:?=[^|\n]*\\)" (1 'org-formula t))
+	   '("^[ \t]*| *\\([#!$*_^]\\) *|" (1 'org-formula t))
+	   )))
+    (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
     ;; Now set the full font-lock-keywords
     (set (make-local-variable 'org-font-lock-keywords)
 	 org-font-lock-extra-keywords)
@@ -6960,7 +6980,7 @@
 	(s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
 	(pos (point))
 	(pre "") (post "")
-	words re0 re1 re2 re3 re4 re5 reall camel)
+	words re0 re1 re2 re3 re4 re5 re2a reall camel)
     (cond ((save-excursion
 	     (goto-char (point-min))
 	     (and
@@ -6995,11 +7015,13 @@
 		   (org-split-string s "[ \n\r\t]+"))
 		 re0 (concat "<<" (regexp-quote s0) ">>")
 		 re2 (concat "\\<" (mapconcat 'downcase words "[ \t]+") "\\>")
+		 re2a (concat "\\<" (mapconcat 'downcase words "[ \t\r\n]+") "\\>")
 		 re4 (concat "\\<" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\>")
 		 re1 (concat pre re2 post)
 		 re3 (concat pre re4 post)
 		 re5 (concat pre ".*" re4)
 		 re2 (concat pre re2)
+		 re2a (concat pre re2a)
 		 re4 (concat pre re4)
 		 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
 			       "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
@@ -7009,12 +7031,14 @@
 	    ((eq type 'org-occur) (org-occur reall))
 	    ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
 	    (t (goto-char (point-min))
-	       (if (or (re-search-forward re0 nil t)
-		       (re-search-forward re1 nil t)
-		       (re-search-forward re2 nil t)
-		       (re-search-forward re3 nil t)
-		       (re-search-forward re4 nil t)
-		       (re-search-forward re5 nil t))
+	       (if (or (org-search-not-link re0 nil t)
+		       (org-search-not-link re1 nil t)
+		       (org-search-not-link re2 nil t)
+		       (org-search-not-link re2a nil t) ;; FIXME: Right place???
+		       (org-search-not-link re3 nil t)
+		       (org-search-not-link re4 nil t)
+		       (org-search-not-link re5 nil t)
+		       )
 		   (goto-char (match-beginning 0))
 		 (goto-char pos)
 		 (error "No match")))))
@@ -7026,6 +7050,21 @@
 	     (error "No match"))))
     (and (eq major-mode 'org-mode) (org-show-hierarchy-above))))
 
+(defun org-search-not-link (&rest args)
+  "Execute `re-search-forward', but only accept matches that are not a link."
+  (catch 'exit
+    (let ((pos (point)) p1)
+      (while (apply 're-search-forward args)
+	(setq p1 (point))
+	(if (not (save-match-data
+		   (and (re-search-backward "\\[\\[" nil t)
+			(looking-at org-bracket-link-regexp)
+			(<= (match-beginning 0) p1)
+			(>= (match-end 0) p1))))
+	    (progn (goto-char (match-end 0))
+		   (throw 'exit (point)))
+	  (goto-char (match-end 0)))))))
+
 (defun org-do-occur (regexp &optional cleanup)
   "Call the Emacs command `occur'.
 If CLEANUP is non-nil, remove the printout of the regular expression
@@ -7284,24 +7323,32 @@
     header-field)))
 
 (defun org-follow-mhe-link (folder article)
-  "Follow an MHE link to FOLDER and ARTICLE."
-  (setq article (org-add-angle-brackets article))
+  "Follow an MHE link to FOLDER and ARTICLE.
+If ARTICLE is nil FOLDER is shown.  If the configuration variable
+`org-mhe-search-all-folders' is t and `mh-searcher' is pick,
+ARTICLE is searched in all folders.  Indexed searches (swish++,
+namazu, and others supported by MH-E) will always search in all
+folders."
   (require 'mh-e)
   (require 'mh-search)
+  (require 'mh-utils)
   (mh-find-path)
-  (mh-search-choose)
-  (if (equal mh-searcher 'pick)
-      (progn
-        (mh-search folder (list "--message-id" article))
-        (when (and org-mhe-search-all-folders
-                 (not (org-mhe-get-message-real-folder)))
-          (kill-this-buffer)
-          (mh-search "+" (list "--message-id" article))))
-    (mh-search "+" article))
-  (if (org-mhe-get-message-real-folder)
-      (mh-show-msg 1)
-    (kill-this-buffer)
-    (error "Message not found")))
+  (if (not article)
+      (mh-visit-folder (mh-normalize-folder-name folder))
+    (setq article (org-add-angle-brackets article))
+    (mh-search-choose)
+    (if (equal mh-searcher 'pick)
+        (progn
+          (mh-search folder (list "--message-id" article))
+          (when (and org-mhe-search-all-folders
+                     (not (org-mhe-get-message-real-folder)))
+            (kill-this-buffer)
+            (mh-search "+" (list "--message-id" article))))
+      (mh-search "+" article))
+    (if (org-mhe-get-message-real-folder)
+        (mh-show-msg 1)
+      (kill-this-buffer)
+      (error "Message not found"))))
 
 (defun org-open-file (path &optional in-emacs line search)
   "Open the file at PATH.
@@ -10563,7 +10610,7 @@
 This will leave level 1 alone, convert level 2 to level 3, level 3 to
 level 5 etc."
   (interactive)
-  (when (yes-or-no-p "Are you sure you want to globally change levels? ")
+  (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
     (let ((org-odd-levels-only nil) n)
       (save-excursion
 	(goto-char (point-min))
@@ -10573,6 +10620,28 @@
 	    (org-demote))
 	  (end-of-line 1))))))
 
+
+(defun org-convert-to-oddeven-levels ()
+  "Convert an org-mode file with only odd levels to one with odd and even levels.
+This promotes level 3 to level 2, level 5 to level 3 etc.  If the file contains a
+section with an even level, conversion would destroy the structure of the file.  An error
+is signaled in this case."
+  (interactive)
+  (goto-char (point-min))
+  ;; First check if there are no even levels
+  (when (re-search-forward "^\\(\\*\\*\\)+[^*]" nil t)
+    (org-show-hierarchy-above)
+    (error "Not all levels are odd in this file.  Conversion not possible."))
+  (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
+    (let ((org-odd-levels-only nil) n)
+      (save-excursion
+	(goto-char (point-min))
+	(while (re-search-forward "^\\*\\*+" nil t)
+	  (setq n (/ (length (match-string 0)) 2))
+	  (while (>= (setq n (1- n)) 0)
+	    (org-promote))
+	  (end-of-line 1))))))
+
 (defun org-tr-level (n)
   "Make N odd if required."
   (if org-odd-levels-only (1+ (/ n 2)) n))
@@ -10817,7 +10886,7 @@
 #+CATEGORY:  %s
 #+SEQ_TODO:  %s
 #+TYP_TODO:  %s
-#+STARTUP:   %s %s
+#+STARTUP:   %s %s %s %s
 #+ARCHIVE:   %s
 "
    (buffer-name) (user-full-name) user-mail-address org-export-default-language
@@ -10841,6 +10910,8 @@
    (cdr (assoc org-startup-folded
 	       '((nil . "nofold")(t . "fold")(content . "content"))))
    (if org-startup-with-deadline-check "dlcheck" "nodlcheck")
+   (if org-odd-levels-only "odd" "oddeven")
+   (if org-hide-leading-stars "hidestars" "showstars")
    org-archive-location
    ))
 
@@ -10924,6 +10995,7 @@
   (setq-default org-deadline-line-regexp org-deadline-line-regexp)
   (setq-default org-done-string org-done-string)
   (let* ((style org-export-html-style)
+	 (odd org-odd-levels-only)
 	 (region-p (org-region-active-p))
          (region
           (buffer-substring
@@ -10987,7 +11059,8 @@
       (switch-to-buffer-other-window buffer))
     (erase-buffer)
     (fundamental-mode)
-    (let ((case-fold-search nil))
+    (let ((case-fold-search nil)
+	  (org-odd-levels-only odd))
       (if options (org-parse-export-options options))
       (setq umax (if arg (prefix-numeric-value arg)
                    org-export-headline-levels))
@@ -12372,7 +12445,8 @@
      "--"
      ["Archive Subtree" org-archive-subtree t]
      "--"
-     ["Convert file to odd levels" org-convert-to-odd-levels t])
+     ["Convert to odd levels" org-convert-to-odd-levels t]
+     ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
     "--"
     ("TODO Lists"
      ["TODO/DONE/-" org-todo t]
@@ -12851,3 +12925,4 @@
 
 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
 ;;; org.el ends here
+