Improved /etc/browse.rc and ~/.browserc macros

Peter da Silva peter at ficc.uu.net
Thu Apr 12 05:38:08 AEST 1990


Archive-name: browse/newmacros

The following sets of TCL macro files for browse greatly enhance the
program. Some of them require the "stream" routines, from my version
of TCL. They will be posted in a subsequent message.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix at uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of shell archive."
# Contents:  browse.rc sample.rc
# Wrapped by peter at ficc.uu.net on Wed Apr 11 14:34:18 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'browse.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'browse.rc'\"
else
echo shar: Extracting \"'browse.rc'\" \(3334 characters\)
sed "s/^X//" >'browse.rc' <<'END_OF_FILE'
Xset more [get env PAGER]
Xif { [length $more chars] == 0 } { set more more }
X
Xproc perror {} {
X	browse message [get error]
X	browse bell
X}
X
Xproc target {} {
X	set file [get file *]
X	if {[length $file chars]==0} {set file [get file .]}
X	return $file
X}
X
Xproc key_'j' {} {
X	if { ![browse move +1] } { browse bell }
X}
Xproc key_'k' {} {
X	if { ![browse move -1] } { browse bell }
X}
Xproc key_':' {} {
X	set command [get response :]
X	if { [length $command chars] > 0 } {
X		if { [catch {eval $command} response] != 0 } {
X			browse message Error: $response
X		} else {
X			if { [length $response chars] > 0 } {
X				browse message Response: $response
X			}
X		}
X	}
X}
Xproc key_'!' {} {
X	global shellcmd
X	set command [get response ! shellcmd]
X	if { [length $command chars] > 0 } {
X		browse shell $command
X		set shellcmd $command
X	}
X}
Xproc key_space {} {
X	global more
X	set file [get file .]
X	if { ![browse chdir $file] } {
X		set file [target]
X		eval [concat browse tag - $file]
X		browse message !$more $file
X		browse shell [concat $more $file]
X	}
X}
Xproc key_'q' {} {
X	if { [string compare q [get key -q-]] == 0 } {
X		browse exit
X	} else {
X		browse message
X	}
X}
Xproc key_'^J' {} {
X	if { [string match *line [get mode]] } { browse redraw }
X}
Xproc key_'d' {} {
X	if { [string compare d [get key -d-]] == 0 } {
X		set file [target]
X		set prompt [concat Delete $file {? }]
X		if { [string match {[yY]} [get key $prompt]] } {
X			if { ![eval [concat browse delete $file]] } {
X				perror
X			}
X		}
X	}
X}
Xproc cdhelp {name def} {
X	set dir $name[get response [concat chdir $name] $def]
X	if { ![browse chdir $dir] } { perror }
X}
Xproc key_'=' {} { cdhelp {} [get file .] }
Xproc key_'.' {} { cdhelp . {} }
Xproc key_'/' {} { cdhelp / {} }
Xproc key_'~' {} { cdhelp [get env HOME] {} }
Xproc key_'t' {} { eval [concat browse tag / [get file .]] }
Xproc key_'H' {} { browse move [get line home] }
Xproc key_'L' {} { browse move [get line last] }
Xproc key_dollar_sign {} { browse move [get line end] }
Xproc key_'J' {} { browse move [get line end] }
Xproc key_'^' {} { browse move 0 }
Xproc key_'K' {} { browse move 0 }
Xproc key_'M' {} { browse move [expr ([get line home]+[get line last])/2] }
Xproc key_'<' {} { browse mode narrow }
Xproc key_'>' {} { browse mode wide }
Xproc key_'^R' {} { browse rescan }
Xproc key_'^L' {} { browse redraw }
X
Xproc key_'r' {} {
X	set file [get file .]
X	set prompt [concat Rename $file {to }]
X	set new_file [get response $prompt $file]
X	if { ![browse rename $file $new_file] } {
X		perror
X	}
X}
X
Xproc key_'R' {} {
X	set files [get file *]
X	if { [length files] == 0 } {
X		key_'r'
X	} else {
X		set dir [get response {Move tagged files to }]
X		foreach file $files {
X			if { ![browse rename $file $dir/$file] } {
X				perror
X				return
X			}
X		}
X	}
X}
X
Xproc key_'v' {} { 
X	set command [concat vi [get file .]]
X	browse message !$command
X	browse shell $command
X}
X
Xproc macro_'#' {} { return [get cwd] }
Xproc macro_'%' {} { return [get file .] }
Xproc macro_'~' {} { return [get env HOME] }
X
Xproc key_'^F' {} {
X	browse move [expr {[get line .]+10}]
X}
X
Xproc key_'^B' {} {
X	browse move [expr {[get line .]-10}]
X}
X
Xproc key_'+' {} {
X	set file [get response {Add file: }]
X	if { [length $file chars] > 0 } {
X		if { ![browse add $file] } {
X			perror
X		}
X	}
X}
X
Xproc key_'p' {} {
X	set files [target]
X	eval [concat browse tag /P [target]]
X	eval [concat browse tag -T [target]]
X}
END_OF_FILE
if test 3334 -ne `wc -c <'browse.rc'`; then
    echo shar: \"'browse.rc'\" unpacked with wrong size!
