annotate lisp/emacs-lisp/re-builder.el @ 37909:3d650ae7e609

(byte-compile-file-form-autoload): Use the same definition in byte-compile-function-environment as `autoload' would put in `symbol-function'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 27 May 2001 11:40:30 +0000
parents e178314a581e
children b174db545cfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; re-builder.el --- Building Regexps with visual feedback
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Detlev Zundel <dzu@gnu.org>
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Keywords: matching, lisp, tools
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; any later version.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;; When I have to come up with regular expressions that are more
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; complex than simple string matchers, especially if they contain sub
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; expressions, I find myself spending quite some time in the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; `development cycle'. `re-builder' aims to shorten this time span
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; so I can get on with the more interesting bits.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; With it you can have immediate visual feedback about how well the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; regexp behaves to your expectations on the intended data.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; When called up `re-builder' attaches itself to the current buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; which becomes its target buffer, where all the matching is done.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; The active window is split so you have a view on the data while
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; authoring the RE. If the edited expression is valid the matches in
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; the target buffer are marked automatically with colored overlays
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; (for non-color displays see below) giving you feedback over the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; extents of the matched (sub) expressions. The (non-)validity is
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; shown only in the modeline without throwing the errors at you. If
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; you want to know the reason why RE Builder considers it as invalid
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; call `reb-force-update' ("\C-c\C-u") which should reveal the error.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; The `re-builder' keeps the focus while updating the matches in the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; target buffer so corrections are easy to incorporate. If you are
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; satisfied with the result you can paste the RE to the kill-ring
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; with `reb-copy' ("\C-c\C-w"), quit the `re-builder' ("\C-c\C-q")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; and use it wherever you need it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; As the automatic updates can take some time on large buffers, they
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; can be limited by `reb-auto-match-limit' so that they should not
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; have a negative impact on the editing. Setting it to nil makes
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; even the auto updates go all the way. Forcing an update overrides
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; this limit allowing an easy way to see all matches.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; Currently `re-builder' understands four different forms of input,
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; namely `read', `string', `sregex' and `lisp-re' syntax. Read
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; syntax and string syntax are both delimited by `"'s and behave
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; according to their name. With the `string' syntax there's no need
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; to escape the backslashes and double quotes simplifying the editing
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; somewhat. The other two allow editing of symbolic regular
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; expressions supported by the packages of the same name. (`lisp-re'
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; is a package by me and its support may go away as it is nearly the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; same as the `sregex' package in Emacs)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; Editing symbolic expressions is done through a major mode derived
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; from `emacs-lisp-mode' so you'll get all the good stuff like
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; automatic indentation and font-locking etc.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; When editing a symbolic regular expression, only the first
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; expression in the RE Builder buffer is considered, which helps
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; limiting the extent of the expression like the `"'s do for the text
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;; modes. For the `sregex' syntax the function `sregex' is applied to
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; the evaluated expression read. So you can use quoted arguments
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; with something like '("findme") or you can construct arguments to
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; your hearts delight with a valid ELisp expression. (The compiled
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; string form will be copied by `reb-copy') If you want to take
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;; a glance at the corresponding string you can temporarily change the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;; input syntax.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; Changing the input syntax is transparent (for the obvious exception
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; non-symbolic -> symbolic) so you can change your mind as often as
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;; you like.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; There is also a shortcut function for toggling the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; `case-fold-search' variable in the target buffer with an immediate
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; update.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; Q: But what if my display cannot show colored overlays?
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; A: Then the cursor will flash around the matched text making it stand
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; out.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 ;; Q: But how can I then make out the sub-expressions?
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; A: Thats where the `sub-expression mode' comes in. In it only the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;; digit keys are assigned to perform an update that will flash the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 ;; corresponding subexp only.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 ;;; Code:
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 ;; On XEmacs, load the overlay compatibility library
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (if (not (fboundp 'make-overlay))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (require 'overlay))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 ;; User costomizable variables
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (defgroup re-builder nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 "Options for the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 :group 'lisp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 :prefix "reb-")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (defcustom reb-blink-delay 0.5
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 "*Seconds to blink cursor for next/previous match in RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 :type 'number)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (defcustom reb-mode-hook nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 "*Hooks to run on entering RE Builder mode."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 :type 'hook)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (defcustom reb-re-syntax 'read
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 "*Syntax for the REs in the RE Builder.
28097
5d7390b72a44 (reb-re-syntax): Fix typo in `:type'. Fix comment.
Gerd Moellmann <gerd@gnu.org>
parents: 28077
diff changeset
127 Can either be `read', `string', `sregex' or `lisp-re'."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 :type '(choice (const :tag "Read syntax" read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (const :tag "String syntax" string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (const :tag "`sregex' syntax" sregex)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (const :tag "`lisp-re' syntax" lisp-re)
28097
5d7390b72a44 (reb-re-syntax): Fix typo in `:type'. Fix comment.
Gerd Moellmann <gerd@gnu.org>
parents: 28077
diff changeset
133 (value: string)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (defcustom reb-auto-match-limit 200
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 "*Positive integer limiting the matches for RE Builder auto updates.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 Set it to nil if you don't want limits here."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 :type '(restricted-sexp :match-alternatives
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (integerp 'nil)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (defface reb-match-0
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 '((((class color))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (:background "lightblue"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (t (:inverse-video t)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 "Used for displaying the whole match."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (defface reb-match-1
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 '((((class color))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (:background "aquamarine"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (t (:inverse-video t)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 "Used for displaying the first matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (defface reb-match-2
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 '((((class color))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (:background "springgreen"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (t (:inverse-video t)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 "Used for displaying the second matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (defface reb-match-3
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 '((((class color))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (:background "yellow"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (t (:inverse-video t)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 "Used for displaying the third matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 ;; Internal variables below
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (defvar reb-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 "Enables the RE Builder minor mode.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (defvar reb-target-buffer nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 "Buffer to which the RE is applied to.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (defvar reb-target-window nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 "Window to which the RE is applied to.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (defvar reb-regexp nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 "Last regexp used by RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (defvar reb-regexp-src nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 "Last regexp used by RE Builder before processing it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 Except for Lisp syntax this is the same as `reb-regexp'.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (defvar reb-overlays nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 "List of overlays of the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (defvar reb-window-config nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 "Old window configuration.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (defvar reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 "Indicates whether sub-exp mode is active.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (defvar reb-subexp-displayed nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 "Indicates which sub-exp is active.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (defvar reb-mode-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 "String in mode line for additional info.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (defvar reb-valid-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 "String in mode line showing validity of RE.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (make-variable-buffer-local 'reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (make-variable-buffer-local 'reb-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (make-variable-buffer-local 'reb-regexp-src)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (defconst reb-buffer "*RE-Builder*"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 "Buffer to use for the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 ;; Define the local "\C-c" keymap
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (defvar reb-mode-map nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 "Keymap used by the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (if (not reb-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (setq reb-mode-map (make-sparse-keymap))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (define-key reb-mode-map "\C-c\C-c" 'reb-toggle-case)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (define-key reb-mode-map "\C-c\C-q" 'reb-quit)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (define-key reb-mode-map "\C-c\C-w" 'reb-copy)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (define-key reb-mode-map "\C-c\C-s" 'reb-next-match)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (define-key reb-mode-map "\C-c\C-r" 'reb-prev-match)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (define-key reb-mode-map "\C-c\C-i" 'reb-change-syntax)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (define-key reb-mode-map "\C-c\C-e" 'reb-enter-subexp-mode)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (define-key reb-mode-map "\C-c\C-u" 'reb-force-update)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (defun reb-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 "Major mode for interactively building Regular Expressions.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 \\{reb-mode-map}"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (setq major-mode 'reb-mode
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 mode-name "RE Builder")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (use-local-map reb-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (reb-mode-common)
36012
e178314a581e (reb-mode): Quote the hook name. From
Dave Love <fx@gnu.org>
parents: 35756
diff changeset
238 (run-hooks 'reb-mode-hook))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (define-derived-mode reb-lisp-mode
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 emacs-lisp-mode "RE Builder Lisp"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 "Major mode for interactively building symbolic Regular Expressions.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 \\{reb-lisp-mode-map}"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (cond ((eq reb-re-syntax 'lisp-re) ; Pull in packages
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (require 'lisp-re)) ; as needed
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 ((eq reb-re-syntax 'sregex) ; sregex is not autoloaded
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (require 'sregex))) ; right now..
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (reb-mode-common))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 ;; Use the same "\C-c" keymap as `reb-mode' and use font-locking from
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 ;; `emacs-lisp-mode'
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (define-key reb-lisp-mode-map "\C-c"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (lookup-key reb-mode-map "\C-c"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (if (boundp 'font-lock-defaults-alist)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (setq font-lock-defaults-alist
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (cons (cons 'reb-lisp-mode
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (cdr (assoc 'emacs-lisp-mode
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 font-lock-defaults-alist)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 font-lock-defaults-alist)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (defvar reb-subexp-mode-map nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 "Keymap used by the RE Builder for the subexpression mode.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (if (not reb-subexp-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (setq reb-subexp-mode-map (make-sparse-keymap))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (suppress-keymap reb-subexp-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 ;; Again share the "\C-c" keymap for the commands
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (define-key reb-subexp-mode-map "\C-c"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (lookup-key reb-mode-map "\C-c"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (define-key reb-subexp-mode-map "q" 'reb-quit-subexp-mode)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (mapcar (lambda (digit)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (define-key reb-subexp-mode-map (int-to-string digit)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 'reb-display-subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 '(0 1 2 3 4 5 6 7 8 9))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (defun reb-mode-common ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 "Setup functions common to functions `reb-mode' and `reb-mode-lisp'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (setq reb-mode-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 reb-valid-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 mode-line-buffer-identification
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 '(25 . ("%b" reb-mode-string reb-valid-string)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (make-local-variable 'after-change-functions)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (add-hook 'after-change-functions
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 'reb-auto-update)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 ;; At least make the overlays go away if the buffer is killed
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (make-local-variable 'reb-kill-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (add-hook 'kill-buffer-hook 'reb-kill-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (reb-auto-update nil nil nil))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 ;; Handy macro for doing things in other windows
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (defmacro reb-with-current-window (window &rest body)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 "With WINDOW selected evaluate BODY forms and reselect previous window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (let ((oldwindow (make-symbol "*oldwindow*")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 `(let ((,oldwindow (selected-window)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (select-window ,window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (unwind-protect
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ,@body)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 (select-window ,oldwindow)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (put 'reb-with-current-window 'lisp-indent-function 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (defun reb-color-display-p ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 "Return t if display is capable of displaying colors."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (eq 'color
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 ;; emacs/xemacs compatibility
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (if (fboundp 'frame-parameter)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (frame-parameter (selected-frame) 'display-type)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (frame-property (selected-frame) 'display-type))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (defsubst reb-lisp-syntax-p ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 "Return non-nil if RE Builder uses a Lisp syntax."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (memq reb-re-syntax '(lisp-re sregex)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (defmacro reb-target-binding (symbol)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 "Return binding for SYMBOL in the RE Builder target buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 `(with-current-buffer reb-target-buffer ,symbol))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 ;;;###autoload
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (defun re-builder ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 "Call up the RE Builder for the current window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (if reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (reb-delete-overlays))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (setq reb-target-buffer (current-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 reb-target-window (selected-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 reb-window-config (current-window-configuration))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (select-window (split-window (selected-window) (- (window-height) 4)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (switch-to-buffer (get-buffer-create reb-buffer))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (erase-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (reb-insert-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (goto-char (+ 2 (point-min)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (cond
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (reb-lisp-mode))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (t (reb-mode))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (defun reb-force-update ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 "Forces an update in the RE Builder target window without a match limit."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (let ((reb-auto-match-limit nil))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (reb-update-overlays
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (if reb-subexp-mode reb-subexp-displayed nil))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (defun reb-quit ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 "Quit the RE Builder mode."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (setq reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 reb-subexp-displayed nil)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (reb-delete-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (bury-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (set-window-configuration reb-window-config))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (defun reb-next-match ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 "Go to next match in the RE Builder target window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (reb-with-current-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 reb-target-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (if (not (re-search-forward reb-regexp (point-max) t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (message "No more matches.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (reb-show-subexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 (or (and reb-subexp-mode reb-subexp-displayed) 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 t))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (defun reb-prev-match ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 "Go to previous match in the RE Builder target window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (reb-with-current-window reb-target-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (goto-char (1- (point)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (if (not (re-search-backward reb-regexp (point-min) t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (message "No more matches.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (reb-show-subexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (or (and reb-subexp-mode reb-subexp-displayed) 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 t))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (defun reb-toggle-case ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 "Toggle case sensitivity of searches for RE Builder target buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (setq case-fold-search (not case-fold-search)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (reb-auto-update nil nil nil t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (defun reb-copy ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 "Copy current RE into the kill ring for later insertion."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (reb-update-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (let ((re (with-output-to-string
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (print (reb-target-binding reb-regexp)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (kill-new (substring re 1 (1- (length re))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (message "Regexp copied to kill-ring")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 ;; The subexpression mode is not electric because the number of
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 ;; matches should be seen rather than a prompt.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (defun reb-enter-subexp-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 "Enter the subexpression mode in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (setq reb-subexp-mode t)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (use-local-map reb-subexp-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (message "`0'-`9' to display subexpressions `q' to quit subexp mode."))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (defun reb-show-subexp (subexp &optional pause)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 "Visually show limit of subexpression SUBEXP of recent search.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 On color displays this just puts point to the end of the expression as
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 the match should already be marked by an overlay.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 On other displays jump to the beginning and the end of it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 If the optional PAUSE is non-nil then pause at the end in any case."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (reb-with-current-window reb-target-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 (if (not (reb-color-display-p))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (progn (goto-char (match-beginning subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (sit-for reb-blink-delay)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (goto-char (match-end subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (if (or (not (reb-color-display-p)) pause)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (sit-for reb-blink-delay))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (defun reb-quit-subexp-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 "Quit the subexpression mode in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (setq reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 reb-subexp-displayed nil)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (use-local-map reb-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (reb-do-update))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (defun reb-change-syntax (&optional syntax)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 "Change the syntax used by the RE Builder.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 Optional argument SYNTAX must be specified if called non-interactively."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (interactive
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (list (intern
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (completing-read "Select syntax: "
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (mapcar (lambda (el) (cons (symbol-name el) 1))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 '(read string lisp-re sregex))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 nil t (symbol-name reb-re-syntax)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (if (memq syntax '(read string lisp-re sregex))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (let ((buffer (get-buffer reb-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (setq reb-re-syntax syntax)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (if buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (with-current-buffer buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (erase-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (reb-insert-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 (goto-char (+ 2 (point-min)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (cond ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 (reb-lisp-mode))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (t (reb-mode))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (error "Invalid syntax: %s" syntax)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 ;; Non-interactive functions below
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (defun reb-do-update (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 "Update matches in the RE Builder target window.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 If SUBEXP is non-nil mark only the corresponding sub-expressions."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (reb-update-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 (reb-update-overlays subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (defun reb-auto-update (beg end lenold &optional force)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 "Called from `after-update-functions' to update the display.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 BEG END and LENOLD are passed in from the hook.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 An actual update is only done if the regexp has changed or if the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 optional fourth argument FORCE is non-nil."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (let ((prev-valid reb-valid-string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (new-valid
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 (condition-case nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 (if (or (reb-update-regexp) force)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (reb-do-update)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (error " *invalid*"))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (setq reb-valid-string new-valid)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (force-mode-line-update)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 ;; Through the caching of the re a change invalidating the syntax
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 ;; for symbolic expressions will not delete the overlays so we
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 ;; catch it here
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (if (and (reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (not (string= prev-valid new-valid))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (string= prev-valid ""))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (reb-delete-overlays))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (defun reb-delete-overlays ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 "Delete all RE Builder overlays in the `reb-target-buffer' buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (if (buffer-live-p reb-target-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (mapcar 'delete-overlay reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 (setq reb-overlays nil))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 (defun reb-assert-buffer-in-window ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 "Assert that `reb-target-buffer' is displayed in `reb-target-window'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (if (not (eq reb-target-buffer (window-buffer reb-target-window)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (set-window-buffer reb-target-window reb-target-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (defun reb-update-modestring ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 "Update the variable `reb-mode-string' displayed in the mode line."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (setq reb-mode-string
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (concat
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (if reb-subexp-mode
35756
8a4490cbee15 (reb-update-modestring): Don't use concat for integers.
Eli Zaretskii <eliz@gnu.org>
parents: 28107
diff changeset
521 (format " (subexp %s)" (or reb-subexp-displayed "-"))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 (if (not (reb-target-binding case-fold-search))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 " Case"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (force-mode-line-update))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (defun reb-display-subexp (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 "Highlight only subexpression SUBEXP in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (setq reb-subexp-displayed
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (or subexp (string-to-int (format "%c" last-command-char))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (reb-do-update reb-subexp-displayed))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (defun reb-kill-buffer ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 "When the RE Builder buffer is killed make sure no overlays stay around."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (if (member major-mode '(reb-mode reb-lisp-mode))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 (reb-delete-overlays)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 ;; The next functions are the interface between the regexp and
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 ;; its textual representation in the RE Builder buffer.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 ;; They are the only functions concerned with the actual syntax
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 ;; being used.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (defun reb-read-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 "Read current RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 (save-excursion
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (cond ((eq reb-re-syntax 'read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (read (current-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 ((eq reb-re-syntax 'string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 (re-search-forward "\"")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (let ((beg (point)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 (goto-char (point-max))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 (re-search-backward "\"")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (buffer-substring-no-properties beg (point))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (buffer-string)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 (defun reb-empty-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 "Return empty RE for current syntax."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (cond ((reb-lisp-syntax-p) "'()")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (t "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 (defun reb-insert-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 "Insert current RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 (let ((re (or (reb-target-binding reb-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 (reb-empty-regexp))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 (cond ((eq reb-re-syntax 'read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (print re (current-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 ((eq reb-re-syntax 'string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (insert "\n\"" re "\""))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 ;; For the Lisp syntax we need the "source" of the regexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 (insert (or (reb-target-binding reb-regexp-src)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 (reb-empty-regexp)))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (defun reb-cook-regexp (re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 "Return RE after processing it according to `reb-re-syntax'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (cond ((eq reb-re-syntax 'lisp-re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (lre-compile-string (eval (car (read-from-string re)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 ((eq reb-re-syntax 'sregex)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 (apply 'sregex (eval (car (read-from-string re)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (t re)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (defun reb-update-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 "Update the regexp for the target buffer.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 Return t if the (cooked) expression changed."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (let* ((re-src (reb-read-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 (re (reb-cook-regexp re-src)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (let ((oldre reb-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (prog1
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (not (string= oldre re))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (setq reb-regexp re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 ;; Only update the source re for the lisp formats
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (if (reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 (setq reb-regexp-src re-src)))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 ;; And now the real core of the whole thing
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (defun reb-count-subexps (re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 "Return number of sub-expressions in the regexp RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 (let ((i 0) (beg 0))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 (while (string-match "\\\\(" re beg)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 (setq i (1+ i)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 beg (match-end 0)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 (defun reb-update-overlays (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 "Switch to `reb-target-buffer' and mark all matches of `reb-regexp'.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 If SUBEXP is non-nil mark only the corresponding sub-expressions."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621 (let* ((re (reb-target-binding reb-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 (subexps (reb-count-subexps re))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (matches 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (submatches 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (save-excursion
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (set-buffer reb-target-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 (reb-delete-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 (while (and (re-search-forward re (point-max) t)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631 (or (not reb-auto-match-limit)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 (< matches reb-auto-match-limit)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (if (= 0 (length (match-string 0)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (error "Empty regular expression!"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 (let ((i 0))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (setq matches (1+ matches))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 (while (<= i subexps)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 (if (and (or (not subexp) (= subexp i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 (match-beginning i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 (let ((overlay (make-overlay (match-beginning i)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 (match-end i)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 (face-name (format "reb-match-%d" i)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 (if (not firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 (setq firstmatch (match-data)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 (setq reb-overlays (cons overlay reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 submatches (1+ submatches))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 (overlay-put
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 overlay 'face
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 (or (intern-soft face-name)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 (error "Too many subexpressions - face `%s' not defined"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 face-name )))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 (overlay-put overlay 'priority i)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (setq i (1+ i))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 (let ((count (if subexp submatches matches)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 (message"%s %smatch(es)%s"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 (if (= 0 count) "No" (int-to-string count))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 (if subexp "subexpression " "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (if (and reb-auto-match-limit
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 (= reb-auto-match-limit count))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 " (limit reached)" "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 (if firstmatch
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 (progn (store-match-data firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (reb-show-subexp (or subexp 0))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665 ;;; re-builder.el ends here