From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Christ Subject: Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks Date: Thu, 12 Nov 2015 20:23:00 +0100 Message-ID: References: <8737wdssfe.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwxSx-0006XJ-W1 for emacs-orgmode@gnu.org; Thu, 12 Nov 2015 14:23:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwxSt-00026d-V8 for emacs-orgmode@gnu.org; Thu, 12 Nov 2015 14:23:27 -0500 Received: from plane.gmane.org ([80.91.229.3]:49198) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwxSt-00026Z-Nq for emacs-orgmode@gnu.org; Thu, 12 Nov 2015 14:23:23 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZwxSi-0000S8-Tr for emacs-orgmode@gnu.org; Thu, 12 Nov 2015 20:23:12 +0100 Received: from ip5f591fba.dynamic.kabel-deutschland.de ([95.89.31.186]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 12 Nov 2015 20:23:12 +0100 Received: from rudolfo.christ by ip5f591fba.dynamic.kabel-deutschland.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 12 Nov 2015 20:23:12 +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 Hi Aaron, thanks for the tip with (org-element-property :value X). I also got rid of the let*. Actually, the previous patch is buggy and I've thought had submitted another patch to fix that. But unfortunately it seems it got lost in the interwebs. Best wishes, Sebastian --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-extra.el-Fix-filtering-of-latex-header-blocks.patch >From a814380158de6185747975848533e3bd6e675afd Mon Sep 17 00:00:00 2001 From: Sebastian Christ Date: Thu, 12 Nov 2015 19:23:05 +0100 Subject: [PATCH] ox-extra.el: Fix filtering of latex header blocks * contrib/lisp/ox-extra.el (org-latex-header-blocks-filter): Use `org-element' API to find beginning, end and contents of latex header blocks. `org-latex-header-blocks-filter' still called `org-edit-src-find-region-and-lang' and raised an undefined function error because the funtion was removed from org-mode. This is fixed by determining the begin and end of the latex block via `org-element'. --- contrib/lisp/ox-extra.el | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el index e6d45cc..232f623 100644 --- a/contrib/lisp/ox-extra.el +++ b/contrib/lisp/ox-extra.el @@ -60,7 +60,7 @@ (defun org-latex-header-blocks-filter (backend) (when (org-export-derived-backend-p backend 'latex) - (let ((positions + (let ((blocks (org-element-map (org-element-parse-buffer 'greater-element nil) 'export-block (lambda (block) (when (and (string= (org-element-property :type block) "LATEX") @@ -69,23 +69,18 @@ "yes")) (list (org-element-property :begin block) (org-element-property :end block) - (org-element-property :post-affiliated block))))))) - (mapc (lambda (pos) - (goto-char (nth 2 pos)) - (destructuring-bind - (beg end &rest ignore) - (org-edit-src-find-region-and-lang) - (let ((contents-lines (split-string - (buffer-substring-no-properties beg end) - "\n"))) - (delete-region (nth 0 pos) (nth 1 pos)) - (dolist (line contents-lines) - (insert (concat "#+latex_header: " - (replace-regexp-in-string "\\` *" "" line) - "\n")))))) - ;; go in reverse, to avoid wrecking the numeric positions + (org-element-property :value block))))))) + (mapc (lambda (block) + (goto-char (nth 0 block)) + (let ((contents-lines (split-string (nth 2 block) "\n" t))) + (delete-region (nth 0 block) (nth 1 block)) + (dolist (line contents-lines) + (insert (concat "#+latex_header: " + (replace-regexp-in-string "\\` *" "" line) + "\n"))))) + ;; go in reverse, to avoid wrecking the numeric blocks ;; earlier in the file - (reverse positions))))) + (reverse blocks))))) ;; During export headlines which have the "ignore" tag are removed -- 2.6.3 --=-=-=--