initial commit
[emacs-init.git] / nxhtml / util / ourcomments-widgets.el
1 ;;; ourcomments-widgets.el --- widgets for custom etc
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2009-10-13 Tue
5 ;; Version:
6 ;; Last-Updated:
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;;
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;;; Change log:
24 ;;
25 ;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;
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.
32 ;;
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.
37 ;;
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.
42 ;;
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;
45 ;;; Code:
46
47 (eval-when-compile (require 'mumamo nil t))
48
49 ;;;###autoload (autoload 'command "ourcomments-widgets")
50 (define-widget 'command 'restricted-sexp
51   "A command function."
52   :complete-function (lambda ()
53                        (interactive)
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)))
65                 widget))
66   :value 'ignore
67   :tag "Command")
68
69
70 ;;;###autoload
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)))
75       (major-modep value)))
76
77 ;; Fix-me: This might in the future be defined in Emacs.
78 ;;;###autoload
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.
84     ;;
85     ;; Fix-me: Maybe test for minor modes? How was that done?
86     (when (and (fboundp value)
87                (commandp value)
88                (not (memq value '(flyspell-mode
89                                   isearch-mode
90                                   savehist-mode
91                                   )))
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))))
96                    (progn
97                      (message "loading ")
98                      (load (cadr (symbol-function value)) t t))
99                  t)
100                (or (memq value
101                          ;; Fix-me: Complement this table of known major modes:
102                          '(fundamental-mode
103                            xml-mode
104                            nxml-mode
105                            nxhtml-mode
106                            css-mode
107                            javascript-mode
108                            espresso-mode
109                            php-mode
110                            ))
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)
115                           ;;(sit-for 4)
116                           nil)
117                    ))
118       t)))
119
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 ()
124                        (interactive)
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)))
133                 widget))
134   :value 'fundamental-mode
135   :tag "Major mode function")
136
137
138
139 (provide 'ourcomments-widgets)
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;;; ourcomments-widgets.el ends here