Skip to content

Commit c9b820d

Browse files
committed
* 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.
1 parent d4fa998 commit c9b820d

File tree

1 file changed

+31
-67
lines changed

1 file changed

+31
-67
lines changed

lisp/mail/footnote.el

Lines changed: 31 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -73,50 +73,38 @@
7373

7474
(defcustom footnote-mode-line-string " FN"
7575
"String to display in modes section of the mode-line."
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)
76+
:type 'string)
8377

8478
(defcustom footnote-narrow-to-footnotes-when-editing nil
8579
"If non-nil, narrow to footnote text body while editing a footnote."
86-
:type 'boolean
87-
:group 'footnote)
80+
:type 'boolean)
8881

8982
(defcustom footnote-prompt-before-deletion t
9083
"If non-nil, prompt before deleting a footnote.
9184
There is currently no way to undo deletions."
92-
:type 'boolean
93-
:group 'footnote)
85+
:type 'boolean)
9486

9587
(defcustom footnote-spaced-footnotes t
9688
"If non-nil, insert an empty line between footnotes.
9789
Customizing this variable has no effect on buffers already
9890
displaying footnotes."
99-
:type 'boolean
100-
:group 'footnote)
91+
:type 'boolean)
10192

10293
(defcustom footnote-use-message-mode t ; Nowhere used.
10394
"If non-nil, assume Footnoting will be done in `message-mode'."
104-
:type 'boolean
105-
:group 'footnote)
95+
:type 'boolean)
10696

10797
(defcustom footnote-body-tag-spacing 2
10898
"Number of spaces separating a footnote body tag and its text.
10999
Customizing this variable has no effect on buffers already
110100
displaying footnotes."
111-
:type 'integer
112-
:group 'footnote)
101+
:type 'integer)
113102

114103
(defcustom footnote-prefix [(control ?c) ?!]
115104
"Prefix key to use for Footnote command in Footnote minor mode.
116105
The value of this variable is checked as part of loading Footnote mode.
117106
After that, changing the prefix key requires manipulating keymaps."
118-
:type 'key-sequence
119-
:group 'footnote)
107+
:type 'key-sequence)
120108

121109
;;; Interface variables that probably shouldn't be changed
122110

@@ -127,8 +115,7 @@ value of `footnote-section-tag-regexp' is ignored. Customizing
127115
this variable has no effect on buffers already displaying
128116
footnotes."
129117
:version "27.1"
130-
:type 'string
131-
:group 'footnote)
118+
:type 'string)
132119

133120
(defcustom footnote-section-tag-regexp
134121
;; 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
139126
empty string. Customizing this variable has no effect on buffers
140127
already displaying footnotes."
141128
:version "27.1"
142-
:type 'regexp
143-
:group 'footnote)
129+
:type 'regexp)
144130

145131
;; The following three should be consumed by footnote styles.
146132
(defcustom footnote-start-tag "["
147133
"String used to denote start of numbered footnote.
148134
Should not be set to the empty string. Customizing this variable
149135
has no effect on buffers already displaying footnotes."
150-
:type 'string
151-
:group 'footnote)
136+
:type 'string)
152137

153138
(defcustom footnote-end-tag "]"
154139
"String used to denote end of numbered footnote.
155140
Should not be set to the empty string. Customizing this variable
156141
has no effect on buffers already displaying footnotes."
157-
:type 'string
158-
:group 'footnote)
142+
:type 'string)
159143

160144
(defcustom footnote-signature-separator
161145
(if (boundp 'message-signature-separator)
162146
message-signature-separator
163147
"^-- $")
164148
"Regexp used by Footnote mode to recognize signatures."
165-
:type 'regexp
166-
:group 'footnote)
149+
:type 'regexp)
167150

168151
(defcustom footnote-align-to-fn-text t
169152
"How to left-align footnote text.
@@ -187,6 +170,8 @@ left with the first character of footnote text."
187170
(make-variable-buffer-local 'footnote-pointer-marker-alist)
188171

189172
(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.
190175
"Text property name to enable mouse over highlight.")
191176

192177
(defvar footnote-mode)
@@ -441,20 +426,15 @@ Customizing this variable has no effect on buffers already
441426
displaying footnotes. To change the style of footnotes in such a
442427
buffer use the command `footnote-set-style'."
443428
:type (cons 'choice (mapcar (lambda (x) (list 'const (car x)))
444-
footnote-style-alist))
445-
:group 'footnote)
429+
footnote-style-alist)))
446430

