From xemacs-m  Tue Apr  8 04:35:26 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id EAA24957
	for <xemacs-beta@xemacs.org>; Tue, 8 Apr 1997 04:35:20 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id LAA09739; Tue, 8 Apr 1997 11:35:06 +0200 (MET DST)
Sender: hniksic@public.srce.hr
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: Fully customizable x-toolbar.el
X-URL: ftp://gnjilux.cc.fer.hr/pub/unix/util/wget/
X-Attribution: Hrv
X-Face: &}4JQk=L;e.~x+|eo]#DGk@x3~ed!.~lZ}YQcYb7f[WL9L'Z*+OyA\nA
        EL1M(".[qvI#a2E6WYI5>>e7'@_)3Ol9p|Nn2wNa/;~06jL*B%tTcn/X
        vhAu7qeES0\|MF%$;sI#yn1+y"
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 08 Apr 1997 11:35:05 +0200
Message-ID: <kigwwqdamd2.fsf@jagor.srce.hr>
Lines: 281
X-Mailer: Gnus v5.4.42/XEmacs 19.15

I have finished excellent Jeff Miller's job.

* Jeff Miller
> I'd like to see the lists for news reader & mail reader be customizable
> and the selectors auto-generated from the alists I haven't found an
> example of something like that yet.

The selectors aren't autogenerated from the alists, but are validated
from them, and the docs mention what is valid.  I think it is good
enough.

You'll probably need to redump for this to take effect.  I have
changed the default definition (but not the semantics!) of
`toolbar-{mail,news}-commands-alist' to not include the compiled
functions, and made `toolbar-external' a defun.

This is a patch agains stock 20.1-b11 x-toolbar.el:

--- /home/srce/hniksic/work/xemacs/xemacs-20.1-b11/lisp/x11/x-toolbar.el	Sat Feb 15 23:21:51 1997
+++ x-toolbar.el	Tue Apr  8 11:20:46 1997
@@ -25,64 +25,95 @@
 ;; order to get different behaviour.
 ;;
 
-(defvar toolbar-open-function 'find-file
-  "*Function to call when the open icon is selected.")
+(defgroup toolbar nil
+  "Configure XEmacs Toolbar functions and properties"
+  :group 'environment)
+
+(defcustom toolbar-open-function 'find-file
+  "*Function to call when the open icon is selected."
+  :type '(radio (function-item find-file)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-open ()
   (interactive)
   (call-interactively toolbar-open-function))
 
-(defvar toolbar-dired-function 'dired
-  "*Function to call when the dired icon is selected.")
+(defcustom toolbar-dired-function 'dired
+  "*Function to call when the dired icon is selected."
+  :type '(radio (function-item dired)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-dired ()
   (interactive)
   (call-interactively toolbar-dired-function))
 
-(defvar toolbar-save-function 'save-buffer
-  "*Function to call when the save icon is selected.")
+(defcustom toolbar-save-function 'save-buffer
+  "*Function to call when the save icon is selected."
+  :type '(radio (function-item save-buffer)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-save ()
   (interactive)
   (call-interactively toolbar-save-function))
 
-(defvar toolbar-print-function 'lpr-buffer
-  "*Function to call when the print icon is selected.")
+(defcustom toolbar-print-function 'lpr-buffer
+  "*Function to call when the print icon is selected."
+  :type '(radio (function-item lpr-buffer)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-print ()
   (interactive)
   (call-interactively toolbar-print-function))
 
-(defvar toolbar-cut-function 'x-kill-primary-selection
-  "*Function to call when the cut icon is selected.")
+(defcustom toolbar-cut-function 'x-kill-primary-selection
+  "*Function to call when the cut icon is selected."
+  :type '(radio (function-item x-kill-primary-selection)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-cut ()
   (interactive)
   (call-interactively toolbar-cut-function))
 
-(defvar toolbar-copy-function 'x-copy-primary-selection
-  "*Function to call when the copy icon is selected.")
+(defcustom toolbar-copy-function 'x-copy-primary-selection
+  "*Function to call when the copy icon is selected."
+  :type '(radio (function-item x-copy-primary-selection)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-copy ()
   (interactive)
   (call-interactively toolbar-copy-function))
 
-(defvar toolbar-paste-function 'x-yank-clipboard-selection
-  "*Function to call when the paste icon is selected.")
+(defcustom toolbar-paste-function 'x-yank-clipboard-selection
+  "*Function to call when the paste icon is selected."
+  :type '(radio (function-item x-yank-primary-selection)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-paste ()
   (interactive)
   (call-interactively toolbar-paste-function))
 
-(defvar toolbar-undo-function 'undo
-  "*Function to call when the undo icon is selected.")
+(defcustom toolbar-undo-function 'undo
+  "*Function to call when the undo icon is selected."
+  :type '(radio (function-item undo)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-undo ()
   (interactive)
   (call-interactively toolbar-undo-function))
 
-(defvar toolbar-replace-function 'query-replace
-  "*Function to call when the replace icon is selected.")
+(defcustom toolbar-replace-function 'query-replace
+  "*Function to call when the replace icon is selected."
+  :type '(radio (function-item query-replace)
+                (function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-replace ()
   (interactive)
@@ -92,13 +123,17 @@
 ;; toolbar ispell variables and defuns
 ;;
 
-(defvar toolbar-ispell-function
-  (lambda ()
-    (interactive)
-    (if (region-active-p)
-	(ispell-region (region-beginning) (region-end))
-      (ispell-buffer)))
-  "*Function to call when the ispell icon is selected.")
+(defun toolbar-ispell-internal ()
+  (interactive)
+     (if (region-active-p)
+	 (ispell-region (region-beginning) (region-end))
+       (ispell-buffer)))
+
+(defcustom toolbar-ispell-function 'toolbar-ispell-internal
+  "*Function to call when the ispell icon is selected."
+  :type '(radio (function-item toolbar-ispell-internal)
+		(function :tag "Other"))
+  :group 'toolbar)
 
 (defun toolbar-ispell ()
   "Intelligently spell the region or buffer."
@@ -109,28 +144,43 @@
 ;; toolbar mail variables and defuns
 ;;
 
-(defmacro toolbar-external (process &rest args)
-  `(lambda () (interactive) (call-process ,process nil 0 nil ,@args)))
+;; This used to be a macro that expanded its arguments to a form that
+;; called `call-process'.  With the advent of customize, it's better
+;; to have it as a defun, to make customization easier.
+(defun toolbar-external (process &rest args)
+  (interactive)
+  (apply 'call-process process nil 0 nil args))
 
-(defvar toolbar-mail-commands-alist
+(defcustom toolbar-mail-commands-alist
   `((vm		. vm)
     (gnus	. gnus-no-server)
     (rmail	. rmail)
     (mh		. mh-rmail)
-    (pine	. ,(toolbar-external "xterm" "-e" "pine")) ; *gag*
-    (elm	. ,(toolbar-external "xterm" "-e" "elm"))
-    (mutt	. ,(toolbar-external "xterm" "-e" "mutt"))
-    (exmh	. ,(toolbar-external "exmh"))
+    (pine	. (toolbar-external "xterm" "-e" "pine")) ; *gag*
+    (elm	. (toolbar-external "xterm" "-e" "elm"))
+    (mutt	. (toolbar-external "xterm" "-e" "mutt"))
+    (exmh	. (toolbar-external "exmh"))
     ;; How to turn on netscape mail, command-line??
-    (netscape	. ,(toolbar-external "netscape")))
-  "Alist of mail readers and their commands.
-The car of the alist is the mail reader, and the cdr is the form
-used to start it.")
+    (netscape	. (toolbar-external "netscape")))
+  "*Alist of mail readers and their commands.
+The car of each alist element is the mail reader, and the cdr is the form
+used to start it."
+  :type '(repeat (cons (symbol :tag "Mailer") (function :tag "Start with")))
+  :group 'toolbar)
 
-(defvar toolbar-mail-reader 'vm
+(defcustom toolbar-mail-reader 'vm
   "*Mail reader toolbar will invoke.
-The legal values are `vm' and `gnus', but you can add your own values
-by customizing `toolbar-mail-commands-alist'.")
+The legal values are the keys from `toolbar-mail-command-alist', which should
+be used to add new mail readers.
+
+Mail readers known by default are vm, gnus, rmail, mh, pine, elm, mutt,
+exmh and netscape."
+  :type '(symbol :validate (lambda (wid)
+			     (if (assq (widget-value wid) toolbar-mail-commands-alist)
+				 nil
+			       (widget-put wid :error "Unknown mail reader.")
+			       wid)))
+  :group 'toolbar)
 
 
 (defun toolbar-mail ()
@@ -192,27 +242,40 @@
 ;; toolbar news variables and defuns
 ;;
 
-(defvar toolbar-news-commands-alist
+(defcustom toolbar-news-commands-alist
   `((gnus	. gnus)			; M-x all-hail-gnus
-    (rn		. ,(toolbar-external "xterm" "-e" "rn"))
-    (nn		. ,(toolbar-external "xterm" "-e" "nn"))
-    (trn	. ,(toolbar-external "xterm" "-e" "trn"))
-    (xrn	. ,(toolbar-external "xrn"))
-    (slrn	. ,(toolbar-external "xterm" "-e" "slrn"))
-    (pine	. ,(toolbar-external "xterm" "-e" "pine")) ; *gag*
-    (tin	. ,(toolbar-external "xterm" "-e" "tin")) ; *gag*
-    (netscape	. ,(toolbar-external "netscape" "news:")))
-  "Alist of news readers and their commands.
-Each list element is a pair.  The car of the pair is the mail
-reader, and the cdr is the form used to start it.")
+    (rn		. (toolbar-external "xterm" "-e" "rn"))
+    (nn		. (toolbar-external "xterm" "-e" "nn"))
+    (trn	. (toolbar-external "xterm" "-e" "trn"))
+    (xrn	. (toolbar-external "xrn"))
+    (slrn	. (toolbar-external "xterm" "-e" "slrn"))
+    (pine	. (toolbar-external "xterm" "-e" "pine")) ; *gag*
+    (tin	. (toolbar-external "xterm" "-e" "tin")) ; *gag*
+    (netscape	. (toolbar-external "netscape" "news:")))
+  "*Alist of news readers and their commands.
+The car of each alist element the pair is the news reader, and the cdr
+is the form used to start it."
+  :type '(repeat (cons (symbol :tag "Reader") (sexp :tag "Start with")))
+  :group 'toolbar)
 
-(defvar toolbar-news-reader 'gnus
+(defcustom toolbar-news-reader 'gnus
   "*News reader toolbar will invoke.
-The legal values are gnus, rn, nn, trn, xrn, slrn, pine and netscape.
-You can add your own values by customizing `toolbar-news-commands-alist'.")
+The legal values are the keys from `toolbar-news-command-alist', which should
+be used to add new news readers.
 
-(defvar toolbar-news-use-separate-frame t
-  "*Whether Gnus is invoked in a separate frame.")
+Newsreaders known by default are gnus, rn, nn, trn, xrn, slrn, pine and
+netscape."
+  :type '(symbol :validate (lambda (wid)
+			     (if (assq (widget-value wid) toolbar-news-commands-alist)
+				 nil
+			       (widget-put wid :error "Unknown newsreader.")
+			       wid)))
+  :group 'toolbar)
+
+(defcustom toolbar-news-use-separate-frame t
+  "*Whether Gnus is invoked in a separate frame."
+  :type 'boolean
+  :group 'toolbar)
 
 (defvar toolbar-news-frame nil
   "The frame in which news is displayed.")


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
Speak softly and carry a +6 two-handed sword.

