[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Lynx-dev] Invoking a lynx script

From: Bela Lubkin
Subject: Re: [Lynx-dev] Invoking a lynx script
Date: Mon, 10 Oct 2011 02:02:47 -0700

Graham Lawrence wrote directly to me:

> Having 2 macros, one lynx and one vim, would be fine, except the only way
> I've found to invoke a lynx macro is by a separate invocation of lynx, as
> xterm -g 120x54 -e lynx -cmd_log=/path/to/script "url"
> so its just like "lynx -dump", you have to know the url you want to operate
> on.
> I can do a dump of the current page most economically by
> p<ENTER><CTRL-U>~/d<ENTER><ALT-TAB>:r ~/d<ENTER> 15 keystrokes vs.
> <CTRL-A><CTRL-C><ALT-TAB><CTRL-V> 4 keystrokes in a gui browser and editor.
> Is there a way to invoke a lynx script without requiring a separate
> invocation of lynx?

I replied asking him to repost to the list, but he didn't, nor replied
to me, so I think my reply didn't get through.  As there is nothing
private in the message, I am following up here instead.

First, I dispute the keystroke counts: I see 20 for the dump-and-read
method vs. 8 for cut-and-paste.  Ctrl-foo and alt-bar are 2 keys each
for the operator, regardless of what a program's input stream might

Second, both parts of the dump-and-read method can be shortened up.

In lynx.cfg, add a PRINTER or DOWNLOADER which doesn't take a filename
(only one "%s" in its definition) and which writes its output to an
agreed-upon location.  I suggest something like "$HOME/.lynx-copy-out".
Now it's "p1<ENTER>" (3 keys) to copy out.  If my reading of the PRINTER
section of lynx.cfg is correct, the script for this could be as simple
as just 'cp $1 $HOME/.lynx-copy-out'.  You could reduce this to two keys
("p<ENTER<") if you can figure out how to make your PRINTER definition
the first in the 'p' menu.

In vim, make a macro which performs ":r $HOME/.lynx-copy-out" (whatever
shared filename you've chosen).

So the full sequence is: "p1<ENTER><ALT-TAB><CTRL-???>": 5 keys by your
count or 7 by mine.  Assuming you can dedicate a ctrl-??? or alt-???
"2-key" sequence to the operation.

Or you can use the program `xsel` (available in package "xsel" on Ubuntu
and Debian).  Your PRINTER script can be 'xsel -p -i < $1'.  Your full
key sequence is: "p1<ENTER><ALT-TAB><SHIFT-INS>", and you don't need to
create a vim macro.  This is effectively the same as the agreed-upon
location method, but the agreed-upon location is the X "primary
selection" buffer.

Finally, look for "EXTERNAL:" in lynx.cfg.  I added the following lines
to mine:

   EXTERNAL:ftp: lynx -dump -nolist "%s" | xsel -p -i:::XWINDOWS
   EXTERNAL:http:lynx -dump -nolist "%s" | xsel -p -i:::XWINDOWS
   EXTERNAL:file:lynx -dump -nolist "%s" | xsel -p -i:::XWINDOWS

Now if I hit ',' in Lynx, it brings up a menu where the first choice is
"lynx -dump ..."; I hit <ENTER> and it copies the contents of the
current page into the X primary selection.  '.' does the same with the
current link that Lynx's cursor is on.

Then I commented out the previously existing "EXTERNAL:" lines; now '.'
and ',' did their work *without* putting up a menu.  Note: I originally
had an "EXTERNAL:https:" line as well, but that caused it to bring up
two identical choices in a menu on https URLs.  It seems that https URLs
get offered both http & https external choices.

Nota bene: unlike a PRINTER definition, EXTERNALs receive a URL rather
than a formatted output file.  In my examples I'm invoking a Lynx
subprocess to format that URL.  The resulting output is similar to what
you might see if you hit ^R (reload) inside Lynx, then 'p'rinted the
result.  Pages which come up differently each time (e.g. rotating ads)
will be different; pages that check the HTTP referrer header may be
different; etc.

You might use that to advantage, e.g. adding "-width 10000" so that
paragraphs are inserted without line breaks (then vim's :set textwidth=
wrapping will work).  Slight bug there: Lynx has a line length limit of
1014 chars (from testing); paragraphs longer than that will have
arbitrary line breaks inserted.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]