[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [patch] better(?) indention for cdlatex-environment
From: |
Rasmus |
Subject: |
Re: [O] [patch] better(?) indention for cdlatex-environment |
Date: |
Thu, 12 Feb 2015 00:40:57 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Hi,
Thanks for the comments!
Nicolas Goaziou <address@hidden> 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
>From c43d7bb49a047b91a88327ce016b17383697376d Mon Sep 17 00:00:00 2001
From: rasmus <address@hidden>
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))))
;;;; LaTeX fragments
--
2.3.0
- [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/10
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/10
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/10
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/11
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/11
- Re: [O] [patch] better(?) indention for cdlatex-environment,
Rasmus <=
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/13
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/13
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/13
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/14
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/14
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/15
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/16
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/17
- Re: [O] [patch] better(?) indention for cdlatex-environment, Rasmus, 2015/02/17
- Re: [O] [patch] better(?) indention for cdlatex-environment, Nicolas Goaziou, 2015/02/17