Thread View: news.software.readers
4 messages
4 total messages
Started by Randall Hopper
Sun, 13 Apr 1997 00:00
slrn wish: Regex filter for auto-subscribe
Author: Randall Hopper
Date: Sun, 13 Apr 1997 00:00
Date: Sun, 13 Apr 1997 00:00
13 lines
962 bytes
962 bytes
I like having autoscribe on. However, I can easily define a regex of
some groups I have no desire to subscribe to. I currently manually
unsubscribe to these, but it'd be nice if I could give slrn a regex for
newsgroup names I don't want to auto-subscribe to.
BTW, Tx to John and the SLRN devel team -- great news reader!
Randall Hopper
rhh@ct.picker.com
Re: slrn wish: Regex filter for auto-subscribe
Author: J.B. Nicholson-Owens
Date: Tue, 15 Apr 1997 00:00
Date: Tue, 15 Apr 1997 00:00
276 lines
9942 bytes
9942 bytes
rhh@ct.picker.com (Randall Hopper) wrote:
> However, I can easily define a regex of some groups I have no desire
> to subscribe to.
I've written something that you might find handy. As the docs say, it works
with your unsubscribe_new_groups variable to do a reasonable thing. Stick
it in a file and load it either with "interpret" from your slrn.rc or
autoload it from some S-Lang code somewhere.
The trick is in the AUTO_SUB_UNSUB_REGEX variable. I'll leave the details
below. The easy way to get it working:
variable AUTO_SUB_UNSUB_REGEX = "^alt\.";
auto_sub_unsub ();
should go in some S-Lang file where it'll run on group mode startup. Slrn's
unsubscribe_new_groups setting and AUTO_SUB_UNSUB_REGEX are intended to be
complimentary -- if you automatically subscribe to all new groups,
AUTO_SUB_UNSUB_REGEX describes the groups you want to automatically
unsubscribe. It should be okay if you run auto_sub_unsub() more than once,
since it only works on new newsgroups (and since slrn no longer downloads
new group info when you refresh the newsgroup list). However, it shouldn't
be necessary to run auto_sub_unsub more than once.
Please forgive the weird code formatting, I had to do something to get it
under 80 columns for posting (this is the only time I wish I hadn't
suggested JED enforce the >80 column rule). As unusual as the formatting
is, it should run okay.
I hope this fills your need.
% -*- mode: slang; mode: fold -*-
% author: J.B. Nicholson-Owens
% version: 1.2
% Full documentation %{{{
%
% Automatically subscribe/unsubscribe groups that match a regexp. This
% macro does not affect the newness of the group (groups still remain
% marked as "new" after this function is complete). This macro only works
% on new newsgroups.
%
% Requires:
% AUTO_SUB_UNSUB_REGEX: comma separated regex(es) describing groups to
% toggle subscribe or unsubscribe status.
%
% This macro works with your unsubscribe_new_groups setting (default is 0,
% new groups are unsubscribed, according to slrn.rc documentation).
%
% Examples:
%
% AUTO_SUB_UNSUB_REGEX = "^clari\.weather\.,^news\.software\.,pokey-lokey";
% automatically toggles subscription status of:
% clari.weather.*
% news.software.*
% any newsgroup with "pokey-lokey" in its name
%
% To INSTALL, call auto_sub_unsub() from group_mode_startup_hook().
% sub_unsub_edit_regex(), sub_unsub_add_current_group() and
% sub_unsub_del_current_group() are optional and can be bound to keys.
%
% find_first_sub_group() is designed to be called from
% group_mode_startup_hook() and is completely optional as well. It leaves
% the pointer at the first subscribed group.
%}}}
% Change log %{{{
% v1.2: added UI for editing AUTO_SUB_UNSUB_REGEX from inside slrn:
% add_current_group ()
% del_current_group ()
% edit_sub_unsub_regex ()
%
% added sub_unsub_find_first_sub_group () to leave the pointer at the
% first subscribed group (small, perhaps silly but handy if you
% unsubscribe from most new groups).
%
% v1.1: made function use one variable (AUTO_SUB_UNSUB_REGEX) instead of
% two by using unsubscribe_new_groups setting from slrnrc file.
% Now, regex variable describes groups to toggle. Made regex compare
% case insensitive (newsgroups names are supposed to be case
% insensitive). Fixed subscriber/unsubscriber.
%
% v1.0: new macro. Only tested on Unix.
%}}}
define auto_sub_unsub () %{{{
{
% set defaults for AUTO_SUB_UNSUB_REGEX if the user hasn't set it
if (orelse
{ get_group_flags () & ~ (GROUP_NEW_GROUP_FLAG); } % no new newsgroups
{ is_defined ("AUTO_SUB_UNSUB_REGEX") == 0; } % or no regex defined
{ not (strlen (AUTO_SUB_UNSUB_REGEX)); }) % or regex == Null_String
return; % no actionable setting, nothing to do
variable
element = 0, % current element of regex list
regex = Null_String, % current regex
new_group_count = 0, % number of new newsgroups
toggle_count = 0, % number of new newsgroups toggled
message = Null_String, % message to user summarizing changes
slrnrc_unsubscribe = get_variable_value ("unsubscribe_new_groups");
% For each new group, see if that group should remain subscribed or
% unsubscribed by seeing if any of the regex(es) in AUTO_SUB_UNSUB_REGEX
% match the group name. If so, toggle the group's sub/unsub status.
% record the group where this started (might not be the top)
variable started_newsgroup = current_newsgroup ();
do
{
if (get_group_flags () & ~ (GROUP_NEW_GROUP_FLAG)) {
!if (group_down_n (1))
return;
continue; % group is not new
}
while (regex = strlow (extract_element (AUTO_SUB_UNSUB_REGEX, element, ',')),
strlen (regex)) {
if (string_match (strlow (current_newsgroup ()), regex, 1)) {
% found a matching regex, change subscribe status but
% leave the group as new (some other function may use
% the new tag later).
%
% the nested if (get_group_flags) prevents undesirable
% action if this is run more than once per fetching of
% new groups (e.g., this is mistakenly put in
% group_mode_hook() instead of group_mode_startup_hook()
if (slrnrc_unsubscribe) {
if (get_group_flags () & GROUP_UNSUBSCRIBED) {
% make grp subscribed & new
set_group_flags (~ (get_group_flags ())
| GROUP_UNSUBSCRIBED
| GROUP_NEW_GROUP_FLAG);
toggle_count++;
}
} else {
if (get_group_flags () & ~ (GROUP_UNSUBSCRIBED)) {
% make grp unsubscribed & new
set_group_flags (get_group_flags ()
| GROUP_UNSUBSCRIBED
| GROUP_NEW_GROUP_FLAG);
toggle_count++;
}
}
break;
} % if (string_match...
element++; % next regex
} % while (regex...
element = 0; % reset regex pointer for next newsgroup
new_group_count++;
}
while (group_down_n (1));
% go to group where you started
call ("group_bob"); % reset newsgroup pointer to top
while (not (case (current_newsgroup (), started_newsgroup)))
!if (group_down_n (1))
error (Sprintf ("Can\'t find %s!", started_newsgroup, 1));
% summarize the results
if (toggle_count)
{
if (slrnrc_unsubscribe)
% slrnrc says to subscribe to new groups,
% count reflects unsubscribed groups
message = "unsubscribed";
else
% slrnrc says to unsubscribe to new groups,
% count reflects subscribed groups
message = "subscribed";
message (Sprintf ("Of %i new groups, %i groups are %s",
new_group_count, toggle_count, message, 3));
}
}
%}}}
define sub_unsub_edit_regex () %{{{
{
variable new_regex = Null_String;
if (is_defined ("AUTO_SUB_UNSUB_REGEX"))
new_regex = read_mini ("Edit AUTO_SUB_UNSUB_REGEX",
Null_String,
strcat (AUTO_SUB_UNSUB_REGEX, ","));
else
{
variable newsgroup_str =
Sprintf ("^%s$",
str_quote_string (current_newsgroup(), ".", '\\'),
1);
new_regex = read_mini ("Edit AUTO_SUB_UNSUB_REGEX",
Null_String,
newsgroup_str);
}
!if (strlen (new_regex))
return;
AUTO_SUB_UNSUB_REGEX =
Sprintf ("%s,%s", AUTO_SUB_UNSUB_REGEX, new_regex, 2);
}
%}}}
define sub_unsub_add_current_group () %{{{
{
variable
newsgroup = current_newsgroup (),
newsgroup_str =
Sprintf ("^%s$", str_quote_string (newsgroup, ".", '\\'), 1);
AUTO_SUB_UNSUB_REGEX =
Sprintf ("%s,%s", AUTO_SUB_UNSUB_REGEX, newsgroup_str, 2);
message (strcat (newsgroup, " added to AUTO_SUB_UNSUB_REGEX"));
}
%}}}
define sub_unsub_del_current_group () %{{{
{
!if (strlen (AUTO_SUB_UNSUB_REGEX))
return; % nothing to do
% find the literal that matches the group name
variable
newsgroup_str =
Sprintf ("^%s$",
str_quote_string (strlow (current_newsgroup ()), ".", '\\'),
1),
new_sub_unsub_regex = Null_String, % temp AUTO_SUB_UNSUB_REGEX
regex = Null_String, % regex being examined
element = 0;
% rebuild the temp regex var w/o the current newsgroup
while (regex =
strlow (extract_element (AUTO_SUB_UNSUB_REGEX, element, ',')),
strlen (regex))
if (not (case (regex, newsgroup_str)))
new_sub_unsub_regex = Sprintf ("%s,%s", new_sub_unsub_regex, regex);
}
%}}}
define sub_unsub_find_first_sub_group () %{{{
{
variable started_newsgroup = current_newsgroup ();
if (case (started_newsgroup, Null_String))
error ("No newsgroups!");
% find the topmost subscribed group
while (get_group_flags () & GROUP_UNSUBSCRIBED)
{
!if (group_down_n (1))
% return ptr to where it started
{
call ("bob");
while (0 == case (current_newsgroup (), started_newsgroup))
() = group_down_n (1);
error ("No subscribed groups!");
}
}
}
%}}}
Re: slrn wish: Regex filter for auto-subscribe
Author: Heikki Kantola
Date: Tue, 15 Apr 1997 00:00
Date: Tue, 15 Apr 1997 00:00
29 lines
2077 bytes
2077 bytes
According to rhh@ct.picker.com (Randall Hopper):
> I like having autoscribe on. However, I can easily define a regex of
> some groups I have no desire to subscribe to. I currently manually
> unsubscribe to these, but it'd be nice if I could give slrn a regex for
> newsgroup names I don't want to auto-subscribe to.
Well, I prefer just the other way around (unsubscribe by default), but
I second that there should be ability to control that on group
hierarchy basis. It would be nice if slrn understood the same
AUTO[UN]SUBSCRIBE enviroment variables� as tin and rn-family and
preferably even in such fashion that if you unsubscribe by default it
would hide the unwanted groups.
� From trn's manpage:
AUTOSUBSCRIBE is a comma separated list of newsgroup patterns ala
'o', '/', etc. It can also include "but not" entries preceded by
'!'. "a,b,!c,d" is read as "matching a or b, unless it also
matches c; matching d regardless". Another way to look at it is
"(((a or b) and not c) or d)". To automatically subscribe to all
local groups but be choosy about non-local groups, one might say
"*,!*.*".
--
Heikki "Hezu" Kantola, <Heikki.Kantola@IKI.FI>
L�hett�m�ll� mainoksia tai muuta asiatonta s�hk�postia yll� olevaan
osoitteeseen sitoudut maksamaan oikolukupalvelusta FIM500 alkavalta
tunnilta.
Re: slrn wish: Regex filter for auto-subscribe
Author: Jan Hlavacek
Date: Tue, 15 Apr 1997 00:00
Date: Tue, 15 Apr 1997 00:00
45 lines
1994 bytes
1994 bytes
On 15 Apr 1997 09:26:30 GMT, Heikki Kantola <hkantola@cc.Helsinki.FI> wrote:
>According to rhh@ct.picker.com (Randall Hopper):
>> I like having autoscribe on. However, I can easily define a regex of
>> some groups I have no desire to subscribe to. I currently manually
>> unsubscribe to these, but it'd be nice if I could give slrn a regex for
>> newsgroup names I don't want to auto-subscribe to.
>
>Well, I prefer just the other way around (unsubscribe by default), but
>I second that there should be ability to control that on group
>hierarchy basis
Why don't you try something like
define group_mode_hook ()
{
variable flags;
call ("bob");
do
{
flags = get_group_flags ();
if (flags & GROUP_NEW_GROUP_FLAG)
{
if ( some confition on current_newsgroup () )
{
set_group_flags (flags & ~(GROUP_UNSUBSCRIBED)); % or the
% other way
}
}
}
while (group_down_n (1));
call ("bob");
}
I didn't try that (didn't get any new groups for a few weeks), but I think
it should work.
lahvak
--
Jan Hlav\'{a}\v{c}ek
lahvak+n@math.ohio-state.edu (Blind Carbon Copies will bounce)
www: http://www.math.ohio-state.edu/~lahvak/ is back!
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