Mercurial > hg > xemacs-beta
comparison lisp/term/sun-mouse.el @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | 3ecd8885ac67 |
children |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
32 | 32 |
33 ;; | 33 ;; |
34 ;; Modelled after the GNUEMACS keymap interface. | 34 ;; Modelled after the GNUEMACS keymap interface. |
35 ;; | 35 ;; |
36 ;; User Functions: | 36 ;; User Functions: |
37 ;; make-mousemap, copy-mousemap, | 37 ;; make-mousemap, copy-mousemap, |
38 ;; define-mouse, global-set-mouse, local-set-mouse, | 38 ;; define-mouse, global-set-mouse, local-set-mouse, |
39 ;; use-global-mousemap, use-local-mousemap, | 39 ;; use-global-mousemap, use-local-mousemap, |
40 ;; mouse-lookup, describe-mouse-bindings | 40 ;; mouse-lookup, describe-mouse-bindings |
41 ;; | 41 ;; |
42 ;; Options: | 42 ;; Options: |
187 (defmacro eval-in-windows (form &optional yesmini) | 187 (defmacro eval-in-windows (form &optional yesmini) |
188 "Switches to each window and evaluates FORM. Optional argument | 188 "Switches to each window and evaluates FORM. Optional argument |
189 YESMINI says to include the minibuffer as a window. | 189 YESMINI says to include the minibuffer as a window. |
190 This is a macro, and does not evaluate its arguments." | 190 This is a macro, and does not evaluate its arguments." |
191 `(let ((OriginallySelectedWindow (selected-window))) | 191 `(let ((OriginallySelectedWindow (selected-window))) |
192 (unwind-protect | 192 (unwind-protect |
193 (while (progn | 193 (while (progn |
194 ,form | 194 ,form |
195 (not (eq OriginallySelectedWindow | 195 (not (eq OriginallySelectedWindow |
196 (select-window | 196 (select-window |
197 (next-window nil ,yesmini)))))) | 197 (next-window nil ,yesmini)))))) |
214 x)))))) | 214 x)))))) |
215 (- nc cc))) | 215 (- nc cc))) |
216 | 216 |
217 | 217 |
218 (defun minibuffer-window-p (window) | 218 (defun minibuffer-window-p (window) |
219 "True iff this WINDOW is minibuffer." | 219 "Return t if this WINDOW is a minibuffer." |
220 (= (frame-height) | 220 (= (frame-height) |
221 (nth 3 (window-edges window)) ; The bottom edge. | 221 (nth 3 (window-edges window)) ; The bottom edge. |
222 )) | 222 )) |
223 | 223 |
224 | 224 |
225 (defun sun-mouse-handler (&optional hit) | 225 (defun sun-mouse-handler (&optional hit) |
226 "Evaluates the function or list associated with a mouse hit. | 226 "Evaluates the function or list associated with a mouse hit. |
227 Expecting to read a hit, which is a list: (button x y delta). | 227 Expecting to read a hit, which is a list: (button x y delta). |
228 A form bound to button by define-mouse is found by mouse-lookup. | 228 A form bound to button by define-mouse is found by mouse-lookup. |
229 The variables: *mouse-window*, *mouse-x*, *mouse-y* are bound. | 229 The variables: *mouse-window*, *mouse-x*, *mouse-y* are bound. |
230 If the form is a symbol (symbolp), it is funcall'ed with *mouse-window*, | 230 If the form is a symbol (symbolp), it is funcall'ed with *mouse-window*, |
231 *mouse-x*, and *mouse-y* as arguments; if the form is a list (listp), | 231 *mouse-x*, and *mouse-y* as arguments; if the form is a list (listp), |
232 the form is eval'ed; if the form is neither of these, it is an error. | 232 the form is eval'ed; if the form is neither of these, it is an error. |
233 Returns nil." | 233 Returns nil." |
234 (interactive) | 234 (interactive) |
240 (mouse-code (mouse-event-code hit loc))) | 240 (mouse-code (mouse-event-code hit loc))) |
241 (let ((form (with-current-buffer (window-buffer *mouse-window*) | 241 (let ((form (with-current-buffer (window-buffer *mouse-window*) |
242 (mouse-lookup mouse-code)))) | 242 (mouse-lookup mouse-code)))) |
243 (cond ((null form) | 243 (cond ((null form) |
244 (if (not (sm::hit-up-p hit)) ; undefined up hits are ok. | 244 (if (not (sm::hit-up-p hit)) ; undefined up hits are ok. |
245 (error "Undefined mouse event: %s" | 245 (error "Undefined mouse event: %s" |
246 (prin1-to-string | 246 (prin1-to-string |
247 (mouse-code-to-mouse-list mouse-code))))) | 247 (mouse-code-to-mouse-list mouse-code))))) |
248 ((symbolp form) | 248 ((symbolp form) |
249 (setq this-command form) | 249 (setq this-command form) |
250 (funcall form *mouse-window* *mouse-x* *mouse-y*)) | 250 (funcall form *mouse-window* *mouse-x* *mouse-y*)) |
251 ((listp form) | 251 ((listp form) |
266 (let ((hit1 (mouse-hit-read))) | 266 (let ((hit1 (mouse-hit-read))) |
267 (if (not (sm::hit-up-p hit1)) ; Up hits dont start doubles or chords. | 267 (if (not (sm::hit-up-p hit1)) ; Up hits dont start doubles or chords. |
268 (let ((hit2 (mouse-second-hit extra-click-wait))) | 268 (let ((hit2 (mouse-second-hit extra-click-wait))) |
269 (if hit2 ; we cons'd it, we can smash it. | 269 (if hit2 ; we cons'd it, we can smash it. |
270 ; (setf (sm::hit-code hit1) (logior (sm::hit-code hit1) ...)) | 270 ; (setf (sm::hit-code hit1) (logior (sm::hit-code hit1) ...)) |
271 (setcar hit1 (logior (sm::hit-code hit1) | 271 (setcar hit1 (logior (sm::hit-code hit1) |
272 (sm::hit-code hit2) | 272 (sm::hit-code hit2) |
273 (if (= (sm::hit-button hit1) | 273 (if (= (sm::hit-button hit1) |
274 (sm::hit-button hit2)) | 274 (sm::hit-button hit2)) |
275 sm::DoubleBits 0)))))) | 275 sm::DoubleBits 0)))))) |
276 hit1)) | 276 hit1)) |
277 | 277 |
278 (defun mouse-hit-read () | 278 (defun mouse-hit-read () |
279 "Read mouse-hit list from keyboard. Like (read 'read-char), | 279 "Read mouse-hit list from keyboard. Like (read 'read-char), |
280 but that uses minibuffer, and mucks up last-command." | 280 but that uses minibuffer, and mucks up last-command." |
281 (let ((char-list nil) (char nil)) | 281 (let ((char-list nil) (char nil)) |
282 (while (not (equal 13 ; Carriage return. | 282 (while (not (equal 13 ; Carriage return. |
283 (prog1 (setq char (read-char)) | 283 (prog1 (setq char (read-char)) |
284 (setq char-list (cons char char-list)))))) | 284 (setq char-list (cons char char-list)))))) |
285 (read (mapconcat 'char-to-string (nreverse char-list) "")) | 285 (read (mapconcat 'char-to-string (nreverse char-list) "")) |
286 )) | 286 )) |
287 | 287 |
288 ;;; Second Click Hackery.... | 288 ;;; Second Click Hackery.... |
329 (defun sm::window-xy (x y) | 329 (defun sm::window-xy (x y) |
330 "Find window containing screen coordinates X and Y. | 330 "Find window containing screen coordinates X and Y. |
331 Returns list (window x y) where x and y are relative to window." | 331 Returns list (window x y) where x and y are relative to window." |
332 (or | 332 (or |
333 (catch 'found | 333 (catch 'found |
334 (eval-in-windows | 334 (eval-in-windows |
335 (let ((we (window-edges (selected-window)))) | 335 (let ((we (window-edges (selected-window)))) |
336 (let ((le (nth 0 we)) | 336 (let ((le (nth 0 we)) |
337 (te (nth 1 we)) | 337 (te (nth 1 we)) |
338 (re (nth 2 we)) | 338 (re (nth 2 we)) |
339 (be (nth 3 we))) | 339 (be (nth 3 we))) |
345 ;; id est, if window is not multple of char size. | 345 ;; id est, if window is not multple of char size. |
346 (setq be (1+ be))) | 346 (setq be (1+ be))) |
347 | 347 |
348 (if (and (>= x le) (< x re) | 348 (if (and (>= x le) (< x re) |
349 (>= y te) (< y be)) | 349 (>= y te) (< y be)) |
350 (throw 'found | 350 (throw 'found |
351 (list (selected-window) (- x le) (- y te)))))) | 351 (list (selected-window) (- x le) (- y te)))))) |
352 t)) ; include minibuffer in eval-in-windows | 352 t)) ; include minibuffer in eval-in-windows |
353 ;;If x,y from a real mouse click, we shouldn't get here. | 353 ;;If x,y from a real mouse click, we shouldn't get here. |
354 (list nil x y) | 354 (list nil x y) |
355 )) | 355 )) |
373 (>= x (+ 2 (window-line-end w x y)))) | 373 (>= x (+ 2 (window-line-end w x y)))) |
374 'scrollbar) | 374 'scrollbar) |
375 (t 'text))))) | 375 (t 'text))))) |
376 | 376 |
377 (defun window-line-end (w x y) | 377 (defun window-line-end (w x y) |
378 "Return WINDOW column (ignore X) containing end of line Y" | 378 "Return WINDOW column (ignore X) containing end of line Y." |
379 (eval-in-window w (save-excursion (move-to-loc (frame-width) y)))) | 379 (eval-in-window w (save-excursion (move-to-loc (frame-width) y)))) |
380 | 380 |
381 ;;; | 381 ;;; |
382 ;;; The encoding of mouse events into a mousemap. | 382 ;;; The encoding of mouse events into a mousemap. |
383 ;;; These values must agree with coding in emacstool: | 383 ;;; These values must agree with coding in emacstool: |
384 ;;; | 384 ;;; |
385 (defconst sm::keyword-alist | 385 (defconst sm::keyword-alist |
386 '((left . 1) (middle . 2) (right . 4) | 386 '((left . 1) (middle . 2) (right . 4) |
387 (shift . 8) (control . 16) (meta . 32) (double . 64) (up . 128) | 387 (shift . 8) (control . 16) (meta . 32) (double . 64) (up . 128) |
388 (text . 256) (scrollbar . 512) (modeline . 1024) (minibuffer . 2048) | 388 (text . 256) (scrollbar . 512) (modeline . 1024) (minibuffer . 2048) |
389 )) | 389 )) |
390 | 390 |
536 (princ "--------- ------") (terpri) | 536 (princ "--------- ------") (terpri) |
537 (print-mouse-bindings 'scrollbar))) | 537 (print-mouse-bindings 'scrollbar))) |
538 | 538 |
539 (defun describe-mouse-briefly (mouse-list) | 539 (defun describe-mouse-briefly (mouse-list) |
540 "Print a short description of the function bound to MOUSE-LIST." | 540 "Print a short description of the function bound to MOUSE-LIST." |
541 (interactive "xDescibe mouse list briefly: ") | 541 (interactive "xDescribe mouse list briefly: ") |
542 (let ((function (mouse-lookup (mouse-list-to-mouse-code mouse-list)))) | 542 (let ((function (mouse-lookup (mouse-list-to-mouse-code mouse-list)))) |
543 (if function | 543 (if function |
544 (message "%s runs the command %s" mouse-list function) | 544 (message "%s runs the command %s" mouse-list function) |
545 (message "%s is undefined" mouse-list)))) | 545 (message "%s is undefined" mouse-list)))) |
546 | 546 |
582 of MENU. MENU (or its symbol-value) should be a menu defined by defmenu. | 582 of MENU. MENU (or its symbol-value) should be a menu defined by defmenu. |
583 A menu ITEM is a (STRING . FORM) pair; | 583 A menu ITEM is a (STRING . FORM) pair; |
584 the FORM associated with the selected STRING is evaluated, | 584 the FORM associated with the selected STRING is evaluated, |
585 and the resulting value is returned. Generally these FORMs are | 585 and the resulting value is returned. Generally these FORMs are |
586 evaluated for their side-effects rather than their values. | 586 evaluated for their side-effects rather than their values. |
587 If the selected form is a menu or a symbol whose value is a menu, | 587 If the selected form is a menu or a symbol whose value is a menu, |
588 then it is displayed and evaluated as a pullright menu item. | 588 then it is displayed and evaluated as a pullright menu item. |
589 If the FORM of the first ITEM is nil, the STRING of the item | 589 If the FORM of the first ITEM is nil, the STRING of the item |
590 is used as a label for the menu, i.e. it's inverted and not selectable." | 590 is used as a label for the menu, i.e. it's inverted and not selectable." |
591 | 591 |
592 (if (symbolp menu) (setq menu (symbol-value menu))) | 592 (if (symbolp menu) (setq menu (symbol-value menu))) |
593 (eval (sun-menu-internal *menu-window* *menu-x* *menu-y* 4 menu))) | 593 (eval (sun-menu-internal *menu-window* *menu-x* *menu-y* 4 menu))) |
594 | 594 |
595 (defun sun-get-frame-data (code) | 595 (defun sun-get-frame-data (code) |
596 "Sends the tty-sub-window escape sequence CODE to terminal, | 596 "Sends the tty-sub-window escape sequence CODE to terminal, |
597 and returns a cons of the two numbers in returned escape sequence. | 597 and returns a cons of the two numbers in returned escape sequence. |
598 That is it returns (cons <car> <cdr>) from \"\\E[n;<car>;<cdr>t\". | 598 That is it returns (cons <car> <cdr>) from \"\\E[n;<car>;<cdr>t\". |
599 CODE values: 13 = Tool-Position, 14 = Size-in-Pixels, 18 = Size-in-Chars." | 599 CODE values: 13 = Tool-Position, 14 = Size-in-Pixels, 18 = Size-in-Chars." |
600 (send-string-to-terminal (concat "\033[" (int-to-string code) "t")) | 600 (send-string-to-terminal (concat "\033[" (int-to-string code) "t")) |
601 (let (char str x y) | 601 (let (char str x y) |
602 (while (not (equal 116 (setq char (read-char)))) ; #\t = 116 | 602 (while (not (equal 116 (setq char (read-char)))) ; #\t = 116 |
603 (setq str (cons char str))) | 603 (setq str (cons char str))) |
613 "Returns font size in pixels: (cons Ysize Xsize)" | 613 "Returns font size in pixels: (cons Ysize Xsize)" |
614 (let ((pix (sun-get-frame-data 14)) ; returns size in pixels | 614 (let ((pix (sun-get-frame-data 14)) ; returns size in pixels |
615 (chr (sun-get-frame-data 18))) ; returns size in chars | 615 (chr (sun-get-frame-data 18))) ; returns size in chars |
616 (cons (/ (car pix) (car chr)) (/ (cdr pix) (cdr chr))))) | 616 (cons (/ (car pix) (car chr)) (/ (cdr pix) (cdr chr))))) |
617 | 617 |
618 (defvar sm::menu-kludge-x nil | 618 (defvar sm::menu-kludge-x nil |
619 "Cached frame-to-window X-Offset for sm::menu-kludge") | 619 "Cached frame-to-window X-Offset for sm::menu-kludge") |
620 (defvar sm::menu-kludge-y nil | 620 (defvar sm::menu-kludge-y nil |
621 "Cached frame-to-window Y-Offset for sm::menu-kludge") | 621 "Cached frame-to-window Y-Offset for sm::menu-kludge") |
622 | 622 |
623 (defun sm::menu-kludge () | 623 (defun sm::menu-kludge () |
624 "If sunfns.c uses <Menu_Base_Kludge> this function must be here!" | 624 "If sunfns.c uses <Menu_Base_Kludge> this function must be here!" |
625 (or sm::menu-kludge-y | 625 (or sm::menu-kludge-y |
639 Insert contents into the current buffer at point." | 639 Insert contents into the current buffer at point." |
640 (interactive "*") | 640 (interactive "*") |
641 (set-mark-command nil) | 641 (set-mark-command nil) |
642 (insert-string (sun-get-selection))) | 642 (insert-string (sun-get-selection))) |
643 | 643 |
644 (defun sun-select-region (beg end) | 644 (defun sun-select-region (start end) |
645 "Set the sunwindows selection to the region in the current buffer." | 645 "Set the sunwindows selection to the region in the current buffer." |
646 (interactive "r") | 646 (interactive "r") |
647 (sun-set-selection (buffer-substring beg end))) | 647 (sun-set-selection (buffer-substring start end))) |
648 | 648 |
649 ;;; | 649 ;;; |
650 ;;; Support for emacstool | 650 ;;; Support for emacstool |
651 ;;; This closes the window instead of stopping emacs. | 651 ;;; This closes the window instead of stopping emacs. |
652 ;;; | 652 ;;; |
653 (defun suspend-emacstool (&optional stuffstring) | 653 (defun suspend-emacstool (&optional stuffstring) |
654 "Suspend emacstool. | 654 "Suspend emacstool. |
655 If running under as a detached process emacstool, | 655 If running under as a detached process emacstool, |
656 you don't want to suspend (there is no way to resume), | 656 you don't want to suspend (there is no way to resume), |
657 just close the window, and wait for reopening." | 657 just close the window, and wait for reopening." |
658 (interactive) | 658 (interactive) |
659 (run-hooks 'suspend-hook) | 659 (run-hooks 'suspend-hook) |
660 (if stuffstring (send-string-to-terminal stuffstring)) | 660 (if stuffstring (send-string-to-terminal stuffstring)) |
661 (send-string-to-terminal "\033[2t") ; To close EmacsTool window. | 661 (send-string-to-terminal "\033[2t") ; To close EmacsTool window. |