* Moving footnotes
@ 2014-05-21 12:23 Leonard Randall
2014-05-21 16:39 ` Nicolas Goaziou
2014-05-30 12:57 ` Bastien
0 siblings, 2 replies; 10+ messages in thread
From: Leonard Randall @ 2014-05-21 12:23 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1469 bytes --]
Hi all,
One of the things I really like about org-mode is the ability to quickly
move material between projects. For instance, I sometimes write material as
a conference paper and want to use some sections in my thesis. I also like
to keep a file with old chapter drafts for later reference (I could just
use git for this, but keeping an old-drafts file around makes some jobs
more convenient). One issue that I am running into is that when I move
material with org-refile, footnotes defined in the Footnote section do not
move with it. Additionally, if I try to export a subtree as an org buffer,
it does not take footnote definitions with it.
The obvious workaround for both problems is to define footnotes inline.
Another option (the one that I am using currently) is to set
org-footnote-section to nil, and to set org-footnote-auto-label to 'random.
This way footnotes are kept at the bottom of the section, so they move with
refile, and they have randomly generated names, so they won't conflict with
any footnote definitions in the destination file.
This solution works, but I wondered if there was any way to get org-refile
and org-export-org to take footnotes definitions with them, wherever they
are located.
With org-export-org, this seems especially important as backends are
supposed to faithfully export footnotes with their definitions.
Additionally, is there a way to easily convert numbered footnotes to
randomly named footnotes?
Thanks,
Leonard
[-- Attachment #2: Type: text/html, Size: 1664 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-21 12:23 Moving footnotes Leonard Randall
@ 2014-05-21 16:39 ` Nicolas Goaziou
2014-05-30 12:57 ` Bastien
1 sibling, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2014-05-21 16:39 UTC (permalink / raw)
To: Leonard Randall; +Cc: emacs-orgmode
Hello,
Leonard Randall <leonard.a.randall@gmail.com> writes:
> Additionally, if I try to export a subtree as an org buffer, it does
> not take footnote definitions with it.
This particular point should now be fixed. Thank you for reporting it.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-21 12:23 Moving footnotes Leonard Randall
2014-05-21 16:39 ` Nicolas Goaziou
@ 2014-05-30 12:57 ` Bastien
2014-05-30 13:35 ` Nicolas Goaziou
1 sibling, 1 reply; 10+ messages in thread
From: Bastien @ 2014-05-30 12:57 UTC (permalink / raw)
To: Leonard Randall; +Cc: emacs-orgmode
Hi Leonard,
from the master branch, you can now use
`org-footnote-inline-footnotes' to convert external footnotes into
inline ones.
This is also accessible from the `C-c C-x f' menu that gets displayed
when calling `C-c C-x f' from a location where no sensible footnote
action can be done, or from `C-u C-c C-x f', which forces the display
of this menu.
As for converting numbered footnotes into random ones, yes, this
should be feasible -- hopefully someone can provide this hack and
add it to worg/org-hacks.org.
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-30 12:57 ` Bastien
@ 2014-05-30 13:35 ` Nicolas Goaziou
2014-05-30 13:51 ` Bastien
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-05-30 13:35 UTC (permalink / raw)
To: Bastien; +Cc: Leonard Randall, emacs-orgmode
Hello,
Bastien <bzg@gnu.org> writes:
> from the master branch, you can now use
> `org-footnote-inline-footnotes' to convert external footnotes into
> inline ones.
You didn't ask for it, but here are a few comments about it anyway ;)
(concat org-footnote-re "\\]")
will fail for numbered footnotes, since the regexp already contains the
closing bracket for this case. I suggest to use:
(while (re-search-forward org-footnote-re nil t)
(let ((context (save-excursion (backward-char) (org-element-context))))
(when (and (eq (org-element-type context) 'footnote-reference)
(eq (org-element-property :type context) 'standard))
...)))
Also, as a rule of thumb,
(car (org-element-at-point)) => (org-element-type (org-element-at-point))
Indeed, `car' relies on the internal representation of the object, which
might change. Public interface is less likely to do so.
You don't need to use `org-forward-element' since you called
`org-element-at-point', which will give you all the information needed,
which is probably (org-element-property :end element).
You should check if `org-footnote-section' is not nil before trying to
remove it.
Eventually, you should note that this process is bound to fail in some
situations, as footnote definitions can contain way more objects than
inline ones (e.g., lists, tables, multiple paragraphs ...). Worse, it
will break the current document when attempting to do so since footnote
definitions can contain blank lines.
All in all, I'm not convinced this should be a function provided in Org.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-30 13:35 ` Nicolas Goaziou
@ 2014-05-30 13:51 ` Bastien
2014-05-31 9:30 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2014-05-30 13:51 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Leonard Randall, emacs-orgmode
Hi Nicolas,
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> You didn't ask for it, but here are a few comments about it anyway ;)
Sure ! I unconsciously asked, I guess.
> All in all, I'm not convinced this should be a function provided in Org.
Okay. Still, it's useful to have it *somewhere*. If you have a
moment, could you revert the commit, rewrite the function with the
suggested enhancements and add it to worg/org-hacks.org?
If you don't want to clean my dirt after me that's okay, I will
do so later on.
Thanks,
PS: I think it's useful to trigger the org-footnote-action menu
when org-footnote-new cannot do anything useful.
--
Bastien
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-30 13:51 ` Bastien
@ 2014-05-31 9:30 ` Nicolas Goaziou
2014-05-31 11:09 ` Bastien
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-05-31 9:30 UTC (permalink / raw)
To: Bastien; +Cc: Leonard Randall, emacs-orgmode
Bastien <bzg@gnu.org> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>> All in all, I'm not convinced this should be a function provided in Org.
>
> Okay. Still, it's useful to have it *somewhere*. If you have a
> moment, could you revert the commit
Done.
> rewrite the function with the suggested enhancements
Here it is. It could be prettier but I think it should get the job done.
(defun org-footnote-inline-footnotes ()
"Convert external footnotes into inline ones."
(interactive)
(org-with-wide-buffer
(let ((random-labels (make-hash-table :test #'equal)) failed seen)
(goto-char (point-min))
(while (re-search-forward org-footnote-re nil t)
(let ((context (save-excursion (backward-char) (org-element-context))))
;; Ignore false positives.
(when (eq (org-element-type context) 'footnote-reference)
(let ((label (org-element-property :label context)))
;; Ignore anonymous footnotes.
(when label
(if (member label seen)
(let ((normalized-label (gethash label random-labels)))
(when normalized-label
(search-backward "[" nil t)
(forward-char)
(insert normalized-label)
(delete-region
(point)
(progn (skip-chars-forward "0-9") (point)))))
(push label seen)
(when (eq (org-element-property :type context) 'standard)
(let ((beg (copy-marker (org-element-property :begin context)))
(end (copy-marker
(save-excursion
(goto-char (org-element-property :end context))
(skip-chars-backward " \t")
(point))))
(definition
(save-excursion
(goto-char (point-min))
(catch 'exit
(while (re-search-forward
(format "^\\[%s\\]" (regexp-quote label))
nil t)
(let ((def (save-excursion
(backward-char) (org-element-at-point))))
(when (eq (org-element-type def) 'footnote-definition)
(let ((cbeg (org-element-property :contents-begin def))
(cend (org-element-property :contents-end def)))
;; Ensure definition can be inline,
;; i.e., contains a single
;; paragraph. Return nil if it
;; cannot.
(if (not cbeg) (throw 'exit "")
(goto-char cbeg)
(let ((contents (org-element-at-point)))
(if (or (not (eq (org-element-type contents) 'paragraph))
(< (org-element-property :end contents) cend))
(throw 'exit nil)
(throw 'exit
(prog1 (org-trim (buffer-substring cbeg cend))
(delete-region
(org-element-property :begin def)
(org-element-property :end def)))))))))))))))
(if (not definition) (push label failed)
(delete-region beg end)
(goto-char beg)
;; Convert [1] to [fn:random-id] to avoid
;; confusion between [1] and [fn:1].
(let ((normalized-label
(if (not (org-string-match-p "\\`[0-9]+\\'" label))
label
(require 'org-id)
(puthash
label
(concat "fn:" (substring (org-id-uuid) 0 8))
random-labels))))
(insert "[" normalized-label ":" definition "]")))
(set-marker beg nil)
(set-marker end nil)))))))))
(cond (failed (user-error "Some footnotes could not be converted : %s"
(mapconcat #'identity failed ", ")))
;; If process completed without failure, there is no regular
;; footnote definition left, so we remove footnote sections,
;; if any.
(org-footnote-section
(goto-char (point-min))
(let ((section-re (concat "^\\*+ " org-footnote-section "[ \t]*$")))
(while (re-search-forward section-re nil t)
(delete-region (match-beginning 0) (org-end-of-subtree t t))))))
(message "Footnotes successfully inlined."))))
> and add it to worg/org-hacks.org?
I suggest to test it first.
> PS: I think it's useful to trigger the org-footnote-action menu
> when org-footnote-new cannot do anything useful.
Sure, I will add it back later today, unless you're faster than me.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-31 9:30 ` Nicolas Goaziou
@ 2014-05-31 11:09 ` Bastien
2014-06-01 6:48 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2014-05-31 11:09 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Leonard Randall, emacs-orgmode
Hi Nicolas,
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Here it is. It could be prettier but I think it should get the job
> done.
Wow, thanks! I didn't expect this to be that long...
I tested it with various input files and it works fine.
>> PS: I think it's useful to trigger the org-footnote-action menu
>> when org-footnote-new cannot do anything useful.
>
> Sure, I will add it back later today, unless you're faster than me.
No hurry. I won't be connected later today.
Thanks a lot!
--
Bastien
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-05-31 11:09 ` Bastien
@ 2014-06-01 6:48 ` Nicolas Goaziou
2014-06-01 8:49 ` Bastien
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-06-01 6:48 UTC (permalink / raw)
To: Bastien; +Cc: Leonard Randall, emacs-orgmode
Hello,
Bastien <bzg@altern.org> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> Here it is. It could be prettier but I think it should get the job
>> done.
>
> Wow, thanks! I didn't expect this to be that long...
> I tested it with various input files and it works fine.
It could probably be refactored to gain a few lines of code. However it
has to deal with a few corner cases so there is no simple solution.
>>> PS: I think it's useful to trigger the org-footnote-action menu
>>> when org-footnote-new cannot do anything useful.
>>
>> Sure, I will add it back later today, unless you're faster than me.
>
> No hurry. I won't be connected later today.
Done. Though, I changed `org-footnote-action' instead of
`org-footnote-new', since the latter should, IMO, return an error when
called from a point where no footnote is allowed.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-06-01 6:48 ` Nicolas Goaziou
@ 2014-06-01 8:49 ` Bastien
2014-06-02 12:10 ` Leonard Avery Randall
0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2014-06-01 8:49 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Leonard Randall, emacs-orgmode
Hi Nicolas,
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Done. Though, I changed `org-footnote-action' instead of
> `org-footnote-new', since the latter should, IMO, return an error when
> called from a point where no footnote is allowed.
Right, thanks,
--
Bastien
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Moving footnotes
2014-06-01 8:49 ` Bastien
@ 2014-06-02 12:10 ` Leonard Avery Randall
0 siblings, 0 replies; 10+ messages in thread
From: Leonard Avery Randall @ 2014-06-02 12:10 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
Hi Bastien and Nicolas,
Thanks for the work. I do think the footnote transformation function
looks useful, though for now I think I will stick with defining the
footnotes at the end of each section and re-sorting the footnotes before
refile. I still think it would be useful to have org-refile move
footnotes by default. If I have some time soon I will look at what might
be required to do this effectively. I may ask the two of you for help as
I am still familiarizing myself with the org mode code.
All best,
Leonard
[-- Attachment #2: Type: text/html, Size: 654 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-06-02 12:10 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-21 12:23 Moving footnotes Leonard Randall
2014-05-21 16:39 ` Nicolas Goaziou
2014-05-30 12:57 ` Bastien
2014-05-30 13:35 ` Nicolas Goaziou
2014-05-30 13:51 ` Bastien
2014-05-31 9:30 ` Nicolas Goaziou
2014-05-31 11:09 ` Bastien
2014-06-01 6:48 ` Nicolas Goaziou
2014-06-01 8:49 ` Bastien
2014-06-02 12:10 ` Leonard Avery Randall
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).