Re: [Muse-el-discuss] Footnote Patch, (was Footnote-mode limitation )
Posted by paul r on November 22, 2007 - 14:29:
here is a bit of code I just wrote that helps a lot with footnotes.
This new version is more robust and more readable. If you want to try
it interactively, feed your *scratch* with the following code and hit
M-x muse-test-paul-footnotes. Reminder, it should not be called
interactively, but be hooked into the publish process at the same
level than :before function.
New to this version :
- reference does not need anymore to stick to the word
- footnote definition is much more robust, as definition ends with
either an other definition, a blank line or the end of the buffer.
- safe fail with helpful error message
(defun muse-test-paul-footnotes ()
"interactively call (muse-build-list-of-footnotes)"
(setq muse-footnote-prefix "fn:")
(defun muse-build-list-of-footnotes ()
(let ((ref "")(def "")(count 0)(deb 0)(def-deb 0)(def-fin 0)(liste
"[" (group (and (eval muse-footnote-prefix)
(setq found t)
(setq ref (match-string 1))
(replace-match (number-to-string count) nil nil nil 1)
(rx (seq bol
"[" (eval ref) "]"
(zero-or-more blank))) nil t)
(setq def (list (concat "Unable to find footnote definition for "
(signal 'quit def))
(setq deb (match-beginning 0))
(setq def-deb (match-end 0))
(rx (or "\n\n"
(seq "\n[" (eval muse-footnote-prefix))
(seq (zero-or-one "\n") buffer-end))))
(setq def-fin (match-beginning 0))
(push (buffer-substring def-deb def-fin) liste)
(delete-region deb def-fin)
(setq liste (reverse liste))
(setq count 0)
(setq def (dolist (elem liste def)
(setq def (concat def "[" (number-to-string count) "] "
(if found (insert (concat "\n\nFootnotes:\n" def)) nil)
Powered by MHonArc
, Updated Sun Nov 25 00:01:05 2007