🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
8 messages
8 total messages Started by Doug713705 Tue, 12 Jan 2016 23:34
[slrn] Automattic subject modification
#259951
Author: Doug713705
Date: Tue, 12 Jan 2016 23:34
22 lines
1962 bytes
Hello all,

I'm looking for a way to make slrn modify the subject (or virtualy any 
header).

Typically, when a post is selected and displayed I'd like to press a 
key that allow me to edit an answer to that post but with a modified 
subject like "[tag] actual post subject".

I'm totally noob with slang but I looked at macros provided with slrn 
and others from the slrn web site but none of them modify the subject 
header and I found no suitable hook or intrinsic functions in the 
slrnfuns.txt.

Is it possible ? If yes how ?

Thank you for your help.
-- 
Je ne connaîtrai rien de tes habitudes
Il se peut même que tu sois décédée
Mais j'demanderai ta main pour la couper
                    -- H.F. Thiéfaine, L'ascenceur de 22H43
Re: [slrn] Automattic subject modification
#259955
Author: J.B. Nicholson
Date: Wed, 13 Jan 2016 00:19
63 lines
4083 bytes
Doug713705 <doug.letough@free.fr> wrote:
> Typically, when a post is selected and displayed I'd like to press a 
> key that allow me to edit an answer to that post but with a modified 
> subject like "[tag] actual post subject".

Sounds like you want to send a reply or post a followup with a subject
header based on the post's subject header.

You could do this with a macro that uses a hook (a function which is
always run before or after some event):

- post_filter_hook() -- called when you use the "F"ilter option at the
  "Post the message?" prompt. If you haven't seen this option when
  posting, it's probably because you don't have any post_filter_hook
  functions defined.

- post_hook() and reply_hook() -- called when posting/replying-to an
  article. If you want to run *every* post you make through some
  function, these hooks give you what you need to do that job.  But
  you'll have no interactive means of deciding to avoid running your
  post through the filter 'just this once' (the bit about initiating
  your subject change via pressing a key like you mentioned).

> I'm totally noob with slang but I looked at macros provided with slrn 
> and others from the slrn web site but none of them modify the subject 
> header and I found no suitable hook or intrinsic functions in the 
> slrnfuns.txt.

S-Lang isn't hard to learn or use. If you have any programming
experience you'll catch on to it quickly. To get used to S-Lang you
might start with something simple, like making slrn show a message
each time you resize the screen (which means using the
resize_screen_hook()):

#v+
% Define a simple function to print a message. This function takes
% no arguments (hence the "()" empty argument list).
define print_my_message () { message ("foo!"); }

% Make slrn run the simple function each time you resize the screen.
ifnot (register_hook ("resize_screen_hook", "print_my_message"))
{
   message ("Cannot register print_my_message() with resize_screen_hook!");
}
#v-

Check out http://slrn.sourceforge.net/docs/slrnfuns-7.html for docs on
slrn's intrinsic functions like register_hook().

The "#v+" and "#v-" are, if I recall correctly, slrn's markup for
showing some lines of a post verbatim -- no modification for
collapsing quoted lines and other effects. Typically one uses these
marks in cases like these where one wants to mix code and prose.

Getting back to your request: There's nothing special about the
Subject: header, it's just like any other header. That means you could
parse out the header from looking at the post file line by line from
the start of the post (stopping when you come across "\n\n" as that's
the header-body separator) and then modify the subject in your editor
(in which case you'd look to writing some code for your editor, not
writing code for slrn), or you could look at slrn macros that do
something to posts/replies before they're sent out and learn from that
code.
Re: [slrn] Automattic subject modification
#259952
Author: Doug713705
Date: Wed, 13 Jan 2016 09:24
72 lines
4760 bytes
Hello J.B,

Le 13-01-2016, J.B. Nicholson nous expliquait dans 
news.software.readers
(<slrnn9b613.39r.jbn@forestfield.org>) :

