File: re-builder.el.html

When I have to come up with regular expressions that are more complex than simple string matchers, especially if they contain sub expressions, I find myself spending quite some time in the development cycle. re-builder aims to shorten this time span so I can get on with the more interesting bits.

With it you can have immediate visual feedback about how well the regexp behaves to your expectations on the intended data.

When called up re-builder attaches itself to the current buffer which becomes its target buffer, where all the matching is done. The active window is split so you have a view on the data while authoring the RE. If the edited expression is valid the matches in the target buffer are marked automatically with colored overlays
(for non-color displays see below) giving you feedback over the
extents of the matched (sub) expressions. The (non-)validity is shown only in the mode line without throwing the errors at you. If you want to know the reason why RE Builder considers it as invalid call reb-force-update ("\\C-c\\C-u") which should reveal the error.

The target buffer can be changed with reb-change-target-buffer
("\\C-c\\C-b"). Changing the target buffer automatically removes
the overlays from the old buffer and displays the new one in the target window.

The re-builder keeps the focus while updating the matches in the target buffer so corrections are easy to incorporate. If you are satisfied with the result you can paste the RE to the kill-ring with reb-copy ("\\C-c\\C-w"), quit the re-builder ("\\C-c\\C-q") and use it wherever you need it.

As the automatic updates can take some time on large buffers, they can be limited by reb-auto-match-limit so that they should not have a negative impact on the editing. Setting it to nil makes even the auto updates go all the way. Forcing an update overrides this limit allowing an easy way to see all matches.

Currently re-builder understands three different forms of input, namely read, string, and rx syntax. Read syntax and string syntax are both delimited by "s and behave according to their name. With the string syntax there's no need to escape the backslashes and double quotes simplifying the editing somewhat. The rx syntax allows editing of symbolic regular expressions supported by the package of the same name.

Editing symbolic expressions is done through a major mode derived from emacs-lisp-mode so you'll get all the good stuff like automatic indentation and font-locking etc.

When editing a symbolic regular expression, only the first expression in the RE Builder buffer is considered, which helps limiting the extent of the expression like the "s do for the text modes. For the rx syntax the function rx-to-string is applied to the evaluated expression read. So you can use quoted arguments with something like '("findme") or you can construct arguments to your hearts delight with a valid Elisp expression. (The compiled
string form will be copied by reb-copy) If you want to take
a glance at the corresponding string you can temporarily change the input syntax.

Changing the input syntax is transparent (for the obvious exception non-symbolic -> symbolic) so you can change your mind as often as you like.

There is also a shortcut function for toggling the case-fold-search variable in the target buffer with an immediate update.

Q: But what if my display cannot show colored overlays? A: Then the cursor will flash around the matched text making it stand
   out.

Q: But how can I then make out the sub-expressions? A: That's where the sub-expression mode comes in. In it only the
   digit keys are assigned to perform an update that will flash the
   corresponding subexp only.

Defined variables (25)

reb-auto-match-limitPositive integer limiting the matches for RE Builder auto updates.
reb-blink-delaySeconds to blink cursor for next/previous match in RE Builder.
reb-bufferBuffer to use for the RE Builder.
reb-lisp-mode-abbrev-tableAbbrev table for ‘reb-lisp-mode’.
reb-lisp-mode-hookHook run after entering ‘reb-lisp-mode’.
reb-lisp-mode-mapKeymap for ‘reb-lisp-mode’.
reb-lisp-mode-syntax-tableSyntax table for ‘reb-lisp-mode’.
reb-modeEnables the RE Builder minor mode.
reb-mode-abbrev-tableAbbrev table for ‘reb-mode’.
reb-mode-hookHooks to run on entering RE Builder mode.
reb-mode-mapKeymap used by the RE Builder.
reb-mode-menuMenu for the RE Builder.
reb-mode-stringString in mode line for additional info.
reb-mode-syntax-tableSyntax table for ‘reb-mode’.
reb-overlaysList of overlays of the RE Builder.
reb-re-syntaxSyntax for the REs in the RE Builder.
reb-regexpLast regexp used by RE Builder.
reb-regexp-srcLast regexp used by RE Builder before processing it.
reb-subexp-displayedIndicates which sub-exp is active.
reb-subexp-modeIndicates whether sub-exp mode is active.
reb-subexp-mode-mapKeymap used by the RE Builder for the subexpression mode.
reb-target-bufferBuffer to which the RE is applied to.
reb-target-windowWindow to which the RE is applied to.
reb-valid-stringString in mode line showing validity of RE.
reb-window-configOld window configuration.

Defined functions (41)

re-builder()
re-builder-unload-function()
reb-assert-buffer-in-window()
reb-auto-update(BEG END LENOLD &optional FORCE)
reb-change-syntax(&optional SYNTAX)
reb-change-target-buffer(BUF)
reb-color-display-p()
reb-cook-regexp(RE)
reb-copy()
reb-count-subexps(RE)
reb-delete-overlays()
reb-display-subexp(&optional SUBEXP)
reb-do-update(&optional SUBEXP)
reb-empty-regexp()
reb-enter-subexp-mode()
reb-fontify-string-re(BOUND)
reb-force-update()
reb-initialize-buffer()
reb-insert-regexp()
reb-kill-buffer()
reb-lisp-mode()
reb-lisp-syntax-p()
reb-mark-non-matching-parenthesis(BOUND)
reb-mode()
reb-mode-buffer-p()
reb-mode-common()
reb-mode-menu(ARG1)
reb-next-match()
reb-prev-match()
reb-quit()
reb-quit-subexp-mode()
reb-read-regexp()
reb-restart-font-lock()
reb-show-subexp(SUBEXP &optional PAUSE)
reb-target-value(SYMBOL)
reb-toggle-case()
reb-update-modestring()
reb-update-overlays(&optional SUBEXP)
reb-update-regexp()
reb-while(LIMIT CURRENT WHERE)
regexp-builder()

Defined faces (6)

reb-match-0Used for displaying the whole match.
reb-match-1Used for displaying the first matching subexpression.
reb-match-2Used for displaying the second matching subexpression.
reb-match-3Used for displaying the third matching subexpression.
reb-regexp-grouping-backslashFont Lock mode face for backslashes in Lisp regexp grouping constructs.
reb-regexp-grouping-constructFont Lock mode face used to highlight grouping constructs in Lisp regexps.