Thread View: news.software.readers
1 messages
1 total messages
Started by blue... Dawn Owens-Nicholson
Fri, 16 Apr 1999 00:00
slrn macro to do arbitrary things with # tags
Author: blue... Dawn Owens-Nicholson
Date: Fri, 16 Apr 1999 00:00
Date: Fri, 16 Apr 1999 00:00
405 lines
15224 bytes
15224 bytes
% Eval function on range of articles % -*- mode: slang; mode: fold -*-
%
% Copyright © 1998 J.B. Nicholson-Owens
% Author: J.B. Nicholson-Owens
% Title: TagAction.sl
% Version: 1.2
% Requires: slrn 0.9.5.3 or greater, S-Lang 1.3.5 or greater
#iffalse % Documentation %{{{
Inspired by Parand Tony Darugar in <35992446...@binevolve.com>, see
<URL:http://www.dejanews.com/msgid.xp?MID=%3C35992446.F7165815@binevolve.com%3E>
Thanks for the great idea!
Quick docs:
(1) Put down some numeric tags on headers in article mode.
(2) Load this file and execute:
TagAction->between_tags_do (&TagAction->sample_function);
(3) All the headers between each pair of tags (including the numerically
tagged headers) are now tagged with an asterisk.
(4) Clear the asterisks (ESC-1 ESC-* with the default keybinding) and
execute:
TagAction->on_tags_do (&TagAction->sample_function);
With between_tags_do(Ref_Type f) you can do things *between* numeric tag(s),
with on_tags_do(Ref_Type f) you can do things *on* numeric tagged articles.
Both work with slrn v0.9.5.2 (and later versions as well).
_THIS_ _IS_ _IMPORTANT_: S-Lang code that moves the cursor (arrow or bar) is
not recommended for use with this macro. In the future I'll try to minimize
the adverse effects of using code like the following:
define my_function () % DO _NOT_ USE THIS!
{
call ("toggle_header_tag");
call ("next");
}
TagAction->between_tags_do (&my_function); % eval "my_function" on range.
but ultimately, this warning should be heeded whenever possible. This is
bad code to use with this macro set because both call()s will move the
cursor to some other article, throwing off the macro's ability to keep up
with things. A working version follows:
define my_function () % USE _THIS_ INSTEAD!
{
set_header_flags (get_header_flags () xor HEADER_TAGGED);
}
TagAction->between_tags_do (&my_function); % eval "my_function" on range.
my_function() needs to do the work for each article in the range. Moving
the cursor to the next article will be handled by this macro. Using
set_header_flags() instead accomplishes the same goal without moving the
cursor. sample_function() is provided and does precisely what is shown
above in the second my_function().
Inside your function, do not do any of the following:
* Do not re-order or delete articles from the header list. Lifting
this limit would make this macro *really* slow on large header lists.
* Do not move the cursor at all. (this limit will be somewhat lifted in
a future version). If you *must* move the cursor, move it back to
where it was before your function exits. You can do this with a
function that looks like this:
define my_function ()
{
variable starting_point = extract_article_header ("Message-ID");
.
.
set_input_string (starting_point);
call ("locate_header_by_msgid");
}
* Do not apply numeric tags -- this will cause frustration because the
more tags you apply, the more this macro will do what you don't
expect. Removing numeric tags is not recommended, but (if you know
what you're doing) should not pose a problem. Again, lifting this
limit poses an unreasonably high execution time for long header
lists.
Your function is called many times rather rapidly, so odds are message()s
will go unseen. Using error() will stop this macro set (this might be handy
if you don't want it to complete its task). Return values from your
function will be ignored by this macro set; they will accumulate on the
stack (which might also be handy).
on_tags_do() executes the named function on each tag in turn.
between_tags_do() executes the named function on articles between pairs of
tags: articles betwen tags #1 and #2, #3 and #4, #5 and #6, etc. If there
is no corresponding higher number tag (for instance, one header is tagged
with 29, but no header is tagged with 30), the macro acts as if the higher
numbered tag is on the bottom-most article in the bottom-most thread.
between_tags_do(&TagAction->sample_function()) with the numeric tags as
shown below, the header list would look like this:
tag headers (* is an affected article)
=== =======
1 ------- * <--- beginning of the first range
------- *
------- *
2 ------- * <--- end of the first range
------- <--- this article is not in either range, it is unaffected
3 ------- * <--- beginning of the second range
------- *
------- *
------- * <--- (implied) end of the second range
Reading the tags from top to bottom, if the higher numbered tag in a pair is
above the lower numbered tag, between_tags_do() will wrap around to
mark articles. Again, between_tags_do(&TagAction->sample_function()) and
the following numeric tags:
tag headers (* is an affected article)
=== =======
------- * (5th article to be affected)
------- * (6th article to be affected)
2 ------- * <--- End of range (7th, last, article to be affected)
------- These two articles will not be affected by the macro
------- at all. They lie outside the range of the two tags.
1 ------- * <--- Start of range (1st article to be affected)
------- * (2nd article to be affected)
------- * (3rd article to be affected)
------- * (4th article to be affected)
Compare with this situation where the numeric tags are reversed:
tag headers (* is an affected article)
=== =======
-------
-------
1 ------- * <--- Start of range (first article to be affected)
------- * These two articles are affected by the macro. (2nd)
------- * They lie inside the range of the 1 & 2 pair of tags. (3rd)
2 ------- * <--- End of range (4th & last article to be affected)
-------
-------
-------
Both numeric_tags_do() and between_tags_do() will always affect the articles
(or headers, depending on your function) tagged with numeric tags.
between_tags_do() was written to preserve the threading display as much as
possible, so you shouldn't notice any changes in the thread display
(assuming the macro executes to completion).
To install: Load this file from your slrn.rc or from an S-Lang file. If you
don't know which one to pick, append the slrn.rc instruction line to your
slrn rc ($HOME/.slrnrc in Unix):
interpret "TagAction.sl" % slrn.rc instruction
() = evalfile ("TagAction.sl"); % S-Lang instruction
then use the macro set in S-Lang code:
TagAction->between_tags_do (Ref_Type f) % @f _between_ pairs of tags
TagAction->on_tags_do (Ref_Type f) % @f _on_ each tag in order
Where "f" is a reference to a defined function. For example:
TagAction->between_tags_do (&TagAction->sample_function);
TagAction->on_tags_do (&TagAction->sample_function);
Change log:
v1.1: * Fixed bug where thread in last numeric tag was not re-collapsed in
between_tags_do().
* Fixed minor documentation function listing bug.
v1.2 * Added the TagAction namespace and made private functions file-local.
* Renamed TA_sample_function() to sample_function(). Updated
documentation.
* Used private scope where needed.
* Renamed thread_size2() to thread_size() and goto_num_tagged_header2()
to goto_num_tagged_header().
#endif % End documentation %}}}
implements ("TagAction");
private define thread_size () %{{{
{
% Returns size of the thread from the cursor to the end of the thread,
% subthreads are included (unlike thread_size() where only the current
% header and immediate child articles are included).
if (is_group_mode ())
error (_function_name () + " doesn\'t work in group mode!");
variable
starting_point = extract_article_header ("Message-ID"),
thread_was_collapsed = is_thread_collapsed (),
t_size = 0;
!if (thread_was_collapsed) collapse_thread ();
if (extract_article_header ("Message-ID") == starting_point)
{
!if (thread_was_collapsed) uncollapse_thread ();
return (thread_size ());
}
t_size = Global->thread_size ();
uncollapse_thread ();
loop (t_size - 1)
{
!if (header_down (1))
error (_function_name () +
": Unexpected inability to move down one header!");
t_size--;
if (extract_article_header ("Message-ID") == starting_point)
return (t_size);
}
error (_function_name () + "should never have reached this point.");
}
%}}}
private define eval_range_to (tag, function) %{{{
{
% Returns 1 if the tag was found, 0 otherwise (in this case, @function()
% was executed through the last header in the last thread.
variable
t_size = 0,
thread_was_collapsed = 0,
index = 0;
forever
{
t_size = thread_size ();
thread_was_collapsed = is_thread_collapsed ();
if (thread_was_collapsed) uncollapse_thread ();
for (index = 1; index <= t_size; index++)
{
% Do something here to record message ID?
@function ();
% Do something here to move cursor back to affected article?
if (tag == get_header_tag_number ())
{
if (thread_was_collapsed) collapse_thread ();
return (1);
}
if (index < t_size) () = header_down (1);
}
if (thread_was_collapsed) collapse_thread ();
!if (header_down (1))
{
if (tag == get_header_tag_number ()) return (1);
else return (0);
}
}
}
%}}}
private define goto_num_tagged_header (tag) %{{{
{
% Because Global->goto_num_tagged_header() doesn't return info on
% whether the thread in which the tag was found was collapsed or not.
if (get_header_tag_number () == tag) return (1, is_thread_collapsed ());
variable
index = 0,
t_size = 0,
thread_was_collapsed = 0,
starting_thread_was_collapsed = is_thread_collapsed (),
starting_place = extract_article_header ("Message-ID");
call ("header_bob");
do
{
thread_was_collapsed = is_thread_collapsed ();
t_size = Global->thread_size ();
if (thread_was_collapsed) uncollapse_thread ();
for (index = 1; index <= t_size; index++)
{
if (get_header_tag_number () == tag)
return (1, thread_was_collapsed);
if (index != t_size) () = header_down (1); % next header
}
if (thread_was_collapsed) collapse_thread ();
}
while (header_down (1)); % next thread
set_input_string (starting_place);
call ("locate_header_by_msgid");
if (starting_thread_was_collapsed) collapse_thread ();
return (0, thread_was_collapsed);
}
%}}}
static define version () { return (1.2); }
static define between_tags_do (function) %{{{
{
if (is_group_mode ())
error (_function_name () + ": doesn\'t work in group mode!");
variable
success = 0,
thread_was_collapsed = 0,
new_thread_was_collapsed = 0,
d = 1,
starting_place = extract_article_header ("Message-ID"),
starting_thread_was_collapsed = is_thread_collapsed ();
(success, thread_was_collapsed) = goto_num_tagged_header (d);
while (success)
{
d++;
if (eval_range_to (d, function))
{
goto_num_tagged_header (d - 1);
if (thread_was_collapsed) collapse_thread ();
d++;
}
else
{
(success, new_thread_was_collapsed) = goto_num_tagged_header (d);
!if (success)
{
if (thread_was_collapsed) collapse_thread ();
else uncollapse_thread ();
break;
}
thread_was_collapsed = new_thread_was_collapsed;
call ("header_bob");
() = eval_range_to (d, function);
if (thread_was_collapsed) collapse_thread ();
else uncollapse_thread ();
d++;
}
(success, thread_was_collapsed) = goto_num_tagged_header (d);
}
set_input_string (starting_place);
call ("locate_header_by_msgid");
if (starting_thread_was_collapsed) collapse_thread ();
}
%}}}
static define on_tags_do (function) %{{{
{
if (is_group_mode ())
error (_function_name () + ": doesn\'t work in group mode!");
variable
header_tag = 1,
thread_was_collapsed = 0,
success = 0,
message_ID = "",
starting_place = extract_article_header ("Message-ID");
(success, thread_was_collapsed) = goto_num_tagged_header (header_tag);
while (success)
{
% should we record the location of the affected header with
message_ID = extract_article_header ("Message-ID");
@function ();
% should we put the pointer/bar back at the affected article with:
% if (extract_article_header ("Message-ID") != message_ID)
% {
% set_input_string (message_ID);
% call ("locate_header_by_msgid");
% }
% (this will add the message-ID if it's not there.)
% XOR should we try to account for expunging (deleting) headers?
if (andelse
{ extract_article_header ("Message-ID") != message_ID }
{ get_header_tag_number () <= header_tag })
continue;
if (thread_was_collapsed) collapse_thread ();
header_tag++;
(success, thread_was_collapsed) = goto_num_tagged_header (header_tag);
}
set_input_string (starting_place);
call ("locate_header_by_msgid");
if (thread_was_collapsed) collapse_thread ();
}
%}}}
static define sample_function () %{{{
{
set_header_flags (get_header_flags () xor HEADER_TAGGED);
}
%}}}
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