> - post_hook() and reply_hook() -- called when posting/replying-to an
>   article. If you want to run *every* post you make through some
>   function, these hooks give you what you need to do that job.  But
>   you'll have no interactive means of deciding to avoid running your
>   post through the filter 'just this once' (the bit about initiating
>   your subject change via pressing a key like you mentioned).

That exactly the point. I don't want the subject be tagged on every post 
but only when needed and that's why at first I was looking for another 
hook than the reply_hook().

>> I'm totally noob with slang but I looked at macros provided with slrn 
>> and others from the slrn web site but none of them modify the subject 
>> header and I found no suitable hook or intrinsic functions in the 
>> slrnfuns.txt.
>
> S-Lang isn't hard to learn or use. If you have any programming
> experience you'll catch on to it quickly. To get used to S-Lang you
> might start with something simple, like making slrn show a message
> each time you resize the screen (which means using the
> resize_screen_hook()):

[SNIP sample code]

I already succeeded in displaying the subject or any header's content by 
getting it with the extract_displayed_article_header() function and 
displaying it with the message() function but I found no way to replace 
the subject header of the reply.

My guess was, when a dedicated key is pressed (not the 'f' key or the 
'p' key), to get the subject header content with 
extract_displayed_article_header() (this part is already working like a 
charm), modify it and then call the reply_hook() so the editor receive 
the article as ususal but with a modified subject header.

At this point I can get the subject content, I can modify it but I don't 
know where to store it (with a function that could have been called 
set_selected_article_header()) so the editor get the modified version.

I also tried to pipe the article to an external program with the 
pipe_article() function. No succes at the moment but it was late and 
I was tired.

> Getting back to your request: There's nothing special about the
> Subject: header, it's just like any other header. That means you could
> parse out the header from looking at the post file line by line from
> the start of the post (stopping when you come across "\n\n" as that's
> the header-body separator) and then modify the subject in your editor
> (in which case you'd look to writing some code for your editor, not
> writing code for slrn), or you could look at slrn macros that do
> something to posts/replies before they're sent out and learn from that
> code.

I looked over all macros but did not found what I was looking for, that 
why I posted here. I may look for something impossible or have 
overlooked something. The closest macros to what I'm looking for is the 
indentity.sl but it only change some variable (from, reply-to, ...) 
that are used after that. This macro doe not modify the selected 
article before passing it to the editor which is what I' trying 
to do (right or wrong).

-- 
Je ne connaîtrai rien de tes habitudes
Il se peut même que tu sois décédée
Mais j'demanderai ta main pour la couper
                    -- H.F. Thiéfaine, L'ascenceur de 22H43
Re: [slrn] Automattic subject modification
#259963
Author: J.B. Nicholson
Date: Thu, 14 Jan 2016 03:40
78 lines
4125 bytes
Doug713705 <doug.letough@free.fr> wrote:
> I already succeeded in displaying the subject or any header's
> content by getting it with the extract_displayed_article_header()
> function and displaying it with the message() function but I found
> no way to replace the subject header of the reply.

Then you'll want to spend some time experimenting with slsh (an S-Lang
shell) and reading http://www.jedsoft.org/slang/doc/html/slangfun.html
which is the S-Lang intrinsic function documentation.

There's a whole section called "Functions that Operate on Strings" in
http://www.jedsoft.org/slang/doc/html/slangfun-5.html which is
helpful.

Chop up strings with strchop() & strchopr(), and get to portions of
strings using array syntax:

#v+
slsh> a="hello world";
slsh> char(a[0]);
h
slsh> char(a[1]);
e
#v-

Try using string_match() for matching a string against a regular
expression.

Try using "+" for string concatenation, or strcat().

Consider reading and posting to the slang-users mailing list (visit
http://jedsoft.org/slang/mailinglists.html for information) or
visiting alt.lang.s-lang if your server carries it, since some of what
you're asking are really S-Lang questions.

> At this point I can get the subject content, I can modify it but I
> don't know where to store it (with a function that could have been
> called set_selected_article_header()) so the editor get the modified
> version.

