* How to insert/replace during `org-elemment-map' call?
@ 2014-08-07 11:27 Thorsten Jolitz
2014-08-07 13:14 ` Nicolas Goaziou
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-08-07 11:27 UTC (permalink / raw)
To: emacs-orgmode
Hi List,
when I change the signature of my new function `tj/rewire-element' by
adding an mandatory 'element' argument, it can be used in
`org-element-map' calls too:
#+begin_src emacs-lisp
(defun* tj/rewire-element (element &optional replace &rest args &key type &allow-other-keys)
"..."
(let* ((elem (or element (org-element-at-point))) ...)))
#+end_src
e.g. for converting all src-blocks in a buffer to example blocks:
#+begin_src emacs-lisp
(org-element-map ptree 'src-block
(lambda (--elem)
(tj/rewire-element --elem nil
:type 'example-block
:header nil)))
#+end_src
but the above just returns a list of strings with the created
example-blocks because argument 'replace' is nil:
,----
| (tj/rewire-element --elem nil ...)
`----
When I set that argument to non-nil (t or 'append or 'prepend), things
stop working because replacing/appending changes the parsed buffer,
but the :begin and :end properties of the already parsed elements are
not adjusted and I use them e.g. to delete a region.
Without using the export-framework (which seems overkill in this
case), is there a way to make this work anyway?
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to insert/replace during `org-elemment-map' call?
2014-08-07 11:27 How to insert/replace during `org-elemment-map' call? Thorsten Jolitz
@ 2014-08-07 13:14 ` Nicolas Goaziou
2014-08-07 16:11 ` Thorsten Jolitz
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2014-08-07 13:14 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
Hello,
Thorsten Jolitz <tjolitz@gmail.com> writes:
> When I set that argument to non-nil (t or 'append or 'prepend), things
> stop working because replacing/appending changes the parsed buffer,
> but the :begin and :end properties of the already parsed elements are
> not adjusted and I use them e.g. to delete a region.
>
> Without using the export-framework (which seems overkill in this
> case), is there a way to make this work anyway?
You can make replacements backwards, i.e., starting from the bottom of
the buffer.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to insert/replace during `org-elemment-map' call?
2014-08-07 13:14 ` Nicolas Goaziou
@ 2014-08-07 16:11 ` Thorsten Jolitz
2014-08-07 19:32 ` Nicolas Goaziou
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-08-07 16:11 UTC (permalink / raw)
To: emacs-orgmode
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
Hello,
> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> When I set that argument to non-nil (t or 'append or 'prepend), things
>> stop working because replacing/appending changes the parsed buffer,
>> but the :begin and :end properties of the already parsed elements are
>> not adjusted and I use them e.g. to delete a region.
>>
>> Without using the export-framework (which seems overkill in this
>> case), is there a way to make this work anyway?
>
> You can make replacements backwards, i.e., starting from the bottom of
> the buffer.
Its not really obvious for me how to do that. You mean simply by doing
it in 2 steps
1. map parse-tree and get the result list
2. goto point-max of buffer and use the result list to replace mapped
elements backwards
or rather a 'trick' to make org-element-map process the parse-tree
backwards and thus start with replacing the last element?
Not sure what this trick would be - partly reverse the parse-tree?
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How to insert/replace during `org-elemment-map' call?
2014-08-07 16:11 ` Thorsten Jolitz
@ 2014-08-07 19:32 ` Nicolas Goaziou
0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2014-08-07 19:32 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Its not really obvious for me how to do that. You mean simply by doing
> it in 2 steps
>
> 1. map parse-tree and get the result list
>
> 2. goto point-max of buffer and use the result list to replace mapped
> elements backwards
Yes, that is what I mean. Just make sure to reverse the list returned by
`org-element-map'.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-07 19:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-07 11:27 How to insert/replace during `org-elemment-map' call? Thorsten Jolitz
2014-08-07 13:14 ` Nicolas Goaziou
2014-08-07 16:11 ` Thorsten Jolitz
2014-08-07 19:32 ` Nicolas Goaziou
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).