diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-06-09 09:43:49 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-06-09 09:43:49 +0200 |
commit | 9a8506b7affd9332f86d74024c44e86c6b1e9af7 (patch) | |
tree | 20e418ce358b088867265523fcb7c09b6fe6069e | |
parent | 9fdc77a3cdd28f35c4e053d4282dc644477b2478 (diff) | |
download | org-mode-9a8506b7affd9332f86d74024c44e86c6b1e9af7.tar.gz |
org-footnote: Fix footnote deletion
* lisp/org-footnote.el (org-footnote-delete-definitions): Preserve
blank lines after the definition.
* testing/lisp/test-org-footnote.el (test-org-footnote/delete): Add
test.
-rw-r--r-- | lisp/org-footnote.el | 20 | ||||
-rw-r--r-- | testing/lisp/test-org-footnote.el | 11 |
2 files changed, 22 insertions, 9 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index e6a3321..af03fbf 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -712,14 +712,18 @@ Return the number of footnotes removed." (let ((def-re (format "^\\[fn:%s\\]" (regexp-quote label))) (ndef 0)) (while (re-search-forward def-re nil t) - (let ((full-def (org-footnote-at-definition-p))) - (when full-def - ;; Remove the footnote, and all blank lines before it. - (goto-char (nth 1 full-def)) - (skip-chars-backward " \r\t\n") - (unless (bolp) (forward-line)) - (delete-region (point) (nth 2 full-def)) - (cl-incf ndef)))) + (pcase (org-footnote-at-definition-p) + (`(,_ ,start ,end ,_) + ;; Remove the footnote, and all blank lines before it. + (delete-region (progn + (goto-char start) + (skip-chars-backward " \r\t\n") + (if (bobp) (point) (line-beginning-position 2))) + (progn + (goto-char end) + (skip-chars-backward " \r\t\n") + (if (bobp) (point) (line-beginning-position 2)))) + (cl-incf ndef)))) ndef))) (defun org-footnote-delete (&optional label) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index 253f4ee..b2347cb 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -166,7 +166,16 @@ (org-test-with-temp-text "Para[fn:1]\n\n[fn:1] para1\n\npara2\n\n\nOutside footnote." (org-footnote-delete "1") - (org-trim (buffer-string))))))) + (org-trim (buffer-string)))))) + ;; Remove blank lines above the footnote but preserve those after + ;; it. + (should + (equal "Text\n\n\nOther text." + (let ((org-footnote-section nil)) + (org-test-with-temp-text + "Text[fn:1]\n\n[fn:1] Definition.\n\n\nOther text." + (org-footnote-delete "1") + (buffer-string)))))) (ert-deftest test-org-footnote/goto-definition () "Test `org-footnote-goto-definition' specifications." |