Skip to content

Instantly share code, notes, and snippets.

@Klinkenstecker
Created July 23, 2015 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Klinkenstecker/8e21c8b36b2ddd91a073 to your computer and use it in GitHub Desktop.
Save Klinkenstecker/8e21c8b36b2ddd91a073 to your computer and use it in GitHub Desktop.
(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