aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoruch Baum2017-12-22 23:06:22 -0500
committerStefan Monnier2017-12-22 23:06:22 -0500
commitc7a50740273a338285abe7c9bb24a1f45928e02a (patch)
tree66363b9a69476c57adf732f6f0337460b7072853
parent57d54a0edd0c59fbd09efd826db1ef2b3f41b902 (diff)
downloademacs-c7a50740273a338285abe7c9bb24a1f45928e02a.tar.gz
emacs-c7a50740273a338285abe7c9bb24a1f45928e02a.zip
* lisp/mail/footnote.el (footnote-align-to-fn-text): New config var
(footnote-mode): Declare. (Footnote--get-area-point-min): Fix last change to use 'car` instead of the undefined 'first'. (Footnote--calc-fn-alignment-column, Footnote--fill-prefix-string) (Footnote--adaptive-fill-function): New functions. (footnote-mode): Use them.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/mail/footnote.el61
2 files changed, 59 insertions, 7 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 714e964c967..1f8fe67152f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -87,6 +87,11 @@ strings in non-text modes.
87 87
88* Changes in Specialized Modes and Packages in Emacs 27.1 88* Changes in Specialized Modes and Packages in Emacs 27.1
89 89
90** Footnote-mode
91*** Support Hebrew-style footnotes
92*** Footnote text lines are now aligned.
93Can be controlled via the new variable 'footnote-align-to-fn-text'.
94
90** CSS mode 95** CSS mode
91 96
92--- 97---
diff --git a/lisp/mail/footnote.el b/lisp/mail/footnote.el
index 272672904bf..adfe03d3061 100644
--- a/lisp/mail/footnote.el
+++ b/lisp/mail/footnote.el
@@ -156,13 +156,21 @@ has no effect on buffers already displaying footnotes."
156 :type 'string 156 :type 'string
157 :group 'footnote) 157 :group 'footnote)
158 158
159(defcustom footnote-signature-separator (if (boundp 'message-signature-separator) 159(defcustom footnote-signature-separator
160 message-signature-separator 160 (if (boundp 'message-signature-separator)
161 "^-- $") 161 message-signature-separator
162 "^-- $")
162 "Regexp used by Footnote mode to recognize signatures." 163 "Regexp used by Footnote mode to recognize signatures."
163 :type 'regexp 164 :type 'regexp
164 :group 'footnote) 165 :group 'footnote)
165 166
167(defcustom footnote-align-to-fn-text t
168 "If non-nil, align footnote text lines.
169If nil, footnote text lines are to be aligned flush left with left side
170of the footnote number. If non-nil footnote text lines are to be aligned
171with the first character of footnote text."
172 :type 'boolean)
173
166;;; Private variables 174;;; Private variables
167 175
168(defvar footnote-style-number nil 176(defvar footnote-style-number nil
@@ -180,6 +188,8 @@ has no effect on buffers already displaying footnotes."
180(defvar footnote-mouse-highlight 'highlight 188(defvar footnote-mouse-highlight 'highlight
181 "Text property name to enable mouse over highlight.") 189 "Text property name to enable mouse over highlight.")
182 190
191(defvar footnote-mode)
192
183;;; Default styles 193;;; Default styles
184;;; NUMERIC 194;;; NUMERIC
185(defconst footnote-numeric-regexp "[0-9]+" 195(defconst footnote-numeric-regexp "[0-9]+"
@@ -675,6 +685,22 @@ Return nil if the cursor is not over a footnote."
675 (or (get-text-property (point) 'footnote-number) 685 (or (get-text-property (point) 'footnote-number)
676 (Footnote-text-under-cursor))) 686 (Footnote-text-under-cursor)))
677 687
688(defun Footnote--calc-fn-alignment-column ()
689 "Calculate the left alignment for footnote text."
690 ;; FIXME: Maybe it would be better to go to the footnote's beginning and
691 ;; see at which column it starts.
692 (+ footnote-body-tag-spacing
693 (string-width
694 (concat footnote-start-tag footnote-end-tag
695 (Footnote-index-to-string
696 (caar (last footnote-text-marker-alist)))))))
697
698(defun Footnote--fill-prefix-string ()
699 "Return the fill prefix to be used by footnote mode."
700 ;; TODO: Prefix to this value other prefix strings, such as those
701 ;; designating a comment line, a message response, or a boxquote.
702 (make-string (Footnote--calc-fn-alignment-column) ?\s))
703
678(defun Footnote--point-in-body-p () 704(defun Footnote--point-in-body-p ()
679 "Return non-nil if point is in the buffer text area, 705 "Return non-nil if point is in the buffer text area,
680i.e. before the beginning of the footnote area." 706i.e. before the beginning of the footnote area."
@@ -688,12 +714,12 @@ instead, if applicable."
688 (cond 714 (cond
689 ;; FIXME: Shouldn't we use `Footnote--get-area-point-max' instead? 715 ;; FIXME: Shouldn't we use `Footnote--get-area-point-max' instead?
690 ((not footnote-text-marker-alist) (point-max)) 716 ((not footnote-text-marker-alist) (point-max))
691 ((not before-tag) (cdr (first footnote-text-marker-alist))) 717 ((not before-tag) (cdr (car footnote-text-marker-alist)))
692 ((string-equal footnote-section-tag "") 718 ((string-equal footnote-section-tag "")
693 (cdr (first footnote-text-marker-alist))) 719 (cdr (car footnote-text-marker-alist)))
694 (t 720 (t
695 (save-excursion 721 (save-excursion
696 (goto-char (cdr (first footnote-text-marker-alist))) 722 (goto-char (cdr (car footnote-text-marker-alist)))
697 (if (re-search-backward (concat "^" footnote-section-tag-regexp) nil t) 723 (if (re-search-backward (concat "^" footnote-section-tag-regexp) nil t)
698 (match-beginning 0) 724 (match-beginning 0)
699 (message "Footnote section tag not found!") 725 (message "Footnote section tag not found!")
@@ -713,7 +739,7 @@ instead, if applicable."
713 ;; function, and repeat. 739 ;; function, and repeat.
714 ;; 740 ;;
715 ;; TODO: integrate sanity checks at reasonable operational points. 741 ;; TODO: integrate sanity checks at reasonable operational points.
716 (cdr (first footnote-text-marker-alist))))))) 742 (cdr (car footnote-text-marker-alist)))))))
717 743
718(defun Footnote--get-area-point-max () 744(defun Footnote--get-area-point-max ()
719 "Return the end of footnote area. 745 "Return the end of footnote area.
@@ -722,6 +748,18 @@ defined by variable `footnote-signature-separator'. If there is no
722footnote area, returns `point-max'." 748footnote area, returns `point-max'."
723 (save-excursion (Footnote-goto-char-point-max))) 749 (save-excursion (Footnote-goto-char-point-max)))
724 750
751(defun Footnote--adaptive-fill-function (orig-fun)
752 (or
753 (and
754 footnote-mode
755 footnote-align-to-fn-text
756 (Footnote-text-under-cursor)
757 ;; (not (Footnote--point-in-body-p))
758 ;; (< (point) (Footnote--signature-area-start-point))
759 (Footnote--fill-prefix-string))
760 ;; If not within a footnote's text, fallback to the default.
761 (funcall orig-fun)))
762
725;;; User functions 763;;; User functions
726 764
727(defun Footnote-make-hole () 765(defun Footnote-make-hole ()
@@ -913,6 +951,12 @@ play around with the following keys:
913 :lighter footnote-mode-line-string 951 :lighter footnote-mode-line-string
914 :keymap footnote-minor-mode-map 952 :keymap footnote-minor-mode-map
915 ;; (filladapt-mode t) 953 ;; (filladapt-mode t)
954 (unless adaptive-fill-function
955 ;; nil and `ignore' have the same semantics for adaptive-fill-function,
956 ;; but only `ignore' behaves correctly with add/remove-function.
957 (setq adaptive-fill-function #'ignore))
958 (remove-function (local 'adaptive-fill-function)
959 #'Footnote--adaptive-fill-function)
916 (when footnote-mode 960 (when footnote-mode
917 ;; (Footnote-setup-keybindings) 961 ;; (Footnote-setup-keybindings)
918 (make-local-variable 'footnote-style) 962 (make-local-variable 'footnote-style)
@@ -922,6 +966,9 @@ play around with the following keys:
922 (make-local-variable 'footnote-section-tag-regexp) 966 (make-local-variable 'footnote-section-tag-regexp)
923 (make-local-variable 'footnote-start-tag) 967 (make-local-variable 'footnote-start-tag)
924 (make-local-variable 'footnote-end-tag) 968 (make-local-variable 'footnote-end-tag)
969 (make-local-variable 'adaptive-fill-function)
970 (add-function :around (local 'adaptive-fill-function)
971 #'Footnote--adaptive-fill-function)
925 972
926 ;; filladapt is an XEmacs package which AFAIK has never been ported 973 ;; filladapt is an XEmacs package which AFAIK has never been ported
927 ;; to Emacs. 974 ;; to Emacs.