From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [patch] better(?) indention for cdlatex-environment Date: Sat, 14 Feb 2015 01:29:26 +0100 Message-ID: <87twypgwt5.fsf@gmx.us> References: <87386e0zuy.fsf@gmx.us> <87wq3pwg29.fsf@nicolasgoaziou.fr> <87lhk48z9x.fsf@gmx.us> <87fvacw2jv.fsf@nicolasgoaziou.fr> <87mw4kyq2e.fsf@gmx.us> <87fva9tqdj.fsf@nicolasgoaziou.fr> <873869h0cd.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMQc9-00064U-31 for emacs-orgmode@gnu.org; Fri, 13 Feb 2015 19:29:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMQc3-0007CK-WE for emacs-orgmode@gnu.org; Fri, 13 Feb 2015 19:29:41 -0500 Received: from plane.gmane.org ([80.91.229.3]:50241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMQc3-0007CC-LN for emacs-orgmode@gnu.org; Fri, 13 Feb 2015 19:29:35 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YMQc2-00071x-3a for emacs-orgmode@gnu.org; Sat, 14 Feb 2015 01:29:34 +0100 Received: from 102.201.133.37.dynamic.jazztel.es ([37.133.201.102]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 14 Feb 2015 01:29:34 +0100 Received: from rasmus by 102.201.133.37.dynamic.jazztel.es with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 14 Feb 2015 01:29:34 +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 Rasmus writes: > Hi, > > Nicolas Goaziou writes: > >>> I don't feel strongly about it. Anyway, I like this better. Cdlatex is, >>> um, "opinionated" about is insertion of newlines. >> >> I still think it is better to split line. Your behaviour just requires >> a C-e before calling the function. > > I agree that the "simpler" approach is better. That's what I mean by the > "this" above. This patch applies indentation unless at BOL in which case it stays at BOL. The rest is basically just to work with cdlatex and not insert too many blank lines. It's still quicky, but these quirks seem to be cdlatex quirks. I wonder, are there any commands to merge two elements buffer-undo-list into one? 'Cause ATM it takes two undo-presses to undo an environment insert via this command. —Rasmus -- El Rey ha muerto. ¡Larga vida al Rey! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org.el-Change-indention-for-cdlatex-environments.patch >From 85e6e454412c20b13d10e3d2b15dd3f9cb7e3a6b 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 | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 59b245a..eaa9084 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -18645,12 +18645,47 @@ Revert to the normal definition outside of these fragments." (call-interactively (key-binding (vector last-input-event)))))) (defun org-cdlatex-environment-indent (&optional environment item) - "Execute `cdlatex-environment' and indent the inserted environment." + "Execute `cdlatex-environment' and indent the inserted environment. + +The inserted environment is indented to current indentation +unless point is at the beginning of the line in which case no +indentation occurs." (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 (if (bolp) 0 + (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 --=-=-=--