From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [patch] better(?) indention for cdlatex-environment Date: Thu, 12 Feb 2015 00:40:57 +0100 Message-ID: <87mw4kyq2e.fsf@gmx.us> References: <87386e0zuy.fsf@gmx.us> <87wq3pwg29.fsf@nicolasgoaziou.fr> <87lhk48z9x.fsf@gmx.us> <87fvacw2jv.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLgtz-0008GP-CA for emacs-orgmode@gnu.org; Wed, 11 Feb 2015 18:41:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLgtw-0000kG-3w for emacs-orgmode@gnu.org; Wed, 11 Feb 2015 18:41:03 -0500 Received: from mout.gmx.net ([212.227.15.19]:63536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLgtv-0000k8-QQ for emacs-orgmode@gnu.org; Wed, 11 Feb 2015 18:41:00 -0500 Received: from W530 ([46.166.186.250]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MbPLI-1Y57zK3aeS-00ImGm for ; Thu, 12 Feb 2015 00:40:59 +0100 In-Reply-To: <87fvacw2jv.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Wed, 11 Feb 2015 22:39:32 +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 Hi, Thanks for the comments! Nicolas Goaziou 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)) =E2=80=94Rasmus --=20 to err is human. To screw up 10=E2=81=B6 times per second, you need a compu= ter --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org.el-Change-indention-for-cdlatex-environments.patch >From c43d7bb49a047b91a88327ce016b17383697376d 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..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 --=-=-=--