fi
# end of 'browse.rc'
fi
if test -f 'sample.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sample.rc'\"
else
echo shar: Extracting \"'sample.rc'\" \(2204 characters\)
sed "s/^X//" >'sample.rc' <<'END_OF_FILE'
Xproc key_'^K' {} {
X	browse message {Edit key }
X	set key [get key]
X	set func key_[get keyname $key]
X	set file [get env HOME]/.function
X	if { [length [info procs $func] ] != 0 } {
X		set def [list proc $func {} [info body $func]]
X	} else {
X		set def [list proc $func {} { ... }]
X	}
X	print $def\n $file
X	browse message !vi $file
X	browse shell [concat vi $file]
X	source $file
X}
X
Xproc save {file args} {
X	if { [length $args chars] == 0 } {
X		print "# *** all procs ***" $file
X		print \n $file append
X		set args [info procs]
X	} else {
X		print [concat {#} $args] $file
X		print \n $file append
X	}
X	foreach proc $args {
X		set def [list proc $proc [info args $proc] [info body $proc]]
X		print \n$def\n $file append
X	}
X}
X
Xproc macro_'#' {} { return [get cwd] }
X
Xproc key_'s' {} { 
X	set f [stream open [get file .] r]
X	for {} { [stream gets $f line] } {} {
X		if {[string match Subject:* $line]} {
X			browse message $line
X			break
X		}
X	}
X	stream close $f
X}
X
Xproc key_'g' {} { 
X	set f [stream open [get file .] r]
X	for {} { [stream gets $f line] } {} {
X		if {[string match Newsgroups:* $line]} {
X			browse message [range $line 1 end]
X			break
X		}
X	}
X	stream close $f
X}
X
Xproc key_'i' {} {
X	if { [string match *line [get mode]] } { browse redraw }
X}
X
Xproc key_'^F' {} {
X	set func [get line {Edit function }]
X	if { [length $func chars] == 0 }
X		return
X	set file [get env HOME]/.function
X	if { [length [info procs $func] ] != 0 } {
X		set def [list proc $func {} [info body $func]]
X	} else {
X		set def [list proc $func {} { ... }]
X	}
X	print $def\n $file
X	browse message !vi $file
X	browse shell [concat vi $file]
X	source $file
X}
X
Xproc key_'S' {} { 
X	set f [stream open [get file .] r]
X	set newname [get file .]
X	for {} { [stream gets $f line] } {} {
X		if {[string match Subject:* $line]} {
X			set newname [get line $line\ =\ ]
X			break
X		}
X	}
X	stream close $f
X	browse rename [get file .] $newname
X}
X
Xproc key_'?' {} {
X	set fd [stream open [get file .] r]
X	for {} { [stream gets $fd line] } {} {
X		set line [range <$line> 0 78 chars]
X		set key [get key $line]
X		if { [string compare $key ?] != 0 } break
X	}
X	if { [string compare $key ?] == 0 } {
X		browse message
X	} else {
X		eval key_[get keyname $key]
X	}
X	stream close $fd
X}
END_OF_FILE
if test 2204 -ne `wc -c <'sample.rc'`; then
    echo shar: \"'sample.rc'\" unpacked with wrong size!
fi
# end of 'sample.rc'
fi
echo shar: End of shell archive.
exit 0
-- 
 _--_|\  `-_-' Peter da Silva. +1 713 274 5180. <peter at ficc.uu.net>.
/      \  'U`
\_.--._/
      v



More information about the Alt.sources mailing list