in reply to [emacs] short review of regex-tool.el

When I want to test a regex, I usually open up an xemacs shell buffer (or even a regular command shell) and run the following eval loop to check regular expressions: perl -ne'print eval($_) . "\n"'. Then I type in lines like

$re=qr{^abc}; 'abcdef' =~ $re; 'zabcdef' =~ $re; $x='Some long and ugly text'; $x =~ /long and ugly/; # and so on...

Doing it in a shell buffer makes it easy to cut and paste values for either the text or the regex from other code. Then when I have a regular expression that does what I want I can cut & paste it back into my code very easily as well. An eval shell a lot gives me a lot of flexibility for playing "write-a-little, test-a-little".

Yet you write with enthusiam "I like it!". Perhaps you could explain what a dedicated regex mode adds for you beyond what I just described? I'm probably too set in my ways, but I'm not seeing it.

Now, what would be nice is Perl command buffer along the lines of the e-shell. That would convert even my minimal one-liner to start the eval loop into a mindless click. I wrote something like that for myself a year or so ago, but it seems to have disappeared in one of my periodic migrations from machine to machine.

Best, beth

Replies are listed 'Best First'.
Re^2: [emacs] short review of regex-tool.el
by LanX (Saint) on Sep 21, 2009 at 13:55 UTC
    Hi Beth,

    just some short answers, let me list some advantages in comparison to your method:

  • the matches in the string are highlighted (see screenshot)
  • you get an immediate update while you type and change the regex or text
  • you can manage larger (then one line) texts easier than from command prompt.
  • you can use all emacs commands/macros on the windows, especially undo and redo to get back and forward in your change history.

    Furthermore, from a emacs perspective, the elisp-code is _very_ short and simple, facilitating personal changes in just this module.

    (For instance I would like to run a command to take a snapshot of the three windows, and to append it persistently to my tests. And vice versa I would like to select just one of these tests again to continue interactive testing. One doesn't need deep knowledge of elisp to do this, since one can simply pipe any window's text in and out a perl-script to transform it.)

    Did you ever think (or try) to change the code in cperl-mode.el? It's a huge monolithic block of over 4000 lines, unfortunately it's not broken up into smaller modules... it's very hard to realize changes which will survive the next update.

    Of course your technique or the other mentioned in Composing regular expressions at runtime give experienced coders deeper testing possibilities for complicated code ... but if one is either new or in "brainless-mode" and doesn't want to code a loop it's a very good start. Talking about shell-support, you might wanna give sepia a try, it's full perl REPL integrated into emacs, of course with history functions.

    Furthermore it should be possible to tweak the perldebugger into a regex-tester with history cache, one can add aliases for personal commands and the docs mention pre and post commands to run with each prompt. (anyway I couldn't make the latter work using commands like <,> and { ...???)

    Cheers Rolf

    UPDATE: just found a note that it doesn't work with Xemacs :-( Sadly these incompatibilities are the main reason why I switched to Gnu Emacs a year ago, while I still recommend xemacs for newbies.

Re^2: [emacs] short review of regex-tool.el
by LanX (Saint) on Sep 23, 2009 at 12:37 UTC
    Hi

    Now, what would be nice is Perl command buffer along the lines of the e-shell.

    I took a look into M-x eshell, in both emacsen, but I have problems to see what it's good for... the documentation is a stub and the functionality is barely better than with M-x shell ...???

    Anyway if you want a nice perl-shell embedded into emacs you should really try to install sepia, I simply took the debian install package and it worked straight away (well in GNU not Xemacs).

    Cheers Rolf