From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: [patch] better(?) indention for cdlatex-environment Date: Tue, 10 Feb 2015 12:28:53 +0100 Message-ID: <87386e0zuy.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YL90B-0004Kv-Af for emacs-orgmode@gnu.org; Tue, 10 Feb 2015 06:29:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YL908-0001on-3X for emacs-orgmode@gnu.org; Tue, 10 Feb 2015 06:29:11 -0500 Received: from plane.gmane.org ([80.91.229.3]:51419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YL907-0001oc-T6 for emacs-orgmode@gnu.org; Tue, 10 Feb 2015 06:29:08 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YL906-0005Az-Jm for emacs-orgmode@gnu.org; Tue, 10 Feb 2015 12:29:06 +0100 Received: from tsn109-201-154-147.dyn.nltelcom.net ([109.201.154.147]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Feb 2015 12:29:06 +0100 Received: from rasmus by tsn109-201-154-147.dyn.nltelcom.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Feb 2015 12:29:06 +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: 8bit Hi, Cdlatex environment inserted via org-cdlatex-environment-indent are pretty bad at getting the right indention. Consider: - concept :: a long description of concept | Where | is cursor. When I call org-cdlatex-environment-indent, I expect - concept :: a long description of concept \begin{equation} | \end{equation} But I get - concept :: a long description of concept \begin{equation} | \end{equation} This is because it determines the indention after the element is inserted at column zero. So the correct indention /is/ column zero but I wanted it to be part of the description. IOW I want Org to use the correct indention of when the time when I call the command. Note that I can still get an environment at column zero by issuing the command here: - concept :: a long description of concept | This patch just fixes this for org-cdlatex-indent-environment only, but maybe it's more correct to fix it in org-indent-region? —Rasmus -- . . . It begins of course with The Internet. A Net of Peers --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org.el-Change-indention-for-cdlatex-environments.patch >From 1a61c446fa1c92df9ba28a68d13188c296b8b718 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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 9bc67a8..e0a8842 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -18647,10 +18647,24 @@ 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)))) + (let* ((ind (org-get-indentation)) + (ind-str (make-string ind ? ))) + (cdlatex-environment environment item) + (let* ((element (org-element-at-point)) + (beg (org-element-property :begin element)) + (end (org-element-property :end element))) + ;; Make a rough estimate of the indention. We do this to + ;; because `org-indent-region' will always guess column zero, + ;; when dealing with e.g. description items. + (save-excursion + ;; Walk backwards. Otherwise we'd need markers. + (goto-char end) + (beginning-of-line) + (while (>= (point) beg) + (insert ind-str) + (forward-line -1))) + ;; indent cursor + (forward-char ind)))) ;;;; LaTeX fragments -- 2.3.0 --=-=-=--