;; To use, load this file ;; turn on balloon-help-mode ;; run footnote-balloons, or have it run automatically, e.g., ;; (add-hook 'gnus-article-display-hook 'footnote-balloons t) ;; Limitations: Currently, the program may make an extraneous balloon ;; here and there (e.g., if there is a footnote reference in a ;; citation which uses the same numbering scheme). (require 'balloon-help) (setq balloon-help-timeout 200) (defvar footnote-extent-face 'red) (defvar footnote-balloon-regexp "\\[[^\]\n]+\\]") ;; The following might have been more appropriate, but who knows ;; what people will dream up for footnote markers. ;(defvar footnote-balloon-regexp "\\[\\([0-9]+\\|[a-z]\\|[ixv]+\\)\\]") (defun get-foot-string () (let (start end foot-string ; ext ) (while (looking-at "[ \t]") (forward-char)) (setq start (point)) ;; Find the end of the footnote. (re-search-forward (concat "\\\n\\\n\\|\\'\\|" footnote-balloon-regexp) nil t) (beginning-of-line) (while (looking-at "^") (backward-char)) (setq end (point)) (setq foot-string (buffer-substring start end)) ;; Superfluous colorizing of the footnotes. ; (setq ext (make-extent start end)) ; (set-extent-property ext 'footnote t) ; (set-extent-face ext 'green) foot-string)) (defun footnote-balloons () "Make references to footnotes pop up a help balloon containing the text of the footnote." (interactive) (map-extents (lambda (extent ignore) (when (extent-property extent 'footnote) (delete-extent extent)))) (save-excursion (let (ref-beg ref-end ext footnum note) (goto-char (point-min)) ;; Looking for footnote refs in the text. (while (re-search-forward footnote-balloon-regexp nil t) (setq ref-beg (match-beginning 0)) (setq ref-end (match-end 0)) (setq footnum (buffer-substring ref-beg ref-end)) (goto-char (point-max)) ;; Now find the footnote itself. ; (when (search-forward footnum nil t) (when (search-backward footnum ref-end t) (search-forward footnum nil t) (setq note (get-foot-string)) (setq ext (make-extent ref-beg ref-end)) (set-extent-face ext footnote-extent-face) (set-extent-property ext 'footnote t) (set-extent-property ext 'balloon-help note) ) (goto-char ref-end)))))