My bad, wrong manipulation. Here is the patch.
To reproduce the error, you can type the following in a fresh Org
#+begin_src org
target some text <<<target>>> another text target
#+end_src
Using C-c C-o on any of the two links will return an error.
Regards,
>From f7738f3e9239fc4fddccc7850dad7a0936087a58 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Sat, 19 Feb 2011 09:37:48 +0100
Subject: [PATCH] Fix bug with link to radio target at beginning or end of buffer
* lisp/org.el (org-open-at-point): if a link to a radio target is the
first, (resp. the last), element of a buffer, function cannot find
the property change required to get its boundaries, and
`buffer-substring' is called with an invalid nil argument.
* lisp/org.el (org-ctrl-c-ctrl-c): call `org-list-send-list' only when
cursor it at very first item of the list, as specified in the
manual. Also refactored the list part of the function a bit.
* lisp/org.el (org-toggle-item, org-toggle-heading): make sure every
sub-item in a list is changed into a sub-heading and sub-headings
are translated into sub-items. Also ignore inline tasks in the
process.
org-toggle-item on headlines preserves hierarchy
* lisp/org.el (org-set-autofill-regexps): use `org-item-re' in
`paragraph-start' to recognize alphabetical lists.
(org-fill-paragraph): enforce a pre-computed fill-prefix before
calling fill-paragraph when point in in an item. Also prevent
paragraphs getting merged into an adjacent list upon filling.
(org-adaptive-fill-function): make sure to determine real fill-prefix
for auto-fill.
(org-auto-fill-function): use a pre-computed fill-prefix before
calling do-auto-fill.
* lisp/org-list.el (org-list-item-body-column): new function
* lisp/org-inlinetask.el (org-inlinetask-at-task-p,
org-inlinetask-toggle-visibility): new functions.
* lisp/org-list.el (org-list-set-item-visibility): new function.
* lisp/org.el (org-cycle, org-cycle-internal-local): separate lists
and inline tasks from headlines.
(org-outline-level): do not consider lists as headlines.
Cycling visibility is using different tools.
* lisp/org-list.el (org-list-struct): mark items less indented than
top item of the list, so that they will be modified.
(org-list-struct-apply-struct): compare struct's indentation with
line's indentation instead of old-struct's. This is needed because
`org-list-struct' automatically fixes indentation so changes might not
be seen otherwise.
* lisp/org.el (org-ctrl-c-ctrl-c): small refactoring.
* lisp/org-list.el (org-list-struct-apply-struct): inline tasks along
with their content must stay at column 0 even if the item is gaining
indentation. Moreover, fix indentation of text in an inline task,
now it can be in such a task within a list.
* lisp/org-list.el (org-at-item-p): also verify context is valid.
Otherwise it would recognize valid items where org-in-item-p
wouldn't.
(org-in-item-p, org-list-struct-apply-struct): use shorter version of
org-at-item-p.
(org-cycle-list-bullet): fix typo.
(org-list-parse-list): avoid calling org-at-item-p two times by using
an appropriate regexp
* lisp/org.el (org-indent-line-function): use an appropriate regexp
instead of calling org-at-item-p two times.
* lisp/org.el (org-toggle-item): when used on normal text, ensure
every line in region is included in the new item, regardless of its
original indentation.
* lisp/org.el (org-toggle-item): Now accepts a prefix argument. When
used without argument on normal text, it will make the whole region
one item. With an argument, it defaults to old behavior: change each
line in region into an item.
* lisp/org.el (org-return): when called from inside an item with the
indent flag, function should keep text moved inside the item. This
allows to use C-j to separate lines in an item: cursor won't go back
to column 0.
* lisp/org-list.el (org-alphabetical-lists): new variable
(org-item-re, org-list-full-item, org-cycle-list-bullet,
org-list-struct-fix-bul, org-list-inc-bullet-maybe): reflect
introduction of the new variable.
(org-item-beginning-re): changed into a function, so any modification
of `org-alphabetical-lists' will not require reloading Org.
(org-at-item-p, org-toggle-checkbox, org-update-checkbox-count,
org-list-parse-list, org-list-send-list): reflect changes to
`org-item-beginning-re'.
(org-list-use-alpha-bul-p): new function.
* lisp/org.el (org-check-for-hidden): reflect changes to
`org-item-beginning-re'.
* lisp/org-capture.el (org-capture-place-item): reflect changes to
`org-item-beginning-re'.
* lisp/org-docbook.el (org-export-docbook-list-line): handle new type
of items.
* lisp/org-exp.el (org-export-mark-list-end,
org-export-mark-list-properties): reflect changes to
`org-item-beginning-re'.
* lisp/org-html.el (org-html-export-list-line): handle new type of
items.
* lisp/org-latex.el (org-export-latex-lists): handle new type of items
and reflect changes to `org-item-beginning-re'.
* lisp/org-ascii.el (org-export-ascii-preprocess): handle new counters.
Modified from a patch by Nathaniel Flath.
When the function needs to know if cursor is in a plain list and move
to item beginning if it is the case, a fast way is to ignore errors on
(goto-char (org-in-item-p)).
* lisp/org.el (org-get-string-indentation): moved in generally useful
functions section, as it wasn't specific to plain lists and that no
code was using it in org-list.el.
* lisp/org.el (org-skip-over-state-notes,org-store-log-note): use new
accessors.
* list/ob.el (org-babel-result-end): use new accessors.
* list/org-exp.el (org-export-mark-list-ending): use new accessors.
* org.el (org-indent-line-function): Indentation of item's body starts
just after the bullet, not after a checkbox. Moreover, As
`org-in-item-p' also returns item beginning position when point is
in a list, do not compute it a second time.
* org.el (org-ctrl-c-ctrl-c): when called at a list item, replace
usage `org-repair-list', forcing another reading of the list, with
only needed subroutines.
* org.el (org-link-unescape): Simpler algorithm for replacing percent
escapes.
(org-link-unescape-compound): Use cond statements instead of nested
if, convert hex string with string-to-number, save match data.
(org-link-unescape-single-byte-sequence): Use mapconcat and
string-to-number for unescaping single byte sequence.
* org.el (org-link-escape-chars, org-link-escape-chars-browser): New
format of percent escape table.
(org-link-escape): Use new table format.
Just a plain list with the chars that should be escaped.
* org-exp.el (org-export-preprocess-string): Set the source
buffer and use `org-clone-local-variables' to get local
variables from it.
* org.el (org-clone-local-variables): New function.
* lisp/org.el (org-open-at-point): Fix bug when using prefix arg to
construct `org-link-search' call. Rename prefix arg with a more
generic name, to reflect its diverse uses in this function.
* lisp/org.el (org-entry-get): Don't look for a property drawer if we
are before the first heading in the file.
(org-entry-get-with-inheritance): Don't attempt to move up the tree if
we are before the first heading in the file. Also, enclose less of the
function in the save-excursion.
* org.el (org-update-parent-todo-statistics): fix bug when
updating statistics from the column view.
This was reported by James Deaton and confirmed by Bernt Hansen.