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) (defun org-indent-add-properties (beg end)
"Add indentation properties between BEG and END. "Add indentation properties between BEG and END.
Assumes that BEG is at the beginning of a line." Assumes that BEG is at the beginning of a line."
(when (or t org-indent-mode) (let* ((inhibit-modification-hooks t)
(let ((inhibit-modification-hooks t) (inlinetaskp (featurep 'org-inlinetask))
ov b e n level exit nstars) (get-real-level (lambda (pos lvl)
(with-silent-modifications (save-excursion
(save-excursion (goto-char pos)
(goto-char beg) (if (and inlinetaskp (org-inlinetask-in-task-p))
(while (not exit) (org-inlinetask-get-task-level)
(setq e end) lvl))))
(if (not (re-search-forward org-indent-outline-re nil t)) (b beg)
(setq e (point-max) exit t) (e end)
(setq e (match-beginning 0)) (level 0)
(if (>= e end) (setq exit t)) (n 0)
(setq level (- (match-end 0) (match-beginning 0) 1)) exit nstars)
(setq nstars (- (* (1- level) org-indent-indentation-per-level) (with-silent-modifications
(1- level))) (save-excursion
(add-text-properties (goto-char beg)
(point-at-bol) (point-at-eol) (while (not exit)
(list 'line-prefix (setq e end)
(aref org-indent-stars nstars) (if (not (re-search-forward org-indent-outline-re nil t))
'wrap-prefix (setq e (point-max) exit t)
(aref org-indent-strings (setq e (match-beginning 0))
(* level org-indent-indentation-per-level))))) (if (>= e end) (setq exit t))
(when (and b (> e b)) (unless (and inlinetaskp (org-inlinetask-in-task-p))
(add-text-properties (setq level (- (match-end 0) (match-beginning 0) 1)))
b e (list 'line-prefix (aref org-indent-strings n) (setq nstars (* (1- (funcall get-real-level e level))
'wrap-prefix (aref org-indent-strings n)))) (1- org-indent-indentation-per-level)))
(setq b (1+ (point-at-eol)) (add-text-properties
n (* (or level 0) org-indent-indentation-per-level)))))))) (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 () (defun org-indent-refresh-section ()
"Refresh indentation properties in the current outline 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 (when org-indent-mode
(let (beg end) (let (beg end)
(save-excursion (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 beg (point))
(setq end (or (save-excursion (or (outline-next-heading) (point))))) (setq end (or (save-excursion (or (outline-next-heading) (point)))))
(org-indent-remove-properties beg end) (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 (when org-indent-mode
(let ((beg (point)) (end limit)) (let ((beg (point)) (end limit))
(save-excursion (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)))) (setq beg (point))))
(org-indent-remove-properties beg end) (org-indent-remove-properties beg end)
(org-indent-add-properties beg end))) (org-indent-add-properties beg end)))