If you capture the entire article you want to modify in a variable
with article_as_string(), you could use that variable's contents later
to undo your changes (see what I say about toggling the subject
tagging later).

Then identify where in the article string the subject header appears
(the array indices which cover the entire Subject: header), you can
build a new string which contains all of the text up to the subject
header, append a new subject header of your choice, and then append
all of the text after the newline. Now you'd have an article with a
modified subject header.

You could experiment with this in slsh merely by mocking up an article
in a string. This approach would let you focus on doing this one small
task, then bring that knowledge into your slrn macro when you're
ready:

#v+
slsh> article="From: user@somewhere.invalid\nSubject: some subject here\n\nBody text here\n";
#v-

or

#v+
slsh> article="Subject: some subject here\nFrom: user@somewhere.invalid\n\nBody text here\n";
#v-

for instance.

Then when you've got that header modified, you could replace the
entire article with your modified version (via replace_article()) and
let the user run slrn's followup or reply intrinsics in the ordinary
way. This would let you leverage the code that's already in slrn and
not require using any hooks.

You could also bind a key to a function that would restore the article
to it's original state if you want to toggle on/off the subject
tagging.
Re: [slrn] Automattic subject modification
#259965
Author: Shehu Dikko
Date: Thu, 14 Jan 2016 09:17
24 lines
1618 bytes
* Doug713705 <doug.letough@free.fr> [2016-01-13]:
> [...] I also tried to pipe the article to an external program with
> the pipe_article() function. No succes at the moment but it was late
> and I was tired....

How so? Here's an example using reformail which should be able to do
what you want if you look into it:

#v+
 define pipe_to_mbox () 
 { 
    pipe_article ("/usr/bin/reformail -s /usr/bin/maildrop"); 
 } 
 definekey ("pipe_to_mbox", "w", "article");
#v-

That sends the selected article to an mbox based on rules defined in
the maildrop config. You can substitute maildrop for your external
program if the builtin reformail options for rewriting headers are not
quite what you want.

regards,

s h e h u
Re: [slrn] Automattic subject modification
#259967
Author: Doug713705
Date: Thu, 14 Jan 2016 13:07
48 lines
3587 bytes
Le 14-01-2016, J.B. Nicholson nous expliquait dans 
news.software.readers
(<slrnn9e654.h97.jbn@forestfield.org>) :

> Then when you've got that header modified, you could replace the
> entire article with your modified version (via replace_article()) and
> let the user run slrn's followup or reply intrinsics in the ordinary
> way. This would let you leverage the code that's already in slrn and
> not require using any hooks.

That what I thought at first and I already succeed in using 
replace_article(). 

It does the job on screen but it does not modify the article and when I 
followup as usual such a replaced article, the subject is still based 
on the original one as "Re: <original subject>" althought some other 
parts of the article are replaced. The artcile body  part and some of 
the headers are replaced but *not* the subject header or the References 
header that are generated by slrn prior to passing it to the editor.

As far as I can tell Slrn seems to process the original article before 
passing it to the editor rather than processing the replacement one 
that is effectively displayed. So the Subject and References headers 
are generated from the original article independently of the 
modifications.

I think what I need is something like a pre_edit_hook() ;-)

> You could also bind a key to a function that would restore the article
> to it's original state if you want to toggle on/off the subject
> tagging.

At he moment I managed to use the followup_custom_headers variable in 
which I can store my Subject header and some other modified headers. It 
does the job well but I still have to remove the auto-generated headers 
headers (like Subject and References) by hand.

It's a bit annoying but always better than nothing ;-)

Thank for your help and for the S-lang guide pointers. 
I always thought S-lang was a mystical and difficult to apprehend 
language. It seems not ;-)

-- 
Je ne connaîtrai rien de tes habitudes
Il se peut même que tu sois décédée
Mais j'demanderai ta main pour la couper
                    -- H.F. Thiéfaine, L'ascenceur de 22H43
