Fix indentation of text after an inline task in indent-mode

* org-inlinetask.el (org-inlinetask-get-task-level): new function
* org-indent.el (org-indent-add-properties): find true level of indentation wrt inline tasks.
This commit is contained in:
Nicolas Goaziou 2010-11-06 15:48:38 +01:00
parent 9be9f727f8
commit 85591ffcbf
1 changed files with 51 additions and 30 deletions

View File

@ -219,34 +219,47 @@ 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 ((inhibit-modification-hooks t)
ov b e n level 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))
(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)))))))
(defun org-indent-refresh-section ()
"Refresh indentation properties in the current outline section.
@ -255,7 +268,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)
@ -268,7 +285,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)))