annotate lisp/term/sun-mouse.el @ 23:0edd3412f124

Added tag r19-15b94 for changeset 8fc7fe29b841
author cvs
date Mon, 13 Aug 2007 08:50:31 +0200
parents ac2d302a0011
children 5a88923fcbfe
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 ;;; sun-mouse.el --- mouse handling for Sun windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1987 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Jeff Peck
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: hardware
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 file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Jeff Peck, Sun Microsystems, Jan 1987.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Original idea by Stan Jefferson
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 ;;; Modelled after the GNUEMACS keymap interface.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; User Functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; make-mousemap, copy-mousemap,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; define-mouse, global-set-mouse, local-set-mouse,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; use-global-mousemap, use-local-mousemap,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; mouse-lookup, describe-mouse-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; Options:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; extra-click-wait, scrollbar-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar extra-click-wait 150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "*Number of milliseconds to wait for an extra click.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 Set this to zero if you don't want chords or double clicks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defvar scrollbar-width 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "*The character width of the scrollbar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 The cursor is deemed to be in the right edge scrollbar if it is this near the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 right edge, and more than two chars past the end of the indicated line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 Setting to nil limits the scrollbar to the edge or vertical dividing bar.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; Mousemaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defun make-mousemap ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Returns a new mousemap."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (cons 'mousemap nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun copy-mousemap (mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Return a copy of mousemap."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (copy-alist mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun define-mouse (mousemap mouse-list def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "Args MOUSEMAP, MOUSE-LIST, DEF. Define MOUSE-LIST in MOUSEMAP as DEF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 MOUSE-LIST is a list of atoms specifying a mouse hit according to these rules:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 * One of these atoms specifies the active region of the definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 text, scrollbar, modeline, minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 * One or two or these atoms specify the button or button combination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 left, middle, right, double
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 * Any combination of these atoms specify the active shift keys.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 control, shift, meta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 * With a single unshifted button, you can add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 to indicate an up-click.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 The atom `double' is used with a button designator to denote a double click.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 Two button chords are denoted by listing the two buttons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 See sun-mouse-handler for the treatment of the form DEF."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (mousemap-set (mouse-list-to-mouse-code mouse-list) mousemap def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun global-set-mouse (mouse-list def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "Give MOUSE-EVENT-LIST a local definition of DEF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 See define-mouse for a description of MOUSE-EVENT-LIST and DEF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 Note that if MOUSE-EVENT-LIST has a local definition in the current buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 that local definition will continue to shadow any global definition."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (interactive "xMouse event: \nxDefinition: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (define-mouse current-global-mousemap mouse-list def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun local-set-mouse (mouse-list def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Give MOUSE-EVENT-LIST a local definition of DEF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 See define-mouse for a description of the arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 The definition goes in the current buffer's local mousemap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 Normally buffers in the same major mode share a local mousemap."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (interactive "xMouse event: \nxDefinition: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (null current-local-mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setq current-local-mousemap (make-mousemap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (define-mouse current-local-mousemap mouse-list def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun use-global-mousemap (mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Selects MOUSEMAP as the global mousemap."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (setq current-global-mousemap mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun use-local-mousemap (mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Selects MOUSEMAP as the local mousemap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 nil for MOUSEMAP means no local mousemap."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq current-local-mousemap mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; Interface to the Mouse encoding defined in Emacstool.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; Called when mouse-prefix is sent to emacs, additional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; information is read in as a list (button x y time-delta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; First, some generally useful functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defun logtest (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "True if any bits set in X are also set in Y.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 Just like the Common Lisp function of the same name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (not (zerop (logand x y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; Hit accessors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defconst sm::ButtonBits 7) ; Lowest 3 bits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defconst sm::ShiftmaskBits 56) ; Second lowest 3 bits (56 = 63 - 7).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defconst sm::DoubleBits 64) ; Bit 7.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defconst sm::UpBits 128) ; Bit 8.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;; All the useful code bits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defmacro sm::hit-code (hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (` (nth 0 (, hit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; The button, or buttons if a chord.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defmacro sm::hit-button (hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (` (logand sm::ButtonBits (nth 0 (, hit)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; The shift, control, and meta flags.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defmacro sm::hit-shiftmask (hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (` (logand sm::ShiftmaskBits (nth 0 (, hit)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;; Set if a double click (but not a chord).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defmacro sm::hit-double (hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (` (logand sm::DoubleBits (nth 0 (, hit)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;; Set on button release (as opposed to button press).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defmacro sm::hit-up (hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (` (logand sm::UpBits (nth 0 (, hit)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;; Screen x position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defmacro sm::hit-x (hit) (list 'nth 1 hit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;; Screen y position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (defmacro sm::hit-y (hit) (list 'nth 2 hit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;; Milliseconds since last hit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defmacro sm::hit-delta (hit) (list 'nth 3 hit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defmacro sm::hit-up-p (hit) ; A predicate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (` (not (zerop (sm::hit-up (, hit))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; Loc accessors. for sm::window-xy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defmacro sm::loc-w (loc) (list 'nth 0 loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (defmacro sm::loc-x (loc) (list 'nth 1 loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defmacro sm::loc-y (loc) (list 'nth 2 loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defmacro eval-in-buffer (buffer &rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "Macro to switches to BUFFER, evaluates FORMS, returns to original buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; When you don't need the complete window context of eval-in-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (` (let ((StartBuffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (set-buffer (, buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (,@ forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (set-buffer StartBuffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (put 'eval-in-buffer 'lisp-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;; this is used extensively by sun-fns.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (defmacro eval-in-window (window &rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "Switch to WINDOW, evaluate FORMS, return to original window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (` (let ((OriginallySelectedWindow (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (select-window (, window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (,@ forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (select-window OriginallySelectedWindow)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (put 'eval-in-window 'lisp-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;; handy utility, generalizes window_loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;;; It's a macro (and does not evaluate its arguments).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defmacro eval-in-windows (form &optional yesmini)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Switches to each window and evaluates FORM. Optional argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 YESMINI says to include the minibuffer as a window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 This is a macro, and does not evaluate its arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (` (let ((OriginallySelectedWindow (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (, form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (not (eq OriginallySelectedWindow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (next-window nil (, yesmini)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (select-window OriginallySelectedWindow)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (put 'eval-in-window 'lisp-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun move-to-loc (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 "Move cursor to window location X, Y.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 Handles wrapped and horizontally scrolled lines correctly."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (move-to-window-line y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; window-line-end expects this to return the window column it moved to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (let ((cc (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (nc (move-to-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (if (zerop (window-hscroll))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (+ (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (min (- (window-width) 2) ; To stay on the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (+ (window-hscroll) -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (min (1- (window-width)) ; To stay on the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (- nc cc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defun minibuffer-window-p (window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 "True iff this WINDOW is minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (= (frame-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (nth 3 (window-edges window)) ; The bottom edge.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun sun-mouse-handler (&optional hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Evaluates the function or list associated with a mouse hit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 Expecting to read a hit, which is a list: (button x y delta).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 A form bound to button by define-mouse is found by mouse-lookup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 The variables: *mouse-window*, *mouse-x*, *mouse-y* are bound.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 If the form is a symbol (symbolp), it is funcall'ed with *mouse-window*,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 *mouse-x*, and *mouse-y* as arguments; if the form is a list (listp),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 the form is eval'ed; if the form is neither of these, it is an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 Returns nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (null hit) (setq hit (sm::combined-hits)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (let ((loc (sm::window-xy (sm::hit-x hit) (sm::hit-y hit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (let ((*mouse-window* (sm::loc-w loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (*mouse-x* (sm::loc-x loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (*mouse-y* (sm::loc-y loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (mouse-code (mouse-event-code hit loc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (let ((form (eval-in-buffer (window-buffer *mouse-window*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (mouse-lookup mouse-code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (cond ((null form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (if (not (sm::hit-up-p hit)) ; undefined up hits are ok.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (error "Undefined mouse event: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (prin1-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (mouse-code-to-mouse-list mouse-code)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ((symbolp form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (setq this-command form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (funcall form *mouse-window* *mouse-x* *mouse-y*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ((listp form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq this-command (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (eval form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (error "Mouse action must be symbol or list, but was: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; Don't let 'sun-mouse-handler get on last-command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; since this function should be transparent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if (eq this-command 'sun-mouse-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (setq this-command last-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; (message (prin1-to-string this-command)) ; to see what your buttons did
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defun sm::combined-hits ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Read and return next mouse-hit, include possible double click"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (let ((hit1 (mouse-hit-read)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (if (not (sm::hit-up-p hit1)) ; Up hits dont start doubles or chords.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (let ((hit2 (mouse-second-hit extra-click-wait)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (if hit2 ; we cons'd it, we can smash it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ; (setf (sm::hit-code hit1) (logior (sm::hit-code hit1) ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setcar hit1 (logior (sm::hit-code hit1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (sm::hit-code hit2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (if (= (sm::hit-button hit1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (sm::hit-button hit2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 sm::DoubleBits 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 hit1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defun mouse-hit-read ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 "Read mouse-hit list from keyboard. Like (read 'read-char),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 but that uses minibuffer, and mucks up last-command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (let ((char-list nil) (char nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (while (not (equal 13 ; Carriage return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (prog1 (setq char (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setq char-list (cons char char-list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (read (mapconcat 'char-to-string (nreverse char-list) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;;; Second Click Hackery....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;;; if prefix is not mouse-prefix, need a way to unread the char...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;;; or else have mouse flush input queue, or else need a peek at next char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;;; There is no peek, but since one character can be unread, we only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;;; have to flush the queue when the command after a mouse click
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;;; starts with mouse-prefix1 (see below).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;; Something to do later: We could buffer the read commands and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;;; execute them ourselves after doing the mouse command (using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;;; lookup-key ??).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar mouse-prefix1 24 ; C-x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "First char of mouse-prefix. Used to detect double clicks and chords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (defvar mouse-prefix2 0 ; C-@
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 "Second char of mouse-prefix. Used to detect double clicks and chords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defun mouse-second-hit (hit-wait)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 "Returns the next mouse hit occurring within HIT-WAIT milliseconds."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (if (sit-for-millisecs hit-wait) nil ; No input within hit-wait millisecs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (let ((pc1 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if (or (not (equal pc1 mouse-prefix1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (sit-for-millisecs 3)) ; a mouse prefix will have second char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;; Can get away with one unread.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (progn (setq unread-command-events (list pc1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 nil) ; Next input not mouse event.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (let ((pc2 (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (if (not (equal pc2 mouse-prefix2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (progn (setq unread-command-events (list pc1)) ; put back the ^X
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;;; Too bad can't do two: (setq unread-command-event (list pc1 pc2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;;; Well, now we can, but I don't understand this code well enough to fix it...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (ding) ; user will have to retype that pc2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 nil) ; This input is not a mouse event.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; Next input has mouse prefix and is within time limit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (let ((new-hit (mouse-hit-read))) ; Read the new hit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (if (sm::hit-up-p new-hit) ; Ignore up events when timing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (mouse-second-hit (- hit-wait (sm::hit-delta new-hit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 new-hit ; New down hit within limit, return it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (defun sm::window-xy (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 "Find window containing screen coordinates X and Y.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 Returns list (window x y) where x and y are relative to window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (catch 'found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (eval-in-windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (let ((we (window-edges (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (let ((le (nth 0 we))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (te (nth 1 we))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (re (nth 2 we))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (be (nth 3 we)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (if (= re (frame-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; include the continuation column with this window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq re (1+ re)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (if (= be (frame-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; include partial line at bottom of frame with this window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; id est, if window is not multple of char size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq be (1+ be)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (if (and (>= x le) (< x re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (>= y te) (< y be))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (throw 'found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (list (selected-window) (- x le) (- y te))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 t)) ; include minibuffer in eval-in-windows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;;If x,y from a real mouse click, we shouldn't get here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (list nil x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (defun sm::window-region (loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "Parse LOC into a region symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 Returns one of (text scrollbar modeline minibuffer)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (let ((w (sm::loc-w loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (x (sm::loc-x loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (y (sm::loc-y loc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (let ((right (1- (window-width w)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (bottom (1- (window-height w))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (cond ((minibuffer-window-p w) 'minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ((>= y bottom) 'modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ((>= x right) 'scrollbar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; far right column (window separator) is always a scrollbar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ((and scrollbar-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;; mouse within scrollbar-width of edge.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (>= x (- right scrollbar-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;; mouse a few chars past the end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (>= x (+ 2 (window-line-end w x y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 'scrollbar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (t 'text)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defun window-line-end (w x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "Return WINDOW column (ignore X) containing end of line Y"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (eval-in-window w (save-excursion (move-to-loc (frame-width) y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;;; The encoding of mouse events into a mousemap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ;;; These values must agree with coding in emacstool:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (defconst sm::keyword-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 '((left . 1) (middle . 2) (right . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (shift . 8) (control . 16) (meta . 32) (double . 64) (up . 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (text . 256) (scrollbar . 512) (modeline . 1024) (minibuffer . 2048)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defun mouse-event-code (hit loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 "Maps MOUSE-HIT and LOC into a mouse-code."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 ;;;Region is a code for one of text, modeline, scrollbar, or minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (logior (sm::hit-code hit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (mouse-region-to-code (sm::window-region loc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (defun mouse-region-to-code (region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 "Returns partial mouse-code for specified REGION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (cdr (assq region sm::keyword-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (defun mouse-list-to-mouse-code (mouse-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 "Map a MOUSE-LIST to a mouse-code."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (apply 'logior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (cdr (assq x sm::keyword-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 mouse-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defun mouse-code-to-mouse-list (mouse-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 "Map a MOUSE-CODE to a mouse-list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (apply 'nconc (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (if (logtest mouse-code (cdr x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (list (car x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 sm::keyword-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (defun mousemap-set (code mousemap value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (let* ((alist (cdr mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (assq-result (assq code alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if assq-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setcdr assq-result value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setcdr mousemap (cons (cons code value) alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defun mousemap-get (code mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (cdr (assq code (cdr mousemap))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (defun mouse-lookup (mouse-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 "Look up MOUSE-EVENT and return the definition. nil means undefined."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (or (mousemap-get mouse-code current-local-mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (mousemap-get mouse-code current-global-mousemap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;;; I (jpeck) don't understand the utility of the next four functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;;; ask Steven Greenbaum <froud@kestrel>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (defun mouse-mask-lookup (mask list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 "Args MASK (a bit mask) and LIST (a list of (code . form) pairs).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Returns a list of elements of LIST whose code or'ed with MASK is non-zero."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (let ((result nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if (logtest mask (car (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq result (cons (car list) result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defun mouse-union (l l-unique)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "Return the union of list of mouse (code . form) pairs L and L-UNIQUE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 where L-UNIQUE is considered to be union'ized already."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (let ((result l-unique))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (while l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (let ((code-form-pair (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if (not (assq (car code-form-pair) result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq result (cons code-form-pair result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (setq l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (defun mouse-union-first-preferred (l1 l2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 "Return the union of lists of mouse (code . form) pairs L1 and L2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 based on the code's, with preference going to elements in L1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (mouse-union l2 (mouse-union l1 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (defun mouse-code-function-pairs-of-region (region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 "Return a list of (code . function) pairs, where each code is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 currently set in the REGION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (let ((mask (mouse-region-to-code region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (mouse-union-first-preferred
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (mouse-mask-lookup mask (cdr current-local-mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (mouse-mask-lookup mask (cdr current-global-mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;;; Functions for DESCRIBE-MOUSE-BINDINGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;;; And other mouse documentation functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;;; Still need a good procedure to print out a help sheet in readable format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (defun one-line-doc-string (function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 "Returns first line of documentation string for FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 If there is no documentation string, then the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 \"No documentation\" is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (while (consp function) (setq function (car function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (let ((doc (documentation function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (if (null doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "No documentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (string-match "^.*$" doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (substring doc 0 (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (defun print-mouse-format (binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (princ (car binding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (princ ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (lambda (mouse-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (princ mouse-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (princ " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (cdr binding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (princ " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (princ (one-line-doc-string (car binding)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (defun print-mouse-bindings (region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 "Prints mouse-event bindings for REGION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (mapcar 'print-mouse-format (sm::event-bindings region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (defun sm::event-bindings (region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 "Returns an alist of (function . (mouse-list1 ... mouse-listN)) for REGION,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 where each mouse-list is bound to the function in REGION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (let ((mouse-bindings (mouse-code-function-pairs-of-region region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (result nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (while mouse-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let* ((code-function-pair (car mouse-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (current-entry (assoc (cdr code-function-pair) result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (if current-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (setcdr current-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (cons (mouse-code-to-mouse-list (car code-function-pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (cdr current-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (setq result (cons (cons (cdr code-function-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (list (mouse-code-to-mouse-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (car code-function-pair))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq mouse-bindings (cdr mouse-bindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (defun describe-mouse-bindings ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 "Lists all current mouse-event bindings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (princ "Text Region") (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (princ "---- ------") (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (print-mouse-bindings 'text) (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (princ "Modeline Region") (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (princ "-------- ------") (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (print-mouse-bindings 'modeline) (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (princ "Scrollbar Region") (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (princ "--------- ------") (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (print-mouse-bindings 'scrollbar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (defun describe-mouse-briefly (mouse-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 "Print a short description of the function bound to MOUSE-LIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (interactive "xDescibe mouse list briefly: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (let ((function (mouse-lookup (mouse-list-to-mouse-code mouse-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (if function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (message "%s runs the command %s" mouse-list function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (message "%s is undefined" mouse-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (defun mouse-help-menu (function-and-binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (cons (prin1-to-string (car function-and-binding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (menu-create ; Two sub-menu items of form ("String" . nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (list (list (one-line-doc-string (car function-and-binding)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (list (prin1-to-string (cdr function-and-binding)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (defun mouse-help-region (w x y &optional region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 "Displays a menu of mouse functions callable in this region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (let* ((region (or region (sm::window-region (list w x y))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (mlist (mapcar (function mouse-help-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (sm::event-bindings region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (menu (menu-create (cons (list (symbol-name region)) mlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (item (sun-menu-evaluate w 0 y menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ;;; Menu interface functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ;;; use defmenu, because this interface is subject to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ;;; really need a menu-p, but we use vectorp and the context...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (defun menu-create (items)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 "Functional form for defmenu, given a list of ITEMS returns a menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 Each ITEM is a (STRING . VALUE) pair."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (apply 'vector items)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (defmacro defmenu (menu &rest itemlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 "Defines MENU to be a menu, the ITEMS are (STRING . VALUE) pairs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 See sun-menu-evaluate for interpretation of ITEMS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (list 'defconst menu (funcall 'menu-create itemlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (defun sun-menu-evaluate (*menu-window* *menu-x* *menu-y* menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 "Display a pop-up menu in WINDOW at X Y and evaluate selected item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 of MENU. MENU (or its symbol-value) should be a menu defined by defmenu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 A menu ITEM is a (STRING . FORM) pair;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 the FORM associated with the selected STRING is evaluated,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 and the resulting value is returned. Generally these FORMs are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 evaluated for their side-effects rather than their values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 If the selected form is a menu or a symbol whose value is a menu,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 then it is displayed and evaluated as a pullright menu item.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
598 If the FORM of the first ITEM is nil, the STRING of the item
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 is used as a label for the menu, i.e. it's inverted and not selectable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (if (symbolp menu) (setq menu (symbol-value menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (eval (sun-menu-internal *menu-window* *menu-x* *menu-y* 4 menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (defun sun-get-frame-data (code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 "Sends the tty-sub-window escape sequence CODE to terminal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 and returns a cons of the two numbers in returned escape sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 That is it returns (cons <car> <cdr>) from \"\\E[n;<car>;<cdr>t\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 CODE values: 13 = Tool-Position, 14 = Size-in-Pixels, 18 = Size-in-Chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (send-string-to-terminal (concat "\033[" (int-to-string code) "t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (let (char str x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (while (not (equal 116 (setq char (read-char)))) ; #\t = 116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (setq str (cons char str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (setq str (mapconcat 'char-to-string (nreverse str) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (string-match ";[0-9]*" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (setq y (substring str (1+ (match-beginning 0)) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (setq str (substring str (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (string-match ";[0-9]*" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (setq x (substring str (1+ (match-beginning 0)) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (cons (string-to-int y) (string-to-int x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (defun sm::font-size ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 "Returns font size in pixels: (cons Ysize Xsize)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (let ((pix (sun-get-frame-data 14)) ; returns size in pixels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (chr (sun-get-frame-data 18))) ; returns size in chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (cons (/ (car pix) (car chr)) (/ (cdr pix) (cdr chr)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (defvar sm::menu-kludge-x nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 "Cached frame-to-window X-Offset for sm::menu-kludge")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defvar sm::menu-kludge-y nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 "Cached frame-to-window Y-Offset for sm::menu-kludge")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (defun sm::menu-kludge ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 "If sunfns.c uses <Menu_Base_Kludge> this function must be here!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (or sm::menu-kludge-y
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (let ((fs (sm::font-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (setq sm::menu-kludge-y (+ 8 (car fs)) ; a title line and borders
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 sm::menu-kludge-x 4))) ; best values depend on .defaults/Menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (let ((wl (sun-get-frame-data 13))) ; returns frame location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (cons (+ (car wl) sm::menu-kludge-y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (+ (cdr wl) sm::menu-kludge-x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 ;;; Function interface to selection/region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;;; primitive functions are defined in sunfns.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (defun sun-yank-selection ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 "Set mark and yank the contents of the current sunwindows selection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 Insert contents into the current buffer at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (set-mark-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (insert-string (sun-get-selection)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (defun sun-select-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 "Set the sunwindows selection to the region in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (sun-set-selection (buffer-substring beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;;; Support for emacstool
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;;; This closes the window instead of stopping emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (defun suspend-emacstool (&optional stuffstring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 "Suspend emacstool.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 If running under as a detached process emacstool,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 you don't want to suspend (there is no way to resume),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 just close the window, and wait for reopening."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (run-hooks 'suspend-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (if stuffstring (send-string-to-terminal stuffstring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (send-string-to-terminal "\033[2t") ; To close EmacsTool window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (run-hooks 'suspend-resume-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 ;;; initialize mouse maps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (make-variable-buffer-local 'current-local-mousemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (setq-default current-local-mousemap nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (defvar current-global-mousemap (make-mousemap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (provide 'sun-mouse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 ;;; sun-mouse.el ends here