[comp.unix.questions] VI & spell

glex@uf.msc.umn.edu (Jeffrey Gleixner) (11/12/89)

I finally have gotten so sick of typo's that I want to run spell while in
vi, without exiting or suspending, the file.   So I wrote a small script (sp).
It takes the input from vi (:1,$!sp) and redirects it to a file, I run
spell on the file, pulling up a window (Sun) displaying the output from spell.
The window waits for a <CR> and then exits.  Well that works just fine EXCEPT 
that I can't continue with vi until I exit the window, probably waiting for 
the !sp to finish.

There has to be a way to do what I want but I haven't been able to figure 
it out, any ideas???????

Thanks for your help.
Please reply E-Mail to: 
glex@msc.umn.edu
-glex-

wyle@inf.ethz.ch (Mitchell Wyle) (11/13/89)

In article <740@uc.msc.umn.edu> glex@uf.UUCP (Jeffrey Gleixner) writes:
>It takes the input from vi (:1,$!sp) and redirects it to a file, I run
>[...]
>There has to be a way to do what I want but I haven't been able to figure 
>it out, any ideas???????

>Please reply E-Mail to: 
>glex@msc.umn.edu

Well, I hope Jeff reads this group... I think that this "spell check from
within vi" topic should be posted to frequently asked questions and answers.
What do you say, Bill?  I also think that Brandon should scan these groups
for clever scripts and post them to comp.sources.misc.  What about it,
Brandon?

To answer the question,  Among all the schemes that I've seen over the
years, I've settled on this one.  It checks the spelling of one paragraph at
a time and highlights the mis-spelled words with ### chars.


1) Put this or a similar macro in your .exrc

map ;sp !}spell_check^V^M

2) Put spell_check in an appropriate place (/usr/local/bin or ~/bin

#!/bin/sh
############################################################################
#	A sh script to allow spelling checks either in vi or stand alone   #
#	Usage: spell_check < file or within vi,				   #
#		!}spell_check		or				   #
#		:(addressed lines)!spell_check				   #
#									   #
#       The wrongly spelled words will be surrounded by ###bad-word###     #
#	WARNING: Do not try and sell this tiny shell script to some        #
#       poor sucker!							   #
#	Badri Lokanathan, 30 September 1988                                #
#                                              	                           #
#	New flags added for tput support. If tput is present, then         #
#	spell_check -H uses highlight mode for use with more.              #
#	All other flags are passed to spell.                               #
#	Badri Lokanathan,  6 March 1989                                    #
############################################################################

PATH=/usr/local/bin:/usr/bin:/bin:/usr/ucb:$HOME/bin
doc=/tmp/splchk.$$
scr=/tmp/sedscr.$$

trap 'rm -f $doc $scr; exit 1' 1 2 15
#
# Modify the following line to your wordlist database
# spellflags="-d $HOME/lib/wlist"
#
T1="###"
T2="###"
for flag in $*
do
	case $flag in
		-H|-Highlight|-highlight)
			T1="`tput bold; tput smso`"	# Comment out if tput
			T2="`tput sgr0; tput rmso`"	# is not available
			;;
			    	       *) spellflags="$spellflags $flag" ;;
	esac
done

cat > $doc

############################################################################
# The following is for macho sed hackers only.                             #
############################################################################
cat > $scr <<HEAD
s/^/ /
s/\$/ /
HEAD

spell $spellflags < $doc | sed -e "\
	s/^/s;\\\\([ 	][^a-zA-Z0-9]*\\\\)\\\\(/
	s/\$/\\\\)\\\\([^a-zA-Z0-9]*[ 	]\\\\);\\\\1${T1}\\\\2${T2}\\\\3;g/
	s/ \$//" >> $scr

cat >> $scr <<TAIL
s/^ //
s/ \$//
TAIL

#
# Uncomment the following lines if error count is to be limited
#
#count=`wc -l < $scr`
#if [ $count -gt 50 ]
#then
#	echo "Too many mistakes for spell_check. Use spell directly."
#else
	sed -f $scr $doc
#fi

rm -f $doc $scr


BTW:  If you are running on a Sun, why not just have another window open, :w
the file from vi, and spell it from a different window?  I don't get it.

maart@cs.vu.nl (Maarten Litmaath) (11/14/89)

In article <740@uc.msc.umn.edu> glex@uf.UUCP (Jeffrey Gleixner) writes:
\I finally have gotten so sick of typo's that I want to run spell while in
\vi, without exiting or suspending, the file.   So I wrote a small script (sp).
\It takes the input from vi (:1,$!sp) and redirects it to a file, I run
                             ^^^^^^^
This command will overwrite the buffer with the output from sp.
The following command will just feed the buffer to sp:

	:w !sp

