From 85591ffcbfeb566045f41a801d7ad3632b55c653 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 6 Nov 2010 15:48:38 +0100 Subject: [PATCH] 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. --- lisp/org-indent.el | 81 +++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/lisp/org-indent.el b/lisp/org-indent.el index 39ba445eb..e2b28ccda 100644 --- a/lisp/org-indent.el +++ b/lisp/org-indent.el @@ -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)))