From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcin Borkowski Subject: Re: How to change a link? Date: Thu, 16 Oct 2014 19:55:35 +0200 Message-ID: <87mw8vj3vs.fsf@wmi.amu.edu.pl> References: <87a94yjia9.fsf@wmi.amu.edu.pl> <87bnpd4ov7.fsf@nicolasgoaziou.fr> <87tx35hvh8.fsf@wmi.amu.edu.pl> <87y4sh2e7c.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XepHX-0000Kt-Pk for emacs-orgmode@gnu.org; Thu, 16 Oct 2014 13:56:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XepHR-00031z-NG for emacs-orgmode@gnu.org; Thu, 16 Oct 2014 13:56:11 -0400 Received: from msg.wmi.amu.edu.pl ([150.254.78.50]:47092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XepHR-00030C-HI for emacs-orgmode@gnu.org; Thu, 16 Oct 2014 13:56:05 -0400 Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id 7D34441443 for ; Thu, 16 Oct 2014 19:55:43 +0200 (CEST) Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i2I4z-+FoELz for ; Thu, 16 Oct 2014 19:55:43 +0200 (CEST) Received: from localhost (99-229.echostar.pl [213.156.99.229]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id 3B15D41440 for ; Thu, 16 Oct 2014 19:55:43 +0200 (CEST) In-reply-to: <87y4sh2e7c.fsf@nicolasgoaziou.fr> 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: org-mode List On 2014-10-15, at 23:52, Nicolas Goaziou wrote: > Marcin Borkowski 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