Function: footnote-delete-footnote

footnote-delete-footnote is an interactive and byte-compiled function defined in footnote.el.gz.

Signature

(footnote-delete-footnote &optional ARG)

Documentation

Delete a numbered footnote.

With no parameter, delete the footnote under (point). With ARG specified, delete the footnote with that number.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/mail/footnote.el.gz
(defun footnote-delete-footnote (&optional arg)
  "Delete a numbered footnote.
With no parameter, delete the footnote under (point).  With ARG specified,
delete the footnote with that number."
  (interactive "*P")
  (unless arg
    (setq arg (footnote--under-cursor)))
  (when (and arg
	     (or (not footnote-prompt-before-deletion)
		 (y-or-n-p (format "Really delete footnote %d?" arg))))
    (let ((alist-elem (or (assq arg footnote--markers-alist)
                          (error "Can't delete footnote %d" arg)))
          (fn-regexp (footnote--current-regexp)))
      (dolist (locn (cddr alist-elem))
	(save-excursion
	  (goto-char locn)
	  (when (looking-at fn-regexp)
	    (delete-region (match-beginning 0) (match-end 0)))))
      (save-excursion
	(goto-char (cadr alist-elem))
	(delete-region
	 (point)
	 (if footnote-spaced-footnotes
	     (search-forward "\n\n" nil t)
           (save-restriction ; <= 2017-12 Boruch: WHY?? I see no narrowing / widening here.
	     (end-of-line)
	     (next-single-char-property-change
	      (point) 'footnote-number nil (footnote--goto-char-point-max))))))
      (setq footnote--markers-alist
	    (delq alist-elem footnote--markers-alist))
      (if footnote--markers-alist
          (footnote-renumber-footnotes)
	(save-excursion
	  (if (not (string-equal footnote-section-tag ""))
	      (let* ((end (footnote--goto-char-point-max))
		     (start (1- (re-search-backward
				 (concat "^" footnote-section-tag-regexp)
				 nil t))))
		(forward-line -1)
		(when (looking-at "\n")
		  (kill-line))
		(delete-region start (if (< end (point-max))
					 end
				       (point-max))))
	    (footnote--goto-char-point-max)
	    (when (looking-back "\n\n" (- (point) 2))
	      (kill-line -1))))))))