Skip to content

Commit

Permalink
update with comments from @syohex
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny McClanahan committed Feb 9, 2016
1 parent 9bb2523 commit 99a4207
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
26 changes: 13 additions & 13 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2635,15 +2635,16 @@ analysis."

(defun markdown-get-match-boundaries (start-header end-header last &optional pos)
(save-excursion
(goto-char (if pos pos (point-min)))
(goto-char (or pos (point-min)))
(cl-loop
with cur-result = nil
and st-hdr = (or start-header "\\`")
and end-hdr = (or end-header "\n\n\\|\n\\'\\|\\'")
while (and (< (point) last)
(re-search-forward (or start-header "\\`") last t)
(re-search-forward st-hdr last t)
(progn
(setq cur-result (match-data))
(re-search-forward
(or end-header "\n\n\\|\n\\'\\|\\'") nil t)))
(re-search-forward end-hdr nil t)))
collect (list cur-result (match-data)))))

(defvar markdown-conditional-search-function #'re-search-forward
Expand All @@ -2663,15 +2664,14 @@ into a variable to allow for dynamic let-binding.")
(let* ((header-bounds
(markdown-get-match-boundaries start-header end-header last))
(enclosing-header
(cl-first ; just take first if multiple (maybe impossible)
(cl-remove-if-not
(lambda (match-bounds)
(cl-destructuring-bind (start-match end-match) match-bounds
(and
(< (point) (cl-first end-match))
(save-excursion
(re-search-forward regexp (cl-second end-match) t)))))
header-bounds)))
(cl-find-if ; just take first if multiple
(lambda (match-bounds)
(cl-destructuring-bind (start-match end-match) match-bounds
(and
(< (point) (cl-first end-match))
(save-excursion
(re-search-forward regexp (cl-second end-match) t)))))
header-bounds))
(header-begin
(when enclosing-header (cl-second (cl-first enclosing-header))))
(header-end
Expand Down
9 changes: 3 additions & 6 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2252,8 +2252,7 @@ for (var i = 0; i < 10; i++) {

(ert-deftest test-markdown-font-lock/mmd-metadata ()
"Basic MultMarkdown metadata tests."
(markdown-test-string
"Title: peg-multimarkdown User's Guide
(markdown-test-string "Title: peg-multimarkdown User's Guide
Author: Fletcher T. Penney
Base Header Level: 2 "
(markdown-test-range-has-face 1 5 markdown-metadata-key-face)
Expand All @@ -2271,8 +2270,7 @@ Base Header Level: 2 "

(ert-deftest test-markdown-font-lock/mmd-metadata-after-header ()
"Ensure that similar lines are not matched after the header."
(markdown-test-string
"Title: peg-multimarkdown User's Guide
(markdown-test-string "Title: peg-multimarkdown User's Guide
Author: Fletcher T. Penney
Base Header Level: 2 "
Expand All @@ -2284,8 +2282,7 @@ Base Header Level: 2 "

(ert-deftest test-markdown-font-lock/pandoc-metadata ()
"Basic Pandoc metadata tests."
(markdown-test-string
"% title
(markdown-test-string "% title
two-line title
% first author;
second author
Expand Down

0 comments on commit 99a4207

Please sign in to comment.