From: Paul Onyschuk <ptmelville@gmail.com>
To: edbrowse-dev@lists.the-brannons.com
Subject: [Edbrowse-dev] [acmebrowse] Mouse driven interface for edbrowse
Date: Wed, 30 Jul 2014 14:40:46 +0200 [thread overview]
Message-ID: <20140730144046.9db3985ff43654767c4eee8c@gmail.com> (raw)
First of all I would like to thank for edbrowse - this is a fine
software. Second, this isn't much of use for users without a sight.
Since edbrowse accepts the plain text on a standard input and spits out
the plain text on a standard output, it can be scripted. Acme is a
graphical text editor from the Plan9 operating system. I won't go into
much detail explaining exactly what Acme can do. Russ Cox made a
video presenting some of the features [1].
Acme provides interfaces, where events like mouse clicks can be
captured. The acmebrowse script parses those events and pipes
meaningful actions into edbrowse, then an output from edbrowse is piped
back into a window in acme.
Example: the middle click on a text containing "Print" in acme is
translated into "," command, which is sent to edbrowse. Edbrowse
will print whole buffer, which is piped back into acme. I have in the
mind making a screencast, since describing it in words can be hard.
The result is an interface that can be used almost without keyboard.
At the same time no modifications to edbrowse, neither to acme were
done.
Acme can be obtained along with plan9port [2]. After compiling
plan9port, just copy the script and launch it inside acme e.g.:
$ cp acmebrowse ~/plan9port/bin/
$ cd ~/plan9port/bin/
$ ./9 acme
# Execute acmebrowse in acme
[1] http://research.swtch.com/acme
[2] http://swtch.com/plan9port/
I'm including readme (need to update it) and script in a message
(enclosed into "--" marks), since I'm not sure if the mailing list is
accepting attachments.
ACMEBROWSE(1)
NAME
acmebrowse - mouse driven interface for edbrowse
DESCRIPTION
Some familiarity with acme(1) and edbrowse(1) is assumed.
First of all win(1) isn't used. Instead events emitted by acme
are parsed using acmeevent(1). This allows to assign a new context
to the mouse actions. The result is an interface that can be used
almost without a keyboard.
The basic usage is very simple. The text executed with a button two
is send to edbrowse as a literal command with an additional lookup
for custom commands in this script. In a similar fashion button
three is used for sending the selected text as a regular expression.
Example. After launching acmebrowse, an address can by typed in the
tag. Clicking "b http://the-brannons.com/edbrowse/" with a button
two will send text as a literal command, edbrowse will open this
page (not much to see, beside a status information). "Print" after
a button two click will be translated to "," command, which will
print a whole site. The text in a window can be clicked with a
button three to send a search query e.g. "{user's guide}" will be
translated to "/{user's guide}/". The first line with a phrase
will be printed. "Go" clicked with a button two will be send as
"g1" and "," commands - edbrowse will follow a first link in the
line and then print a whole page.
This is pretty much it. Commands with an exclamation mark need some
explanation. The way acme works, a button two click on "Quit!" will
select only "Quit". This quirk/feature is used to prevent an
accidental execution of a command. Whole phrase "Quit!" must be
drag-selected with a button two. In some cases it is used to
provide an alternative version of command e.g. "Go!" will follow
a link without printing.
FILES
~/.eb/bookmarks
EXAMPLES
Managing the bookmarks. "URLs" command will print the HTML version
of links on a specified line. "Bookmarks!" will append the content
of a buffer to a bookmark file. Those commands combined will add
a new entry in bookmarks.
SEE ALSO
acme(1), acmeevent(1), edbrowse(1), rc(1), acme(4)
BUGS
"Paste" and "Edit" aren't working properly (sometimes?).
--
#!/home/melville/p9/bin/rc
# ^ Adjust shebang accordingly.
. 9.rc
. $PLAN9/lib/acme.rc
follow = off
fn acmeinit {
# Create new window in acme, change name
newwindow
winname none
# Add commands to tag in acme
echo '' | winwrite tag
echo -n 'Back! Print Go! Go2! | URLs Bookmarks! Write! | Follow' \
'Javascript Quit! | i? i* i= | DDG | b http://' \
| winwrite tag
}
fn clearwin {
# Select all content of window in acme and erase it
echo -n , | winwrite addr
winctl 'dot=addr'
winwrite data
}
fn ebecho {
# Write command also to acme, so it's visible.
echo $* | winwrite body
echo $*
}
fn setwinname {
# Use '_ variable in eb for winname, if empty replace with "none".
echo '!echo "''_" | sed -e "s/\.browse$//" -e "s/^$/none/"' \
'-e "s/^/name /" | 9p write acme/' ^ $winid ^ '/ctl'
}
fn topofwin {
# Block till edbrowse is done.
sleep 60 &
echo '!kill' $apid
wait $apid >[2=]
# Jump to the top/beginning of text in acme
echo -n 0 | winwrite addr
winctl 'dot=addr'
winctl show
}
fn sanitizere {
# Turn special characters into dots, handle {m,n} pattern
echo $* | tr '^$[]+*?\/' '.' | sed 's/{([0-9]+(,[0-9]+)?)}/.\1./g'
}
fn parsecmd {
switch ($1) {
case Back # Go back one level
ebecho '^'
case Back! # Refresh page - can be useful for JS
ebecho rf
case Bookmarks # Open bookmark file and print
ebecho 'b ~/.eb/bookmarks'
ebecho ,
case Bookmarks! # Add bookmark, used together with URLs command.
ebecho 'w+ ~/.eb/bookmarks'
case DDG* # Searching in duckduckgo.com
ddg = `{echo $1}
ddg = $ddg(2-)
ddg = 'b http://ddg.gg/lite?q=' ^ $"ddg
ebecho $ddg
ebecho ,
case Follow # Toggle opening page after regexp
if (~$follow off) follow = on
if not follow = off
echo Following is $follow | winwrite body
case Go # Follow 1st link in the line and print
ebecho g1
ebecho ,
case Go2 # Follow 2nd link and...
ebecho g2
ebecho ,
case Go! # Follow without print - for binary files etc
ebecho g1
case Go2!
ebecho g2
case Javascript # Toggle off/on javascript
ebecho js
case Print # Print whole file
ebecho ,
case Quit! # With exclamation mark, must be drag-selected.
ebecho qt
windel sure
exit
case URLs # Show addresses behind links in selected line.
ebecho A
ebecho ,
case Write! # Save (binary) file to disk.
ebecho w/
case * # Send selection as plain command to edbrowse
ebecho $1
}
}
# man acmeevent(1)
fn event {
# $1 - c1 origin of event
# $2 - c2 type of action
# $3 - q0 beginning of selection
# $4 - q1 end of selection
# $5 - eq0 beginning of expanded selection
# $6 - eq1 end of expanded selection
# $7 - flag
# $8 - nr number of runes in $9
# $9 - text
# $10 - chorded argument
# $11 - origin of chorded argument
switch ($1$2) {
case E* # write to body or tag
case F* # generated by ourselves; ignore
case K* # type away we do not care
case Mi # mouse: text inserted in tag
case MI # mouse: text inserted in body
case Md # mouse: text deleted from tag
case MD # mouse: text deleted from body
# We don't care about those events
winwriteevent $*
case Mx MX # button 2 in tag or body
if (~ $9 Cut Edit* Look Paste Snarf)
winwriteevent $*
if not {
clearwin
parsecmd $9
setwinname
topofwin
}
case Ml ML # button 3 in tag or body
# Send selection as regexp to edbrowse
clearwin
regexp = `{sanitizere $9}
ebecho / ^ $"regexp ^ /
if (~ $follow on) {
ebecho g1
ebecho ,
setwinname
topofwin
}
}
}
# Initialize acme and start loop
acmeinit
wineventloop | edbrowse | winwrite body
--
Paul Onyschuk
next reply other threads:[~2014-07-30 12:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-30 12:40 Paul Onyschuk [this message]
2014-07-30 14:30 ` Chris Brannon
2014-07-30 15:32 ` Paul Onyschuk
2014-07-31 7:24 Karl Dahlke
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=20140730144046.9db3985ff43654767c4eee8c@gmail.com \
--to=ptmelville@gmail.com \
--cc=edbrowse-dev@lists.the-brannons.com \
/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).