>From a19cfa0f3eb22c4b3a3e3bd313626fb90a9affce Mon Sep 17 00:00:00 2001 From: rasmus Date: Tue, 10 Feb 2015 12:02:59 +0100 Subject: [PATCH] org.el: Change indention for cdlatex environments * org.el (org-cdlatex-environment-indent): Use different indent algorithm based on content above the new latex-environment. --- lisp/org.el | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 64b546f..11fd3de 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -18647,10 +18647,40 @@ Revert to the normal definition outside of these fragments." (defun org-cdlatex-environment-indent (&optional environment item) "Execute `cdlatex-environment' and indent the inserted environment." (interactive) - (cdlatex-environment environment item) - (let ((element (org-element-at-point))) - (org-indent-region (org-element-property :begin element) - (org-element-property :end element)))) + ;; TODO: Cleanup if quit. Unfortunately `cdlatex-environment' + ;; always return nil. + (let* (;; Insert environment on next line unless at beginning of line. + (eol + (unless (<= (point) + (save-excursion (beginning-of-line) + (org-skip-whitespace) + (point))) + (end-of-line) t)) + ;; Get correct indention for next line. + (ind (if eol (save-excursion + (org-return-indent) + (prog1 (org-get-indentation) + (unless (or (eobp) (looking-at "[^ \t]")) + (kill-whole-line)))) + (org-get-indentation)))) + (cdlatex-environment environment item) + ;; Indent new latex-environment to correct indention. + (unless (zerop ind) + (let* ((element (org-element-at-point)) + (beg (org-element-property :begin element)) + (end (copy-marker + (save-excursion + (goto-char (org-element-property :end element)) + (skip-chars-backward " \t\n\r") + (point))))) + (save-excursion + (goto-char beg) + (beginning-of-line) + (while (<= (point) end) + (org-indent-to-column ind) + (forward-line 1))) + (set-marker end nil)) + (forward-char ind)))) ;;;; LaTeX fragments -- 2.3.0