Gnus development mailing list
 help / color / mirror / Atom feed
From: Reiner Steib <4uce.02.r.steib@gmx.net>
Subject: [patch] More buttons for emacs stuff, MIDs, mail addresses (was: Buttonize man page links)
Date: Wed, 18 Sep 2002 22:41:38 +0200	[thread overview]
Message-ID: <v9it13c9od.fsf@marauder.physik.uni-ulm.de> (raw)
In-Reply-To: <iluelc31f38.fsf@latte.josefsson.org>

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

On Mon, Sep 09 2002, Simon Josefsson wrote:

> Reiner Steib <4uce.02.r.steib@gmx.net> writes:
[...]
>> And, what about your idea [1] to make customize-links buttonized?
[...]
> I like it.  But maybe there should be some policy, I have a feeling we
> are beginning to add a gazillion buttons.  Maybe things will get slow.
> Do people care?  Opinions?
>
> IMHO as long as false positives are very uncommon, I like the buttons.

Me too!

>> Another feature request:
>>
>> Gnus shows news:<mid@fqdn> as links. But many people put MIDs in the
>> text without "news:" (<mid@fqdn>) or even without "<" and ">"
>> (mid@fqdn). WIBNI Gnus would buttonize those too?
[...]
> Patches are welcome, I think. :-)

I hope so. ;-) Here is my patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gnus-art.buttons.patch --]
[-- Type: text/x-patch, Size: 8514 bytes --]

Index: lisp/gnus-art.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/gnus-art.el,v
retrieving revision 6.237
diff -u -u -w -r6.237 gnus-art.el
--- lisp/gnus-art.el	2002/09/18 14:50:20	6.237
+++ lisp/gnus-art.el	2002/09/18 21:21:54
@@ -5274,6 +5274,120 @@
 		 (function :tag "Other"))
   :group 'gnus-article-buttons)
 
