aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-07-25 19:35:17 +0200
committerLars Ingebrigtsen2019-07-25 19:39:51 +0200
commite890d4b5d1795b6a02a1baeebb4ae98da0537671 (patch)
tree5dcd656df1abe4c56a2fa45da7f3c51e1a2a21aa
parent28d231dbbb1f71bf1836148bb52969c31a05fe71 (diff)
downloademacs-e890d4b5d1795b6a02a1baeebb4ae98da0537671.tar.gz
emacs-e890d4b5d1795b6a02a1baeebb4ae98da0537671.zip
Fix setting fill-paragraph-function in footnote-mode
* lisp/mail/footnote.el (footnote--local-advice): New macro refactored out from the code used to advice footnote--adaptive-fill-function in footnote-mode. (footnote-mode): Use it to advice both that variable and fill-paragraph-function (the latter to avoid overwriting the major mode's value) (bug#27775) (footnote--fill-paragraph): Adjust calling convention now that it's an :around advice.
-rw-r--r--lisp/mail/footnote.el36
1 files changed, 24 insertions, 12 deletions
diff --git a/lisp/mail/footnote.el b/lisp/mail/footnote.el
index 42ab35b6652..111aa7f3ea3 100644
--- a/lisp/mail/footnote.el
+++ b/lisp/mail/footnote.el
@@ -695,8 +695,9 @@ footnote area, returns `point-max'."
695 ;; If not within a footnote's text, fallback to the default. 695 ;; If not within a footnote's text, fallback to the default.
696 (funcall orig-fun))) 696 (funcall orig-fun)))
697 697
698(defun footnote--fill-paragraph (justify) 698(defun footnote--fill-paragraph (orig-fun justify)
699 (when (footnote--text-under-cursor) 699 (if (not (footnote--text-under-cursor))
700 (funcall orig-fun justify)
700 (let ((fill-paragraph-function nil) 701 (let ((fill-paragraph-function nil)
701 (fill-prefix (if footnote-align-to-fn-text 702 (fill-prefix (if footnote-align-to-fn-text
702 (footnote--fill-prefix-string) 703 (footnote--fill-prefix-string)
@@ -855,6 +856,23 @@ being set it is automatically widened."
855 map) 856 map)
856 "Keymap used for binding footnote minor mode.") 857 "Keymap used for binding footnote minor mode.")
857 858
859(defmacro footnote--local-advice (mode variable function)
860 "Add advice to a variable holding buffer-local functions.
861Typical use would be to advice variables like
862`fill-paragraph-function' from minor modes.
863
864MODE is the minor mode symbol, VARIABLE is the variable to get
865advice, and FUNCTION is what'll be added as an :around advice."
866 `(progn
867 (unless ,variable
868 ;; nil and `ignore' have the same semantics for adaptive-fill-function,
869 ;; but only `ignore' behaves correctly with add/remove-function.
870 (setq ,variable #'ignore))
871 (remove-function (local ',variable) #'function)
872 (when ,mode
873 (add-function :around (local ',variable)
874 #',function))))
875
858;;;###autoload 876;;;###autoload
859(define-minor-mode footnote-mode 877(define-minor-mode footnote-mode
860 "Toggle Footnote mode. 878 "Toggle Footnote mode.
@@ -865,13 +883,10 @@ play around with the following keys:
865\\{footnote-minor-mode-map}" 883\\{footnote-minor-mode-map}"
866 :lighter footnote-mode-line-string 884 :lighter footnote-mode-line-string
867 :keymap footnote-minor-mode-map 885 :keymap footnote-minor-mode-map
868 ;; (filladapt-mode t) 886 (footnote--local-advice footnote-mode adaptive-fill-function
869 (unless adaptive-fill-function 887 footnote--adaptive-fill-function)
870 ;; nil and `ignore' have the same semantics for adaptive-fill-function, 888 (footnote--local-advice footnote-mode fill-paragraph-function
871 ;; but only `ignore' behaves correctly with add/remove-function. 889 footnote--fill-paragraph)
872 (setq adaptive-fill-function #'ignore))
873 (remove-function (local 'adaptive-fill-function)
874 #'footnote--adaptive-fill-function)
875 (when footnote-mode 890 (when footnote-mode
876 ;; (footnote-setup-keybindings) 891 ;; (footnote-setup-keybindings)
877 (make-local-variable 'footnote-style) 892 (make-local-variable 'footnote-style)
@@ -882,9 +897,6 @@ play around with the following keys:
882 (make-local-variable 'footnote-start-tag) 897 (make-local-variable 'footnote-start-tag)
883 (make-local-variable 'footnote-end-tag) 898 (make-local-variable 'footnote-end-tag)
884 (make-local-variable 'adaptive-fill-function) 899 (make-local-variable 'adaptive-fill-function)
885 (add-function :around (local 'adaptive-fill-function)
886 #'footnote--adaptive-fill-function)
887 (setq-local fill-paragraph-function #'footnote--fill-paragraph)
888 900
889 ;; Filladapt was an XEmacs package which is now in GNU ELPA. 901 ;; Filladapt was an XEmacs package which is now in GNU ELPA.
890 (when (boundp 'filladapt-token-table) 902 (when (boundp 'filladapt-token-table)