Created
July 23, 2015 10:27
-
-
Save Klinkenstecker/8e21c8b36b2ddd91a073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun origami-get-positions-eol (content regex open) | |
"Returns a list of positions where REGEX matches in CONTENT. A | |
position is a cons cell of the character and the numerical | |
position in the CONTENT." | |
(with-temp-buffer | |
(insert content) | |
(goto-char (point-min)) | |
(let (acc) | |
(while (re-search-forward regex nil t) | |
(let ((match (match-string 0)) | |
(text-at-point (buffer-substring-no-properties (- (point) (length open)) (point)))) | |
(if (string= text-at-point open) (move-end-of-line 1)) | |
(setq acc (cons (cons match (- (point) (length match))) | |
acc)))) | |
(reverse acc)))) | |
(defun origami-marker-parser (create) | |
(lambda (content) | |
(let ((positions (origami-get-positions-eol content "//{\\|//}" "//{"))) | |
(origami-build-pair-tree create "//{" "//}" positions)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment