emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Marcin Borkowski <mbork@wmi.amu.edu.pl>
Cc: org-mode List <emacs-orgmode@gnu.org>
Subject: Re: How to change a link?
Date: Wed, 15 Oct 2014 23:52:23 +0200	[thread overview]
Message-ID: <87y4sh2e7c.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87tx35hvh8.fsf@wmi.amu.edu.pl> (Marcin Borkowski's message of "Wed, 15 Oct 2014 23:30:11 +0200")

Marcin Borkowski <mbork@wmi.amu.edu.pl> 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.

You may also directly work on the buffer, with something like

  (org-with-wide-buffer
   (goto-char (point-min))
   (while (re-search-forward org-bracket-link-regexp nil t)
     (forward-char -1)
     (let ((context (org-element-context)))
       (when (and (eq (org-element-type context) 'link)
                  (member (org-element-property :type context)
                          '("custom-id" "fuzzy")))
         (goto-char (+ (org-element-property :begin context) 2))
         (insert "file:path/to-file::")))))


Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2014-10-15 21:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15  0:19 How to change a link? Marcin Borkowski
2014-10-15  7:16 ` Thorsten Jolitz
2014-10-15  9:50   ` Marcin Borkowski
2014-10-15 10:02     ` Thorsten Jolitz
2014-10-15 16:17       ` Marcin Borkowski
2014-10-15 22:28         ` Thorsten Jolitz
2014-10-15 22:36           ` Marcin Borkowski
2014-10-15 22:51             ` Thorsten Jolitz
2014-10-15 23:06               ` Thorsten Jolitz
2014-10-15 10:19 ` Nicolas Goaziou
2014-10-15 21:30   ` Marcin Borkowski
2014-10-15 21:52     ` Nicolas Goaziou [this message]
2014-10-16 17:55       ` Marcin Borkowski
2014-10-16 20:10         ` Nicolas Goaziou
2014-10-16 21:46           ` Marcin Borkowski
2014-10-16 22:19         ` Thorsten Jolitz
2014-10-17  8:52           ` Marcin Borkowski
2014-10-17 15:25             ` Nick Dokos
2014-10-18 13:54               ` Thorsten Jolitz
2014-10-18  1:44           ` Marcin Borkowski
2014-10-18 13:48             ` Thorsten Jolitz
2014-10-20  0:02   ` Marcin Borkowski
2014-10-20 13:02     ` Nicolas Goaziou
2014-10-20 13:11       ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y4sh2e7c.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=mbork@wmi.amu.edu.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).