emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] How to change a link?


From: Marcin Borkowski
Subject: Re: [O] How to change a link?
Date: Thu, 16 Oct 2014 19:55:35 +0200

On 2014-10-15, at 23:52, Nicolas Goaziou wrote:

> Marcin Borkowski <address@hidden> writes:
>
>> I have one more question.  What I'm about to do is (basically) put
>> "file:some-file-name::" in front of the link, without changing the
>> description.  I could use `org-element-put-property' and (AFAIU)
>> org-element-link-interpreter to put it into the buffer (and probably
>> delete the old one).  It would be much easier (and maybe faster) just to
>> go to the point in the buffer where the link starts, go `(forward-char
>> 2)' (past the brackets) and `(insert (concat "file" name "::"))'.
>>
>> But, is it safe?  Wouldn't it break something?  And is it considered a
>> good practice?
>
> There are caveats.
>
> For example, as soon as you alter the buffer, your AST becomes invalid
> (buffer positions are all wrong after the insertion). If you want to
> process all the links from the same AST, you can, for example, maintain
> a counter for characters inserted so far that will fix buffer positions,
> or first get all internal links with `org-element-map', then process
> them in reverse order so buffer modifications do not invalidate them.

OK, so what is the canonical way of doing this?  I don't want to use
org-dp, since it is another dependency.

> Regards,

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University



reply via email to

[Prev in Thread] Current Thread [Next in Thread]