From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [patch] better(?) indention for cdlatex-environment Date: Tue, 17 Feb 2015 09:51:08 +0100 Message-ID: <87egpox6o3.fsf@nicolasgoaziou.fr> 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> <87twypgwt5.fsf@gmx.us> <87pp9cnq9w.fsf@nicolasgoaziou.fr> <874mqoc9zf.fsf@gmx.us> <87lhjzo611.fsf@nicolasgoaziou.fr> <87wq3hgyie.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNdr9-0005Ms-F9 for emacs-orgmode@gnu.org; Tue, 17 Feb 2015 03:50:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNdqz-00049x-SD for emacs-orgmode@gnu.org; Tue, 17 Feb 2015 03:50:11 -0500 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:56520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNdqz-000487-8w for emacs-orgmode@gnu.org; Tue, 17 Feb 2015 03:50:01 -0500 In-Reply-To: <87wq3hgyie.fsf@gmx.us> (rasmus@gmx.us's message of "Tue, 17 Feb 2015 01:41:45 +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: Rasmus Cc: emacs-orgmode@gnu.org Rasmus writes: > + ;; cdlatex-environment always return nil. Therefore, capture output > + ;; first and determine if an environment was selected. > + (let* ((beg (point-marker)) > + (end (copy-marker (point) t)) > + (env (org-trim > + (or (progn (ignore-errors (cdlatex-environment environment item)) > + (delete-and-extract-region beg end)) > + "")))) The `or' is not necessary: `delete-and-extract-region' already returns the empty string when markers don't move. (env (progn (ignore-errors (cdlatex-environment environment item)) (org-trim (delete-and-extract-region beg end))) > + (when (org-string-nw-p env) > + ;; Get indentation of next line unless at column 0. > + (let ((ind (if (bolp) 0 > + (save-excursion > + (org-return-indent) > + (prog1 (org-get-indentation) > + (when (and (skip-chars-forward " \t") (eolp)) > + (delete-region beg (point))))))) Nitpick (when (progn (skip-chars-forward " \") (eolp)) ...) since you're not really interested in the return value of `skip-chars-forward' (which is always non-nil). > + (bol (and (skip-chars-backward " \t") (bolp)))) Ditto. > + ;; Insert a newline before environment unless at column zero > + ;; to "escape" the current line. Insert a newline if > + ;; something is one the same line as \end{ENVIRONMENT}. > + (insert (concat (unless bol "\n") > + env > + (and (skip-chars-forward " \t") (not (eolp)) "\n"))) Ditto. > + (unless (zerop ind) > + (let* ((element (org-element-at-point)) > + (elm-beg (org-element-property :begin element)) > + (elm-end (copy-marker > + (save-excursion > + (goto-char (org-element-property :end element)) > + (skip-chars-backward " \t\n\r") > + (point))))) > + (save-excursion > + (goto-char elm-beg) > + (beginning-of-line) > + (while (<= (point) elm-end) > + (org-indent-to-column ind) > + (forward-line))) > + (set-marker elm-end nil))))) I don't think you need `org-element-at-point' at all. You already have BEG and END markers available. I didn't test it, but this should be enough to indent the environment. Also you shouldn't apply `org-indent-to-column' when line is empty. Regards,