From 85e6e454412c20b13d10e3d2b15dd3f9cb7e3a6b 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 | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 59b245a..eaa9084 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -18645,12 +18645,47 @@ Revert to the normal definition outside of these fragments." (call-interactively (key-binding (vector last-input-event)))))) (defun org-cdlatex-environment-indent (&optional environment item) - "Execute `cdlatex-environment' and indent the inserted environment." + "Execute `cdlatex-environment' and indent the inserted environment. + +The inserted environment is indented to current indentation +unless point is at the beginning of the line in which case no +indentation occurs." (interactive) - (cdlatex-environment environment item) - (let ((element (org-element-at-point))) - (org-indent-region (org-element-property :begin element) - (org-element-property :end element)))) + (let ((non-blank-eolp + (save-excursion + (and (not (save-excursion + (skip-chars-backward " \t") + (bolp))) + (progn (skip-chars-forward " \t") (eolp))))) + (ind (if (bolp) 0 + (save-excursion + (unless (and (bolp) + (save-excursion + (skip-chars-forward " \t") + (eolp))) + (org-return-indent)) + (org-get-indentation))))) + ;; Skip forward to next bol to avoid extra newline from + ;; cdlatex-environment. + (when non-blank-eolp (forward-line 1) (beginning-of-line)) + (cdlatex-environment environment item) + ;; Indent new latex-environment. + (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