Thread View: news.software.readers
2 messages
2 total messages
Started by Jim Robinson
Wed, 06 May 1998 00:00
slrn: auto-collapse thread?
Author: Jim Robinson
Date: Wed, 06 May 1998 00:00
Date: Wed, 06 May 1998 00:00
12 lines
790 bytes
790 bytes
Would anyone be able to tell me whether there is a way to make an uncollapsed (open?) thread *automatically* collapse when one moves to the next thread? Thanks -- Jim Robinson robinson@wdg. X mot X .com # remove spaces and Xs in address
Re: slrn: auto-collapse thread?
Author: Dawn Owens-Nicholson
Date: Wed, 06 May 1998 00:00
Date: Wed, 06 May 1998 00:00
726 lines
26476 bytes
26476 bytes
On 6 May 1998 15:57:23 GMT, Jim Robinson <robinson@wdg.mot.com> wrote:
> Would anyone be able to tell me whether there is a way to make an
> uncollapsed (open?) thread *automatically* collapse when one moves to the
> next thread?
Here's something that might help you (one small part isn't fully
debugged, hence the less than 1.0 version number, but otherwise it
works):
% sizer v0.2 % -*- mode: slang; mode: fold -*-
% Author: J.B. Nicholson-Owens
#iffalse Documentation for sizer
This macro set collapses every thread except for the thread being pointed to
by the pointer. Put this file in a directory where slrn can find it (in
some directory listed in your macro_directory, or your home directory).
Installation requires *small* additions to the definition of two hooks
(article_mode_hook() & header_number_hook()). The rest of the macro is
installed by interpreting this file. Include these lines in your slrnrc:
interpret "sizer.sl" % or whatever you called this file
setkey article sizer_prev "p"
setkey article sizer_next "n"
setkey article sizer_up "^P"
setkey article sizer_up "\eOA"
setkey article sizer_up "\e[A"
setkey article sizer_up
setkey article sizer_down "^N"
setkey article sizer_down "\e[B"
setkey article sizer_down "\eOB"
setkey article sizer_pageup "\ev"
setkey article sizer_pagedn "^V"
setkey article sizer_author_search_forward "a"
setkey article sizer_author_search_backward "A"
setkey article sizer_subject_search_forward "s"
setkey article sizer_subject_search_backward "S"
setkey article sizer_delete "d"
setkey article sizer_exchange_mark ","
setkey article sizer_header_bob "\e<"
setkey article sizer_header_eob "\e>"
setkey article sizer_next_high_score "!"
setkey article sizer_get_parent_header "\ep"
setkey article sizer_goto_article "j"
setkey article sizer_locate_header_by_msgid "m"
setkey article sizer_tag_header "#"
The S-Lang code equivalent: %{{{
() = evalfile ("sizer.sl"); % or whatever you called this file
definekey ("sizer_prev", "p", "article");
definekey ("sizer_next", "n", "article");
definekey ("sizer_pageup", "\ev", "article");
definekey ("sizer_pagedn", "^V", "article");
definekey ("sizer_up", "^P", "article");
definekey ("sizer_down", "^N", "article");
% etc...
%}}}
Feel free to change the keymapping, of course, these are only suggestions.
If you don't want the arrow keys to uncollapse threads, don't bind the
sizer_up and sizer_down macros to the arrow keys (you can comment out the
sizer_up and sizer_down lines in your slrnrc by inserting a percent sign
before the word "setkey").
These macros only work in article mode, so don't bind them to keys in group
mode. If you inadvertantly do so, nothing bad will happen, you will receive
an error message.
Next, add this line to your article_mode_hook(): [see bug note]
sizer_article_mode_hook ();
and this line to your header_number_hook():
sizer_header_number_hook ();
If you don't have these hooks defined (or if you have no idea what a `hook'
is), copy these next 9 lines into a file called my_hooks.sl (put my_hooks.sl
in a place slrn will find it, like your home directory):
define header_number_hook ()
{
sizer_header_number_hook ();
}
define article_mode_hook ()
{
sizer_article_mode_hook ();
}
Only if you made the my_hooks.sl file as described above, add this line to
your slrnrc *AFTER* the interpret "sizer.pl" line:
interpret "my_hooks.sl"
Now sizer is installed. When you use keys that move the pointer (including
the next/previous, up/down, page-up/page-down keys or type a header number),
the thread at the pointer will be the only uncollapsed thread. Pointer
movement corresponds to the function called (i.e., "sizer_next" is just like
call("next") or the `n' key except sizer_next displays the entire thread).
Options:
* sizer_prefs.always_uncollapse_threads
This variable controls whether threads will be uncollapsed when moving
from header to header. By default, threads are only uncollapsed when the
next (or previous) article to read is inside a collapsed thread.
The alternative is to always uncollapse threads.
0 = only uncollapse threads when necessary (default)
1 = always uncollapse threads
* sizer_prefs.leave_uncollapsed_threads
When the pointer ("->" or an inverse line) moves to a thread, the thread
is uncollapsed by this macro set (according to the dictates of the
previous option) or it was uncollapsed already. If it was collapsed when
the pointer arrived there and if this preferences is set to non-zero, that
thread will not be collapsed when the pointer leaves that thread (i.e.,
the macro set will leave that uncollapsed thread alone). Otherwise, the
default setting will collapse the thread unconditionally.
0 = unconditionally collapse threads (default)
1 = only recollapse threads that the macro set uncollapsed
To change the setting of any option during a slrn session, bind
sizer_change_prefs to a key by adding the following to your slrnrc, for
example:
setkey article sizer_change_prefs "^O"
setkey group sizer_change_prefs "^O"
Then hit CTRL-O (or whatever key you bound to sizer_change_prefs())
anytime you want to change a preference. When you change preferences you
will see the effect immediately.
Enjoy!
Known bugs:
v0.2: The preference to leave uncollapsed threads alone doesn't work as
intended -- it is supposed to only collapse threads that were
uncollapsed by this macro set. Since it's not a big deal that it
work properly right now, I'll fix it later.
v0.1: There appears to be a bug in slrn 0.9.4.6's article_mode_hook(). Only
call("next") does the unexpected thing (execute uncollapse_thread()
from article_mode_hook() causing the top thread to be uncollapsed).
* call("select_group"))
* call("skip_to_next_group")
* call("page_dn") when reading the last page of the last article in
the previous group
all do the right thing -- uncollapse the thread but recollapse it when
sorting with threading (making uncollapse_thread() or
uncollapse_threads() appear to be a no-op).
Hence, the sizer_article_mode_hook() will not execute as expected all
the time. This is a minor annoyance--using the configured keys will
quickly make the display look as intended.
#endif
% Code %{{{
define bugfix_locate_header_by_msgid () %{{{
{
% With collapsed threads, the intrinsic locate_header_by_msgid will
% unnecessarily uncollapse a thread. This function fixes that and
% only uses the non-buggy portions of locate_header_by_msgid.
variable sought_message_ID = read_mini ("Enter Message-Id", "", "");
!if (strlen (sought_message_ID)) return ();
variable starting_header = extract_article_header ("Message-ID");
call ("header_bob"); % go to top of article list
% The do-while loop moves the pointer from thread to thread while the
% inner for loop checks the articles in each thread. The collapse
% status of the display is only disturbed when the desired message-ID
% is found inside a thread.
do
{
variable
thread_was_collapsed = is_thread_collapsed (),
t_size = thread_size (),
position;
for (position = 1; position <= t_size; position++)
{
if (sought_message_ID == extract_article_header ("Message-ID"))
return ();
if (position == 1) uncollapse_thread ();
else if (andelse
{ position == t_size } % at end of thread
{ thread_was_collapsed })
collapse_thread ();
if (position != t_size) () = header_down (1);
}
}
while (header_down (1));
% moving to starting place
set_input_string (starting_header); call ("locate_header_by_msgid");
% calling the non-buggy part
set_input_string (sought_message_ID); call ("locate_header_by_msgid");
}
%}}}
define enhanced_locate_header_by_msgid (); % needed for recursion! %{{{
define enhanced_locate_header_by_msgid ()
{
% This intrinsic replacement is enhanced in three ways:
% (1) It takes an argument:
% enhanced_locate_header_by_msgid (String_Type Message-ID);
%
% (2) It returns:
% 0 if the message-ID was not found.
% 1 if the message-ID was found in the existing header list.
% 2 if the message-ID was found and added to the header list.
%
% (3) It only uncollapses a thread when the desired message-ID is inside
% a collapsed thread. (functionality from bugfix_locate_header_by_msgid)
variable sought_message_ID;
if (_NARGS == 1) sought_message_ID = ();
else
{
sought_message_ID = read_mini ("Enter Message-Id", "", "");
!if (strlen (sought_message_ID)) return ();
}
variable starting_header = extract_article_header ("Message-ID");
call ("header_bob");
% The do-while (outer) loop moves the pointer from thread to thread
% while the for (inner) loop checks the articles in each thread. The
% collapse status of the display is only disturbed when the desired
% message-ID is found inside a thread.
do
{
variable
thread_was_collapsed = is_thread_collapsed (),
t_size = thread_size (), position;
for (position = 1; position <= t_size; position++)
{
if (sought_message_ID == extract_article_header ("Message-ID"))
return (1);
if (position == 1) uncollapse_thread ();
else if (andelse
{ position == t_size } % at end of thread
{ thread_was_collapsed })
collapse_thread ();
if (position != t_size) () = header_down (1); % next article
}
}
while (header_down (1)); % next thread
% moving back to the starting place
() = enhanced_locate_header_by_msgid (starting_header);
% calling the non-buggy part -- either the header will not be found
% (return 0) or it will be found and added to the article list (return 2)
ERROR_BLOCK { return (0); } % error purposefully not cleared
set_input_string (sought_message_ID);
call ("locate_header_by_msgid");
return (2);
}
%}}}
define intrinsic_function (function) %{{{
{
% return the intrinsic name from a string in the string_intrinsic format
if (string_match (function, "^[^_]*_\\(.+\\)", 1)) {
variable position;
(position, ) = string_match_nth (1);
return (substr (function, position + 1, -1));
}
}
%}}}
variable sizer_prefs = struct
{
always_uncollapse_threads,
% 0 = uncollapse threads when necessary (default)
% 1 = always uncollapse threads
leave_uncollapsed_threads
% 0 = don't leave threads uncollapsed (default)
% 1 = leave originally-uncollapsed threads uncollapsed
};
sizer_prefs.always_uncollapse_threads = 0;
sizer_prefs.leave_uncollapsed_threads = 0;
!if (is_defined ("Sizer_Thread_Collapse_Type")) typedef struct
{
message_ID, % Message-ID of article
is_thread_collapsed, % Is this article collapsed?
next % Pointer to next node
} Sizer_Thread_Collapse_Type;
variable sizer_collapse_list = NULL;
define sizer_record_thread_collapse () %{{{
{
% record the collapse/uncollapse thread status to the article list
variable
starting_point = extract_article_header ("Message-ID"),
list_tail,
thread_was_collapsed, t;
call ("header_bob");
sizer_collapse_list = NULL; % destroy old list
do
{
thread_was_collapsed = is_thread_collapsed ();
if (thread_was_collapsed) uncollapse_thread ();
for (t = thread_size () - 1; t; t--)
{
variable new = @Sizer_Thread_Collapse_Type;
new.message_ID = extract_article_header ("Message-ID");
new.is_thread_collapsed = thread_was_collapsed;
new.next = NULL;
if (sizer_collapse_list == NULL) sizer_collapse_list = new;
else list_tail.next = new;
list_tail = new;
() = header_down (1); % next article in thread
}
if (thread_was_collapsed) collapse_thread ();
}
while (header_down (1)); % next thread
}
%}}}
define sizer_restore_thread_collapse () %{{{
{
% restore the collapse/uncollapse thread status to the article list
variable
list = sizer_collapse_list, % temp pointer
starting_point = extract_article_header ("Message-ID");
call ("header_bob");
while (list != NULL)
{
set_input_string (list.message_ID);
call ("locate_header_by_msgid"); % a buggy intrinsic is OK here...
if (list.is_thread_collapsed) collapse_thread ();
else uncollapse_thread ();
list = list.next;
}
set_input_string (starting_point);
call ("locate_header_by_msgid"); % ...but not preferred here
}
%}}}
define sizer_post_article_mode_hook () %{{{
{
sizer_record_thread_collapse ();
if (sizer_prefs.always_uncollapse_threads) uncollapse_thread ();
}
%}}}
define sizer_header_number_hook () %{{{
{
% if non-odd sorting methods also thread, the get_variable_value clause will have
% to be changed.
if (get_variable_value ("sorting_method") & 1)
{
variable starting_point = extract_article_header ("Message-ID");
if (sizer_prefs.leave_uncollapsed_threads) sizer_restore_thread_collapse ();
else
{
collapse_threads ();
set_input_string (starting_point);
bugfix_locate_header_by_msgid ();
}
if (sizer_prefs.always_uncollapse_threads) uncollapse_thread ();
}
}
%}}}
define sizer_change_prefs () %{{{
{
switch (get_select_box_response
("Preferences",
"Uncollapse thread preference...",
"Leave uncollapsed threads...",
2))
{ case 0 :
sizer_prefs.always_uncollapse_threads = get_select_box_response
("Change uncollapse thread preference:",
"Uncollapse threads when necessary (default)", % Choice 0
"Always uncollapse threads", % Choice 1
2);
}
{ case 1 :
sizer_prefs.leave_uncollapsed_threads = get_select_box_response
("Leave uncollapsed threads alone?",
"No, collapse uncollapsed threads.",
"Yes, leave uncollapsed threads alone.",
2);
}
sizer_header_number_hook ();
}
%}}}
% The following functions have largely the same definition. The function
% name is part of the code, so the function name must remain in the format:
%
% [unique prefix]_<intrinsic slrn function name>
%
% The unique prefix may not contain an underscore character and it must
% adhere to the rules for S-Lang valid identifiers (it must match this
% regex: "^[A-Za-z$_][A-Za-z0-9$_]*$"). Functions calling intrinsics
% that could make the macro operate in both article then group modes
% (such as sizer_next calling the intrinsic "next"), running the sizer
% header number hook is conditional on still being in article mode.
%
%{{{
define sizer_prev () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_next () %{{{
{
if (is_group_mode ())
error (_function_name ()
+ " doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
!if (is_group_mode ()) sizer_header_number_hook ();
}
%}}}
define sizer_up () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call ("up");
sizer_header_number_hook ();
}
%}}}
define sizer_down () %{{{
{
if (is_group_mode ())
error (_function_name ()
+ " doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_pageup () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_pagedn () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
!if (is_group_mode ()) sizer_header_number_hook ();
}
%}}}
define sizer_author_search_forward () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_author_search_backward () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_subject_search_forward () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_subject_search_backward () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_delete () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_exchange_mark () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_header_bob () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_header_eob () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_next_high_score () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_get_parent_header () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_goto_article () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_toggle_sort () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_locate_header_by_msgid () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
if (is_defined ("bugfix_locate_header_by_msgid"))
eval ("bugfix_locate_header_by_msgid");
else call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
define sizer_up_one_header () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call ("up");
if (is_thread_collapsed ()) {
uncollapse_thread ();
loop (thread_size () - 1) call ("down");
}
sizer_header_number_hook ();
}
%}}} % Same functions
define sizer_tag_header () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_header_number_hook ();
}
%}}}
%}}} % Code
% The following functions are defined mostly alike as well, but they're
% unlike the previous group. The functions below call the named intrinsic
% or included function and then update the article thread list by re-reading
% it entirely. Hopefully, updating the entire list by rewriting it from
% scratch is cheap enough that updating the list in a fancier way isn't
% necessary.
define sizer_toggle_collapse_threads () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_record_thread_collapse ();
}
%}}}
define sizer_delete_header () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_record_thread_collapse ();
}
%}}}
define sizer_locate_header () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_record_thread_collapse ();
}
%}}}
define sizer_locate_header_by_msgid () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
call (intrinsic_function (_function_name ()));
sizer_record_thread_collapse ();
}
%}}}
define sizer_enhanced_locate_header_by_msgid () %{{{
{
if (is_group_mode ())
error (_function_name () +
" doesn\'t work in group mode! Check your keybindings!");
if (_NARGS == 1) $0 = enhanced_locate_header_by_msgid ( () );
else
{
_pop_n (_NARGS);
$0 = enhanced_locate_header_by_msgid ();
}
switch ($0)
{ case 1: sizer_record_thread_collapse (); }
{ case 2:
% Find the end of sizer_collapse_list and append new article info to it.
variable list = sizer_collapse_list, tail = sizer_collapse_list;
while (list != NULL)
{
if (list.next == NULL)
{
tail = list;
break;
}
else list = list.next;
}
variable new = @Sizer_Thread_Collapse_Type;
new.message_ID = extract_article_header ("Message-ID");
new.is_thread_collapsed = is_thread_collapsed ();
new.next = tail.next; % should be NULL in all cases
if (tail == NULL) tail = new;
else tail.next = new;
}
return ($0);
}
%}}}
%}}}
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