This chapter is special. Rather than describing intrinsic functions, it gives you a list of hooks that can be used to execute arbitrary S-lang code on certain events (e.g. whenever entering article mode).
You can define code for a hook by putting it into a function that has exactly the same name as the hook. However, the preferred way to add code to a hook is now using the register_hook () intrinsic function on an arbitrary macro. This mechanism allows to connect more than one macro to a hook, which comes in handy if you want to use pre-written macro sets.
Void article_mode_hook ()
This hook is called during article mode after headers have been retrieved but before sorting them. You can use this hook to set variables based on the group name.
The following macro can be used to change the sorting_method
to
something more appropriate for newsgroups which contain encoded articles
and to chose a different signature when posting to comp.*:
define make_group_specific_settings ()
{
variable sorting_method = 7;
variable signature_file = ".signature";
if (is_substr (current_newsgroup (), "binaries")
or is_substr (current_newsgroup (), "pictures"))
sorting_method = 3;
if (0 == strncmp (current_newsgroup (), "comp.", 5))
signature_file = ".nerd-signature";
set_integer_variable ("sorting_method", sorting_method);
set_string_variable ("signature", signature_file);
}
() = register_hook ("article_mode_hook",
"make_group_specific_settings");
Void article_mode_quit_hook ()
This function is called whenever you leave article mode, including the times you switch directly to a different group (without quitting to group mode in between).
Void article_mode_startup_hook ()
Unlike article_mode_hook
, which gets called prior to sorting the
headers, this hook gets called after sorting has taken place.
String cc_hook (String address)
This hook is called when sending a "courtesy copy" of a followup -- it gets the author's email address as an argument and is expected to leave a string on the stack which will be used as the address the CC is actually sent to. If the returned string is empty, no CC is sent.
As this hook returns a value, you cannot bind multiple macros to it.
Void followup_hook ()
Function called when following up to an article.
Void forward_hook ()
Function called when forwarding an article to someone.
Void group_mode_hook ()
This hook will be called whenever group mode is entered. This includes the times when one exits article mode back to group mode.
Void group_mode_startup_hook ()
This hook is called after checking for news and immediately before entering the main keyboard loop. When called, group mode will be active.
Void header_number_hook ()
If defined, this function will be called after selecting a header via a header number.
String make_from_string_hook ()
This function is expected to leave a string on the stack which will be used to generate ``From'' header lines whenever one is needed.
As this hook returns a value, you cannot bind multiple macros to it.
Here is a simple example:
define make_from_string_hook ()
{
return "My Name <me@my.machine>";
}
String make_save_filename_hook ()
This function is expected to leave a string on the stack that will be used to decide what folder an article should be saved to. If the returned filename is not absolute, it is interpreted as relative to save_directory.
As this hook returns a value, you cannot bind multiple macros to it.
Here is a simple example:
define make_save_filename_hook ()
{
if (string_match (extract_article_header ("Subject"), "slrn", 1) != 0)
return "slrn-related";
else
return current_newsgroup();
}
Void post_file_hook ()
Function called after composing and filtering, but before posting article.
An example of this hook is included in macros/ispell.sl in slrn's source tree.
Void post_filter_hook (String file)
This hook may be called just before slrn attempts to post a file. The hook is only called if the user selects the filter option from the prompt:
Post the message? Yes, No, Edit, poStpone, Filter
This hook takes a single parameter: the name of the file that slrn is
about to post.
Void post_hook ()
Function called when posting an article.
Void pre_article_mode_hook ()
This hook is similar to article_mode_hook
except that it is called
before any headers for the group have been retrieved.
Void read_article_hook ()
Function called after reading and processing an article. It may use the replace_article function to change it.
Void reply_hook ()
Function called when replying to poster.
Void resize_screen_hook ()
This hook will be called whenever the screen size changes.
Void startup_hook ()
This hook is called right after the newsreader is initialized and immediately before checking for news. It allows the user to set variables on a server by server basis.
The following example sets the `lines_per_update' variable to 20 and turns off reading of the active file if the servername is `uhog' (it is a slow server):
define make_server_specific_settings ()
{
!if (strcmp (server_name (), "uhog"))
{
set_integer_variable ("lines_per_update", 20);
set_integer_variable ("read_active", 0);
}
}
() = register_hook ("startup_hook",
"make_server_specific_settings");
Integer subject_compare_hook (String subject1, String subject2)
slrn puts postings with identical subjects into the same thread. This hook can be used to override slrn's decision that two subjects are not identical: In this case, it is called with both subjects as arguments. If it returns 0, the articles are put in the same thread.
Void supersede_hook ()
Function called when superseding an article.