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