[Footnote-mode]: alignment option [CODE included]

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Footnote-mode]: alignment option [CODE included]

Boruch Baum
Hi. I'm not a member of the list, but I wanted to share some code that I
think would be useful for emacs users...

The attached code allows one to left-justify footnote text from the
first column of text, instead of from the left margin. I find this
aesthetically preferable, especially when I have long footnotes.

Once the code is evaluated and one has footnote-mode enabled, `C-c ! q'
toggles the feature. Then, whenever one performs an auto-fill, `M-q'',
feature acts. Of course, if one has visual-line-mode enabled, the
auto-fill acts automatically.

The current code is set up as defadvice-s (that's how long I've ended up
sitting on it), but if emacs wants it integrated into the mode, there's
no need for that.



--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0

footnote-snippet.el (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Footnote-mode]: alignment option [CODE included]

Stefan Monnier
> The attached code allows one to left-justify footnote text from the
> first column of text, instead of from the left margin.  I find this
> aesthetically preferable, especially when I have long footnotes.

Could you give some example of the difference?

> Of course, if one has visual-line-mode enabled, the
> auto-fill acts automatically.

Hmm... how does visual-line-mode pay attention to
Footnote-align-to-fn-text (and know if it's inside a footnote)?

> The current code is set up as defadvice-s (that's how long I've ended up
> sitting on it), but if emacs wants it integrated into the mode, there's
> no need for that.

Of course.  Some comments about the code:

> (defun Footnote-align-to-fn()
>   (when Footnote-align-to-fn-text
>     (setq body-auto-fill-prefix fill-prefix
>           fill-prefix (make-string (Footnote-calc-fn-alignment-column) 32))))

IIUC body-auto-fill-prefix is just a var into which we temporarily save
the normal fill-prefix.  So this should be named with a "[Ff]ootnote-"
prefix (arguably with a "--" somewhere to make it clear it's an
internal variable), and it should be made buffer-local (so there's no
cross-buffer pollution).

The more serious problem is that `fill-prefix' is set with no guarantee
it will be reset to its proper value later.  E.g. if the user returns to
the body "manually" rather than via Footnote-back-to-message.

> (defun Footnote-toggle-alignment()
>   (interactive)
>   (setq Footnote-align-to-fn-text (not Footnote-align-to-fn-text))
>   (when footnote-text-marker-alist
>     (if (>= (point) (cdr (first footnote-text-marker-alist)))
>       (if Footnote-align-to-fn-text
>         (Footnote-align-to-fn)
>        (Footnote-align-to-body))))
>   (if Footnote-align-to-fn-text
>     (message "Footnotes will left-align to footnote text")
>    (message "Footnotes will left-align to body text")))

I suggest you make this into a minor mode:

    (define-minor-mode Footnote-align-to-text
      "When enabled, align footnote to the text rather than to the margin."
      :lighter nil
      (when footnote-text-marker-alist
        (if (>= (point) (cdr (first footnote-text-marker-alist)))
            (if Footnote-align-to-text
                (Footnote-align-to-fn)
              (Footnote-align-to-body)))))

> (defadvice Footnote-add-footnote (around abort-when-in-fn-area activate)
>   (interactive)
>   (if (or
>         (not footnote-text-marker-alist)
>         (< (point) (cdr (first footnote-text-marker-alist))))
>     ad-do-it
>    (message "Add footnotes only while in text body")))

I don't see how this relates to this new alignment feature.


        Stefan