diff options
| author | Stefan Monnier | 2019-05-01 13:14:31 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-05-01 13:14:31 -0400 |
| commit | c9b820ddcfb7e44b4aa1ac349de9cf8453bca6bd (patch) | |
| tree | 81386134a0f3fba3782a4f6469e6be1ab6b161c4 | |
| parent | d4fa998c3142b5ae13664295dcf2136397b05f5a (diff) | |
| download | emacs-c9b820ddcfb7e44b4aa1ac349de9cf8453bca6bd.tar.gz emacs-c9b820ddcfb7e44b4aa1ac349de9cf8453bca6bd.zip | |
* lisp/mail/footnote.el: Minor simplifications
Remove redundant :group args.
(footnote-mode-hook): Let define-minor-mode define it.
(footnote--style-p): Delete function.
(footnote--index-to-string): Inline it instead, and simplify.
(footnote-cycle-style): Use a pointer into the alist as the "index"
instead of a number.
(footnote-set-style): Use footnote-style-alist as the completion table.
Prefer `assq` over `footnote--assoc-index`.
(footnote--assoc-index): Delete function.
(footnote--renumber): Remove first (unused) argument; Adjust all callers.
(footnote--sort): Use car-less-than-car.
| -rw-r--r-- | lisp/mail/footnote.el | 98 |
1 files changed, 31 insertions, 67 deletions
diff --git a/lisp/mail/footnote.el b/lisp/mail/footnote.el index 81dc11de763..a1e909cee70 100644 --- a/lisp/mail/footnote.el +++ b/lisp/mail/footnote.el | |||
| @@ -73,50 +73,38 @@ | |||
| 73 | 73 | ||
| 74 | (defcustom footnote-mode-line-string " FN" | 74 | (defcustom footnote-mode-line-string " FN" |
| 75 | "String to display in modes section of the mode-line." | 75 | "String to display in modes section of the mode-line." |
| 76 | :type 'string | 76 | :type 'string) |
| 77 | :group 'footnote) | ||
| 78 | |||
| 79 | (defcustom footnote-mode-hook nil | ||
| 80 | "Hook functions run when footnote-mode is activated." | ||
| 81 | :type 'hook | ||
| 82 | :group 'footnote) | ||
| 83 | 77 | ||
| 84 | (defcustom footnote-narrow-to-footnotes-when-editing nil | 78 | (defcustom footnote-narrow-to-footnotes-when-editing nil |
| 85 | "If non-nil, narrow to footnote text body while editing a footnote." | 79 | "If non-nil, narrow to footnote text body while editing a footnote." |
| 86 | :type 'boolean | 80 | :type 'boolean) |
| 87 | :group 'footnote) | ||
| 88 | 81 | ||
| 89 | (defcustom footnote-prompt-before-deletion t | 82 | (defcustom footnote-prompt-before-deletion t |
| 90 | "If non-nil, prompt before deleting a footnote. | 83 | "If non-nil, prompt before deleting a footnote. |
| 91 | There is currently no way to undo deletions." | 84 | There is currently no way to undo deletions." |
| 92 | :type 'boolean | 85 | :type 'boolean) |
| 93 | :group 'footnote) | ||
| 94 | 86 | ||
| 95 | (defcustom footnote-spaced-footnotes t | 87 | (defcustom footnote-spaced-footnotes t |
| 96 | "If non-nil, insert an empty line between footnotes. | 88 | "If non-nil, insert an empty line between footnotes. |
| 97 | Customizing this variable has no effect on buffers already | 89 | Customizing this variable has no effect on buffers already |
| 98 | displaying footnotes." | 90 | displaying footnotes." |
| 99 | :type 'boolean | 91 | :type 'boolean) |
| 100 | :group 'footnote) | ||
| 101 | 92 | ||
| 102 | (defcustom footnote-use-message-mode t ; Nowhere used. | 93 | (defcustom footnote-use-message-mode t ; Nowhere used. |
| 103 | "If non-nil, assume Footnoting will be done in `message-mode'." | 94 | "If non-nil, assume Footnoting will be done in `message-mode'." |
| 104 | :type 'boolean | 95 | :type 'boolean) |
| 105 | :group 'footnote) | ||
| 106 | 96 | ||
| 107 | (defcustom footnote-body-tag-spacing 2 | 97 | (defcustom footnote-body-tag-spacing 2 |
| 108 | "Number of spaces separating a footnote body tag and its text. | 98 | "Number of spaces separating a footnote body tag and its text. |
| 109 | Customizing this variable has no effect on buffers already | 99 | Customizing this variable has no effect on buffers already |
| 110 | displaying footnotes." | 100 | displaying footnotes." |
| 111 | :type 'integer | 101 | :type 'integer) |
| 112 | :group 'footnote) | ||
| 113 | 102 | ||
| 114 | (defcustom footnote-prefix [(control ?c) ?!] | 103 | (defcustom footnote-prefix [(control ?c) ?!] |
| 115 | "Prefix key to use for Footnote command in Footnote minor mode. | 104 | "Prefix key to use for Footnote command in Footnote minor mode. |
| 116 | The value of this variable is checked as part of loading Footnote mode. | 105 | The value of this variable is checked as part of loading Footnote mode. |
| 117 | After that, changing the prefix key requires manipulating keymaps." | 106 | After that, changing the prefix key requires manipulating keymaps." |
| 118 | :type 'key-sequence | 107 | :type 'key-sequence) |
| 119 | :group 'footnote) | ||
| 120 | 108 | ||
| 121 | ;;; Interface variables that probably shouldn't be changed | 109 | ;;; Interface variables that probably shouldn't be changed |
| 122 | 110 | ||
| @@ -127,8 +115,7 @@ value of `footnote-section-tag-regexp' is ignored. Customizing | |||
| 127 | this variable has no effect on buffers already displaying | 115 | this variable has no effect on buffers already displaying |
| 128 | footnotes." | 116 | footnotes." |
| 129 | :version "27.1" | 117 | :version "27.1" |
| 130 | :type 'string | 118 | :type 'string) |
| 131 | :group 'footnote) | ||
| 132 | 119 | ||
| 133 | (defcustom footnote-section-tag-regexp | 120 | (defcustom footnote-section-tag-regexp |
| 134 | ;; Even if `footnote-section-tag' has a trailing space, let's not require it | 121 | ;; Even if `footnote-section-tag' has a trailing space, let's not require it |
| @@ -139,31 +126,27 @@ This variable is disregarded when `footnote-section-tag' is the | |||
| 139 | empty string. Customizing this variable has no effect on buffers | 126 | empty string. Customizing this variable has no effect on buffers |
| 140 | already displaying footnotes." | 127 | already displaying footnotes." |
| 141 | :version "27.1" | 128 | :version "27.1" |
| 142 | :type 'regexp | 129 | :type 'regexp) |
| 143 | :group 'footnote) | ||
| 144 | 130 | ||
| 145 | ;; The following three should be consumed by footnote styles. | 131 | ;; The following three should be consumed by footnote styles. |
| 146 | (defcustom footnote-start-tag "[" | 132 | (defcustom footnote-start-tag "[" |
| 147 | "String used to denote start of numbered footnote. | 133 | "String used to denote start of numbered footnote. |
| 148 | Should not be set to the empty string. Customizing this variable | 134 | Should not be set to the empty string. Customizing this variable |
| 149 | has no effect on buffers already displaying footnotes." | 135 | has no effect on buffers already displaying footnotes." |
| 150 | :type 'string | 136 | :type 'string) |
| 151 | :group 'footnote) | ||
| 152 | 137 | ||
| 153 | (defcustom footnote-end-tag "]" | 138 | (defcustom footnote-end-tag "]" |
| 154 | "String used to denote end of numbered footnote. | 139 | "String used to denote end of numbered footnote. |
| 155 | Should not be set to the empty string. Customizing this variable | 140 | Should not be set to the empty string. Customizing this variable |
| 156 | has no effect on buffers already displaying footnotes." | 141 | has no effect on buffers already displaying footnotes." |
| 157 | :type 'string | 142 | :type 'string) |
| 158 | :group 'footnote) | ||
| 159 | 143 | ||
| 160 | (defcustom footnote-signature-separator | 144 | (defcustom footnote-signature-separator |
| 161 | (if (boundp 'message-signature-separator) | 145 | (if (boundp 'message-signature-separator) |
| 162 | message-signature-separator | 146 | message-signature-separator |
| 163 | "^-- $") | 147 | "^-- $") |
| 164 | "Regexp used by Footnote mode to recognize signatures." | 148 | "Regexp used by Footnote mode to recognize signatures." |
| 165 | :type 'regexp | 149 | :type 'regexp) |
| 166 | :group 'footnote) | ||
| 167 | 150 | ||
| 168 | (defcustom footnote-align-to-fn-text t | 151 | (defcustom footnote-align-to-fn-text t |
| 169 | "How to left-align footnote text. | 152 | "How to left-align footnote text. |
| @@ -187,6 +170,8 @@ left with the first character of footnote text." | |||
| 187 | (make-variable-buffer-local 'footnote-pointer-marker-alist) | 170 | (make-variable-buffer-local 'footnote-pointer-marker-alist) |
| 188 | 171 | ||
| 189 | (defvar footnote-mouse-highlight 'highlight | 172 | (defvar footnote-mouse-highlight 'highlight |
| 173 | ;; FIXME: This `highlight' property is not currently used. | ||
| 174 | ;; We should use `mouse-face' and make mouse clicks work on them. | ||
| 190 | "Text property name to enable mouse over highlight.") | 175 | "Text property name to enable mouse over highlight.") |
| 191 | 176 | ||
| 192 | (defvar footnote-mode) | 177 | (defvar footnote-mode) |
| @@ -441,20 +426,15 @@ Customizing this variable has no effect on buffers already | |||
| 441 | displaying footnotes. To change the style of footnotes in such a | 426 | displaying footnotes. To change the style of footnotes in such a |
| 442 | buffer use the command `footnote-set-style'." | 427 | buffer use the command `footnote-set-style'." |
| 443 | :type (cons 'choice (mapcar (lambda (x) (list 'const (car x))) | 428 | :type (cons 'choice (mapcar (lambda (x) (list 'const (car x))) |
| 444 | footnote-style-alist)) | 429 | footnote-style-alist))) |
| 445 | :group 'footnote) | ||
| 446 | 430 | ||
| 447 | ;;; Style utilities & functions | 431 | ;;; Style utilities & functions |
| 448 | (defun footnote--style-p (style) | ||
| 449 | "Return non-nil if style is a valid style known to `footnote-mode'." | ||
| 450 | (assq style footnote-style-alist)) | ||
| 451 | 432 | ||
| 452 | (defun footnote--index-to-string (index) | 433 | (defun footnote--index-to-string (index) |
| 453 | "Convert a binary index into a string to display as a footnote. | 434 | "Convert a binary index into a string to display as a footnote. |
| 454 | Conversion is done based upon the current selected style." | 435 | Conversion is done based upon the current selected style." |
| 455 | (let ((alist (if (footnote--style-p footnote-style) | 436 | (let ((alist (or (assq footnote-style footnote-style-alist) |
| 456 | (assq footnote-style footnote-style-alist) | 437 | (nth 0 footnote-style-alist)))) |
| 457 | (nth 0 footnote-style-alist)))) | ||
| 458 | (funcall (nth 1 alist) index))) | 438 | (funcall (nth 1 alist) index))) |
| 459 | 439 | ||
| 460 | (defun footnote--current-regexp () | 440 | (defun footnote--current-regexp () |
| @@ -522,41 +502,27 @@ styles." | |||
| 522 | nil "\\1")) | 502 | nil "\\1")) |
| 523 | (setq i (1+ i)))))) | 503 | (setq i (1+ i)))))) |
| 524 | 504 | ||
| 525 | (defun footnote--assoc-index (key alist) | ||
| 526 | "Give index of key in alist." | ||
| 527 | (let ((i 0) (max (length alist)) rc) | ||
| 528 | (while (and (null rc) | ||
| 529 | (< i max)) | ||
| 530 | (when (eq key (car (nth i alist))) | ||
| 531 | (setq rc i)) | ||
| 532 | (setq i (1+ i))) | ||
| 533 | rc)) | ||
| 534 | |||
| 535 | (defun footnote-cycle-style () | 505 | (defun footnote-cycle-style () |
| 536 | "Select next defined footnote style." | 506 | "Select next defined footnote style." |
| 537 | (interactive) | 507 | (interactive) |
| 538 | (let ((old (footnote--assoc-index footnote-style footnote-style-alist)) | 508 | (let ((old-desc (assq footnote-style footnote-style-alist))) |
| 539 | (max (length footnote-style-alist)) | 509 | (setq footnote-style (caar (or (cdr (memq old-desc footnote-style-alist)) |
| 540 | idx) | 510 | footnote-style-alist))) |
| 541 | (setq idx (1+ old)) | 511 | (footnote--refresh-footnotes (nth 2 old-desc)))) |
| 542 | (when (>= idx max) | 512 | |
| 543 | (setq idx 0)) | 513 | (defun footnote-set-style (style) |
| 544 | (setq footnote-style (car (nth idx footnote-style-alist))) | ||
| 545 | (footnote--refresh-footnotes (nth 2 (nth old footnote-style-alist))))) | ||
| 546 | |||
| 547 | (defun footnote-set-style (&optional style) | ||
| 548 | "Select a specific style." | 514 | "Select a specific style." |
| 549 | (interactive | 515 | (interactive |
| 550 | (list (intern (completing-read | 516 | (list (intern (completing-read |
| 551 | "Footnote Style: " | 517 | "Footnote Style: " |
| 552 | obarray #'footnote--style-p 'require-match)))) | 518 | footnote-style-alist nil 'require-match)))) |
| 553 | (let ((old (footnote--assoc-index footnote-style footnote-style-alist))) | 519 | (let ((old-desc (assq footnote-style footnote-style-alist))) |
| 554 | (setq footnote-style style) | 520 | (setq footnote-style style) |
| 555 | (footnote--refresh-footnotes (nth 2 (nth old footnote-style-alist))))) | 521 | (footnote--refresh-footnotes (nth 2 old-desc)))) |
| 556 | 522 | ||
| 557 | ;; Internal functions | 523 | ;; Internal functions |
| 558 | (defun footnote--insert-numbered-footnote (arg &optional mousable) | 524 | (defun footnote--insert-numbered-footnote (arg &optional mousable) |
| 559 | "Insert numbered footnote at (point)." | 525 | "Insert numbered footnote at point." |
| 560 | (let ((string (concat footnote-start-tag | 526 | (let ((string (concat footnote-start-tag |
| 561 | (footnote--index-to-string arg) | 527 | (footnote--index-to-string arg) |
| 562 | footnote-end-tag))) | 528 | footnote-end-tag))) |
| @@ -566,7 +532,7 @@ styles." | |||
| 566 | string 'footnote-number arg footnote-mouse-highlight t) | 532 | string 'footnote-number arg footnote-mouse-highlight t) |
| 567 | (propertize string 'footnote-number arg))))) | 533 | (propertize string 'footnote-number arg))))) |
| 568 | 534 | ||
| 569 | (defun footnote--renumber (_from to pointer-alist text-alist) | 535 | (defun footnote--renumber (to pointer-alist text-alist) |
| 570 | "Renumber a single footnote." | 536 | "Renumber a single footnote." |
| 571 | (let* ((posn-list (cdr pointer-alist))) | 537 | (let* ((posn-list (cdr pointer-alist))) |
| 572 | (setcar pointer-alist to) | 538 | (setcar pointer-alist to) |
| @@ -675,8 +641,7 @@ styles." | |||
| 675 | (footnote--insert-text-marker arg old-point))) | 641 | (footnote--insert-text-marker arg old-point))) |
| 676 | 642 | ||
| 677 | (defun footnote--sort (list) | 643 | (defun footnote--sort (list) |
| 678 | (sort list (lambda (e1 e2) | 644 | (sort list #'car-less-than-car)) |
| 679 | (< (car e1) (car e2))))) | ||
| 680 | 645 | ||
| 681 | (defun footnote--text-under-cursor () | 646 | (defun footnote--text-under-cursor () |
| 682 | "Return the number of the current footnote if in footnote text. | 647 | "Return the number of the current footnote if in footnote text. |
| @@ -795,8 +760,7 @@ footnote area, returns `point-max'." | |||
| 795 | (footnote--index-to-string (car alist-ptr)) | 760 | (footnote--index-to-string (car alist-ptr)) |
| 796 | (footnote--index-to-string | 761 | (footnote--index-to-string |
| 797 | (1+ (car alist-ptr)))) | 762 | (1+ (car alist-ptr)))) |
| 798 | (footnote--renumber (car alist-ptr) | 763 | (footnote--renumber (1+ (car alist-ptr)) |
| 799 | (1+ (car alist-ptr)) | ||
| 800 | alist-ptr | 764 | alist-ptr |
| 801 | alist-txt))) | 765 | alist-txt))) |
| 802 | (setq i (1+ i))) | 766 | (setq i (1+ i))) |
| @@ -900,7 +864,7 @@ delete the footnote with that number." | |||
| 900 | (setq alist-ptr (nth i footnote-pointer-marker-alist)) | 864 | (setq alist-ptr (nth i footnote-pointer-marker-alist)) |
| 901 | (setq alist-txt (nth i footnote-text-marker-alist)) | 865 | (setq alist-txt (nth i footnote-text-marker-alist)) |
| 902 | (unless (= (1+ i) (car alist-ptr)) | 866 | (unless (= (1+ i) (car alist-ptr)) |
| 903 | (footnote--renumber (car alist-ptr) (1+ i) alist-ptr alist-txt)) | 867 | (footnote--renumber (1+ i) alist-ptr alist-txt)) |
| 904 | (setq i (1+ i)))))) | 868 | (setq i (1+ i)))))) |
| 905 | 869 | ||
| 906 | (defun footnote-goto-footnote (&optional arg) | 870 | (defun footnote-goto-footnote (&optional arg) |