9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Spell checking with acme in p9p
@ 2013-12-15 11:55 trebol
  0 siblings, 0 replies; 7+ messages in thread
From: trebol @ 2013-12-15 11:55 UTC (permalink / raw)
  To: 9fans

When recently I discovered Plan9, the first things I missed were a
non-only-English spell checker, support for other languages in troff
(mostly hyphenation), and other dictionaries for dict.  I've ported
"international ispell" to ape and write aispell, a modified version of
aspell script that work with ispell, I've formatted GCIDE, "Chambers's
Twentieth Century Dictionary", "Diccionario de la Real Academia de la
Lengua Española", "Moby Thesaursus" and "OpenThesaurus-es", and I was
hopping working in troff when I'll learn programming.  The lack of a
web browser capable of deal with today's madness and the portability
limitation of ape (at least for a ignorant like me) forcesme to deal
with other OS I have to install and maintaining, so the simplicity and
cleanness I like so much of plan9 become useless.  Thanks to Russ Cox for P9P!  

I've write a script for p9p too, you only need to install gnu
aspell (or other spell checker with "ispell -a" support) and compile a
slightly modified spout.c with rune support (I've called it uspout), so you can
use the script like native acme's aspell script.  This is from my README.PLAN9 file:

[...]
In the acme directory are aispell, an equivalent script of aspell and
uspout.c, slighted modified spout.c for UTF-8 runes, needed by aispell
to support non English languages.  You can pass ispell options as
arguments to aispell, for example for use the Spanish dictionary you can put
in the tag:
>aispell -despañol -Tutf8 

Or put 'aispell -despañol -Tutf8 $*' in a script and call
it aispelles, for example.  Defining a function in lib/profile didn't
work for me...  You can use it in any text selected, but for now, if
it doesn't start at the beginning of the buffer, the output's
addresses will be wrong.  This package install American and British
dictionaries.  If you are interested, look at the Spanish_ispell package I've
ported from http://www.datsi.fi.upm.es/~coes.
[...]

In P9P you don't need "-Tutf8".  I was going to ask for a directory in
sources, but I haven't see any interest in those things in the list.  I hope 
that this will help you.
The script and spout's source are small, so I'm going to paste both here.
trebol.

#!/usr/local/plan9/bin/rc
# Don't forget to check the path!
# aispell_p9p

rm -f /tmp/$pid^'.'aispell

spellpgr=aspell
args=()
spellflags=()
for(x){
	switch($x){
	case -d*
		spellflags=($spellflags $x)
	case -p*
		spellflags=($spellflags $x)
	case -T*
		spellflags=($spellflags $x)
	case *
		args=($args $x)
	}
}

id=`{9p read acme/new/ctl}
id=$id(1)

echo 'name '^`{pwd}^/-spell | 9p write acme/$id/ctl

{
	if(~ $#args 0){
		cat > /tmp/$pid^'.'aispell
		args=/tmp/$pid^'.'aispell
		pipe=1
	}
	for(i in $args){
			name=$i
			if(~ $pipe 1){
				name=`{9p read acme/$winid/tag | 9 sed 's/ .*//g'}
				if(~ name '') name=nonamedwindow
			}
		for(j in `{{cat $i; echo} | uspout | 9 sort -t: -u +2 | 9 sed 's/$/\!/g' | $spellpgr -a $spellflags | 9 grep '^[&#]' | 9 sed 's/ /_/g'}){
		# {cat $i; echo} is for uspout, needs \n. Also I want to make a list of lines, so j can't have spaces 

			miss=`{ echo $j | awk -F_ '{print $2}'}
			sug=`{ echo $j | 9 sed 's/^.*://g'} # Can't put 9 grep -v '^#' here...
			{cat $i; echo} |
			uspout |
			9 grep '.*:'$miss'$' |
			9 sed 's/$/ '$sug'/g' | # If I put 9 grep -v '^#' above, this 9 sed cuts output, I don't know why ...
			9 sed 's/#_.*$//g' |
			9 sed 's/_/ /g' |  # If I put 9 sed 's/_/ /g' above, variables don't work in 9 sed.  Again, I don't know why...
			9 sed s',^,'$name',g' | 9p write acme/$id/body
		}

	}
	rm -f /tmp/$pid^'.'aispell
	echo clean | 9p write acme/$id/ctl
}


------------------------
------------------------
uspout.c's source:
#include <u.h>
#include <libc.h>
#include <ctype.h>
#include <bio.h>

void	spout(int, char*);

Biobuf bout;

void
main(int argc, char *argv[])
{
	int i, fd;

	Binit(&bout, 1, OWRITE);
	if(argc == 1)
		spout(0, "");
	else
		for(i=1; i<argc; i++){
			fd = open(argv[i], OREAD);
			if(fd < 0){
				fprint(2, "spell: can't open %s: %r\n", argv[i]);
				continue;
			}
			spout(fd, argv[i]);
			close(fd);
		}
	exits(nil);
}

Biobuf b;

void
spout(int fd, char *name)
{
	char *s, *t, *w;
	Rune r;
	int inword, wordchar;
	int n, wn, wid, c, m;
	char buf[1024];

	Binit(&b, fd, OREAD);
	n = 0;
	wn = 0;
	while((s = Brdline(&b, '\n')) != nil){
		if(s[0] == '.')
			for(c=0; c<3 && *s>' '; c++){
				n++;
				s++;
			}
		inword = 0;
		w = s;
		t = s;
		do{
			c = *(uchar*)t;
			if(c < Runeself)
				wid = 1;
			else{
				wid = chartorune(&r, t);
				c = r;
			}
			wordchar = 0;
			if(isalpharune(c))
				wordchar = 1;
			if(inword && !wordchar){
				if(c=='\'' && isalpha(t[1]))
					goto Continue;
				m = t-w;
				if(m > 1){
					memmove(buf, w, m);
					buf[m] = 0;
					Bprint(&bout, "%s:#%d,#%d:%s\n", name, wn, n, buf);
				}
				inword = 0;
			}else if(!inword && wordchar){
				wn = n;
				w = t;
				inword = 1;
			}
			if(c=='\\' && (isalpha(t[1]) || t[1]=='(')){
				switch(t[1]){
				case '(':
					m = 4;
					break;
				case 'f':
					if(t[2] == '(')
						m = 5;
					else
						m = 3;
					break;
				case 's':
					if(t[2] == '+' || t[2]=='-'){
						if(t[3] == '(')
							m = 6;
						else
							m = 4;
					}else{
						if(t[2] == '(')
							m = 5;
						else if(t[2]=='1' || t[2]=='2' || t[2]=='3')
							m = 4;
						else
							m = 3;
					}
					break;
				default:
					m = 2;
				}
				while(m-- > 0){
					if(*t == '\n')
						break;
					n++;
					t++;
				}
				continue;
			}
	Continue:
			n++;
			t += wid;
		}while(c != '\n');
	}
	Bterm(&b);
}



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] Spell checking with acme in p9p
  2013-12-15 15:08   ` Blake McBride
  2013-12-15 16:03     ` erik quanstrom