Notice the space between the `w' and the `!'.

\spell on the file, pulling up a window (Sun) displaying the output from spell.
\The window waits for a <CR> and then exits.  Well that works just fine EXCEPT 
\that I can't continue with vi until I exit the window, probably waiting for 
\the !sp to finish.

Indeed.  Try something like this for sp (without the indentation!):

	#!/bin/sh

	cat > /tmp/sp.$$
	trap '' 2 18 21 22 	# trap SIGINT, SIGTSTP, SIGTTIN and SIGTTOU
	(
		# do funny stuff here
	) &	# maybe some redirections are appropriate

sp exits while its child will continue processing in the background.
If you don't trap the stop signals, something `funny' happens when you
stop vi (^Z) while the background job is still running, so that it would
be stopped too, implicitly: (relevant BSD kernel code)

	case SIGTSTP:
	case SIGTTIN:
	case SIGTTOU:
		/*
		 * Children of init aren't allowed to stop
		 * on signals from the keyboard.
		 */
		if (p->p_pptr == &proc[1]) {
			psignal(p, SIGKILL);
			continue;
		}

The stop signal is changed to a kill signal!
BTW, how about the following, Mr. Bourne?!

	trap '' SIGINT SIGTSTP SIGTTIN SIGTTOU
or
	trap '' INT TSTP TTIN TTOU
-- 
"Richard Sexton is actually an AI program (or Construct, if you will) running
on some AT&T (R) 3B" (Richard Brosseau) | maart@cs.vu.nl, mcsun!botter!maart

steinbac@hpl-opus.HP.COM (Gunter Steinbach) (11/15/89)

/ hpl-opus:comp.unix.questions / glex@uf.msc.umn.edu (Jeffrey Gleixner) / 12:08 am  Nov 12, 1989 /
I finally have gotten so sick of typo's that I want to run spell while in
vi, without exiting or suspending, the file.   So I wrote a small script (sp).
It takes the input from vi (:1,$!sp) and redirects it to a file, I run
spell on the file, pulling up a window (Sun) displaying the output from spell.
The window waits for a <CR> and then exits.  Well that works just fine EXCEPT 
that I can't continue with vi until I exit the window, probably waiting for 
the !sp to finish.

There has to be a way to do what I want but I haven't been able to figure 
it out, any ideas???????

Thanks for your help.
Please reply E-Mail to: 
glex@msc.umn.edu
-glex-
----------

mercer@ncrcce.StPaul.NCR.COM (Dan Mercer) (11/15/89)

In article <4525@ski.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
:In article <740@uc.msc.umn.edu> glex@uf.UUCP (Jeffrey Gleixner) writes:
:\I finally have gotten so sick of typo's that I want to run spell while in
:\vi, without exiting or suspending, the file.   So I wrote a small script (sp).
:\It takes the input from vi (:1,$!sp) and redirects it to a file, I run
:                             ^^^^^^^
:This command will overwrite the buffer with the output from sp.
:The following command will just feed the buffer to sp:
:
:   :w !sp
:
:Notice the space between the `w' and the `!'.
:
:\spell on the file, pulling up a window (Sun) displaying the output from spell.
:\The window waits for a <CR> and then exits.  Well that works just fine EXCEPT 
:\that I can't continue with vi until I exit the window, probably waiting for 
:\the !sp to finish.
:
:Indeed.  Try something like this for sp (without the indentation!):
:
:   #!/bin/sh
:
:   cat > /tmp/sp.$$
:   trap '' 2 18 21 22  # trap SIGINT, SIGTSTP, SIGTTIN and SIGTTOU
:   (
:       # do funny stuff here
:   ) & # maybe some redirections are appropriate
:
:sp exits while its child will continue processing in the background.
:If you don't trap the stop signals, something `funny' happens when you
:stop vi (^Z) while the background job is still running, so that it would
:be stopped too, implicitly: (relevant BSD kernel code)
:
:   case SIGTSTP:
:   case SIGTTIN:
:   case SIGTTOU:
:       /*
:        * Children of init aren't allowed to stop
:        * on signals from the keyboard.
:        */
:       if (p->p_pptr == &proc[1]) {
:           psignal(p, SIGKILL);
:           continue;
:       }
:
:The stop signal is changed to a kill signal!
:BTW, how about the following, Mr. Bourne?!
:
:   trap '' SIGINT SIGTSTP SIGTTIN SIGTTOU
:or
:   trap '' INT TSTP TTIN TTOU
:-- 
:"Richard Sexton is actually an AI program (or Construct, if you will) running
:on some AT&T (R) 3B" (Richard Brosseau) | maart@cs.vu.nl, mcsun!botter!maart

