home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / EmacsTeX / Emacs-3.0.1 / Source / lisp / eterm-low.el < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.3 KB  |  161 lines

  1.  ;; Low-level subroutines for NeXT "Emacs" front end
  2.  ;; Copyright (C) 1990 Free Software Foundation, Inc.
  3.  
  4.  ;; This file is NOT part of the standard GNU Emacs distribution.
  5.  
  6.  ;; GNU Emacs is distributed in the hope that it will be useful,
  7.  ;; but WITHOUT ANY WARRANTY.  No author or distributor
  8.  ;; accepts responsibility to anyone for the consequences of using it
  9.  ;; or for whether it serves any particular purpose or works at all,
  10.  ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  11.  ;; License for full details.
  12.  
  13.  ;; Everyone is granted permission to copy, modify and redistribute
  14.  ;; GNU Emacs, but only under the conditions described in the
  15.  ;; GNU Emacs General Public License.   A copy of this license is
  16.  ;; supposed to have been given to you along with GNU Emacs so you
  17.  ;; can know your rights and responsibilities.  It should be in a
  18.  ;; file named COPYING.  Among other things, the copyright notice
  19.  ;; and this notice must be preserved on all copies.
  20.  
  21.  ;;; Apr 4 '90 jgm    Ripped off of sun-fns.el
  22.  
  23.  ;;(provide 'eterm-low)
  24.  
  25.  (defun eterm-send-terminal-string-function (string function)
  26.    "Send a \\C-q quoted string to the terminal, then send function"
  27.    (send-string-to-terminal (concat "\C-q" string "\377" function)))
  28.  
  29.  (defun eterm-change-title (title)
  30.    "Change the wm title for the gnumacs window."
  31.    (interactive "sTitle: ")
  32.    (eterm-send-terminal-string-function title "t"))
  33.  
  34.  ;(defun global-set-menu (item command)
  35.  ;  "Add a command to the wm menus."
  36.  ;  (interactive "sMenu item: \nCCommand: ")
  37.  ;  (eterm-send-terminal-string-function
  38.  ;   (concat item ":\C-[x" (prin1-to-string command) "\n") "m"))
  39.  ;
  40.  ;(defun global-unset-menu (item)
  41.  ;  "Remove a menu item from the wm menus."
  42.  ;  (interactive "sMenu item: ")
  43.  ;  (eterm-send-terminal-string-function item "m"))
  44.  ;
  45.  ;(defun add-menu-item (item binding &optional page)
  46.  ;  "Add a menu item to the menus.  (obsolete)"
  47.  ;  (interactive "sItem: \nsBinding: \nsPage: ")
  48.  ;  (eterm-send-terminal-string-function
  49.  ;   (concat page (and page ", ")
  50.  ;       item (and binding (not (string= binding "")) ":") binding)
  51.  ;   "m"))
  52.  ;
  53.  ;(defun remove-menu-item (item &optional page)
  54.  ;  "Remove ITEM from the wm menus.  (obsolete)"
  55.  ;  (interactive "sItem: \nsPage:")
  56.  ;  (add-menu-item item "" page))
  57.  
  58.  ; something to hide without using the mouse
  59.  ;(defun eterm-hide-emacs ()
  60.  ;  "Ask the termulator to hide this window."
  61.  ;  (interactive)
  62.  ;  (send-string-to-terminal "\C-z"))
  63.  
  64.  ; cut buffer stuff
  65.  
  66.  (defun eterm-send-region-to-cut-buffer ()
  67.    "   Copy the region between point and mark to the NeXT cut buffer.
  68.     This will not happen if the region contains a \\377."
  69.    (interactive "")
  70.    (save-excursion
  71.      ;; We get our own values for the region, so we can trap the error
  72.      ;; if there is none.
  73.      (condition-case err
  74.      (let ((start (region-beginning))
  75.            (end (region-end)))
  76.        (goto-char start)
  77.        (if (search-forward "\377" end t)
  78.            (progn
  79.          (eterm-send-terminal-string-function "" "c")
  80.          (message "Bogus character in region."))
  81.          (eterm-send-terminal-string-function
  82.           (buffer-substring start end) "c")))
  83.        ;;
  84.        ;; The region is empty, send a nil region out and continue.
  85.        (error (eterm-send-terminal-string-function "" "c")))))
  86.  
  87. (defun eterm-send-region-to-cut-buffer-and-wipe ()
  88.   "  As send-region-to-cut-buffer but also kill the text."
  89.   (interactive "")
  90.   (barf-if-buffer-read-only)
  91.   (eterm-send-region-to-cut-buffer)
  92.   (call-interactively 'kill-region))
  93.  
  94. ;
  95. ; Event server stuff
  96. ;
  97.  
  98. (defvar eserver nil 
  99.   "The event server process.")
  100.  
  101. (defun start-event-server ()
  102.   (interactive)
  103.   (eterm-change-title (concat "Emacs version " emacs-version))
  104.   (let ((host (or (getenv "EVENT_HOST")
  105.           (error "Can't find host for event server")))
  106.     (port (or (getenv "EVENT_PORT")
  107.           (error "Can't find port for event server"))))
  108.     (setq eserver 
  109.       (open-network-stream " event-server" nil host
  110.                    (string-to-int port))))
  111.   (set-process-filter eserver 'event-filter)
  112.   (set-process-sentinel eserver 'event-sentinel)
  113.   (global-set-key "\C-x\C-@" 'eterm-mouse-handler))
  114.  
  115. (defun event-sentinel (process change)
  116.   (message (concat  "The event handler has " change)))
  117.  
  118. (defvar event-partial-output ""
  119.   "Incomplete, unprocessed output from the event server")
  120.  
  121. ;;; Modified by J. Gregory 17-Oct-91.  Save match-end before match
  122. ;;; data gets crunched.
  123. (defun event-filter (process string)
  124.   ;; Add the incoming string to what we have:
  125.   (let ((events (concat event-partial-output string)))
  126.     ;; Each event is terminated with a newline.
  127.     ;; Process events until we run out of newlines.
  128.     (while (string-match "\n" events)    ;sets match-data
  129.       (let ((next (match-end 0)))
  130.     (eval (car (read-from-string events)))
  131.     (setq events (substring events next))))
  132.     ;; Set global to be what we have not yet processed
  133.     (setq event-partial-output events)))
  134.  
  135. ; Handlers for the events that get sent to us.
  136. ;
  137. (defun event-copy ()
  138.   (eterm-send-region-to-cut-buffer))
  139.  
  140. (defun event-cut ()
  141.   (eterm-send-region-to-cut-buffer-and-wipe))
  142.  
  143. (defun event-paste (str)
  144.   (barf-if-buffer-read-only)
  145.   (push-mark (point))
  146.   (insert str))
  147.  
  148. (defun event-quit ()
  149.   (save-buffers-kill-emacs)
  150.   (setq last-command 'save-buffers-kill-emacs))
  151.  
  152. ;(defun event-resize (newx newy)
  153. ;  (if (or (not (= (screen-width) newx))
  154. ;      (not (= (screen-height) newy)))
  155. ;      (progn
  156. ;    (set-screen-width newx)
  157. ;    (set-screen-height newy))
  158. ;    (redraw-display)))
  159.  
  160.  
  161.