1 ;;; gmm-utils.el --- Utility functions for Gnus, Message and MML
3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Reiner Steib <reiner.steib@gmx.de>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This library provides self-contained utility functions. The functions are
27 ;; used in Gnus, Message and MML, but within this library there are no
28 ;; dependencies on Gnus, Message, or MML.
33 "Utility functions for Gnus, Message and MML."
35 :version "22.1" ;; Gnus 5.10.9
38 ;; Helper functions from `gnus-utils.el': gmm-verbose, gmm-message, gmm-error
40 (defcustom gmm-verbose 7
41 "Integer that says how verbose gmm should be.
42 The higher the number, the more messages will flash to say what
43 it did. At zero, it will be totally mute; at five, it will
44 display most important messages; and at ten, it will keep on
45 jabbering all the time."
50 (defun gmm-regexp-concat (regexp)
51 "Potentially concat a list of regexps into a single one.
52 The concatenation is done with logical ORs."
58 (mapconcat (lambda (elt) (concat "\\(" elt "\\)"))
63 (defun gmm-message (level &rest args)
64 "If LEVEL is lower than `gmm-verbose' print ARGS using `message'.
66 Guideline for numbers:
68 3 - non-serious error messages
69 5 - messages for things that take a long time
70 7 - not very important messages on stuff
71 9 - messages inside loops."
72 (if (<= level gmm-verbose)
74 ;; We have to do this format thingy here even if the result isn't
75 ;; shown - the return value has to be the same as the return value
77 (apply 'format args)))
80 (defun gmm-error (level &rest args)
81 "Beep an error if LEVEL is equal to or less than `gmm-verbose'.
82 ARGS are passed to `message'."
83 (when (<= (floor level) gmm-verbose)
87 (when (and (floatp level)
88 (not (zerop (setq duration (* 10 (- level (floor level)))))))
93 (defun gmm-widget-p (symbol)
94 "Non-nil if SYMBOL is a widget."
95 (get symbol 'widget-type))
97 (autoload 'widget-create-child-value "wid-edit")
98 (autoload 'widget-convert "wid-edit")
99 (autoload 'widget-default-get "wid-edit")
101 ;; Copy of the `nnmail-lazy' code from `nnmail.el':
102 (define-widget 'gmm-lazy 'default
103 "Base widget for recursive datastructures.
105 This is a copy of the `lazy' widget in Emacs 22.1 provided for compatibility."
107 :convert-widget 'widget-value-convert-widget
108 :value-create (lambda (widget)
109 (let ((value (widget-get widget :value))
110 (type (widget-get widget :type)))
111 (widget-put widget :children
112 (list (widget-create-child-value
113 widget (widget-convert type) value)))))
114 :value-delete 'widget-children-value-delete
115 :value-get (lambda (widget)
116 (widget-value (car (widget-get widget :children))))
117 :value-inline (lambda (widget)
118 (widget-apply (car (widget-get widget :children))
120 :default-get (lambda (widget)
122 (widget-convert (widget-get widget :type))))
123 :match (lambda (widget value)
124 (widget-apply (widget-convert (widget-get widget :type))
126 :validate (lambda (widget)
127 (widget-apply (car (widget-get widget :children)) :validate)))
129 ;; Note: The format of `gmm-tool-bar-item' may change if some future Emacs
130 ;; version will provide customizable tool bar buttons using a different
133 ;; TODO: Extend API so that the "Command" entry can be a function or a plist.
134 ;; In case of a list it should have the format...
136 ;; (:none command-without-modifier
137 ;; :shift command-with-shift-pressed
138 ;; :control command-with-ctrl-pressed
139 ;; :control-shift command-with-control-and-shift-pressed
140 ;; ;; mouse-2 and mouse-3 can't be used in Emacs yet.
141 ;; :mouse-2 command-on-mouse-2-press
142 ;; :mouse-3 command-on-mouse-3-press) ;; typically a menu of related commands
144 ;; Combinations of mouse-[23] plus shift and/or controll might be overkill.
146 ;; Then use (plist-get rs-command :none), (plist-get rs-command :shift)
148 (define-widget 'gmm-tool-bar-item (if (gmm-widget-p 'lazy) 'lazy 'gmm-lazy)
149 "Tool bar list item."
152 (list :tag "Command and Icon"
153 (function :tag "Command")
154 (string :tag "Icon file")
156 (const :tag "Default map" nil)
157 ;; Note: Usually we need non-nil attributes if map is t.
158 (const :tag "No menu" t)
159 (sexp :tag "Other map"))
160 (plist :inline t :tag "Properties"))
161 (list :tag "Separator"
162 (const :tag "No command" gmm-ignore)
163 (string :tag "Icon file")
164 (const :tag "No map")
165 (plist :inline t :tag "Properties"))))
167 (define-widget 'gmm-tool-bar-zap-list (if (gmm-widget-p 'lazy) 'lazy 'gmm-lazy)
169 :tag "Tool bar zap list"
170 :type '(choice (const :tag "Zap all" t)
171 (const :tag "Keep all" nil)
174 ;; Work around (bug in customize?), see
175 ;; <news:v9is48jrj1.fsf@marauder.physik.uni-ulm.de>
176 ;; (new-file open-file dired kill-buffer write-file
177 ;; print-buffer customize help)
189 (const search-forward)
195 (symbol :tag "Icon item")))))
197 ;; (defun gmm-color-cells (&optional display)
198 ;; "Return the number of color cells supported by DISPLAY.
199 ;; Compatibility function."
200 ;; ;; `display-color-cells' doesn't return more than 256 even if color depth is
201 ;; ;; > 8 in Emacs 21.
203 ;; ;; Feel free to add proper XEmacs support.
204 ;; (let* ((cells (and (fboundp 'display-color-cells)
205 ;; (display-color-cells display)))
206 ;; (plane (and (fboundp 'x-display-planes)
207 ;; (ash 1 (x-display-planes))))
209 ;; (max (if (integerp cells) cells none)
210 ;; (if (integerp plane) plane none))))
212 (defcustom gmm-tool-bar-style
213 (if (and (boundp 'tool-bar-mode)
215 (and (fboundp 'display-visual-class)
216 (not (memq (display-visual-class)
217 (list 'static-gray 'gray-scale
218 'static-color 'pseudo-color)))))
221 "Prefered tool bar style."
222 :type '(choice (const :tag "GNOME style" gnome)
223 (const :tag "Retro look" retro))