unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [Footnote-mode]: alignment option [CODE included]
@ 2017-12-07  6:18 Boruch Baum
  2017-12-08 16:50 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Boruch Baum @ 2017-12-07  6:18 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 798 bytes --]

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

[-- Attachment #2: footnote-snippet.el --]
[-- Type: text/plain, Size: 2471 bytes --]

;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
; Footnote behavior customization
; + left-align footnote text to first character of first paragraph,
;   not to left margin.
; + Instructions:
;   + toggle the feature using 'mode-map-prexic q' (usually 'C-c ! q')
;   + whenever you run `auto-fill' (M-q), it will act
;   + if you set visual-line-mode, it acts automatically
(require 'footnote)

(setq Footnote-align-to-fn-text t
      body-auto-fill-prefix nil)

(defun Footnote-calc-fn-alignment-column()
  (+ footnote-body-tag-spacing
    (length
       (concat footnote-start-tag  footnote-end-tag
         (Footnote-index-to-string
            (caar (last footnote-text-marker-alist)))))))

(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))))

(defun Footnote-align-to-body()
  (when (not Footnote-align-to-fn-text)
    (setq fill-prefix body-auto-fill-prefix)))

(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")))

(define-key footnote-mode-map
  (kbd "q") 'Footnote-toggle-alignment)

(defadvice Footnote-add-footnote (after update-auto-fill-prefix activate)
  (interactive)
  (Footnote-align-to-fn))

(defadvice Footnote-back-to-message (after restore-auto-fill-prefix
                                     activate)
  (interactive)
  (setq fill-prefix body-auto-fill-prefix))

(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")))
;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-18  0:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-07  6:18 [Footnote-mode]: alignment option [CODE included] Boruch Baum
2017-12-08 16:50 ` Stefan Monnier
     [not found]   ` <jwvbmiylnmn.fsf-monnier+gmane.emacs.devel@gnu.org>
2017-12-18  0:13     ` Boruch Baum

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).