emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] better(?) indention for cdlatex-environment
@ 2015-02-10 11:28 Rasmus
  2015-02-10 12:27 ` Rasmus
  2015-02-10 22:35 ` Nicolas Goaziou
  0 siblings, 2 replies; 32+ messages in thread
From: Rasmus @ 2015-02-10 11:28 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Change-indention-for-cdlatex-environments.patch --]
[-- Type: text/x-diff, Size: 1696 bytes --]

From 1a61c446fa1c92df9ba28a68d13188c296b8b718 Mon Sep 17 00:00:00 2001
From: rasmus <rasmus@gmx.us>
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))))
 
 \f
 ;;;; LaTeX fragments
-- 
2.3.0


^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2015-02-20 11:16 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10 11:28 [patch] better(?) indention for cdlatex-environment Rasmus
2015-02-10 12:27 ` Rasmus
2015-02-10 22:35 ` Nicolas Goaziou
2015-02-11 11:26   ` Rasmus
2015-02-11 21:39     ` Nicolas Goaziou
2015-02-11 23:40       ` Rasmus
2015-02-13 22:10         ` Nicolas Goaziou
2015-02-13 23:13           ` Rasmus
2015-02-14  0:29             ` Rasmus
2015-02-14 21:20               ` Nicolas Goaziou
2015-02-15  0:08                 ` Rasmus
2015-02-15  9:52                   ` Nicolas Goaziou
2015-02-17  0:41                     ` Rasmus
2015-02-17  8:51                       ` Nicolas Goaziou
2015-02-17 21:19                         ` Rasmus
2015-02-18  0:39                           ` Nicolas Goaziou
2015-02-18  1:06                             ` Rasmus
2015-02-19  0:22                             ` Rasmus
2015-02-19 23:11                               ` Rasmus
2015-02-19 23:23                                 ` Nicolas Goaziou
2015-02-19 23:32                                   ` Rasmus
2015-02-20  0:13                                     ` Nicolas Goaziou
2015-02-20  0:38                                       ` Rasmus
2015-02-20 10:16                                         ` Nicolas Goaziou
2015-02-20 10:35                                           ` Rasmus
2015-02-20 10:40                                             ` Nicolas Goaziou
2015-02-20 10:43                                               ` Rasmus
2015-02-20 10:49                                                 ` Nicolas Goaziou
2015-02-20 10:54                                                   ` Rasmus
2015-02-20 11:17                                                     ` Nicolas Goaziou
2015-02-20 10:50                                                 ` Rasmus
2015-02-14  1:10             ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).