From mboxrd@z Thu Jan 1 00:00:00 1970 From: Federico Beffa Subject: [PATCH] org.el: make org-paragraph-fill ignore \[...\] regions starting and ending a line Date: Thu, 7 Aug 2014 15:56:13 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFOAy-0001cm-LN for emacs-orgmode@gnu.org; Thu, 07 Aug 2014 09:56:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFOAx-0003Io-M5 for emacs-orgmode@gnu.org; Thu, 07 Aug 2014 09:56:16 -0400 Received: from mail-la0-x22e.google.com ([2a00:1450:4010:c03::22e]:41959) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFOAx-0003IS-Dz for emacs-orgmode@gnu.org; Thu, 07 Aug 2014 09:56:15 -0400 Received: by mail-la0-f46.google.com with SMTP id b8so3554690lan.19 for ; Thu, 07 Aug 2014 06:56:13 -0700 (PDT) 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 > Attached you find a patch with the proposed modification. I would > greatly appreciate if you could consider it for inclusion in org-mode > and provide feedback. Here a more lispy version of the function `org-fill-paragraph-construct-regions' used in the patch.I guess it could be more appealing to people on this list :-) (defun org-fill-paragraph-construct-regions (lbl dmrl) "Construct paragraph regions to be filled. This function takes an ordered list LBL with the positions of org `line-break' objects and an ordered list DMRL with the start and end positions of \\=\\[...\\=\\] LaTeX macros beginning and ending a line. It returns a list of the form ((r1-beg r1-end) ... (rN-beg rN-end)) with the start end end positions of the paragraph regions to be filled." (let ((lbl-len (length lbl))) ; compute only once length of lbl (or ;; elementary case 1: no display math regions and 2 entries in lbl (and (not dmrl) (eq lbl-len 2) (list lbl)) ;; elementary case 2: 1 remaining line break (end of paragraph) and ;; 1 remaining display math region. (and (eq (length dmrl) 1) (eq lbl-len 1) (list (list (nth 1 dmrl) (car lbl)))) ;; remove line-breaks within display math regions (and dmrl (>= (nth 1 lbl) (caar dmrl)) (<= (nth 1 lbl) (nth 1 (car dmrl))) (if (> lbl-len 2) (org-fill-paragraph-construct-regions2 (cons (car lbl) (cddr lbl)) dmrl) ;; a displayed math region finished the paragraph (org-fill-paragraph-construct-regions2 (cons (car lbl) (list (caar dmrl))) nil))) ;; non elementary cases: (if (and dmrl (> (nth 1 lbl) (caar dmrl))) (cons (list (car lbl) (caar dmrl)) (org-fill-paragraph-construct-regions2 (cons (nth 1 (car dmrl)) (cdr lbl)) (cdr dmrl))) (cons (list (car lbl) (nth 1 lbl)) (org-fill-paragraph-construct-regions2 (cdr lbl) dmrl)))))) Regards, Federico