[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Footnote-mode]: alignment option [CODE included]
From: |
Stefan Monnier |
Subject: |
Re: [Footnote-mode]: alignment option [CODE included] |
Date: |
Fri, 08 Dec 2017 11:50:43 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> 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