Gnus development mailing list
 help / color / mirror / Atom feed
* writing a function that pipes the html mime part to an external script
@ 2017-01-20  6:59 John Magolske
  2017-01-20 10:41 ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: John Magolske @ 2017-01-20  6:59 UTC (permalink / raw)
  To: ding

I'm trying to write a function that would pipe the html mime part of
an article to a shell script for further processing.
I can do eval-expression and enter this at the Eval: prompt:

    (gnus-article-pipe-part 1)

Then this appears in the message body:

    =>. text/html]

and on the minibuffer line:

    Shell command on MIME part:

where I enter the absolute path to the shell script I want the html part
of this message piped to:

    Shell command on MIME part: ~/bin/pipe_to_tmp

and everything works as intended. But I'd like to do away with that last
step of having to manually enter the shell command, somehow placing that
"~/bin/pipe_to_tmp" directly into a function that could be mapped to a
key binding. I've been messing around with mm-pipe-part but haven't
found a way to do this. Any suggestions?

Regards,

John

-- 
John Magolske
http://b79.net/contact



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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20  6:59 writing a function that pipes the html mime part to an external script John Magolske
@ 2017-01-20 10:41 ` Andreas Schwab
  2017-01-20 15:56   ` John Magolske
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2017-01-20 10:41 UTC (permalink / raw)
  To: John Magolske; +Cc: ding

On Jan 19 2017, John Magolske <listmail@b79.net> wrote:

> and everything works as intended. But I'd like to do away with that last
> step of having to manually enter the shell command, somehow placing that
> "~/bin/pipe_to_tmp" directly into a function that could be mapped to a
> key binding. I've been messing around with mm-pipe-part but haven't
> found a way to do this. Any suggestions?

Write a function that calls mm-pipe-part directly.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 10:41 ` Andreas Schwab
@ 2017-01-20 15:56   ` John Magolske
  2017-01-20 17:51     ` Andreas Schwab
  2017-01-20 18:07     ` Eric Abrahamsen
  0 siblings, 2 replies; 9+ messages in thread
From: John Magolske @ 2017-01-20 15:56 UTC (permalink / raw)
  To: ding; +Cc: Andreas Schwab

Andreas Schwab <schwab@linux-m68k.org> writes:
> On Jan 19 2017, John Magolske <listmail@b79.net> wrote:
>
>> and everything works as intended. But I'd like to do away with that last
>> step of having to manually enter the shell command, somehow placing that
>> "~/bin/pipe_to_tmp" directly into a function that could be mapped to a
>> key binding. I've been messing around with mm-pipe-part but haven't
>> found a way to do this. Any suggestions?
>
> Write a function that calls mm-pipe-part directly.

This is where I'm stuck... I believe there should be something like

    (mm-pipe-part HANDLE "~/bin/pipe_to_tmp")

in the function, but I can't figure out exactly what should go in the
place of HANDLE here.

John

-- 
John Magolske
http://b79.net/contact



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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 15:56   ` John Magolske
@ 2017-01-20 17:51     ` Andreas Schwab
  2017-01-20 18:24       ` John Magolske
  2017-01-20 18:07     ` Eric Abrahamsen
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2017-01-20 17:51 UTC (permalink / raw)
  To: John Magolske; +Cc: ding

On Jan 20 2017, John Magolske <listmail@b79.net> wrote:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>> On Jan 19 2017, John Magolske <listmail@b79.net> wrote:
>>
>>> and everything works as intended. But I'd like to do away with that last
>>> step of having to manually enter the shell command, somehow placing that
>>> "~/bin/pipe_to_tmp" directly into a function that could be mapped to a
>>> key binding. I've been messing around with mm-pipe-part but haven't
>>> found a way to do this. Any suggestions?
>>
>> Write a function that calls mm-pipe-part directly.
>
> This is where I'm stuck... I believe there should be something like
>
>     (mm-pipe-part HANDLE "~/bin/pipe_to_tmp")
>
> in the function, but I can't figure out exactly what should go in the
> place of HANDLE here.

The same that gnus-article-part-wrapper would pass.  Or pass
gnus-article-part-wrapper a function that calls mm-pipe-part like above.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 15:56   ` John Magolske
  2017-01-20 17:51     ` Andreas Schwab
@ 2017-01-20 18:07     ` Eric Abrahamsen
  2017-01-20 20:04       ` John Magolske
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Abrahamsen @ 2017-01-20 18:07 UTC (permalink / raw)
  To: ding

John Magolske <listmail@b79.net> writes:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>> On Jan 19 2017, John Magolske <listmail@b79.net> wrote:
>>
>>> and everything works as intended. But I'd like to do away with that last
>>> step of having to manually enter the shell command, somehow placing that
>>> "~/bin/pipe_to_tmp" directly into a function that could be mapped to a
>>> key binding. I've been messing around with mm-pipe-part but haven't
>>> found a way to do this. Any suggestions?
>>
>> Write a function that calls mm-pipe-part directly.
>
> This is where I'm stuck... I believe there should be something like
>
>     (mm-pipe-part HANDLE "~/bin/pipe_to_tmp")
>
> in the function, but I can't figure out exactly what should go in the
> place of HANDLE here.
>
> John

