annotate lisp/emacs-lisp/re-builder.el @ 63592:153f4469d91a

(next-error-buffer-p, next-error-find-buffer): Fix typos in docstrings. (kill-whole-line): Doc fix. (clone-indirect-buffer): Improve argument/docstring consistency.
author Juanma Barranquero <lekktu@gmail.com>
date Mon, 20 Jun 2005 10:26:49 +0000
parents 0c94929d0a7d
children 18a818a2ee7c 01137c1fdbe9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36012
diff changeset
1 ;;; re-builder.el --- building Regexps with visual feedback
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
61394
31aa9a390538 * mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents: 60282
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
28077
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
41313
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
47 ;; The target buffer can be changed with `reb-change-target-buffer'
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
48 ;; ("\C-c\C-b"). Changing the target buffer automatically removes
41313
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
49 ;; the overlays from the old buffer and displays the new one in the
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
50 ;; target window.
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
51
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; The `re-builder' keeps the focus while updating the matches in the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; target buffer so corrections are easy to incorporate. If you are
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; 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
55 ;; 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
56 ;; and use it wherever you need it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; As the automatic updates can take some time on large buffers, they
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; 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
60 ;; have a negative impact on the editing. Setting it to nil makes
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; even the auto updates go all the way. Forcing an update overrides
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; this limit allowing an easy way to see all matches.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63
59396
1c58b91ca0df Update copyright. Update commentary to mention rx syntax support.
John Paul Wallington <jpw@pobox.com>
parents: 56698
diff changeset
64 ;; Currently `re-builder' understands five different forms of input,
1c58b91ca0df Update copyright. Update commentary to mention rx syntax support.
John Paul Wallington <jpw@pobox.com>
parents: 56698
diff changeset
65 ;; namely `read', `string', `rx', `sregex' and `lisp-re' syntax. Read
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; syntax and string syntax are both delimited by `"'s and behave
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; according to their name. With the `string' syntax there's no need
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; to escape the backslashes and double quotes simplifying the editing
59396
1c58b91ca0df Update copyright. Update commentary to mention rx syntax support.
John Paul Wallington <jpw@pobox.com>
parents: 56698
diff changeset
69 ;; somewhat. The other three allow editing of symbolic regular
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; expressions supported by the packages of the same name. (`lisp-re'
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; 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
72 ;; same as the `sregex' package in Emacs)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; Editing symbolic expressions is done through a major mode derived
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; 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
76 ;; automatic indentation and font-locking etc.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; When editing a symbolic regular expression, only the first
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; expression in the RE Builder buffer is considered, which helps
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; 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
81 ;; modes. For the `sregex' syntax the function `sregex' is applied to
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;; the evaluated expression read. So you can use quoted arguments
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;; with something like '("findme") or you can construct arguments to
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; your hearts delight with a valid ELisp expression. (The compiled
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; 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
86 ;; a glance at the corresponding string you can temporarily change the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;; input syntax.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; Changing the input syntax is transparent (for the obvious exception
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; non-symbolic -> symbolic) so you can change your mind as often as
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;; you like.
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 ;; There is also a shortcut function for toggling the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; `case-fold-search' variable in the target buffer with an immediate
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; update.
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
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; Q: But what if my display cannot show colored overlays?
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;; 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
100 ;; out.
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 ;; Q: But how can I then make out the sub-expressions?
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 ;; 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
104 ;; digit keys are assigned to perform an update that will flash the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 ;; corresponding subexp only.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 ;;; Code:
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 ;; On XEmacs, load the overlay compatibility library
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (if (not (fboundp 'make-overlay))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (require 'overlay))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 ;; User costomizable variables
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (defgroup re-builder nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 "Options for the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 :group 'lisp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 :prefix "reb-")
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-blink-delay 0.5
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 "*Seconds to blink cursor for next/previous match in RE Builder."
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 'number)
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-mode-hook nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 "*Hooks to run on entering RE Builder mode."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 :type 'hook)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (defcustom reb-re-syntax 'read
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 "*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
132 Can either be `read', `string', `sregex' or `lisp-re'."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 :type '(choice (const :tag "Read syntax" read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (const :tag "String syntax" string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (const :tag "`sregex' syntax" sregex)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (const :tag "`lisp-re' syntax" lisp-re)
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
138 (const :tag "`rx' syntax" rx)
28097
5d7390b72a44 (reb-re-syntax): Fix typo in `:type'. Fix comment.
Gerd Moellmann <gerd@gnu.org>
parents: 28077
diff changeset
139 (value: string)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (defcustom reb-auto-match-limit 200
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 "*Positive integer limiting the matches for RE Builder auto updates.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 Set it to nil if you don't want limits here."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 :type '(restricted-sexp :match-alternatives
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (integerp 'nil)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (defface reb-match-0
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
150 '((((class color) (background light))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
151 :background "lightblue")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
152 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
153 :background "steelblue4")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
154 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
155 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 "Used for displaying the whole match."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (defface reb-match-1
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
160 '((((class color) (background light))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
161 :background "aquamarine")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
162 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
163 :background "blue3")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
164 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
165 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 "Used for displaying the first matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (defface reb-match-2
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
170 '((((class color) (background light))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
171 :background "springgreen")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
172 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
173 :background "chartreuse4")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
174 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
175 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 "Used for displaying the second matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (defface reb-match-3
61394
31aa9a390538 * mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents: 60282
diff changeset
180 '((((min-colors 88) (class color) (background light))
31aa9a390538 * mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents: 60282
diff changeset
181 :background "yellow1")
31aa9a390538 * mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents: 60282
diff changeset
182 (((class color) (background light))
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
183 :background "yellow")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
184 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
185 :background "sienna4")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
186 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
187 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 "Used for displaying the third matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 :group '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 ;; Internal variables below
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (defvar reb-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 "Enables the RE Builder minor mode.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (defvar reb-target-buffer nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 "Buffer to which the RE is applied to.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (defvar reb-target-window nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 "Window to which the RE is applied to.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (defvar reb-regexp nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 "Last regexp used by RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (defvar reb-regexp-src nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 "Last regexp used by RE Builder before processing it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 Except for Lisp syntax this is the same as `reb-regexp'.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (defvar reb-overlays nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 "List of overlays of the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (defvar reb-window-config nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 "Old window configuration.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (defvar reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 "Indicates whether sub-exp mode is active.")
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 (defvar reb-subexp-displayed nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 "Indicates which sub-exp is active.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (defvar reb-mode-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 "String in mode line for additional info.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (defvar reb-valid-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 "String in mode line showing validity of RE.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (make-variable-buffer-local 'reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (make-variable-buffer-local 'reb-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (make-variable-buffer-local 'reb-regexp-src)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (defconst reb-buffer "*RE-Builder*"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 "Buffer to use for the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 ;; Define the local "\C-c" keymap
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
234 (defvar reb-mode-map
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
235 (let ((map (make-sparse-keymap)))
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
236 (define-key map "\C-c\C-c" 'reb-toggle-case)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
237 (define-key map "\C-c\C-q" 'reb-quit)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
238 (define-key map "\C-c\C-w" 'reb-copy)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
239 (define-key map "\C-c\C-s" 'reb-next-match)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
240 (define-key map "\C-c\C-r" 'reb-prev-match)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
241 (define-key map "\C-c\C-i" 'reb-change-syntax)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
242 (define-key map "\C-c\C-e" 'reb-enter-subexp-mode)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
243 (define-key map "\C-c\C-b" 'reb-change-target-buffer)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
244 (define-key map "\C-c\C-u" 'reb-force-update)
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
245 map)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 "Keymap used by the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247
41333
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
248 (defun reb-mode ()
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
249 "Major mode for interactively building Regular Expressions.
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
250 \\{reb-mode-map}"
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
251 (interactive)
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
252 (kill-all-local-variables)
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
253 (setq major-mode 'reb-mode
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
254 mode-name "RE Builder")
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
255 (use-local-map reb-mode-map)
fcb2aaafc8b2 (reb-mode): Don't use define-derived-mode. Call kill-all-local-variables.
Richard M. Stallman <rms@gnu.org>
parents: 41314
diff changeset
256 (reb-mode-common)
62757
0c94929d0a7d (reb-mode): Use run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents: 62402
diff changeset
257 (run-mode-hooks 'reb-mode-hook))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (define-derived-mode reb-lisp-mode
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 emacs-lisp-mode "RE Builder Lisp"
41225
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
261 "Major mode for interactively building symbolic Regular Expressions."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (cond ((eq reb-re-syntax 'lisp-re) ; Pull in packages
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (require 'lisp-re)) ; as needed
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 ((eq reb-re-syntax 'sregex) ; sregex is not autoloaded
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
265 (require 'sregex)) ; right now..
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
266 ((eq reb-re-syntax 'rx) ; rx-to-string is autoloaded
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
267 (require 'rx))) ; require rx anyway
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (reb-mode-common))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 ;; 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
271 ;; `emacs-lisp-mode'
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (define-key reb-lisp-mode-map "\C-c"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (lookup-key reb-mode-map "\C-c"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48379
diff changeset
275 (defvar reb-subexp-mode-map
41225
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
276 (let ((m (make-keymap)))
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
277 (suppress-keymap m)
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
278 ;; Again share the "\C-c" keymap for the commands
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
279 (define-key m "\C-c" (lookup-key reb-mode-map "\C-c"))
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
280 (define-key m "q" 'reb-quit-subexp-mode)
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
281 (dotimes (digit 10)
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
282 (define-key m (int-to-string digit) 'reb-display-subexp))
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
283 m)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 "Keymap used by the RE Builder for the subexpression mode.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (defun reb-mode-common ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 "Setup functions common to functions `reb-mode' and `reb-mode-lisp'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (setq reb-mode-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 reb-valid-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 mode-line-buffer-identification
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 '(25 . ("%b" reb-mode-string reb-valid-string)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (make-local-variable 'after-change-functions)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (add-hook 'after-change-functions
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 'reb-auto-update)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 ;; At least make the overlays go away if the buffer is killed
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (make-local-variable 'reb-kill-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (add-hook 'kill-buffer-hook 'reb-kill-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (reb-auto-update nil nil nil))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 ;; Handy macro for doing things in other windows
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (defmacro reb-with-current-window (window &rest body)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 "With WINDOW selected evaluate BODY forms and reselect previous window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (let ((oldwindow (make-symbol "*oldwindow*")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 `(let ((,oldwindow (selected-window)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (select-window ,window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (unwind-protect
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 ,@body)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (select-window ,oldwindow)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (put 'reb-with-current-window 'lisp-indent-function 0)
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 (defun reb-color-display-p ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 "Return t if display is capable of displaying colors."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (eq 'color
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 ;; emacs/xemacs compatibility
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (if (fboundp 'frame-parameter)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (frame-parameter (selected-frame) 'display-type)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (frame-property (selected-frame) 'display-type))))
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 (defsubst reb-lisp-syntax-p ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 "Return non-nil if RE Builder uses a Lisp syntax."
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
326 (memq reb-re-syntax '(lisp-re sregex rx)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (defmacro reb-target-binding (symbol)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 "Return binding for SYMBOL in the RE Builder target buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 `(with-current-buffer reb-target-buffer ,symbol))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331
60282
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
332 ;;; This is to help people find this in Apropos.
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
333 ;;;###autoload
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
334 (defun regexp-builder ()
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
335 "Alias for `re-builder': Construct a regexp interactively."
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
336 (interactive)
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
337 (re-builder))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 ;;;###autoload
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (defun re-builder ()
60282
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
341 "Construct a regexp interactively."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343
41314
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
344 (if (and (string= (buffer-name) reb-buffer)
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
345 (memq major-mode '(reb-mode reb-lisp-mode)))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
346 (message "Already in the RE Builder")
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
347 (if reb-target-buffer
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
348 (reb-delete-overlays))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
349 (setq reb-target-buffer (current-buffer)
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
350 reb-target-window (selected-window)
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
351 reb-window-config (current-window-configuration))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
352 (select-window (split-window (selected-window) (- (window-height) 4)))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
353 (switch-to-buffer (get-buffer-create reb-buffer))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
354 (erase-buffer)
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
355 (reb-insert-regexp)
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
356 (goto-char (+ 2 (point-min)))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
357 (cond
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
358 ((reb-lisp-syntax-p)
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
359 (reb-lisp-mode))
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
360 (t (reb-mode)))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361
41313
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
362 (defun reb-change-target-buffer (buf)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
363 "Change the target buffer and display it in the target window."
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
364 (interactive "bSet target buffer to: ")
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
365
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
366 (let ((buffer (get-buffer buf)))
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
367 (if (not buffer)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
368 (error "No such buffer")
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
369 (reb-delete-overlays)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
370 (setq reb-target-buffer buffer)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
371 (reb-do-update
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
372 (if reb-subexp-mode reb-subexp-displayed nil))
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
373 (reb-update-modestring))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (defun reb-force-update ()
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
376 "Force an update in the RE Builder target window without a match limit."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (let ((reb-auto-match-limit nil))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (reb-update-overlays
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (if reb-subexp-mode reb-subexp-displayed nil))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (defun reb-quit ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 "Quit the RE Builder mode."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (setq reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 reb-subexp-displayed nil)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (reb-delete-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (bury-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (set-window-configuration reb-window-config))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (defun reb-next-match ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 "Go to next match in the RE Builder target window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (reb-with-current-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 reb-target-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (if (not (re-search-forward reb-regexp (point-max) t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (message "No more matches.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (reb-show-subexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (or (and reb-subexp-mode reb-subexp-displayed) 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 t))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (defun reb-prev-match ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 "Go to previous match in the RE Builder target window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (reb-with-current-window reb-target-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (goto-char (1- (point)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (if (not (re-search-backward reb-regexp (point-min) t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (message "No more matches.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (reb-show-subexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (or (and reb-subexp-mode reb-subexp-displayed) 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 t))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (defun reb-toggle-case ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 "Toggle case sensitivity of searches for RE Builder target buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (setq case-fold-search (not case-fold-search)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (reb-auto-update nil nil nil t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (defun reb-copy ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 "Copy current RE into the kill ring for later insertion."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (reb-update-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (let ((re (with-output-to-string
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (print (reb-target-binding reb-regexp)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (kill-new (substring re 1 (1- (length re))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (message "Regexp copied to kill-ring")))
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 ;; The subexpression mode is not electric because the number of
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 ;; matches should be seen rather than a prompt.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (defun reb-enter-subexp-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 "Enter the subexpression mode in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (setq reb-subexp-mode t)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (use-local-map reb-subexp-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (message "`0'-`9' to display subexpressions `q' to quit subexp mode."))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (defun reb-show-subexp (subexp &optional pause)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 "Visually show limit of subexpression SUBEXP of recent search.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 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
451 the match should already be marked by an overlay.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 On other displays jump to the beginning and the end of it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 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
454 (reb-with-current-window reb-target-window
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (if (not (reb-color-display-p))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (progn (goto-char (match-beginning subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (sit-for reb-blink-delay)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (goto-char (match-end subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (if (or (not (reb-color-display-p)) pause)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (sit-for reb-blink-delay))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (defun reb-quit-subexp-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 "Quit the subexpression mode in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (setq reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 reb-subexp-displayed nil)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (use-local-map reb-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (reb-do-update))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 (defun reb-change-syntax (&optional syntax)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 "Change the syntax used by the RE Builder.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 Optional argument SYNTAX must be specified if called non-interactively."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (interactive
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 (list (intern
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (completing-read "Select syntax: "
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (mapcar (lambda (el) (cons (symbol-name el) 1))
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
478 '(read string lisp-re sregex rx))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 nil t (symbol-name reb-re-syntax)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
481 (if (memq syntax '(read string lisp-re sregex rx))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (let ((buffer (get-buffer reb-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (setq reb-re-syntax syntax)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 (if buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (with-current-buffer buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 (erase-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (reb-insert-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (goto-char (+ 2 (point-min)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (cond ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (reb-lisp-mode))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (t (reb-mode))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (error "Invalid syntax: %s" syntax)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493
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 ;; Non-interactive functions below
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (defun reb-do-update (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 "Update matches in the RE Builder target window.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 If SUBEXP is non-nil mark only the corresponding sub-expressions."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (reb-update-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (reb-update-overlays subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 (defun reb-auto-update (beg end lenold &optional force)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 "Called from `after-update-functions' to update the display.
55404
14a47b65c288 (reb-auto-update): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
506 BEG, END and LENOLD are passed in from the hook.
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 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
508 optional fourth argument FORCE is non-nil."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 (let ((prev-valid reb-valid-string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 (new-valid
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 (condition-case nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (if (or (reb-update-regexp) force)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (progn
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (reb-do-update)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (error " *invalid*"))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (setq reb-valid-string new-valid)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (force-mode-line-update)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 ;; Through the caching of the re a change invalidating the syntax
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 ;; for symbolic expressions will not delete the overlays so we
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 ;; catch it here
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 (if (and (reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (not (string= prev-valid new-valid))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (string= prev-valid ""))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (reb-delete-overlays))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (defun reb-delete-overlays ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 "Delete all RE Builder overlays in the `reb-target-buffer' buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (if (buffer-live-p reb-target-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (mapcar 'delete-overlay reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (setq reb-overlays nil))))
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-assert-buffer-in-window ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 "Assert that `reb-target-buffer' is displayed in `reb-target-window'."
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 (not (eq reb-target-buffer (window-buffer reb-target-window)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 (set-window-buffer reb-target-window reb-target-buffer)))
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 (defun reb-update-modestring ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 "Update the variable `reb-mode-string' displayed in the mode line."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 (setq reb-mode-string
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (concat
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (if reb-subexp-mode
35756
8a4490cbee15 (reb-update-modestring): Don't use concat for integers.
Eli Zaretskii <eliz@gnu.org>
parents: 28107
diff changeset
548 (format " (subexp %s)" (or reb-subexp-displayed "-"))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 (if (not (reb-target-binding case-fold-search))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 " Case"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (force-mode-line-update))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (defun reb-display-subexp (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 "Highlight only subexpression SUBEXP in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 (setq reb-subexp-displayed
62402
a7e02ef1e3d6 Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 61394
diff changeset
560 (or subexp (string-to-number (format "%c" last-command-char))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (reb-do-update reb-subexp-displayed))
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-kill-buffer ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 "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
566
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (if (member major-mode '(reb-mode reb-lisp-mode))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (reb-delete-overlays)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 ;; The next functions are the interface between the regexp and
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 ;; its textual representation in the RE Builder buffer.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 ;; They are the only functions concerned with the actual syntax
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 ;; being used.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (defun reb-read-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 "Read current RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (save-excursion
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (cond ((eq reb-re-syntax 'read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 (read (current-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 ((eq reb-re-syntax 'string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (re-search-forward "\"")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (let ((beg (point)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (goto-char (point-max))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (re-search-backward "\"")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (buffer-substring-no-properties beg (point))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (buffer-string)))))
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-empty-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 "Return empty RE for current syntax."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 (cond ((reb-lisp-syntax-p) "'()")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (t "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (defun reb-insert-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 "Insert current RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (let ((re (or (reb-target-binding reb-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (reb-empty-regexp))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (cond ((eq reb-re-syntax 'read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (print re (current-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 ((eq reb-re-syntax 'string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 (insert "\n\"" re "\""))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 ;; For the Lisp syntax we need the "source" of the regexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (insert (or (reb-target-binding reb-regexp-src)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 (reb-empty-regexp)))))))
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 (defun reb-cook-regexp (re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 "Return RE after processing it according to `reb-re-syntax'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 (cond ((eq reb-re-syntax 'lisp-re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 (lre-compile-string (eval (car (read-from-string re)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 ((eq reb-re-syntax 'sregex)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615 (apply 'sregex (eval (car (read-from-string re)))))
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
616 ((eq reb-re-syntax 'rx)
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
617 (rx-to-string (eval (car (read-from-string re)))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 (t re)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 (defun reb-update-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621 "Update the regexp for the target buffer.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 Return t if the (cooked) expression changed."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (let* ((re-src (reb-read-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (re (reb-cook-regexp re-src)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (let ((oldre reb-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (prog1
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 (not (string= oldre re))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 (setq reb-regexp re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 ;; Only update the source re for the lisp formats
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631 (if (reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 (setq reb-regexp-src re-src)))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 ;; And now the real core of the whole thing
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (defun reb-count-subexps (re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 "Return number of sub-expressions in the regexp RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 (let ((i 0) (beg 0))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 (while (string-match "\\\\(" re beg)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 (setq i (1+ i)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 beg (match-end 0)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 (defun reb-update-overlays (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 "Switch to `reb-target-buffer' and mark all matches of `reb-regexp'.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 If SUBEXP is non-nil mark only the corresponding sub-expressions."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 (let* ((re (reb-target-binding reb-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (subexps (reb-count-subexps re))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 (matches 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (submatches 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 (save-excursion
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 (set-buffer reb-target-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 (reb-delete-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 (while (and (re-search-forward re (point-max) t)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 (or (not reb-auto-match-limit)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 (< matches reb-auto-match-limit)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 (if (= 0 (length (match-string 0)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (error "Empty regular expression!"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 (let ((i 0))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665 (setq matches (1+ matches))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
666 (while (<= i subexps)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 (if (and (or (not subexp) (= subexp i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (match-beginning i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 (let ((overlay (make-overlay (match-beginning i)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 (match-end i)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 (face-name (format "reb-match-%d" i)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 (if (not firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 (setq firstmatch (match-data)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (setq reb-overlays (cons overlay reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 submatches (1+ submatches))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 (overlay-put
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 overlay 'face
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 (or (intern-soft face-name)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 (error "Too many subexpressions - face `%s' not defined"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 face-name )))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 (overlay-put overlay 'priority i)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682 (setq i (1+ i))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
683 (let ((count (if subexp submatches matches)))
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
684 (message "%s %smatch%s%s"
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685 (if (= 0 count) "No" (int-to-string count))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 (if subexp "subexpression " "")
56382
a4c0ce40be3d (reb-update-overlays): Distinguish between one and several matches in message.
John Paul Wallington <jpw@pobox.com>
parents: 55404
diff changeset
687 (if (= 1 count) "" "es")
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
688 (if (and reb-auto-match-limit
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689 (= reb-auto-match-limit count))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
690 " (limit reached)" "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 (if firstmatch
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
692 (progn (store-match-data firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693 (reb-show-subexp (or subexp 0))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694
48379
6e55b7742a81 Add provide call.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 41371
diff changeset
695 (provide 're-builder)
6e55b7742a81 Add provide call.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 41371
diff changeset
696
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
697 ;;; arch-tag: 5c5515ac-4085-4524-a421-033f44f032e7
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 ;;; re-builder.el ends here