From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Andreas_R=c3=b6hler?= Newsgroups: gmane.emacs.help Subject: Re: how to renumber footnotes? Date: Sat, 18 Apr 2020 11:00:14 +0200 Message-ID: References: <87v9lyvk3z.fsf@skimble.plus.com> <127dd11b-9379-361f-d315-d89882a5ac31@easy-emacs.de> <87ftd2kpsp.fsf@skimble.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="65599"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Cc: help-gnu-emacs@gnu.org To: Sharon Kimble Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 18 11:01:07 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPjLW-000H0A-V2 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 18 Apr 2020 11:01:07 +0200 Original-Received: from localhost ([::1]:56076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPjLV-0002QN-St for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 18 Apr 2020 05:01:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53576) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jPjKs-0002QA-Q9 for help-gnu-emacs@gnu.org; Sat, 18 Apr 2020 05:00:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jPjKq-00089Q-GV for help-gnu-emacs@gnu.org; Sat, 18 Apr 2020 05:00:26 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.133]:36999) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jPjKo-0007us-Hh for help-gnu-emacs@gnu.org; Sat, 18 Apr 2020 05:00:24 -0400 Original-Received: from [192.168.178.43] ([94.134.177.60]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MMH2M-1jhoiH0be2-00JLx3; Sat, 18 Apr 2020 11:00:15 +0200 In-Reply-To: <87ftd2kpsp.fsf@skimble.plus.com> Content-Language: en-US X-Provags-ID: V03:K1:FdePoMakK0o7/Q4+OwYoFzxBMy1NYeXSDhnObT0aTpfhjh8JDWT jmd9roAwbTlX9cZlKAGr0kGzPyIsfU+h4eoqFPsnPQVfCMLEULXvLTBljSdpG+s1Rvkucio 4bMhSRP1x+2ISzBRGq1vrVZ6kY+ecGuAwn+YOX0Bf7iF0WBPNg3YNnZB/3gJmL7x7aYe3Xv FzEReNp3pgAjAaqFQz9Ew== X-UI-Out-Filterresults: notjunk:1;V03:K0:/VKJr0pjEa4=:btsfNuZuULD9RGXBMFKdxw t2mK0I9VSPbyqJrTfNLB+9nqnWj/Jsr+t54zgVPpyMaQeszpGpyDV1+mLHE/z83tZ9TQHKxfT 34yeo6KAnNbcbCUh9DouwoTUrmcbtOHM1kt67K3UZsM8MnYy8YoWyruEv+o0zkk+VNNoAnsyN tp86GAGRhjha77y9pi3X0WyZ/hZRrvbtZ0aIuNCtyAOsFzFWucLr4sQF1RtihTz6/D0f/RFoW 3DcLHJbEYvALR4SVbexxmFDc+KOh2XxBG5AkQ1Rnup8ndY/5TfGwpdBH1CWlOwcAJh1h7Vodt yjR+6+vtRb8n18CBJ7IL88nUDGHpi+i/p/DwG1JdpHaJAAey/EbDq6EL6cIv/0DyqYXU5/fQ2 h/2zdfyf67eCMNrk5Rws93dH+xQEPifiHRYaWp4QYF12fH8l5Q7b4WeuFqzULkGF60PJdXVi4 +DtQhMuPXl2h85a6ULAy9PB4Yu0t0QbpdTixWX2oQfUU4+VULKEuQeqCfb3iYXrTfJ7zNed3N 3uH2Uqu1F7ttOJ4Sp+qNWVcwIYohVAudwDu6iu48CgL8ZRs5eueoi5Pr03scPDFOR5iD/X2sT iv2W4siliQfR/OWDc9G9L/JlEAY9ixFLPh04Kh0RHsBdmz7iw0O8zg4wvQkW/gpUiijeWprm/ MZeKlgtSM8c3agYh6ZTYBOP17qvgRf7X8//eFasiw5S3F0ZmAN9i9o9JCMINjrgN57Ngn6+CM 7tcv5YRNhBa3+dr9jxyIe3ubYOLihrdnArJdq/ZR/vRS5uI8cylnoSHdl8lhyYDHnpK1AcmK X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.133 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:122880 Archived-At: Am 17.04.20 um 19:03 schrieb Sharon Kimble: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA512 > > Andreas Röhler 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!")))))