Bugfix.
[sepia.git] / sepia-re.el
blob39a00ae5cdfd1e1bff5b17c6af30e5615c02a3bf
1 (define-derived-mode sepia-regex-mode text-mode "RE"
2 "Mode for looking at 'use re \"debug\"' output."
3 (view-mode 1)
4 (font-lock-add-keywords
5 'sepia-regex-mode
6 '(("^\\(Compiling REx\\|Guessing start of match\\|Matching REx\\|Freeing REx:\\)" . font-lock-keyword-face)
7 ("^Match .*" . font-lock-warning-face)
8 ;; ("^Matches word.*" . font-lock-keyword-face)
9 ;; ("^Matching stclass.* against.*" . font-lock-keyword-face)
10 ("^ +\\([0-9]+\\)[: ]" 1 font-lock-constant-face)
11 ("^ *[0-9]+ <\\([^>]*\\)>" 1 font-lock-string-face)
12 ("^ *[0-9]+ <[^>]*> <\\([^>]*\\)>" 1 font-lock-string-face)
13 ("^ *[0-9]+.*?\\(|.*\\)" 1 font-lock-comment-face)
15 'set)
16 (modify-syntax-entry ?\" "\"")
17 (font-lock-fontify-buffer)
18 (toggle-truncate-lines 1))
20 (defun sepia-test-regex (pat str)
21 (interactive "Smatch pattern: \nSAgainst string: \n")
22 "Show the debug output for compiling `pat' and matching against `str'.
24 XXX: this doesn't work, because I can't figure out how to
25 redirect the debug output to a file."
26 (with-current-buffer (get-buffer-create "*sepia-regex*")
27 (let ((inhibit-read-only t))
28 (erase-buffer)
29 (shell-command (format "perl -Mre=debug -e 'q#%s# =~ m/%s/'" str pat)
30 (current-buffer))
31 ;; (insert (sepia-eval-raw
32 ;; (format "do { use re 'debug'; qq#%s# =~ m#%s# }" str pat)))
34 (sepia-regex-mode)
35 (pop-to-buffer (current-buffer))))