0
|
1 ;;;; psgml-xemacs.el --- Part of SGML-editing mode with parsing support
|
2
|
2 ;; $Id: psgml-xemacs.el,v 1.1.1.2 1996/12/18 03:47:15 steve Exp $
|
0
|
3
|
|
4 ;; Copyright (C) 1994 Lennart Staflin
|
|
5
|
|
6 ;; Author: Lennart Staflin <lenst@lysator.liu.se>
|
|
7 ;; William M. Perry <wmperry@indiana.edu>
|
2
|
8 ;; Synced up with Ben Wing's changes for XEmacs 19.14 by
|
|
9 ;; Steven L Baur <steve@miranova.com>
|
0
|
10
|
|
11 ;;
|
|
12 ;; This program is free software; you can redistribute it and/or
|
|
13 ;; modify it under the terms of the GNU General Public License
|
|
14 ;; as published by the Free Software Foundation; either version 2
|
|
15 ;; of the License, or (at your option) any later version.
|
|
16 ;;
|
|
17 ;; This program is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21 ;;
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with this program; if not, write to the Free Software
|
|
24 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25
|
|
26
|
|
27 ;;;; Commentary:
|
|
28
|
|
29 ;;; Part of psgml.el
|
|
30
|
|
31 ;;; Menus for use with XEmacs
|
|
32
|
|
33
|
|
34 ;;;; Code:
|
|
35
|
|
36 (require 'psgml)
|
|
37 ;;(require 'easymenu)
|
|
38
|
|
39 (eval-and-compile
|
|
40 (autoload 'sgml-do-set-option "psgml-edit"))
|
|
41
|
|
42 (defvar sgml-max-menu-size (/ (* (frame-height) 2) 3)
|
|
43 "*Max number of entries in Tags and Entities menus before they are split
|
|
44 into several panes.")
|
|
45
|
|
46 ;;;; Pop Up Menus
|
|
47
|
|
48 (defun sgml-popup-menu (event title entries)
|
|
49 "Display a popup menu."
|
|
50 (setq entries
|
|
51 (loop for ent in entries collect
|
|
52 (vector (car ent)
|
|
53 (list 'setq 'value (list 'quote (cdr ent)))
|
|
54 t)))
|
|
55 (cond ((> (length entries) sgml-max-menu-size)
|
|
56 (setq entries
|
|
57 (loop for i from 1 while entries collect
|
|
58 (let ((submenu
|
|
59 (subseq entries 0 (min (length entries)
|
|
60 sgml-max-menu-size))))
|
|
61 (setq entries (nthcdr sgml-max-menu-size
|
|
62 entries))
|
|
63 (cons
|
|
64 (format "%s '%s'-'%s'"
|
|
65 title
|
|
66 (sgml-range-indicator (aref (car submenu) 0))
|
|
67 (sgml-range-indicator
|
|
68 (aref (car (last submenu)) 0)))
|
|
69 submenu))))))
|
|
70 (sgml-xemacs-get-popup-value (cons title entries)))
|
|
71
|
|
72
|
|
73 (defun sgml-range-indicator (string)
|
|
74 (substring string
|
|
75 0
|
|
76 (min (length string) sgml-range-indicator-max-length)))
|
|
77
|
|
78
|
|
79 (defun sgml-xemacs-get-popup-value (menudesc)
|
|
80 (let ((value nil)
|
|
81 (event nil))
|
|
82 (popup-menu menudesc)
|
|
83 (while (popup-menu-up-p)
|
|
84 (setq event (next-command-event event))
|
|
85 (cond ((menu-event-p event)
|
|
86 (cond
|
|
87 ((eq (event-object event) 'abort)
|
|
88 (signal 'quit nil))
|
|
89 ((eq (event-object event) 'menu-no-selection-hook)
|
|
90 nil)
|
|
91 (t
|
|
92 (eval (event-object event)))))
|
|
93 ((button-release-event-p event) ; don't beep twice
|
|
94 nil)
|
2
|
95 ;; [sb] added condition
|
0
|
96 ((and (fboundp 'event-matches-key-specifier-p)
|
|
97 (event-matches-key-specifier-p event (quit-char)))
|
|
98 (signal 'quit nil))
|
|
99 (t
|
|
100 (beep)
|
|
101 (message "please make a choice from the menu."))))
|
|
102 value))
|
|
103
|
|
104 (defun sgml-popup-multi-menu (pos title menudesc)
|
|
105 "Display a popup menu.
|
|
106 MENUS is a list of menus on the form (TITLE ITEM1 ITEM2 ...).
|
|
107 ITEM should have to form (STRING EXPR) or STRING. The EXPR gets evaluated
|
|
108 if the item is selected."
|
|
109 (popup-menu
|
|
110 (cons title
|
|
111 (loop for menu in menudesc collect
|
|
112 (cons (car menu) ; title
|
|
113 (loop for item in (cdr menu) collect
|
|
114 (if (stringp item)
|
|
115 item
|
|
116 (vector (car item) (cadr item) t))))))))
|
|
117
|
|
118
|
|
119 ;;;; XEmacs menu bar
|
|
120
|
|
121 (defun sgml-make-options-menu (vars)
|
|
122 (loop for var in vars
|
|
123 for type = (sgml-variable-type var)
|
|
124 for desc = (sgml-variable-description var)
|
|
125 collect
|
|
126 (cond
|
|
127 ((eq type 'toggle)
|
|
128 (vector desc (list 'setq var (list 'not var))
|
|
129 ':style 'toggle ':selected var))
|
|
130 ((consp type)
|
|
131 (cons desc
|
|
132 (loop for c in type collect
|
|
133 (if (atom c)
|
|
134 (vector (prin1-to-string c)
|
|
135 (`(setq (, var) (, c)))
|
|
136 :style 'toggle
|
|
137 :selected (`(eq (, var) '(, c))))
|
|
138 (vector (car c)
|
|
139 (`(setq (, var) '(,(cdr c))))
|
|
140 :style 'toggle
|
|
141 :selected (`(eq (, var) '(,(cdr c)))))))))
|
|
142 (t
|
|
143 (vector desc
|
|
144 (`(sgml-do-set-option '(, var)))
|
|
145 t)))))
|
|
146
|
|
147
|
2
|
148 (unless (or (not (boundp 'emacs-major-version))
|
|
149 (and (boundp 'emacs-minor-version)
|
|
150 (< emacs-minor-version 10)))
|
|
151 (loop for ent on sgml-main-menu
|
|
152 if (vectorp (car ent))
|
|
153 do (cond
|
|
154 ((equal (aref (car ent) 0) "File Options >")
|
|
155 (setcar ent
|
|
156 (cons "File Options"
|
|
157 (sgml-make-options-menu sgml-file-options))))
|
|
158 ((equal (aref (car ent) 0) "User Options >")
|
|
159 (setcar ent
|
|
160 (cons "User Options"
|
|
161 (sgml-make-options-menu sgml-user-options)))))))
|
0
|
162
|
|
163
|
|
164 ;;;; Key definitions
|
|
165
|
|
166 (define-key sgml-mode-map [button3] 'sgml-tags-menu)
|
|
167
|
|
168
|
|
169 ;;;; Insert with properties
|
|
170
|
|
171 (defun sgml-insert (props format &rest args)
|
|
172 (let ((start (point))
|
|
173 tem)
|
|
174 (insert (apply (function format)
|
|
175 format
|
|
176 args))
|
|
177 (remf props 'rear-nonsticky) ; not useful in XEmacs
|
|
178
|
|
179 ;; Copy face prop from category
|
|
180 (when (setq tem (getf props 'category))
|
|
181 (when (setq tem (get tem 'face))
|
|
182 (set-face-underline-p (make-face 'underline) t)
|
|
183 (setf (getf props 'face) tem)))
|
|
184
|
|
185 (add-text-properties start (point) props)
|
|
186
|
|
187 ;; A read-only value of 1 is used for the text after values
|
|
188 ;; and this should in XEmacs be open at the front.
|
|
189 (if (eq 1 (getf props 'read-only))
|
|
190 (set-extent-property
|
|
191 (extent-at start nil 'read-only)
|
|
192 'start-open t))))
|
|
193
|
|
194
|
|
195 ;;;; Set face of markup
|
|
196
|
|
197 (defun sgml-set-face-for (start end type)
|
|
198 (let ((face (cdr (assq type sgml-markup-faces)))
|
|
199 o)
|
|
200 (loop for e being the extents from start to end
|
2
|
201 do (when (extent-property e 'sgml-type)
|
0
|
202 (cond ((and (null o)
|
2
|
203 (eq type (extent-property e 'sgml-type)))
|
0
|
204 (setq o e))
|
|
205 (t (delete-extent e)))))
|
|
206
|
|
207 (cond (o
|
|
208 (set-extent-endpoints o start end))
|
|
209 (face
|
|
210 (setq o (make-extent start end))
|
2
|
211 (set-extent-property o 'sgml-type type)
|
0
|
212 (set-extent-property o 'face face)
|
2
|
213 (set-extent-property o 'start-open t)
|
0
|
214 (set-extent-face o face)))))
|
|
215
|
|
216 (defun sgml-set-face-after-change (start end &optional pre-len)
|
2
|
217 ;; This should not be needed with start-open t
|
0
|
218 (when sgml-set-face
|
2
|
219 (let ((o (extent-at start nil 'sgml-type)))
|
0
|
220 (cond
|
|
221 ((null o))
|
|
222 ((= start (extent-start-position o))
|
|
223 (set-extent-endpoints o end (extent-end-position o)))
|
|
224 (t (delete-extent o))))))
|
|
225
|
|
226 ;(defalias 'next-overlay-at 'next-overlay-change) ; fix bug in cl.el
|
|
227
|
|
228 (defun sgml-clear-faces ()
|
|
229 (interactive)
|
|
230 (loop for o being the overlays
|
|
231 if (extent-property o 'type)
|
|
232 do (delete-extent o)))
|
|
233
|
|
234
|
|
235 ;;;; Functions not in XEmacs
|
|
236
|
|
237 (unless (fboundp 'frame-width)
|
|
238 (defalias 'frame-width 'screen-width))
|
|
239
|
|
240 (unless (fboundp 'frame-height)
|
|
241 (defalias 'frame-height 'screen-height))
|
|
242
|
|
243 (unless (fboundp 'buffer-substring-no-properties)
|
|
244 (defalias 'buffer-substring-no-properties 'buffer-substring))
|
|
245
|
|
246
|
|
247 ;;;; Provide
|
|
248
|
|
249 (provide 'psgml-xemacs)
|
|
250
|
|
251
|
|
252 ;;; psgml-xemacs.el ends here
|