🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Hans Tallis Fri, 03 Apr 1992 13:45
is this good mouse-tracking code?
#67
Author: Hans Tallis
Date: Fri, 03 Apr 1992 13:45
77 lines
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))
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads