% -*- mode: slang; mode: fold -*- % temp-score.sl - "temporarily score" the current newsgroup based on % subject, author or body. % Copyright (C) 1999-2004 Thomas Schultz % set_preference() mechanism borrowed from J.B. Nicholson-Owens % % This file may be redistributed and / or modified under the terms of the % GNU General Public License, version 2, as published by the Free Software % Foundation. #iffalse % Documentation %{{{ Description: This macro makes it possible to assign a "temporary score" on all articles that match a given regular expression in the subject, author or body. It will not affect your scorefile, so the scores are lost as soon as you exit the group. The macro can also "tag" matching headers, so they can be selected using the functions defined in nn.sl. This is done automatically if nn.sl is loaded before this file. Installation: After loading this file, you can bind the function temp_score_newsgroup() to whatever key you prefer, by inserting a command like setkey article TempScore->temp_score_newsgroup "§" into your slrnrc file. Preferences: You can use the set_preference() function to customize the behaviour of this macro. To do this, put calls to this function in a file and load it after this file is loaded. The following examples show the default values: TempScore->set_preference("score_additive", 1); If set to zero, the macro will overwrite existing scores instead of adding "score_value" to them. TempScore->set_preference("score_value", 1000); The score that will be given to any matching article. History: - Revision 1.3: Really select each header while searching its body. - Revision 1.2: Updated for slrn 0.9.7.2. - Revision 1.1: Fixed a bug that occurred in sorting modes 10 and 11. #endif %}}} implements ("TempScore"); private variable Prev_Search_Str = "", Nn_Tag_Header = is_defined("nn_tag_header"), Prefs = Assoc_Type []; % Set preferences %{{{ Prefs["score_additive"] = 1; Prefs["score_value"] = 1000; %}}} static define set_preference (preference, value) %{{{ { !if (assoc_key_exists (Prefs, preference)) error ("Preference does not exist: " + string (preference)); variable desired_type = typeof (Prefs[preference]); if (typeof (value) != desired_type) verror ("Wrong type for %s: This preference wants %s not %s", string (preference), string (desired_type), string (typeof (value))); Prefs[preference] = value; } %}}} static define temp_score_newsgroup () %{{{ { if (is_group_mode ()) error (_function_name () + " doesn\'t work in group mode!"); variable on_what = tolower(get_response("aAbBsS", "Temporarily score based on "+ "\001Author, \001Body or \001Subject?")), search_str = read_mini("Score on regexp: ", Prev_Search_Str, ""), was_metamail = get_variable_value("use_metamail"); if (search_str == "") return; Prev_Search_Str = search_str; EXIT_BLOCK { if (search_str != "") { sort_by_sorting_method (); call("header_bob"); } set_integer_variable("use_metamail", was_metamail); % restore metamail setting } set_integer_variable("use_metamail", 0); % Turn off metamail while searching uncollapse_threads (); call("header_bob"); if (on_what == 'b') { variable deleted; if (is_article_visible ()) call ("hide_article"); do % cycle through all articles, scanning their bodies { deleted = (get_header_flags() & HEADER_READ); call ("article_line_up"); % make sure the current header gets selected if (re_search_article (search_str)) { pop (); if (Prefs["score_additive"]) set_header_score(get_header_score() + Prefs["score_value"]); else set_header_score(Prefs["score_value"]); if (Nn_Tag_Header) eval("nn_tag_header ();"); } else !if (Prefs["score_additive"]) set_header_score(0); !if (deleted) set_header_flags (get_header_flags() & ~(HEADER_READ)); call ("hide_article"); } while (header_down(1)); } else { !if (Prefs["score_additive"]) % set all scores to 0 first { do set_header_score(0); while (header_down(1)); call("header_bob"); } switch(on_what) % search for matching articles { case 'a' : while (re_fsearch_author(search_str)) { set_header_score(get_header_score() + Prefs["score_value"]); if (Nn_Tag_Header) eval("nn_tag_header();"); !if (header_down(1)) break; } } { case 's' : while (re_fsearch_subject(search_str)) { set_header_score(get_header_score() + Prefs["score_value"]); if (Nn_Tag_Header) eval("nn_tag_header();"); !if (header_down(1)) break; } } } } %}}}