home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / terms / tek4404-mouse.el < prev    next >
Encoding:
Text File  |  1991-03-30  |  2.5 KB  |  73 lines

  1. ; Path: utkcs2!emory!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ELF.TN.CORNELL.EDU!eirik
  2. ; >From: eirik@ELF.TN.CORNELL.EDU ("Eirik Fuller")
  3. ; Newsgroups: gnu.emacs
  4. ; Subject: Tek 4404 mouse support
  5. ; Date: 24 Jul 90 03:09:11 GMT
  6. ; Organization: GNUs Not Usenet
  7. ; The enclosed lisp code provides the machine-specific details necessary
  8. ; to use the mouse support in my previous posting with the terminal
  9. ; emulator of a Tektronix 4404 (and its various descendants like the
  10. ; 4315, 4316, and 4317).  On my system it is installed as
  11. ; /usr/local/emacs/lisp/term/4404.el; also included is a support
  12. ; function it uses.
  13. ; ---------------- term/4404.el ----------------
  14. (require 'add-hook)
  15. (require 'mouse)
  16.  
  17. (global-set-key "\M-P" 'tek4404-handle-mouse-event)
  18.  
  19. (defun tek4404-enable-mouse ()
  20.   "Send escape sequence which enables mouse events and graphics cursor"
  21.   (send-string-to-terminal "\C-[Q3;1J\C-[Q1M"))
  22.  
  23. (defun tek4404-disable-mouse ()
  24.   "Send escape sequence which disables mouse events and graphics cursor"
  25.   (send-string-to-terminal "\C-[QJ\C-[QM"))
  26.  
  27. (defun tek4404-handle-mouse-event ()
  28.   "Parse the escape sequence, and call the appropriate function"
  29.   (interactive)
  30.   (let ((state (read-char)) (button (read-char)) (way (read-char))
  31.     point index)
  32.     (setq point (- (read-number) 1))
  33.     (setq point (list (- (read-number) 1) point))
  34.     (setq index (+ (- ?3 button) (* (/ (- way ?D) 17) 4)))
  35.     (if (= (read-char) ?\\ )
  36.     (funcall (aref mouse-map index) point))))
  37.  
  38. (defun read-number ()
  39.   "Read digits from input and keep tally. Lose last character"
  40.   (let ((total 0) digit)
  41.     (while (progn 
  42.          (setq digit (read-char))
  43.          (and (>= digit ?0) (<= digit ?9)))
  44.       (setq total (+ (* total 10) (- digit ?0))))
  45.     total))
  46.  
  47. (add-hook 'kill-emacs-hook 'tek4404-disable-mouse)
  48. (add-hook 'suspend-hook 'tek4404-disable-mouse)
  49. (add-hook 'suspend-resume-hook 'tek4404-enable-mouse)
  50. (tek4404-enable-mouse)
  51.  
  52. ;; ---------------- add-hook.el ----------------
  53.  
  54. (provide 'add-hook)
  55.  
  56. (defun add-hook (hook-var hook-function)
  57.   "Prepend hook-function to hook-var's value, if it is not already an element.
  58. hook-var's value may be a single function or a list of functions."
  59.   (if (boundp hook-var)
  60.       (let ((value (symbol-value hook-var)))
  61.     (if (and (listp value) (not (eq (car value) 'lambda)))
  62.         (and (not (memq hook-function value))
  63.          (set hook-var
  64.               (if value (cons hook-function value) hook-function)))
  65.       (and (not (eq hook-function value))
  66.            (set hook-var
  67.             (list hook-function value)))))
  68.     (set hook-var hook-function)
  69.     ))
  70.