You can get the various article part handles with
`gnus-article-mime-handles', is that what you were looking for?

Eric




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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 17:51     ` Andreas Schwab
@ 2017-01-20 18:24       ` John Magolske
  2017-02-02  8:33         ` John Magolske
  0 siblings, 1 reply; 9+ messages in thread
From: John Magolske @ 2017-01-20 18:24 UTC (permalink / raw)
  To: ding; +Cc: Andreas Schwab

Andreas Schwab <schwab@linux-m68k.org> writes:
> On Jan 20 2017, John Magolske <listmail@b79.net> wrote:
>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>> On Jan 19 2017, John Magolske <listmail@b79.net> wrote:
>>>
>>>> and everything works as intended. But I'd like to do away with that last
>>>> step of having to manually enter the shell command, somehow placing that
>>>> "~/bin/pipe_to_tmp" directly into a function that could be mapped to a
>>>> key binding. I've been messing around with mm-pipe-part but haven't
>>>> found a way to do this. Any suggestions?
>>>
>>> Write a function that calls mm-pipe-part directly.
>>
>> This is where I'm stuck... I believe there should be something like
>>
>>     (mm-pipe-part HANDLE "~/bin/pipe_to_tmp")
>>
>> in the function, but I can't figure out exactly what should go in the
>> place of HANDLE here.
>
> The same that gnus-article-part-wrapper would pass.

So it looks like gnus-article-part-wrapper passes the "N-th MIME handle"
and only that argument:

    (gnus-article-part-wrapper N FUNCTION &optional NO-HANDLE INTERACTIVE)

    Call FUNCTION on MIME part N.
    Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only
    argument. If INTERACTIVE, call FUNCTION interactively.

