* [PATCH] ox-extra.el: Fix filtering of latex header blocks
@ 2015-10-09 16:13 Sebastian Christ
2015-10-11 8:21 ` Sebastian Christ
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Sebastian Christ @ 2015-10-09 16:13 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 211 bytes --]
Hi group,
I'd like to provide a patch to
ox-extra.el. `org-latex-header-blocks-filter' still calls
`org-edit-src-find-region-and-lang' and raises therefore an undefined
function error.
Best wishes,
Sebastian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-extra.el-Fix-filtering-of-latex-header-blocks.patch --]
[-- Type: text/x-patch, Size: 2358 bytes --]
From 34b76e06bda5739e433c95b451915c8b804a1733 Mon Sep 17 00:00:00 2001
From: Sebastian Christ <rudolfo.christ@gmail.com>
Date: Fri, 9 Oct 2015 17:37:39 +0200
Subject: [PATCH] ox-extra.el: Fix filtering of latex header blocks
* ox-extra.el (org-latex-header-blocks-filter): Use `org-element' API to
find begin and end 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'.
---
| 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
--git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el
index e6d45cc..bb838fc 100644
--- a/contrib/lisp/ox-extra.el
+++ b/contrib/lisp/ox-extra.el
@@ -71,18 +71,22 @@
(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"))))))
+ (let* ((beg (third pos))
+ (end (second pos))
+ (post-affiliated (first pos))
+ (contents-lines
+ (cdr (butlast
+ (split-string
+ (buffer-substring-no-properties post-affiliated
+ end)
+ "\n")
+ 2))))
+ (goto-char beg)
+ (delete-region beg end)
+ (dolist (line contents-lines)
+ (insert (concat "#+latex_header: "
+ (replace-regexp-in-string "\\` *" "" line)
+ "\n")))))
;; go in reverse, to avoid wrecking the numeric positions
;; earlier in the file
(reverse positions)))))
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-10-09 16:13 [PATCH] ox-extra.el: Fix filtering of latex header blocks Sebastian Christ
@ 2015-10-11 8:21 ` Sebastian Christ
2015-11-09 6:30 ` Kyle Meyer
2015-11-10 16:57 ` Aaron Ecay
2 siblings, 0 replies; 9+ messages in thread
From: Sebastian Christ @ 2015-10-11 8:21 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 212 bytes --]
And of course,
the previous patch contains a bug. I should have tested it with multiple
latex header blocks. Sorry for the inconvenience. The attached patch
should (hopefully) fix that.
Best wishes,
Sebastian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-extra.el-Fix-filtering-of-latex-header-blocks.patch --]
[-- Type: text/x-patch, Size: 2653 bytes --]
From d9890ab84c92ec60e76913d2a1b3967353819500 Mon Sep 17 00:00:00 2001
From: Sebastian Christ <rudolfo.christ@gmail.com>
Date: Fri, 9 Oct 2015 17:37:39 +0200
Subject: [PATCH] ox-extra.el: Fix filtering of latex header blocks
* ox-extra.el (org-latex-header-blocks-filter): Use `org-element' API to
find begin and end 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'.
---
| 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
--git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el
index e6d45cc..669d54f 100644
--- a/contrib/lisp/ox-extra.el
+++ b/contrib/lisp/ox-extra.el
@@ -71,18 +71,24 @@
(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"))))))
+ (let* ((beg (first pos))
+ (end (second pos))
+ (post-affiliated (third pos))
+ (contents-lines (split-string
+ (buffer-substring-no-properties beg
+ end)
+ "\n")))
+ (goto-char post-affiliated)
+ (delete-region beg end)
+ (dolist (line (remove-if (lambda (line)
+ (or
+ (string-prefix-p "#+HEADER:" line)
+ (string-prefix-p "#+BEGIN_LaTeX" line)
+ (string-prefix-p "#+END_LaTeX" line)))
+ contents-lines))
+ (insert (concat "#+latex_header: "
+ (replace-regexp-in-string "\\` *" "" line)
+ "\n")))))
;; go in reverse, to avoid wrecking the numeric positions
;; earlier in the file
(reverse positions)))))
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-10-09 16:13 [PATCH] ox-extra.el: Fix filtering of latex header blocks Sebastian Christ
2015-10-11 8:21 ` Sebastian Christ
@ 2015-11-09 6:30 ` Kyle Meyer
2015-11-10 9:54 ` Sebastian Christ
2015-11-10 16:57 ` Aaron Ecay
2 siblings, 1 reply; 9+ messages in thread
From: Kyle Meyer @ 2015-11-09 6:30 UTC (permalink / raw)
To: Sebastian Christ; +Cc: emacs-orgmode
Hello,
Sebastian Christ <rudolfo.christ@gmail.com> writes:
> Hi group,
>
> I'd like to provide a patch to
> ox-extra.el. `org-latex-header-blocks-filter' still calls
> `org-edit-src-find-region-and-lang' and raises therefore an undefined
> function error.
Thanks for the patch. Sorry for the delayed response.
> * ox-extra.el (org-latex-header-blocks-filter): Use `org-element' API to
> find begin and end of latex header blocks.
s|ox-extra.el|contrib/lisp/ox-extra.el|
s/begin/beginning/
[...]
> (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"))))))
> + (let* ((beg (third pos))
> + (end (second pos))
> + (post-affiliated (first pos))
Nitpick: nth is more commonly used in the Org code base.
Hmm, the pos items are constructed as
(list (org-element-property :begin block)
(org-element-property :end block)
(org-element-property :post-affiliated block)))))))
so shouldn't beg be the first element and post-affiliated the third?
Hopefully Aaron will get a chance to have a look.
--
Kyle
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-11-09 6:30 ` Kyle Meyer
@ 2015-11-10 9:54 ` Sebastian Christ
2015-11-10 15:11 ` Kyle Meyer
0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Christ @ 2015-11-10 9:54 UTC (permalink / raw)
To: emacs-orgmode
>>>>> On Mon, 09 Nov 2015 01:30:23 -0500, Kyle Meyer <kyle@kyleam.com> said:
>> * ox-extra.el (org-latex-header-blocks-filter): Use `org-element' API to
>> find begin and end of latex header blocks.
Kyle>
Kyle> s|ox-extra.el|contrib/lisp/ox-extra.el|
Kyle> s/begin/beginning/
Kyle>
Thanks. I'll change that.
>> (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"))))))
>> + (let* ((beg (third pos))
>> + (end (second pos))
>> + (post-affiliated (first pos))
Kyle>
Kyle> Hmm, the pos items are constructed as
Kyle>
Kyle> (list (org-element-property :begin block)
Kyle> (org-element-property :end block)
Kyle> (org-element-property :post-affiliated block)))))))
Kyle>
Kyle> so shouldn't beg be the first element and post-affiliated the third?
I thought it would be better to change as little as
possible. Rearranging the list is obviously the cleaner solution. I'll
change that.
Thanks for the review.
-Sebastian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-11-10 9:54 ` Sebastian Christ
@ 2015-11-10 15:11 ` Kyle Meyer
2015-11-12 19:30 ` Sebastian Christ
0 siblings, 1 reply; 9+ messages in thread
From: Kyle Meyer @ 2015-11-10 15:11 UTC (permalink / raw)
To: Sebastian Christ; +Cc: emacs-orgmode
Sebastian Christ <rudolfo.christ@gmail.com> writes:
[...]
> >> + (let* ((beg (third pos))
> >> + (end (second pos))
> >> + (post-affiliated (first pos))
> Kyle>
> Kyle> Hmm, the pos items are constructed as
> Kyle>
> Kyle> (list (org-element-property :begin block)
> Kyle> (org-element-property :end block)
> Kyle> (org-element-property :post-affiliated block)))))))
> Kyle>
> Kyle> so shouldn't beg be the first element and post-affiliated the third?
>
> I thought it would be better to change as little as
> possible. Rearranging the list is obviously the cleaner solution. I'll
> change that.
Sorry, my question wasn't clear. I wasn't concerned about arrangement,
but about whether you're accessing the correct element of the list. If
the list is constructed as (:begin :end :post-affiliated), why does your
let-binding above take the third element as beg and the first element as
post-affiliated?
--
Kyle
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-10-09 16:13 [PATCH] ox-extra.el: Fix filtering of latex header blocks Sebastian Christ
2015-10-11 8:21 ` Sebastian Christ
2015-11-09 6:30 ` Kyle Meyer
@ 2015-11-10 16:57 ` Aaron Ecay
2015-11-12 19:23 ` Sebastian Christ
2 siblings, 1 reply; 9+ messages in thread
From: Aaron Ecay @ 2015-11-10 16:57 UTC (permalink / raw)
To: Sebastian Christ, emacs-orgmode
Hi Sebastian,
Thanks for the patch. In addition to Kyle’s comments:
2015ko urriak 9an, Sebastian Christ-ek idatzi zuen:
>
> Hi group,
>
> I'd like to provide a patch to
> ox-extra.el. `org-latex-header-blocks-filter' still calls
> `org-edit-src-find-region-and-lang' and raises therefore an undefined
> function error.
>
> Best wishes,
> Sebastian
>
> From 34b76e06bda5739e433c95b451915c8b804a1733 Mon Sep 17 00:00:00 2001
> From: Sebastian Christ <rudolfo.christ@gmail.com>
> Date: Fri, 9 Oct 2015 17:37:39 +0200
> Subject: [PATCH] ox-extra.el: Fix filtering of latex header blocks
>
> * ox-extra.el (org-latex-header-blocks-filter): Use `org-element' API to
> find begin and end 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 | 28 ++++++++++++++++------------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el
> index e6d45cc..bb838fc 100644
> --- a/contrib/lisp/ox-extra.el
> +++ b/contrib/lisp/ox-extra.el
> @@ -71,18 +71,22 @@
> (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"))))))
> + (let* ((beg (third pos))
> + (end (second pos))
> + (post-affiliated (first pos))
> + (contents-lines
> + (cdr (butlast
> + (split-string
> + (buffer-substring-no-properties post-affiliated
> + end)
> + "\n")
> + 2))))
Here I think you should use (org-element-property :value X) to get the
contents-lines. This means that it should be added to the list that’s
constructed from :begin, :end, and :post-affiliated higher up. (And
then I think :post-affiliated can be dropped from that list.)
I’m not sure why I didn’t do it that way in the first place, actually.
--
Aaron Ecay
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-11-10 16:57 ` Aaron Ecay
@ 2015-11-12 19:23 ` Sebastian Christ
2015-12-08 10:12 ` Sebastian Christ
0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Christ @ 2015-11-12 19:23 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 274 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-extra.el-Fix-filtering-of-latex-header-blocks.patch --]
[-- Type: text/x-patch, Size: 2657 bytes --]
From a814380158de6185747975848533e3bd6e675afd Mon Sep 17 00:00:00 2001
From: Sebastian Christ <rudolfo.christ@gmail.com>
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'.
---
| 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
--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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-11-10 15:11 ` Kyle Meyer
@ 2015-11-12 19:30 ` Sebastian Christ
0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Christ @ 2015-11-12 19:30 UTC (permalink / raw)
To: emacs-orgmode
Hi Kyle,
you're completely right. This is a bug in the provided patch. I've
thought I had submitted another patch to fix that, but it seems that it
got lost somewhere on the interwebs. It took some time until I've
realized this.
I've submitted an new patch already.
Thanks.
-Sebastian
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] ox-extra.el: Fix filtering of latex header blocks
2015-11-12 19:23 ` Sebastian Christ
@ 2015-12-08 10:12 ` Sebastian Christ
0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Christ @ 2015-12-08 10:12 UTC (permalink / raw)
To: emacs-orgmode
BUMP ???
Best wishes,
Sebastian
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-12-08 10:12 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-09 16:13 [PATCH] ox-extra.el: Fix filtering of latex header blocks Sebastian Christ
2015-10-11 8:21 ` Sebastian Christ
2015-11-09 6:30 ` Kyle Meyer
2015-11-10 9:54 ` Sebastian Christ
2015-11-10 15:11 ` Kyle Meyer
2015-11-12 19:30 ` Sebastian Christ
2015-11-10 16:57 ` Aaron Ecay
2015-11-12 19:23 ` Sebastian Christ
2015-12-08 10:12 ` Sebastian Christ
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.