+(defcustom gnus-button-prefer-mid-or-mail 'guess
+  "What to do when the button on a string as \"foo123@bar.com\" is pushed.
+Strings like this can be either a message ID or a mail address.  If the
+variable is set to the symbol `ask', query the user what do do.  If it is the
+symbol `guess', Gnus will do a guess and query the user what do do if it is
+ambiguous. If it is one of the sybols `mid' or `mail', Gnus will always assume
+that the string is a message ID or a mail address, respectivly.  See the
+variable `gnus-button-guessed-mid-regexp' for details concerning the
+guessing."
+  ;; FIXME: doc-string could/should be improved.
+  :group 'gnus-article-buttons
+  :type '(choice (const ask)
+		 (const guess)
+		 (const mid)
+		 (const mail)))
+
+(defcustom gnus-button-guessed-mid-regexp
+  (concat "^<?\\(slrn\\|Pine\\)\\."
+	  "\\|\\.fsf@\\|@4ax\\.com\\|@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de"
+	  "\\|^<?.*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*@")
+  "Regular expression that matches message IDs and not mail addresses."
+  ;; TODO: Incorporate more matches from
+  ;; <URL:http://piology.org/perl/id-or-mail.pl.html>. I.e. translate the
+  ;; Perl-REs to Elisp-REs.
+  :group 'gnus-article-buttons
+  :type 'regexp)
+
+(defun gnus-button-handle-mid-or-mail (mid-or-mail)
+  (let* ((pref gnus-button-prefer-mid-or-mail)
+	 (url-mid (concat "news" ":" mid-or-mail))
+	 (url-mailto (concat "mailto" ":" mid-or-mail)))
+    (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
+    ;; If it looks like a MID (well known readers or servers) use 'mid,
+    ;; otherwise 'ask the user.
+    (if (eq pref 'guess)
+	(if (string-match gnus-button-guessed-mid-regexp mid-or-mail)
+	    (setq pref 'mid)
+	  (setq pref 'ask)))
+    (if (eq pref 'ask)
+	(save-window-excursion
+	  (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
+	      (setq pref 'mail)
+	    (setq pref 'mid))))
+    (cond ((eq pref 'mid)
+	   (gnus-message 9 "calling `gnus-button-handle-news' %s" url-mid)
+	   (gnus-button-handle-news url-mid))
+	  ((eq pref 'mail)
+	   (gnus-message 9 "calling `gnus-url-mailto'  %s" url-mailto)
+	   (gnus-url-mailto url-mailto)))))
+
+(defun gnus-button-handle-custom (url)
+  "Follow a Custom URL."
+  (customize-apropos (gnus-url-unhex-string url)))
+
+(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[F1]1>?\\)")
+
+(defun gnus-button-handle-describe-function (url)
+  "Call describe-function when pushing the corresponing URL button."
+  (describe-function
+   (intern
+    (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
+
+(defun gnus-button-handle-describe-variable (url)
+  "Call describe-variable when pushing the corresponing URL button."
+  (describe-variable
+   (intern
+    (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
+
+;; FIXME: Is is possible to implement this?  Else it should be removed here
+;; and in `gnus-button-alist'.
+(defun gnus-button-handle-describe-key (url)
+  "Call describe-key when pushing the corresponing URL button."
+  (error "not implemented"))
+
+(defun gnus-button-handle-apropos (url)
+  "Call apropos when pushing the corresponing URL button."
+  (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
+
+(defun gnus-button-handle-apropos-command (url)
+  "Call apropos when pushing the corresponing URL button."
+  (apropos-command (gnus-replace-in-string url
+					   gnus-button-handle-describe-prefix "")))
+
+(defun gnus-button-handle-apropos-variable (url)
+  "Call apropos when pushing the corresponing URL button."
+  (apropos-variable (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
+
+(defcustom gnus-button-man-level 5
+  "*Integer that says how many man-related buttons Gnus will show.
+The higher the number, the more buttons will appear and the more false
+positves are possible.  Note that you can set this variable local to
+specifific groups.  Setting it higher in Unix groups is probably a good idea.
+See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
+how to set variables in specific groups."
+  :group 'gnus-article-buttons
+  :type 'integer)
+
+(defcustom gnus-button-emacs-level 5
+  "*Integer that says how many emacs-related buttons Gnus will show.  
+The higher the number, the more buttons will appear and the more false
+positves are possible.  Note that you can set this variable local to
+specifific groups.  Setting it higher in Emacs or Gnus related groups is
+probably a good idea.See Info node `(gnus)Group Parameters' and the variable
+`gnus-parameters' on how to set variables in specific groups."
+  :group 'gnus-article-buttons
+  :type 'integer)
+
+(defcustom gnus-button-mail-level 5
+  "*Integer that says how many buttons for message IDs or mail addresses will appear.
+The higher the number, the more buttons will appear and the more false
+positves are possible."
+  :group 'gnus-article-buttons
+  :type 'integer)
+
 (defcustom gnus-button-alist
   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
      0 t gnus-button-handle-news 3)
@@ -5289,14 +5403,48 @@
     ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
     ;; This is info
-    ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
+    ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 
      gnus-button-handle-info 2)
+    ;; This is custom
+    ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)" 0
+     (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
+    ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
+     (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
+    ;; Emacs help commands
+    ("M-x[ \t\n]apropos[ \t\n]\\([^ ]+\\)[ \t\n]RET"
+     ;; regexp doesn't match arguments containing ` '.
+     0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
+    ("M-x[ \t\n]apropos-command[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
+     (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
+    ("M-x[ \t\n]apropos-variable[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
+     (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
+    ("\\W\\(C-h\\|<?[F1]1>?\\)[ \t\n]f[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
+     (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
+    ("\\W\\(C-h\\|<?[F1]1>?\\)[ \t\n]v[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
+     (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
+    ("\\W\\(C-h\\|<?[F1]1>?\\)[ \t\n]k[ \t\n]\\([^ ]+\\)[ \t\n]" 0
+     ;; this regexp needs to be fixed!
+     (>= gnus-button-emacs-level 9) gnus-button-handle-describe-key 2)
     ;; This is how URLs _should_ be embedded in text...
     ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
     ;; Raw URLs.
     (gnus-button-url-regexp 0 t browse-url 0)
     ;; man pages
-    ("\\b\\([a-z]+\\)([0-9])\\W" 0 t gnus-button-handle-man 1))
+    ("\\b\\([a-z][a-z]+\\)([0-9])\\W" 0 (>= gnus-button-man-level 1)
+     gnus-button-handle-man 1)
+    ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
+    ("\\b\\([a-zA-Z][-_.a-zA-Z0-9]+\\)([0-9]x?)\\W" 0
+     (>= gnus-button-man-level 3) gnus-button-handle-man 3)
+    ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm), SoWWWAnchor(3iv)
+    ("\\b\\([a-zA-Z][-_.:a-zA-Z0-9]+\\)([0-9][a-z]*)\\W" 0
+     (>= gnus-button-man-level 5) gnus-button-handle-man 1)
+    ;; MID or mail: To avoid too many false positives we don't try to catch
+    ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
+    ;; at least one dot.  TLD must contain two or three chars or be a know TLD
+    ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
+    ;; so that non-ambiguous entries (see above) match first.
+    ("\\b\\(<?[a-zA-Z0-9][^>)!;:,{}\n\t ]*@[a-zA-Z0-9][-.a-zA-Z0-9]+\\.\\([a-zA-Z][a-zA-Z]\\([a-zA-Z]\\)?\\|[Ii][Nn][Ff][Oo]\\|[Nn][Aa][Mm][Ee]\\)>?\\)\\b"
+     0 (>= gnus-button-mail-level 5) gnus-button-handle-mid-or-mail 1))
   "*Alist of regexps matching buttons in article bodies.
 
 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where

[-- Attachment #3: Type: text/plain, Size: 2875 bytes --]


I used it for some days now. I tried to get rid of false positives,
especially for `gnus-button-handle-man' and
`gnus-button-handle-mid-or-mail'. Needless to say that it works for
me. ;-)

Suggested ChangeLog entry:

--8<---------------cut here---------------start------------->8---
	* gnus-art.el (gnus-button-handle-custom,
	gnus-button-handle-mid-or-mail,
	gnus-button-handle-describe-{function,variable,key},
	gnus-button-handle-apropos{,command,variable}): New functions.
	(gnus-button-prefer-mid-or-mail,gnus-button-guessed-mid-regexp,
	gnus-button-{man,emacs,mail}-level): New variables.
	(gnus-button-alist): Use the above to buttonize emacs and mail
	related links.
--8<---------------cut here---------------end--------------->8---

I have to mention, that the stuff related to custom is borrowed from
Simon's previous posting.

As I'm a Lisp beginner I would appreciate your comments.

Some remarks and questions:

(1)

Is `intern' (used in `gnus-button-handle-describe-*') the correct way
to get a symbol corresponding to a given string? `intern' creates a
symbol if it doesn't exist. Should we avoid this side effect in
`gnus-button-handle-describe-{function,variable}'?

(2)

Feel free to change (or suggest changes to) the doc-strings. I'm not
a native speaker, neither for English nor Gnus-speek. :-)

(3)

I couldn't find out how to implement `g-b-handle-describe-key'. I
added a regexp (needs to be improved!) in the list and a dummy
function. But the button is not enabled by default. If it doesn't seem
to be feasible this should be removed.

(4)

The regexp for g-b-handle-apropos could be improved too. It only
matches expressions without space up to now:

"M-x[ \t\n]apropos[ \t\n]\\([^ ]+\\)[ \t\n]RET"

(5)

Per Abrahamsen suggested in news:<rjvg5fz1rr.fsf@zuse.dina.kvl.dk>:
"We might want button types specific for groups whose name match some
regexp.".

Why don't we use the `FORM' mentioned in the doc-string of
`gnus-button-alist' in combination with group parameters or
`gnus-parameters'? I've chosen this way and added the
`gnus-button-*-level' variables (should we use a different naming
convention?). The user may set this variables specific to certain
groups. If he doesn't like buttons, he can set the `g-b-*-level'
variables to zero.

Andreas Fuchs mentioned <URL:http://asf.void.at/emacs/gnus-BTS.el>: He
uses `in-debian-group-p' (a variable. BTW: shouldn't *-p be a function
by convention?) and `gnus-article-mode-hook' to set the additional
buttons. Are there advantages over the `FORM'/gnus-parameters approach
described above?

(6)

I've signed the paperwork of the FSF for Emacs.

(7)

In news:<v9elbrt7tc.fsf@marauder.physik.uni-ulm.de> (in gnus.test)
you'll see some examples of the new buttons. Hope you like it.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo--- PGP key available via WWW   http://rsteib.home.pages.de/

  parent reply	other threads:[~2002-09-18 20:41 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <lcoumukovevvjjmjdn1svsl8ns6316aoca@4ax.com>
     [not found] ` <3D6FED17.6040201@yahoo.com.cn>
     [not found]   ` <m3ptvr2j4k.fsf@hartford-hwp.com>
     [not found]     ` <ilu8z2c4hl5.fsf@latte.josefsson.org>
     [not found]       ` <alfu5t$m59$1@quimby.gnus.org>
2002-09-09 12:43         ` Buttonize man page links Reiner Steib
2002-09-09 13:12           ` Simon Josefsson
2002-09-09 14:12             ` Reiner Steib
2002-09-09 14:16             ` Per Abrahamsen
2002-09-09 17:15               ` Andreas Fuchs
2002-09-10  7:26             ` Mats Lidell
2002-09-18 20:41             ` Reiner Steib [this message]
2002-09-19 11:42               ` [patch] More buttons for emacs stuff, MIDs, mail addresses Reiner Steib
2002-09-20 15:58               ` Kai Großjohann
2002-09-23 18:12                 ` Reiner Steib
2002-09-23 19:55                   ` Kai Großjohann
2002-09-24  0:32                     ` Katsumi Yamaoka
2002-09-24  8:07                       ` Kai Großjohann
2002-09-24 12:40                         ` Katsumi Yamaoka
2002-09-24 20:28                         ` XEmacs compiler warnings (was: [patch] More buttons for emacs stuff, MIDs, mail addresses) Reiner Steib
2002-09-25 13:16                           ` XEmacs compiler warnings Kai Großjohann
2002-09-25 17:44                             ` Reiner Steib
2002-09-24 20:29                       ` [patch] More buttons for emacs stuff, MIDs, mail addresses Reiner Steib
2002-09-24 20:39                         ` Paul Jarc
2002-09-24 22:15                           ` Reiner Steib
2002-09-25 13:52                         ` Kai Großjohann
2002-09-25 14:51                           ` Reiner Steib
2002-09-25 15:02                             ` Kai Großjohann
2002-09-24 19:28                   ` Raymond Scholz
2002-09-24 19:49                     ` Frank Schmitt
2002-09-24 20:56                     ` Reiner Steib
2002-10-16 17:20                       ` Raymond Scholz
2002-10-16 20:10                         ` Raymond Scholz
2002-10-17 15:03                         ` Reiner Steib
2002-12-29 17:55                       ` Lars Magne Ingebrigtsen
2002-12-30 17:58                         ` Reiner Steib
2003-01-01 19:09                           ` Lars Magne Ingebrigtsen
2003-01-01 20:38                             ` Reiner Steib
2003-01-01 20:59                               ` Lars Magne Ingebrigtsen
2003-01-07 18:21                                 ` Docu and menu patches for message.el/message.texi (was: [patch] More buttons for emacs stuff, MIDs, mail addresses) Reiner Steib
2003-01-08  4:08                                   ` Docu and menu patches for message.el/message.texi Lars Magne Ingebrigtsen
2003-01-08 12:03                                     ` Reiner Steib
2003-01-08 12:28                                       ` Lars Magne Ingebrigtsen
2003-01-08 15:12                                         ` Reiner Steib
2003-01-08 16:05                                           ` Lars Magne Ingebrigtsen
2003-01-02 16:47                         ` [patch] More buttons for emacs stuff, MIDs, mail addresses Reiner Steib
2003-01-02 18:00                           ` Henrik Enberg
2003-01-02 18:16                             ` Norbert Koch
2003-01-02 18:29                           ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=v9it13c9od.fsf@marauder.physik.uni-ulm.de \
    --to=4uce.02.r.steib@gmx.net \
    --cc=reiner.steib@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).