sam-fans - fans of the sam editor
 help / color / mirror / Atom feed
From: Ed Kubaitis - CCSO <ejk@ux2.cso.uiuc.edu>
To: sam-fans@hawkwind.utcs.toronto.edu
Subject: substitute delimited words
Date: Sun, 25 Apr 1993 13:13:48 -0400	[thread overview]
Message-ID: <199304251713.AA64824@ux2.cso.uiuc.edu> (raw)

Here's a script that uses the sam command pipe to save keystrokes when
substituting delimited words.                                              

Ed
==============================================================================
#! /usr/local/bin/perl
#
#   sam_sw - generate sam command to substitute delimited words
#
#   usage: !sam_sw [-X] [-,] from to

while($_ = $ARGV[0], /^-/) {
   shift;
   if    (m!^-X$!) { $XFlag++; $CommaFlag++; }
   elsif (m!^-,$!) { $CommaFlag++; }
   else            { &usage; }
   }
($from,$to, @toomany) = @ARGV;
&usage if @toomany || !$from || !$to;

$command = "X " if $XFlag;
$command .= "," if $CommaFlag;
$from =~ s/([()*[\]\\^\$+?!])/\\$1/g; # escape meta characters
$to =~ s/([()*[\]\\^\$+?!])/\\$1/g;
$command .= "s!(^|[^A-Za-z0-9_])$from(\$|[^A-Za-z0-9_])!\\1$to\\2!g\n";
&sampipe($command);

sub sampipe {
   local($commands) = @_;

   $user = $ENV{'USER'};
   $user = $ENV{'LOGNAME'} unless $user;
   $user || die "$0: no USER or LOGNAME environment variable.\n";

   $pipe = ".sam.$user";
   $pipe .= ".$ENV{'DISPLAY'}" if $ENV{'DISPLAY'};

   $Pipe = "/tmp/$pipe";
   $Pipe = "/usr/tmp/$pipe" unless -p $Pipe;
   -p $Pipe || die "$0: no sam pipe($pipe) in /tmp or /usr/tmp\n";

   open(Pipe, ">$Pipe") || die "$0: $Pipe: $!\n";
   print Pipe "$commands";
   close(Pipe);
   }

sub usage { die "usage: !sam_sw [-X] [-,] from to\n"; }


                 reply	other threads:[~1993-04-25 17:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199304251713.AA64824@ux2.cso.uiuc.edu \
    --to=ejk@ux2.cso.uiuc.edu \
    --cc=sam-fans@hawkwind.utcs.toronto.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).