4.18.6 Article Buttons

People often include references to other stuff in articles, and it would be nice if Gnus could just fetch whatever it is that people talk about with the minimum of fuzz when you hit RET or use the middle mouse button on these references.

Gnus adds buttons to certain standard references by default: Well-formed URLs, mail addresses, Message-IDs, Info links, man pages and Emacs or Gnus related references. This is controlled by two variables, one that handles article bodies and one that handles article heads:

gnus-button-alist

This is an alist where each entry has this form:

(regexp button-par use-p function data-par)
regexp

All text that match this regular expression (case insensitive) will be considered an external reference. Here’s a typical regexp that matches embedded URLs: ‘<URL:\\([^\n\r>]*\\)>’. This can also be a variable containing a regexp, useful variables to use include gnus-button-url-regexp and gnus-button-mid-or-mail-regexp.

button-par

Gnus has to know which parts of the matches is to be highlighted. This is a number that says what sub-expression of the regexp is to be highlighted. If you want it all highlighted, you use 0 here.

use-p

This form will be evaled, and if the result is non-nil, this is considered a match. This is useful if you want extra sifting to avoid false matches. Often variables named gnus-button-*-level are used here, See Article button levels, but any other form may be used too.

function

This function will be called when you click on this button.

data-par

As with button-par, this is a sub-expression number, but this one says which part of the match is to be sent as data to function.

So the full entry for buttonizing URLs is then

("<URL:\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
gnus-header-button-alist

This is just like the other alist, except that it is applied to the article head only, and that each entry has an additional element that is used to say what headers to apply the buttonize coding to:

(header regexp button-par use-p function data-par)

header is a regular expression.