mailRe: [Muse-el-discuss] Footnote Patch, (was Footnote-mode limitation )

Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]



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
'())(found nil))
      (goto-char (point-min))
      (while (re-search-forward
              (rx (minimal-match
                    (one-or-more not-newline)
                    "[" (group (and (eval muse-footnote-prefix)
                                    (one-or-more wordchar)))
              nil t)
        (setq found t)
        (incf count)
        (setq ref (match-string 1))
        (replace-match (number-to-string count) nil nil nil 1)
          (unless (re-search-forward
                   (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)
      (goto-char (point-max))
      (setq liste (reverse liste))
      (setq count 0)
      (setq def (dolist (elem liste def)
                  (incf count)
                  (setq def (concat def "[" (number-to-string count) "] " 
elem "\n\n"))))
      (if found (insert (concat "\n\nFootnotes:\n" def)) nil)

Related Messages

Powered by MHonArc, Updated Sun Nov 25 00:01:05 2007