From 2673711f7c35b3f496635e93162968fc2ce97561 Mon Sep 17 00:00:00 2001 From: Greg Sexton Date: Mon, 25 Aug 2014 18:53:52 +0100 Subject: [PATCH] Improve the clojure parser --- origami-parsers.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/origami-parsers.el b/origami-parsers.el index 9bbbd05..fcfd81f 100644 --- a/origami-parsers.el +++ b/origami-parsers.el @@ -39,7 +39,7 @@ (c++-mode . origami-c-style-parser) (emacs-lisp-mode . origami-elisp-parser) (lisp-interaction-mode . origami-elisp-parser) - (clojure-mode . origami-elisp-parser)) + (clojure-mode . origami-clj-parser)) "alist mapping major-mode to parser function." :type 'hook :group 'origami) @@ -67,7 +67,7 @@ children of the pair." (parser-1? pair)) pair)))) -(defun origami-elisp-parser (create) +(defun origami-lisp-parser (create regex) (lambda (content) (with-temp-buffer (insert (parser-content-string content)) @@ -76,7 +76,7 @@ children of the pair." (let (beg end offset acc) (while (< (point) (point-max)) (setq beg (point)) - (search-forward-regexp "(def\\w*\\s-*\\(\\s_\\|\\w\\|[?!]\\)*\\([ \\t]*(.*?)\\)?" nil t) + (search-forward-regexp regex nil t) (setq offset (- (point) beg)) (end-of-defun) (backward-char) @@ -86,6 +86,12 @@ children of the pair." (beginning-of-defun -1)) (list (reverse acc)))))) +(defun origami-elisp-parser (create) + (origami-lisp-parser create "(def\\w*\\s-*\\(\\s_\\|\\w\\|[?!]\\)*\\([ \\t]*(.*?)\\)?")) + +(defun origami-clj-parser (create) + (origami-lisp-parser create "(def\\(\\w\\|-\\)*\\s-*\\(\\s_\\|\\w\\|[?!]\\)*\\([ \\t]*\\[.*?\\]\\)?")) + (provide 'origami-parsers) ;;; parser.el ends here