Hi, Thanks again! Nicolas Goaziou writes: >> I did not know markers but they seem perfect in this case. The manual >> mentions setting markers to nil after use. I guess it's not necessary >> here since they are in a (let ⋯)? > > It is. Binding between the symbol and the marker disappears with the > `let', but the marker still exists. It cannot be GC'ed unless it is set > to nil. > > It is not terribly important here as we're working in a temporary buffer > anyway, so the marker will ultimately disappear at the end of the export > process. However, it's a good habit to have. Thanks for the explanation. >> I check if I'm at a footnote reference 'cause I never want to deal with a >> footnote-*definition* directly. AFAIK org-footnote-re matches both. It >> seems a footnote-reference can never be at the beginning of line, but I >> would still prefer a more explicit test through org-element. > > I wasn't clear. The check is important. The minor issue is that you bind > LABEL and FOOTNOTE-TYPE too early, before making sure you are at > a footnote reference. It would be more logical to do > > (let ((object (org-element-context))) > (when (eq (org-element-type object) 'footnote-reference) > (let ((footnote-type (org-element-property :type object)) > (label (org-element-property :label object))) > ...))) I see. I disagree that it's more since it's directly inside a loop over org-footnote-re. So if we are not at a footnote-{reference,definition} it's probably a bug in the regexp. >> The only "bug" *I'm aware of* is that it will pick up the wrong new-label >> for footnote for something like [fn:ref with space]. But this is anyway >> not a proper label, I think. Is that OK? > > [fn: ref with space] While your comment excels in preciseness the terseness makes it hard to appreciate its depth. In my org-installation "[fn: ref with space]" is not a valid footnote. >> + (when (and (not included) (> (hash-table-count footnotes) 0)) >> + (org-with-wide-buffer >> + (goto-char (point-max)) >> + (unless (bolp) (insert "\n")) >> + (maphash (lambda (ref def) (insert (format "[%s] %s\n" ref def))) >> + footnotes))))))))))) > > (unless included ...) > > is sufficient. No need to check for table emptiness (although it doesn't > cost much): maphash will simply do nothing. Thanks. It's not necessary anymore. >> + (let ((marker-min (point-min-marker)) > > This marker is not necessary since you're not going to add contents > before (point-min) anyway. A plain number is enough. I might if I include *Bar here: * Foo [1] foo * Bar Baz[1] >> + (goto-char (point-min)) >> + (while (re-search-forward org-footnote-re nil t) >> + (let* ((reference (org-element-context)) >> + (label (org-element-property :label reference)) >> + (digit-label (and label (org-string-match-p "\\`[0-9]+\\'" label)))) >> + (when (eq (org-element-type reference) 'footnote-reference) > > See above about order of bindings. Adopted and commented on above. >> + (goto-char (1+ (org-element-property :begin reference))) >> + (when label >> + (let ((new-label >> + (buffer-substring-no-properties >> + (point) >> + (progn (if digit-label (insert (format "fn:%d-" id)) >> + (forward-char 3) >> + (insert (format "%d-" id))) >> + (1- (search-forward "]")))))) > >> + (unless (eq (org-element-property :type reference) 'inline) > > A comment about what we're going to do would be nice. Comments are added. —Rasmus -- I feel emotional landscapes they puzzle me