From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: Sharon Kimble <boudiccas@skimble.plus.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: how to renumber footnotes?
Date: Sat, 18 Apr 2020 11:00:14 +0200 [thread overview]
Message-ID: <d139b89d-6592-7e7d-947b-4571fdfd6baa@easy-emacs.de> (raw)
In-Reply-To: <87ftd2kpsp.fsf@skimble.plus.com>
Am 17.04.20 um 19:03 schrieb Sharon Kimble:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>
>> On 17.04.20 05:58, Sharon Kimble wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA512
>>>
>>>
>>> Please, can someone help me sort out an org-mode footnote problem?
>>>
>>> I have 2 org-mode documents called 'file-a' and 'file-b', and both have
>>> got several hundred footnotes starting with 1. I'm adding file-b on to
>>> the end of file-a, and trying to renumber the footnotes, so that even if
>>> file-a has 354 footnotes, and file-b has 421 footnotes, the whole file
>>> renumbers the footnotes and continues on from 354 to 355, 356, 357, etc
>>> and onwards.
>>>
>>> But how can I do this please? The org-mode footnote program can't do it,
>>> so how do I do it please?
>>>
>>> (The footnote numbers I've shown are purely arbitrary, some files that
>>> I'm wanting to do this with have up to 700 footnotes in their combined
>> Make sure there is only one footnote-section at the end of file and all fn appear in correct order:
>>
>> (defun ar-org-footnote-renumber-intern ()
>> (let ((c 0))
>> (while (re-search-forward org-footnote-re nil t)
>> (backward-char 2)
>> (when (looking-at "[0-9]+")
>> (replace-match (number-to-string (cl-incf c)))))))
>>
>> (defun ar-org-footnote-renumber ()
>> "Renumber footnotes."
>> (interactive "*")
>> (save-restriction
>> (widen)
>> (goto-char (point-min))
>> (when (re-search-forward "^* Footnotes" nil t)
>> ;; first renumber fns in text section, afterwards the
>> ;; fn-definitions
>> (save-restriction
>> (narrow-to-region (point-min) (line-beginning-position))
>> (goto-char (point-min))
>> (ar-org-footnote-renumber-intern)
>> (widen)
>> (when (re-search-forward "^* Footnotes" nil t)
>> (narrow-to-region (line-beginning-position) (point-max))
>> (goto-char (point-min))
>> (ar-org-footnote-renumber-intern))))))
>>
> Thanks Andreas, but all my footnotes are inline. Perhaps I should've
> said that earlier on, sorry!
>
> Perhaps I could put them at the end but I'm too tired at the moment to
> think about it, but plenty of time at the weekend, hooray!
>
> Thanks
> Sharon.
> - --
> A taste of linux = http://www.sharons.org.uk
> TGmeds = http://www.tgmeds.org.uk
> DrugFacts = https://www.drugfacts.org.uk
> Debian 10.2, fluxbox 1.3.7, emacs 27.0.90, org 9.3.6
This version allows re-numbering in reverse order, as some footnote-mode
seem to require. Inlined fn should be supported.
Works only on active region.
(defun ar-org-footnote-renumber-intern (&optional reverse)
(let* ((c 0)
(nav-function (if reverse 're-search-backward 're-search-forward)))
(if reverse
(goto-char (point-max))
(goto-char (point-min)))
(while (funcall nav-function org-footnote-re nil t)
(save-excursion
(goto-char (match-beginning 0))
(search-forward ":")
(when (looking-at "[0-9]+")
(replace-match (number-to-string (cl-incf c))))))))
(defun ar-renumber-footnote-in-region (arg &optional beg end)
"Renumber footnotes in active region.
ARG: With \\[universal-argument] renumber in reverse order.
Optional BEG: specify start position ignoring region.
Optional END: specify end position ignoring region.
"
(interactive "*P")
(save-excursion
(let ((beg (cond (beg)
((use-region-p)
(region-beginning))))
(end (cond (end)
((use-region-p)
(copy-marker (region-end)))))
(reverse (eq 4 (prefix-numeric-value arg))))
(if
(and beg end)
(progn
(save-restriction
(narrow-to-region beg end)
(ar-org-footnote-renumber-intern reverse)))
(error "Need an active region to work on!")))))
next prev parent reply other threads:[~2020-04-18 9:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-17 3:58 how to renumber footnotes? Sharon Kimble
2020-04-17 4:12 ` Emanuel Berg via Users list for the GNU Emacs text editor
[not found] ` <mailman.453.1587096748.3066.help-gnu-emacs@gnu.org>
2020-04-17 6:26 ` Gijs Hillenius
2020-04-17 10:05 ` Sharon Kimble
2020-04-17 12:10 ` Gijs Hillenius
2020-04-17 12:45 ` Giovanni Bono
2020-04-17 13:53 ` Giovanni Bono
2020-04-17 12:45 ` Stephen Berman
[not found] ` <87d086s8q3.fsf@fastmail.fm>
2020-04-18 7:14 ` Fwd: " Joost Kremers
2020-04-18 15:53 ` Kyle Meyer
2020-04-17 10:16 ` Sharon Kimble
2020-04-18 1:37 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-04-17 16:10 ` Andreas Röhler
2020-04-17 17:03 ` Sharon Kimble
2020-04-17 19:16 ` Andreas Röhler
2020-04-18 6:06 ` Andreas Röhler
2020-04-18 9:00 ` Andreas Röhler [this message]
2020-04-19 15:00 ` Andreas Röhler
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d139b89d-6592-7e7d-947b-4571fdfd6baa@easy-emacs.de \
--to=andreas.roehler@easy-emacs.de \
--cc=boudiccas@skimble.plus.com \
--cc=help-gnu-emacs@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.