Article View: gnu.epoch.misc
Article #67is this good mouse-tracking code?
From: Hans Tallis
Date: Fri, 03 Apr 1992 13:45
Date: Fri, 03 Apr 1992 13:45
77 lines
3061 bytes
3061 bytes
This is my first attempt at writing a mouse-tracker. I'm not sure whether I'm
doing things in the best way, so if you could comment/correct I'd be grateful.
--Hans
This is for e/lisp code.
I want to highlight the following list structure whenever the mouse is over a
left parenthesis. I just want to look at the mouse motion event, and then pass
it on to the next motion event handler on the stack.
Questions:
- How to pass on to the next event handler? I kludged this below, but
is this the best way?
- This is expensive code to run, tracking the mouse all the time. Any
way to speed it up?
- Should I be using drag zones for the highlighting?
--------------------snip, snip------------------------------------------------
(defvar running-epoch (boundp 'epoch::version))
;;; mouse-tracking: live action following the mouse
;;; --------------
;;; highlights a list if looking-at one. Does _not_ copy it into kill buffer
;;; until you mouse-left.
;;;
;;; mousing is defined in the epoch manual, "Mouse Events"
(require 'motion)
(defvar mouse-tracker-drag-zone nil)
;;; the motion event handler: if over a list in a lisp-mode buffer, hilite.
(defun mouse-tracker (type value screen)
(let ((epoch::event-handler-abort nil)
)
(save-excursion
(save-window-excursion
(let ((point (coords-to-point (elt value 0)(elt value 1) (current-screen))))
(when point
(mouse::set-point point)
(when ;; am I interested in event?
(or (equal mode-name "Emacs-Lisp")
(equal mode-name "Lisp"))
(if (looking-at "(")
(progn
(call-interactively 'set-mark-command)
(condition-case nil
(forward-sexp)
(error ))
(when mouse-tracker-drag-zone
(delete-zone mouse-tracker-drag-zone))
(setq mouse-tracker-drag-zone (add-zone (point) (mark)
motion::style)))
(when mouse-tracker-drag-zone
(delete-zone mouse-tracker-drag-zone)))
)
))))
;; and pass on event to next handler
(let* ((myself (pop-event 'motion))
(next-handler (pop-event 'motion)))
(push-event 'motion next-handler)
(funcall next-handler type value screen)
(push-event 'motion myself))
;; keep feeding myself fresh events
(epoch::query-pointer)
))
(defun add-mouse-tracker-handler ()
(push-event 'motion 'mouse-tracker))
(defun remove-mouse-tracker-handler ()
"be careful! must follow previous push-event!"
(pop-event 'motion))
(when running-epoch
(add-mouse-tracker-handler))
Technical Details
Message-ID:
<tallis.702308714@starbase>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!linus!linus.mitre.org!starbase!tallisShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!linus!linus.mitre.org!starbase!tallis From: tallis@starbase.mitre.org (Hans Tallis) Newsgroups: gnu.epoch.misc Subject: is this good mouse-tracking code? Message-ID: <tallis.702308714@starbase> Date: 3 Apr 92 13:45:14 GMT Sender: news@linus.mitre.org (News Service) Distribution: usa Organization: The MITRE Corporation Lines: 77 Nntp-Posting-Host: starbase.mitre.org