emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [patch] better(?) indention for cdlatex-environment
Date: Thu, 12 Feb 2015 00:40:57 +0100	[thread overview]
Message-ID: <87mw4kyq2e.fsf@gmx.us> (raw)
In-Reply-To: <87fvacw2jv.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Wed, 11 Feb 2015 22:39:32 +0100")

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

Hi,

Thanks for the comments!

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> I don't see how it is desirable. The logical behaviour is to split the
> line, unless, of course, docstring clearly specifies this.

I don't feel strongly about it.  Anyway, I like this better.  Cdlatex is,
um, "opinionated" about is insertion of newlines.

>> +  ;; TODO: Cleanup if quit.  Unfortunately `cdlatex-environment'
>> +  ;; always return nil.
>
> What do you want to clean up? In what situations? Can't `unwind-protect'
> help you?

cdlatex-environment always return nil.  I would have to analyze if
something got inserted "manually".  IOW, I don't have the name of the
environment, and cdlatex-environment returns nil if I press C-g and if I
select and environment.  I don't know how to distinguish the cases.

> Anyway, why bother?

Newlines is very hard to get right with cdlatex.  Unintended newlines is a
bug.

The attached patch works "as expected" at all locations marked with "|",
but not the one marked with "/" and "\", which lead to the next question.
| - i1 | i2 |
/ - i3 |
\

I expect indentation at all points not at bol.

At "\" (org-get-indentation) returns 2 even though I'm at bol.  Why?

Regarding "/".  In the following i2 is indented meaning that
(org-get-indentation) becomes 2.  Is that a feature?

(with-temp-buffer
  (org-mode)
  (insert "\n- i1\n- i2")
  (beginning-of-line)
  (org-return-indent)
  (buffer-string))

—Rasmus

-- 
to err is human. To screw up 10⁶ times per second, you need a computer

[-- 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: 2121 bytes --]

From c43d7bb49a047b91a88327ce016b17383697376d 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 | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 64b546f..682d27a 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))))
+  (let ((non-blank-eolp
+	 (save-excursion
+	   (and (not (save-excursion
+		       (skip-chars-backward " \t")
+		       (bolp)))
+		(progn (skip-chars-forward " \t") (eolp)))))
+	(ind (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))))
 
 \f
 ;;;; LaTeX fragments
-- 
2.3.0


  reply	other threads:[~2015-02-11 23:41 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mw4kyq2e.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).