447431
;;; 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))
451432

452433
(defun footnote--index-to-string (index)
453434
"Convert a binary index into a string to display as a footnote.
454435
Conversion is done based upon the current selected style."
455-
(let ((alist (if (footnote--style-p footnote-style)
456-
(assq footnote-style footnote-style-alist)
457-
(nth 0 footnote-style-alist))))
436+
(let ((alist (or (assq footnote-style footnote-style-alist)
437+
(nth 0 footnote-style-alist))))
458438
(funcall (nth 1 alist) index)))
459439

460440
(defun footnote--current-regexp ()
@@ -522,41 +502,27 @@ styles."
522502
nil "\\1"))
523503
(setq i (1+ i))))))
524504

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-
535505
(defun footnote-cycle-style ()
536506
"Select next defined footnote style."
537507
(interactive)
538-
(let ((old (footnote--assoc-index footnote-style footnote-style-alist))
539-
(max (length footnote-style-alist))
540-
idx)
541-
(setq idx (1+ old))
542-
(when (>= idx max)
543-
(setq idx 0))
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)
508+
(let ((old-desc (assq footnote-style footnote-style-alist)))
509+
(setq footnote-style (caar (or (cdr (memq old-desc footnote-style-alist))
510+
footnote-style-alist)))
511+
(footnote--refresh-footnotes (nth 2 old-desc))))
512+
513+
(defun footnote-set-style (style)
548514
"Select a specific style."
549515
(interactive
550516
(list (intern (completing-read
551517
"Footnote Style: "
552-
obarray #'footnote--style-p 'require-match))))
553-
(let ((old (footnote--assoc-index footnote-style footnote-style-alist)))
518+
footnote-style-alist nil 'require-match))))
519+
(let ((old-desc (assq footnote-style footnote-style-alist)))
554520
(setq footnote-style style)
555-
(footnote--refresh-footnotes (nth 2 (nth old footnote-style-alist)))))
521+
(footnote--refresh-footnotes (nth 2 old-desc))))
556522

557523
;; Internal functions
558524
(defun footnote--insert-numbered-footnote (arg &optional mousable)
559-
"Insert numbered footnote at (point)."
525+
"Insert numbered footnote at point."
560526
(let ((string (concat footnote-start-tag
561527
(footnote--index-to-string arg)
562528
footnote-end-tag)))
@@ -566,7 +532,7 @@ styles."
566532
string 'footnote-number arg footnote-mouse-highlight t)
567533
(propertize string 'footnote-number arg)))))
568534

569-
(defun footnote--renumber (_from to pointer-alist text-alist)
535+
(defun footnote--renumber (to pointer-alist text-alist)
570536
"Renumber a single footnote."
571537
(let* ((posn-list (cdr pointer-alist)))
572538
(setcar pointer-alist to)
@@ -675,8 +641,7 @@ styles."
675641
(footnote--insert-text-marker arg old-point)))
676642

677643
(defun footnote--sort (list)
678-
(sort list (lambda (e1 e2)
679-
(< (car e1) (car e2)))))
644+
(sort list #'car-less-than-car))
680645

681646
(defun footnote--text-under-cursor ()
682647
"Return the number of the current footnote if in footnote text.
@@ -795,8 +760,7 @@ footnote area, returns `point-max'."
795760
(footnote--index-to-string (car alist-ptr))
796761
(footnote--index-to-string
797762
(1+ (car alist-ptr))))
798-
(footnote--renumber (car alist-ptr)
799-
(1+ (car alist-ptr))
763+
(footnote--renumber (1+ (car alist-ptr))
800764
alist-ptr
801765
alist-txt)))
802766
(setq i (1+ i)))
@@ -900,7 +864,7 @@ delete the footnote with that number."
900864
(setq alist-ptr (nth i footnote-pointer-marker-alist))
901865
(setq alist-txt (nth i footnote-text-marker-alist))
902866
(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))
904868
(setq i (1+ i))))))
905869

906870
(defun footnote-goto-footnote (&optional arg)

0 commit comments

Comments
 (0)