Skip to content

Commit

Permalink
More efficient code matching function
Browse files Browse the repository at this point in the history
  • Loading branch information
jrblevin committed Dec 15, 2015
1 parent 9b75ef6 commit 23113fa
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2293,17 +2293,25 @@ GFM quoted code blocks. Calls `markdown-code-block-at-pos-p'."
"Match inline code from the point to LAST."
(unless (bobp)
(backward-char 1))
(cond ((and (re-search-forward markdown-regex-code last t)
(goto-char (match-beginning 0))
(not (markdown-code-block-at-point-p))
(goto-char (match-end 0)))
(set-match-data (list (match-beginning 1) (match-end 1)
(match-beginning 2) (match-end 2)
(match-beginning 3) (match-end 3)
(match-beginning 4) (match-end 4)))
(goto-char (match-end 0))
t)
(t (forward-char 2) nil)))
(when (re-search-forward markdown-regex-code last t)
(cond
;; In code block: move past it and recursively search again
((markdown-code-block-at-point-p)
(while (and (markdown-code-block-at-point-p)
(< (point) (point-max)))
(markdown-end-of-block))
(when (and (< (point) last))
(markdown-match-code last)))
;; End of match out of range: return nil
((> (match-end 0) last)
nil)
;; Found: set match data and move point
(t
(set-match-data (list (match-beginning 1) (match-end 1)
(match-beginning 2) (match-end 2)
(match-beginning 3) (match-end 3)
(match-beginning 4) (match-end 4)))
(goto-char (1+ (match-end 0)))))))

(defun markdown-match-propertized-text (property last)
"Match text with PROPERTY from point to LAST.
Expand Down

0 comments on commit 23113fa

Please sign in to comment.