Re: [slrn] Automattic subject modification
#259973
Author: J.B. Nicholson
Date: Fri, 15 Jan 2016 04:23
27 lines
2684 bytes
Doug713705 <doug.letough@free.fr> wrote:
> That what I thought at first and I already succeed in using 
> replace_article(). 

It's good that you're experimenting. Since you've posted no code it's
hard to know what you tried.

> It does the job on screen but it does not modify the article and when I 
> followup as usual such a replaced article, the subject is still based 
> on the original one as "Re: <original subject>" althought some other 
> parts of the article are replaced. The artcile body  part and some of 
> the headers are replaced but *not* the subject header or the References 
> header that are generated by slrn prior to passing it to the editor.

Consider trying a combination of slrn macro plus editor macro: a slrn
macro that sets the tempfile to a new known place, sets the slrn
editor setting to call an editor that will run a macro on load, then
calls the intrinsic to send a reply or post a followup. Then also make
an editor macro that replaces the subject as needed. After
posting/replying, the slrn macro can restore the previous values of
the modified slrn settings to what they were before the slrn macro
began. Thus this macro shouldn't interfere with normal
posting/replying.

I don't quite see the point in overriding the references header as
that risks breaking threading. Regardless of what you change the
subject to, if you're posting a followup it should thread properly.
Re: [slrn] Automattic subject modification
#259974
Author: Doug713705
Date: Fri, 15 Jan 2016 09:22
69 lines
4716 bytes
Le 15-01-2016, J.B. Nicholson nous expliquait dans 
news.software.readers (<slrnn9gt1i.65f.jbn@forestfield.org>) :

>> That what I thought at first and I already succeed in using 
>> replace_article(). 
>
> It's good that you're experimenting. Since you've posted no code it's
> hard to know what you tried.

I have overwritten the code that had been written with replace_article() 
so I can't show you but this was as simple as you described before:
- Get the article with article_as_string()
- Get the subject with extract_displayed_article_header()
- Replace the subject within that string using strreplace()
- Replace the article by the modified string with replace_article() 

Very simple code indeed.

I tried many version of that code (using strchop to get the article line 
by line, etc).

All worked and subject was replaced in slrn article view but when I
attempt to followup such a replaced article, the editor gets a prepared 
reply based on the the original article (subject and references headers 
are still based on the original headers).

>> It does the job on screen but it does not modify the article and when I 
>> followup as usual such a replaced article, the subject is still based 
>> on the original one as "Re: <original subject>" althought some other 
>> parts of the article are replaced. The artcile body  part and some of 
>> the headers are replaced but *not* the subject header or the References 
>> header that are generated by slrn prior to passing it to the editor.
>
> Consider trying a combination of slrn macro plus editor macro: a slrn
> macro that sets the tempfile to a new known place, sets the slrn
> editor setting to call an editor that will run a macro on load, then
> calls the intrinsic to send a reply or post a followup. Then also make
> an editor macro that replaces the subject as needed. After
> posting/replying, the slrn macro can restore the previous values of
> the modified slrn settings to what they were before the slrn macro
> began. Thus this macro shouldn't interfere with normal
> posting/replying.

The point is that I use nano as my editor which is a very basic editor 
that do not have any macro feature. It may be time for me to switch to a 
better but more complex editor like vi or so.

Note that also tried to 'sed' the article in tmp file and get that tmp 
file to the editor with no success (I didn't try too hard though).

For now my script works good even if it does not remove the original 
subject header but I can manage this situation by a single keystroke.

Comparing the effort to get used to a new editor, a single keystroke 
once or two a day is far easyer. I may come to it one day but not now 
;-)

> I don't quite see the point in overriding the references header as
> that risks breaking threading. Regardless of what you change the
> subject to, if you're posting a followup it should thread properly.

I only tried to override the references for testing purpose as I noticed 
that header was based on the original article ;-)

Thank you again for your help.
-- 
Mais dans les souterrains, les rêveurs sont perdants.
Serions-nous condamnés à nous sentir trop lourds ?
      H.F. Thiéfaine- 713705 Cherche Futur
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads