annotate lisp/hm--html-menus/adapt.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 6a22abad6937
children 0d2f883870bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
1 ;;; $Id: adapt.el,v 1.1.1.1 1996/12/18 22:43:20 steve Exp $
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3 ;;; Copyright (C) 1993, 1994, 1995 Heiko Muenkel
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; email: muenkel@tnt.uni-hannover.de
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Description:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
23 ;;; General functions to port Lucid Emacs to GNU Emacs 19.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Put this file in one of your lisp load directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defun adapt-xemacsp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 "Returns non nil if the editor is the XEmacs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (or (string-match "Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (string-match "XEmacs" emacs-version)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defun adapt-lemacsp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "Returns non nil if the editor is the XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Old version, use `adapt-xemacsp' instead of this."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (or (string-match "Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (string-match "XEmacs" emacs-version)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun adapt-emacs19p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Returns non nil if the editor is the GNU Emacs 19."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (not (adapt-xemacsp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (string= (substring emacs-version 0 2) "19")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
50 ;;; Functions, which doesn't exist in both emacses
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun adapt-region-active-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "Returns t, if a region is active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if (adapt-xemacsp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 mark-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (if (adapt-emacs19p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (load-library "lucid")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (load-library "lmenu")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (require 'font-lock)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (make-face 'font-lock-comment-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defun read-number (prompt &optional integers-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "Reads a number from the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (let ((error t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (number nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (if integers-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (while error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (let ((input-string (read-string prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq number (if (string= "" input-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (read input-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if (integerp number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (setq error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (while error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (let ((input-string (read-string prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq number (if (string= "" input-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (read input-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if (numberp number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (setq error nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 number))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defvar original-read-string-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Points to the original Emacs 19 function read-string.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (if (not original-read-string-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (fset 'original-read-string-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (symbol-function 'read-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defun read-string (prompt &optional initial-contents history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "Return a string from the minibuffer, prompting with string PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 in the minibuffer before reading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 Third arg HISTORY, if non-nil, specifies a history list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (read-from-minibuffer prompt initial-contents nil nil history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defun make-extent (beg end &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (make-overlay beg end buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (defun set-extent-property (extent prop value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (eq prop 'duplicable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (cond ((and value (not (overlay-get extent prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; If becoming duplicable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; copy all overlay props to text props.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (add-text-properties (overlay-start extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (overlay-end extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (overlay-properties extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (overlay-buffer extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; If becoming no longer duplicable, remove these text props.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ((and (not value) (overlay-get extent prop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (remove-text-properties (overlay-start extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (overlay-end extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (overlay-properties extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (overlay-buffer extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; If extent is already duplicable, put this property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; on the text as well as on the overlay.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (if (overlay-get extent 'duplicable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (put-text-property (overlay-start extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (overlay-end extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 prop value (overlay-buffer extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (overlay-put extent prop value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun set-extent-face (extent face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (set-extent-property extent 'face face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun delete-extent (extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (set-extent-property extent 'duplicable nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (delete-overlay extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ; (defun make-extent (from to &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ; "Make extent for range [FROM, TO) in BUFFER -- BUFFER defaults to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;current buffer. Insertions at point TO will be outside of the extent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;insertions at FROM will be inside the extent (and the extent will grow.).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;This is only a simple emulation of the Lucid Emacs extents !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ; (list 'extent from to buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ; (defun set-extent-face (extent face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ; "Make the given EXTENT have the graphic attributes specified by FACE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;This is only a simple emulation of the Lucid Emacs extents !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ; (put-text-property (car (cdr extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ; (car (cdr (cdr extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ; 'face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ; face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ; (car (cdr (cdr (cdr extent))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ; (defun delete-extent (extent_obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ; "Remove EXTENT from its buffer; this does not modify the buffer's text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;only its display properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;This is only a simple emulation of the Lucid Emacs extents !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ; (remove-text-properties (car (cdr extent_obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ; (car (cdr (cdr extent_obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ; (list 'face nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ; (car (cdr (cdr (cdr extent_obj))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if (not (fboundp 'emacs-pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defun emacs-pid ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "Return the process ID of Emacs, as an integer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 This is a dummy function for old versions of the Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 You should install a new version, which has `emacs-pid' implemented."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (if (not (fboundp 'facep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun facep (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Whether OBJECT is a FACE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 It's only a dummy function in the Emacs 19, which returns always nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ; (if (not (fboundp 'set-extent-property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ; (defun set-extent-property (extent property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ; "Change a property of an extent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;Only a dummy version in Emacs 19."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
185 (if (not (fboundp 'region-active-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
186 (defun region-active-p ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
187 "Non-nil iff the region is active.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
188 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
189 Otherwise, this function always returns false."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
190 (adapt-region-active-p)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
191
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
192 (if (not (fboundp 'next-command-event))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
193 (defun next-command-event (&optional event prompt)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
194 "Unlike the XEmacs version it reads the next event, if
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
195 it is a command event or not.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
196
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
197 Return the next available \"user\" event.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
198 Pass this object to `dispatch-event' to handle it.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
199
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
200 If EVENT is non-nil, it should be an event object and will be filled in
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
201 and returned; otherwise a new event object will be created and returned.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
202 If PROMPT is non-nil, it should be a string and will be displayed in the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
203 echo area while this function is waiting for an event.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
204
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
205 The event returned will be a keyboard, mouse press, or mouse release event.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
206 If there are non-command events available (mouse motion, sub-process output,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
207 etc) then these will be executed (with `dispatch-event') and discarded. This
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
208 function is provided as a convenience; it is equivalent to the lisp code
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
209
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
210 (while (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
211 (next-event event prompt)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
212 (not (or (key-press-event-p event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
213 (button-press-event-p event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
214 (button-release-event-p event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
215 (misc-user-event-p event))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
216 (dispatch-event event))"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
217 (message prompt)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
218 (or event
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
219 (read-event))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
220
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
221 (if (not (fboundp 'button-event-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
222 (defun button-event-p (obj)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
223 "True if OBJ is a button-press or button-release event object."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
224 (and (eventp obj)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
225 (or (eq 'mouse-1 (event-basic-type obj))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
226 (eq 'mouse-2 (event-basic-type obj))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
227 (eq 'mouse-3 (event-basic-type obj))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
228
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
229 (if (not (fboundp 'button-press-event-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
230 (defun button-press-event-p (obj)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
231 "True if OBJ is a mouse-button-press event object."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
232 (and (button-event-p obj)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
233 (member 'down (event-modifiers obj)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
234
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
235 (if (not (fboundp 'button-release-event-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
236 (defun button-release-event-p (obj)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
237 "True if OBJ is a mouse-button-release event object."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
238 (and (button-event-p obj)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
239 (not (button-press-event-p obj)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
240
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
241 (if (not (fboundp 'event-window))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
242 (defun event-window (event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
243 "Return the window of the given mouse event.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
244 This may be nil if the event occurred in the border or over a toolbar.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
245 The modeline is considered to be in the window it represents."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
246 (and (eventp event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
247 (listp event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
248 (listp (cdr event))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
249 (listp (car (cdr event)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
250 (car (car (cdr event))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
251
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
252 (if (not (fboundp 'event-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
253 (defun event-buffer (event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
254 "Given a mouse-motion, button-press, or button-release event, return
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
255 the buffer on which that event occurred. This will be nil for non-mouse
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
256 events. If event-over-text-area-p is nil, this will also be nil."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
257 (if (button-event-p event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
258 (window-buffer (event-window event)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
259
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
260
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
261 (if (not (fboundp 'event-closest-point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
262 (defun event-closest-point (event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
263 "Return the character position of the given mouse event.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
264 If the event did not occur over a window or over text, return the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
265 closest point to the location of the event. If the Y pixel position
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
266 overlaps a window and the X pixel position is to the left of that
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
267 window, the closest point is the beginning of the line containing the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
268 Y position. If the Y pixel position overlaps a window and the X pixel
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
269 position is to the right of that window, the closest point is the end
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
270 of the line containing the Y position. If the Y pixel position is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
271 above a window, return 0. If it is below a window, return the value
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
272 of (window-end)."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
273 (posn-point (event-start event))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
274
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
275 (if (not (fboundp 'add-minor-mode))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
276 (defun add-minor-mode (toggle
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
277 name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
278 &optional
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
279 keymap
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
280 after
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
281 toggle-fun)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
282 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
283 TOGGLE is a symbol whose value as a variable specifies whether the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
284 minor mode is active. NAME is the name that should appear in the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
285 modeline (it should be a string beginning with a space). KEYMAP is a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
286 keymap to make active when the minor mode is active. AFTER is the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
287 toggling symbol used for another minor mode. If AFTER is non-nil,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
288 then it is used to position the new mode in the minor-mode alists.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
289
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
290 TOGGLE-FUN is only a dummy variable in the Emacs 19. In the XEmacs
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
291 it has the following description:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
292 TOGGLE-FUN specifies an interactive function that is called to toggle
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
293 the mode on and off; this affects what happens when button2 is pressed
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
294 on the mode, and when button3 is pressed somewhere in the list of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
295 modes. If TOGGLE-FUN is nil and TOGGLE names an interactive function,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
296 TOGGLE is used as the toggle function.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
297
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
298 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
299
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
300 WARNING: THIS FUNCTION ISN'T READ YET."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
301 (if after
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
302 (add-minor-mode-1 toggle name keymap after)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
303 (if (not (assq toggle minor-mode-alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
304 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
305 (setq minor-mode-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
306 (cons (list toggle name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
307 minor-mode-alist))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
308 (if (not (assq toggle minor-mode-map-alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
309 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
310 (setq minor-mode-map-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
311 (cons (cons toggle keymap)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
312 minor-mode-map-alist))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
313 ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
314 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
316
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (provide 'adapt)