[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Treat article with external script
From: |
Helmut Waitzmann Anti-Spam-Ticket . b . qc3c |
Subject: |
Re: Treat article with external script |
Date: |
Tue, 23 Jun 2020 10:24:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Breanndán Ó Nualláin <o@uva.nl>:
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.