소스 검색

Merge remote branch 'ngz/end-lists'

Carsten Dominik 15 년 전
부모
커밋
411c829489
9개의 변경된 파일1692개의 추가작업 그리고 1110개의 파일을 삭제
  1. 3 3
      lisp/org-ascii.el
  2. 3 3
      lisp/org-capture.el
  3. 42 77
      lisp/org-docbook.el
  4. 28 0
      lisp/org-exp.el
  5. 203 255
      lisp/org-html.el
  6. 2 2
      lisp/org-latex.el
  7. 1203 567
      lisp/org-list.el
  8. 26 18
      lisp/org-timer.el
  9. 182 185
      lisp/org.el

+ 3 - 3
lisp/org-ascii.el

@@ -571,9 +571,9 @@ publishing directory."
       (replace-match "\\1\\2")))
       (replace-match "\\1\\2")))
   ;; Remove list start counters
   ;; Remove list start counters
   (goto-char (point-min))
   (goto-char (point-min))
-  (while (re-search-forward  "\\[@start:[0-9]+\\] ?" nil t)
-    (org-if-unprotected
-     (replace-match "")))
+  (while (org-search-forward-unenclosed
+	  "\\[@\\(?:start:\\)?[0-9]+\\][ \t]*" nil t)
+    (replace-match ""))
   (remove-text-properties
   (remove-text-properties
    (point-min) (point-max)
    (point-min) (point-max)
    '(face nil font-lock-fontified nil font-lock-multiline nil line-prefix nil wrap-prefix nil)))
    '(face nil font-lock-fontified nil font-lock-multiline nil line-prefix nil wrap-prefix nil)))

+ 3 - 3
lisp/org-capture.el

@@ -744,14 +744,14 @@ already gone."
     (if (org-capture-get :prepend)
     (if (org-capture-get :prepend)
 	(progn
 	(progn
 	  (goto-char beg)
 	  (goto-char beg)
-	  (if (re-search-forward (concat "^" (org-item-re)) end t)
+	  (if (org-search-forward-unenclosed org-item-beginning-re end t)
 	      (progn
 	      (progn
 		(goto-char (match-beginning 0))
 		(goto-char (match-beginning 0))
 		(setq ind (org-get-indentation)))
 		(setq ind (org-get-indentation)))
 	    (goto-char end)
 	    (goto-char end)
 	    (setq ind 0)))
 	    (setq ind 0)))
       (goto-char end)
       (goto-char end)
-      (if (re-search-backward (concat "^" (org-item-re)) beg t)
+      (if (org-search-backward-unenclosed org-item-beginning-re beg t)
 	  (progn
 	  (progn
 	    (setq ind (org-get-indentation))
 	    (setq ind (org-get-indentation))
 	    (org-end-of-item))
 	    (org-end-of-item))
@@ -973,7 +973,7 @@ Point will remain at the first line after the inserted text."
       (insert template)
       (insert template)
       (org-capture-empty-lines-after)
       (org-capture-empty-lines-after)
       (goto-char beg)
       (goto-char beg)
-      (org-maybe-renumber-ordered-list)
+      (org-list-repair)
       (org-end-of-item)
       (org-end-of-item)
       (setq end (point)))
       (setq end (point)))
      (t (insert template)))
      (t (insert template)))

+ 42 - 77
lisp/org-docbook.el

@@ -552,9 +552,9 @@ publishing directory."
 	  (nth 2 (assoc "=" org-export-docbook-emphasis-alist)))
 	  (nth 2 (assoc "=" org-export-docbook-emphasis-alist)))
 	 table-open type
 	 table-open type
 	 table-buffer table-orig-buffer
 	 table-buffer table-orig-buffer
-	 ind item-type starter didclose
+	 ind item-type starter
 	 rpl path attr caption label desc descp desc1 desc2 link
 	 rpl path attr caption label desc descp desc1 desc2 link
-	 fnc item-tag initial-number
+	 fnc item-tag item-number
 	 footref-seen footnote-list
 	 footref-seen footnote-list
 	 id-file
 	 id-file
 	 )
 	 )