@ 2013-12-15 16:27     ` Mark van Atten
  1 sibling, 0 replies; 7+ messages in thread
From: Mark van Atten @ 2013-12-15 16:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> Sometimes, like when you issue a command and the result goes to the Errors
> window, I would like to be able to execute text in the Errors window that
> would affect the window the Error window represents.  This would be very
> powerful.

If the original window already has the Edit command in the tag, and
the commands in +Error (or some other window) are in sam's language,
you can select those commands with B1 and then execute them in the
context of the original window by a B2-B1 chord on that window's Edit.

Closely related:
http://9fans.net/archive/2009/06/138

Mark.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] Spell checking with acme in p9p
  2013-12-15 15:08   ` Blake McBride
@ 2013-12-15 16:03     ` erik quanstrom
  2013-12-15 16:27     ` Mark van Atten
  1 sibling, 0 replies; 7+ messages in thread
From: erik quanstrom @ 2013-12-15 16:03 UTC (permalink / raw)
  To: 9fans

> window, I would like to be able to execute text in the Errors window that
> would affect the window the Error window represents.  This would be very
> powerful.  I could highlight text in a window, execute a command on it, and
> that command would provide me with a series of commands I can run on the
> original window to perform some operation (since the original window and
> the Error window are related at that point).  Anyway, please let me know if
> this is possible.

