Merge changes from emacs-23 branch
[bpt/emacs.git] / lisp / org / org-indent.el
index d88688d..a177a6f 100644 (file)
@@ -4,7 +4,7 @@
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.01
+;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
 (eval-when-compile
   (require 'cl))
 
+(defvar org-inlinetask-min-level)
+(declare-function org-inlinetask-get-task-level "org-inlinetask" ())
+(declare-function org-inlinetask-in-task-p "org-inlinetask" ())
+
 (defgroup org-indent nil
   "Options concerning dynamic virtual outline indentation."
   :tag "Org Indent"
@@ -135,11 +139,11 @@ FIXME:  How to update when broken?"
    ((org-bound-and-true-p org-inhibit-startup)
     (setq org-indent-mode nil))
    ((and org-indent-mode (featurep 'xemacs))
-    (message "org-indent-mode does not work in XEmacs - refused to turn it on")
+    (message "org-indent-mode does not work in XEmacs - refusing to turn it on")
     (setq org-indent-mode nil))
    ((and org-indent-mode
         (not (org-version-check "23.1.50" "Org Indent mode" :predicate)))
-    (message "org-indent-mode is can crash Emacs 23.1 - refused to turn it on!")
+    (message "org-indent-mode can crash Emacs 23.1 - refusing to turn it on!")
     (ding)
     (sit-for 1)
     (setq org-indent-mode nil))
@@ -203,8 +207,9 @@ useful to make it ever so slightly different."
 
 (defun org-indent-remove-properties (beg end)
   "Remove indentations between BEG and END."
-  (org-unmodified
-   (remove-text-properties beg end '(line-prefix nil wrap-prefix nil))))
+  (let ((inhibit-modification-hooks t))
+    (with-silent-modifications
+      (remove-text-properties beg end '(line-prefix nil wrap-prefix nil)))))
 
 (defun org-indent-remove-properties-from-string (string)
   "Remove indentations between BEG and END."
@@ -218,34 +223,49 @@ useful to make it ever so slightly different."
 (defun org-indent-add-properties (beg end)
   "Add indentation properties between BEG and END.
 Assumes that BEG is at the beginning of a line."
-  (when (or t org-indent-mode)
-    (let (ov b e n level exit nstars)
-      (org-unmodified
-       (save-excursion
-        (goto-char beg)
-        (while (not exit)
-          (setq e end)
-          (if (not (re-search-forward org-indent-outline-re nil t))
-              (setq e (point-max) exit t)
-            (setq e (match-beginning 0))
-            (if (>= e end) (setq exit t))
-            (setq level (- (match-end 0) (match-beginning 0) 1))
-            (setq nstars (- (* (1- level) org-indent-indentation-per-level)
-                            (1- level)))
-            (add-text-properties
-             (point-at-bol) (point-at-eol)
-             (list 'line-prefix
-                   (aref org-indent-stars nstars)
-                   'wrap-prefix
-                   (aref org-indent-strings
-                         (* level org-indent-indentation-per-level)))))
-          (when (and b (> e b))
-            (add-text-properties
-             b  e (list 'line-prefix (aref org-indent-strings n)
-                        'wrap-prefix (aref org-indent-strings n))))
-          (setq b (1+ (point-at-eol))
-                n (* (or level 0) org-indent-indentation-per-level))))))))
+  (let* ((inhibit-modification-hooks t)
+        (inlinetaskp (featurep 'org-inlinetask))
+        (get-real-level (lambda (pos lvl)
+                          (save-excursion
+                            (goto-char pos)
+                            (if (and inlinetaskp (org-inlinetask-in-task-p))
+                                (org-inlinetask-get-task-level)
+                              lvl))))
+        (b beg)
+        (e end)
+        (level 0)
+        (n 0)
+        exit nstars)
+    (with-silent-modifications
+      (save-excursion
+       (goto-char beg)
+       (while (not exit)
+         (setq e end)
+         (if (not (re-search-forward org-indent-outline-re nil t))
+             (setq e (point-max) exit t)
+           (setq e (match-beginning 0))
+           (if (>= e end) (setq exit t))
+           (unless (and inlinetaskp (org-inlinetask-in-task-p))
+             (setq level (- (match-end 0) (match-beginning 0) 1)))
+           (setq nstars (* (1- (funcall get-real-level e level))
+                           (1- org-indent-indentation-per-level)))
+           (add-text-properties
+            (point-at-bol) (point-at-eol)
+            (list 'line-prefix
+                  (aref org-indent-stars nstars)
+                  'wrap-prefix
+                  (aref org-indent-strings
+                        (* (funcall get-real-level e level)
+                           org-indent-indentation-per-level)))))
+         (when (> e b)
+           (add-text-properties
+            b  e (list 'line-prefix (aref org-indent-strings n)
+                       'wrap-prefix (aref org-indent-strings n))))
+         (setq b (1+ (point-at-eol))
+               n (* (funcall get-real-level b level)
+                    org-indent-indentation-per-level)))))))
 
+(defvar org-inlinetask-min-level)
 (defun org-indent-refresh-section ()
   "Refresh indentation properties in the current outline section.
 Point is assumed to be at the beginning of a headline."
@@ -253,7 +273,11 @@ Point is assumed to be at the beginning of a headline."
   (when org-indent-mode
     (let (beg end)
       (save-excursion
-       (when (ignore-errors (org-back-to-heading))
+       (when (ignore-errors (let ((outline-regexp (format "\\*\\{1,%s\\}[ \t]+"
+                               (if (featurep 'org-inlinetask)
+                                   (1- org-inlinetask-min-level)
+                                 ""))))
+                              (org-back-to-heading)))
          (setq beg (point))
          (setq end (or (save-excursion (or (outline-next-heading) (point)))))
          (org-indent-remove-properties beg end)
@@ -266,7 +290,11 @@ Point is assumed to be at the beginning of a headline."
   (when org-indent-mode
     (let ((beg (point)) (end limit))
       (save-excursion
-       (and (ignore-errors (org-back-to-heading t))
+       (and (ignore-errors (let ((outline-regexp (format "\\*\\{1,%s\\}[ \t]+"
+                               (if (featurep 'org-inlinetask)
+                                   (1- org-inlinetask-min-level)
+                                 ""))))
+                             (org-back-to-heading)))
             (setq beg (point))))
       (org-indent-remove-properties beg end)
       (org-indent-add-properties beg end)))