so I can do something like

    (gnus-article-part-wrapper 1 'mm-pipe-part)

which still requires manual input to the minibuffer of the command I
want the mime part piped to. This obviously doesn't work:

    (mm-pipe-part 1 "~/bin/pipe_to_tmp")

I guess I'm still foggy on exactly how to call HANDLE and how HANDLE is
named.

> Or pass gnus-article-part-wrapper a function that calls mm-pipe-part
> like above.

That's what I'll probably try next, but was hoping for a way to call
HANDLE in (mm-pipe-part HANDLE "~/bin/pipe_to_tmp") to make for a more
simple function. Also, I'd like to get a clearer idea about what HANDLE
is here, how it's named, called, etc.

John

-- 
John Magolske
http://b79.net/contact



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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 18:07     ` Eric Abrahamsen
@ 2017-01-20 20:04       ` John Magolske
  2017-01-20 20:34         ` Eric Abrahamsen
  0 siblings, 1 reply; 9+ messages in thread
From: John Magolske @ 2017-01-20 20:04 UTC (permalink / raw)
  To: ding; +Cc: Eric Abrahamsen

Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> John Magolske <listmail@b79.net> writes:
>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>
>>> Write a function that calls mm-pipe-part directly.
>>
>> This is where I'm stuck... I believe there should be something like
>>
>>     (mm-pipe-part HANDLE "~/bin/pipe_to_tmp")
>>
>> in the function, but I can't figure out exactly what should go in the
>> place of HANDLE here.
>
> You can get the various article part handles with
> `gnus-article-mime-handles', is that what you were looking for?

I just tried that in an article buffer, got this:

    ((1 #<buffer  *mm*> ("text/html" (charset . "UTF-8"))
    quoted-printable nil nil nil nil nil))

and am wondering which part of that is HANDLE ...

I tried:

    Eval: (mm-pipe-part "text/html" "~/bin/pipe_to_tmp")
    (wrong-type-argument listp "text/html") in eval

    Eval: (mm-pipe-part ("text/html" (charset . "UTF-8")) "~/bin/pipe_to_tmp")
    (invalid-function "text/html") in mm-pipe-part

John

-- 
John Magolske
http://b79.net/contact



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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 20:04       ` John Magolske
@ 2017-01-20 20:34         ` Eric Abrahamsen
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Abrahamsen @ 2017-01-20 20:34 UTC (permalink / raw)
  To: ding

John Magolske <listmail@b79.net> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>> John Magolske <listmail@b79.net> writes:
>>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>>
>>>> Write a function that calls mm-pipe-part directly.
>>>
>>> This is where I'm stuck... I believe there should be something like
>>>
>>>     (mm-pipe-part HANDLE "~/bin/pipe_to_tmp")
>>>
>>> in the function, but I can't figure out exactly what should go in the
>>> place of HANDLE here.
>>
>> You can get the various article part handles with
>> `gnus-article-mime-handles', is that what you were looking for?
>
> I just tried that in an article buffer, got this:
>
>     ((1 #<buffer  *mm*> ("text/html" (charset . "UTF-8"))
>     quoted-printable nil nil nil nil nil))
>
> and am wondering which part of that is HANDLE ...
>
> I tried:
>
>     Eval: (mm-pipe-part "text/html" "~/bin/pipe_to_tmp")
>     (wrong-type-argument listp "text/html") in eval
>
>     Eval: (mm-pipe-part ("text/html" (charset . "UTF-8")) "~/bin/pipe_to_tmp")
>     (invalid-function "text/html") in mm-pipe-part

I believe the car of the result (ie the "1") is the handle, though I'm a
bit at sea with this code. I think what you'll need to do is loop
through the handles and see which one is "text/html", and then pass the
handle (the number) to `mm-pipe-part'.

Like I said, though, I really don't have much experience with this code,
so hopefully someone else will confirm/deny.

Eric




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

* Re: writing a function that pipes the html mime part to an external script
  2017-01-20 18:24       ` John Magolske
@ 2017-02-02  8:33         ` John Magolske
  0 siblings, 0 replies; 9+ messages in thread
From: John Magolske @ 2017-02-02  8:33 UTC (permalink / raw)
  To: ding; +Cc: Andreas Schwab

> Andreas Schwab <schwab@linux-m68k.org> writes:
>>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>>> On Jan 19 2017, John Magolske <listmail@b79.net> wrote:
>>>>
>>>>> and everything works as intended. But I'd like to do away with that last
>>>>> step of having to manually enter the shell command, somehow placing that
>>>>> "~/bin/pipe_to_tmp" directly into a function that could be mapped to a
>>>>> key binding. I've been messing around with mm-pipe-part but haven't
>>>>> found a way to do this. Any suggestions?
>>>>
>>>> Write a function that calls mm-pipe-part directly.
>>>
>
>> Or pass gnus-article-part-wrapper a function that calls mm-pipe-part
>> like above.

This ended up working out rather well:

    (defun jfm-pipe-part-view-post (handle)
    (mm-pipe-part handle "~/bin/rss_post_view.sh"))

    (defun jfm-pipe-part-1-view-post ()
    (interactive)
    (gnus-article-part-wrapper 1 'jfm-pipe-part-view-post)
    (gnus-switch-to-summary-buffer)
    (gnus-summary-goto-article gnus-current-article nil t))

    (define-key gnus-summary-mode-map (kbd "C-@") 'jfm-pipe-part-1-view-post)

and my rss_post_view.sh is as follows (uses ELinks running in tmux, note
that document.browse.margin_width is used with a custom-patched ELinks):

    #!/bin/bash
    rm -rf /tmp/pipe-post1
    mkfifo /tmp/pipe-post1
    cat | grep "View post" | sed -e 's/^.*\(http.*\)".*/\1/g' >| /tmp/pipe-post1 &
    url=\"`cat /tmp/pipe-post1&`\"
    #echo $url
    #exit 0
    if # check if there's an elinks running on session-ring 21
        elinks -session-ring 21 -remote 'ping()' 2>&1 | grep 'No running ELinks' >/dev/null
    then  # if not, then start one on tmux window 98 and open the URL called above
        tmux new-window -n rss -t 98 "elinks -force-html -touch-files 1 -session-ring 21 -eval 'set document.browse.margin_width = 18' -eval 'set document.browse.use_margin = 1' $url"
        sleep 3
    else  # otherwise open the URL in the existing session-ring 21 elinks...
        elinks -force-html -touch-files 1 -session-ring 21 -eval 'set document.browse.margin_width = 18' -eval 'set document.browse.use_margin = 1' -remote openURL\($url,new-tab\)
    fi

That grabs the url to articles ("View post") in rss feeds and opens them
in successive tabs in Elinks, allowing me to quickly go through a series
of rss items, opening the main articles in a backround browser one after
another without having Emacs "freeze" or wait while webpages load.

To gather rss feeds I use https://github.com/sloonz/ua , which fetches
rss feeds and loads them into a maidir. After trying a variety of the
the "rss2maildir" packages out there, I've found ua to be quite nice.

Regards,

John

-- 
John Magolske
http://b79.net/contact



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

end of thread, other threads:[~2017-02-02  8:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20  6:59 writing a function that pipes the html mime part to an external script John Magolske
2017-01-20 10:41 ` Andreas Schwab
2017-01-20 15:56   ` John Magolske
2017-01-20 17:51     ` Andreas Schwab
2017-01-20 18:24       ` John Magolske
2017-02-02  8:33         ` John Magolske
2017-01-20 18:07     ` Eric Abrahamsen
2017-01-20 20:04       ` John Magolske
2017-01-20 20:34         ` Eric Abrahamsen

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