if the directory is properly set for the +Errors window (unfortunately it's not),
then external commands will be run in the same directory.  but Edit commands
do not refer to the original window.  without some major rearrangment of
acme's internals, i don't think this is possible.  this would be like having a ~~sam~~
window.

- erik



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] Spell checking with acme in p9p
  2013-12-15 12:01 ` Rubén Berenguel
@ 2013-12-15 15:08   ` Blake McBride
  2013-12-15 16:03     ` erik quanstrom
  2013-12-15 16:27     ` Mark van Atten
  0 siblings, 2 replies; 7+ messages in thread
From: Blake McBride @ 2013-12-15 15:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 2088 bytes --]

On Sun, Dec 15, 2013 at 6:01 AM, Rubén Berenguel <ruben@mostlymaths.net>wrote:

> ....
> By the way, do you know about 1-2 chords, don't you? For some of these
> tasks it may be useful.
>
>
I have only a vague notion of chords at this point.  I have two button mouse.
 I simulate the button-2 with alt-left-click.  Because of this I thought I
might not even be able to do chords.

As you can tell, I am just learning acme.  So far, I have been successful
in making it my main editor.  I initially spent a bunch of time with sam.
 I like it a lot too.  I had a problem with sam trying to deal with
multiple buffers.  I understand the ability to define where they are
displayed but switching between a bunch of buffers was inconvenient.  IMO,
acme is much better at handling multiple windows since you can drag things
around very easily.  Acme's ability to dump/load state is very convenient
too.  One big thing I like about sam is the edit window.  I can deal with a
buffer in sudu-ed commands and see the results.  I like this.

One thing I just noticed about acme which I don't yet understand is the
following.  I just noticed that I can click-drag with the button-2 and
button-3 too.  Didn't realize this before.  Not sure what they do yet.

Another thing that I don't think can be done with acme but I am wondering
is as follows.  When you have a command in a window (Undo for example), the
command affects either the window it is in, or the window it is a tag for.
 Sometimes, like when you issue a command and the result goes to the Errors
window, I would like to be able to execute text in the Errors window that
would affect the window the Error window represents.  This would be very
powerful.  I could highlight text in a window, execute a command on it, and
that command would provide me with a series of commands I can run on the
original window to perform some operation (since the original window and
the Error window are related at that point).  Anyway, please let me know if
this is possible.

Thanks a lot for all the help!!

Blake