On our SYSV Towers,  spell is implemented as a very inefficient shell
script,  with /usr/lib/spell/spellprog as the actual program (although
it requires a word/line input).  I de-engineered it and turned it into
Spell,  designed not only to proofread,  but to mark errors

=======================CUT HERE============================
HLISTA="/usr/lib/spell/spellprog /usr/lib/spell/hlista"
TMP=/usr/tmp/Spell$$

SCRIPT=

for i in `tee $TMP | deroff -w | $HLISTA`
    do
    SCRIPT="${SCRIPT}s/$i/\/\/\/${i}\/\/\//g
"
    done

sed "$SCRIPT" $TMP

rm $TMP

exit 0
=======================CUT HERE============================

the following two command in my .exrc file invoke it:

map ^V<ESC>s !}Spell^V^M/\/\/\/^Mw
map! ^V<ESC>s ^V<ESC>!}Spell^V^M/\/\/\/^Mw

============================================================

Now is the winter of ourr discontemt made weerder
by the moment by trying to think up sammple paragrafs
to demo this shit.


================is replaced by==============================

Now is the winter of ///ourr/// ///discontemt/// made ///weerder///
by the moment by trying to think up ///sammple/// ///paragrafs///
to ///demo/// this ///shit///.

============================================================

Of course,  this cores on our old news machine (Tower 1650).


On our normal machines,  it works quite well and speedily.

Normal disclaimers apply.

Does anyone know how spellprog works - the format of the spell
databases?  If I knew I'd do this up right.


-- 

Dan Mercer
Reply-To: mercer@ncrcce.StPaul.NCR.COM (Dan Mercer)

jon@jonlab.UUCP (Jon H. LaBadie) (11/22/89)

In article <4525@ski.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes:
> In article <740@uc.msc.umn.edu> glex@uf.UUCP (Jeffrey Gleixner) writes:
> \I finally have gotten so sick of typo's that I want to run spell while in
> \vi, without exiting or suspending, the file.   So I wrote a small script (sp).
> \It takes the input from vi (:1,$!sp) and redirects it to a file, I run

I may have overlooked this suggestion in past articles.
If so, I apologize to regular readers.

I integrate spell and vi using the editor's own facilities.  My .exrc
file, or EXINIT parameter if you chose, contains the following function
key maping:

  map #1 :w^MGo-----  Output Of Spell Program  -----^M^[!!spell %^M

Note, the ^M sequence represents a real <RETURN> and the ^[ is a real
<ESC> character.  These may have to be entered by quoting them with
the editor's quoting character ^V, <CONTROL V>.

Now, the effect of all this.  Press function key number 1, your current
buffer is saved under the current name (:w^M).

Back in the editor, your cursor is moved to the end of the file (G) and
two lines are added to the buffer.  The first one is a separator, the
second one is blank (o-----  Output Of Spell Program  -----^M^[).

The blank line is passed to the spell program's standard input stream
which ignores is since we also give it a filename argument with the "%"
character.  The output of spell, when it finishes, replaces the blank
line in the buffer.

What we end up with then looks like this:

  some text in the unix file
  more text, maybe with a misteak
  the last line of text from the original file
  -----  Output Of Spell Program  -----
  misteak
  unix

Note, spell's output is in your editor buffer, not in some file, not
blasting away at your terminal screen.  Your cursor is on the first
"misspelled" word in the list.

Now, what do we do with the list?  First, if you are certain the
spelling is correct, simply delete the line from the list (dd).
This is useful if the "misspelled" word is a personal name or a
known acronym.

If you feel the word is misspelled, search for it:
  /misteak^M
correct it:
  cwmistake^[
repeat the search for a second occurrance.
  n
If you are back to spell output list, you have found each occurrance.
Delete the line from the list.  Otherwise, you are on a second
instance of the misspelling.  Correct it also but use the vi "dot"
command to repeat the last change to the buffer:
  .

BTW, to assist in the look-up of the correct spelling of words,
I wrote a short shell script, "spelltell", that accepts the initial
fragment of a word and prints all words in a dictionary that begin
with that fragment.  For example, here is a sample run:

  Enter an initial fragment of the word you are seeking: acro
  acrobacy
  acrobat
  acrobatic
  acrolein
  acronym
  acrophobia
  acropolis
  across
  acrostic
  Enter an initial fragment of the word you are seeking: ^D

Let me know if there is any interest.  You need 3 things,
 1. ksh
 2. a version of look(1) - one was posted to comp.sources.misc
 3. an ascii version of the dictionary

-- 
Jon LaBadie
{att, princeton, bcr}!jonlab!jon
{att, attmail, bcr}!auxnj!jon