🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
7 messages
7 total messages Started by Thomas Schultz Fri, 28 May 1999 00:00
[slrn macro] End of Thread?
#48902
Author: Thomas Schultz
Date: Fri, 28 May 1999 00:00
14 lines
1142 bytes
Hi,

slrn is definitely able to distinguish between the end of a thread and
the end of a subthread (this information is displayed when <z>ooming
the article window).

However, in an slrn macro, I only managed to find out whether the
current article is the end of a subthread (thread_size() returns 1).
How can I tell whether I'm at the end of a thread in an slrn macro?
-- 
Kind regards,
    Thomas Schultz

Re: [slrn macro] End of Thread?
#48971
Author: Dawn Owens-Nicholson
Date: Sun, 30 May 1999 00:00
30 lines
1643 bytes
Thomas Schultz wrote:
> How can I tell whether I'm at the end of a thread in an slrn macro?

There's more than one way to do it, but you could do something like this:

  define is_at_end_of_thread ()
  {
     if (is_group_mode ())
       error (_function_name () + " doesn\'t work in group mode!");

     variable
       thread_was_collapsed = is_thread_collapsed (),
       starting_point = extract_article_header ("Message-ID");

     EXIT_BLOCK                                  % put thread back as it was
       {
	  () = locate_header_by_msgid (starting_point, 0);
	  if (thread_was_collapsed) collapse_thread ();
       }

     collapse_thread ();                         % go to top of thread
     uncollapse_thread ();
     () = header_down (thread_size () - 1);      % go to end of thread
     return (extract_article_header ("Message-ID") == starting_point);
  }

This will return boolean depending on whether the cursor is at the end of
the thread or not.

Re: [slrn macro] End of Thread?
#49035
Author: Thomas Schultz
Date: Thu, 03 Jun 1999 00:00
71 lines
2699 bytes
On 30 May 1999, Dawn Owens-Nicholson <bluemoon@ux6.cso.uiuc.edu> wrote:

> This will return boolean depending on whether the cursor is at the end of
> the thread or not.

Thank you; with your help, I finally was able to write a macro that
will go to the next article which matches a given condition without
changing the toggled-/untoggled-status of the threads:


define next_article_matching (condition, err_msg)
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");
   
   variable n;
   variable starting_article = extract_article_header("Message-ID");
   variable thread_was_collapsed = is_thread_collapsed ();

   uncollapse_thread();

   forever % loop through article headers
     {
	for (n = thread_size(); n > 1; n--)
	  {
     	     () = header_down(1);
	     if (eval(condition)) return;
	  }
	
	if (is_at_end_of_thread())
	  {
	     if (thread_was_collapsed) collapse_thread;
	     !if (header_down(1)) break;
	     thread_was_collapsed = is_thread_collapsed ();
	     if (eval(condition)) return;
	     else
	       {
		  thread_was_collapsed = is_thread_collapsed ();
		  uncollapse_thread();
	       }
	  }
	else
	  {	
	     !if (header_down(1)) break;
	     if (eval(condition)) return;
	  }
     }
   
   % if no article is found, return to starting point and display error message
   () = locate_header_by_msgid (starting_article, 0);   
   error (err_msg);
}


An example of its use is the following function that will go to the
next article which has a positive score:


define next_pos_score ()
{
   next_article_matching("get_header_score () > 0", "No more articles with a positive score.");
}


I hope this will also be useful for others; suggestions about what
could still be improved are welcome.
-- 
Kind regards,
    Thomas Schultz

Re: [slrn macro] End of Thread?
#49040
Author: Dawn Owens-Nicholson
Date: Thu, 03 Jun 1999 00:00
37 lines
2178 bytes
Thomas Schultz wrote:
> Thank you; with your help, I finally was able to write a macro that
> will go to the next article which matches a given condition without
> changing the toggled-/untoggled-status of the threads:

You might be interested in <slrn7hde4b.4in.bluemoon@ux6.cso.uiuc.edu> which
does something quite similar but for article ranges bounded by the
number-tagged headers.  To process the entire group, you could place a #1
tag at the topmost header and

   TagAction->between_tags_do (&TagAction->sample_function);

to see what will happen.  TagAction->between_tags_do() processes articles
between numeric tags, TagAction->on_tags_do() processes only numerically
tagged articles.  The documentation shows how these work.

> An example of its use is the following function that will go to the
> next article which has a positive score:

I suggest using the intrinsic functions as much as possible because they're
so much faster.  Your example could be done another way that will scale
better in larger groups:

define next_pos_score ()
{
   ERROR_BLOCK
     {
	_clear_error ();                         % clear the original error.
	error ("No more articles with a positive score.");
     }
   call ("next_high_score");                     % default keybinding: "!"
}

The referenced article can be found:
http://www.deja.com/=dnc/msgid.xp?MID=%3Cslrn7hde4b.4in.bluemoon@ux6.cso.uiuc.edu%3E

Re: [slrn macro] End of Thread?
#49047
Author: John E. Davis
Date: Thu, 03 Jun 1999 00:00
21 lines
1335 bytes
On 3 Jun 1999 15:34:13 GMT, Thomas Schultz <tststs@gmx.de>
wrote:
>   forever % loop through article headers
>     {
>	for (n = thread_size(); n > 1; n--)
>	  {
>     	     () = header_down(1);
>	     if (eval(condition)) return;
>	  }

I think it is cleaner if you write the last loop as:

   loop (thread_size () - 1)
     {
        () = header_down(1);
	if (eval(condition)) return;
     }

--John

Re: [slrn macro] End of Thread?
#49053
Author: Thomas Schultz
Date: Fri, 04 Jun 1999 00:00
27 lines
1830 bytes
On 3 Jun 1999, Dawn Owens-Nicholson <bluemoon@ux6.cso.uiuc.edu> wrote:

> You might be interested in <slrn7hde4b.4in.bluemoon@ux6.cso.uiuc.edu>
> which does something quite similar but for article ranges bounded by
> the number-tagged headers.  To process the entire group, you could
> place a #1 tag at the topmost header and [...]

Thanks for the hint. I fetched your article from deja.com; maybe I
will need such a macro one day.

> define next_pos_score ()
> {
>    ERROR_BLOCK
>      {
> 	_clear_error ();                         % clear the original error.
> 	error ("No more articles with a positive score.");
>      }
>    call ("next_high_score");                     % default keybinding: "!"
> }

This will not work as expected if "min_high_score" is not set to 1.
This is BTW the reason why I originally started writing my macro.
-- 
Kind regards,
    Thomas Schultz

Re: [slrn macro] End of Thread?
#49067
Author: Thomas Schultz
Date: Fri, 04 Jun 1999 00:00
14 lines
1238 bytes
On 3 Jun 1999, John E. Davis <davis@space.mit.edu> wrote:

> I think it is cleaner if you write the last loop as:
> 
>    loop (thread_size () - 1)
[...]

Thank you, I changed this. I was unaware of the loop-statement; I
guess I should look at slang.txt more often...
-- 
Kind regards,
    Thomas Schultz

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