Discussion:
Treat article with external script
(too old to reply)
Breanndán Ó Nualláin
2020-06-20 15:43:43 UTC
Permalink
I'd like to be able to do article washing by running the article through
an external python script. Is there an easy way to do this?
Boris Dorestand
2020-06-20 23:48:02 UTC
Permalink
Post by Breanndán Ó Nualláin
I'd like to be able to do article washing by running the article through
an external python script. Is there an easy way to do this?
I just looked at the menu when in the summary buffer and there is

Article -> Washing -> Unix pipe...

But I don't know which command that is. It is not currently mapped to a
keyboard shortcut on my GNU Emacs 24.3.1. There's the command

gnus-summary-pipe-output

But I'm not sure which is used when I used the menu. In fact, how would
I discover that? That's my question. Thanks!
Helmut Waitzmann Anti-Spam-Ticket.b.qc3c
2020-06-23 08:24:10 UTC
Permalink
Post by Breanndán Ó Nualláin
I'd like to be able to do article washing by running the article
through an external python script. Is there an easy way to do
this?
You could define a function: 


(defun my-gnus-article-wash nil
"Invoke the program '(car my-gnus-article-wash)' on the current buffer.
If the variable 'my-gnus-article-wash' is a non-nil list of a
program name and positional parameters, run it as a filter on
the current buffer's contents."
(interactive)
(if my-gnus-article-wash
(apply
(function call-process-region)
(point-min)
(point-max)
(car my-gnus-article-wash)
t
t
nil
(cdr my-gnus-article-wash))))


… and a variable: 


(defvar my-gnus-article-wash nil
"*invocation list to be executed on contents of the article buffer.
If non-nil, is a list containing an executable file name and argv1
... argvn invocation arguments to execute on the contents of
the article buffer and replacing it. One example would be
'(\"iconv\" \"-t\" \"ASCII//TRANSLIT\")
to transliterate every non-ASCII character to its corresponding
ASCII approximate character.")


You might put the function and variable definitions in a file, for
example "~/my_emacs_libs/gnus_wash_articles.el".  Byte compile
that file.  Have it loaded from the emacs startup file: 

(load "~/my_emacs_libs/gnus_wash_articles")


You might put the following assignments into the gnus startup
file: 


Assign a value to the variable: 


(setq-default
my-gnus-article-wash
'("the_external_python_script" "and" "its" "parameters"))


Put the function into the gnus-part-display-hook: 


(add-hook
'gnus-part-display-hook
(function my-gnus-article-wash))

That will invoke the python script with the given parameters on
the article content. 

Loading...