[-- Attachment #2: Type: text/html, Size: 3479 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] Spell checking with acme in p9p
  2013-12-15  2:46 Blake McBride
  2013-12-15  3:45 ` Bakul Shah
@ 2013-12-15 12:01 ` Rubén Berenguel
  2013-12-15 15:08   ` Blake McBride
  1 sibling, 1 reply; 7+ messages in thread
From: Rubén Berenguel @ 2013-12-15 12:01 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 2730 bytes --]

Sometimes (for long pieces of text like blog posts) I use wwb to check
style and readability. Correcting something usually is

1. Right-click the line number in +errors
2. Correct
3. Go back to 1

For spell checking, tweaking aspell's output is best. Also, keep in mind
that all the steps can be (after tweaking)

1. Double click the correct word in +Errors
2. 2-3 chord to copy it (so you don't even leave the line or mouse)
2. 3 click the line number (I think there is a way to use :lineno with an
additional regex, that would be handy here to directly land on the word)
3. Double click the wrong word
4. Without leaving 1 pressed, 3 to paste (pressing command if on trackpad)

It's pretty fast, actually. Beware of adding column pos to aspell output,
since after editing the buffer these will change.

By the way, do you know about 1-2 chords, don't you? For some of these
tasks it may be useful.

Ruben

PS: Sent it a while ago, always forgetting I don't have this email account
configured on my iPad :/


On Sun, Dec 15, 2013 at 3:46 AM, Blake McBride <blake@mcbride.name> wrote:

> Greetings,
>
> I am trying to get spell checking working with acme on a Mac using p9p.  I
> am using the following script:
>
>     #
>     aspell pipe |grep '^&'
>
> When run on a text selection (with >), it returns me with a list of
> incorrectly spelled words along with a list of potential corrections.  Each
> line represents the misspelled word and its suggested corrections.  Cool,
> I've got what I need.
>
> I can modify what it returns through awk to give me the line and
> character of the word, and reformat the line to be more meaningful to acmeif it would be helpful.
>
> The problem is that there are a lot of steps to make a correction.  I
> think I need to:
>
> 1.  snarf the misspelled word from the Errors buffer
>
> 2.  Paste the word into the tag line of the file being checked
>
> 3.  Right-click on the word in the tag line to find it in the input file
>
> 4.  Select the correct spelling from one of the aspell suggestions in the
> Errors window and snarf it.
>
> 5.  Select the incorrectly spelled word in the input file and paste the
> corrected word in its place.
>
> As I said earlier, I may be able to simplify a step or so by reformatting
> the result of the spell check with awk, but I'm not sure what would be
> helpful yet.
>
> So, I guess the point of this is that there are a lot of steps necessary
> to correct a text's spelling.  It would be easier just to do:
>
>     aspell check file.txt
>
> But that would be side-stepping acme.  I am just wondering how others
> handle this situation.
>
> Thank you!
>
> Blake McBride
>
>

[-- Attachment #2: Type: text/html, Size: 5598 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] Spell checking with acme in p9p
  2013-12-15  2:46 Blake McBride
@ 2013-12-15  3:45 ` Bakul Shah
  2013-12-15 12:01 ` Rubén Berenguel
  1 sibling, 0 replies; 7+ messages in thread
From: Bakul Shah @ 2013-12-15  3:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Sat, 14 Dec 2013 20:46:40 CST Blake McBride <blake@mcbride.name> wrote:
>
> So, I guess the point of this is that there are a lot of steps necessary to
> correct a text's spelling.  It would be easier just to do:
>
>     aspell check file.txt
>
> But that would be side-stepping acme.  I am just wondering how others
> handle this situation.

Don't think acme is particularly suited for spell correction.
If I am unsure of a spelling I just use "look <prefix>" which
spits out words with that prefix -- this is usually good
enough.  For scripts with complex layout (which are not
displayed properly by most all CLI programs), I use TextEdit
or a word processor.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [9fans] Spell checking with acme in p9p
@ 2013-12-15  2:46 Blake McBride
  2013-12-15  3:45 ` Bakul Shah
  2013-12-15 12:01 ` Rubén Berenguel
  0 siblings, 2 replies; 7+ messages in thread
From: Blake McBride @ 2013-12-15  2:46 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

Greetings,

I am trying to get spell checking working with acme on a Mac using p9p.  I
am using the following script:

    #
    aspell pipe |grep '^&'

When run on a text selection (with >), it returns me with a list of
incorrectly spelled words along with a list of potential corrections.  Each
line represents the misspelled word and its suggested corrections.  Cool,
I've got what I need.

I can modify what it returns through awk to give me the line and character
of the word, and reformat the line to be more meaningful to acme if it
would be helpful.

The problem is that there are a lot of steps to make a correction.  I think
I need to:

1.  snarf the misspelled word from the Errors buffer

2.  Paste the word into the tag line of the file being checked

3.  Right-click on the word in the tag line to find it in the input file

4.  Select the correct spelling from one of the aspell suggestions in the
Errors window and snarf it.

5.  Select the incorrectly spelled word in the input file and paste the
corrected word in its place.

As I said earlier, I may be able to simplify a step or so by reformatting
the result of the spell check with awk, but I'm not sure what would be
helpful yet.

So, I guess the point of this is that there are a lot of steps necessary to
correct a text's spelling.  It would be easier just to do:

    aspell check file.txt

But that would be side-stepping acme.  I am just wondering how others
handle this situation.

Thank you!

Blake McBride

[-- Attachment #2: Type: text/html, Size: 2884 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-12-15 16:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-15 11:55 [9fans] Spell checking with acme in p9p trebol
  -- strict thread matches above, loose matches on Subject: below --
2013-12-15  2:46 Blake McBride
2013-12-15  3:45 ` Bakul Shah
2013-12-15 12:01 ` Rubén Berenguel
2013-12-15 15:08   ` Blake McBride
2013-12-15 16:03     ` erik quanstrom
2013-12-15 16:27     ` Mark van Atten

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).