I've adapted the code such that it handles both bracketed and
unbracketed links, and links with descriptions.
As it is now, the changes are always automatically applied.

> Also, rewriting needs not be always absolute path, if both directories
> share a common root.

I couldn't find a simple way of rewriting links without making them
absolute, as `org-export--prepare-file-contents` does not have access
to the path of the including file, only of the included file.

On Thu, Mar 1, 2018 at 11:42 PM, Nicolas Goaziou <m...@nicolasgoaziou.fr> wrote:
> Hello,
> Daniel P Gomez <gomez.d...@gmail.com> writes:
>> Currently when passing the :absolute-paths toggle to an include
>> derivative, as in :
>> #+INCLUDE: file.org :absolute-paths t
>> The function `org-export--prepare-file-contents` will automatically
>> deduce the directory from file.org and adapt links by calling:
>> `(new-path (expand-file-name old-path (file-name-directory file)))`.
>> I could either make this a default option, such that links get
>> corrected but users can overwrite this by calling `:absolute-paths
>> nil`, or I could completely remove this toggle and always correct
>> links no matter what.
> I am wondering about the latter. If there is no reason to keep broken
> file names, it makes sense to automatically apply it.
> Also, rewriting needs not be always absolute path, if both directories
> share a common root.
>> One question regarding the implementation, currently I'm deleting the
>> link with a call to `delete-region` and using `(insert "[[file:"
>> new-path "]]")` to insert the corrected one. This does not take into
>> consideration whether links are bracketed or not ( is there a
>> functional difference if links are not bracketed?).
> Yes. White spaces are handled differently in each link type.
>> Also, my approach completely disregards link descriptions, which may
>> be relevant if the linked file would be, for example, an html
>> document. Would there be a cleaner org approach to replace the path
>> keeping the description?
> You could check :contents-begin and :contents-end for the link. If they
> are not nil, extract this region, and insert it again in the new link.
> Regards,
> --
> Nicolas Goaziou                                                0x80A93738

Attachment: 0001-Fix-file-links-when-using-INCLUDE.patch
Description: Binary data

Reply via email to