From bc79248c605a5ebd01d96b26e5d5dba39bddcdc7 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sat, 23 Sep 2017 15:02:06 +0200 Subject: [PATCH] Insert references before local variables Fixes #216 --- markdown-mode.el | 8 ++++++++ tests/markdown-test.el | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/markdown-mode.el b/markdown-mode.el index 5a0535c..37a03e5 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -4376,6 +4376,14 @@ be used to populate the title attribute when converted to XHTML." (immediately (markdown-end-of-text-block)) (subtree (markdown-end-of-subtree)) (header (markdown-end-of-defun))) + ;; Skip backwards over local variables. This logic is similar to the one + ;; used in ‘hack-local-variables’. + (when (and enable-local-variables (eobp)) + (search-backward "\n\f" (max (- (point) 3000) (point-min)) :move) + (when (let ((case-fold-search t)) + (search-forward "Local Variables:" nil :move)) + (beginning-of-line 0) + (when (eq (char-before) ?\n) (backward-char)))) (unless (or (markdown-cur-line-blank-p) (thing-at-point-looking-at markdown-regex-reference-definition)) (insert "\n")) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 764ac6a..d753024 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -1134,6 +1134,26 @@ Test point position upon removal and insertion." (should (= (point) 38)) (should (looking-back "https://www.gnu.org/\n\\[2\\]: " nil))))) +(ert-deftest test-markdown-insertion/reference-link-before-file-locals () + "Test inserting a reference link before file-local variables." + (markdown-test-string " + + + + +" + (markdown-insert-reference-link "link" "" "http://jblevins.org/") + (should (equal (buffer-substring-no-properties 1 (point-max)) + "[link][] + +\[link]: http://jblevins.org/ + + + + +")) + (should (equal (point) 9)))) + (ert-deftest test-markdown-insertion/inline-to-reference-link () "Inline link to reference link conversion with tab completion." (markdown-test-string "[text](http://jblevins.org/ \"title\")" -- 2.11.4.GIT