@@ -671,7 +671,21 @@ publishing directory."
 	      (org-export-docbook-open-para))
 	      (org-export-docbook-open-para))
 	    (throw 'nextline nil))
 	    (throw 'nextline nil))
 
 
-	  (org-export-docbook-close-lists-maybe line)
+	  ;; List ender: close every open list.
+	  (when (equal "ORG-LIST-END" line)
+	    (while local-list-type
+	      (let ((listtype (car local-list-type)))
+		(org-export-docbook-close-li listtype)
+		(insert (cond
+			 ((equal listtype "o") "</orderedlist>\n")
+			 ((equal listtype "u") "</itemizedlist>\n")
+			 ((equal listtype "d") "</variablelist>\n"))))
+	      (pop local-list-type))
+	    ;; We did close a list, normal text follows: need <para>
+	    (org-export-docbook-open-para)
+	    (setq local-list-indent nil
+		  in-local-list nil)
+	    (throw 'nextline nil))
 
 
 	  ;; Protected HTML
 	  ;; Protected HTML
 	  (when (get-text-property 0 'org-protected line)
 	  (when (get-text-property 0 'org-protected line)
@@ -963,18 +977,6 @@ publishing directory."
 		  txt (match-string 2 line))
 		  txt (match-string 2 line))
 	    (if (string-match quote-re0 txt)
 	    (if (string-match quote-re0 txt)
 		(setq txt (replace-match "" t t txt)))
 		(setq txt (replace-match "" t t txt)))
-	    (when in-local-list
-	      ;; Close any local lists before inserting a new header line
-	      (while local-list-type
-		(let ((listtype (car local-list-type)))
-		  (org-export-docbook-close-li listtype)
-		  (insert (cond
-			   ((equal listtype "o") "</orderedlist>\n")
-			   ((equal listtype "u") "</itemizedlist>\n")
-			   ((equal listtype "d") "</variablelist>\n"))))
-		(pop local-list-type))
-	      (setq local-list-indent nil
-		    in-local-list nil))
 	    (org-export-docbook-level-start level txt)
 	    (org-export-docbook-level-start level txt)
 	    ;; QUOTES
 	    ;; QUOTES
 	    (when (string-match quote-re line)
 	    (when (string-match quote-re line)
@@ -1004,6 +1006,7 @@ publishing directory."
 	      (org-export-docbook-close-para-maybe)
 	      (org-export-docbook-close-para-maybe)
 	      (insert (org-export-docbook-finalize-table
 	      (insert (org-export-docbook-finalize-table
 		       (org-format-table-html table-buffer table-orig-buffer)))))
 		       (org-format-table-html table-buffer table-orig-buffer)))))
+
 	   (t
 	   (t
 	    ;; Normal lines
 	    ;; Normal lines
 	    (when (string-match
 	    (when (string-match
@@ -1020,34 +1023,14 @@ publishing directory."
 				(substring (match-string 2 line) 0 -1))
 				(substring (match-string 2 line) 0 -1))
 		    line (substring line (match-beginning 5))
 		    line (substring line (match-beginning 5))
 		    item-tag nil
 		    item-tag nil
-		    initial-number nil)
-	      (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line)
-		  (setq initial-number (match-string 1 line)
+		    item-number nil)
+	      (if (string-match "\\[@\\(?:start:\\)?\\([0-9]+\\)\\][ \t]?" line)
+		  (setq item-number (match-string 1 line)
 			line (replace-match "" t t line)))
 			line (replace-match "" t t line)))
 	      (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
 	      (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
 		  (setq item-type "d"
 		  (setq item-type "d"
 			item-tag (match-string 1 line)
 			item-tag (match-string 1 line)
 			line (substring line (match-end 0))))
 			line (substring line (match-end 0))))
-	      (when (and (not (equal item-type "d"))
-			 (not (string-match "[^ \t]" line)))
-		;; Empty line.  Pretend indentation is large.
-		(setq ind (if org-empty-line-terminates-plain-lists
-			      0
-			    (1+ (or (car local-list-indent) 1)))))
-	      (setq didclose nil)
-	      (while (and in-local-list
-			  (or (and (= ind (car local-list-indent))
-				   (not starter))
-			      (< ind (car local-list-indent))))
-		(setq didclose t)
-		(let ((listtype (car local-list-type)))
-		  (org-export-docbook-close-li listtype)
-		  (insert (cond
-			   ((equal listtype "o") "</orderedlist>\n")
-			   ((equal listtype "u") "</itemizedlist>\n")
-			   ((equal listtype "d") "</variablelist>\n"))))
-		(pop local-list-type) (pop local-list-indent)
-		(setq in-local-list local-list-indent))
 	      (cond
 	      (cond
 	       ((and starter
 	       ((and starter
 		     (or (not in-local-list)
 		     (or (not in-local-list)
@@ -1056,7 +1039,7 @@ publishing directory."
 		(org-export-docbook-close-para-maybe)
 		(org-export-docbook-close-para-maybe)
 		(insert (cond
 		(insert (cond
 			 ((equal item-type "u") "<itemizedlist>\n<listitem>\n")
 			 ((equal item-type "u") "<itemizedlist>\n<listitem>\n")
-			 ((equal item-type "o")
+			 ((and (equal item-type "o") item-number)
 			  ;; Check for a specific start number.  If it
 			  ;; Check for a specific start number.  If it
 			  ;; is specified, we use the ``override''
 			  ;; is specified, we use the ``override''
 			  ;; attribute of element <listitem> to pass the
 			  ;; attribute of element <listitem> to pass the
@@ -1064,10 +1047,8 @@ publishing directory."
 			  ;; ``startingnumber'' attribute of element
 			  ;; ``startingnumber'' attribute of element
 			  ;; <orderedlist>, but the former works on both
 			  ;; <orderedlist>, but the former works on both
 			  ;; DocBook 5.0 and prior versions.
 			  ;; DocBook 5.0 and prior versions.
-			  (if initial-number
-			      (format "<orderedlist>\n<listitem override=\"%s\">\n"
-				      initial-number)
-			    "<orderedlist>\n<listitem>\n"))
+			  (format "<orderedlist>\n<listitem override=\"%s\">\n" item-number))
+			 ((equal item-type "o") "<orderedlist>\n<listitem>\n")
 			 ((equal item-type "d")
 			 ((equal item-type "d")
 			  (format "<variablelist>\n<varlistentry><term>%s</term><listitem>\n" item-tag))))
 			  (format "<variablelist>\n<varlistentry><term>%s</term><listitem>\n" item-tag))))
 		;; For DocBook, we need to open a para right after tag
 		;; For DocBook, we need to open a para right after tag
@@ -1076,11 +1057,27 @@ publishing directory."
 		(push item-type local-list-type)
 		(push item-type local-list-type)
 		(push ind local-list-indent)
 		(push ind local-list-indent)
 		(setq in-local-list t))
 		(setq in-local-list t))
-	       (starter
 		;; Continue current list
 		;; Continue current list
+	       (starter
+		;; terminate any previous sublist but first ensure
+		;; list is not ill-formed
+		(let ((min-ind (apply 'min local-list-indent)))
+		  (when (< ind min-ind) (setq ind min-ind)))
+		(while (< ind (car local-list-indent))
+		  (let ((listtype (car local-list-type)))
+		    (org-export-docbook-close-li listtype)
+		    (insert (cond
+			     ((equal listtype "o") "</orderedlist>\n")
+			     ((equal listtype "u") "</itemizedlist>\n")
+			     ((equal listtype "d") "</variablelist>\n"))))
+		  (pop local-list-type) (pop local-list-indent)
+		  (setq in-local-list local-list-indent))
+		;; insert new item
 		(let ((listtype (car local-list-type)))
 		(let ((listtype (car local-list-type)))
 		  (org-export-docbook-close-li listtype)
 		  (org-export-docbook-close-li listtype)
 		  (insert (cond
 		  (insert (cond
+			   ((and (equal listtype "o") item-number)
+			    (format "<listitem override=\"%s\">" item-number))
 			   ((equal listtype "o") "<listitem>")
 			   ((equal listtype "o") "<listitem>")
 			   ((equal listtype "u") "<listitem>")
 			   ((equal listtype "u") "<listitem>")
 			   ((equal listtype "d") (format
 			   ((equal listtype "d") (format
@@ -1089,9 +1086,6 @@ publishing directory."
 						      "???"))))))
 						      "???"))))))
 		;; For DocBook, we need to open a para right after tag
 		;; For DocBook, we need to open a para right after tag
 		;; <listitem>.
 		;; <listitem>.
-		(org-export-docbook-open-para))
-	       (didclose
-		;; We did close a list, normal text follows: need <para>
 		(org-export-docbook-open-para)))
 		(org-export-docbook-open-para)))
 	      ;; Checkboxes.
 	      ;; Checkboxes.
 	      (if (string-match "^[ \t]*\\(\\[[X -]\\]\\)" line)
 	      (if (string-match "^[ \t]*\\(\\[[X -]\\]\\)" line)
@@ -1134,18 +1128,7 @@ publishing directory."
       (when inquote
       (when inquote
 	(insert "]]></programlisting>\n")
 	(insert "]]></programlisting>\n")
 	(org-export-docbook-open-para))
 	(org-export-docbook-open-para))
-      (when in-local-list
-	;; Close any local lists before inserting a new header line
-	(while local-list-type
-	  (let ((listtype (car local-list-type)))
-	    (org-export-docbook-close-li listtype)
-	    (insert (cond
-		     ((equal listtype "o") "</orderedlist>\n")
-		     ((equal listtype "u") "</itemizedlist>\n")
-		     ((equal listtype "d") "</variablelist>\n"))))
-	  (pop local-list-type))
-	(setq local-list-indent nil
-	      in-local-list nil))
+
       ;; Close all open sections.
       ;; Close all open sections.
       (org-export-docbook-level-start 1 nil)
       (org-export-docbook-level-start 1 nil)
 
 
@@ -1212,24 +1195,6 @@ publishing directory."
 (defvar in-local-list)
 (defvar in-local-list)
 (defvar local-list-indent)
 (defvar local-list-indent)
 (defvar local-list-type)
 (defvar local-list-type)
-(defun org-export-docbook-close-lists-maybe (line)
-  (let ((ind (or (get-text-property 0 'original-indentation line)))
-;		 (and (string-match "\\S-" line)
-;		      (org-get-indentation line))))
-	didclose)
-    (when ind
-      (while (and in-local-list
-		  (<= ind (car local-list-indent)))
-	(setq didclose t)
-	(let ((listtype (car local-list-type)))
-	  (org-export-docbook-close-li listtype)
-	  (insert (cond
-		   ((equal listtype "o") "</orderedlist>\n")
-		   ((equal listtype "u") "</itemizedlist>\n")
-		   ((equal listtype "d") "</variablelist>\n"))))
-	(pop local-list-type) (pop local-list-indent)
-	(setq in-local-list local-list-indent))
-      (and didclose (org-export-docbook-open-para)))))
 
 
 (defun org-export-docbook-level-start (level title)
 (defun org-export-docbook-level-start (level title)
   "Insert a new level in DocBook export.
   "Insert a new level in DocBook export.

+ 28 - 0
lisp/org-exp.el

@@ -1076,6 +1076,9 @@ on this string to produce the exported version."
 				     (plist-get parameters :exclude-tags))
 				     (plist-get parameters :exclude-tags))
       (run-hooks 'org-export-preprocess-after-tree-selection-hook)
       (run-hooks 'org-export-preprocess-after-tree-selection-hook)
 
 
+      ;; Mark end of lists
+      (org-export-mark-list-ending backend)
+
       ;; Handle source code snippets
       ;; Handle source code snippets
       (org-export-replace-src-segments-and-examples backend)
       (org-export-replace-src-segments-and-examples backend)
 
 
@@ -1626,6 +1629,31 @@ These special cookies will later be interpreted by the backend."
 	(delete-region beg end)
 	(delete-region beg end)
 	(insert (org-add-props content nil 'original-indentation ind))))))
 	(insert (org-add-props content nil 'original-indentation ind))))))
 
 
+(defun org-export-mark-list-ending (backend)
+  "Mark list endings with special cookies.
+These special cookies will later be interpreted by the backend.
+`org-list-end-re' is replaced by a blank line in the process."
+  (let ((process-buffer
+	 (lambda (end-list-marker)
+	   (goto-char (point-min))
+	   (while (org-search-forward-unenclosed org-item-beginning-re nil t)
+	     (goto-char (org-list-bottom-point))
+	     (when (and (not (eq org-list-ending-method 'indent))
+			(looking-at (org-list-end-re)))
+	       (replace-match "\n"))
+	     (insert end-list-marker)))))
+  ;; We need to divide backends into 3 categories.
+  (cond
+   ;; 1. Backends using `org-list-parse-list' do not need markers.
+   ((memq backend '(latex))
+    nil)
+   ;; 2. Line-processing backends need to be told where lists end.
+   ((memq backend '(html docbook))
+    (funcall process-buffer "ORG-LIST-END\n"))
+   ;; 3. Others backends do not need to know this: clean list enders.
+   (t
+    (funcall process-buffer "")))))
+
 (defun org-export-attach-captions-and-attributes (backend target-alist)
 (defun org-export-attach-captions-and-attributes (backend target-alist)
   "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
   "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
 If the next thing following is a table, add the text properties to the first
 If the next thing following is a table, add the text properties to the first

+ 203 - 255
lisp/org-html.el

@@ -890,8 +890,8 @@ PUB-DIR is set, use this as the publishing directory."
 		       (string-match "\\S-" (plist-get opt-plist :link-up))
 		       (string-match "\\S-" (plist-get opt-plist :link-up))
 		       (plist-get opt-plist :link-up)))
 		       (plist-get opt-plist :link-up)))
 	 (link-home (and (plist-get opt-plist :link-home)
 	 (link-home (and (plist-get opt-plist :link-home)
-			(string-match "\\S-" (plist-get opt-plist :link-home))
-			(plist-get opt-plist :link-home)))
+			 (string-match "\\S-" (plist-get opt-plist :link-home))
+			 (plist-get opt-plist :link-home)))
 	 (dummy (setq opt-plist (plist-put opt-plist :title title)))
 	 (dummy (setq opt-plist (plist-put opt-plist :title title)))
 	 (html-table-tag (plist-get opt-plist :html-table-tag))
 	 (html-table-tag (plist-get opt-plist :html-table-tag))
 	 (quote-re0   (concat "^[ \t]*" org-quote-string "\\>"))
 	 (quote-re0   (concat "^[ \t]*" org-quote-string "\\>"))
@@ -960,9 +960,9 @@ PUB-DIR is set, use this as the publishing directory."
 	    ""))
 	    ""))
 	 table-open type
 	 table-open type
 	 table-buffer table-orig-buffer
 	 table-buffer table-orig-buffer
-	 ind item-type starter didclose
+	 ind item-type starter
 	 rpl path attr desc descp desc1 desc2 link
 	 rpl path attr desc descp desc1 desc2 link
-	 snumber fnc item-tag initial-number
+	 snumber fnc item-tag item-number
 	 footnotes footref-seen
 	 footnotes footref-seen
 	 id-file href
 	 id-file href
 	 )
 	 )
@@ -1072,73 +1072,73 @@ lang=\"%s\" xml:lang=\"%s\">
 	    (push "<ul>\n<li>" thetoc)
 	    (push "<ul>\n<li>" thetoc)
 	    (setq lines
 	    (setq lines
 		  (mapcar '(lambda (line)
 		  (mapcar '(lambda (line)
-		    (if (and (string-match org-todo-line-regexp line)
-			     (not (get-text-property 0 'org-protected line)))
-			;; This is a headline
-			(progn
-			  (setq have-headings t)
-			  (setq level (- (match-end 1) (match-beginning 1)
-					 level-offset)
-				level (org-tr-level level)
-				txt (save-match-data
-				      (org-html-expand
-				       (org-export-cleanup-toc-line
-					(match-string 3 line))))
-				todo
-				(or (and org-export-mark-todo-in-toc
-					 (match-beginning 2)
-					 (not (member (match-string 2 line)
-						      org-done-keywords)))
+			     (if (and (string-match org-todo-line-regexp line)
+				      (not (get-text-property 0 'org-protected line)))
+				 ;; This is a headline
+				 (progn
+				   (setq have-headings t)
+				   (setq level (- (match-end 1) (match-beginning 1)
+						  level-offset)
+					 level (org-tr-level level)
+					 txt (save-match-data
+					       (org-html-expand
+						(org-export-cleanup-toc-line
+						 (match-string 3 line))))
+					 todo
+					 (or (and org-export-mark-todo-in-toc
+						  (match-beginning 2)
+						  (not (member (match-string 2 line)
+							       org-done-keywords)))
 					; TODO, not DONE
 					; TODO, not DONE
-				    (and org-export-mark-todo-in-toc
-					 (= level umax-toc)
-					 (org-search-todo-below
-					  line lines level))))
-			  (if (string-match
-			       (org-re "[ \t]+:\\([[:alnum:]_@#%:]+\\):[ \t]*$") txt)
-			      (setq txt (replace-match  "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
-			  (if (string-match quote-re0 txt)
-			      (setq txt (replace-match "" t t txt)))
-			  (setq snumber (org-section-number level))
-			  (if org-export-with-section-numbers
-			      (setq txt (concat snumber " " txt)))
-			  (if (<= level (max umax umax-toc))
-			      (setq head-count (+ head-count 1)))
-			  (if (<= level umax-toc)
-			      (progn
-				(if (> level org-last-level)
-				    (progn
-				      (setq cnt (- level org-last-level))
-				      (while (>= (setq cnt (1- cnt)) 0)
-					(push "\n<ul>\n<li>" thetoc))
-				      (push "\n" thetoc)))
-				(if (< level org-last-level)
-				    (progn
-				      (setq cnt (- org-last-level level))
-				      (while (>= (setq cnt (1- cnt)) 0)
-					(push "</li>\n</ul>" thetoc))
-				      (push "\n" thetoc)))
-				;; Check for targets
-				(while (string-match org-any-target-regexp line)
-				  (setq line (replace-match
-					      (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
-					      t t line)))
-				(while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
-				  (setq txt (replace-match "" t t txt)))
-				(setq href
-				      (replace-regexp-in-string
-				       "\\." "_" (format "sec-%s" snumber)))
-				(setq href (or (cdr (assoc href org-export-preferred-target-alist)) href))
-				(push
-				 (format
-				  (if todo
-				      "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
-				    "</li>\n<li><a href=\"#%s\">%s</a>")
-				  href txt) thetoc)
-
-				(setq org-last-level level))
-			    )))
-		    line)
+					     (and org-export-mark-todo-in-toc
+						  (= level umax-toc)
+						  (org-search-todo-below
+						   line lines level))))
+				   (if (string-match
+					(org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
+				       (setq txt (replace-match  "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
+				   (if (string-match quote-re0 txt)
+				       (setq txt (replace-match "" t t txt)))
+				   (setq snumber (org-section-number level))
+				   (if org-export-with-section-numbers
+				       (setq txt (concat snumber " " txt)))
+				   (if (<= level (max umax umax-toc))
+				       (setq head-count (+ head-count 1)))
+				   (if (<= level umax-toc)
+				       (progn
+					 (if (> level org-last-level)
+					     (progn
+					       (setq cnt (- level org-last-level))
+					       (while (>= (setq cnt (1- cnt)) 0)
+						 (push "\n<ul>\n<li>" thetoc))
+					       (push "\n" thetoc)))
+					 (if (< level org-last-level)
+					     (progn
+					       (setq cnt (- org-last-level level))
+					       (while (>= (setq cnt (1- cnt)) 0)
+						 (push "</li>\n</ul>" thetoc))
+					       (push "\n" thetoc)))
+					 ;; Check for targets
+					 (while (string-match org-any-target-regexp line)
+					   (setq line (replace-match
+						       (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
+						       t t line)))
+					 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
+					   (setq txt (replace-match "" t t txt)))
+					 (setq href
+					       (replace-regexp-in-string
+						"\\." "_" (format "sec-%s" snumber)))
+					 (setq href (or (cdr (assoc href org-export-preferred-target-alist)) href))
+					 (push
+					  (format
+					   (if todo
+					       "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
+					     "</li>\n<li><a href=\"#%s\">%s</a>")
+					   href txt) thetoc)
+
+					 (setq org-last-level level))
+				     )))
+			     line)
 			  lines))
 			  lines))
 	    (while (> org-last-level (1- org-min-level))
 	    (while (> org-last-level (1- org-min-level))
 	      (setq org-last-level (1- org-last-level))
 	      (setq org-last-level (1- org-last-level))
@@ -1181,7 +1181,16 @@ lang=\"%s\" xml:lang=\"%s\">
 	      (org-open-par))
 	      (org-open-par))
 	    (throw 'nextline nil))
 	    (throw 'nextline nil))
 
 
-	  (org-export-html-close-lists-maybe line)
+	  ;; Explicit list closure
+	  (when (equal "ORG-LIST-END" line)
+	    (while local-list-indent
+	      (org-close-li (car local-list-type))
+	      (insert (format "</%sl>\n" (car local-list-type)))
+	      (pop local-list-type)
+	      (pop local-list-indent))
+	    (setq in-local-list nil)
+	    (org-open-par)
+	    (throw 'nextline nil))
 
 
 	  ;; Protected HTML
 	  ;; Protected HTML
 	  (when (get-text-property 0 'org-protected line)
 	  (when (get-text-property 0 'org-protected line)
@@ -1300,79 +1309,79 @@ lang=\"%s\" xml:lang=\"%s\">
 		  desc2 (if (match-end 2) (concat type ":" path) path)
 		  desc2 (if (match-end 2) (concat type ":" path) path)
 		  descp (and desc1 (not (equal desc1 desc2)))
 		  descp (and desc1 (not (equal desc1 desc2)))
 		  desc (or desc1 desc2))
 		  desc (or desc1 desc2))
-	     ;; Make an image out of the description if that is so wanted
+	    ;; Make an image out of the description if that is so wanted
 	    (when (and descp (org-file-image-p
 	    (when (and descp (org-file-image-p
-				desc org-export-html-inline-image-extensions))
-	       (save-match-data
-		  (if (string-match "^file:" desc)
-		     (setq desc (substring desc (match-end 0)))))
-	       (setq desc (org-add-props
+			      desc org-export-html-inline-image-extensions))
+	      (save-match-data
+		(if (string-match "^file:" desc)
+		    (setq desc (substring desc (match-end 0)))))
+	      (setq desc (org-add-props
 			     (concat "<img src=\"" desc "\"/>")
 			     (concat "<img src=\"" desc "\"/>")
 			     '(org-protected t))))
 			     '(org-protected t))))
 	    (cond
 	    (cond
 	     ((equal type "internal")
 	     ((equal type "internal")
-		(let
-		   ((frag-0
-		       (if (= (string-to-char path) ?#)
-			  (substring path 1)
-			  path)))
-		   (setq rpl
+	      (let
+		  ((frag-0
+		    (if (= (string-to-char path) ?#)
+			(substring path 1)
+		      path)))
+		(setq rpl
 		      (org-html-make-link
 		      (org-html-make-link
-			 opt-plist
-			 ""
-			 ""
-			 (org-solidify-link-text
-			    (save-match-data (org-link-unescape frag-0))
-			    nil)
-			 desc attr nil))))
+		       opt-plist
+		       ""
+		       ""
+		       (org-solidify-link-text
+			(save-match-data (org-link-unescape frag-0))
+			nil)
+		       desc attr nil))))
 	     ((and (equal type "id")
 	     ((and (equal type "id")
 		   (setq id-file (org-id-find-id-file path)))
 		   (setq id-file (org-id-find-id-file path)))
 	      ;; This is an id: link to another file (if it was the same file,
 	      ;; This is an id: link to another file (if it was the same file,
 	      ;; it would have become an internal link...)
 	      ;; it would have become an internal link...)
 	      (save-match-data
 	      (save-match-data
 		(setq id-file (file-relative-name
 		(setq id-file (file-relative-name
-				 id-file
-				 (file-name-directory org-current-export-file)))
+			       id-file
+			       (file-name-directory org-current-export-file)))
 		(setq rpl
 		(setq rpl
-		   (org-html-make-link opt-plist
-		      "file" id-file
-		      (concat (if (org-uuidgen-p path) "ID-") path)
-		       desc
-		      attr
-		      nil))))
+		      (org-html-make-link opt-plist
+					  "file" id-file
+					  (concat (if (org-uuidgen-p path) "ID-") path)
+					  desc
+					  attr
+					  nil))))
 	     ((member type '("http" "https"))
 	     ((member type '("http" "https"))
-		;; standard URL, can inline as image
-		(setq rpl
-		   (org-html-make-link opt-plist
-		      type path nil
-		      desc
-		      attr
-		      (org-html-should-inline-p path descp))))
+	      ;; standard URL, can inline as image
+	      (setq rpl
+		    (org-html-make-link opt-plist
+					type path nil
+					desc
+					attr
+					(org-html-should-inline-p path descp))))
 	     ((member type '("ftp" "mailto" "news"))
 	     ((member type '("ftp" "mailto" "news"))
-		;; standard URL, can't inline as image
-		(setq rpl
-		   (org-html-make-link opt-plist
-		      type path nil
-		      desc
-		      attr
-		      nil)))
+	      ;; standard URL, can't inline as image
+	      (setq rpl
+		    (org-html-make-link opt-plist
+					type path nil
+					desc
+					attr
+					nil)))
 
 
 	     ((string= type "coderef")
 	     ((string= type "coderef")
-		(let*
-		   ((coderef-str (format "coderef-%s" path))
-		      (attr-1
-			 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
+	      (let*
+		  ((coderef-str (format "coderef-%s" path))
+		   (attr-1
+		    (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
 			    coderef-str coderef-str)))
 			    coderef-str coderef-str)))
-		   (setq rpl
+		(setq rpl
 		      (org-html-make-link opt-plist
 		      (org-html-make-link opt-plist
-			 type "" coderef-str
-			 (format
-			    (org-export-get-coderef-format
-			       path
-			       (and descp desc))
-			    (cdr (assoc path org-export-code-refs)))
-			 attr-1
-			 nil))))
+					  type "" coderef-str
+					  (format
+					   (org-export-get-coderef-format
+					    path
+					    (and descp desc))
+					   (cdr (assoc path org-export-code-refs)))
+					  attr-1
+					  nil))))
 
 
 	     ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
 	     ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
 	      ;; The link protocol has a function for format the link
 	      ;; The link protocol has a function for format the link
@@ -1381,55 +1390,55 @@ lang=\"%s\" xml:lang=\"%s\">
 		      (funcall fnc (org-link-unescape path) desc1 'html))))
 		      (funcall fnc (org-link-unescape path) desc1 'html))))
 
 
 	     ((string= type "file")
 	     ((string= type "file")
-		;; FILE link
-		(save-match-data
-		   (let*
-		      ((components
-			  (if
-			     (string-match "::\\(.*\\)" path)
-			     (list
-				(replace-match "" t nil path)
-				(match-string 1 path))
-			     (list path nil)))
-
-			 ;;The proper path, without a fragment
-			 (path-1
-			    (first components))
-
-			 ;;The raw fragment
-			 (fragment-0
-			    (second components))
-
-			 ;;Check the fragment.  If it can't be used as
-			 ;;target fragment we'll pass nil instead.
-			 (fragment-1
-			    (if
-			       (and fragment-0
-				  (not (string-match "^[0-9]*$" fragment-0))
-				  (not (string-match "^\\*" fragment-0))
-				  (not (string-match "^/.*/$" fragment-0)))
-			       (org-solidify-link-text
-				  (org-link-unescape fragment-0))
-			       nil))
-			 (desc-2
-			    ;;Description minus "file:" and ".org"
-			    (if (string-match "^file:" desc)
-			       (let
-				  ((desc-1 (replace-match "" t t desc)))
-				  (if (string-match "\\.org$" desc-1)
-				     (replace-match "" t t desc-1)
-				     desc-1))
-			       desc)))
-
-		      (setq rpl
-			 (if
+	      ;; FILE link
+	      (save-match-data
+		(let*
+		    ((components
+		      (if
+			  (string-match "::\\(.*\\)" path)
+			  (list
+			   (replace-match "" t nil path)
+			   (match-string 1 path))
+			(list path nil)))
+
+		     ;;The proper path, without a fragment
+		     (path-1
+		      (first components))
+
+		     ;;The raw fragment
+		     (fragment-0
+		      (second components))
+
+		     ;;Check the fragment.  If it can't be used as
+		     ;;target fragment we'll pass nil instead.
+		     (fragment-1
+		      (if
+			  (and fragment-0
+			       (not (string-match "^[0-9]*$" fragment-0))
+			       (not (string-match "^\\*" fragment-0))
+			       (not (string-match "^/.*/$" fragment-0)))
+			  (org-solidify-link-text
+			   (org-link-unescape fragment-0))
+			nil))
+		     (desc-2
+		      ;;Description minus "file:" and ".org"
+		      (if (string-match "^file:" desc)
+			  (let
+			      ((desc-1 (replace-match "" t t desc)))
+			    (if (string-match "\\.org$" desc-1)
+				(replace-match "" t t desc-1)
+			      desc-1))
+			desc)))
+
+		  (setq rpl
+			(if
 			    (and
 			    (and
-			       (functionp link-validate)
-			       (not (funcall link-validate path-1 current-dir)))
+			     (functionp link-validate)
+			     (not (funcall link-validate path-1 current-dir)))
 			    desc
 			    desc
-			    (org-html-make-link opt-plist
-			       "file" path-1 fragment-1 desc-2 attr
-			       (org-html-should-inline-p path-1 descp)))))))
+			  (org-html-make-link opt-plist
+					      "file" path-1 fragment-1 desc-2 attr
+					      (org-html-should-inline-p path-1 descp)))))))
 
 
 	     (t
 	     (t
 	      ;; just publish the path, as default
 	      ;; just publish the path, as default
@@ -1486,14 +1495,6 @@ lang=\"%s\" xml:lang=\"%s\">
 		(setq txt (replace-match "" t t txt)))
 		(setq txt (replace-match "" t t txt)))
 	    (if (<= level (max umax umax-toc))
 	    (if (<= level (max umax umax-toc))
 		(setq head-count (+ head-count 1)))
 		(setq head-count (+ head-count 1)))
-	    (when in-local-list
-	      ;; Close any local lists before inserting a new header line
-	      (while local-list-type
-		(org-close-li (car local-list-type))
-		(insert (format "</%sl>\n" (car local-list-type)))
-		(pop local-list-type))
-	      (setq local-list-indent nil
-		    in-local-list nil))
 	    (setq first-heading-pos (or first-heading-pos (point)))
 	    (setq first-heading-pos (or first-heading-pos (point)))
 	    (org-html-level-start level txt umax
 	    (org-html-level-start level txt umax
 				  (and org-export-with-toc (<= level umax))
 				  (and org-export-with-toc (<= level umax))
@@ -1505,19 +1506,6 @@ lang=\"%s\" xml:lang=\"%s\">
 	      (insert "<pre>")
 	      (insert "<pre>")
 	      (setq inquote t)))
 	      (setq inquote t)))
 
 
-	   ((string-match "^[ \t]*- __+[ \t]*$" line)
-	    ;; Explicit list closure
-	    (when local-list-type
-	      (let ((ind (org-get-indentation line)))
-		(while (and local-list-indent
-			    (<= ind (car local-list-indent)))
-		  (org-close-li (car local-list-type))
-		  (insert (format "</%sl>\n" (car local-list-type)))
-		  (pop local-list-type)
-		  (pop local-list-indent))
-		(or local-list-indent (setq in-local-list nil))))
-	    (throw 'nextline nil))
-
 	   ((and org-export-with-tables
 	   ((and org-export-with-tables
 		 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
 		 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
 	    (when (not table-open)
 	    (when (not table-open)
@@ -1550,66 +1538,57 @@ lang=\"%s\" xml:lang=\"%s\">
 		    starter (if (match-beginning 2)
 		    starter (if (match-beginning 2)
 				(substring (match-string 2 line) 0 -1))
 				(substring (match-string 2 line) 0 -1))
 		    line (substring line (match-beginning 5))
 		    line (substring line (match-beginning 5))
-		    initial-number nil
+		    item-number nil
 		    item-tag nil)
 		    item-tag nil)
-	      (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line)
-		  (setq initial-number (match-string 1 line)
+	      (if (string-match "\\[@\\(?:start:\\)?\\([0-9]+\\)\\][ \t]?" line)
+		  (setq item-number (match-string 1 line)
 			line (replace-match "" t t line)))
 			line (replace-match "" t t line)))
 	      (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
 	      (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
 		  (setq item-type "d"
 		  (setq item-type "d"
 			item-tag (match-string 1 line)
 			item-tag (match-string 1 line)
 			line (substring line (match-end 0))))
 			line (substring line (match-end 0))))
-	      (when (and (not (equal item-type "d"))
-			 (not (string-match "[^ \t]" line)))
-		;; empty line.  Pretend indentation is large.
-		(setq ind (if org-empty-line-terminates-plain-lists
-			      0
-			    (1+ (or (car local-list-indent) 1)))))
-	      (setq didclose nil)
-	      (while (and in-local-list
-			  (or (and (= ind (car local-list-indent))
-				   (not starter))
-			      (< ind (car local-list-indent))))
-		(setq didclose t)
-		(org-close-li (car local-list-type))
-		(insert (format "</%sl>\n" (car local-list-type)))
-		(pop local-list-type) (pop local-list-indent)
-		(setq in-local-list local-list-indent))
 	      (cond
 	      (cond
 	       ((and starter
 	       ((and starter
 		     (or (not in-local-list)
 		     (or (not in-local-list)
 			 (> ind (car local-list-indent))))
 			 (> ind (car local-list-indent))))
-		;; check for a specified start number
 		;; Start new (level of) list
 		;; Start new (level of) list
 		(org-close-par-maybe)
 		(org-close-par-maybe)
 		(insert (cond
 		(insert (cond
 			 ((equal item-type "u") "<ul>\n<li>\n")
 			 ((equal item-type "u") "<ul>\n<li>\n")
-			 ((equal item-type "o")
-			  (if initial-number
-			      (format "<ol start=%s>\n<li>\n" initial-number)
-			    "<ol>\n<li>\n"))
+			 ((and (equal item-type "o") item-number)
+			  (format "<ol>\n<li value=\"%s\">\n" item-number))
+			 ((equal item-type "o") "<ol>\n<li>\n")
 			 ((equal item-type "d")
 			 ((equal item-type "d")
 			  (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
 			  (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
 		(push item-type local-list-type)
 		(push item-type local-list-type)
 		(push ind local-list-indent)
 		(push ind local-list-indent)
 		(setq in-local-list t))
 		(setq in-local-list t))
+	       ;; Continue list
 	       (starter
 	       (starter
-		;; continue current list
+		;; terminate any previous sublist but first ensure
+		;; list is not ill-formed.
+		(let ((min-ind (apply 'min local-list-indent)))
+		  (when (< ind min-ind) (setq ind min-ind)))
+		(while (< ind (car local-list-indent))
+		  (org-close-li (car local-list-type))
+		  (insert (format "</%sl>\n" (car local-list-type)))
+		  (pop local-list-type) (pop local-list-indent)
+		  (setq in-local-list local-list-indent))
+		;; insert new item
 		(org-close-li (car local-list-type))
 		(org-close-li (car local-list-type))
 		(insert (cond
 		(insert (cond
 			 ((equal (car local-list-type) "d")
 			 ((equal (car local-list-type) "d")
 			  (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
 			  (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
-			 (t "<li>\n"))))
-	       (didclose
-		;; we did close a list, normal text follows: need <p>
-		(org-open-par)))
+			 ((and (equal item-type "o") item-number)
+			  (format "<li value=\"%s\">\n" item-number))
+			 (t "<li>\n")))))
 	      (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
 	      (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
 		  (setq line
 		  (setq line
 			(replace-match
 			(replace-match
 			 (if (equal (match-string 1 line) "X")
 			 (if (equal (match-string 1 line) "X")
 			     "<b>[X]</b>"
 			     "<b>[X]</b>"
 			   "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
 			   "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
-			   t t line))))
+			 t t line))))
 
 
 	    ;; Horizontal line
 	    ;; Horizontal line
 	    (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
 	    (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
@@ -1664,14 +1643,7 @@ lang=\"%s\" xml:lang=\"%s\">
       (when inquote
       (when inquote
 	(insert "</pre>\n")
 	(insert "</pre>\n")
 	(org-open-par))
 	(org-open-par))
-      (when in-local-list
-	;; Close any local lists before inserting a new header line
-	(while local-list-type
-	  (org-close-li (car local-list-type))
-	  (insert (format "</%sl>\n" (car local-list-type)))
-	  (pop local-list-type))
-	(setq local-list-indent nil
-	      in-local-list nil))
+
       (org-html-level-start 1 nil umax
       (org-html-level-start 1 nil umax
 			    (and org-export-with-toc (<= level umax))
 			    (and org-export-with-toc (<= level umax))
 			    head-count)
 			    head-count)
@@ -1752,8 +1724,6 @@ lang=\"%s\" xml:lang=\"%s\">
       (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
       (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
 	(replace-match ""))
 	(replace-match ""))
       (goto-char (point-min))
       (goto-char (point-min))
-      (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
-	(replace-match ""))
       ;; Convert whitespace place holders
       ;; Convert whitespace place holders
       (goto-char (point-min))
       (goto-char (point-min))
       (let (beg end n)
       (let (beg end n)
@@ -2274,28 +2244,6 @@ If there are links in the string, don't modify these."
 (defvar in-local-list)
 (defvar in-local-list)
 (defvar local-list-indent)
 (defvar local-list-indent)
 (defvar local-list-type)
 (defvar local-list-type)
-(defun org-export-html-close-lists-maybe (line)
-  "Close local lists based on the original indentation of the line."
-  (let* ((rawhtml (and in-local-list
-		       (get-text-property 0 'org-protected line)
-		       (not (get-text-property 0 'org-example line))))
-	 ;; rawhtml means: This was between #+begin_html..#+end_html
-	 ;; originally, thus it excludes stuff that was a source code example
-	 ;; Actually, this code seems wrong, I don't know why it works, but
-	 ;; it seems to work.... So keep it like this for now.
-         (ind (if rawhtml
-		  (org-get-indentation line)
-		(get-text-property 0 'original-indentation line)))
-	 didclose)
-    (when ind
-      (while (and in-local-list
-		  (<= ind (car local-list-indent)))
-	(setq didclose t)
-	(org-close-li (car local-list-type))
-	(insert (format "</%sl>\n" (car local-list-type)))
-	(pop local-list-type) (pop local-list-indent)
-	(setq in-local-list local-list-indent))
-      (and didclose (org-open-par)))))
 
 
 (defvar body-only) ; dynamically scoped into this.
 (defvar body-only) ; dynamically scoped into this.
 (defun org-html-level-start (level title umax with-toc head-count)
 (defun org-html-level-start (level title umax with-toc head-count)

+ 2 - 2
lisp/org-latex.el

@@ -2238,11 +2238,11 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
   "Convert plain text lists in current buffer into LaTeX lists."
   "Convert plain text lists in current buffer into LaTeX lists."
   (let (res)
   (let (res)
     (goto-char (point-min))
     (goto-char (point-min))
-    (while (org-re-search-forward-unprotected org-list-beginning-re nil t)
+    (while (org-search-forward-unenclosed org-item-beginning-re nil t)
       (beginning-of-line)
       (beginning-of-line)
       (setq res (org-list-to-latex (org-list-parse-list t)
       (setq res (org-list-to-latex (org-list-parse-list t)
 				   org-export-latex-list-parameters))
 				   org-export-latex-list-parameters))
-      (while (string-match "^\\(\\\\item[ \t]+\\)\\[@start:\\([0-9]+\\)\\]"
+      (while (string-match "^\\(\\\\item[ \t]+\\)\\[@\\(?:start:\\)?\\([0-9]+\\)\\]"
 			   res)
 			   res)
 	(setq res (replace-match
 	(setq res (replace-match
 		   (concat (format "\\setcounter{enumi}{%d}"
 		   (concat (format "\\setcounter{enumi}{%d}"

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1203 - 567
lisp/org-list.el


+ 26 - 18
lisp/org-timer.el

@@ -145,18 +145,23 @@ With prefix arg STOP, stop it entirely."
   (org-timer-set-mode-line 'off))
   (org-timer-set-mode-line 'off))
 
 
 ;;;###autoload
 ;;;###autoload
-(defun org-timer (&optional restart)
+(defun org-timer (&optional restart no-insert-p)
   "Insert a H:MM:SS string from the timer into the buffer.
   "Insert a H:MM:SS string from the timer into the buffer.
 The first time this command is used, the timer is started.  When used with
 The first time this command is used, the timer is started.  When used with
 a \\[universal-argument] prefix, force restarting the timer.
 a \\[universal-argument] prefix, force restarting the timer.
 When used with a double prefix argument \
 When used with a double prefix argument \
 \\[universal-argument] \\universal-argument], change all the timer string
 \\[universal-argument] \\universal-argument], change all the timer string
 in the region by a fixed amount.  This can be used to recalibrate a timer
 in the region by a fixed amount.  This can be used to recalibrate a timer
-that was not started at the correct moment."
+that was not started at the correct moment.
+
+If NO-INSERT-P is non-nil, return the string instead of inserting
+it in the buffer."
   (interactive "P")
   (interactive "P")
-  (if (equal restart '(4)) (org-timer-start))
-  (or org-timer-start-time (org-timer-start))
-  (insert (org-timer-value-string)))
+  (when (or (equal restart '(4)) (not org-timer-start-time))
+    (org-timer-start))
+  (if no-insert-p
+      (org-timer-value-string)
+    (insert (org-timer-value-string))))
 
 
 (defun org-timer-value-string ()
 (defun org-timer-value-string ()
   (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds)))))
   (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds)))))
@@ -195,19 +200,22 @@ that was not started at the correct moment."
 (defun org-timer-item (&optional arg)
 (defun org-timer-item (&optional arg)
   "Insert a description-type item with the current timer value."
   "Insert a description-type item with the current timer value."
   (interactive "P")
   (interactive "P")
-  (let ((ind 0))
-    (save-excursion
-      (skip-chars-backward " \n\t")
-      (condition-case nil
-	  (progn
-	    (org-beginning-of-item)
-	    (setq ind (org-get-indentation)))
-	(error nil)))
-    (or (bolp) (newline))
-    (org-indent-line-to ind)
-    (insert "- ")
-    (org-timer (if arg '(4)))
-    (insert ":: ")))
+  (cond
+   ;; In a timer list, insert with `org-list-insert-item-generic'.
+   ((and (org-in-item-p)
+	 (save-excursion (org-beginning-of-item) (org-at-item-timer-p)))
+    (org-list-insert-item-generic
+     (point) nil (concat (org-timer (when arg '(4)) t) ":: ")))
+   ;; In a list of another type, don't break anything: throw an error.
+   ((org-in-item-p)
+    (error "This is not a timer list"))
+   ;; Else, insert the timer correctly indented at bol.
+   (t
+    (beginning-of-line)
+    (org-indent-line-function)
+    (insert  "- ")
+    (org-timer (when arg '(4)))
+    (insert ":: "))))
 
 
 (defun org-timer-fix-incomplete (hms)
 (defun org-timer-fix-incomplete (hms)
   "If hms is a H:MM:SS string with missing hour or hour and minute, fix it."
   "If hms is a H:MM:SS string with missing hour or hour and minute, fix it."

+ 182 - 185
lisp/org.el

@@ -5457,13 +5457,13 @@ needs to be inserted at a specific position in the font-lock sequence.")
                    '(org-do-emphasis-faces (0 nil append))
                    '(org-do-emphasis-faces (0 nil append))
                  '(org-do-emphasis-faces)))
                  '(org-do-emphasis-faces)))
 	   ;; Checkboxes
 	   ;; Checkboxes
-	   '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)"
-	     2 'org-checkbox prepend)
-	   (if org-provide-checkbox-statistics
+	   '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
+	     1 'org-checkbox prepend)
+	   (if (cdr (assq 'checkbox org-list-automatic-rules))
 	       '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
 	       '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
 		 (0 (org-get-checkbox-statistics-face) t)))
 		 (0 (org-get-checkbox-statistics-face) t)))
 	   ;; Description list items
 	   ;; Description list items
-	   '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)"
+	   '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\(.*? ::\\)"
 	     2 'bold prepend)
 	     2 'bold prepend)
 	   ;; ARCHIVEd headings
 	   ;; ARCHIVEd headings
 	   (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
 	   (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)")
@@ -5900,12 +5900,15 @@ in special contexts.
 	(outline-next-heading)
 	(outline-next-heading)
 	(setq has-children (and (org-at-heading-p t)
 	(setq has-children (and (org-at-heading-p t)
 				(> (funcall outline-level) level))))
 				(> (funcall outline-level) level))))
-      (org-end-of-subtree t)
-      (unless (eobp)
-	(skip-chars-forward " \t\n")
-	(beginning-of-line 1) ; in case this is an item
-	)
-      (setq eos (if (eobp) (point) (1- (point)))))
+      ;; if we're in a list, org-end-of-subtree is in fact org-end-of-item.
+      (if (org-at-item-p)
+	  (setq eos (if (and (org-end-of-item) (bolp))
+			(1- (point))
+		      (point)))
+	(org-end-of-subtree t)
+	(unless (eobp)
+	  (skip-chars-forward " \t\n"))
+	(setq eos (if (eobp) (point) (1- (point))))))
     ;; Find out what to do next and set `this-command'
     ;; Find out what to do next and set `this-command'
     (cond
     (cond
      ((= eos eoh)
      ((= eos eoh)
@@ -5939,14 +5942,14 @@ in special contexts.
       ;; We just showed the children, or no children are there,
       ;; We just showed the children, or no children are there,
       ;; now show everything.
       ;; now show everything.
       (run-hook-with-args 'org-pre-cycle-hook 'subtree)
       (run-hook-with-args 'org-pre-cycle-hook 'subtree)
-      (org-show-subtree)
+      (outline-flag-region eoh eos nil)
       (message (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
       (message (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
       (setq org-cycle-subtree-status 'subtree)
       (setq org-cycle-subtree-status 'subtree)
       (run-hook-with-args 'org-cycle-hook 'subtree))
       (run-hook-with-args 'org-cycle-hook 'subtree))
      (t
      (t
       ;; Default action: hide the subtree.
       ;; Default action: hide the subtree.
       (run-hook-with-args 'org-pre-cycle-hook 'folded)
       (run-hook-with-args 'org-pre-cycle-hook 'folded)
-      (hide-subtree)
+      (outline-flag-region eoh eos t)
       (message "FOLDED")
       (message "FOLDED")
       (setq org-cycle-subtree-status 'folded)
       (setq org-cycle-subtree-status 'folded)
       (run-hook-with-args 'org-cycle-hook 'folded)))))
       (run-hook-with-args 'org-cycle-hook 'folded)))))
@@ -7516,13 +7519,15 @@ and still retain the repeater to cover future instances of the task."
 ;;; Outline Sorting
 ;;; Outline Sorting
 
 
 (defun org-sort (with-case)
 (defun org-sort (with-case)
-  "Call `org-sort-entries-or-items' or `org-table-sort-lines'.
+  "Call `org-sort-entries', `org-table-sort-lines' or `org-sort-list'.
 Optional argument WITH-CASE means sort case-sensitively.
 Optional argument WITH-CASE means sort case-sensitively.
 With a double prefix argument, also remove duplicate entries."
 With a double prefix argument, also remove duplicate entries."
   (interactive "P")
   (interactive "P")
-  (if (org-at-table-p)
-      (org-call-with-arg 'org-table-sort-lines with-case)
-    (org-call-with-arg 'org-sort-entries-or-items with-case)))
+  (cond
+   ((org-at-table-p) (org-call-with-arg 'org-table-sort-lines with-case))
+   ((org-at-item-p) (org-call-with-arg 'org-sort-list with-case))
+   (t
+    (org-call-with-arg 'org-sort-entries with-case))))
 
 
 (defun org-sort-remove-invisible (s)
 (defun org-sort-remove-invisible (s)
   (remove-text-properties 0 (length s) org-rm-props s)
   (remove-text-properties 0 (length s) org-rm-props s)
@@ -7540,14 +7545,12 @@ When children are sorted, the cursor is in the parent line when this
 hook gets called.  When a region or a plain list is sorted, the cursor
 hook gets called.  When a region or a plain list is sorted, the cursor
 will be in the first entry of the sorted region/list.")
 will be in the first entry of the sorted region/list.")
 
 
-(defun org-sort-entries-or-items
+(defun org-sort-entries
   (&optional with-case sorting-type getkey-func compare-func property)
   (&optional with-case sorting-type getkey-func compare-func property)
-  "Sort entries on a certain level of an outline tree, or plain list items.
+  "Sort entries on a certain level of an outline tree.
 If there is an active region, the entries in the region are sorted.
 If there is an active region, the entries in the region are sorted.
 Else, if the cursor is before the first entry, sort the top-level items.
 Else, if the cursor is before the first entry, sort the top-level items.
 Else, the children of the entry at point are sorted.
 Else, the children of the entry at point are sorted.
-If the cursor is at the first item in a plain list, the list items will be
-sorted.
 
 
 Sorting can be alphabetically, numerically, by date/time as given by
 Sorting can be alphabetically, numerically, by date/time as given by
 a time stamp, by a property or by priority.
 a time stamp, by a property or by priority.
@@ -7561,7 +7564,6 @@ n   Numerically, by converting the beginning of the entry/item to a number.
 a   Alphabetically, ignoring the TODO keyword and the priority, if any.
 a   Alphabetically, ignoring the TODO keyword and the priority, if any.
 t   By date/time, either the first active time stamp in the entry, or, if
 t   By date/time, either the first active time stamp in the entry, or, if
     none exist, by the first inactive one.
     none exist, by the first inactive one.
-    In items, only the first line will be checked.
 s   By the scheduled date/time.
 s   By the scheduled date/time.
 d   By deadline date/time.
 d   By deadline date/time.
 c   By creation time, which is assumed to be the first inactive time stamp
 c   By creation time, which is assumed to be the first inactive time stamp
@@ -7580,7 +7582,7 @@ WITH-CASE, the sorting considers case as well."
   (interactive "P")
   (interactive "P")
   (let ((case-func (if with-case 'identity 'downcase))
   (let ((case-func (if with-case 'identity 'downcase))
         start beg end stars re re2
         start beg end stars re re2
-        txt what tmp plain-list-p)
+        txt what tmp)
     ;; Find beginning and end of region to sort
     ;; Find beginning and end of region to sort
     (cond
     (cond
      ((org-region-active-p)
      ((org-region-active-p)
@@ -7590,15 +7592,6 @@ WITH-CASE, the sorting considers case as well."
       (goto-char (region-beginning))
       (goto-char (region-beginning))
       (if (not (org-on-heading-p)) (outline-next-heading))
       (if (not (org-on-heading-p)) (outline-next-heading))
       (setq start (point)))
       (setq start (point)))
-     ((org-at-item-p)
-      ;; we will sort this plain list
-      (org-beginning-of-item-list) (setq start (point))
-      (org-end-of-item-list)
-      (or (bolp) (insert "\n"))
-      (setq end (point))
-      (goto-char start)
-      (setq plain-list-p t
-	    what "plain list"))
      ((or (org-on-heading-p)
      ((or (org-on-heading-p)
           (condition-case nil (progn (org-back-to-heading) t) (error nil)))
           (condition-case nil (progn (org-back-to-heading) t) (error nil)))
       ;; we will sort the children of the current headline
       ;; we will sort the children of the current headline
@@ -7631,43 +7624,39 @@ WITH-CASE, the sorting considers case as well."
     (setq beg (point))
     (setq beg (point))
     (if (>= beg end) (error "Nothing to sort"))
     (if (>= beg end) (error "Nothing to sort"))
 
 
-    (unless plain-list-p
-      (looking-at "\\(\\*+\\)")
-      (setq stars (match-string 1)
-	    re (concat "^" (regexp-quote stars) " +")
-	    re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
-	    txt (buffer-substring beg end))
-      (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
-      (if (and (not (equal stars "*")) (string-match re2 txt))
-	  (error "Region to sort contains a level above the first entry")))
+    (looking-at "\\(\\*+\\)")
+    (setq stars (match-string 1)
+	  re (concat "^" (regexp-quote stars) " +")
+	  re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]")
+	  txt (buffer-substring beg end))
+    (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
+    (if (and (not (equal stars "*")) (string-match re2 txt))
+	(error "Region to sort contains a level above the first entry"))
 
 
     (unless sorting-type
     (unless sorting-type
       (message
       (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  [p]riority  p[r]operty  todo[o]rder  [f]unc
+       "Sort %s: [a]lpha  [n]umeric  [p]riority  p[r]operty  todo[o]rder  [f]unc
                [t]ime [s]cheduled  [d]eadline  [c]reated
                [t]ime [s]cheduled  [d]eadline  [c]reated
-               A/N/T/S/D/C/P/O/F means reversed:")
+               A/N/T/S/D/C/P/O/F means reversed:"
        what)
        what)
       (setq sorting-type (read-char-exclusive))
       (setq sorting-type (read-char-exclusive))
 
 
       (and (= (downcase sorting-type) ?f)
       (and (= (downcase sorting-type) ?f)
            (setq getkey-func
            (setq getkey-func
                  (org-icompleting-read "Sort using function: "
                  (org-icompleting-read "Sort using function: "
-                                  obarray 'fboundp t nil nil))
+				       obarray 'fboundp t nil nil))
            (setq getkey-func (intern getkey-func)))
            (setq getkey-func (intern getkey-func)))
 
 
       (and (= (downcase sorting-type) ?r)
       (and (= (downcase sorting-type) ?r)
            (setq property
            (setq property
                  (org-icompleting-read "Property: "
                  (org-icompleting-read "Property: "
-				  (mapcar 'list (org-buffer-property-keys t))
-                                  nil t))))
+				       (mapcar 'list (org-buffer-property-keys t))
+				       nil t))))
 
 
     (message "Sorting entries...")
     (message "Sorting entries...")
 
 
     (save-restriction
     (save-restriction
       (narrow-to-region start end)
       (narrow-to-region start end)
-
       (let ((dcst (downcase sorting-type))
       (let ((dcst (downcase sorting-type))
 	    (case-fold-search nil)
 	    (case-fold-search nil)
             (now (current-time)))
             (now (current-time)))
@@ -7675,99 +7664,70 @@ WITH-CASE, the sorting considers case as well."
          (/= dcst sorting-type)
          (/= dcst sorting-type)
          ;; This function moves to the beginning character of the "record" to
          ;; This function moves to the beginning character of the "record" to
          ;; be sorted.
          ;; be sorted.
-	 (if plain-list-p
-	     (lambda nil
-	       (if (org-at-item-p) t (goto-char (point-max))))
-	   (lambda nil
-	     (if (re-search-forward re nil t)
-		 (goto-char (match-beginning 0))
-	       (goto-char (point-max)))))
+	 (lambda nil
+	   (if (re-search-forward re nil t)
+	       (goto-char (match-beginning 0))
+	     (goto-char (point-max))))
          ;; This function moves to the last character of the "record" being
          ;; This function moves to the last character of the "record" being
          ;; sorted.
          ;; sorted.
-	 (if plain-list-p
-	     'org-end-of-item
-	   (lambda nil
-	     (save-match-data
-	       (condition-case nil
-		   (outline-forward-same-level 1)
-		 (error
-		  (goto-char (point-max)))))))
-
+	 (lambda nil
+	   (save-match-data
+	     (condition-case nil
+		 (outline-forward-same-level 1)
+	       (error
+		(goto-char (point-max))))))
          ;; This function returns the value that gets sorted against.
          ;; This function returns the value that gets sorted against.
-	 (if plain-list-p
-	     (lambda nil
-	       (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+")
-		 (cond
-		  ((= dcst ?n)
-		   (string-to-number (buffer-substring (match-end 0)
-						       (point-at-eol))))
-		  ((= dcst ?a)
-		   (buffer-substring (match-end 0) (point-at-eol)))
-		  ((= dcst ?t)
-		   (if (or (re-search-forward org-ts-regexp (point-at-eol) t)
-			   (re-search-forward org-ts-regexp-both
-					      (point-at-eol) t))
-		       (org-time-string-to-seconds (match-string 0))
-		     (org-float-time now)))
-		  ((= dcst ?f)
-		   (if getkey-func
-		       (progn
-			 (setq tmp (funcall getkey-func))
-			 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
-			 tmp)
-		     (error "Invalid key function `%s'" getkey-func)))
-		  (t (error "Invalid sorting type `%c'" sorting-type)))))
-	   (lambda nil
-	     (cond
-	      ((= dcst ?n)
-	       (if (looking-at org-complex-heading-regexp)
-		   (string-to-number (match-string 4))
-		 nil))
-	      ((= dcst ?a)
-	       (if (looking-at org-complex-heading-regexp)
-		   (funcall case-func (match-string 4))
-		 nil))
-	      ((= dcst ?t)
-	       (let ((end (save-excursion (outline-next-heading) (point))))
-		 (if (or (re-search-forward org-ts-regexp end t)
-			 (re-search-forward org-ts-regexp-both end t))
-		     (org-time-string-to-seconds (match-string 0))
-		   (org-float-time now))))
-	      ((= dcst ?c)
-	       (let ((end (save-excursion (outline-next-heading) (point))))
-		 (if (re-search-forward
-		      (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
-		      end t)
-		     (org-time-string-to-seconds (match-string 0))
-		   (org-float-time now))))
-	      ((= dcst ?s)
-	       (let ((end (save-excursion (outline-next-heading) (point))))
-		 (if (re-search-forward org-scheduled-time-regexp end t)
-		     (org-time-string-to-seconds (match-string 1))
-		   (org-float-time now))))
-	      ((= dcst ?d)
-	       (let ((end (save-excursion (outline-next-heading) (point))))
-		 (if (re-search-forward org-deadline-time-regexp end t)
-		     (org-time-string-to-seconds (match-string 1))
-		   (org-float-time now))))
-	      ((= dcst ?p)
-	       (if (re-search-forward org-priority-regexp (point-at-eol) t)
-		   (string-to-char (match-string 2))
-		 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
-		     (setq tmp (funcall getkey-func))
-		     (if (stringp tmp) (setq tmp (funcall case-func tmp)))
-		     tmp)
-		 (error "Invalid key function `%s'" getkey-func)))
-	      (t (error "Invalid sorting type `%c'" sorting-type)))))
+	 (lambda nil
+	   (cond
+	    ((= dcst ?n)
+	     (if (looking-at org-complex-heading-regexp)
+		 (string-to-number (match-string 4))
+	       nil))
+	    ((= dcst ?a)
+	     (if (looking-at org-complex-heading-regexp)
+		 (funcall case-func (match-string 4))
+	       nil))
+	    ((= dcst ?t)
+	     (let ((end (save-excursion (outline-next-heading) (point))))
+	       (if (or (re-search-forward org-ts-regexp end t)
+		       (re-search-forward org-ts-regexp-both end t))
+		   (org-time-string-to-seconds (match-string 0))
+		 (org-float-time now))))
+	    ((= dcst ?c)
+	     (let ((end (save-excursion (outline-next-heading) (point))))
+	       (if (re-search-forward
+		    (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
+		    end t)
+		   (org-time-string-to-seconds (match-string 0))
+		 (org-float-time now))))
+	    ((= dcst ?s)
+	     (let ((end (save-excursion (outline-next-heading) (point))))
+	       (if (re-search-forward org-scheduled-time-regexp end t)
+		   (org-time-string-to-seconds (match-string 1))
+		 (org-float-time now))))
+	    ((= dcst ?d)
+	     (let ((end (save-excursion (outline-next-heading) (point))))
+	       (if (re-search-forward org-deadline-time-regexp end t)
+		   (org-time-string-to-seconds (match-string 1))
+		 (org-float-time now))))
+	    ((= dcst ?p)
+	     (if (re-search-forward org-priority-regexp (point-at-eol) t)
+		 (string-to-char (match-string 2))
+	       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
+		   (setq tmp (funcall getkey-func))
+		   (if (stringp tmp) (setq tmp (funcall case-func tmp)))
+		   tmp)
+	       (error "Invalid key function `%s'" getkey-func)))
+	    (t (error "Invalid sorting type `%c'" sorting-type))))
          nil
          nil
          (cond
          (cond
           ((= dcst ?a) 'string<)
           ((= dcst ?a) 'string<)
@@ -11739,7 +11699,7 @@ This is done in the same way as adding a state change note."
 
 
 (defvar org-property-end-re)
 (defvar org-property-end-re)
 (defun org-add-log-setup (&optional purpose state prev-state
 (defun org-add-log-setup (&optional purpose state prev-state
-				    findpos how &optional extra)
+				    findpos how extra)
   "Set up the post command hook to take a note.
   "Set up the post command hook to take a note.
 If this is about to TODO state change, the new state is expected in STATE.
 If this is about to TODO state change, the new state is expected in STATE.
 When FINDPOS is non-nil, find the correct position for the note in
 When FINDPOS is non-nil, find the correct position for the note in
@@ -11888,8 +11848,8 @@ EXTRA is additional text that will be inserted into the notes buffer."
 	  (move-marker org-log-note-marker nil)
 	  (move-marker org-log-note-marker nil)
 	  (end-of-line 1)
 	  (end-of-line 1)
 	  (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
 	  (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
-	  (insert "- " (pop lines))
 	  (org-indent-line-function)
 	  (org-indent-line-function)
+	  (insert "- " (pop lines))
 	  (beginning-of-line 1)
 	  (beginning-of-line 1)
 	  (looking-at "[ \t]*")
 	  (looking-at "[ \t]*")
 	  (setq ind (concat (match-string 0) "  "))
 	  (setq ind (concat (match-string 0) "  "))
@@ -17247,12 +17207,12 @@ This command does many different things, depending on context:
 	  (org-footnote-at-definition-p))
 	  (org-footnote-at-definition-p))
       (call-interactively 'org-footnote-action))
       (call-interactively 'org-footnote-action))
      ((org-at-item-checkbox-p)
      ((org-at-item-checkbox-p)
+      (call-interactively 'org-list-repair)
       (call-interactively 'org-toggle-checkbox)
       (call-interactively 'org-toggle-checkbox)
       (org-list-send-list 'maybe))
       (org-list-send-list 'maybe))
      ((org-at-item-p)
      ((org-at-item-p)
-      (if arg
-	  (call-interactively 'org-toggle-checkbox)
-	(call-interactively 'org-maybe-renumber-ordered-list))
+      (call-interactively 'org-list-repair)
+      (when arg (call-interactively 'org-toggle-checkbox))
       (org-list-send-list 'maybe))
       (org-list-send-list 'maybe))
      ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
      ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
       ;; Dynamic block
       ;; Dynamic block
@@ -17375,21 +17335,21 @@ If the first line is normal text, add an item bullet to each line."
 	  ;; We already have items, de-itemize
 	  ;; We already have items, de-itemize
 	  (while (< (setq l (1+ l)) l2)
 	  (while (< (setq l (1+ l)) l2)
 	    (when (org-at-item-p)
 	    (when (org-at-item-p)
-	      (goto-char (match-beginning 2))
-	      (delete-region (match-beginning 2) (match-end 2))
-	      (and (looking-at "[ \t]+") (replace-match "")))
+	      (skip-chars-forward " \t")
+	      (delete-region (point) (match-end 0)))
 	    (beginning-of-line 2))
 	    (beginning-of-line 2))
 	(if (org-on-heading-p)
 	(if (org-on-heading-p)
 	    ;; Headings, convert to items
 	    ;; Headings, convert to items
 	    (while (< (setq l (1+ l)) l2)
 	    (while (< (setq l (1+ l)) l2)
 	      (if (looking-at org-outline-regexp)
 	      (if (looking-at org-outline-regexp)
-		  (replace-match "- " t t))
+		  (replace-match (org-list-bullet-string "-") t t))
 	      (beginning-of-line 2))
 	      (beginning-of-line 2))
 	  ;; normal lines, turn them into items
 	  ;; normal lines, turn them into items
 	  (while (< (setq l (1+ l)) l2)
 	  (while (< (setq l (1+ l)) l2)
 	    (unless (org-at-item-p)
 	    (unless (org-at-item-p)
 	      (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
 	      (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
-		  (replace-match "\\1- \\2")))
+		  (replace-match
+		   (concat "\\1" (org-list-bullet-string "-") "\\2"))))
 	    (beginning-of-line 2)))))))
 	    (beginning-of-line 2)))))))
 
 
 (defun org-toggle-heading (&optional nstars)
 (defun org-toggle-heading (&optional nstars)
@@ -18272,16 +18232,23 @@ really on, so that the block visually is on the match."
 	      (throw 'exit t)))
 	      (throw 'exit t)))
 	nil))))
 	nil))))
 
 
-(defun org-in-regexps-block-p (start-re end-re)
-  "Return t if the current point is between matches of START-RE and END-RE.
-This will also return to if point is on one of the two matches."
-  (interactive)
-  (let ((p (point)))
+(defun org-in-regexps-block-p (start-re end-re &optional bound)
+  "Returns t if the current point is between matches of START-RE and END-RE.
+This will also return t if point is on one of the two matches or
+in an unfinished block. END-RE can be a string or a form
+returning a string.
+
+An optional third argument bounds the search for START-RE. It
+defaults to previous heading or `point-min'."
+  (let ((pos (point))
+	(limit (or bound (save-excursion (outline-previous-heading)))))
     (save-excursion
     (save-excursion
-      (and (or (org-at-regexp-p start-re)
-	       (re-search-backward start-re nil t))
-	   (re-search-forward end-re nil t)
-	   (>= (point) p)))))
+      ;; we're on a block when point is on start-re...
+      (or (org-at-regexp-p start-re)
+	  ;; ... or start-re can be found above...
+	  (and (re-search-backward start-re limit t)
+	       ;; ... but no end-re between start-re and point.
+	       (not (re-search-forward (eval end-re) pos t)))))))
 
 
 (defun org-occur-in-agenda-files (regexp &optional nlines)
 (defun org-occur-in-agenda-files (regexp &optional nlines)
   "Call `multi-occur' with buffers for all agenda files."
   "Call `multi-occur' with buffers for all agenda files."
@@ -18561,57 +18528,87 @@ which make use of the date at the cursor."
     ;; Find the previous relevant line
     ;; Find the previous relevant line
     (beginning-of-line 1)
     (beginning-of-line 1)
     (cond
     (cond
+     ;; Comments
      ((looking-at "#") (setq column 0))
      ((looking-at "#") (setq column 0))
+     ;; Headings
      ((looking-at "\\*+ ") (setq column 0))
      ((looking-at "\\*+ ") (setq column 0))
+     ;; Drawers
      ((and (looking-at "[ \t]*:END:")
      ((and (looking-at "[ \t]*:END:")
 	   (save-excursion (re-search-backward org-drawer-regexp nil t)))
 	   (save-excursion (re-search-backward org-drawer-regexp nil t)))
       (save-excursion
       (save-excursion
 	(goto-char (1- (match-beginning 1)))
 	(goto-char (1- (match-beginning 1)))
 	(setq column (current-column))))
 	(setq column (current-column))))
-     ((and (looking-at "[ \t]+#\\+end_\\([a-z]+\\)")
+     ;; Special blocks
+     ((and (looking-at "[ \t]*#\\+end_\\([a-z]+\\)")
 	   (save-excursion
 	   (save-excursion
 	     (re-search-backward
 	     (re-search-backward
 	      (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
 	      (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
       (setq column (org-get-indentation (match-string 0))))
       (setq column (org-get-indentation (match-string 0))))
+     ((and (not (looking-at "[ \t]*#\\+begin_"))
+	   (org-in-regexps-block-p "^[ \t]*#\\+begin_" "[ \t]*#\\+end_"))
+      (save-excursion
+	(re-search-backward "^[ \t]*#\\+begin_\\([a-z]+\\)" nil t))
+      (setq column
+	    (if (equal (downcase (match-string 1)) "src")
+		;; src blocks: let `org-edit-src-exit' handle them
+		(org-get-indentation)
+	      (org-get-indentation (match-string 0)))))
+     ;; Lists
+     ((org-in-item-p)
+      (org-beginning-of-item)
+      (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
+      (setq bpos (match-beginning 1) tpos (match-end 0)
+	    bcol (progn (goto-char bpos) (current-column))
+	    tcol (progn (goto-char tpos) (current-column))
+	    bullet (match-string 1)
+	    bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
+      (if (> tcol (+ bcol org-description-max-indent))
+	  (setq tcol (+ bcol 5)))
+      (if (not itemp)
+	  (setq column tcol)
+	(beginning-of-line 1)
+	(goto-char pos)
+	(if (looking-at "\\S-")
+	    (progn
+	      (looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
+	      (setq bullet (match-string 1)
+		    btype (if (string-match "[0-9]" bullet) "n" bullet))
+	      (setq column (if (equal btype bullet-type) bcol tcol)))
+	  (setq column (org-get-indentation)))))
+     ;; This line has nothing special, look upside to get a clue about
+     ;; what to do.
      (t
      (t
       (beginning-of-line 0)
       (beginning-of-line 0)
       (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
       (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")
-		  (not (looking-at "[ \t]*:END:"))
-		  (not (looking-at org-drawer-regexp)))
-	(beginning-of-line 0))
+      		  (not (looking-at "[ \t]*:END:"))
+      		  (not (looking-at org-drawer-regexp)))
+      	(beginning-of-line 0))
       (cond
       (cond
+       ;; There was an heading above.
        ((looking-at "\\*+[ \t]+")
        ((looking-at "\\*+[ \t]+")
 	(if (not org-adapt-indentation)
 	(if (not org-adapt-indentation)
 	    (setq column 0)
 	    (setq column 0)
 	  (goto-char (match-end 0))
 	  (goto-char (match-end 0))
 	  (setq column (current-column))))
 	  (setq column (current-column))))
+       ;; A drawer had started and is unfinished: indent consequently.
        ((looking-at org-drawer-regexp)
        ((looking-at org-drawer-regexp)
-	  (goto-char (1- (match-beginning 1)))
-	  (setq column (current-column)))
+	(goto-char (1- (match-beginning 1)))
+	(setq column (current-column)))
+       ;; The drawer had ended: indent like its :END: line.
        ((looking-at "\\([ \t]*\\):END:")
        ((looking-at "\\([ \t]*\\):END:")
-	  (goto-char (match-end 1))
-	  (setq column (current-column)))
+	(goto-char (match-end 1))
+	(setq column (current-column)))
+       ;; There was a list that since ended: indent relatively to
+       ;; current heading.
        ((org-in-item-p)
        ((org-in-item-p)
-	(org-beginning-of-item)
-	(looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?")
-	(setq bpos (match-beginning 1) tpos (match-end 0)
-	      bcol (progn (goto-char bpos) (current-column))
-	      tcol (progn (goto-char tpos) (current-column))
-	      bullet (match-string 1)
-	      bullet-type (if (string-match "[0-9]" bullet) "n" bullet))
-	(if (> tcol (+ bcol org-description-max-indent))
-	    (setq tcol (+ bcol 5)))
-	(if (not itemp)
-	    (setq column tcol)
-	  (goto-char pos)
-	  (beginning-of-line 1)
-	  (if (looking-at "\\S-")
-	      (progn
-		(looking-at "[ \t]*\\(\\S-+\\)[ \t]*")
-		(setq bullet (match-string 1)
-		      btype (if (string-match "[0-9]" bullet) "n" bullet))
-		(setq column (if (equal btype bullet-type) bcol tcol)))
-	    (setq column (org-get-indentation)))))
+	(outline-previous-heading)
+	(if (and org-adapt-indentation
+		 (looking-at "\\*+[ \t]+"))
+	    (progn
+	      (goto-char (match-end 0))
+	      (setq column (current-column)))
+	  (setq column 0)))
+       ;; Else, nothing noticeable found: get indentation and go on.
        (t (setq column (org-get-indentation))))))
        (t (setq column (org-get-indentation))))))
     (goto-char pos)
     (goto-char pos)
     (if (<= (current-column) (current-indentation))
     (if (<= (current-column) (current-indentation))

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.