1 ;;; ourcomments-widgets.el --- widgets for custom etc
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2009-10-13 Tue
11 ;; Features that might be required by this library:
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; This program is free software; you can redistribute it and/or
29 ;; modify it under the terms of the GNU General Public License as
30 ;; published by the Free Software Foundation; either version 3, or
31 ;; (at your option) any later version.
33 ;; This program is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 ;; General Public License for more details.
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program; see the file COPYING. If not, write to
40 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
41 ;; Floor, Boston, MA 02110-1301, USA.
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 (eval-when-compile (require 'mumamo nil t))
49 ;;;###autoload (autoload 'command "ourcomments-widgets")
50 (define-widget 'command 'restricted-sexp
52 :complete-function (lambda ()
54 (lisp-complete-symbol 'commandp))
55 :prompt-value 'widget-field-prompt-value
56 :prompt-internal 'widget-symbol-prompt-internal
57 :prompt-match 'commandp
58 :prompt-history 'widget-command-prompt-value-history
59 :action 'widget-field-action
60 :match-alternatives '(commandp)
61 :validate (lambda (widget)
62 (unless (commandp (widget-value widget))
63 (widget-put widget :error (format "Invalid command: %S"
64 (widget-value widget)))
71 (defun major-or-multi-majorp (value)
72 "Return t if VALUE is a major or multi major mode function."
73 (or (and (fboundp 'mumamo-multi-major-modep)
74 (fboundp (mumamo-multi-major-modep value)))
77 ;; Fix-me: This might in the future be defined in Emacs.
79 (defun major-modep (value)
80 "Return t if VALUE is a major mode function."
81 (let ((sym-name (symbol-name value)))
82 ;; Do some reasonable test to find out if it is a major mode.
83 ;; Load autoloaded mode functions.
85 ;; Fix-me: Maybe test for minor modes? How was that done?
86 (when (and (fboundp value)
88 (not (memq value '(flyspell-mode
92 (< 5 (length sym-name))
93 (string= "-mode" (substring sym-name (- (length sym-name) 5)))
94 (if (and (listp (symbol-function value))
95 (eq 'autoload (car (symbol-function value))))
98 (load (cadr (symbol-function value)) t t))
101 ;; Fix-me: Complement this table of known major modes:
111 (and (intern-soft (concat sym-name "-hook"))
112 ;; This fits `define-derived-mode'
113 (get (intern-soft (concat sym-name "-hook")) 'variable-documentation))
114 (progn (message "Not a major mode: %s" value)
120 ;;;###autoload (autoload 'major-mode-function "ourcomments-widgets")
121 (define-widget 'major-mode-function 'function
122 "A major mode lisp function."
123 :complete-function (lambda ()
125 (lisp-complete-symbol 'major-or-multi-majorp))
126 :prompt-match 'major-or-multi-majorp
127 :prompt-history 'widget-function-prompt-value-history
128 :match-alternatives '(major-or-multi-majorp)
129 :validate (lambda (widget)
130 (unless (major-or-multi-majorp (widget-value widget))
131 (widget-put widget :error (format "Invalid function: %S"
132 (widget-value widget)))
134 :value 'fundamental-mode
135 :tag "Major mode function")
139 (provide 'ourcomments-widgets)
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;;; ourcomments-widgets.el ends here