annotate lisp/emacs-lisp/re-builder.el @ 104777:537e1db33ebf

*** empty log message ***
author Glenn Morris <rgm@gnu.org>
date Tue, 01 Sep 2009 03:27:52 +0000
parents b1cb2e195329
children df4934f25eef
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
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64624
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100048
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Author: Detlev Zundel <dzu@gnu.org>
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Keywords: matching, lisp, tools
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;; When I have to come up with regular expressions that are more
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;; complex than simple string matchers, especially if they contain sub
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; expressions, I find myself spending quite some time in the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; `development cycle'. `re-builder' aims to shorten this time span
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; so I can get on with the more interesting bits.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; With it you can have immediate visual feedback about how well the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; regexp behaves to your expectations on the intended data.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; When called up `re-builder' attaches itself to the current buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; which becomes its target buffer, where all the matching is done.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; 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
38 ;; authoring the RE. If the edited expression is valid the matches in
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; the target buffer are marked automatically with colored overlays
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; (for non-color displays see below) giving you feedback over the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; extents of the matched (sub) expressions. The (non-)validity is
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; shown only in the modeline without throwing the errors at you. If
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; 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
44 ;; 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
45
41313
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
46 ;; 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
47 ;; ("\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
48 ;; 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
49 ;; target window.
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
50
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; The `re-builder' keeps the focus while updating the matches in the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; target buffer so corrections are easy to incorporate. If you are
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; 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
54 ;; 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
55 ;; and use it wherever you need it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; As the automatic updates can take some time on large buffers, they
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; 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
59 ;; have a negative impact on the editing. Setting it to nil makes
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; even the auto updates go all the way. Forcing an update overrides
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; this limit allowing an easy way to see all matches.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62
59396
1c58b91ca0df Update copyright. Update commentary to mention rx syntax support.
John Paul Wallington <jpw@pobox.com>
parents: 56698
diff changeset
63 ;; 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
64 ;; namely `read', `string', `rx', `sregex' and `lisp-re' syntax. Read
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; syntax and string syntax are both delimited by `"'s and behave
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; according to their name. With the `string' syntax there's no need
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; 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
68 ;; somewhat. The other three allow editing of symbolic regular
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; expressions supported by the packages of the same name. (`lisp-re'
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; 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
71 ;; same as the `sregex' package in Emacs)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; Editing symbolic expressions is done through a major mode derived
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; 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
75 ;; automatic indentation and font-locking etc.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; When editing a symbolic regular expression, only the first
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; expression in the RE Builder buffer is considered, which helps
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; 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
80 ;; modes. For the `sregex' syntax the function `sregex' is applied to
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;; the evaluated expression read. So you can use quoted arguments
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;; with something like '("findme") or you can construct arguments to
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;; your hearts delight with a valid ELisp expression. (The compiled
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; 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
85 ;; a glance at the corresponding string you can temporarily change the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;; input syntax.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; Changing the input syntax is transparent (for the obvious exception
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; non-symbolic -> symbolic) so you can change your mind as often as
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; you like.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; There is also a shortcut function for toggling the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; `case-fold-search' variable in the target buffer with an immediate
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; update.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 ;; Q: But what if my display cannot show colored overlays?
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; 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
99 ;; out.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 ;; Q: But how can I then make out the sub-expressions?
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 ;; 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
103 ;; digit keys are assigned to perform an update that will flash the
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 ;; corresponding subexp only.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105
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 ;;; Code:
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 ;; On XEmacs, load the overlay compatibility library
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
110 (unless (fboundp 'make-overlay)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
111 (require 'overlay))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112
70404
ce092da13632 (reb-update-overlays): Cycle through provided faces once they all have been
Eli Zaretskii <eliz@gnu.org>
parents: 68648
diff changeset
113 ;; User customizable variables
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 (defgroup re-builder nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 "Options for the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 :group 'lisp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 :prefix "reb-")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (defcustom reb-blink-delay 0.5
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
120 "Seconds to blink cursor for next/previous match in RE Builder."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 :type 'number)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (defcustom reb-mode-hook nil
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
125 "Hooks to run on entering RE Builder mode."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 :type 'hook)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (defcustom reb-re-syntax 'read
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
130 "Syntax for the REs in the RE Builder.
76350
afaae6720920 (reb-re-syntax): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 75346
diff changeset
131 Can either be `read', `string', `sregex', `lisp-re', `rx'."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 :type '(choice (const :tag "Read syntax" read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (const :tag "String syntax" string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (const :tag "`sregex' syntax" sregex)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (const :tag "`lisp-re' syntax" lisp-re)
76350
afaae6720920 (reb-re-syntax): Fix custom type.
Richard M. Stallman <rms@gnu.org>
parents: 75346
diff changeset
137 (const :tag "`rx' syntax" rx)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (defcustom reb-auto-match-limit 200
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
140 "Positive integer limiting the matches for RE Builder auto updates.
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 Set it to nil if you don't want limits here."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 :group 're-builder
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 :type '(restricted-sexp :match-alternatives
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (integerp 'nil)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (defface reb-match-0
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
148 '((((class color) (background light))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
149 :background "lightblue")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
150 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
151 :background "steelblue4")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
152 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
153 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 "Used for displaying the whole match."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (defface reb-match-1
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
158 '((((class color) (background light))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
159 :background "aquamarine")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
160 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
161 :background "blue3")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
162 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
163 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 "Used for displaying the first matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (defface reb-match-2
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
168 '((((class color) (background light))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
169 :background "springgreen")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
170 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
171 :background "chartreuse4")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
172 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
173 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 "Used for displaying the second matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (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
178 '((((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
179 :background "yellow1")
31aa9a390538 * mh-customize.el (mh-speedbar-selected-folder-face): Special case
Dan Nicolaescu <dann@ics.uci.edu>
parents: 60282
diff changeset
180 (((class color) (background light))
41371
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
181 :background "yellow")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
182 (((class color) (background dark))
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
183 :background "sienna4")
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
184 (t
d99daedf49db (reb-match-0, reb-match-1)
Miles Bader <miles@gnu.org>
parents: 41333
diff changeset
185 :inverse-video t))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 "Used for displaying the third matching subexpression."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 :group 're-builder)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 ;; Internal variables below
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (defvar reb-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 "Enables the RE Builder minor mode.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (defvar reb-target-buffer nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 "Buffer to which the RE is applied to.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (defvar reb-target-window nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 "Window to which the RE is applied to.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (defvar reb-regexp nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 "Last regexp used by RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (defvar reb-regexp-src nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 "Last regexp used by RE Builder before processing it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 Except for Lisp syntax this is the same as `reb-regexp'.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (defvar reb-overlays nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 "List of overlays of the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (defvar reb-window-config nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 "Old window configuration.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (defvar reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 "Indicates whether sub-exp mode is active.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 (defvar reb-subexp-displayed nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 "Indicates which sub-exp is active.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (defvar reb-mode-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 "String in mode line for additional info.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (defvar reb-valid-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 "String in mode line showing validity of RE.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (make-variable-buffer-local 'reb-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (make-variable-buffer-local 'reb-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (make-variable-buffer-local 'reb-regexp-src)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (defconst reb-buffer "*RE-Builder*"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 "Buffer to use for the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 ;; Define the local "\C-c" keymap
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
232 (defvar reb-mode-map
93674
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
233 (let ((map (make-sparse-keymap))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
234 (menu-map (make-sparse-keymap)))
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
235 (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
236 (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
237 (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
238 (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
239 (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
240 (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
241 (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
242 (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
243 (define-key map "\C-c\C-u" 'reb-force-update)
93674
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
244 (define-key map [menu-bar reb-mode] (cons "Re-Builder" menu-map))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
245 (define-key menu-map [rq]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
246 '(menu-item "Quit" reb-quit
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
247 :help "Quit the RE Builder mode"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
248 (define-key menu-map [rt]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
249 '(menu-item "Case sensitive" reb-toggle-case
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
250 :button (:toggle . case-fold-search)
100048
d872c709fff2 * emacs-lisp/re-builder.el (reb-mode-map): Fix typo in menu tooltip.
Juanma Barranquero <lekktu@gmail.com>
parents: 100018
diff changeset
251 :help "Toggle case sensitivity of searches for RE Builder target buffer"))
93674
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
252 (define-key menu-map [rb]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
253 '(menu-item "Change target buffer..." reb-change-target-buffer
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
254 :help "Change the target buffer and display it in the target window"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
255 (define-key menu-map [rs]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
256 '(menu-item "Change syntax..." reb-change-syntax
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
257 :help "Change the syntax used by the RE Builder"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
258 (define-key menu-map [re]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
259 '(menu-item "Enter subexpression mode" reb-enter-subexp-mode
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
260 :help "Enter the subexpression mode in the RE Builder"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
261 (define-key menu-map [ru]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
262 '(menu-item "Force update" reb-force-update
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
263 :help "Force an update in the RE Builder target window without a match limit"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
264 (define-key menu-map [rn]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
265 '(menu-item "Go to next match" reb-next-match
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
266 :help "Go to next match in the RE Builder target window"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
267 (define-key menu-map [rp]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
268 '(menu-item "Go to previous match" reb-prev-match
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
269 :help "Go to previous match in the RE Builder target window"))
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
270 (define-key menu-map [rc]
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
271 '(menu-item "Copy current RE" reb-copy
44fab469d68d * outline.el (outline-mode-menu-bar-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93198
diff changeset
272 :help "Copy current RE into the kill ring for later insertion"))
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
273 map)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 "Keymap used by the RE Builder.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275
100048
d872c709fff2 * emacs-lisp/re-builder.el (reb-mode-map): Fix typo in menu tooltip.
Juanma Barranquero <lekktu@gmail.com>
parents: 100018
diff changeset
276 (define-derived-mode reb-mode nil "RE Builder"
d872c709fff2 * emacs-lisp/re-builder.el (reb-mode-map): Fix typo in menu tooltip.
Juanma Barranquero <lekktu@gmail.com>
parents: 100018
diff changeset
277 "Major mode for interactively building Regular Expressions."
73928
5aa08f9f45e5 (reb-mode): Set `blink-matching-paren' to nil in the *RE-Builder*
Juanma Barranquero <lekktu@gmail.com>
parents: 70404
diff changeset
278 (set (make-local-variable 'blink-matching-paren) nil)
100048
d872c709fff2 * emacs-lisp/re-builder.el (reb-mode-map): Fix typo in menu tooltip.
Juanma Barranquero <lekktu@gmail.com>
parents: 100018
diff changeset
279 (reb-mode-common))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (define-derived-mode reb-lisp-mode
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 emacs-lisp-mode "RE Builder Lisp"
41225
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
283 "Major mode for interactively building symbolic Regular Expressions."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (cond ((eq reb-re-syntax 'lisp-re) ; Pull in packages
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (require 'lisp-re)) ; as needed
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 ((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
287 (require 'sregex)) ; right now..
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
288 ((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
289 (require 'rx))) ; require rx anyway
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (reb-mode-common))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 ;; 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
293 ;; `emacs-lisp-mode'
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (define-key reb-lisp-mode-map "\C-c"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (lookup-key reb-mode-map "\C-c"))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48379
diff changeset
297 (defvar reb-subexp-mode-map
41225
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
298 (let ((m (make-keymap)))
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
299 (suppress-keymap m)
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
300 ;; 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
301 (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
302 (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
303 (dotimes (digit 10)
74219f3013c6 (reb-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38436
diff changeset
304 (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
305 m)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 "Keymap used by the RE Builder for the subexpression mode.")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (defun reb-mode-common ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 "Setup functions common to functions `reb-mode' and `reb-mode-lisp'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (setq reb-mode-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 reb-valid-string ""
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 mode-line-buffer-identification
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 '(25 . ("%b" reb-mode-string reb-valid-string)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (reb-update-modestring)
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
316 (add-hook 'after-change-functions 'reb-auto-update nil t)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 ;; At least make the overlays go away if the buffer is killed
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
318 (add-hook 'kill-buffer-hook 'reb-kill-buffer nil t)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (reb-auto-update nil nil nil))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (defun reb-color-display-p ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 "Return t if display is capable of displaying colors."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (eq 'color
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 ;; emacs/xemacs compatibility
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (if (fboundp 'frame-parameter)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (frame-parameter (selected-frame) 'display-type)
64382
c16c027014c6 (reb-cook-regexp): Avoid warning calling lre-compile-string.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
327 (if (fboundp 'frame-property)
c16c027014c6 (reb-cook-regexp): Avoid warning calling lre-compile-string.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
328 (frame-property (selected-frame) 'display-type)))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (defsubst reb-lisp-syntax-p ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 "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
332 (memq reb-re-syntax '(lisp-re sregex rx)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (defmacro reb-target-binding (symbol)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 "Return binding for SYMBOL in the RE Builder target buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 `(with-current-buffer reb-target-buffer ,symbol))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
338 (defun reb-initialize-buffer ()
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
339 "Initialize the current buffer as a RE Builder buffer."
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
340 (erase-buffer)
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
341 (reb-insert-regexp)
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
342 (goto-char (+ 2 (point-min)))
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
343 (cond ((reb-lisp-syntax-p)
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
344 (reb-lisp-mode))
100018
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
345 (t (reb-mode)))
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
346 (reb-do-update))
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
347
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
348 (defun reb-mode-buffer-p ()
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
349 "Return non-nil if the current buffer is a RE Builder buffer."
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
350 (memq major-mode '(reb-mode reb-lisp-mode)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
351
60282
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
352 ;;; This is to help people find this in Apropos.
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
353 ;;;###autoload
64557
c68bf82df188 (regexp-builder): Use `defalias' instead of faking it.
Juanma Barranquero <lekktu@gmail.com>
parents: 64382
diff changeset
354 (defalias 'regexp-builder 're-builder)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 ;;;###autoload
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (defun re-builder ()
60282
b6fcc94c2d6a (regexp-builder): New function.
Richard M. Stallman <rms@gnu.org>
parents: 59396
diff changeset
358 "Construct a regexp interactively."
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360
41314
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
361 (if (and (string= (buffer-name) reb-buffer)
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
362 (reb-mode-buffer-p))
41314
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
363 (message "Already in the RE Builder")
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
364 (when reb-target-buffer
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
365 (reb-delete-overlays))
41314
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
366 (setq reb-target-buffer (current-buffer)
100018
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
367 reb-target-window (selected-window))
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
368 (select-window (or (get-buffer-window reb-buffer)
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
369 (progn
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
370 (setq reb-window-config (current-window-configuration))
811c2c99eed5 * emacs-lisp/re-builder.el (reb-auto-update): Remove redundant code.
Juanma Barranquero <lekktu@gmail.com>
parents: 94655
diff changeset
371 (split-window (selected-window) (- (window-height) 4)))))
41314
a2bce9d9c349 (re-builder): Don't re-enter RE Builder Mode.
Eli Zaretskii <eliz@gnu.org>
parents: 41313
diff changeset
372 (switch-to-buffer (get-buffer-create reb-buffer))
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
373 (reb-initialize-buffer)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374
41313
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
375 (defun reb-change-target-buffer (buf)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
376 "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
377 (interactive "bSet target buffer to: ")
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
378
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
379 (let ((buffer (get-buffer buf)))
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
380 (if (not buffer)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
381 (error "No such buffer")
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
382 (reb-delete-overlays)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
383 (setq reb-target-buffer buffer)
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
384 (reb-do-update
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
385 (if reb-subexp-mode reb-subexp-displayed nil))
2186cf9476ba (reb-change-target-buffer): New function.
Eli Zaretskii <eliz@gnu.org>
parents: 41225
diff changeset
386 (reb-update-modestring))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (defun reb-force-update ()
56698
7dbbaf3dc171 (reb-mode-map): Define within defvar.
John Paul Wallington <jpw@pobox.com>
parents: 56611
diff changeset
389 "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
390 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (let ((reb-auto-match-limit nil))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (reb-update-overlays
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (if reb-subexp-mode reb-subexp-displayed nil))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (defun reb-quit ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 "Quit the RE Builder mode."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (setq reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 reb-subexp-displayed nil)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (reb-delete-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (bury-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (set-window-configuration reb-window-config))
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-next-match ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 "Go to next 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)
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
411 (with-selected-window reb-target-window
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (if (not (re-search-forward reb-regexp (point-max) t))
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
413 (message "No more matches")
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (reb-show-subexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (or (and reb-subexp-mode reb-subexp-displayed) 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 t))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (defun reb-prev-match ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 "Go to previous match in the RE Builder target window."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (reb-assert-buffer-in-window)
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
423 (with-selected-window reb-target-window
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
424 (let ((p (point)))
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
425 (goto-char (1- p))
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
426 (if (re-search-backward reb-regexp (point-min) t)
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
427 (reb-show-subexp
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
428 (or (and reb-subexp-mode reb-subexp-displayed) 0)
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
429 t)
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
430 (goto-char p)
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
431 (message "No more matches")))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (defun reb-toggle-case ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 "Toggle case sensitivity of searches for RE Builder target buffer."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (setq case-fold-search (not case-fold-search)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (reb-auto-update nil nil nil t))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (defun reb-copy ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 "Copy current RE into the kill ring for later insertion."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (reb-update-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (let ((re (with-output-to-string
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (print (reb-target-binding reb-regexp)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (kill-new (substring re 1 (1- (length re))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (message "Regexp copied to kill-ring")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 ;; The subexpression mode is not electric because the number of
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 ;; matches should be seen rather than a prompt.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (defun reb-enter-subexp-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 "Enter the subexpression mode in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (setq reb-subexp-mode t)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (use-local-map reb-subexp-mode-map)
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
460 (message "`0'-`9' to display subexpressions `q' to quit subexp mode"))
28077
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-show-subexp (subexp &optional pause)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 "Visually show limit of subexpression SUBEXP of recent search.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 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
465 the match should already be marked by an overlay.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 On other displays jump to the beginning and the end of it.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 If the optional PAUSE is non-nil then pause at the end in any case."
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
468 (with-selected-window reb-target-window
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
469 (unless (reb-color-display-p)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
470 (goto-char (match-beginning subexp))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
471 (sit-for reb-blink-delay))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (goto-char (match-end subexp))
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
473 (when (or (not (reb-color-display-p)) pause)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
474 (sit-for reb-blink-delay))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (defun reb-quit-subexp-mode ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 "Quit the subexpression mode in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (setq reb-subexp-mode nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 reb-subexp-displayed nil)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (use-local-map reb-mode-map)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (reb-do-update))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (defun reb-change-syntax (&optional syntax)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 "Change the syntax used by the RE Builder.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 Optional argument SYNTAX must be specified if called non-interactively."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (interactive
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (list (intern
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (completing-read "Select syntax: "
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (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
492 '(read string lisp-re sregex rx))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 nil t (symbol-name reb-re-syntax)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
495 (if (memq syntax '(read string lisp-re sregex rx))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (let ((buffer (get-buffer reb-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (setq reb-re-syntax syntax)
64624
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
498 (when buffer
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
499 (with-current-buffer buffer
c3a907cbd503 (reb-with-current-window): Delete.
Juanma Barranquero <lekktu@gmail.com>
parents: 64557
diff changeset
500 (reb-initialize-buffer))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (error "Invalid syntax: %s" syntax)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 ;; Non-interactive functions below
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (defun reb-do-update (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 "Update matches in the RE Builder target window.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 If SUBEXP is non-nil mark only the corresponding sub-expressions."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 (reb-assert-buffer-in-window)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 (reb-update-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 (reb-update-overlays subexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (defun reb-auto-update (beg end lenold &optional force)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 "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
515 BEG, END and LENOLD are passed in from the hook.
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 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
517 optional fourth argument FORCE is non-nil."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (let ((prev-valid reb-valid-string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (new-valid
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (condition-case nil
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 (progn
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
522 (when (or (reb-update-regexp) force)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
523 (reb-do-update))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 (error " *invalid*"))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (setq reb-valid-string new-valid)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (force-mode-line-update)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 ;; Through the caching of the re a change invalidating the syntax
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 ;; for symbolic expressions will not delete the overlays so we
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 ;; catch it here
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
532 (when (and (reb-lisp-syntax-p)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
533 (not (string= prev-valid new-valid))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
534 (string= prev-valid ""))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
535 (reb-delete-overlays))))
28077
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-delete-overlays ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 "Delete all RE Builder overlays in the `reb-target-buffer' buffer."
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
539 (when (buffer-live-p reb-target-buffer)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (with-current-buffer reb-target-buffer
84902
ba9c9ff8aab7 (reb-delete-overlays): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents: 78217
diff changeset
541 (mapc 'delete-overlay reb-overlays)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 (setq reb-overlays nil))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 (defun reb-assert-buffer-in-window ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 "Assert that `reb-target-buffer' is displayed in `reb-target-window'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (if (not (eq reb-target-buffer (window-buffer reb-target-window)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (set-window-buffer reb-target-window reb-target-buffer)))
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 (defun reb-update-modestring ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 "Update the variable `reb-mode-string' displayed in the mode line."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 (setq reb-mode-string
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (concat
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 (if reb-subexp-mode
35756
8a4490cbee15 (reb-update-modestring): Don't use concat for integers.
Eli Zaretskii <eliz@gnu.org>
parents: 28107
diff changeset
555 (format " (subexp %s)" (or reb-subexp-displayed "-"))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 "")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (if (not (reb-target-binding case-fold-search))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 " Case"
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (force-mode-line-update))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (defun reb-display-subexp (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 "Highlight only subexpression SUBEXP in the RE Builder."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 (interactive)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (setq reb-subexp-displayed
101008
5aa3a4e05089 Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
567 (or subexp (string-to-number (format "%c" last-command-event))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (reb-update-modestring)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 (reb-do-update reb-subexp-displayed))
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 (defun reb-kill-buffer ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 "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
573
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
574 (when (reb-mode-buffer-p)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
575 (reb-delete-overlays)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 ;; The next functions are the interface between the regexp and
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 ;; its textual representation in the RE Builder buffer.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 ;; They are the only functions concerned with the actual syntax
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 ;; being used.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 (defun reb-read-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 "Read current RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (save-excursion
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (cond ((eq reb-re-syntax 'read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (read (current-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 ((eq reb-re-syntax 'string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (goto-char (point-min))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (re-search-forward "\"")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (let ((beg (point)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 (goto-char (point-max))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 (re-search-backward "\"")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (buffer-substring-no-properties beg (point))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (buffer-string)))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (defun reb-empty-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 "Return empty RE for current syntax."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (cond ((reb-lisp-syntax-p) "'()")
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (t "")))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 (defun reb-insert-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 "Insert current RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 (let ((re (or (reb-target-binding reb-regexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (reb-empty-regexp))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 (cond ((eq reb-re-syntax 'read)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609 (print re (current-buffer)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 ((eq reb-re-syntax 'string)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 (insert "\n\"" re "\""))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 ;; For the Lisp syntax we need the "source" of the regexp
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 ((reb-lisp-syntax-p)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 (insert (or (reb-target-binding reb-regexp-src)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615 (reb-empty-regexp)))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 (defun reb-cook-regexp (re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 "Return RE after processing it according to `reb-re-syntax'."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 (cond ((eq reb-re-syntax 'lisp-re)
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
620 (when (fboundp 'lre-compile-string)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
621 (lre-compile-string (eval (car (read-from-string re))))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 ((eq reb-re-syntax 'sregex)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (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
624 ((eq reb-re-syntax 'rx)
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
625 (rx-to-string (eval (car (read-from-string re)))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (t re)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 (defun reb-update-regexp ()
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 "Update the regexp for the target buffer.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 Return t if the (cooked) expression changed."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631 (let* ((re-src (reb-read-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 (re (reb-cook-regexp re-src)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (with-current-buffer reb-target-buffer
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (let ((oldre reb-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 (prog1
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (not (string= oldre re))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 (setq reb-regexp re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 ;; Only update the source re for the lisp formats
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
639 (when (reb-lisp-syntax-p)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
640 (setq reb-regexp-src re-src)))))))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 ;; And now the real core of the whole thing
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 (defun reb-count-subexps (re)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 "Return number of sub-expressions in the regexp RE."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 (let ((i 0) (beg 0))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 (while (string-match "\\\\(" re beg)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 (setq i (1+ i)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 beg (match-end 0)))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 i))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (defun reb-update-overlays (&optional subexp)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 "Switch to `reb-target-buffer' and mark all matches of `reb-regexp'.
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 If SUBEXP is non-nil mark only the corresponding sub-expressions."
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 (let* ((re (reb-target-binding reb-regexp))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 (subexps (reb-count-subexps re))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (matches 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 (submatches 0)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 firstmatch)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 (save-excursion
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 (set-buffer reb-target-buffer)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (reb-delete-overlays)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 (goto-char (point-min))
76540
2f2e0b6d33c0 (reb-update-overlays): Do not mark zero-width regexps as invalid
Juanma Barranquero <lekktu@gmail.com>
parents: 76350
diff changeset
665 (while (and (not (eobp))
2f2e0b6d33c0 (reb-update-overlays): Do not mark zero-width regexps as invalid
Juanma Barranquero <lekktu@gmail.com>
parents: 76350
diff changeset
666 (re-search-forward re (point-max) t)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 (or (not reb-auto-match-limit)
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (< matches reb-auto-match-limit)))
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
669 (when (and (= 0 (length (match-string 0)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
670 (not (eobp)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
671 (forward-char 1))
70404
ce092da13632 (reb-update-overlays): Cycle through provided faces once they all have been
Eli Zaretskii <eliz@gnu.org>
parents: 68648
diff changeset
672 (let ((i 0)
ce092da13632 (reb-update-overlays): Cycle through provided faces once they all have been
Eli Zaretskii <eliz@gnu.org>
parents: 68648
diff changeset
673 suffix max-suffix)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (setq matches (1+ matches))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 (while (<= i subexps)
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
676 (when (and (or (not subexp) (= subexp i))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
677 (match-beginning i))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
678 (let ((overlay (make-overlay (match-beginning i)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
679 (match-end i)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
680 ;; When we have exceeded the number of provided faces,
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
681 ;; cycle thru them where `max-suffix' denotes the maximum
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
682 ;; suffix for `reb-match-*' that has been defined and
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
683 ;; `suffix' the suffix calculated for the current match.
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
684 (face
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
685 (cond
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
686 (max-suffix
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
687 (if (= suffix max-suffix)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
688 (setq suffix 1)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
689 (setq suffix (1+ suffix)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
690 (intern-soft (format "reb-match-%d" suffix)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
691 ((intern-soft (format "reb-match-%d" i)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
692 ((setq max-suffix (1- i))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
693 (setq suffix 1)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
694 ;; `reb-match-1' must exist.
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
695 'reb-match-1))))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
696 (unless firstmatch (setq firstmatch (match-data)))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
697 (setq reb-overlays (cons overlay reb-overlays)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
698 submatches (1+ submatches))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
699 (overlay-put overlay 'face face)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
700 (overlay-put overlay 'priority i)))
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701 (setq i (1+ i))))))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 (let ((count (if subexp submatches matches)))
56611
8b14a3e64595 (reb-re-syntax): Add `rx' syntax.
John Paul Wallington <jpw@pobox.com>
parents: 56382
diff changeset
703 (message "%s %smatch%s%s"
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 (if (= 0 count) "No" (int-to-string count))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (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
706 (if (= 1 count) "" "es")
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 (if (and reb-auto-match-limit
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708 (= reb-auto-match-limit count))
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709 " (limit reached)" "")))
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
710 (when firstmatch
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
711 (store-match-data firstmatch)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
712 (reb-show-subexp (or subexp 0)))))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
713
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
714 ;; The End
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
715 (defun re-builder-unload-function ()
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
716 "Unload the RE Builder library."
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
717 (when (buffer-live-p (get-buffer reb-buffer))
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
718 (with-current-buffer reb-buffer
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
719 (remove-hook 'after-change-functions 'reb-auto-update t)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
720 (remove-hook 'kill-buffer-hook 'reb-kill-buffer t)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
721 (when (reb-mode-buffer-p)
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
722 (reb-delete-overlays)
104684
b1cb2e195329 * arc-mode.el (archive-mode):
Juanma Barranquero <lekktu@gmail.com>
parents: 104682
diff changeset
723 (funcall (or (default-value 'major-mode) 'fundamental-mode)))))
93198
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
724 ;; continue standard unloading
eb3d659f5085 (reb-mode-common): Remove reference to bogus variable `reb-kill-buffer';
Juanma Barranquero <lekktu@gmail.com>
parents: 87649
diff changeset
725 nil)
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
726
48379
6e55b7742a81 Add provide call.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 41371
diff changeset
727 (provide 're-builder)
6e55b7742a81 Add provide call.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 41371
diff changeset
728
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93674
diff changeset
729 ;; arch-tag: 5c5515ac-4085-4524-a421-033f44f032e7
28077
30c2ad45d57b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730 ;;; re-builder.el ends here