Nyes, even more slithering Perl Horrors for you to use!

I'll put a few helpful Perl (and elisp) scripts here. These are not really long enough to be noded separately...

Take and use these as you see fit. Just don't blame me if they don't work. =)

e2-filter.el

This will filter text files in Emacs/XEmacs so that they'll look more or less interesting when copied/pasted. (I used it to filter these scripts, for example... =)

What this does?... it translates & to &amp;, translates square brackets to &#91; and &#93;, and < and > to &lt; and &gt;.

Has been tested in XEmacs 21.4.something and above. I have no idea how it works in other Emacs versions.

To use this, put (load "~/path/to/file/e2-filter") to your ~/.emacs or ~/.xemacs/init.el file.


;;; Filters the region for potentially annoying stuff...
;;; By Weyfour WWWWolf, 2000-10-20
;;;
;;; $Id: e2-filter.el,v 1.0.1.1 2000/10/20 18:06:35 wwwwolf Exp wwwwolf $
;;;
;;; Distributed under the Artistic Lisence.

; Taken mostly from documentation...
(defun glob-replace (from to)
  "Globally replaces string `from' to `to'."
  (goto-char 0)
  (while (search-forward from nil t)
    (replace-match to nil t)))

(defun e2-escape-region (min max)
  "HTML-escapes the current region, also replacing square brackets with
   &#91; and &#93;. Mostly aimed at Everything2.com users."
  (interactive "r")
  (buffer-disable-undo)
  (narrow-to-region min max)
  (glob-replace "&" "&amp;")
  (glob-replace "[" "&#91;")
  (glob-replace "]" "&#93;")
  (glob-replace "<" "&lt;")
  (glob-replace ">" "&gt;")
  (widen)
  (buffer-enable-undo)
  (message "Done."))

fake-e2-linker.pl

This generates a HTML for previewing purposes. See that sumbit sinking feeling for philosophical background. This script is probably better than the Python script featured there. =)

It's called "fake" linker because the first version didn't link the links anywhere, but it did produce the <A> tags.

Usage: perl fake-e2-linker.pl yournode.txt > nodepreview.html

Variations of theme:

  • that sumbit sinking feeling (Python script that does the same)
  • E2 Offline Scratchpad (Windows app. Not that I have anything against it, but let's compare it a little: Do you want a huge bells-and-whistles noding environment, or a little tool that integrates well with others? For bells and whistles, go for E2OS. For a nice little tool, try my script.)


#!/usr/bin/perl -w
############################################################################
#
# Fake E2 linker
# Useful for "previewing" stuff "offline" before posting.
#
# Written by Weyfour WWWWolf / Urpo Lankinen
# Use as you see fit, no warranty.
#
# $Id: fake-e2-linker.pl,v 1.5 2001/05/05 23:29:58 wwwwolf Exp wwwwolf $
#
############################################################################
#
# Updated 2000-08-20 - Noether mentioned some Python crap that
#   was apparently cooler than this (See "that sumbit sinking
#   feeling"). Punished with extreme cruelty.
# Updated 2001-05-06 - Uses some More Interesting Perl Idioms now,
#   like proper looping, commented regular expressions,
#   and "s" modifier of regex instead of concatenation - so now
#   <pre>...</pre> elements will no longer break and other weird
#   things should not happen... as often! =) This ought to be
#   easier to understand for the newbies, too.
#
############################################################################

use strict; # Jawohl, Herr Obersturmführer!
use URI;    # Doesn't come with Perl, but everyone should have it anyway =)

# Print HTML header
print "<!doctype html public \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n",
  "<html>\n<head>\n<title>Cheesy node preview</title>",
  "\n</head>\n<body>\n<h1>Node preview</h1>\n\n<hr>\n";

# Join everything from input files. (All lines have "\n" in the end...)
# I know, I know, memory/efficiency requirements.
$_ = join "", <>;

# Loop as long as there are linked words.
while(1) {
  if(m{
       \[               # Starting bracket
       ([^\|\]]*\|)?    # Possibly the pipelink part (To $1)
       ([^\]]*)         # Link text                  (To $2)
       \]               # Ending bracket
      }sx) {

    my $match = $&;     # Whole matched expression (to be replaced later)
    my $dest = $1 || "";
    my $linkword = $2;

    $dest =~ s/\|$//;  # Remove the oft-abused idiom
    $dest =~ s/\s+/ /; # Keep whitespace in order

    # Link is either pipelink or link word destination in E2...
    my $link =
      URI->new('http://www.everything2.com/?node=' .
	       ($dest ? $dest : $linkword))->canonical->as_string;

    # We do quoting so that our pattern match will work a bit better...
    $match = quotemeta($match);

    # Replace our previously matched text with the link...
    s!$match!<a href="$link">$linkword</a>!gi;

  } else {
    # We no longer have anything that matches, so let's exit the loop.
    last;
  }
}
# Print out the new and improved file.
print;

# Print out the HTML footer.
print "<hr>\n<p>Spewed forth by fake-e2-linker.pl by WWWWolf\n",
       "</body>\n</html>\n";



More Slithering Perl Horrors!