# HG changeset patch # User Kim Alvefur # Date 1395585667 -3600 # Node ID e5903656c21adf956c6e1f0eddad6f9e9227ce72 # Parent 1c94ed0bfdec2c447687a4ebd3de0b4d5a3cc00c plugins.ietf: Report number of matches diff -r 1c94ed0bfdec -r e5903656c21a plugins/ietf.lua --- a/plugins/ietf.lua Sun Mar 23 15:35:57 2014 +0100 +++ b/plugins/ietf.lua Sun Mar 23 15:41:07 2014 +0100 @@ -47,10 +47,12 @@ debug("really search for %s", string); local number = tonumber(string); local link, match, matches; + local count = 0 if number then number = ("%04d"):format(number); debug("search for RFC%s", number); link, match = self.data:match("\n(" .. number .. ")%s*([^\n]*)"); + count = 1 else local pat = string:gsub("[()]", function(s) return "%" .. s end) :gsub("[%[]",function(s) return "%" .. s end) @@ -60,6 +62,7 @@ --link, match = self.data:match("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)"); for l,m in self.data:gmatch("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)") do link, match = l, m + count = count + 1 -- Note: This allways returns the last result. -- FIXME Decide on what to do if >1 results. end @@ -94,6 +97,7 @@ end); link = self.links:format(link); match = match:gsub("%. ", ".\n", 1); -- Add a newline between title and authors + if count > 1 then link = link .. " (" .. count .. " more matches)" end cb(match .. "\n" .. link); else cb("Sorry, no match");