From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [patch] better(?) indention for cdlatex-environment Date: Wed, 11 Feb 2015 12:26:34 +0100 Message-ID: <87lhk48z9x.fsf@gmx.us> References: <87386e0zuy.fsf@gmx.us> <87wq3pwg29.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLVRK-0002r5-Ih for emacs-orgmode@gnu.org; Wed, 11 Feb 2015 06:26:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLVRH-0002mi-Cp for emacs-orgmode@gnu.org; Wed, 11 Feb 2015 06:26:42 -0500 Received: from mout.gmx.net ([212.227.17.21]:62532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLVRH-0002lo-3v for emacs-orgmode@gnu.org; Wed, 11 Feb 2015 06:26:39 -0500 Received: from x200s ([109.201.154.208]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0LeiJ8-1Xp8M60RHq-00qPNZ for ; Wed, 11 Feb 2015 12:26:36 +0100 In-Reply-To: <87wq3pwg29.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 10 Feb 2015 23:35:26 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Nicolas Goaziou writes: > You can get real indentation by indenting a new line first. What about > the following? > > (org-return-indent) Indeed that this the trick. The attached patch seems to work nicely and takes care of the corner cases I could think of. I now get the following (desirable) behavior - key :: foo | bar baz # insert latex-environment with cdlatex - key :: foo | bar \begin{ENV} whatever \end{ENV} baz Here's another case p1 - item | item p2 # insert latex-environment with cdlatex p1 - item item \begin{equation} \label{eq:9} =20=20=20 \end{equation} And more... Behavior is better now. To improve further I'd need to change cdlatex.el and last time I tried it was ignored... =E2=80=94Rasmus --=20 I feel emotional landscapes they puzzle me --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org.el-Change-indention-for-cdlatex-environments.patch >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 --=-=-=--