emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [bug, patch, ox] INCLUDE and footnotes


From: Rasmus
Subject: Re: [O] [bug, patch, ox] INCLUDE and footnotes
Date: Thu, 18 Dec 2014 18:37:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Hi,

Thanks for the notes.  Hopefully patch one if good now.  Patch two needs
tests, but I can write those if we agree to impose minlevel automatically.

Nicolas Goaziou <address@hidden> writes:

> AFAICT, there's no reason to include a rule about whitespace separating
> anything. Just make sure that any INCLUDE keyword that doesn't have
> a :minlevel property gets one set to 1+N, where N is the current level
> (or 0 if at top level).
>
> Another option is to delay insertion of included files: expand them
> completely in different strings, then replace keywords with appropriate
> strings. IOW, just make sure expansion doesn't happen sequentially.

OK.  Solution one sounds easier.  A quick attempt, without tests, is given
in the second patch.  I'll add patches if you agree with the easy
approach.  It seems to work, though I'm not sure if the matching of
headlines which should have :minlevel added is robust enough.

>>  Objects can be extracted via =#+INCLUDE= using file links.  It is
>> -possible to include only the contents of the object.  See manual for
>> +possible to include only the contents of the object.  Further,
>> +footnotes are now supported when using =#+INCLUDE=.  See manual for
>
> This is not quite true. Footnotes are already supported with INCLUDE
> keywords. This is the combination of :lines and footnotes that is new.
> It is more a bugfix than a new feature.

Right.  Removed.

>> +               (goto-char (point-min))
>> +               (while (and (search-forward-regexp org-footnote-re nil t))
>> +                 (let* ((reference (org-element-context))
>> +                        (type (org-element-type reference))
>> +                        (label (org-element-property :label reference)))
>> +                   (when (and label (eq type 'footnote-reference))
>> +                     (unless (org-footnote-get-definition label)
>> +                       (save-excursion
>> +                         (org-footnote-create-definition label)
>> +                         ;; We do not need an error here since ox
>> +                         ;; will complain if a footnote is missing.
>> +                         (insert (or (gethash label footnotes) "")))))))
>
> Why is the above necessary? Shouldn't you only insert footnotes
> definitions at the end of the master document (i.e. when INCLUDED is
> nil)?

Indeed.  Thanks for the hint!

> I think a `maphash' is enough.
>
> Also, looking for every footnote reference sounds tedious. You should
> simply insert every footnote definition collected there, and filter out
> unnecessary definitions at another level (e.g., before storing it in the
> hash table).

Thanks!

>> +      (when id
>> +    (unless (eq major-mode 'org-mode)
>> +      (let ((org-inhibit-startup t)) (org-mode)))
>
> Is it necessary?

I think org-with-wide-buffer is sufficient.

>> +            (forward-char 4)
>> +            (insert (format "%d-" id))
>> +            (and (not (eq footnote-type 'inline))
>> +                 (let ((new-label (org-element-property
>> +                                   :label (org-element-context))))
>
> Why do you need to parse the new label, since you know it already:
>
>   (concat (format "%d-" id) label)

Almost, but label contains fn: first, so the above would be e.g. 1-fn:1.
I didn't see an elegant way of doing it at first, thus I used elements,
but now I just use regexp-replace...  I solved in another way.

>> +                   (save-restriction
>> +                     (save-excursion
>> +                       (widen)
>
> `save-restriction' + `save-excursion' + `widen' = `org-with-wide-buffer'

Cool.

>> +                              (puthash new-label
>> +                                       (org-element-normalize-string
>> +                                        (buffer-substring
>> +                                         (org-element-property
>> +                                          :contents-begin definition)
>> +                                         (org-element-property
>> +                                          :contents-end definition)))
>> +                                       footnotes))
>
> Here you could check if :contents-begin is within LINES, in which case
> the definition needs not be inserted at the end of the master document.

Good idea.  I did it a bit more elaborated since footnotes can in
principle also be before the definition.  I don't check for the end.

Thanks,
Rasmus

-- 
Slowly unravels in a ball of yarn and the devil collects it

Attachment: 0001-ox.el-Fix-footnote-bug-in-INCLUDE-keyword.patch
Description: Text Data

Attachment: 0002-ox.el-Guess-the-minlevel-for-INCLUDE-keywords.patch
Description: Text Data


reply via email to

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