Skip to content

Commit

Permalink
Insert references before local variables
Browse files Browse the repository at this point in the history
Fixes #216
  • Loading branch information
phst committed Sep 23, 2017
1 parent 7050c4d commit 463a9b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4367,6 +4367,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"))
Expand Down
20 changes: 20 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,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 "

<!-- Local Variables: -->
<!-- mode: markdown -->
<!-- End: -->
"
(markdown-insert-reference-link "link" "" "http://jblevins.org/")
(should (equal (buffer-substring-no-properties 1 (point-max))
"[link][]

\[link]: http://jblevins.org/

<!-- Local Variables: -->
<!-- mode: markdown -->
<!-- End: -->
"))
(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\")"
Expand Down

0 comments on commit 463a9b9

Please sign in to comment.