annotate lisp/psgml/psgml-other.el @ 74:54cc21c15cbb r20-0b32

Import from CVS: tag r20-0b32
author cvs
date Mon, 13 Aug 2007 09:04:33 +0200
parents 131b0175ea99
children c7528f8e288d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;;; psgml-other.el --- Part of SGML-editing mode with parsing support
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
2 ;; $Id: psgml-other.el,v 1.1.1.1 1996/12/18 22:43:36 steve Exp $
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1994 Lennart Staflin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Lennart Staflin <lenst@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This program is free software; you can redistribute it and/or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; modify it under the terms of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; as published by the Free Software Foundation; either version 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; of the License, or (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;;; Part of psgml.el. Code not compatible with XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (require 'psgml)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (require 'easymenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defvar sgml-max-menu-size (/ (* (frame-height) 2) 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "*Max number of entries in Tags and Entities menus before they are split
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 into several panes.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;;; Key Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Doesn't this work in Lucid? ***
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
42 (define-key sgml-mode-map [?\M-\C-\ ] 'sgml-mark-element)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
44 (define-key sgml-mode-map [S-mouse-1] 'sgml-tags-menu)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;;; Pop Up Menus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defun sgml-popup-menu (event title entries)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "Display a popup menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ENTRIES is a list where every element has the form (STRING . VALUE) or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (x-popup-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (let ((menus (list (cons title entries))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 ((> (length entries) sgml-max-menu-size)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 (setq menus
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 (loop for i from 1 while entries
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60 collect
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 (let ((submenu
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 (subseq entries 0 (min (length entries)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 sgml-max-menu-size))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64 (setq entries (nthcdr sgml-max-menu-size entries))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 (cons
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
66 (format "%s '%s'-'%s'"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 title
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
68 (sgml-range-indicator (caar submenu))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
69 (sgml-range-indicator (caar (last submenu))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
70 submenu))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (cons title menus))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defun sgml-range-indicator (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (substring string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (min (length string) sgml-range-indicator-max-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defun sgml-popup-multi-menu (event title menus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "Display a popup menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 MENUS is a list of menus on the form (TITLE ITEM1 ITEM2 ...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ITEM should have to form (STRING EXPR) or STRING. The EXPR gets evaluated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 if the item is selected."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (nconc menus '(("---" "---"))) ; Force x-popup-menu to use two level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ; menu even if there is only one entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ; on the first level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (eval (car (x-popup-menu event (cons title menus)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;;; Insert with properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar sgml-write-protect-intagible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (not (boundp 'emacs-minor-version)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun sgml-insert (props format &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (insert (apply (function format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (when (and sgml-write-protect-intagible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (getf props 'intangible))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setf (getf props 'read-only) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (add-text-properties start (point) props)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;;; Set face of markup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
107 (defvar sgml-use-text-properties nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
108
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (defun sgml-set-face-for (start end type)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
110 (let ((face (cdr (assq type sgml-markup-faces))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
111 (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
112 (sgml-use-text-properties
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
113 (let ((inhibit-read-only t)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
114 (after-change-function nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
115 (before-change-function nil))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
116 (put-text-property start end 'face face)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
117 (t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
118 (let ((current (overlays-at start))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
119 (pos start)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
120 old-overlay)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
121 (while current
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
122 (cond ((and (null old-overlay)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
123 (eq type (overlay-get (car current) 'sgml-type)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
124 (setq old-overlay (car current)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
125 ((overlay-get (car current) 'sgml-type)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
126 (message "delov: %s" (overlay-get (car current) 'sgml-type))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
127 (delete-overlay (car current))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
128 (setq current (cdr current)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
129 (while (< (setq pos (next-overlay-change pos))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
130 end)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
131 (setq current (overlays-at pos))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
132 (while current
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
133 (when (overlay-get (car current) 'sgml-type)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
134 (delete-overlay (car current)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
135 (setq current (cdr current))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
136 (cond (old-overlay
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
137 (move-overlay old-overlay start end)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
138 (if (null (overlay-get old-overlay 'face))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
139 (overlay-put old-overlay 'face face)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
140 (face
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
141 (setq old-overlay (make-overlay start end))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
142 (overlay-put old-overlay 'sgml-type type)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
143 (overlay-put old-overlay 'face face))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun sgml-set-face-after-change (start end &optional pre-len)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
146 ;; If inserting in front of an markup overlay, move that overlay.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
147 ;; this avoids the overlay beeing deleted and recreated by
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
148 ;; sgml-set-face-for.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
149 (when (and sgml-set-face (not sgml-use-text-properties))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (loop for o in (overlays-at start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 do (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ((not (overlay-get o 'sgml-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ((= start (overlay-start o))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (move-overlay o end (overlay-end o)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
156 (defun sgml-fix-overlay-after-change (overlay flag start end &optional size)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
157 (message "sfix(%s): %d-%d (%s)" flag start end size)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
158 (overlay-put overlay 'front-nonsticky t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
159 (when nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
160 (move-overlay overlay end (overlay-end overlay))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
161
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defalias 'next-overlay-at 'next-overlay-change) ; fix bug in cl.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (defun sgml-clear-faces ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (loop for o being the overlays
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 if (overlay-get o 'sgml-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 do (delete-overlay o)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
171 ;;;; Emacs before 19.29
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
172
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
173 (unless (fboundp 'buffer-substring-no-properties)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
174 (defalias 'buffer-substring-no-properties 'buffer-substring))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
175
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
176
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;;; Provide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (provide 'psgml-other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;; psgml-other.el ends here